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

Generated by: LCOV version 1.10