docmodel/source/color/ComplexColorJSON.cxx    |   52 +++++++++++++-------------
 editeng/source/items/textitem.cxx             |    9 ++--
 svx/source/theme/ThemeColorPaletteManager.cxx |    2 -
 sw/source/filter/ww8/docxattributeoutput.cxx  |    4 +-
 4 files changed, 35 insertions(+), 32 deletions(-)

New commits:
commit 7d2a7307da71b245fe55c55c5a29f4695c3c54f7
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Fri Jun 9 16:06:37 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Jun 9 14:12:18 2023 +0200

    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 <qui...@gmail.com>

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;
 }
diff --git a/editeng/source/items/textitem.cxx 
b/editeng/source/items/textitem.cxx
index 2f11ab7bb9b2..546918197a34 100644
--- a/editeng/source/items/textitem.cxx
+++ b/editeng/source/items/textitem.cxx
@@ -1555,11 +1555,11 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, 
sal_uInt8 nMemberId )
                 return false;
 
             if (sComplexColorJson.isEmpty())
-            {
                 return false;
-            }
+
             OString aJSON = OUStringToOString(sComplexColorJson, 
RTL_TEXTENCODING_ASCII_US);
-            model::color::convertFromJSON(aJSON, maComplexColor);
+            if (!model::color::convertFromJSON(aJSON, maComplexColor))
+                return false;
         }
         break;
         case MID_COMPLEX_COLOR:
@@ -1575,7 +1575,8 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, 
sal_uInt8 nMemberId )
         case MID_COLOR_RGB:
         default:
         {
-            return rVal >>= mColor;
+            if (!(rVal >>= mColor))
+                return false;
         }
         break;
     }
diff --git a/svx/source/theme/ThemeColorPaletteManager.cxx 
b/svx/source/theme/ThemeColorPaletteManager.cxx
index c1fcc9fc0aa7..2a81106a8ffb 100644
--- a/svx/source/theme/ThemeColorPaletteManager.cxx
+++ b/svx/source/theme/ThemeColorPaletteManager.cxx
@@ -151,7 +151,7 @@ OString ThemeColorPaletteManager::generateJSON()
             aComplexColor.addTransformation(
                 { model::TransformationType::LumMod, rEffectData.mnLumMod });
             aComplexColor.addTransformation(
-                { model::TransformationType::LumMod, rEffectData.mnLumOff });
+                { model::TransformationType::LumOff, rEffectData.mnLumOff });
             boost::property_tree::ptree aDataTree;
             model::color::convertToJSONTree(aDataTree, aComplexColor);
             aColorTree.add_child("Data", aDataTree);
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 306c648c7dd6..380884cfa51e 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -7661,8 +7661,8 @@ void DocxAttributeOutput::CharColor(const SvxColorItem& 
rColorItem)
         { model::ThemeColorType::Accent4, "accent4" },
         { model::ThemeColorType::Accent5, "accent5" },
         { model::ThemeColorType::Accent6, "accent6" },
-        { model::ThemeColorType::Hyperlink, "hlink" },
-        { model::ThemeColorType::FollowedHyperlink, "folHlink" }
+        { model::ThemeColorType::Hyperlink, "hyperlink" },
+        { model::ThemeColorType::FollowedHyperlink, "followedHyperlink" }
     };
 
     const Color aColor = rColorItem.getColor();

Reply via email to