LCOV - code coverage report
Current view: top level - xmloff/source/draw - XMLGraphicsDefaultStyle.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 68 75 90.7 %
Date: 2014-04-11 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             : 
      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          42 : TYPEINIT1( XMLGraphicsDefaultStyle, XMLPropStyleContext );
      46             : 
      47         157 : XMLGraphicsDefaultStyle::XMLGraphicsDefaultStyle( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const Reference< XAttributeList >& xAttrList, SvXMLStylesContext& rStyles )
      48         157 : : XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, XML_STYLE_FAMILY_SD_GRAPHICS_ID, true )
      49             : {
      50         157 : }
      51             : 
      52         314 : XMLGraphicsDefaultStyle::~XMLGraphicsDefaultStyle()
      53             : {
      54         314 : }
      55             : 
      56         469 : SvXMLImportContext *XMLGraphicsDefaultStyle::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList > & xAttrList )
      57             : {
      58         469 :     SvXMLImportContext *pContext = 0;
      59             : 
      60         469 :     if( XML_NAMESPACE_STYLE == nPrefix )
      61             :     {
      62         469 :         sal_uInt32 nFamily = 0;
      63         469 :         if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
      64         157 :             nFamily = XML_TYPE_PROP_TEXT;
      65         312 :         else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
      66         157 :             nFamily = XML_TYPE_PROP_PARAGRAPH;
      67         155 :         else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
      68         155 :             nFamily = XML_TYPE_PROP_GRAPHIC;
      69         469 :         if( nFamily )
      70             :         {
      71         469 :             UniReference < SvXMLImportPropertyMapper > xImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() );
      72         469 :             if( xImpPrMap.is() )
      73         469 :                 pContext = new XMLShapePropertySetContext( GetImport(), nPrefix, rLocalName, xAttrList, nFamily, GetProperties(), xImpPrMap );
      74             :         }
      75             :     }
      76             : 
      77         469 :     if( !pContext )
      78           0 :         pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
      79             : 
      80         469 :     return pContext;
      81             : }
      82             : 
      83             : struct XMLPropertyByIndex {
      84             :     sal_Int32 const m_nIndex;
      85         124 :     XMLPropertyByIndex(sal_Int32 const nIndex) : m_nIndex(nIndex) {}
      86        1487 :     bool operator()(XMLPropertyState const& rProp) {
      87        1487 :         return m_nIndex == rProp.mnIndex;
      88             :     }
      89             : };
      90             : 
      91             : // This method is called for every default style
      92         157 : void XMLGraphicsDefaultStyle::SetDefaults()
      93             : {
      94         157 :     Reference< XMultiServiceFactory > xFact( GetImport().GetModel(), UNO_QUERY );
      95         157 :     if( !xFact.is() )
      96           0 :         return;
      97             : 
      98         314 :     Reference< XPropertySet > xDefaults( xFact->createInstance( "com.sun.star.drawing.Defaults" ), UNO_QUERY );
      99         157 :     if( !xDefaults.is() )
     100           0 :         return;
     101             :                                             // SJ: #i114750#
     102         157 :     sal_Bool bWordWrapDefault = sal_True;   // initializing with correct ODF fo:wrap-option default
     103         157 :     sal_Int32 nUPD( 0 );
     104         157 :     sal_Int32 nBuild( 0 );
     105         157 :     const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
     106         187 :     if ( bBuildIdFound && (
     107          30 :         ((nUPD >= 600) &&  (nUPD < 700))
     108          30 :         ||
     109          37 :         ((nUPD == 300) && (nBuild <= 9535))
     110          23 :         ||
     111          46 :         ((nUPD > 300) && (nUPD <= 330))
     112             :     ) )
     113          15 :         bWordWrapDefault = sal_False;
     114             : 
     115         314 :     const OUString sTextWordWrap( "TextWordWrap" );
     116         314 :     Reference< XPropertySetInfo > xInfo( xDefaults->getPropertySetInfo() );
     117         157 :     if ( xInfo->hasPropertyByName( sTextWordWrap ) )
     118         157 :         xDefaults->setPropertyValue( sTextWordWrap, Any( bWordWrapDefault ) );
     119             : 
     120         622 :     if (GetImport().IsOOoXML()
     121         477 :         && xInfo->hasPropertyByName("IsFollowingTextFlow"))
     122             :     {
     123             :         // OOo 1.x only supported "true" so that is the more appropriate
     124             :         // default for OOoXML format documents.
     125           1 :         xDefaults->setPropertyValue("IsFollowingTextFlow", uno::makeAny(true));
     126             :     }
     127             : 
     128             :     bool const bIsAOO4(
     129         157 :            GetImport().getGeneratorVersion() >= SvXMLImport::AOO_40x
     130         157 :         && GetImport().getGeneratorVersion() <= SvXMLImport::AOO_4x);
     131             : 
     132             :     // fdo#75872: backward compatibility for pool defaults change
     133         314 :     if (GetImport().isGeneratorVersionOlderThan(
     134         157 :                 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         157 :         || bIsAOO4)
     139             :     {
     140             :         UniReference<XMLPropertySetMapper> const pImpPrMap(
     141          62 :             GetStyles()->GetImportPropertyMapper(GetFamily())
     142          62 :                 ->getPropertySetMapper());
     143             :         sal_Int32 const nStrokeIndex(
     144          62 :             pImpPrMap->GetEntryIndex(XML_NAMESPACE_SVG, "stroke-color", 0));
     145         248 :         if (std::find_if(GetProperties().begin(), GetProperties().end(),
     146         248 :                     XMLPropertyByIndex(nStrokeIndex)) == GetProperties().end())
     147             :         {
     148             :             sal_Int32 const nStroke(
     149          23 :                     (bIsAOO4) ? RGB_COLORDATA(128, 128, 128) : COL_BLACK);
     150          23 :             xDefaults->setPropertyValue("LineColor", makeAny(nStroke));
     151             :         }
     152             :         sal_Int32 const nFillColor( (bIsAOO4)
     153          62 :             ? RGB_COLORDATA(0xCF, 0xE7, 0xF5) : RGB_COLORDATA(153, 204, 255));
     154             :         sal_Int32 const nFillIndex(
     155          62 :             pImpPrMap->GetEntryIndex(XML_NAMESPACE_DRAW, "fill-color", 0));
     156         248 :         if (std::find_if(GetProperties().begin(), GetProperties().end(),
     157         248 :                     XMLPropertyByIndex(nFillIndex)) == GetProperties().end())
     158             :         {
     159          23 :             xDefaults->setPropertyValue("FillColor", makeAny(nFillColor));
     160             :         }
     161          62 :         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          62 :         }
     171             :     }
     172             : 
     173         314 :     FillPropertySet( xDefaults );
     174             : }
     175             : 
     176             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10