LCOV - code coverage report
Current view: top level - oox/source/vml - vmltextboxcontext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 23 41 56.1 %
Date: 2012-08-25 Functions: 5 6 83.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 49 24.5 %

           Branch data     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/vml/vmltextboxcontext.hxx"
      21                 :            : 
      22                 :            : namespace oox {
      23                 :            : namespace vml {
      24                 :            : 
      25                 :            : // ============================================================================
      26                 :            : 
      27                 :            : using ::oox::core::ContextHandler2;
      28                 :            : using ::oox::core::ContextHandler2Helper;
      29                 :            : using ::oox::core::ContextHandlerRef;
      30                 :            : using ::rtl::OUString;
      31                 :            : 
      32                 :            : // ============================================================================
      33                 :            : 
      34                 :          3 : TextPortionContext::TextPortionContext( ContextHandler2Helper& rParent,
      35                 :            :         TextBox& rTextBox, const TextFontModel& rParentFont,
      36                 :            :         sal_Int32 nElement, const AttributeList& rAttribs ) :
      37                 :            :     ContextHandler2( rParent ),
      38                 :            :     mrTextBox( rTextBox ),
      39                 :            :     maFont( rParentFont ),
      40         [ +  - ]:          3 :     mnInitialPortions( rTextBox.getPortionCount() )
      41                 :            : {
      42   [ +  -  -  -  :          3 :     switch( nElement )
             -  -  -  - ]
      43                 :            :     {
      44                 :            :         case XML_font:
      45         [ +  - ]:          3 :             maFont.moName = rAttribs.getXString( XML_face );
      46         [ +  - ]:          3 :             maFont.moColor = rAttribs.getXString( XML_color );
      47         [ +  - ]:          3 :             maFont.monSize = rAttribs.getInteger( XML_size );
      48                 :          3 :         break;
      49                 :            :         case XML_u:
      50                 :            :             OSL_ENSURE( !maFont.monUnderline, "TextPortionContext::TextPortionContext - nested <u> elements" );
      51 [ #  # ][ #  # ]:          0 :             maFont.monUnderline = (rAttribs.getToken( XML_class, XML_TOKEN_INVALID ) == XML_font4) ? XML_double : XML_single;
                 [ #  # ]
      52                 :          0 :         break;
      53                 :            :         case XML_sub:
      54                 :            :         case XML_sup:
      55                 :            :             OSL_ENSURE( !maFont.monEscapement, "TextPortionContext::TextPortionContext - nested <sub> or <sup> elements" );
      56         [ #  # ]:          0 :             maFont.monEscapement = nElement;
      57                 :          0 :         break;
      58                 :            :         case XML_b:
      59                 :            :             OSL_ENSURE( !maFont.mobBold, "TextPortionContext::TextPortionContext - nested <b> elements" );
      60         [ #  # ]:          0 :             maFont.mobBold = true;
      61                 :          0 :         break;
      62                 :            :         case XML_i:
      63                 :            :             OSL_ENSURE( !maFont.mobItalic, "TextPortionContext::TextPortionContext - nested <i> elements" );
      64         [ #  # ]:          0 :             maFont.mobItalic = true;
      65                 :          0 :         break;
      66                 :            :         case XML_s:
      67                 :            :             OSL_ENSURE( !maFont.mobStrikeout, "TextPortionContext::TextPortionContext - nested <s> elements" );
      68         [ #  # ]:          0 :             maFont.mobStrikeout = true;
      69                 :          0 :         break;
      70                 :            :         case XML_span:
      71                 :          0 :         break;
      72                 :            :         default:
      73                 :            :             OSL_ENSURE( false, "TextPortionContext::TextPortionContext - unknown element" );
      74                 :            :     }
      75                 :          3 : }
      76                 :            : 
      77                 :          0 : ContextHandlerRef TextPortionContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      78                 :            : {
      79                 :            :     OSL_ENSURE( nElement != XML_font, "TextPortionContext::onCreateContext - nested <font> elements" );
      80         [ #  # ]:          0 :     return new TextPortionContext( *this, mrTextBox, maFont, nElement, rAttribs );
      81                 :            : }
      82                 :            : 
      83                 :          3 : void TextPortionContext::onCharacters( const OUString& rChars )
      84                 :            : {
      85         [ -  + ]:          3 :     switch( getCurrentElement() )
      86                 :            :     {
      87                 :            :         case XML_span:
      88                 :            :             // replace all NBSP characters with SP
      89         [ #  # ]:          0 :             mrTextBox.appendPortion( maFont, rChars.replace( 0xA0, ' ' ) );
      90                 :          0 :         break;
      91                 :            :         default:
      92                 :          3 :             mrTextBox.appendPortion( maFont, rChars );
      93                 :            :     }
      94                 :          3 : }
      95                 :            : 
      96                 :          3 : void TextPortionContext::onEndElement()
      97                 :            : {
      98                 :            :     /*  A child element without own child elements may contain a single space
      99                 :            :         character, for example:
     100                 :            : 
     101                 :            :           <div>
     102                 :            :             <font><i>abc</i></font>
     103                 :            :             <font> </font>
     104                 :            :             <font><b>def</b></font>
     105                 :            :           </div>
     106                 :            : 
     107                 :            :         represents the italic text 'abc', an unformatted space character, and
     108                 :            :         the bold text 'def'. Unfortunately, the XML parser skips the space
     109                 :            :         character without issuing a 'characters' event. The class member
     110                 :            :         'mnInitialPortions' contains the number of text portions existing when
     111                 :            :         this context has been constructed. If no text has been added in the
     112                 :            :         meantime, the space character has to be added manually.
     113                 :            :      */
     114         [ -  + ]:          3 :     if( mrTextBox.getPortionCount() == mnInitialPortions )
     115         [ #  # ]:          0 :         mrTextBox.appendPortion( maFont, OUString( sal_Unicode( ' ' ) ) );
     116                 :          3 : }
     117                 :            : 
     118                 :            : // ============================================================================
     119                 :            : 
     120                 :         27 : TextBoxContext::TextBoxContext( ContextHandler2Helper& rParent, TextBox& rTextBox, const AttributeList& /*rAttribs*/ ) :
     121                 :            :     ContextHandler2( rParent ),
     122                 :         27 :     mrTextBox( rTextBox )
     123                 :            : {
     124                 :         27 : }
     125                 :            : 
     126                 :          6 : ContextHandlerRef TextBoxContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     127                 :            : {
     128      [ +  +  - ]:          6 :     switch( getCurrentElement() )
     129                 :            :     {
     130                 :            :         case VML_TOKEN( textbox ):
     131         [ +  - ]:          3 :             if( nElement == XML_div ) return this;
     132                 :          0 :         break;
     133                 :            :         case XML_div:
     134 [ +  - ][ +  - ]:          3 :             if( nElement == XML_font ) return new TextPortionContext( *this, mrTextBox, TextFontModel(), nElement, rAttribs );
     135                 :          0 :         break;
     136                 :            :     }
     137                 :          6 :     return 0;
     138                 :            : }
     139                 :            : 
     140                 :            : // ============================================================================
     141                 :            : 
     142                 :            : } // namespace vml
     143                 :            : } // namespace oox
     144                 :            : 
     145                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10