LCOV - code coverage report
Current view: top level - oox/source/drawingml - textparagraphpropertiescontext.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 126 145 86.9 %
Date: 2014-04-11 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             : #include <com/sun/star/style/ParagraphAdjust.hpp>
      25             : 
      26             : #include <svx/unopage.hxx>
      27             : 
      28             : #include "oox/drawingml/colorchoicecontext.hxx"
      29             : #include "oox/drawingml/textcharacterpropertiescontext.hxx"
      30             : #include "oox/drawingml/fillproperties.hxx"
      31             : #include "oox/helper/attributelist.hxx"
      32             : #include "textspacingcontext.hxx"
      33             : #include "texttabstoplistcontext.hxx"
      34             : 
      35             : using namespace ::oox::core;
      36             : using ::com::sun::star::awt::FontDescriptor;
      37             : using namespace ::com::sun::star::uno;
      38             : using namespace ::com::sun::star::xml::sax;
      39             : using namespace ::com::sun::star::style;
      40             : using namespace ::com::sun::star::text;
      41             : 
      42             : namespace oox { namespace drawingml {
      43             : 
      44             : // CT_TextParagraphProperties
      45        1671 : TextParagraphPropertiesContext::TextParagraphPropertiesContext( ContextHandler2Helper& rParent,
      46             :                                                                 const AttributeList& rAttribs,
      47             :                                                                 TextParagraphProperties& rTextParagraphProperties )
      48             : : ContextHandler2( rParent )
      49             : , mrTextParagraphProperties( rTextParagraphProperties )
      50        1671 : , mrBulletList( rTextParagraphProperties.getBulletList() )
      51             : {
      52        1671 :     OUString sValue;
      53             : 
      54        1671 :     PropertyMap& rPropertyMap( mrTextParagraphProperties.getTextParagraphPropertyMap() );
      55             : 
      56             :     // ST_TextAlignType
      57        1671 :     rPropertyMap.setProperty( PROP_ParaAdjust, GetParaAdjust( rAttribs.getToken( XML_algn, XML_l ) ));
      58             :     // TODO see to do the same with RubyAdjust
      59             : 
      60             :     // ST_Coordinate32
      61             : //  sValue = rAttribs.getString( XML_defTabSz ).get();    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 = rAttribs.getBool( XML_eaLnBrk, true );
      67        1671 :     if ( rAttribs.hasAttribute( XML_latinLnBrk ) )
      68             :     {
      69         577 :         bool bLatinLineBrk = rAttribs.getBool( XML_latinLnBrk, true );
      70         577 :         rPropertyMap.setProperty( PROP_ParaIsHyphenation, bLatinLineBrk);
      71             :     }
      72             :     // TODO see what to do with Asian hyphenation
      73             : 
      74             :     // ST_TextFontAlignType
      75             :     // TODO
      76             : //  sal_Int32 nFontAlign = rAttribs.getToken( XML_fontAlgn, XML_base );
      77             : 
      78        1671 :     if ( rAttribs.hasAttribute( XML_hangingPunct ) )
      79             :     {
      80         635 :         bool bHangingPunct = rAttribs.getBool( XML_hangingPunct, false );
      81         635 :         rPropertyMap.setProperty( PROP_ParaIsHangingPunctuation, bHangingPunct);
      82             :     }
      83             : 
      84             :   // ST_Coordinate
      85        1671 :     if ( rAttribs.hasAttribute( XML_indent ) )
      86             :     {
      87         341 :         sValue = rAttribs.getString( XML_indent ).get();
      88         341 :         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        1671 :     sal_Int32 nLevel = rAttribs.getInteger( XML_lvl, 0 );
      94        1671 :     if( nLevel > 8 || nLevel < 0 )
      95             :     {
      96           0 :         nLevel = 0;
      97             :     }
      98             : 
      99        1671 :     mrTextParagraphProperties.setLevel( static_cast< sal_Int16 >( nLevel ) );
     100             : 
     101        1671 :     char name[] = "Outline X";
     102        1671 :     name[8] = static_cast<char>( '1' + nLevel );
     103        3342 :     const OUString sStyleNameValue( OUString::createFromAscii( name ) );
     104        1671 :     mrBulletList.setStyleName( sStyleNameValue );
     105             : 
     106             :     // ST_TextMargin
     107             :     // ParaLeftMargin
     108        1671 :     if ( rAttribs.hasAttribute( XML_marL ) )
     109             :     {
     110         756 :         sValue = rAttribs.getString( XML_marL ).get();
     111         756 :         mrTextParagraphProperties.getParaLeftMargin() = boost::optional< sal_Int32 >( sValue.isEmpty() ? 0 : GetCoordinate( sValue ) );
     112             :     }
     113             : 
     114             :     // ParaRightMargin
     115        1671 :     if ( rAttribs.hasAttribute( XML_marR ) )
     116             :     {
     117          48 :         sValue = rAttribs.getString( XML_marR ).get();
     118          48 :         sal_Int32 nMarR  = sValue.isEmpty() ? 0 : GetCoordinate( sValue ) ;
     119          48 :         rPropertyMap.setProperty( PROP_ParaRightMargin, nMarR);
     120             :     }
     121             : 
     122        1671 :     if ( rAttribs.hasAttribute( XML_rtl ) )
     123             :     {
     124         765 :         bool bRtl = rAttribs.getBool( XML_rtl, false );
     125         765 :         rPropertyMap.setProperty( PROP_WritingMode, ( bRtl ? WritingMode2::RL_TB : WritingMode2::LR_TB ));
     126        1671 :     }
     127        1671 : }
     128             : 
     129             : 
     130        5013 : TextParagraphPropertiesContext::~TextParagraphPropertiesContext()
     131             : {
     132        1671 :     PropertyMap& rPropertyMap( mrTextParagraphProperties.getTextParagraphPropertyMap() );
     133        1671 :     if ( maLineSpacing.bHasValue )
     134         296 :         rPropertyMap.setProperty( PROP_ParaLineSpacing, maLineSpacing.toLineSpacing());
     135             :     else
     136        1375 :         rPropertyMap.setProperty( PROP_ParaLineSpacing, ::com::sun::star::style::LineSpacing( ::com::sun::star::style::LineSpacingMode::PROP, 100 ));
     137             : 
     138             : 
     139        1671 :     ::std::list< TabStop >::size_type nTabCount = maTabList.size();
     140        1671 :     if( nTabCount != 0 )
     141             :     {
     142           8 :         Sequence< TabStop > aSeq( nTabCount );
     143           8 :         TabStop * aArray = aSeq.getArray();
     144             :         OSL_ENSURE( aArray != NULL, "sequence array is NULL" );
     145           8 :         ::std::copy( maTabList.begin(), maTabList.end(), aArray );
     146           8 :         rPropertyMap.setProperty( PROP_ParaTabStops, aSeq);
     147             :     }
     148             : 
     149        1671 :     if ( mxBlipProps.get() && mxBlipProps->mxGraphic.is() )
     150           0 :         mrBulletList.setGraphic( mxBlipProps->mxGraphic );
     151             : 
     152        1671 :     if( mrBulletList.is() )
     153         414 :         rPropertyMap.setProperty( PROP_IsNumbering, sal_True);
     154        1671 :     sal_Int16 nLevel = mrTextParagraphProperties.getLevel();
     155        1671 :     rPropertyMap.setProperty( PROP_NumberingLevel, nLevel);
     156        1671 :     rPropertyMap.setProperty( PROP_NumberingIsNumber, sal_True);
     157             : 
     158        1671 :     if( mrTextParagraphProperties.getParaAdjust() )
     159          35 :         rPropertyMap.setProperty( PROP_ParaAdjust, mrTextParagraphProperties.getParaAdjust().get());
     160        3342 : }
     161             : 
     162             : 
     163             : 
     164        3335 : ContextHandlerRef TextParagraphPropertiesContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     165             : {
     166        3335 :     Reference< XFastContextHandler > xRet;
     167        3335 :     switch( aElementToken )
     168             :     {
     169             :         case A_TOKEN( lnSpc ):          // CT_TextSpacing
     170         254 :             return new TextSpacingContext( *this, maLineSpacing );
     171             :         case A_TOKEN( spcBef ):         // CT_TextSpacing
     172         479 :             return new TextSpacingContext( *this, mrTextParagraphProperties.getParaTopMargin() );
     173             :         case A_TOKEN( spcAft ):         // CT_TextSpacing
     174         354 :             return new TextSpacingContext( *this, mrTextParagraphProperties.getParaBottomMargin() );
     175             :         // EG_TextBulletColor
     176             :         case A_TOKEN( buClrTx ):        // CT_TextBulletColorFollowText ???
     177           9 :             mrBulletList.mbBulletColorFollowText <<= sal_True;
     178           9 :             break;
     179             :         case A_TOKEN( buClr ):          // CT_Color
     180          62 :             return new ColorContext( *this, *mrBulletList.maBulletColorPtr );
     181             :         // EG_TextBulletSize
     182             :         case A_TOKEN( buSzTx ):         // CT_TextBulletSizeFollowText
     183          46 :             mrBulletList.setBulletSize(100);
     184          46 :             break;
     185             :         case A_TOKEN( buSzPct ):        // CT_TextBulletSizePercent
     186          77 :             mrBulletList.setBulletSize( static_cast<sal_Int16>( GetPercent( rAttribs.getString( XML_val ).get() ) / 1000 ) );
     187          77 :             break;
     188             :         case A_TOKEN( buSzPts ):        // CT_TextBulletSizePoint
     189           0 :             mrBulletList.setBulletSize(0);
     190           0 :             mrBulletList.setFontSize( static_cast<sal_Int16>(GetTextSize( rAttribs.getString( XML_val ).get() ) ) );
     191           0 :             break;
     192             : 
     193             :         // EG_TextBulletTypeface
     194             :         case A_TOKEN( buFontTx ):       // CT_TextBulletTypefaceFollowText
     195          21 :             mrBulletList.mbBulletFontFollowText <<= sal_True;
     196          21 :             break;
     197             :         case A_TOKEN( buFont ):         // CT_TextFont
     198         260 :             mrBulletList.maBulletFont.setAttributes( rAttribs );
     199         260 :             break;
     200             : 
     201             :         // EG_TextBullet
     202             :         case A_TOKEN( buNone ):         // CT_TextNoBullet
     203         165 :             mrBulletList.setNone();
     204         165 :             break;
     205             :         case A_TOKEN( buAutoNum ):      // CT_TextAutonumberBullet
     206             :         {
     207             :             try {
     208           0 :                 sal_Int32 nType = rAttribs.getToken( XML_type, 0 );
     209           0 :                 sal_Int32 nStartAt = rAttribs.getInteger( XML_startAt, 1 );
     210           0 :                 if( nStartAt > 32767 )
     211             :                 {
     212           0 :                     nStartAt = 32767;
     213             :                 }
     214           0 :                 else if( nStartAt < 1 )
     215             :                 {
     216           0 :                     nStartAt = 1;
     217             :                 }
     218           0 :                 mrBulletList.setStartAt( nStartAt );
     219           0 :                 mrBulletList.setType( nType );
     220             :             }
     221           0 :             catch(SAXException& /* e */ )
     222             :             {
     223             :                 OSL_TRACE("OOX: SAXException in XML_buAutoNum");
     224             :             }
     225           0 :             break;
     226             :         }
     227             :         case A_TOKEN( buChar ):         // CT_TextCharBullet
     228             :             try {
     229         249 :                 mrBulletList.setBulletChar( rAttribs.getString( XML_char ).get() );
     230             :             }
     231           0 :             catch(SAXException& /* e */)
     232             :             {
     233             :                 OSL_TRACE("OOX: SAXException in XML_buChar");
     234             :             }
     235         249 :             break;
     236             :         case A_TOKEN( buBlip ):         // CT_TextBlipBullet
     237             :             {
     238           0 :                 mxBlipProps.reset( new BlipFillProperties );
     239           0 :                 return new BlipFillContext( *this, rAttribs, *mxBlipProps );
     240             :             }
     241             :         case A_TOKEN( tabLst ):         // CT_TextTabStopList
     242          56 :             return new TextTabStopListContext( *this, maTabList );
     243             :         case A_TOKEN( defRPr ):         // CT_TextCharacterProperties
     244         954 :             return new TextCharacterPropertiesContext( *this, rAttribs, mrTextParagraphProperties.getTextCharacterProperties() );
     245             :         case OOX_TOKEN( doc, jc ):
     246             :             {
     247          52 :                 OptValue< OUString > oParaAdjust = rAttribs.getString( OOX_TOKEN(doc, val) );
     248          52 :                 if( oParaAdjust.has() && !oParaAdjust.get().isEmpty() )
     249             :                 {
     250          52 :                     const OUString& sParaAdjust = oParaAdjust.get();
     251          52 :                     if( sParaAdjust == "left" )
     252           0 :                         mrTextParagraphProperties.setParaAdjust(ParagraphAdjust_LEFT);
     253          52 :                     else if ( sParaAdjust == "right" )
     254           4 :                         mrTextParagraphProperties.setParaAdjust(ParagraphAdjust_RIGHT);
     255          48 :                     else if ( sParaAdjust == "center" )
     256          29 :                         mrTextParagraphProperties.setParaAdjust(ParagraphAdjust_CENTER);
     257          19 :                     else if ( sParaAdjust == "both" )
     258           2 :                         mrTextParagraphProperties.setParaAdjust(ParagraphAdjust_BLOCK);
     259          52 :                 }
     260             :             }
     261          52 :             break;
     262             :         case OOX_TOKEN( doc, spacing ):
     263             :             {
     264             :                 // Spacing before
     265          46 :                 if( !rAttribs.getBool(OOX_TOKEN(doc, beforeAutospacing), false) )
     266             :                 {
     267          44 :                     OptValue<sal_Int32> oBefore = rAttribs.getInteger(OOX_TOKEN(doc, before));
     268          44 :                     if (oBefore.has())
     269             :                     {
     270          22 :                         TextSpacing& rSpacing = mrTextParagraphProperties.getParaTopMargin();
     271          22 :                         rSpacing.nUnit = TextSpacing::POINTS;
     272          22 :                         rSpacing.nValue = TWIPS_TO_MM(oBefore.get());
     273          22 :                         rSpacing.bHasValue = true;
     274             :                     }
     275             :                     else
     276             :                     {
     277          22 :                         OptValue<sal_Int32> oBeforeLines = rAttribs.getInteger(OOX_TOKEN(doc, beforeLines));
     278          22 :                         if (oBeforeLines.has())
     279             :                         {
     280           2 :                             TextSpacing& rSpacing = mrTextParagraphProperties.getParaTopMargin();
     281           2 :                             rSpacing.nUnit = TextSpacing::PERCENT;
     282           2 :                             rSpacing.nValue = oBeforeLines.get() * MAX_PERCENT / 100;
     283           2 :                             rSpacing.bHasValue = true;
     284             :                         }
     285             :                     }
     286             :                 }
     287             : 
     288             :                 // Spacing after
     289          46 :                 if( !rAttribs.getBool(OOX_TOKEN(doc, afterAutospacing), false) )
     290             :                 {
     291          44 :                     OptValue<sal_Int32> oAfter = rAttribs.getInteger(OOX_TOKEN(doc, after));
     292          44 :                     if (oAfter.has())
     293             :                     {
     294          29 :                         TextSpacing& rSpacing = mrTextParagraphProperties.getParaBottomMargin();
     295          29 :                         rSpacing.nUnit = TextSpacing::POINTS;
     296          29 :                         rSpacing.nValue = TWIPS_TO_MM(oAfter.get());
     297          29 :                         rSpacing.bHasValue = true;
     298             :                     }
     299             :                     else
     300             :                     {
     301          15 :                         OptValue<sal_Int32> oAfterLines = rAttribs.getInteger(OOX_TOKEN(doc, afterLines));
     302          15 :                         if (oAfterLines.has())
     303             :                         {
     304           2 :                             TextSpacing& rSpacing = mrTextParagraphProperties.getParaBottomMargin();
     305           2 :                             rSpacing.nUnit = TextSpacing::PERCENT;
     306           2 :                             rSpacing.nValue = oAfterLines.get() * MAX_PERCENT / 100;
     307           2 :                             rSpacing.bHasValue = true;
     308             :                         }
     309             :                     }
     310             :                 }
     311             : 
     312             :                 // Line spacing
     313          46 :                 OptValue<OUString> oLineRule = rAttribs.getString(OOX_TOKEN(doc, lineRule));
     314          46 :                 OptValue<sal_Int32> oLineSpacing = rAttribs.getInteger(OOX_TOKEN(doc, line));
     315          46 :                 if (oLineSpacing.has())
     316             :                 {
     317          42 :                     if( !oLineRule.has() || oLineRule.get() == "auto" )
     318             :                     {
     319          39 :                         maLineSpacing.nUnit = TextSpacing::PERCENT;
     320          39 :                         maLineSpacing.nValue = oLineSpacing.get() * MAX_PERCENT / 240;
     321             :                     }
     322             :                     else
     323             :                     {
     324           3 :                         maLineSpacing.nUnit = TextSpacing::POINTS;
     325           3 :                         maLineSpacing.nValue = TWIPS_TO_MM(oLineSpacing.get());
     326             :                     }
     327          42 :                     maLineSpacing.bHasValue = true;
     328          46 :                 }
     329             :             }
     330          46 :             break;
     331             :         default:
     332             :             SAL_WARN("oox", "TextParagraphPropertiesContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
     333             :     }
     334        1176 :     return this;
     335             : }
     336             : 
     337             : } }
     338             : 
     339             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10