LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/oox/source/vml - vmltextbox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 60 62 96.8 %
Date: 2013-07-09 Functions: 7 7 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/vml/vmltextbox.hxx"
      21             : 
      22             : #include <rtl/ustrbuf.hxx>
      23             : #include <com/sun/star/awt/FontWeight.hpp>
      24             : #include <com/sun/star/beans/XPropertySet.hpp>
      25             : #include <com/sun/star/text/XTextAppend.hpp>
      26             : #include <com/sun/star/text/WritingMode.hpp>
      27             : #include <com/sun/star/style/ParagraphAdjust.hpp>
      28             : 
      29             : namespace oox {
      30             : namespace vml {
      31             : 
      32             : using namespace com::sun::star;
      33             : 
      34          91 : TextFontModel::TextFontModel()
      35             : {
      36          91 : }
      37             : 
      38         166 : TextPortionModel::TextPortionModel( const TextParagraphModel& rParagraph, const TextFontModel& rFont, const OUString& rText ) :
      39             :     maParagraph( rParagraph ),
      40             :     maFont( rFont ),
      41         166 :     maText( rText )
      42             : {
      43         166 : }
      44             : 
      45          36 : TextBox::TextBox(ShapeTypeModel& rTypeModel)
      46             :     : mrTypeModel(rTypeModel)
      47             :     , borderDistanceSet( false )
      48             :     , borderDistanceLeft(0)
      49             :     , borderDistanceTop(0)
      50             :     , borderDistanceRight(0)
      51          36 :     , borderDistanceBottom(0)
      52             : {
      53          36 : }
      54             : 
      55         166 : void TextBox::appendPortion( const TextParagraphModel& rParagraph, const TextFontModel& rFont, const OUString& rText )
      56             : {
      57         166 :     maPortions.push_back( TextPortionModel( rParagraph, rFont, rText ) );
      58         166 : }
      59             : 
      60           1 : const TextFontModel* TextBox::getFirstFont() const
      61             : {
      62           1 :     return maPortions.empty() ? 0 : &maPortions.front().maFont;
      63             : }
      64             : 
      65           1 : OUString TextBox::getText() const
      66             : {
      67           1 :     OUStringBuffer aBuffer;
      68           2 :     for( PortionVector::const_iterator aIt = maPortions.begin(), aEnd = maPortions.end(); aIt != aEnd; ++aIt )
      69           1 :         aBuffer.append( aIt->maText );
      70           1 :     return aBuffer.makeStringAndClear();
      71             : }
      72             : 
      73          11 : void TextBox::convert(uno::Reference<drawing::XShape> xShape) const
      74             : {
      75          11 :     uno::Reference<text::XTextAppend> xTextAppend(xShape, uno::UNO_QUERY);
      76          52 :     for (PortionVector::const_iterator aIt = maPortions.begin(), aEnd = maPortions.end(); aIt != aEnd; ++aIt)
      77             :     {
      78          41 :         beans::PropertyValue aPropertyValue;
      79          82 :         std::vector<beans::PropertyValue> aPropVec;
      80          41 :         const TextParagraphModel& rParagraph = aIt->maParagraph;
      81          41 :         const TextFontModel& rFont = aIt->maFont;
      82          41 :         if (rFont.mobBold.has())
      83             :         {
      84          11 :             aPropertyValue.Name = "CharWeight";
      85          11 :             aPropertyValue.Value = uno::makeAny(rFont.mobBold.get() ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL);
      86          11 :             aPropVec.push_back(aPropertyValue);
      87             :         }
      88          41 :         if (rFont.monSize.has())
      89             :         {
      90          15 :             aPropertyValue.Name = "CharHeight";
      91          15 :             aPropertyValue.Value = uno::makeAny(double(rFont.monSize.get()) / 2.);
      92          15 :             aPropVec.push_back(aPropertyValue);
      93             :         }
      94          41 :         if (rParagraph.moParaAdjust.has())
      95             :         {
      96          15 :             style::ParagraphAdjust eAdjust = style::ParagraphAdjust_LEFT;
      97          15 :             if (rParagraph.moParaAdjust.get() == "center")
      98          13 :                 eAdjust = style::ParagraphAdjust_CENTER;
      99           2 :             else if (rParagraph.moParaAdjust.get() == "right")
     100           2 :                 eAdjust = style::ParagraphAdjust_RIGHT;
     101             : 
     102          15 :             aPropertyValue.Name = "ParaAdjust";
     103          15 :             aPropertyValue.Value = uno::makeAny(eAdjust);
     104          15 :             aPropVec.push_back(aPropertyValue);
     105             :         }
     106          41 :         if (rFont.moColor.has())
     107             :         {
     108           5 :             aPropertyValue.Name = "CharColor";
     109           5 :             aPropertyValue.Value = uno::makeAny(rFont.moColor.get().toUInt32(16));
     110           5 :             aPropVec.push_back(aPropertyValue);
     111             :         }
     112          82 :         uno::Sequence<beans::PropertyValue> aPropSeq(aPropVec.size());
     113          41 :         beans::PropertyValue* pValues = aPropSeq.getArray();
     114          87 :         for (std::vector<beans::PropertyValue>::iterator i = aPropVec.begin(); i != aPropVec.end(); ++i)
     115          46 :             *pValues++ = *i;
     116          41 :         xTextAppend->appendTextPortion(aIt->maText, aPropSeq);
     117          41 :     }
     118             : 
     119             :     // Remove the last character of the shape text, if it would be a newline.
     120          22 :     uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursor();
     121          11 :     xCursor->gotoEnd(false);
     122          11 :     xCursor->goLeft(1, true);
     123          11 :     if (xCursor->getString() == "\n")
     124          11 :         xCursor->setString("");
     125             : 
     126          11 :     if ( maLayoutFlow == "vertical" )
     127             :     {
     128           0 :         uno::Reference<beans::XPropertySet> xProperties(xShape, uno::UNO_QUERY);
     129           0 :         xProperties->setPropertyValue( "TextWritingMode", uno::makeAny( text::WritingMode_TB_RL ) );
     130          11 :     }
     131          11 : }
     132             : 
     133             : } // namespace vml
     134             : } // namespace oox
     135             : 
     136             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10