LCOV - code coverage report
Current view: top level - oox/source/vml - vmltextboxcontext.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 113 0.0 %
Date: 2014-04-14 Functions: 0 9 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/vml/vmlformatting.hxx"
      21             : #include "oox/vml/vmltextboxcontext.hxx"
      22             : #include "oox/vml/vmlshape.hxx"
      23             : #include <com/sun/star/drawing/XShape.hpp>
      24             : 
      25             : namespace oox {
      26             : namespace vml {
      27             : 
      28             : 
      29             : 
      30             : using ::oox::core::ContextHandler2;
      31             : using ::oox::core::ContextHandler2Helper;
      32             : using ::oox::core::ContextHandlerRef;
      33             : 
      34             : 
      35             : 
      36           0 : TextPortionContext::TextPortionContext( ContextHandler2Helper& rParent,
      37             :         TextBox& rTextBox, TextParagraphModel& rParagraph, const TextFontModel& rParentFont,
      38             :         sal_Int32 nElement, const AttributeList& rAttribs ) :
      39             :     ContextHandler2( rParent ),
      40             :     mrTextBox( rTextBox ),
      41             :     maParagraph( rParagraph ),
      42             :     maFont( rParentFont ),
      43           0 :     mnInitialPortions( rTextBox.getPortionCount() )
      44             : {
      45           0 :     switch( nElement )
      46             :     {
      47             :         case XML_font:
      48           0 :             maFont.moName = rAttribs.getXString( XML_face );
      49           0 :             maFont.moColor = rAttribs.getXString( XML_color );
      50           0 :             maFont.monSize = rAttribs.getInteger( XML_size );
      51           0 :         break;
      52             :         case XML_u:
      53             :             OSL_ENSURE( !maFont.monUnderline, "TextPortionContext::TextPortionContext - nested <u> elements" );
      54           0 :             maFont.monUnderline = (rAttribs.getToken( XML_class, XML_TOKEN_INVALID ) == XML_font4) ? XML_double : XML_single;
      55           0 :         break;
      56             :         case XML_sub:
      57             :         case XML_sup:
      58             :             OSL_ENSURE( !maFont.monEscapement, "TextPortionContext::TextPortionContext - nested <sub> or <sup> elements" );
      59           0 :             maFont.monEscapement = nElement;
      60           0 :         break;
      61             :         case XML_b:
      62             :             OSL_ENSURE( !maFont.mobBold, "TextPortionContext::TextPortionContext - nested <b> elements" );
      63           0 :             maFont.mobBold = true;
      64           0 :         break;
      65             :         case XML_i:
      66             :             OSL_ENSURE( !maFont.mobItalic, "TextPortionContext::TextPortionContext - nested <i> elements" );
      67           0 :             maFont.mobItalic = true;
      68           0 :         break;
      69             :         case XML_s:
      70             :             OSL_ENSURE( !maFont.mobStrikeout, "TextPortionContext::TextPortionContext - nested <s> elements" );
      71           0 :             maFont.mobStrikeout = true;
      72           0 :         break;
      73             :         case OOX_TOKEN(dml, blip):
      74             :             {
      75           0 :                 OptValue<OUString> oRelId = rAttribs.getString(R_TOKEN(embed));
      76           0 :                 if (oRelId.has())
      77           0 :                     mrTextBox.mrTypeModel.moGraphicPath = getFragmentPathFromRelId(oRelId.get());
      78             :             }
      79           0 :         break;
      80             :         case VML_TOKEN(imagedata):
      81             :             {
      82           0 :                 OptValue<OUString> oRelId = rAttribs.getString(R_TOKEN(id));
      83           0 :                 if (oRelId.has())
      84           0 :                     mrTextBox.mrTypeModel.moGraphicPath = getFragmentPathFromRelId(oRelId.get());
      85             :             }
      86           0 :         break;
      87             :         case XML_span:
      88             :         case OOX_TOKEN(doc, r):
      89           0 :         break;
      90             :         default:
      91             :             OSL_ENSURE( false, "TextPortionContext::TextPortionContext - unknown element" );
      92             :     }
      93           0 : }
      94             : 
      95           0 : ContextHandlerRef TextPortionContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      96             : {
      97             :     OSL_ENSURE( nElement != XML_font, "TextPortionContext::onCreateContext - nested <font> elements" );
      98           0 :     if (getNamespace(getCurrentElement()) == NMSP_doc)
      99           0 :         return this;
     100           0 :     return new TextPortionContext( *this, mrTextBox, maParagraph, maFont, nElement, rAttribs );
     101             : }
     102             : 
     103           0 : void TextPortionContext::onCharacters( const OUString& rChars )
     104             : {
     105           0 :     if (getNamespace(getCurrentElement()) == NMSP_doc && getCurrentElement() != OOX_TOKEN(doc, t))
     106           0 :         return;
     107             : 
     108           0 :     switch( getCurrentElement() )
     109             :     {
     110             :         case XML_span:
     111             :             // replace all NBSP characters with SP
     112           0 :             mrTextBox.appendPortion( maParagraph, maFont, rChars.replace( 0xA0, ' ' ) );
     113           0 :         break;
     114             :         default:
     115           0 :             mrTextBox.appendPortion( maParagraph, maFont, rChars );
     116             :     }
     117             : }
     118             : 
     119           0 : void TextPortionContext::onStartElement(const AttributeList& rAttribs)
     120             : {
     121           0 :     switch (getCurrentElement())
     122             :     {
     123             :         case OOX_TOKEN(doc, b):
     124           0 :             maFont.mobBold = true;
     125           0 :         break;
     126             :         case OOX_TOKEN(doc, sz):
     127           0 :             maFont.monSize = rAttribs.getInteger( OOX_TOKEN(doc, val) );
     128           0 :         break;
     129             :         case OOX_TOKEN(doc, br):
     130           0 :             mrTextBox.appendPortion( maParagraph, maFont, "\n" );
     131           0 :         break;
     132             :         case OOX_TOKEN(doc, color):
     133           0 :             maFont.moColor = rAttribs.getString( OOX_TOKEN(doc, val) );
     134           0 :         break;
     135             :         case OOX_TOKEN(doc, spacing):
     136           0 :             maFont.monSpacing = rAttribs.getInteger(OOX_TOKEN(doc, val));
     137           0 :         break;
     138             :         case OOX_TOKEN(doc, r):
     139             :         case OOX_TOKEN(doc, rPr):
     140             :         case OOX_TOKEN(doc, t):
     141           0 :         break;
     142             :         default:
     143             :             SAL_INFO("oox", "unhandled: 0x" << std::hex<< getCurrentElement());
     144           0 :         break;
     145             :     }
     146           0 : }
     147             : 
     148           0 : void TextPortionContext::onEndElement()
     149             : {
     150           0 :     if (getNamespace(getCurrentElement()) == NMSP_doc && getCurrentElement() != OOX_TOKEN(doc, t))
     151           0 :         return;
     152             : 
     153             :     /*  A child element without own child elements may contain a single space
     154             :         character, for example:
     155             : 
     156             :           <div>
     157             :             <font><i>abc</i></font>
     158             :             <font> </font>
     159             :             <font><b>def</b></font>
     160             :           </div>
     161             : 
     162             :         represents the italic text 'abc', an unformatted space character, and
     163             :         the bold text 'def'. Unfortunately, the XML parser skips the space
     164             :         character without issuing a 'characters' event. The class member
     165             :         'mnInitialPortions' contains the number of text portions existing when
     166             :         this context has been constructed. If no text has been added in the
     167             :         meantime, the space character has to be added manually.
     168             :      */
     169           0 :     if( mrTextBox.getPortionCount() == mnInitialPortions )
     170           0 :         mrTextBox.appendPortion( maParagraph, maFont, OUString( ' ' ) );
     171             : }
     172             : 
     173             : 
     174             : 
     175           0 : TextBoxContext::TextBoxContext( ContextHandler2Helper& rParent, TextBox& rTextBox, const AttributeList& rAttribs,
     176             :     const GraphicHelper& graphicHelper ) :
     177             :     ContextHandler2( rParent ),
     178           0 :     mrTextBox( rTextBox )
     179             : {
     180           0 :     if( rAttribs.getString( XML_insetmode ).get() != "auto" )
     181             :     {
     182           0 :         OUString inset = rAttribs.getString( XML_inset ).get();
     183           0 :         OUString value;
     184           0 :         OUString remainingStr;
     185             : 
     186           0 :         ConversionHelper::separatePair( value, remainingStr, inset, ',' );
     187             :         rTextBox.borderDistanceLeft = ConversionHelper::decodeMeasureToHmm( graphicHelper,
     188           0 :             value.isEmpty() ? "0.1in" : value, 0, false, false );
     189             : 
     190           0 :         inset = remainingStr;
     191           0 :         ConversionHelper::separatePair( value, remainingStr, inset, ',' );
     192             :         rTextBox.borderDistanceTop = ConversionHelper::decodeMeasureToHmm( graphicHelper,
     193           0 :             value.isEmpty() ? "0.05in" : value, 0, false, false );
     194             : 
     195           0 :         inset = remainingStr;
     196           0 :         ConversionHelper::separatePair( value, remainingStr, inset, ',' );
     197             :         rTextBox.borderDistanceRight = ConversionHelper::decodeMeasureToHmm( graphicHelper,
     198           0 :             value.isEmpty() ? "0.1in" : value, 0, false, false );
     199             : 
     200           0 :         inset = remainingStr;
     201           0 :         ConversionHelper::separatePair( value, remainingStr, inset, ',' );
     202             :         rTextBox.borderDistanceBottom = ConversionHelper::decodeMeasureToHmm( graphicHelper,
     203           0 :             value.isEmpty() ? "0.05in" : value, 0, false, false );
     204             : 
     205           0 :         rTextBox.borderDistanceSet = true;
     206             :     }
     207             : 
     208           0 :     OUString sStyle = rAttribs.getString( XML_style, OUString() );
     209           0 :     sal_Int32 nIndex = 0;
     210           0 :     while( nIndex >= 0 )
     211             :     {
     212           0 :         OUString aName, aValue;
     213           0 :         if( ConversionHelper::separatePair( aName, aValue, sStyle.getToken( 0, ';', nIndex ), ':' ) )
     214             :         {
     215           0 :             if( aName == "layout-flow" )      rTextBox.maLayoutFlow = aValue;
     216           0 :             else if (aName == "mso-fit-shape-to-text")
     217           0 :                 rTextBox.mrTypeModel.mbAutoHeight = true;
     218           0 :             else if (aName == "mso-layout-flow-alt")
     219           0 :                 rTextBox.mrTypeModel.maLayoutFlowAlt = aValue;
     220             :             else
     221             :                 SAL_WARN("oox", "unhandled style property: " << aName);
     222             :         }
     223           0 :     }
     224           0 : }
     225             : 
     226           0 : ContextHandlerRef TextBoxContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     227             : {
     228           0 :     switch( getCurrentElement() )
     229             :     {
     230             :         case VML_TOKEN( textbox ):
     231           0 :             if( nElement == XML_div ) return this;
     232           0 :             else if (nElement == OOX_TOKEN(doc, txbxContent)) return this;
     233           0 :         break;
     234             :         case XML_div:
     235           0 :             if( nElement == XML_font ) return new TextPortionContext( *this, mrTextBox, maParagraph, TextFontModel(), nElement, rAttribs );
     236           0 :         break;
     237             :         case OOX_TOKEN(doc, txbxContent):
     238           0 :             if (nElement == OOX_TOKEN(doc, p)) return this;
     239           0 :         break;
     240             :         case OOX_TOKEN(doc, p):
     241             :         case OOX_TOKEN(doc, sdtContent):
     242             :         case OOX_TOKEN(doc, smartTag):
     243           0 :             if (nElement == OOX_TOKEN(doc, r))
     244           0 :                 return new TextPortionContext( *this, mrTextBox, maParagraph, TextFontModel(), nElement, rAttribs );
     245             :             else
     246           0 :                 return this;
     247             :         break;
     248             :         case OOX_TOKEN(doc, pPr):
     249             :         case OOX_TOKEN(doc, sdt):
     250           0 :             return this;
     251             :         break;
     252             :         default:
     253             :             SAL_INFO("oox", "unhandled 0x" << std::hex << getCurrentElement());
     254           0 :         break;
     255             :     }
     256           0 :     return 0;
     257             : }
     258             : 
     259           0 : void TextBoxContext::onStartElement(const AttributeList& rAttribs)
     260             : {
     261           0 :     switch (getCurrentElement())
     262             :     {
     263             :         case OOX_TOKEN(doc, jc):
     264           0 :             maParagraph.moParaAdjust = rAttribs.getString( OOX_TOKEN(doc, val) );
     265           0 :         break;
     266             :     }
     267           0 : }
     268             : 
     269           0 : void TextBoxContext::onEndElement()
     270             : {
     271           0 :     if (getCurrentElement() == OOX_TOKEN(doc, p))
     272             :     {
     273           0 :         mrTextBox.appendPortion( maParagraph, TextFontModel(), "\n" );
     274           0 :         maParagraph = TextParagraphModel();
     275             :     }
     276           0 : }
     277             : 
     278             : 
     279             : 
     280             : } // namespace vml
     281             : } // namespace oox
     282             : 
     283             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10