tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / xmloff / source / text / XMLComplexColorContext.cxx
blob5d81983596702935b81d022aa367b1342edb3742
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/config.h>
12 #include <sal/log.hxx>
13 #include <sax/tools/converter.hxx>
14 #include <xmloff/xmluconv.hxx>
15 #include <xmloff/xmlnamespace.hxx>
16 #include <xmloff/xmlimp.hxx>
17 #include <xmloff/xmltoken.hxx>
18 #include <xmloff/xmlement.hxx>
19 #include <xmloff/XMLComplexColorContext.hxx>
20 #include <docmodel/uno/UnoComplexColor.hxx>
22 using namespace css;
23 using namespace xmloff::token;
25 SvXMLEnumMapEntry<sal_Int16> const pXML_ThemeColor_Enum[] = { { XML_NONE, -1 },
26 { XML_DARK1, 0 },
27 { XML_LIGHT1, 1 },
28 { XML_DARK2, 2 },
29 { XML_LIGHT2, 3 },
30 { XML_ACCENT1, 4 },
31 { XML_ACCENT2, 5 },
32 { XML_ACCENT3, 6 },
33 { XML_ACCENT4, 7 },
34 { XML_ACCENT5, 8 },
35 { XML_ACCENT6, 9 },
36 { XML_HYPERLINK, 10 },
37 { XML_FOLLOWED_HYPERLINK, 11 },
38 { XML_TOKEN_INVALID, 0 } };
40 XMLComplexColorImport::XMLComplexColorImport(model::ComplexColor& rComplexColor)
41 : mrComplexColor(rComplexColor)
45 void XMLComplexColorImport::fillAttributes(
46 const uno::Reference<xml::sax::XFastAttributeList>& xAttrList)
48 for (auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList))
50 switch (aIter.getToken())
52 case XML_ELEMENT(LO_EXT, XML_THEME_TYPE):
54 sal_Int16 nValue = -1;
55 if (SvXMLUnitConverter::convertEnum(nValue, aIter.toView(), pXML_ThemeColor_Enum))
57 mrComplexColor.setThemeColor(model::convertToThemeColorType(nValue));
59 break;
61 case XML_ELEMENT(LO_EXT, XML_COLOR_TYPE):
63 const OUString aValue = aIter.toString();
64 if (aValue == u"theme")
65 mrComplexColor.setType(model::ColorType::Theme);
66 // TODO - handle other color types
67 break;
69 default:
70 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
71 break;
76 bool XMLComplexColorImport::handleTransformContext(
77 sal_Int32 nElement, const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList)
79 if (nElement == XML_ELEMENT(LO_EXT, XML_TRANSFORMATION))
81 auto eTransformationType = model::TransformationType::Undefined;
82 sal_Int16 nTransformationValue = 0;
83 for (auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList))
85 switch (aIter.getToken())
87 case XML_ELEMENT(LO_EXT, XML_TYPE):
89 const OUString aValue = aIter.toString();
90 if (aValue == u"tint")
91 eTransformationType = model::TransformationType::Tint;
92 else if (aValue == u"shade")
93 eTransformationType = model::TransformationType::Shade;
94 else if (aValue == u"lumoff")
95 eTransformationType = model::TransformationType::LumOff;
96 else if (aValue == u"lummod")
97 eTransformationType = model::TransformationType::LumMod;
98 break;
100 case XML_ELEMENT(LO_EXT, XML_VALUE):
102 sal_Int32 nValue;
103 if (::sax::Converter::convertNumber(nValue, aIter.toView(), SHRT_MIN, SHRT_MAX))
104 nTransformationValue = static_cast<sal_Int16>(nValue);
105 break;
107 default:
108 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
109 break;
112 mrComplexColor.addTransformation({ eTransformationType, nTransformationValue });
113 return true;
115 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
116 return false;
119 XMLPropertyComplexColorContext::XMLPropertyComplexColorContext(
120 SvXMLImport& rImport, sal_Int32 nElement,
121 const uno::Reference<xml::sax::XFastAttributeList>& xAttrList, const XMLPropertyState& rProp,
122 std::vector<XMLPropertyState>& rProps)
123 : XMLElementPropertyContext(rImport, nElement, rProp, rProps)
124 , mnRootElement(nElement)
125 , maComplexColorImport(maComplexColor)
127 maComplexColorImport.fillAttributes(xAttrList);
130 css::uno::Reference<css::xml::sax::XFastContextHandler>
131 XMLPropertyComplexColorContext::createFastChildContext(
132 sal_Int32 nElement, const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList)
134 if (maComplexColorImport.handleTransformContext(nElement, xAttrList))
135 return this;
136 return nullptr;
139 void XMLPropertyComplexColorContext::endFastElement(sal_Int32 nElement)
141 if (nElement == mnRootElement)
143 if (getComplexColor().getThemeColorType() != model::ThemeColorType::Unknown)
145 aProp.maValue <<= model::color::createXComplexColor(getComplexColor());
146 SetInsert(true);
149 XMLElementPropertyContext::endFastElement(nElement);
152 XMLComplexColorContext::XMLComplexColorContext(
153 SvXMLImport& rImport, model::ComplexColor& rComplexColor,
154 const uno::Reference<xml::sax::XFastAttributeList>& xAttrList)
155 : SvXMLImportContext(rImport)
156 , maComplexColorImport(rComplexColor)
158 maComplexColorImport.fillAttributes(xAttrList);
161 css::uno::Reference<css::xml::sax::XFastContextHandler>
162 XMLComplexColorContext::createFastChildContext(
163 sal_Int32 nElement, const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList)
165 if (maComplexColorImport.handleTransformContext(nElement, xAttrList))
166 return this;
167 return nullptr;
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */