LCOV - code coverage report
Current view: top level - oox/source/drawingml - textparagraphpropertiescontext.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 145 0.0 %
Date: 2014-04-14 Functions: 0 4 0.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           0 : TextParagraphPropertiesContext::TextParagraphPropertiesContext( ContextHandler2Helper& rParent,
      46             :                                                                 const AttributeList& rAttribs,
      47             :                                                                 TextParagraphProperties& rTextParagraphProperties )
      48             : : ContextHandler2( rParent )
      49             : , mrTextParagraphProperties( rTextParagraphProperties )
      50           0 : , mrBulletList( rTextParagraphProperties.getBulletList() )
      51             : {
      52           0 :     OUString sValue;
      53             : 
      54           0 :     PropertyMap& rPropertyMap( mrTextParagraphProperties.getTextParagraphPropertyMap() );
      55             : 
      56             :     // ST_TextAlignType
      57           0 :     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           0 :     if ( rAttribs.hasAttribute( XML_latinLnBrk ) )
      68             :     {
      69           0 :         bool bLatinLineBrk = rAttribs.getBool( XML_latinLnBrk, true );
      70           0 :         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           0 :     if ( rAttribs.hasAttribute( XML_hangingPunct ) )
      79             :     {
      80           0 :         bool bHangingPunct = rAttribs.getBool( XML_hangingPunct, false );
      81           0 :         rPropertyMap.setProperty( PROP_ParaIsHangingPunctuation, bHangingPunct);
      82             :     }
      83             : 
      84             :   // ST_Coordinate
      85           0 :     if ( rAttribs.hasAttribute( XML_indent ) )
      86             :     {
      87           0 :         sValue = rAttribs.getString( XML_indent ).get();
      88           0 :         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           0 :     sal_Int32 nLevel = rAttribs.getInteger( XML_lvl, 0 );
      94           0 :     if( nLevel > 8 || nLevel < 0 )
      95             :     {
      96           0 :         nLevel = 0;
      97             :     }
      98             : 
      99           0 :     mrTextParagraphProperties.setLevel( static_cast< sal_Int16 >( nLevel ) );
     100             : 
     101           0 :     char name[] = "Outline X";
     102           0 :     name[8] = static_cast<char>( '1' + nLevel );
     103           0 :     const OUString sStyleNameValue( OUString::createFromAscii( name ) );
     104           0 :     mrBulletList.setStyleName( sStyleNameValue );
     105             : 
     106             :     // ST_TextMargin
     107             :     // ParaLeftMargin
     108           0 :     if ( rAttribs.hasAttribute( XML_marL ) )
     109             :     {
     110           0 :         sValue = rAttribs.getString( XML_marL ).get();
     111           0 :         mrTextParagraphProperties.getParaLeftMargin() = boost::optional< sal_Int32 >( sValue.isEmpty() ? 0 : GetCoordinate( sValue ) );
     112             :     }
     113             : 
     114             :     // ParaRightMargin
     115           0 :     if ( rAttribs.hasAttribute( XML_marR ) )
     116             :     {
     117           0 :         sValue = rAttribs.getString( XML_marR ).get();
     118           0 :         sal_Int32 nMarR  = sValue.isEmpty() ? 0 : GetCoordinate( sValue ) ;
     119           0 :         rPropertyMap.setProperty( PROP_ParaRightMargin, nMarR);
     120             :     }
     121             : 
     122           0 :     if ( rAttribs.hasAttribute( XML_rtl ) )
     123             :     {
     124           0 :         bool bRtl = rAttribs.getBool( XML_rtl, false );
     125           0 :         rPropertyMap.setProperty( PROP_WritingMode, ( bRtl ? WritingMode2::RL_TB : WritingMode2::LR_TB ));
     126           0 :     }
     127           0 : }
     128             : 
     129             : 
     130           0 : TextParagraphPropertiesContext::~TextParagraphPropertiesContext()
     131             : {
     132           0 :     PropertyMap& rPropertyMap( mrTextParagraphProperties.getTextParagraphPropertyMap() );
     133           0 :     if ( maLineSpacing.bHasValue )
     134           0 :         rPropertyMap.setProperty( PROP_ParaLineSpacing, maLineSpacing.toLineSpacing());
     135             :     else
     136           0 :         rPropertyMap.setProperty( PROP_ParaLineSpacing, ::com::sun::star::style::LineSpacing( ::com::sun::star::style::LineSpacingMode::PROP, 100 ));
     137             : 
     138             : 
     139           0 :     ::std::list< TabStop >::size_type nTabCount = maTabList.size();
     140           0 :     if( nTabCount != 0 )
     141             :     {
     142           0 :         Sequence< TabStop > aSeq( nTabCount );
     143           0 :         TabStop * aArray = aSeq.getArray();
     144             :         OSL_ENSURE( aArray != NULL, "sequence array is NULL" );
     145           0 :         ::std::copy( maTabList.begin(), maTabList.end(), aArray );
     146           0 :         rPropertyMap.setProperty( PROP_ParaTabStops, aSeq);
     147             :     }
     148             : 
     149           0 :     if ( mxBlipProps.get() && mxBlipProps->mxGraphic.is() )
     150           0 :         mrBulletList.setGraphic( mxBlipProps->mxGraphic );
     151             : 
     152           0 :     if( mrBulletList.is() )
     153           0 :         rPropertyMap.setProperty( PROP_IsNumbering, sal_True);
     154           0 :     sal_Int16 nLevel = mrTextParagraphProperties.getLevel();
     155           0 :     rPropertyMap.setProperty( PROP_NumberingLevel, nLevel);
     156           0 :     rPropertyMap.setProperty( PROP_NumberingIsNumber, sal_True);
     157             : 
     158           0 :     if( mrTextParagraphProperties.getParaAdjust() )
     159           0 :         rPropertyMap.setProperty( PROP_ParaAdjust, mrTextParagraphProperties.getParaAdjust().get());
     160           0 : }
     161             : 
     162             : 
     163             : 
     164           0 : ContextHandlerRef TextParagraphPropertiesContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     165             : {
     166           0 :     Reference< XFastContextHandler > xRet;
     167           0 :     switch( aElementToken )
     168             :     {
     169             :         case A_TOKEN( lnSpc ):          // CT_TextSpacing
     170           0 :             return new TextSpacingContext( *this, maLineSpacing );
     171             :         case A_TOKEN( spcBef ):         // CT_TextSpacing
     172           0 :             return new TextSpacingContext( *this, mrTextParagraphProperties.getParaTopMargin() );
     173             :         case A_TOKEN( spcAft ):         // CT_TextSpacing
     174           0 :             return new TextSpacingContext( *this, mrTextParagraphProperties.getParaBottomMargin() );
     175             :         // EG_TextBulletColor
     176             :         case A_TOKEN( buClrTx ):        // CT_TextBulletColorFollowText ???
     177           0 :             mrBulletList.mbBulletColorFollowText <<= sal_True;
     178           0 :             break;
     179             :         case A_TOKEN( buClr ):          // CT_Color
     180           0 :             return new ColorContext( *this, *mrBulletList.maBulletColorPtr );
     181             :         // EG_TextBulletSize
     182             :         case A_TOKEN( buSzTx ):         // CT_TextBulletSizeFollowText
     183           0 :             mrBulletList.setBulletSize(100);
     184           0 :             break;
     185             :         case A_TOKEN( buSzPct ):        // CT_TextBulletSizePercent
     186           0 :             mrBulletList.setBulletSize( static_cast<sal_Int16>( GetPercent( rAttribs.getString( XML_val ).get() ) / 1000 ) );
     187           0 :             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           0 :             mrBulletList.mbBulletFontFollowText <<= sal_True;
     196           0 :             break;
     197             :         case A_TOKEN( buFont ):         // CT_TextFont
     198           0 :             mrBulletList.maBulletFont.setAttributes( rAttribs );
     199           0 :             break;
     200             : 
     201             :         // EG_TextBullet
     202             :         case A_TOKEN( buNone ):         // CT_TextNoBullet
     203           0 :             mrBulletList.setNone();
     204           0 :             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           0 :                 mrBulletList.setBulletChar( rAttribs.getString( XML_char ).get() );
     230             :             }
     231           0 :             catch(SAXException& /* e */)
     232             :             {
     233             :                 OSL_TRACE("OOX: SAXException in XML_buChar");
     234             :             }
     235           0 :             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           0 :             return new TextTabStopListContext( *this, maTabList );
     243             :         case A_TOKEN( defRPr ):         // CT_TextCharacterProperties
     244           0 :             return new TextCharacterPropertiesContext( *this, rAttribs, mrTextParagraphProperties.getTextCharacterProperties() );
     245             :         case OOX_TOKEN( doc, jc ):
     246             :             {
     247           0 :                 OptValue< OUString > oParaAdjust = rAttribs.getString( OOX_TOKEN(doc, val) );
     248           0 :                 if( oParaAdjust.has() && !oParaAdjust.get().isEmpty() )
     249             :                 {
     250           0 :                     const OUString& sParaAdjust = oParaAdjust.get();
     251           0 :                     if( sParaAdjust == "left" )
     252           0 :                         mrTextParagraphProperties.setParaAdjust(ParagraphAdjust_LEFT);
     253           0 :                     else if ( sParaAdjust == "right" )
     254           0 :                         mrTextParagraphProperties.setParaAdjust(ParagraphAdjust_RIGHT);
     255           0 :                     else if ( sParaAdjust == "center" )
     256           0 :                         mrTextParagraphProperties.setParaAdjust(ParagraphAdjust_CENTER);
     257           0 :                     else if ( sParaAdjust == "both" )
     258           0 :                         mrTextParagraphProperties.setParaAdjust(ParagraphAdjust_BLOCK);
     259           0 :                 }
     260             :             }
     261           0 :             break;
     262             :         case OOX_TOKEN( doc, spacing ):
     263             :             {
     264             :                 // Spacing before
     265           0 :                 if( !rAttribs.getBool(OOX_TOKEN(doc, beforeAutospacing), false) )
     266             :                 {
     267           0 :                     OptValue<sal_Int32> oBefore = rAttribs.getInteger(OOX_TOKEN(doc, before));
     268           0 :                     if (oBefore.has())
     269             :                     {
     270           0 :                         TextSpacing& rSpacing = mrTextParagraphProperties.getParaTopMargin();
     271           0 :                         rSpacing.nUnit = TextSpacing::POINTS;
     272           0 :                         rSpacing.nValue = TWIPS_TO_MM(oBefore.get());
     273           0 :                         rSpacing.bHasValue = true;
     274             :                     }
     275             :                     else
     276             :                     {
     277           0 :                         OptValue<sal_Int32> oBeforeLines = rAttribs.getInteger(OOX_TOKEN(doc, beforeLines));
     278           0 :                         if (oBeforeLines.has())
     279             :                         {
     280           0 :                             TextSpacing& rSpacing = mrTextParagraphProperties.getParaTopMargin();
     281           0 :                             rSpacing.nUnit = TextSpacing::PERCENT;
     282           0 :                             rSpacing.nValue = oBeforeLines.get() * MAX_PERCENT / 100;
     283           0 :                             rSpacing.bHasValue = true;
     284             :                         }
     285             :                     }
     286             :                 }
     287             : 
     288             :                 // Spacing after
     289           0 :                 if( !rAttribs.getBool(OOX_TOKEN(doc, afterAutospacing), false) )
     290             :                 {
     291           0 :                     OptValue<sal_Int32> oAfter = rAttribs.getInteger(OOX_TOKEN(doc, after));
     292           0 :                     if (oAfter.has())
     293             :                     {
     294           0 :                         TextSpacing& rSpacing = mrTextParagraphProperties.getParaBottomMargin();
     295           0 :                         rSpacing.nUnit = TextSpacing::POINTS;
     296           0 :                         rSpacing.nValue = TWIPS_TO_MM(oAfter.get());
     297           0 :                         rSpacing.bHasValue = true;
     298             :                     }
     299             :                     else
     300             :                     {
     301           0 :                         OptValue<sal_Int32> oAfterLines = rAttribs.getInteger(OOX_TOKEN(doc, afterLines));
     302           0 :                         if (oAfterLines.has())
     303             :                         {
     304           0 :                             TextSpacing& rSpacing = mrTextParagraphProperties.getParaBottomMargin();
     305           0 :                             rSpacing.nUnit = TextSpacing::PERCENT;
     306           0 :                             rSpacing.nValue = oAfterLines.get() * MAX_PERCENT / 100;
     307           0 :                             rSpacing.bHasValue = true;
     308             :                         }
     309             :                     }
     310             :                 }
     311             : 
     312             :                 // Line spacing
     313           0 :                 OptValue<OUString> oLineRule = rAttribs.getString(OOX_TOKEN(doc, lineRule));
     314           0 :                 OptValue<sal_Int32> oLineSpacing = rAttribs.getInteger(OOX_TOKEN(doc, line));
     315           0 :                 if (oLineSpacing.has())
     316             :                 {
     317           0 :                     if( !oLineRule.has() || oLineRule.get() == "auto" )
     318             :                     {
     319           0 :                         maLineSpacing.nUnit = TextSpacing::PERCENT;
     320           0 :                         maLineSpacing.nValue = oLineSpacing.get() * MAX_PERCENT / 240;
     321             :                     }
     322             :                     else
     323             :                     {
     324           0 :                         maLineSpacing.nUnit = TextSpacing::POINTS;
     325           0 :                         maLineSpacing.nValue = TWIPS_TO_MM(oLineSpacing.get());
     326             :                     }
     327           0 :                     maLineSpacing.bHasValue = true;
     328           0 :                 }
     329             :             }
     330           0 :             break;
     331             :         default:
     332             :             SAL_WARN("oox", "TextParagraphPropertiesContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
     333             :     }
     334           0 :     return this;
     335             : }
     336             : 
     337             : } }
     338             : 
     339             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10