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/lang/XMultiServiceFactory.hpp>
24 #include <tools/color.hxx>
26 #include <xmloff/xmlimp.hxx>
27 #include <xmloff/nmspmap.hxx>
28 #include <xmloff/xmlnmspe.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/families.hxx>
31 #include <xmloff/xmltypes.hxx>
32 #include <xmloff/maptype.hxx>
34 #include "XMLShapePropertySetContext.hxx"
37 using namespace ::com::sun::star
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star::beans
;
41 using namespace ::com::sun::star::xml::sax
;
43 using ::xmloff::token::IsXMLToken
;
44 using ::xmloff::token::XML_TEXT_PROPERTIES
;
45 using ::xmloff::token::XML_GRAPHIC_PROPERTIES
;
46 using ::xmloff::token::XML_PARAGRAPH_PROPERTIES
;
48 TYPEINIT1( XMLGraphicsDefaultStyle
, XMLPropStyleContext
);
50 XMLGraphicsDefaultStyle::XMLGraphicsDefaultStyle( SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
, const Reference
< XAttributeList
>& xAttrList
, SvXMLStylesContext
& rStyles
)
51 : XMLPropStyleContext( rImport
, nPrfx
, rLName
, xAttrList
, rStyles
, XML_STYLE_FAMILY_SD_GRAPHICS_ID
, true )
55 XMLGraphicsDefaultStyle::~XMLGraphicsDefaultStyle()
59 SvXMLImportContext
*XMLGraphicsDefaultStyle::CreateChildContext( sal_uInt16 nPrefix
, const OUString
& rLocalName
, const Reference
< XAttributeList
> & xAttrList
)
61 SvXMLImportContext
*pContext
= 0;
63 if( XML_NAMESPACE_STYLE
== nPrefix
|| XML_NAMESPACE_LO_EXT
== nPrefix
)
65 sal_uInt32 nFamily
= 0;
66 if( IsXMLToken( rLocalName
, XML_TEXT_PROPERTIES
) )
67 nFamily
= XML_TYPE_PROP_TEXT
;
68 else if( IsXMLToken( rLocalName
, XML_PARAGRAPH_PROPERTIES
) )
69 nFamily
= XML_TYPE_PROP_PARAGRAPH
;
70 else if( IsXMLToken( rLocalName
, XML_GRAPHIC_PROPERTIES
) )
71 nFamily
= XML_TYPE_PROP_GRAPHIC
;
74 rtl::Reference
< SvXMLImportPropertyMapper
> xImpPrMap
= GetStyles()->GetImportPropertyMapper( GetFamily() );
76 pContext
= new XMLShapePropertySetContext( GetImport(), nPrefix
, rLocalName
, xAttrList
, nFamily
, GetProperties(), xImpPrMap
);
81 pContext
= XMLPropStyleContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
86 struct XMLPropertyByIndex
{
87 sal_Int32
const m_nIndex
;
88 XMLPropertyByIndex(sal_Int32
const nIndex
) : m_nIndex(nIndex
) {}
89 bool operator()(XMLPropertyState
const& rProp
) {
90 return m_nIndex
== rProp
.mnIndex
;
94 // This method is called for every default style
95 void XMLGraphicsDefaultStyle::SetDefaults()
97 Reference
< XMultiServiceFactory
> xFact( GetImport().GetModel(), UNO_QUERY
);
101 Reference
< XPropertySet
> xDefaults( xFact
->createInstance( "com.sun.star.drawing.Defaults" ), UNO_QUERY
);
102 if( !xDefaults
.is() )
105 bool bWordWrapDefault
= true; // initializing with correct ODF fo:wrap-option default
107 sal_Int32
nBuild( 0 );
108 const bool bBuildIdFound
= GetImport().getBuildIds( nUPD
, nBuild
);
109 if ( bBuildIdFound
&& (
110 ((nUPD
>= 600) && (nUPD
< 700))
112 ((nUPD
== 300) && (nBuild
<= 9535))
114 ((nUPD
> 300) && (nUPD
<= 330))
116 bWordWrapDefault
= false;
118 const OUString
sTextWordWrap( "TextWordWrap" );
119 Reference
< XPropertySetInfo
> xInfo( xDefaults
->getPropertySetInfo() );
120 if ( xInfo
->hasPropertyByName( sTextWordWrap
) )
121 xDefaults
->setPropertyValue( sTextWordWrap
, Any( bWordWrapDefault
) );
123 if (GetImport().IsOOoXML()
124 && xInfo
->hasPropertyByName("IsFollowingTextFlow"))
126 // OOo 1.x only supported "true" so that is the more appropriate
127 // default for OOoXML format documents.
128 xDefaults
->setPropertyValue("IsFollowingTextFlow", uno::makeAny(true));
131 // NOTE: the only reason why it's legal to check "==" (not "<") against
132 // arbitrary versions here is that the default value of these attributes
133 // is not defined by ODF, therefore it is implementation-defined
134 // (and we of course must not override any attributes that are actually
135 // in the document, so check for that)
137 GetImport().getGeneratorVersion() >= SvXMLImport::AOO_40x
138 && GetImport().getGeneratorVersion() <= SvXMLImport::AOO_4x
);
140 // fdo#75872: backward compatibility for pool defaults change
141 if (GetImport().isGeneratorVersionOlderThan(
142 SvXMLImport::AOO_40x
, SvXMLImport::LO_42x
)
143 // argh... it turns out that LO has also changed defaults for these
144 // since LO 4.0, and so even the _new_ AOO 4.0+ default needs
145 // special handling since AOO still does _not_ write it into the file
148 rtl::Reference
<XMLPropertySetMapper
> const pImpPrMap(
149 GetStyles()->GetImportPropertyMapper(GetFamily())
150 ->getPropertySetMapper());
151 sal_Int32
const nStrokeIndex(
152 pImpPrMap
->GetEntryIndex(XML_NAMESPACE_SVG
, "stroke-color", 0));
153 if (std::none_of(GetProperties().begin(), GetProperties().end(),
154 XMLPropertyByIndex(nStrokeIndex
)))
156 sal_Int32
const nStroke(
157 (bIsAOO4
) ? RGB_COLORDATA(128, 128, 128) : COL_BLACK
);
158 xDefaults
->setPropertyValue("LineColor", makeAny(nStroke
));
160 sal_Int32
const nFillColor( (bIsAOO4
)
161 ? RGB_COLORDATA(0xCF, 0xE7, 0xF5) : RGB_COLORDATA(153, 204, 255));
162 sal_Int32
const nFillIndex(
163 pImpPrMap
->GetEntryIndex(XML_NAMESPACE_DRAW
, "fill-color", 0));
164 if (std::none_of(GetProperties().begin(), GetProperties().end(),
165 XMLPropertyByIndex(nFillIndex
)))
167 xDefaults
->setPropertyValue("FillColor", makeAny(nFillColor
));
169 if (xInfo
->hasPropertyByName("FillColor2"))
171 sal_Int32
const nFill2Index(pImpPrMap
->GetEntryIndex(
172 XML_NAMESPACE_DRAW
, "secondary-fill-color", 0));
173 if (std::none_of(GetProperties().begin(), GetProperties().end(),
174 XMLPropertyByIndex(nFill2Index
)))
176 xDefaults
->setPropertyValue("FillColor2", makeAny(nFillColor
));
181 FillPropertySet( xDefaults
);
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */