Files
loongoffice/xmloff/source/text/XMLThemeColorContext.cxx
Tomaž Vajngerl 3eb53d327f xmloff: use XThemeColor in ODF, change the format for themes
Change the xmloff filter to use XThemeColor and the associated
proprties (CharColorThemeReference and FillColorThemeReference).

Change the ODF format for referencing a theme color - make it an
element instead a series of attributes on the *-properties style
element.

Change-Id: I0fa7d8ebffecc02897b7fe9824d6f1776ef36380
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144923
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
2023-01-13 13:44:09 +00:00

117 lines
4.2 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/config.h>
#include <sal/log.hxx>
#include <sax/tools/converter.hxx>
#include <xmloff/xmluconv.hxx>
#include <xmloff/namespacemap.hxx>
#include <xmloff/xmlnamespace.hxx>
#include <xmloff/xmlimp.hxx>
#include <xmloff/xmltoken.hxx>
#include <xmloff/xmlement.hxx>
#include <xmloff/xmlprhdl.hxx>
#include <XMLThemeColorContext.hxx>
using namespace css;
using namespace xmloff::token;
SvXMLEnumMapEntry<sal_Int16> const pXML_ThemeColor_Enum[]
= { { XML_NONE, -1 }, { XML_DK1, 0 }, { XML_LT1, 1 }, { XML_DK2, 2 },
{ XML_LT2, 3 }, { XML_ACCENT1, 4 }, { XML_ACCENT2, 5 }, { XML_ACCENT3, 6 },
{ XML_ACCENT4, 7 }, { XML_ACCENT5, 8 }, { XML_ACCENT6, 9 }, { XML_HLINK, 10 },
{ XML_FOLHLINK, 11 }, { XML_TOKEN_INVALID, 0 } };
XMLThemeColorContext::XMLThemeColorContext(
SvXMLImport& rImport, sal_Int32 nElement,
const uno::Reference<xml::sax::XFastAttributeList>& xAttrList, const XMLPropertyState& rProp,
std::vector<XMLPropertyState>& rProps)
: XMLElementPropertyContext(rImport, nElement, rProp, rProps)
, mnRootElement(nElement)
{
for (auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList))
{
switch (aIter.getToken())
{
case XML_ELEMENT(LO_EXT, XML_TYPE):
{
sal_Int16 nValue = -1;
if (SvXMLUnitConverter::convertEnum(nValue, aIter.toView(), pXML_ThemeColor_Enum))
{
aThemeColor.setType(model::convertToThemeColorType(nValue));
}
break;
}
default:
XMLOFF_WARN_UNKNOWN("xmloff", aIter);
break;
}
}
}
css::uno::Reference<css::xml::sax::XFastContextHandler>
XMLThemeColorContext::createFastChildContext(
sal_Int32 nElement, const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList)
{
if (nElement == XML_ELEMENT(LO_EXT, XML_TRANSFORMATION))
{
auto eTransformationType = model::TransformationType::Undefined;
sal_Int16 nTransformationValue = 0;
for (auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList))
{
switch (aIter.getToken())
{
case XML_ELEMENT(LO_EXT, XML_TYPE):
{
const OUString aValue = aIter.toString();
if (aValue == u"tint")
eTransformationType = model::TransformationType::Tint;
else if (aValue == u"shade")
eTransformationType = model::TransformationType::Shade;
else if (aValue == u"lumoff")
eTransformationType = model::TransformationType::LumOff;
else if (aValue == u"lummod")
eTransformationType = model::TransformationType::LumMod;
break;
}
case XML_ELEMENT(LO_EXT, XML_VALUE):
{
sal_Int32 nValue;
if (::sax::Converter::convertNumber(nValue, aIter.toView(), SHRT_MIN, SHRT_MAX))
nTransformationValue = static_cast<sal_Int16>(nValue);
break;
}
default:
XMLOFF_WARN_UNKNOWN("xmloff", aIter);
break;
}
}
aThemeColor.addTransformation({ eTransformationType, nTransformationValue });
return this;
}
XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
return nullptr;
}
void XMLThemeColorContext::endFastElement(sal_Int32 nElement)
{
if (nElement == mnRootElement)
{
if (aThemeColor.getType() != model::ThemeColorType::Unknown)
{
aProp.maValue <<= model::theme::createXThemeColor(aThemeColor);
SetInsert(true);
}
}
XMLElementPropertyContext::endFastElement(nElement);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */