LCOV - code coverage report
Current view: top level - xmloff/source/draw - XMLGraphicsDefaultStyle.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 68 75 90.7 %
Date: 2015-06-13 12:38:46 Functions: 10 12 83.3 %
Legend: Lines: hit not hit

          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             : #include <xmloff/families.hxx>
      31             : #include <xmloff/xmltypes.hxx>
      32             : #include <xmloff/maptype.hxx>
      33             : 
      34             : #include "XMLShapePropertySetContext.hxx"
      35             : #include <algorithm>
      36             : 
      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;
      42             : 
      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;
      47             : 
      48         132 : TYPEINIT1( XMLGraphicsDefaultStyle, XMLPropStyleContext );
      49             : 
      50         472 : XMLGraphicsDefaultStyle::XMLGraphicsDefaultStyle( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const Reference< XAttributeList >& xAttrList, SvXMLStylesContext& rStyles )
      51         472 : : XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, XML_STYLE_FAMILY_SD_GRAPHICS_ID, true )
      52             : {
      53         472 : }
      54             : 
      55         944 : XMLGraphicsDefaultStyle::~XMLGraphicsDefaultStyle()
      56             : {
      57         944 : }
      58             : 
      59        1197 : SvXMLImportContext *XMLGraphicsDefaultStyle::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList > & xAttrList )
      60             : {
      61        1197 :     SvXMLImportContext *pContext = 0;
      62             : 
      63        1197 :     if( XML_NAMESPACE_STYLE == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix )
      64             :     {
      65        1197 :         sal_uInt32 nFamily = 0;
      66        1197 :         if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
      67         390 :             nFamily = XML_TYPE_PROP_TEXT;
      68         807 :         else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
      69         390 :             nFamily = XML_TYPE_PROP_PARAGRAPH;
      70         417 :         else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
      71         417 :             nFamily = XML_TYPE_PROP_GRAPHIC;
      72        1197 :         if( nFamily )
      73             :         {
      74        1197 :             rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() );
      75        1197 :             if( xImpPrMap.is() )
      76        1197 :                 pContext = new XMLShapePropertySetContext( GetImport(), nPrefix, rLocalName, xAttrList, nFamily, GetProperties(), xImpPrMap );
      77             :         }
      78             :     }
      79             : 
      80        1197 :     if( !pContext )
      81           0 :         pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
      82             : 
      83        1197 :     return pContext;
      84             : }
      85             : 
      86             : struct XMLPropertyByIndex {
      87             :     sal_Int32 const m_nIndex;
      88         178 :     explicit XMLPropertyByIndex(sal_Int32 const nIndex) : m_nIndex(nIndex) {}
      89        2105 :     bool operator()(XMLPropertyState const& rProp) {
      90        2105 :         return m_nIndex == rProp.mnIndex;
      91             :     }
      92             : };
      93             : 
      94             : // This method is called for every default style
      95         472 : void XMLGraphicsDefaultStyle::SetDefaults()
      96             : {
      97         472 :     Reference< XMultiServiceFactory > xFact( GetImport().GetModel(), UNO_QUERY );
      98         472 :     if( !xFact.is() )
      99           0 :         return;
     100             : 
     101         944 :     Reference< XPropertySet > xDefaults( xFact->createInstance( "com.sun.star.drawing.Defaults" ), UNO_QUERY );
     102         472 :     if( !xDefaults.is() )
     103           0 :         return;
     104             :                                             // SJ: #i114750#
     105         472 :     bool bWordWrapDefault = true;   // initializing with correct ODF fo:wrap-option default
     106         472 :     sal_Int32 nUPD( 0 );
     107         472 :     sal_Int32 nBuild( 0 );
     108         472 :     const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
     109         532 :     if ( bBuildIdFound && (
     110          64 :         ((nUPD >= 600) &&  (nUPD < 700))
     111          56 :         ||
     112          63 :         ((nUPD == 300) && (nBuild <= 9535))
     113          49 :         ||
     114          98 :         ((nUPD > 300) && (nUPD <= 330))
     115             :     ) )
     116          21 :         bWordWrapDefault = false;
     117             : 
     118         944 :     const OUString sTextWordWrap( "TextWordWrap" );
     119         944 :     Reference< XPropertySetInfo > xInfo( xDefaults->getPropertySetInfo() );
     120         472 :     if ( xInfo->hasPropertyByName( sTextWordWrap ) )
     121         472 :         xDefaults->setPropertyValue( sTextWordWrap, Any( bWordWrapDefault ) );
     122             : 
     123        1881 :     if (GetImport().IsOOoXML()
     124        1423 :         && xInfo->hasPropertyByName("IsFollowingTextFlow"))
     125             :     {
     126             :         // OOo 1.x only supported "true" so that is the more appropriate
     127             :         // default for OOoXML format documents.
     128           2 :         xDefaults->setPropertyValue("IsFollowingTextFlow", uno::makeAny(true));
     129             :     }
     130             : 
     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)
     136             :     bool const bIsAOO4(
     137         472 :            GetImport().getGeneratorVersion() >= SvXMLImport::AOO_40x
     138         472 :         && GetImport().getGeneratorVersion() <= SvXMLImport::AOO_4x);
     139             : 
     140             :     // fdo#75872: backward compatibility for pool defaults change
     141         944 :     if (GetImport().isGeneratorVersionOlderThan(
     142         472 :                 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
     146         472 :         || bIsAOO4)
     147             :     {
     148             :         rtl::Reference<XMLPropertySetMapper> const pImpPrMap(
     149          89 :             GetStyles()->GetImportPropertyMapper(GetFamily())
     150          89 :                 ->getPropertySetMapper());
     151             :         sal_Int32 const nStrokeIndex(
     152          89 :             pImpPrMap->GetEntryIndex(XML_NAMESPACE_SVG, "stroke-color", 0));
     153         356 :         if (std::none_of(GetProperties().begin(), GetProperties().end(),
     154         356 :                          XMLPropertyByIndex(nStrokeIndex)))
     155             :         {
     156             :             sal_Int32 const nStroke(
     157          32 :                     (bIsAOO4) ? RGB_COLORDATA(128, 128, 128) : COL_BLACK);
     158          32 :             xDefaults->setPropertyValue("LineColor", makeAny(nStroke));
     159             :         }
     160             :         sal_Int32 const nFillColor( (bIsAOO4)
     161          89 :             ? RGB_COLORDATA(0xCF, 0xE7, 0xF5) : RGB_COLORDATA(153, 204, 255));
     162             :         sal_Int32 const nFillIndex(
     163          89 :             pImpPrMap->GetEntryIndex(XML_NAMESPACE_DRAW, "fill-color", 0));
     164         356 :         if (std::none_of(GetProperties().begin(), GetProperties().end(),
     165         356 :                          XMLPropertyByIndex(nFillIndex)))
     166             :         {
     167          32 :             xDefaults->setPropertyValue("FillColor", makeAny(nFillColor));
     168             :         }
     169          89 :         if (xInfo->hasPropertyByName("FillColor2"))
     170             :         {
     171             :             sal_Int32 const nFill2Index(pImpPrMap->GetEntryIndex(
     172           0 :                         XML_NAMESPACE_DRAW, "secondary-fill-color", 0));
     173           0 :             if (std::none_of(GetProperties().begin(), GetProperties().end(),
     174           0 :                              XMLPropertyByIndex(nFill2Index)))
     175             :             {
     176           0 :                 xDefaults->setPropertyValue("FillColor2", makeAny(nFillColor));
     177             :             }
     178          89 :         }
     179             :     }
     180             : 
     181         944 :     FillPropertySet( xDefaults );
     182             : }
     183             : 
     184             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11