LibreOffice Module xmloff (master) 1
XMLComplexColorContext.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10#include <sal/config.h>
11
12#include <sal/log.hxx>
14#include <xmloff/xmluconv.hxx>
17#include <xmloff/xmlimp.hxx>
18#include <xmloff/xmltoken.hxx>
19#include <xmloff/xmlement.hxx>
20#include <xmloff/xmlprhdl.hxx>
22
23using namespace css;
24using namespace xmloff::token;
25
27 { XML_DARK1, 0 },
28 { XML_LIGHT1, 1 },
29 { XML_DARK2, 2 },
30 { XML_LIGHT2, 3 },
31 { XML_ACCENT1, 4 },
32 { XML_ACCENT2, 5 },
33 { XML_ACCENT3, 6 },
34 { XML_ACCENT4, 7 },
35 { XML_ACCENT5, 8 },
36 { XML_ACCENT6, 9 },
37 { XML_HYPERLINK, 10 },
39 { XML_TOKEN_INVALID, 0 } };
40
42 SvXMLImport& rImport, sal_Int32 nElement,
43 const uno::Reference<xml::sax::XFastAttributeList>& xAttrList, const XMLPropertyState& rProp,
44 std::vector<XMLPropertyState>& rProps)
45 : XMLElementPropertyContext(rImport, nElement, rProp, rProps)
46 , mnRootElement(nElement)
47{
48 for (auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList))
49 {
50 switch (aIter.getToken())
51 {
52 case XML_ELEMENT(LO_EXT, XML_THEME_TYPE):
53 {
54 sal_Int16 nValue = -1;
56 {
58 }
59 break;
60 }
61 case XML_ELEMENT(LO_EXT, XML_COLOR_TYPE):
62 {
63 const OUString aValue = aIter.toString();
64 if (aValue == u"theme")
66 // TODO - handle other color types
67 break;
68 }
69 default:
70 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
71 break;
72 }
73 }
74}
75
76css::uno::Reference<css::xml::sax::XFastContextHandler>
78 sal_Int32 nElement, const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList)
79{
80 if (nElement == XML_ELEMENT(LO_EXT, XML_TRANSFORMATION))
81 {
82 auto eTransformationType = model::TransformationType::Undefined;
83 sal_Int16 nTransformationValue = 0;
84 for (auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList))
85 {
86 switch (aIter.getToken())
87 {
88 case XML_ELEMENT(LO_EXT, XML_TYPE):
89 {
90 const OUString aValue = aIter.toString();
91 if (aValue == u"tint")
92 eTransformationType = model::TransformationType::Tint;
93 else if (aValue == u"shade")
94 eTransformationType = model::TransformationType::Shade;
95 else if (aValue == u"lumoff")
96 eTransformationType = model::TransformationType::LumOff;
97 else if (aValue == u"lummod")
98 eTransformationType = model::TransformationType::LumMod;
99 break;
100 }
101 case XML_ELEMENT(LO_EXT, XML_VALUE):
102 {
103 sal_Int32 nValue;
104 if (::sax::Converter::convertNumber(nValue, aIter.toView(), SHRT_MIN, SHRT_MAX))
105 nTransformationValue = static_cast<sal_Int16>(nValue);
106 break;
107 }
108 default:
109 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
110 break;
111 }
112 }
113 maComplexColor.addTransformation({ eTransformationType, nTransformationValue });
114 return this;
115 }
116 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
117 return nullptr;
118}
119
121{
122 if (nElement == mnRootElement)
123 {
125 {
127 SetInsert(true);
128 }
129 }
131}
132
133/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLEnumMapEntry< sal_Int16 > const pXML_ThemeColor_Enum[]
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
Definition: xmluconv.hxx:145
css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
XMLComplexColorContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, const XMLPropertyState &rProp, std::vector< XMLPropertyState > &rProps)
model::ComplexColor maComplexColor
void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
void setSchemeColor(ThemeColorType eType)
void setType(ColorType eType)
void addTransformation(Transformation const &rTransform)
ThemeColorType getSchemeType() const
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
float u
sal_Int16 nValue
uno::Reference< util::XComplexColor > createXComplexColor(model::ComplexColor const &rColor)
constexpr ThemeColorType convertToThemeColorType(sal_Int32 nIndex)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
@ XML_FOLLOWED_HYPERLINK
Definition: xmltoken.hxx:3508
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:140
css::uno::Any maValue
Definition: maptype.hxx:142
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
Definition: xmlictxt.hxx:120
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97