LCOV - code coverage report
Current view: top level - oox/source/drawingml - textcharacterproperties.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 109 111 98.2 %
Date: 2014-11-03 Functions: 7 7 100.0 %
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 "drawingml/textcharacterproperties.hxx"
      21             : #include <com/sun/star/lang/Locale.hpp>
      22             : #include <com/sun/star/awt/FontSlant.hpp>
      23             : #include <com/sun/star/awt/FontWeight.hpp>
      24             : #include <i18nlangtag/languagetag.hxx>
      25             : #include <editeng/escapementitem.hxx>
      26             : #include "oox/helper/helper.hxx"
      27             : #include "oox/helper/propertyset.hxx"
      28             : #include "oox/core/xmlfilterbase.hxx"
      29             : #include "oox/drawingml/drawingmltypes.hxx"
      30             : #include "oox/token/tokens.hxx"
      31             : 
      32             : using ::oox::core::XmlFilterBase;
      33             : using namespace ::com::sun::star;
      34             : using namespace ::com::sun::star::uno;
      35             : using namespace ::com::sun::star::beans;
      36             : 
      37             : namespace oox {
      38             : namespace drawingml {
      39             : 
      40      122804 : void TextCharacterProperties::assignUsed( const TextCharacterProperties& rSourceProps )
      41             : {
      42             :     // overwrite all properties exisiting in rSourceProps
      43      122804 :     maHyperlinkPropertyMap.assignUsed( rSourceProps.maHyperlinkPropertyMap );
      44      122804 :     maLatinFont.assignIfUsed( rSourceProps.maLatinFont );
      45      122804 :     maLatinThemeFont.assignIfUsed( rSourceProps.maLatinThemeFont );
      46      122804 :     maAsianFont.assignIfUsed( rSourceProps.maAsianFont );
      47      122804 :     maAsianThemeFont.assignIfUsed( rSourceProps.maAsianThemeFont );
      48      122804 :     maComplexFont.assignIfUsed( rSourceProps.maComplexFont );
      49      122804 :     maComplexThemeFont.assignIfUsed( rSourceProps.maComplexThemeFont );
      50      122804 :     maSymbolFont.assignIfUsed( rSourceProps.maSymbolFont );
      51      122804 :     maCharColor.assignIfUsed( rSourceProps.maCharColor );
      52      122804 :     maHighlightColor.assignIfUsed( rSourceProps.maHighlightColor );
      53      122804 :     maUnderlineColor.assignIfUsed( rSourceProps.maUnderlineColor );
      54      122804 :     moHeight.assignIfUsed( rSourceProps.moHeight );
      55      122804 :     moSpacing.assignIfUsed( rSourceProps.moSpacing );
      56      122804 :     moUnderline.assignIfUsed( rSourceProps.moUnderline );
      57      122804 :     moBaseline.assignIfUsed( rSourceProps.moBaseline );
      58      122804 :     moStrikeout.assignIfUsed( rSourceProps.moStrikeout );
      59      122804 :     moCaseMap.assignIfUsed( rSourceProps.moCaseMap );
      60      122804 :     moBold.assignIfUsed( rSourceProps.moBold );
      61      122804 :     moItalic.assignIfUsed( rSourceProps.moItalic );
      62      122804 :     moUnderlineLineFollowText.assignIfUsed( rSourceProps.moUnderlineLineFollowText );
      63      122804 :     moUnderlineFillFollowText.assignIfUsed( rSourceProps.moUnderlineFillFollowText );
      64             : 
      65      122804 :     maTextEffectsProperties = rSourceProps.maTextEffectsProperties;
      66      122804 :     maGradientProps.assignUsed( rSourceProps.maGradientProps );
      67      122804 : }
      68             : 
      69        5928 : void TextCharacterProperties::pushToPropMap( PropertyMap& rPropMap, const XmlFilterBase& rFilter, bool bUseOptional ) const
      70             : {
      71        5928 :     OUString aFontName;
      72        5928 :     sal_Int16 nFontPitch = 0;
      73        5928 :     sal_Int16 nFontFamily = 0;
      74             : 
      75        5928 :     bool bRet = maLatinFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
      76        5928 :     if (!bRet)
      77             :         // In case there is no direct font, try to look it up as a theme reference.
      78         854 :         bRet = maLatinThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
      79        5928 :     if (bRet)
      80             :     {
      81        5086 :         rPropMap.setProperty( PROP_CharFontName, aFontName);
      82        5086 :         rPropMap.setProperty( PROP_CharFontPitch, nFontPitch);
      83        5086 :         rPropMap.setProperty( PROP_CharFontFamily, nFontFamily);
      84             :     }
      85             : 
      86        5928 :     bRet = maAsianFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
      87        5928 :     if (!bRet)
      88        5786 :         bRet = maAsianThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
      89        5928 :     if (bRet)
      90             :     {
      91         144 :         rPropMap.setProperty( PROP_CharFontNameAsian, aFontName);
      92         144 :         rPropMap.setProperty( PROP_CharFontPitchAsian, nFontFamily);
      93         144 :         rPropMap.setProperty( PROP_CharFontFamilyAsian, nFontPitch);
      94             :     }
      95             : 
      96        5928 :     bRet = maComplexFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
      97        5928 :     if (!bRet)
      98        5406 :         bRet = maComplexThemeFont.getFontData( aFontName, nFontPitch, nFontFamily, rFilter );
      99        5928 :     if (bRet)
     100             :     {
     101         522 :         rPropMap.setProperty( PROP_CharFontNameComplex, aFontName);
     102         522 :         rPropMap.setProperty( PROP_CharFontPitchComplex, nFontPitch);
     103         522 :         rPropMap.setProperty( PROP_CharFontFamilyComplex, nFontFamily);
     104             :     }
     105             : 
     106             :     // symbolfont, will now be ... textrun.cxx ... ausgewertet !!!i#113673
     107             : 
     108        5928 :     if( maCharColor.isUsed() )
     109        5220 :         rPropMap.setProperty( PROP_CharColor, maCharColor.getColor( rFilter.getGraphicHelper() ));
     110        5928 :     if( maGradientProps.maGradientStops.size() > 0 )
     111           2 :         rPropMap.setProperty( PROP_CharColor, maGradientProps.maGradientStops.begin()->second.getColor( rFilter.getGraphicHelper() ));
     112             : 
     113        5928 :     if( moLang.has() && !moLang.get().isEmpty() )
     114             :     {
     115         312 :         lang::Locale aLocale( LanguageTag( moLang.get()).getLocale());
     116         312 :         rPropMap.setProperty( PROP_CharLocale, aLocale);
     117         312 :         rPropMap.setProperty( PROP_CharLocaleAsian, aLocale);
     118         312 :         rPropMap.setProperty( PROP_CharLocaleComplex, aLocale);
     119             :     }
     120             : 
     121        5928 :     if( moHeight.has() )
     122             :     {
     123        5354 :         float fHeight = GetFontHeight( moHeight.get() );
     124        5354 :         rPropMap.setProperty( PROP_CharHeight, fHeight);
     125        5354 :         rPropMap.setProperty( PROP_CharHeightAsian, fHeight);
     126        5354 :         rPropMap.setProperty( PROP_CharHeightComplex, fHeight);
     127             :     }
     128             : 
     129        5928 :     rPropMap.setProperty( PROP_CharKerning, (sal_Int16) GetTextSpacingPoint( moSpacing.get( 0 ) ));
     130             : 
     131        5928 :     rPropMap.setProperty( PROP_CharUnderline, GetFontUnderline( moUnderline.get( XML_none ) ));
     132        5928 :     rPropMap.setProperty( PROP_CharStrikeout, GetFontStrikeout( moStrikeout.get( XML_noStrike ) ));
     133        5928 :     rPropMap.setProperty( PROP_CharCaseMap, GetCaseMap( moCaseMap.get( XML_none ) ));
     134             : 
     135        5928 :     if( moBaseline.has() ) {
     136           8 :         rPropMap.setProperty( PROP_CharEscapement, sal_Int16(moBaseline.get( 0 ) / 1000));
     137           8 :         rPropMap.setProperty( PROP_CharEscapementHeight, sal_Int8(DFLT_ESC_PROP));
     138             :     } else {
     139        5920 :         rPropMap.setProperty( PROP_CharEscapement, sal_Int16(0));
     140        5920 :         rPropMap.setProperty( PROP_CharEscapementHeight, sal_Int8(100)); // 100%
     141             :     }
     142             : 
     143        5928 :     if( !bUseOptional || moBold.has() ) {
     144        5928 :         float fWeight = moBold.get( false ) ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL;
     145        5928 :         rPropMap.setProperty( PROP_CharWeight, fWeight);
     146        5928 :         rPropMap.setProperty( PROP_CharWeightAsian, fWeight);
     147        5928 :         rPropMap.setProperty( PROP_CharWeightComplex, fWeight);
     148             :     }
     149             : 
     150        5928 :     if( !bUseOptional || moItalic.has() ) {
     151        5928 :         awt::FontSlant eSlant = moItalic.get( false ) ? awt::FontSlant_ITALIC : awt::FontSlant_NONE;
     152        5928 :         rPropMap.setProperty( PROP_CharPosture, eSlant);
     153        5928 :         rPropMap.setProperty( PROP_CharPostureAsian, eSlant);
     154        5928 :         rPropMap.setProperty( PROP_CharPostureComplex, eSlant);
     155             :     }
     156             : 
     157        5928 :     bool bUnderlineFillFollowText = moUnderlineFillFollowText.get( false );
     158        5928 :     if( moUnderline.has() && maUnderlineColor.isUsed() && !bUnderlineFillFollowText )
     159             :     {
     160           0 :         rPropMap.setProperty( PROP_CharUnderlineHasColor, true);
     161           0 :         rPropMap.setProperty( PROP_CharUnderlineColor, maUnderlineColor.getColor( rFilter.getGraphicHelper() ));
     162        5928 :     }
     163        5928 : }
     164             : 
     165        5928 : void pushToGrabBag( PropertySet& rPropSet, const std::vector<PropertyValue>& aVectorOfProperyValues )
     166             : {
     167        5928 :     if (!rPropSet.hasProperty(PROP_CharInteropGrabBag) || aVectorOfProperyValues.empty())
     168       11850 :         return;
     169           6 :     Sequence<PropertyValue> aGrabBag;
     170          12 :     Any aAnyGrabBag = rPropSet.getAnyProperty(PROP_CharInteropGrabBag);
     171           6 :     aAnyGrabBag >>= aGrabBag;
     172             : 
     173           6 :     sal_Int32 nLength = aGrabBag.getLength();
     174           6 :     aGrabBag.realloc(nLength + aVectorOfProperyValues.size());
     175             : 
     176          66 :     for (size_t i = 0; i < aVectorOfProperyValues.size(); i++)
     177             :     {
     178          60 :         PropertyValue aPropertyValue = aVectorOfProperyValues[i];
     179          60 :         aGrabBag[nLength + i] = aPropertyValue;
     180          60 :     }
     181             : 
     182          12 :     rPropSet.setAnyProperty(PROP_CharInteropGrabBag, makeAny(aGrabBag));
     183             : }
     184             : 
     185        5928 : void TextCharacterProperties::pushToPropSet( PropertySet& rPropSet, const XmlFilterBase& rFilter, bool bUseOptional ) const
     186             : {
     187        5928 :     PropertyMap aPropMap;
     188        5928 :     pushToPropMap( aPropMap, rFilter, bUseOptional );
     189        5928 :     rPropSet.setProperties( aPropMap );
     190        5928 :     pushToGrabBag(rPropSet, maTextEffectsProperties);
     191        5928 : }
     192             : 
     193         154 : float TextCharacterProperties::getCharHeightPoints( float fDefault ) const
     194             : {
     195         154 :     return moHeight.has() ? GetFontHeight( moHeight.get() ) : fDefault;
     196             : }
     197             : 
     198             : } // namespace drawingml
     199         408 : } // namespace oox
     200             : 
     201             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10