diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-06-09 16:06:37 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-06-09 14:12:18 +0200 |
commit | 7d2a7307da71b245fe55c55c5a29f4695c3c54f7 (patch) | |
tree | b1d063405b1f8cb0fb002511fca945b469766a33 /docmodel | |
parent | 30bc5fdb49621269b7281aace610ca85b150766c (diff) |
fix wrong transform type, error handling when JSON parsing
also fix theme export - change scheme enum type name "hlink" to
"hyperlink" and "folHlink" to "followedHyperlink"
Change-Id: Id5435d59cd51352efc4a4a8e333ec1ff45847a6f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152782
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'docmodel')
-rw-r--r-- | docmodel/source/color/ComplexColorJSON.cxx | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/docmodel/source/color/ComplexColorJSON.cxx b/docmodel/source/color/ComplexColorJSON.cxx index db36f29e6a4e..f6b52d1bf55c 100644 --- a/docmodel/source/color/ComplexColorJSON.cxx +++ b/docmodel/source/color/ComplexColorJSON.cxx @@ -18,40 +18,42 @@ namespace model::color bool convertFromJSON(OString const& rJsonString, model::ComplexColor& rComplexColor) { model::ComplexColor aComplexColor; - std::stringstream aStream((std::string(rJsonString))); - boost::property_tree::ptree aRootTree; + try { + std::stringstream aStream((std::string(rJsonString))); + boost::property_tree::ptree aRootTree; boost::property_tree::read_json(aStream, aRootTree); + + sal_Int32 nThemeType = aRootTree.get<sal_Int32>("ThemeIndex", -1); + aComplexColor.setSchemeColor(model::convertToThemeColorType(nThemeType)); + boost::property_tree::ptree aTransformTree = aRootTree.get_child("Transformations"); + for (const auto& rEachTransformationNode : + boost::make_iterator_range(aTransformTree.equal_range(""))) + { + auto const& rTransformationTree = rEachTransformationNode.second; + std::string sType = rTransformationTree.get<std::string>("Type", ""); + sal_Int16 nValue = rTransformationTree.get<sal_Int16>("Value", 0); + + auto eType = model::TransformationType::Undefined; + if (sType == "LumOff") + eType = model::TransformationType::LumOff; + else if (sType == "LumMod") + eType = model::TransformationType::LumMod; + else if (sType == "Tint") + eType = model::TransformationType::Tint; + else if (sType == "Shade") + eType = model::TransformationType::Shade; + + if (eType != model::TransformationType::Undefined) + aComplexColor.addTransformation({ eType, nValue }); + } } catch (const boost::property_tree::json_parser_error& /*exception*/) { return false; } - sal_Int32 nThemeType = aRootTree.get<sal_Int32>("ThemeIndex", -1); - aComplexColor.setSchemeColor(model::convertToThemeColorType(nThemeType)); - boost::property_tree::ptree aTransformTree = aRootTree.get_child("Transformations"); - for (const auto& rEachTransformationNode : - boost::make_iterator_range(aTransformTree.equal_range(""))) - { - auto const& rTransformationTree = rEachTransformationNode.second; - std::string sType = rTransformationTree.get<std::string>("Type", ""); - sal_Int16 nValue = rTransformationTree.get<sal_Int16>("Value", 0); - - auto eType = model::TransformationType::Undefined; - if (sType == "LumOff") - eType = model::TransformationType::LumOff; - else if (sType == "LumMod") - eType = model::TransformationType::LumMod; - else if (sType == "Tint") - eType = model::TransformationType::Tint; - else if (sType == "Shade") - eType = model::TransformationType::Shade; - - if (eType != model::TransformationType::Undefined) - aComplexColor.addTransformation({ eType, nValue }); - } rComplexColor = aComplexColor; return true; } |