nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / draw / XMLGraphicsDefaultStyle.cxx
blob8795e0a7a64594b2b969850a2f387ff2482152cb
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <xmloff/XMLGraphicsDefaultStyle.hxx>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/frame/XModel.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <tools/color.hxx>
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/xmlnamespace.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>
37 #include <XMLShapePropertySetContext.hxx>
38 #include <algorithm>
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::beans;
44 using namespace ::com::sun::star::xml::sax;
46 using ::xmloff::token::IsXMLToken;
47 using ::xmloff::token::XML_TEXT_PROPERTIES;
48 using ::xmloff::token::XML_GRAPHIC_PROPERTIES;
49 using ::xmloff::token::XML_PARAGRAPH_PROPERTIES;
52 XMLGraphicsDefaultStyle::XMLGraphicsDefaultStyle( SvXMLImport& rImport, SvXMLStylesContext& rStyles )
53 : XMLPropStyleContext( rImport, rStyles, XmlStyleFamily::SD_GRAPHICS_ID, true )
57 XMLGraphicsDefaultStyle::~XMLGraphicsDefaultStyle()
61 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLGraphicsDefaultStyle::createFastChildContext(
62 sal_Int32 nElement,
63 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
65 SvXMLImportContextRef xContext;
67 if( IsTokenInNamespace(nElement, XML_NAMESPACE_STYLE) ||
68 IsTokenInNamespace(nElement, XML_NAMESPACE_LO_EXT) )
70 sal_Int32 nLocalName = nElement & TOKEN_MASK;
71 sal_uInt32 nFamily = 0;
72 if( nLocalName == XML_TEXT_PROPERTIES )
73 nFamily = XML_TYPE_PROP_TEXT;
74 else if( nLocalName == XML_PARAGRAPH_PROPERTIES )
75 nFamily = XML_TYPE_PROP_PARAGRAPH;
76 else if( nLocalName == XML_GRAPHIC_PROPERTIES )
77 nFamily = XML_TYPE_PROP_GRAPHIC;
78 if( nFamily )
80 rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() );
81 if( xImpPrMap.is() )
82 return new XMLShapePropertySetContext( GetImport(), nElement, xAttrList, nFamily, GetProperties(), xImpPrMap );
86 return XMLPropStyleContext::createFastChildContext( nElement, xAttrList );
89 namespace {
91 struct XMLPropertyByIndex {
92 sal_Int32 const m_nIndex;
93 explicit XMLPropertyByIndex(sal_Int32 const nIndex) : m_nIndex(nIndex) {}
94 bool operator()(XMLPropertyState const& rProp) {
95 return m_nIndex == rProp.mnIndex;
101 // This method is called for every default style
102 void XMLGraphicsDefaultStyle::SetDefaults()
104 Reference< XMultiServiceFactory > xFact( GetImport().GetModel(), UNO_QUERY );
105 if( !xFact.is() )
106 return;
108 Reference< XPropertySet > xDefaults( xFact->createInstance( "com.sun.star.drawing.Defaults" ), UNO_QUERY );
109 if( !xDefaults.is() )
110 return;
111 // SJ: #i114750#
112 bool bWordWrapDefault = true; // initializing with correct ODF fo:wrap-option default
113 sal_Int32 nUPD( 0 );
114 sal_Int32 nBuild( 0 );
115 const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
116 if ( bBuildIdFound && (
117 ((nUPD >= 600) && (nUPD < 700))
119 ((nUPD == 300) && (nBuild <= 9535))
121 ((nUPD > 300) && (nUPD <= 330))
123 bWordWrapDefault = false;
125 const OUString sTextWordWrap( "TextWordWrap" );
126 Reference< XPropertySetInfo > xInfo( xDefaults->getPropertySetInfo() );
127 if ( xInfo->hasPropertyByName( sTextWordWrap ) )
128 xDefaults->setPropertyValue( sTextWordWrap, Any( bWordWrapDefault ) );
130 if (GetImport().IsOOoXML()
131 && xInfo->hasPropertyByName("IsFollowingTextFlow"))
133 // OOo 1.x only supported "true" so that is the more appropriate
134 // default for OOoXML format documents.
135 xDefaults->setPropertyValue("IsFollowingTextFlow", uno::makeAny(true));
138 // NOTE: the only reason why it's legal to check "==" (not "<") against
139 // arbitrary versions here is that the default value of these attributes
140 // is not defined by ODF, therefore it is implementation-defined
141 // (and we of course must not override any attributes that are actually
142 // in the document, so check for that)
143 bool const bIsAOO4(
144 GetImport().getGeneratorVersion() >= SvXMLImport::AOO_40x
145 && GetImport().getGeneratorVersion() <= SvXMLImport::AOO_4x);
147 // fdo#75872: backward compatibility for pool defaults change
148 if (GetImport().isGeneratorVersionOlderThan(
149 SvXMLImport::AOO_40x, SvXMLImport::LO_42x)
150 // argh... it turns out that LO has also changed defaults for these
151 // since LO 4.0, and so even the _new_ AOO 4.0+ default needs
152 // special handling since AOO still does _not_ write it into the file
153 || bIsAOO4)
155 rtl::Reference<XMLPropertySetMapper> const pImpPrMap(
156 GetStyles()->GetImportPropertyMapper(GetFamily())
157 ->getPropertySetMapper());
158 sal_Int32 const nStrokeIndex(
159 pImpPrMap->GetEntryIndex(XML_NAMESPACE_SVG, "stroke-color", 0));
160 if (std::none_of(GetProperties().begin(), GetProperties().end(),
161 XMLPropertyByIndex(nStrokeIndex)))
163 Color const nStroke(
164 bIsAOO4 ? Color(128, 128, 128) : COL_BLACK);
165 xDefaults->setPropertyValue("LineColor", makeAny(nStroke));
167 Color const nFillColor( bIsAOO4
168 ? Color(0xCF, 0xE7, 0xF5) : Color(153, 204, 255));
169 sal_Int32 const nFillIndex(
170 pImpPrMap->GetEntryIndex(XML_NAMESPACE_DRAW, "fill-color", 0));
171 if (std::none_of(GetProperties().begin(), GetProperties().end(),
172 XMLPropertyByIndex(nFillIndex)))
174 xDefaults->setPropertyValue("FillColor", makeAny(nFillColor));
176 if (xInfo->hasPropertyByName("FillColor2"))
178 sal_Int32 const nFill2Index(pImpPrMap->GetEntryIndex(
179 XML_NAMESPACE_DRAW, "secondary-fill-color", 0));
180 if (std::none_of(GetProperties().begin(), GetProperties().end(),
181 XMLPropertyByIndex(nFill2Index)))
183 xDefaults->setPropertyValue("FillColor2", makeAny(sal_Int32(nFillColor)));
188 FillPropertySet( xDefaults );
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */