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
49
50
52: XMLPropStyleContext( rImport, rStyles, XmlStyleFamily::SD_GRAPHICS_ID, true )
53{
54}
55
57{
58}
59
60css::uno::Reference< css::xml::sax::XFastContextHandler > XMLGraphicsDefaultStyle::createFastChildContext(
61 sal_Int32 nElement,
62 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
63{
66 {
67 sal_Int32 nLocalName = nElement & TOKEN_MASK;
68 sal_uInt32 nFamily = 0;
69 if( nLocalName == XML_TEXT_PROPERTIES )
70 nFamily = XML_TYPE_PROP_TEXT;
71 else if( nLocalName == XML_PARAGRAPH_PROPERTIES )
73 else if( nLocalName == XML_GRAPHIC_PROPERTIES )
74 nFamily = XML_TYPE_PROP_GRAPHIC;
75 if( nFamily )
76 {
78 if( xImpPrMap.is() )
79 return new XMLShapePropertySetContext( GetImport(), nElement, xAttrList, nFamily, GetProperties(), xImpPrMap );
80 }
81 }
82
83 return XMLPropStyleContext::createFastChildContext( nElement, xAttrList );
84}
85
86namespace {
87
88struct XMLPropertyByIndex {
89 sal_Int32 const m_nIndex;
90 explicit XMLPropertyByIndex(sal_Int32 const nIndex) : m_nIndex(nIndex) {}
91 bool operator()(XMLPropertyState const& rProp) {
92 return m_nIndex == rProp.mnIndex;
93 }
94};
95
96}
97
98// This method is called for every default style
100{
101 Reference< XMultiServiceFactory > xFact( GetImport().GetModel(), UNO_QUERY );
102 if( !xFact.is() )
103 return;
104
105 Reference< XPropertySet > xDefaults( xFact->createInstance( "com.sun.star.drawing.Defaults" ), UNO_QUERY );
106 if( !xDefaults.is() )
107 return;
108 // SJ: #i114750#
109 bool bWordWrapDefault = true; // initializing with correct ODF fo:wrap-option default
110 sal_Int32 nUPD( 0 );
111 sal_Int32 nBuild( 0 );
112 const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
113 if ( bBuildIdFound && (
114 ((nUPD >= 600) && (nUPD < 700))
115 ||
116 ((nUPD == 300) && (nBuild <= 9535))
117 ||
118 ((nUPD > 300) && (nUPD <= 330))
119 ) )
120 bWordWrapDefault = false;
121
122 static constexpr OUStringLiteral sTextWordWrap( u"TextWordWrap" );
123 Reference< XPropertySetInfo > xInfo( xDefaults->getPropertySetInfo() );
124 if ( xInfo->hasPropertyByName( sTextWordWrap ) )
125 xDefaults->setPropertyValue( sTextWordWrap, Any( bWordWrapDefault ) );
126
127 if (GetImport().IsOOoXML()
128 && xInfo->hasPropertyByName("IsFollowingTextFlow"))
129 {
130 // OOo 1.x only supported "true" so that is the more appropriate
131 // default for OOoXML format documents.
132 xDefaults->setPropertyValue("IsFollowingTextFlow", uno::Any(true));
133 }
134
135 // NOTE: the only reason why it's legal to check "==" (not "<") against
136 // arbitrary versions here is that the default value of these attributes
137 // is not defined by ODF, therefore it is implementation-defined
138 // (and we of course must not override any attributes that are actually
139 // in the document, so check for that)
140 bool const bIsAOO4(
141 GetImport().getGeneratorVersion() >= SvXMLImport::AOO_40x
142 && GetImport().getGeneratorVersion() <= SvXMLImport::AOO_4x);
143
144 // fdo#75872: backward compatibility for pool defaults change
145 if (GetImport().isGeneratorVersionOlderThan(
146 SvXMLImport::AOO_40x, SvXMLImport::LO_42x)
147 // argh... it turns out that LO has also changed defaults for these
148 // since LO 4.0, and so even the _new_ AOO 4.0+ default needs
149 // special handling since AOO still does _not_ write it into the file
150 || bIsAOO4)
151 {
153 GetStyles()->GetImportPropertyMapper(GetFamily())
154 ->getPropertySetMapper());
155 sal_Int32 const nStrokeIndex(
156 pImpPrMap->GetEntryIndex(XML_NAMESPACE_SVG, u"stroke-color", 0));
157 if (std::none_of(GetProperties().begin(), GetProperties().end(),
158 XMLPropertyByIndex(nStrokeIndex)))
159 {
160 Color const nStroke(
161 bIsAOO4 ? Color(128, 128, 128) : COL_BLACK);
162 xDefaults->setPropertyValue("LineColor", Any(nStroke));
163 }
164 Color const nFillColor( bIsAOO4
165 ? Color(0xCF, 0xE7, 0xF5) : Color(153, 204, 255));
166 sal_Int32 const nFillIndex(
167 pImpPrMap->GetEntryIndex(XML_NAMESPACE_DRAW, u"fill-color", 0));
168 if (std::none_of(GetProperties().begin(), GetProperties().end(),
169 XMLPropertyByIndex(nFillIndex)))
170 {
171 xDefaults->setPropertyValue("FillColor", Any(nFillColor));
172 }
173 if (xInfo->hasPropertyByName("FillColor2"))
174 {
175 sal_Int32 const nFill2Index(pImpPrMap->GetEntryIndex(
176 XML_NAMESPACE_DRAW, u"secondary-fill-color", 0));
177 if (std::none_of(GetProperties().begin(), GetProperties().end(),
178 XMLPropertyByIndex(nFill2Index)))
179 {
180 xDefaults->setPropertyValue("FillColor2", Any(sal_Int32(nFillColor)));
181 }
182 }
183 }
184
185 FillPropertySet( xDefaults );
186}
187
188/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
XmlStyleFamily GetFamily() const
Definition: xmlstyle.hxx:85
virtual rtl::Reference< SvXMLImportPropertyMapper > GetImportPropertyMapper(XmlStyleFamily nFamily) const
Definition: xmlstyle.cxx:522
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:2634
@ XML_GRAPHIC_PROPERTIES
Definition: xmltoken.hxx:2629
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:140
sal_Int32 mnIndex
Definition: maptype.hxx:141
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
Definition: xmlimp.hxx:104
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:94
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