LCOV - code coverage report
Current view: top level - xmloff/source/draw - XMLGraphicsDefaultStyle.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 68 75 90.7 %
Date: 2014-11-03 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             : 
      36             : using namespace ::com::sun::star;
      37             : using namespace ::com::sun::star::uno;
      38             : using namespace ::com::sun::star::lang;
      39             : using namespace ::com::sun::star::beans;
      40             : using namespace ::com::sun::star::xml::sax;
      41             : 
      42             : using ::xmloff::token::IsXMLToken;
      43             : using ::xmloff::token::XML_TEXT_PROPERTIES;
      44             : using ::xmloff::token::XML_GRAPHIC_PROPERTIES;
      45             : using ::xmloff::token::XML_PARAGRAPH_PROPERTIES;
      46             : 
      47         108 : TYPEINIT1( XMLGraphicsDefaultStyle, XMLPropStyleContext );
      48             : 
      49         578 : XMLGraphicsDefaultStyle::XMLGraphicsDefaultStyle( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const Reference< XAttributeList >& xAttrList, SvXMLStylesContext& rStyles )
      50         578 : : XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, XML_STYLE_FAMILY_SD_GRAPHICS_ID, true )
      51             : {
      52         578 : }
      53             : 
      54        1156 : XMLGraphicsDefaultStyle::~XMLGraphicsDefaultStyle()
      55             : {
      56        1156 : }
      57             : 
      58        1312 : SvXMLImportContext *XMLGraphicsDefaultStyle::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList > & xAttrList )
      59             : {
      60        1312 :     SvXMLImportContext *pContext = 0;
      61             : 
      62        1312 :     if( XML_NAMESPACE_STYLE == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix )
      63             :     {
      64        1312 :         sal_uInt32 nFamily = 0;
      65        1312 :         if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
      66         420 :             nFamily = XML_TYPE_PROP_TEXT;
      67         892 :         else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
      68         420 :             nFamily = XML_TYPE_PROP_PARAGRAPH;
      69         472 :         else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
      70         472 :             nFamily = XML_TYPE_PROP_GRAPHIC;
      71        1312 :         if( nFamily )
      72             :         {
      73        1312 :             rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() );
      74        1312 :             if( xImpPrMap.is() )
      75        1312 :                 pContext = new XMLShapePropertySetContext( GetImport(), nPrefix, rLocalName, xAttrList, nFamily, GetProperties(), xImpPrMap );
      76             :         }
      77             :     }
      78             : 
      79        1312 :     if( !pContext )
      80           0 :         pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
      81             : 
      82        1312 :     return pContext;
      83             : }
      84             : 
      85             : struct XMLPropertyByIndex {
      86             :     sal_Int32 const m_nIndex;
      87         292 :     XMLPropertyByIndex(sal_Int32 const nIndex) : m_nIndex(nIndex) {}
      88        3466 :     bool operator()(XMLPropertyState const& rProp) {
      89        3466 :         return m_nIndex == rProp.mnIndex;
      90             :     }
      91             : };
      92             : 
      93             : // This method is called for every default style
      94         578 : void XMLGraphicsDefaultStyle::SetDefaults()
      95             : {
      96         578 :     Reference< XMultiServiceFactory > xFact( GetImport().GetModel(), UNO_QUERY );
      97         578 :     if( !xFact.is() )
      98           0 :         return;
      99             : 
     100        1156 :     Reference< XPropertySet > xDefaults( xFact->createInstance( "com.sun.star.drawing.Defaults" ), UNO_QUERY );
     101         578 :     if( !xDefaults.is() )
     102           0 :         return;
     103             :                                             // SJ: #i114750#
     104         578 :     bool bWordWrapDefault = true;   // initializing with correct ODF fo:wrap-option default
     105         578 :     sal_Int32 nUPD( 0 );
     106         578 :     sal_Int32 nBuild( 0 );
     107         578 :     const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
     108         658 :     if ( bBuildIdFound && (
     109          80 :         ((nUPD >= 600) &&  (nUPD < 700))
     110          80 :         ||
     111          94 :         ((nUPD == 300) && (nBuild <= 9535))
     112          66 :         ||
     113         132 :         ((nUPD > 300) && (nUPD <= 330))
     114             :     ) )
     115          32 :         bWordWrapDefault = false;
     116             : 
     117        1156 :     const OUString sTextWordWrap( "TextWordWrap" );
     118        1156 :     Reference< XPropertySetInfo > xInfo( xDefaults->getPropertySetInfo() );
     119         578 :     if ( xInfo->hasPropertyByName( sTextWordWrap ) )
     120         578 :         xDefaults->setPropertyValue( sTextWordWrap, Any( bWordWrapDefault ) );
     121             : 
     122        2300 :     if (GetImport().IsOOoXML()
     123        1746 :         && xInfo->hasPropertyByName("IsFollowingTextFlow"))
     124             :     {
     125             :         // OOo 1.x only supported "true" so that is the more appropriate
     126             :         // default for OOoXML format documents.
     127           2 :         xDefaults->setPropertyValue("IsFollowingTextFlow", uno::makeAny(true));
     128             :     }
     129             : 
     130             :     // NOTE: the only reason why it's legal to check "==" (not "<") against
     131             :     // arbitrary versions here is that the default value of these attributes
     132             :     // is not defined by ODF, therefore it is implementation-defined
     133             :     // (and we of course must not override any attributes that are actually
     134             :     // in the document, so check for that)
     135             :     bool const bIsAOO4(
     136         578 :            GetImport().getGeneratorVersion() >= SvXMLImport::AOO_40x
     137         578 :         && GetImport().getGeneratorVersion() <= SvXMLImport::AOO_4x);
     138             : 
     139             :     // fdo#75872: backward compatibility for pool defaults change
     140        1156 :     if (GetImport().isGeneratorVersionOlderThan(
     141         578 :                 SvXMLImport::AOO_40x, SvXMLImport::LO_42x)
     142             :         // argh... it turns out that LO has also changed defaults for these
     143             :         // since LO 4.0, and so even the _new_ AOO 4.0+ default needs
     144             :         // special handling since AOO still does _not_ write it into the file
     145         578 :         || bIsAOO4)
     146             :     {
     147             :         rtl::Reference<XMLPropertySetMapper> const pImpPrMap(
     148         146 :             GetStyles()->GetImportPropertyMapper(GetFamily())
     149         146 :                 ->getPropertySetMapper());
     150             :         sal_Int32 const nStrokeIndex(
     151         146 :             pImpPrMap->GetEntryIndex(XML_NAMESPACE_SVG, "stroke-color", 0));
     152         584 :         if (std::find_if(GetProperties().begin(), GetProperties().end(),
     153         584 :                     XMLPropertyByIndex(nStrokeIndex)) == GetProperties().end())
     154             :         {
     155             :             sal_Int32 const nStroke(
     156          52 :                     (bIsAOO4) ? RGB_COLORDATA(128, 128, 128) : COL_BLACK);
     157          52 :             xDefaults->setPropertyValue("LineColor", makeAny(nStroke));
     158             :         }
     159             :         sal_Int32 const nFillColor( (bIsAOO4)
     160         146 :             ? RGB_COLORDATA(0xCF, 0xE7, 0xF5) : RGB_COLORDATA(153, 204, 255));
     161             :         sal_Int32 const nFillIndex(
     162         146 :             pImpPrMap->GetEntryIndex(XML_NAMESPACE_DRAW, "fill-color", 0));
     163         584 :         if (std::find_if(GetProperties().begin(), GetProperties().end(),
     164         584 :                     XMLPropertyByIndex(nFillIndex)) == GetProperties().end())
     165             :         {
     166          52 :             xDefaults->setPropertyValue("FillColor", makeAny(nFillColor));
     167             :         }
     168         146 :         if (xInfo->hasPropertyByName("FillColor2"))
     169             :         {
     170             :             sal_Int32 const nFill2Index(pImpPrMap->GetEntryIndex(
     171           0 :                         XML_NAMESPACE_DRAW, "secondary-fill-color", 0));
     172           0 :             if (std::find_if(GetProperties().begin(), GetProperties().end(),
     173           0 :                     XMLPropertyByIndex(nFill2Index)) == GetProperties().end())
     174             :             {
     175           0 :                 xDefaults->setPropertyValue("FillColor2", makeAny(nFillColor));
     176             :             }
     177         146 :         }
     178             :     }
     179             : 
     180        1156 :     FillPropertySet( xDefaults );
     181             : }
     182             : 
     183             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10