LCOV - code coverage report
Current view: top level - oox/source/drawingml - textbodycontext.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 52 53 98.1 %
Date: 2014-04-11 Functions: 12 12 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/textbodycontext.hxx"
      21             : #include "oox/drawingml/textbodypropertiescontext.hxx"
      22             : #include "oox/drawingml/textparagraph.hxx"
      23             : #include "oox/drawingml/textparagraphpropertiescontext.hxx"
      24             : #include "oox/drawingml/textcharacterpropertiescontext.hxx"
      25             : #include "oox/drawingml/textliststylecontext.hxx"
      26             : #include "oox/drawingml/textfield.hxx"
      27             : #include "oox/drawingml/textfieldcontext.hxx"
      28             : 
      29             : using namespace ::oox::core;
      30             : using namespace ::com::sun::star::uno;
      31             : using namespace ::com::sun::star::text;
      32             : using namespace ::com::sun::star::xml::sax;
      33             : 
      34             : namespace oox { namespace drawingml {
      35             : 
      36             : 
      37             : 
      38             : // CT_TextParagraph
      39        3740 : class TextParagraphContext : public ContextHandler2
      40             : {
      41             : public:
      42             :     TextParagraphContext( ContextHandler2Helper& rParent, TextParagraph& rPara );
      43             : 
      44             :     virtual ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs ) SAL_OVERRIDE;
      45             : 
      46             : protected:
      47             :     TextParagraph& mrParagraph;
      48             : };
      49             : 
      50             : 
      51        1870 : TextParagraphContext::TextParagraphContext( ContextHandler2Helper& rParent, TextParagraph& rPara )
      52             : : ContextHandler2( rParent )
      53        1870 : , mrParagraph( rPara )
      54             : {
      55        1870 :     mbEnableTrimSpace = false;
      56        1870 : }
      57             : 
      58             : 
      59             : 
      60        3187 : ContextHandlerRef TextParagraphContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
      61             : {
      62             :     // EG_TextRun
      63        3187 :     switch( aElementToken )
      64             :     {
      65             :     case A_TOKEN( r ):      // "CT_RegularTextRun" Regular Text Run.
      66             :     case OOX_TOKEN( doc, r ):
      67             :     {
      68         897 :         TextRunPtr pRun( new TextRun );
      69         897 :         mrParagraph.addRun( pRun );
      70         897 :         return new RegularTextRunContext( *this, pRun );
      71             :     }
      72             :     case A_TOKEN( br ): // "CT_TextLineBreak" Soft return line break (vertical tab).
      73             :     {
      74          22 :         TextRunPtr pRun( new TextRun );
      75          22 :         pRun->setLineBreak();
      76          22 :         mrParagraph.addRun( pRun );
      77          22 :         return new RegularTextRunContext( *this, pRun );
      78             :     }
      79             :     case A_TOKEN( fld ):    // "CT_TextField" Text Field.
      80             :     {
      81          81 :         TextFieldPtr pField( new TextField );
      82          81 :         mrParagraph.addRun( pField );
      83          81 :         return new TextFieldContext( *this, rAttribs, *pField );
      84             :     }
      85             :     case A_TOKEN( pPr ):
      86             :     case OOX_TOKEN( doc, pPr ):
      87         788 :         return new TextParagraphPropertiesContext( *this, rAttribs, mrParagraph.getProperties() );
      88             :     case A_TOKEN( endParaRPr ):
      89        1363 :         return new TextCharacterPropertiesContext( *this, rAttribs, mrParagraph.getEndProperties() );
      90             :     case OOX_TOKEN( doc, sdt ):
      91             :     case OOX_TOKEN( doc, sdtContent ):
      92          10 :         return this;
      93             :     }
      94             : 
      95          26 :     return 0;
      96             : }
      97             : 
      98             : 
      99         919 : RegularTextRunContext::RegularTextRunContext( ContextHandler2Helper& rParent, TextRunPtr pRunPtr )
     100             : : ContextHandler2( rParent )
     101             : , mpRunPtr( pRunPtr )
     102         919 : , mbIsInText( false )
     103             : {
     104         919 : }
     105             : 
     106             : 
     107             : 
     108        1815 : void RegularTextRunContext::onEndElement( )
     109             : {
     110        1815 :     switch( getCurrentElement() )
     111             :     {
     112             :     case A_TOKEN( t ):
     113             :     case OOX_TOKEN( doc, t ):
     114             :     {
     115         896 :         mbIsInText = false;
     116         896 :         break;
     117             :     }
     118             :     case A_TOKEN( r ):
     119             :     {
     120         716 :         break;
     121             :     }
     122             : 
     123             :     }
     124        1815 : }
     125             : 
     126             : 
     127             : 
     128        1009 : void RegularTextRunContext::onCharacters( const OUString& aChars )
     129             : {
     130        1009 :     if( mbIsInText )
     131             :     {
     132         894 :         mpRunPtr->getText() += aChars;
     133             :     }
     134        1009 : }
     135             : 
     136             : 
     137             : 
     138        1789 : ContextHandlerRef RegularTextRunContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs)
     139             : {
     140        1789 :     switch( aElementToken )
     141             :     {
     142             :     case A_TOKEN( rPr ):    // "CT_TextCharPropertyBag" The text char properties of this text run.
     143             :     case OOX_TOKEN( doc, rPr ):
     144         893 :         return new TextCharacterPropertiesContext( *this, rAttribs, mpRunPtr->getTextCharacterProperties() );
     145             :     case A_TOKEN( t ):      // "xsd:string" minOccurs="1" The actual text string.
     146             :     case OOX_TOKEN( doc, t ):
     147         896 :         mbIsInText = true;
     148         896 :         break;
     149             :     default:
     150             :         SAL_WARN("oox", "RegularTextRunContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
     151           0 :         break;
     152             :     }
     153             : 
     154         896 :     return this;
     155             : }
     156             : 
     157             : 
     158             : 
     159        1602 : TextBodyContext::TextBodyContext( ContextHandler2Helper& rParent, TextBody& rTextBody )
     160             : : ContextHandler2( rParent )
     161        1602 : , mrTextBody( rTextBody )
     162             : {
     163        1602 : }
     164             : 
     165             : 
     166             : 
     167        4829 : ContextHandlerRef TextBodyContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     168             : {
     169        4829 :     switch( aElementToken )
     170             :     {
     171             :     case A_TOKEN( bodyPr ):     // CT_TextBodyPropertyBag
     172        1472 :         return new TextBodyPropertiesContext( *this, rAttribs, mrTextBody.getTextProperties() );
     173             :     case A_TOKEN( lstStyle ):   // CT_TextListStyle
     174        1419 :         return new TextListStyleContext( *this, mrTextBody.getTextListStyle() );
     175             :     case A_TOKEN( p ):          // CT_TextParagraph
     176             :     case OOX_TOKEN( doc, p ):
     177        1870 :         return new TextParagraphContext( *this, mrTextBody.addParagraph() );
     178             :     case OOX_TOKEN( doc, sdt ):
     179             :     case OOX_TOKEN( doc, sdtContent ):
     180          36 :         return this;
     181             :     case OOX_TOKEN( doc, sdtPr ):
     182             :     case OOX_TOKEN( doc, sdtEndPr ):
     183          32 :         break;
     184             :     default:
     185             :         SAL_WARN("oox", "TextBodyContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
     186             :     }
     187             : 
     188          32 :     return 0;
     189             : }
     190             : 
     191             : 
     192             : 
     193         177 : } }
     194             : 
     195             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10