LibreOffice Module xmloff (master) 1
XMLGraphicsDefaultStyle.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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
21
22#include <com/sun/star/beans/XPropertySet.hpp>
23#include <com/sun/star/frame/XModel.hpp>
24#include <com/sun/star/lang/XMultiServiceFactory.hpp>
25
26#include <tools/color.hxx>
27
28#include <xmloff/xmlimp.hxx>
30#include <xmloff/xmltoken.hxx>
31#include <xmloff/families.hxx>
32#include <xmloff/xmltypes.hxx>
33#include <xmloff/maptype.hxx>
34#include <xmloff/xmlimppr.hxx>
35#include <xmloff/xmlprmap.hxx>
36
38#include <algorithm>
39
40using namespace ::com::sun::star;
41using namespace ::com::sun::star::uno;
42using namespace ::com::sun::star::lang;
43using namespace ::com::sun::star::beans;
44using namespace ::com::sun::star::xml::sax;
45
50
51
53: XMLPropStyleContext( rImport, rStyles, XmlStyleFamily::SD_GRAPHICS_ID, true )
54{
55}
56
58{
59}
60
61css::uno::Reference< css::xml::sax::XFastContextHandler > XMLGraphicsDefaultStyle::createFastChildContext(
62 sal_Int32 nElement,
63 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
64{
67 {
68 sal_Int32 nLocalName = nElement & TOKEN_MASK;
69 sal_uInt32 nFamily = 0;
70 if( nLocalName == XML_TEXT_PROPERTIES )
71 nFamily = XML_TYPE_PROP_TEXT;
72 else if( nLocalName == XML_PARAGRAPH_PROPERTIES )
74 else if( nLocalName == XML_GRAPHIC_PROPERTIES )
75 nFamily = XML_TYPE_PROP_GRAPHIC;
76 if( nFamily )
77 {
79 if( xImpPrMap.is() )
80 return new XMLShapePropertySetContext( GetImport(), nElement, xAttrList, nFamily, GetProperties(), xImpPrMap );
81 }
82 }
83
84 return XMLPropStyleContext::createFastChildContext( nElement, xAttrList );
85}
86
87namespace {
88
89struct XMLPropertyByIndex {
90 sal_Int32 const m_nIndex;
91 explicit XMLPropertyByIndex(sal_Int32 const nIndex) : m_nIndex(nIndex) {}
92 bool operator()(XMLPropertyState const& rProp) {
93 return m_nIndex == rProp.mnIndex;
94 }
95};
96
97}
98
99// This method is called for every default style
101{
102 Reference< XMultiServiceFactory > xFact( GetImport().GetModel(), UNO_QUERY );
103 if( !xFact.is() )
104 return;
105
106 Reference< XPropertySet > xDefaults( xFact->createInstance( "com.sun.star.drawing.Defaults" ), UNO_QUERY );
107 if( !xDefaults.is() )
108 return;
109 // SJ: #i114750#
110 bool bWordWrapDefault = true; // initializing with correct ODF fo:wrap-option default
111 sal_Int32 nUPD( 0 );
112 sal_Int32 nBuild( 0 );
113 const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
114 if ( bBuildIdFound && (
115 ((nUPD >= 600) && (nUPD < 700))
116 ||
117 ((nUPD == 300) && (nBuild <= 9535))
118 ||
119 ((nUPD > 300) && (nUPD <= 330))
120 ) )
121 bWordWrapDefault = false;
122
123 static const OUStringLiteral sTextWordWrap( u"TextWordWrap" );
124 Reference< XPropertySetInfo > xInfo( xDefaults->getPropertySetInfo() );
125 if ( xInfo->hasPropertyByName( sTextWordWrap ) )
126 xDefaults->setPropertyValue( sTextWordWrap, Any( bWordWrapDefault ) );
127
128 if (GetImport().IsOOoXML()
129 && xInfo->hasPropertyByName("IsFollowingTextFlow"))
130 {
131 // OOo 1.x only supported "true" so that is the more appropriate
132 // default for OOoXML format documents.
133 xDefaults->setPropertyValue("IsFollowingTextFlow", uno::Any(true));
134 }
135
136 // NOTE: the only reason why it's legal to check "==" (not "<") against
137 // arbitrary versions here is that the default value of these attributes
138 // is not defined by ODF, therefore it is implementation-defined
139 // (and we of course must not override any attributes that are actually
140 // in the document, so check for that)
141 bool const bIsAOO4(
142 GetImport().getGeneratorVersion() >= SvXMLImport::AOO_40x
143 && GetImport().getGeneratorVersion() <= SvXMLImport::AOO_4x);
144
145 // fdo#75872: backward compatibility for pool defaults change
146 if (GetImport().isGeneratorVersionOlderThan(
148 // argh... it turns out that LO has also changed defaults for these
149 // since LO 4.0, and so even the _new_ AOO 4.0+ default needs
150 // special handling since AOO still does _not_ write it into the file
151 || bIsAOO4)
152 {
154 GetStyles()->GetImportPropertyMapper(GetFamily())
155 ->getPropertySetMapper());
156 sal_Int32 const nStrokeIndex(
157 pImpPrMap->GetEntryIndex(XML_NAMESPACE_SVG, u"stroke-color", 0));
158 if (std::none_of(GetProperties().begin(), GetProperties().end(),
159 XMLPropertyByIndex(nStrokeIndex)))
160 {
161 Color const nStroke(
162 bIsAOO4 ? Color(128, 128, 128) : COL_BLACK);
163 xDefaults->setPropertyValue("LineColor", Any(nStroke));
164 }
165 Color const nFillColor( bIsAOO4
166 ? Color(0xCF, 0xE7, 0xF5) : Color(153, 204, 255));
167 sal_Int32 const nFillIndex(
168 pImpPrMap->GetEntryIndex(XML_NAMESPACE_DRAW, u"fill-color", 0));
169 if (std::none_of(GetProperties().begin(), GetProperties().end(),
170 XMLPropertyByIndex(nFillIndex)))
171 {
172 xDefaults->setPropertyValue("FillColor", Any(nFillColor));
173 }
174 if (xInfo->hasPropertyByName("FillColor2"))
175 {
176 sal_Int32 const nFill2Index(pImpPrMap->GetEntryIndex(
177 XML_NAMESPACE_DRAW, u"secondary-fill-color", 0));
178 if (std::none_of(GetProperties().begin(), GetProperties().end(),
179 XMLPropertyByIndex(nFill2Index)))
180 {
181 xDefaults->setPropertyValue("FillColor2", Any(sal_Int32(nFillColor)));
182 }
183 }
184 }
185
186 FillPropertySet( xDefaults );
187}
188
189/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
static const sal_uInt16 AOO_4x
Definition: xmlimp.hxx:550
bool getBuildIds(sal_Int32 &rUPD, sal_Int32 &rBuild) const
returns the upd and build id (f.e.
Definition: xmlimp.cxx:1827
static const sal_uInt16 LO_42x
Definition: xmlimp.hxx:554
static const sal_uInt16 AOO_40x
Definition: xmlimp.hxx:544
XmlStyleFamily GetFamily() const
Definition: xmlstyle.hxx:85
virtual rtl::Reference< SvXMLImportPropertyMapper > GetImportPropertyMapper(XmlStyleFamily nFamily) const
Definition: xmlstyle.cxx:518
virtual void SetDefaults() override
virtual ~XMLGraphicsDefaultStyle() override
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
XMLGraphicsDefaultStyle(SvXMLImport &rImport, SvXMLStylesContext &rStyles)
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
Definition: prstylei.cxx:222
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
Definition: prstylei.cxx:175
::std::vector< XMLPropertyState > & GetProperties()
Definition: prstylei.hxx:79
SvXMLStylesContext * GetStyles()
Definition: prstylei.hxx:78
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
float u
XmlStyleFamily
Definition: families.hxx:50
sal_Int32 nIndex
enumrange< T >::Iterator begin(enumrange< T >)
end
@ XML_PARAGRAPH_PROPERTIES
Definition: xmltoken.hxx:2627
@ XML_GRAPHIC_PROPERTIES
Definition: xmltoken.hxx:2622
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3581
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:141
sal_Int32 mnIndex
Definition: maptype.hxx:142
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
Definition: xmlimp.hxx:105
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:95
constexpr sal_uInt16 XML_NAMESPACE_DRAW
constexpr sal_uInt16 XML_NAMESPACE_SVG
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
constexpr sal_uInt16 XML_NAMESPACE_STYLE
#define XML_TYPE_PROP_GRAPHIC
Definition: xmltypes.hxx:94
#define XML_TYPE_PROP_PARAGRAPH
Definition: xmltypes.hxx:99
#define XML_TYPE_PROP_TEXT
Definition: xmltypes.hxx:98