Line data Source code
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 :
20 : #include <xmloff/XMLGraphicsDefaultStyle.hxx>
21 :
22 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
23 :
24 : #include <tools/color.hxx>
25 :
26 : #include <xmloff/xmlimp.hxx>
27 : #include <xmloff/nmspmap.hxx>
28 : #include <xmloff/xmlnmspe.hxx>
29 : #include <xmloff/xmltoken.hxx>
30 :
31 : #include <xmloff/families.hxx>
32 : #include "XMLShapePropertySetContext.hxx"
33 :
34 : using namespace ::com::sun::star;
35 : using namespace ::com::sun::star::uno;
36 : using namespace ::com::sun::star::lang;
37 : using namespace ::com::sun::star::beans;
38 : using namespace ::com::sun::star::xml::sax;
39 :
40 : using ::xmloff::token::IsXMLToken;
41 : using ::xmloff::token::XML_TEXT_PROPERTIES;
42 : using ::xmloff::token::XML_GRAPHIC_PROPERTIES;
43 : using ::xmloff::token::XML_PARAGRAPH_PROPERTIES;
44 :
45 0 : TYPEINIT1( XMLGraphicsDefaultStyle, XMLPropStyleContext );
46 :
47 0 : XMLGraphicsDefaultStyle::XMLGraphicsDefaultStyle( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const Reference< XAttributeList >& xAttrList, SvXMLStylesContext& rStyles )
48 0 : : XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, XML_STYLE_FAMILY_SD_GRAPHICS_ID, true )
49 : {
50 0 : }
51 :
52 0 : XMLGraphicsDefaultStyle::~XMLGraphicsDefaultStyle()
53 : {
54 0 : }
55 :
56 0 : SvXMLImportContext *XMLGraphicsDefaultStyle::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList > & xAttrList )
57 : {
58 0 : SvXMLImportContext *pContext = 0;
59 :
60 0 : if( XML_NAMESPACE_STYLE == nPrefix )
61 : {
62 0 : sal_uInt32 nFamily = 0;
63 0 : if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
64 0 : nFamily = XML_TYPE_PROP_TEXT;
65 0 : else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
66 0 : nFamily = XML_TYPE_PROP_PARAGRAPH;
67 0 : else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
68 0 : nFamily = XML_TYPE_PROP_GRAPHIC;
69 0 : if( nFamily )
70 : {
71 0 : UniReference < SvXMLImportPropertyMapper > xImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() );
72 0 : if( xImpPrMap.is() )
73 0 : pContext = new XMLShapePropertySetContext( GetImport(), nPrefix, rLocalName, xAttrList, nFamily, GetProperties(), xImpPrMap );
74 : }
75 : }
76 :
77 0 : if( !pContext )
78 0 : pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
79 :
80 0 : return pContext;
81 : }
82 :
83 : struct XMLPropertyByIndex {
84 : sal_Int32 const m_nIndex;
85 0 : XMLPropertyByIndex(sal_Int32 const nIndex) : m_nIndex(nIndex) {}
86 0 : bool operator()(XMLPropertyState const& rProp) {
87 0 : return m_nIndex == rProp.mnIndex;
88 : }
89 : };
90 :
91 : // This method is called for every default style
92 0 : void XMLGraphicsDefaultStyle::SetDefaults()
93 : {
94 0 : Reference< XMultiServiceFactory > xFact( GetImport().GetModel(), UNO_QUERY );
95 0 : if( !xFact.is() )
96 0 : return;
97 :
98 0 : Reference< XPropertySet > xDefaults( xFact->createInstance( "com.sun.star.drawing.Defaults" ), UNO_QUERY );
99 0 : if( !xDefaults.is() )
100 0 : return;
101 : // SJ: #i114750#
102 0 : sal_Bool bWordWrapDefault = sal_True; // initializing with correct ODF fo:wrap-option default
103 0 : sal_Int32 nUPD( 0 );
104 0 : sal_Int32 nBuild( 0 );
105 0 : const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
106 0 : if ( bBuildIdFound && (
107 0 : ((nUPD >= 600) && (nUPD < 700))
108 0 : ||
109 0 : ((nUPD == 300) && (nBuild <= 9535))
110 0 : ||
111 0 : ((nUPD > 300) && (nUPD <= 330))
112 : ) )
113 0 : bWordWrapDefault = sal_False;
114 :
115 0 : const OUString sTextWordWrap( "TextWordWrap" );
116 0 : Reference< XPropertySetInfo > xInfo( xDefaults->getPropertySetInfo() );
117 0 : if ( xInfo->hasPropertyByName( sTextWordWrap ) )
118 0 : xDefaults->setPropertyValue( sTextWordWrap, Any( bWordWrapDefault ) );
119 :
120 0 : if (GetImport().IsOOoXML()
121 0 : && xInfo->hasPropertyByName("IsFollowingTextFlow"))
122 : {
123 : // OOo 1.x only supported "true" so that is the more appropriate
124 : // default for OOoXML format documents.
125 0 : xDefaults->setPropertyValue("IsFollowingTextFlow", uno::makeAny(true));
126 : }
127 :
128 : bool const bIsAOO4(
129 0 : GetImport().getGeneratorVersion() >= SvXMLImport::AOO_40x
130 0 : && GetImport().getGeneratorVersion() <= SvXMLImport::AOO_4x);
131 :
132 : // fdo#75872: backward compatibility for pool defaults change
133 0 : if (GetImport().isGeneratorVersionOlderThan(
134 0 : SvXMLImport::AOO_40x, SvXMLImport::LO_42x)
135 : // argh... it turns out that LO has also changed defaults for these
136 : // since LO 4.0, and so even the _new_ AOO 4.0+ default needs
137 : // special handling since AOO still does _not_ write it into the file
138 0 : || bIsAOO4)
139 : {
140 : UniReference<XMLPropertySetMapper> const pImpPrMap(
141 0 : GetStyles()->GetImportPropertyMapper(GetFamily())
142 0 : ->getPropertySetMapper());
143 : sal_Int32 const nStrokeIndex(
144 0 : pImpPrMap->GetEntryIndex(XML_NAMESPACE_SVG, "stroke-color", 0));
145 0 : if (std::find_if(GetProperties().begin(), GetProperties().end(),
146 0 : XMLPropertyByIndex(nStrokeIndex)) == GetProperties().end())
147 : {
148 : sal_Int32 const nStroke(
149 0 : (bIsAOO4) ? RGB_COLORDATA(128, 128, 128) : COL_BLACK);
150 0 : xDefaults->setPropertyValue("LineColor", makeAny(nStroke));
151 : }
152 : sal_Int32 const nFillColor( (bIsAOO4)
153 0 : ? RGB_COLORDATA(0xCF, 0xE7, 0xF5) : RGB_COLORDATA(153, 204, 255));
154 : sal_Int32 const nFillIndex(
155 0 : pImpPrMap->GetEntryIndex(XML_NAMESPACE_DRAW, "fill-color", 0));
156 0 : if (std::find_if(GetProperties().begin(), GetProperties().end(),
157 0 : XMLPropertyByIndex(nFillIndex)) == GetProperties().end())
158 : {
159 0 : xDefaults->setPropertyValue("FillColor", makeAny(nFillColor));
160 : }
161 0 : if (xInfo->hasPropertyByName("FillColor2"))
162 : {
163 : sal_Int32 const nFill2Index(pImpPrMap->GetEntryIndex(
164 0 : XML_NAMESPACE_DRAW, "secondary-fill-color", 0));
165 0 : if (std::find_if(GetProperties().begin(), GetProperties().end(),
166 0 : XMLPropertyByIndex(nFill2Index)) == GetProperties().end())
167 : {
168 0 : xDefaults->setPropertyValue("FillColor2", makeAny(nFillColor));
169 : }
170 0 : }
171 : }
172 :
173 0 : FillPropertySet( xDefaults );
174 : }
175 :
176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|