1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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::XML_TEXT_PROPERTIES
;
47 using ::xmloff::token::XML_GRAPHIC_PROPERTIES
;
48 using ::xmloff::token::XML_PARAGRAPH_PROPERTIES
;
51 XMLGraphicsDefaultStyle::XMLGraphicsDefaultStyle( SvXMLImport
& rImport
, SvXMLStylesContext
& rStyles
)
52 : XMLPropStyleContext( rImport
, rStyles
, XmlStyleFamily::SD_GRAPHICS_ID
, true )
56 XMLGraphicsDefaultStyle::~XMLGraphicsDefaultStyle()
60 css::uno::Reference
< css::xml::sax::XFastContextHandler
> XMLGraphicsDefaultStyle::createFastChildContext(
62 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
64 if( IsTokenInNamespace(nElement
, XML_NAMESPACE_STYLE
) ||
65 IsTokenInNamespace(nElement
, XML_NAMESPACE_LO_EXT
) )
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
)
72 nFamily
= XML_TYPE_PROP_PARAGRAPH
;
73 else if( nLocalName
== XML_GRAPHIC_PROPERTIES
)
74 nFamily
= XML_TYPE_PROP_GRAPHIC
;
77 rtl::Reference
< SvXMLImportPropertyMapper
> xImpPrMap
= GetStyles()->GetImportPropertyMapper( GetFamily() );
79 return new XMLShapePropertySetContext( GetImport(), nElement
, xAttrList
, nFamily
, GetProperties(), xImpPrMap
);
83 return XMLPropStyleContext::createFastChildContext( nElement
, xAttrList
);
88 struct 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
;
98 // This method is called for every default style
99 void XMLGraphicsDefaultStyle::SetDefaults()
101 Reference
< XMultiServiceFactory
> xFact( GetImport().GetModel(), UNO_QUERY
);
105 Reference
< XPropertySet
> xDefaults( xFact
->createInstance( u
"com.sun.star.drawing.Defaults"_ustr
), UNO_QUERY
);
106 if( !xDefaults
.is() )
109 bool bWordWrapDefault
= true; // initializing with correct ODF fo:wrap-option default
111 sal_Int32
nBuild( 0 );
112 const bool bBuildIdFound
= GetImport().getBuildIds( nUPD
, nBuild
);
113 if ( bBuildIdFound
&& (
114 ((nUPD
>= 600) && (nUPD
< 700))
116 ((nUPD
== 300) && (nBuild
<= 9535))
118 ((nUPD
> 300) && (nUPD
<= 330))
120 bWordWrapDefault
= false;
122 static constexpr OUString
sTextWordWrap( u
"TextWordWrap"_ustr
);
123 Reference
< XPropertySetInfo
> xInfo( xDefaults
->getPropertySetInfo() );
124 if ( xInfo
->hasPropertyByName( sTextWordWrap
) )
125 xDefaults
->setPropertyValue( sTextWordWrap
, Any( bWordWrapDefault
) );
127 if (GetImport().IsOOoXML()
128 && xInfo
->hasPropertyByName(u
"IsFollowingTextFlow"_ustr
))
130 // OOo 1.x only supported "true" so that is the more appropriate
131 // default for OOoXML format documents.
132 xDefaults
->setPropertyValue(u
"IsFollowingTextFlow"_ustr
, uno::Any(true));
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)
141 GetImport().getGeneratorVersion() >= SvXMLImport::AOO_40x
142 && GetImport().getGeneratorVersion() <= SvXMLImport::AOO_4x
);
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
152 rtl::Reference
<XMLPropertySetMapper
> const pImpPrMap(
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
)))
161 bIsAOO4
? Color(128, 128, 128) : COL_BLACK
);
162 xDefaults
->setPropertyValue(u
"LineColor"_ustr
, Any(nStroke
));
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
)))
171 xDefaults
->setPropertyValue(u
"FillColor"_ustr
, Any(nFillColor
));
173 if (xInfo
->hasPropertyByName(u
"FillColor2"_ustr
))
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
)))
180 xDefaults
->setPropertyValue(u
"FillColor2"_ustr
, Any(sal_Int32(nFillColor
)));
185 FillPropertySet( xDefaults
);
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */