LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/oox/source/drawingml - textparagraphpropertiescontext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 73 95 76.8 %
Date: 2013-07-09 Functions: 4 4 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 "oox/drawingml/textparagraphpropertiescontext.hxx"
      21             : 
      22             : #include <com/sun/star/text/WritingMode2.hpp>
      23             : #include <com/sun/star/awt/FontDescriptor.hpp>
      24             : 
      25             : #include "oox/drawingml/colorchoicecontext.hxx"
      26             : #include "oox/drawingml/textcharacterpropertiescontext.hxx"
      27             : #include "oox/drawingml/fillproperties.hxx"
      28             : #include "oox/helper/attributelist.hxx"
      29             : #include "textspacingcontext.hxx"
      30             : #include "texttabstoplistcontext.hxx"
      31             : 
      32             : using namespace ::oox::core;
      33             : using ::com::sun::star::awt::FontDescriptor;
      34             : using namespace ::com::sun::star::uno;
      35             : using namespace ::com::sun::star::xml::sax;
      36             : using namespace ::com::sun::star::style;
      37             : using namespace ::com::sun::star::text;
      38             : 
      39             : namespace oox { namespace drawingml {
      40             : 
      41             : // CT_TextParagraphProperties
      42         469 : TextParagraphPropertiesContext::TextParagraphPropertiesContext( ContextHandler2Helper& rParent,
      43             :                                                                 const AttributeList& rAttribs,
      44             :                                                                 TextParagraphProperties& rTextParagraphProperties )
      45             : : ContextHandler2( rParent )
      46             : , mrTextParagraphProperties( rTextParagraphProperties )
      47         469 : , mrSpaceBefore( rTextParagraphProperties.getParaTopMargin() )
      48         469 : , mrSpaceAfter( rTextParagraphProperties.getParaBottomMargin() )
      49        1407 : , mrBulletList( rTextParagraphProperties.getBulletList() )
      50             : {
      51         469 :     OUString sValue;
      52             : 
      53         469 :     PropertyMap& rPropertyMap( mrTextParagraphProperties.getTextParagraphPropertyMap() );
      54             : 
      55             :     // ST_TextAlignType
      56         469 :     rPropertyMap[ PROP_ParaAdjust ] <<= GetParaAdjust( rAttribs.getToken( XML_algn, XML_l ) );
      57             :     // TODO see to do the same with RubyAdjust
      58             : 
      59             :     // ST_Coordinate32
      60             : //  sValue = rAttribs.getString( XML_defTabSz ).get();    SJ: we need to be able to set the default tab size for each text object,
      61             : //                                                          this is possible at the moment only for the whole document.
      62             : //  sal_Int32 nDefTabSize = ( sValue.getLength() == 0 ? 0 : GetCoordinate(  sValue ) );
      63             :     // TODO
      64             : 
      65             : //  bool bEaLineBrk = rAttribs.getBool( XML_eaLnBrk, true );
      66         469 :     if ( rAttribs.hasAttribute( XML_latinLnBrk ) )
      67             :     {
      68         182 :         bool bLatinLineBrk = rAttribs.getBool( XML_latinLnBrk, true );
      69         182 :         rPropertyMap[ PROP_ParaIsHyphenation ] <<= bLatinLineBrk;
      70             :     }
      71             :     // TODO see what to do with Asian hyphenation
      72             : 
      73             :     // ST_TextFontAlignType
      74             :     // TODO
      75             : //  sal_Int32 nFontAlign = rAttribs.getToken( XML_fontAlgn, XML_base );
      76             : 
      77         469 :     if ( rAttribs.hasAttribute( XML_hangingPunct ) )
      78             :     {
      79         230 :         bool bHangingPunct = rAttribs.getBool( XML_hangingPunct, false );
      80         230 :         rPropertyMap[ PROP_ParaIsHangingPunctuation ] <<= bHangingPunct;
      81             :     }
      82             : 
      83             :   // ST_Coordinate
      84         469 :     if ( rAttribs.hasAttribute( XML_indent ) )
      85             :     {
      86         122 :         sValue = rAttribs.getString( XML_indent ).get();
      87         122 :         mrTextParagraphProperties.getFirstLineIndentation() = boost::optional< sal_Int32 >( sValue.isEmpty() ? 0 : GetCoordinate( sValue ) );
      88             :     }
      89             : 
      90             :   // ST_TextIndentLevelType
      91             :     // -1 is an invalid value and denote the lack of level
      92         469 :     sal_Int32 nLevel = rAttribs.getInteger( XML_lvl, 0 );
      93         469 :     if( nLevel > 8 || nLevel < 0 )
      94             :     {
      95           0 :         nLevel = 0;
      96             :     }
      97             : 
      98         469 :     mrTextParagraphProperties.setLevel( static_cast< sal_Int16 >( nLevel ) );
      99             : 
     100         469 :     char name[] = "Outline X";
     101         469 :     name[8] = static_cast<char>( '1' + nLevel );
     102         938 :     const OUString sStyleNameValue( OUString::createFromAscii( name ) );
     103         469 :     mrBulletList.setStyleName( sStyleNameValue );
     104             : 
     105             :     // ST_TextMargin
     106             :     // ParaLeftMargin
     107         469 :     if ( rAttribs.hasAttribute( XML_marL ) )
     108             :     {
     109         247 :         sValue = rAttribs.getString( XML_marL ).get();
     110         247 :         mrTextParagraphProperties.getParaLeftMargin() = boost::optional< sal_Int32 >( sValue.isEmpty() ? 0 : GetCoordinate( sValue ) );
     111             :     }
     112             : 
     113             :     // ParaRightMargin
     114         469 :     if ( rAttribs.hasAttribute( XML_marR ) )
     115             :     {
     116          41 :         sValue = rAttribs.getString( XML_marR ).get();
     117          41 :         sal_Int32 nMarR  = sValue.isEmpty() ? 0 : GetCoordinate( sValue ) ;
     118          41 :         rPropertyMap[ PROP_ParaRightMargin ] <<= nMarR;
     119             :     }
     120             : 
     121         469 :     if ( rAttribs.hasAttribute( XML_rtl ) )
     122             :     {
     123         252 :         bool bRtl = rAttribs.getBool( XML_rtl, false );
     124         252 :         rPropertyMap[ PROP_WritingMode ] <<= ( bRtl ? WritingMode2::RL_TB : WritingMode2::LR_TB );
     125         469 :     }
     126         469 : }
     127             : 
     128             : 
     129        1407 : TextParagraphPropertiesContext::~TextParagraphPropertiesContext()
     130             : {
     131         469 :     PropertyMap& rPropertyMap( mrTextParagraphProperties.getTextParagraphPropertyMap() );
     132         469 :     if ( maLineSpacing.bHasValue )
     133          53 :         rPropertyMap[ PROP_ParaLineSpacing ] <<= maLineSpacing.toLineSpacing();
     134             :     else
     135         416 :         rPropertyMap[ PROP_ParaLineSpacing ] <<= ::com::sun::star::style::LineSpacing( ::com::sun::star::style::LineSpacingMode::PROP, 100 );
     136             : 
     137             : 
     138         469 :     ::std::list< TabStop >::size_type nTabCount = maTabList.size();
     139         469 :     if( nTabCount != 0 )
     140             :     {
     141           0 :         Sequence< TabStop > aSeq( nTabCount );
     142           0 :         TabStop * aArray = aSeq.getArray();
     143             :         OSL_ENSURE( aArray != NULL, "sequence array is NULL" );
     144           0 :         ::std::copy( maTabList.begin(), maTabList.end(), aArray );
     145           0 :         rPropertyMap[ PROP_ParaTabStops ] <<= aSeq;
     146             :     }
     147             : 
     148         469 :     if ( mxBlipProps.get() && mxBlipProps->mxGraphic.is() )
     149           0 :         mrBulletList.setGraphic( mxBlipProps->mxGraphic );
     150             : 
     151         469 :     if( mrBulletList.is() )
     152         138 :         rPropertyMap[ PROP_IsNumbering ] <<= sal_True;
     153         469 :     sal_Int16 nLevel = mrTextParagraphProperties.getLevel();
     154         469 :     rPropertyMap[ PROP_NumberingLevel ] <<= nLevel;
     155         469 :     rPropertyMap[ PROP_NumberingIsNumber ] <<= sal_True;
     156         938 : }
     157             : 
     158             : // --------------------------------------------------------------------
     159             : 
     160         994 : ContextHandlerRef TextParagraphPropertiesContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     161             : {
     162         994 :     Reference< XFastContextHandler > xRet;
     163         994 :     switch( aElementToken )
     164             :     {
     165             :         case A_TOKEN( lnSpc ):          // CT_TextSpacing
     166          53 :             return new TextSpacingContext( *this, maLineSpacing );
     167             :         case A_TOKEN( spcBef ):         // CT_TextSpacing
     168         162 :             return new TextSpacingContext( *this, mrSpaceBefore );
     169             :         case A_TOKEN( spcAft ):         // CT_TextSpacing
     170         118 :             return new TextSpacingContext( *this, mrSpaceAfter );
     171             :         // EG_TextBulletColor
     172             :         case A_TOKEN( buClrTx ):        // CT_TextBulletColorFollowText ???
     173           4 :             mrBulletList.mbBulletColorFollowText <<= sal_True;
     174           4 :             break;
     175             :         case A_TOKEN( buClr ):          // CT_Color
     176          37 :             return new ColorContext( *this, *mrBulletList.maBulletColorPtr );
     177             :         // EG_TextBulletSize
     178             :         case A_TOKEN( buSzTx ):         // CT_TextBulletSizeFollowText
     179          41 :             mrBulletList.setBulletSize(100);
     180          41 :             break;
     181             :         case A_TOKEN( buSzPct ):        // CT_TextBulletSizePercent
     182           9 :             mrBulletList.setBulletSize( static_cast<sal_Int16>( GetPercent( rAttribs.getString( XML_val ).get() ) / 1000 ) );
     183           9 :             break;
     184             :         case A_TOKEN( buSzPts ):        // CT_TextBulletSizePoint
     185           0 :             mrBulletList.setBulletSize(0);
     186           0 :             mrBulletList.setFontSize( static_cast<sal_Int16>(GetTextSize( rAttribs.getString( XML_val ).get() ) ) );
     187           0 :             break;
     188             : 
     189             :         // EG_TextBulletTypeface
     190             :         case A_TOKEN( buFontTx ):       // CT_TextBulletTypefaceFollowText
     191          16 :             mrBulletList.mbBulletFontFollowText <<= sal_True;
     192          16 :             break;
     193             :         case A_TOKEN( buFont ):         // CT_TextFont
     194          86 :             mrBulletList.maBulletFont.setAttributes( rAttribs );
     195          86 :             break;
     196             : 
     197             :         // EG_TextBullet
     198             :         case A_TOKEN( buNone ):         // CT_TextNoBullet
     199          64 :             mrBulletList.setNone();
     200          64 :             break;
     201             :         case A_TOKEN( buAutoNum ):      // CT_TextAutonumberBullet
     202             :         {
     203             :             try {
     204           0 :                 sal_Int32 nType = rAttribs.getToken( XML_type, 0 );
     205           0 :                 sal_Int32 nStartAt = rAttribs.getInteger( XML_startAt, 1 );
     206           0 :                 if( nStartAt > 32767 )
     207             :                 {
     208           0 :                     nStartAt = 32767;
     209             :                 }
     210           0 :                 else if( nStartAt < 1 )
     211             :                 {
     212           0 :                     nStartAt = 1;
     213             :                 }
     214           0 :                 mrBulletList.setStartAt( nStartAt );
     215           0 :                 mrBulletList.setType( nType );
     216             :             }
     217           0 :             catch(SAXException& /* e */ )
     218             :             {
     219             :                 OSL_TRACE("OOX: SAXException in XML_buAutoNum");
     220             :             }
     221           0 :             break;
     222             :         }
     223             :         case A_TOKEN( buChar ):         // CT_TextCharBullet
     224             :             try {
     225          74 :                 mrBulletList.setBulletChar( rAttribs.getString( XML_char ).get() );
     226             :             }
     227           0 :             catch(SAXException& /* e */)
     228             :             {
     229             :                 OSL_TRACE("OOX: SAXException in XML_buChar");
     230             :             }
     231          74 :             break;
     232             :         case A_TOKEN( buBlip ):         // CT_TextBlipBullet
     233             :             {
     234           0 :                 mxBlipProps.reset( new BlipFillProperties );
     235           0 :                 return new BlipFillContext( *this, rAttribs, *mxBlipProps );
     236             :             }
     237             :         case A_TOKEN( tabLst ):         // CT_TextTabStopList
     238          41 :             return new TextTabStopListContext( *this, maTabList );
     239             :         case A_TOKEN( defRPr ):         // CT_TextCharacterProperties
     240         289 :             return new TextCharacterPropertiesContext( *this, rAttribs, mrTextParagraphProperties.getTextCharacterProperties() );
     241             :     }
     242         294 :     return this;
     243             : }
     244             : 
     245             : } }
     246             : 
     247             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10