LCOV - code coverage report
Current view: top level - oox/source/vml - vmltextbox.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 67 67 100.0 %
Date: 2015-06-13 12:38:46 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 <svx/unopage.hxx>
      24             : #include <com/sun/star/awt/FontWeight.hpp>
      25             : #include <com/sun/star/beans/XPropertySet.hpp>
      26             : #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
      27             : #include <com/sun/star/text/XTextAppend.hpp>
      28             : #include <com/sun/star/text/WritingMode.hpp>
      29             : #include <com/sun/star/style/ParagraphAdjust.hpp>
      30             : 
      31             : namespace oox {
      32             : namespace vml {
      33             : 
      34             : using namespace com::sun::star;
      35             : 
      36         676 : TextFontModel::TextFontModel()
      37             : {
      38         676 : }
      39             : 
      40         525 : TextPortionModel::TextPortionModel( const TextParagraphModel& rParagraph, const TextFontModel& rFont, const OUString& rText ) :
      41             :     maParagraph( rParagraph ),
      42             :     maFont( rFont ),
      43         525 :     maText( rText )
      44             : {
      45         525 : }
      46             : 
      47         262 : TextBox::TextBox(ShapeTypeModel& rTypeModel)
      48             :     : mrTypeModel(rTypeModel)
      49             :     , borderDistanceSet( false )
      50             :     , borderDistanceLeft(0)
      51             :     , borderDistanceTop(0)
      52             :     , borderDistanceRight(0)
      53         262 :     , borderDistanceBottom(0)
      54             : {
      55         262 : }
      56             : 
      57         525 : void TextBox::appendPortion( const TextParagraphModel& rParagraph, const TextFontModel& rFont, const OUString& rText )
      58             : {
      59         525 :     maPortions.push_back( TextPortionModel( rParagraph, rFont, rText ) );
      60         525 : }
      61             : 
      62           1 : const TextFontModel* TextBox::getFirstFont() const
      63             : {
      64           1 :     return maPortions.empty() ? 0 : &maPortions.front().maFont;
      65             : }
      66             : 
      67           1 : OUString TextBox::getText() const
      68             : {
      69           1 :     OUStringBuffer aBuffer;
      70           2 :     for( PortionVector::const_iterator aIt = maPortions.begin(), aEnd = maPortions.end(); aIt != aEnd; ++aIt )
      71           1 :         aBuffer.append( aIt->maText );
      72           1 :     return aBuffer.makeStringAndClear();
      73             : }
      74             : 
      75         182 : void TextBox::convert(uno::Reference<drawing::XShape> xShape) const
      76             : {
      77         182 :     uno::Reference<text::XTextAppend> xTextAppend(xShape, uno::UNO_QUERY);
      78         582 :     for (PortionVector::const_iterator aIt = maPortions.begin(), aEnd = maPortions.end(); aIt != aEnd; ++aIt)
      79             :     {
      80         400 :         beans::PropertyValue aPropertyValue;
      81         800 :         std::vector<beans::PropertyValue> aPropVec;
      82         400 :         const TextParagraphModel& rParagraph = aIt->maParagraph;
      83         400 :         const TextFontModel& rFont = aIt->maFont;
      84         400 :         if (rFont.mobBold.has())
      85             :         {
      86          23 :             aPropertyValue.Name = "CharWeight";
      87          23 :             aPropertyValue.Value = uno::makeAny(rFont.mobBold.get() ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL);
      88          23 :             aPropVec.push_back(aPropertyValue);
      89             :         }
      90         400 :         if (rFont.monSize.has())
      91             :         {
      92         197 :             aPropertyValue.Name = "CharHeight";
      93         197 :             aPropertyValue.Value = uno::makeAny(double(rFont.monSize.get()) / 2.);
      94         197 :             aPropVec.push_back(aPropertyValue);
      95             :         }
      96         400 :         if (rFont.monSpacing.has())
      97             :         {
      98           2 :             aPropertyValue.Name = "CharKerning";
      99             :             // Value is not converted to mm100: SvxKerningItem::PutValue() gets
     100             :             // called with nMemberId = 0, so no mm100 -> twips conversion will
     101             :             // be done there.
     102           2 :             aPropertyValue.Value = uno::makeAny(sal_Int16(rFont.monSpacing.get()));
     103           2 :             aPropVec.push_back(aPropertyValue);
     104             :         }
     105         400 :         if (rParagraph.moParaAdjust.has())
     106             :         {
     107         117 :             style::ParagraphAdjust eAdjust = style::ParagraphAdjust_LEFT;
     108         117 :             if (rParagraph.moParaAdjust.get() == "center")
     109         115 :                 eAdjust = style::ParagraphAdjust_CENTER;
     110           2 :             else if (rParagraph.moParaAdjust.get() == "right")
     111           2 :                 eAdjust = style::ParagraphAdjust_RIGHT;
     112             : 
     113         117 :             aPropertyValue.Name = "ParaAdjust";
     114         117 :             aPropertyValue.Value = uno::makeAny(eAdjust);
     115         117 :             aPropVec.push_back(aPropertyValue);
     116             :         }
     117         400 :         if (rFont.moColor.has())
     118             :         {
     119         131 :             aPropertyValue.Name = "CharColor";
     120         131 :             aPropertyValue.Value = uno::makeAny(rFont.moColor.get().toUInt32(16));
     121         131 :             aPropVec.push_back(aPropertyValue);
     122             :         }
     123         800 :         uno::Sequence<beans::PropertyValue> aPropSeq(aPropVec.size());
     124         400 :         beans::PropertyValue* pValues = aPropSeq.getArray();
     125         870 :         for (std::vector<beans::PropertyValue>::iterator i = aPropVec.begin(); i != aPropVec.end(); ++i)
     126         470 :             *pValues++ = *i;
     127         400 :         xTextAppend->appendTextPortion(aIt->maText, aPropSeq);
     128         400 :     }
     129             : 
     130             :     // Remove the last character of the shape text, if it would be a newline.
     131         364 :     uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursor();
     132         182 :     xCursor->gotoEnd(false);
     133         182 :     xCursor->goLeft(1, true);
     134         182 :     if (xCursor->getString() == "\n")
     135         182 :         xCursor->setString("");
     136             : 
     137         182 :     if ( maLayoutFlow == "vertical" )
     138             :     {
     139           2 :         uno::Reference<beans::XPropertySet> xProperties(xShape, uno::UNO_QUERY);
     140             : 
     141             :         // VML has the text horizontally aligned to left (all the time),
     142             :         // v-text-anchor for vertical alignment, and vertical mode to swap the
     143             :         // two.  drawinglayer supports both horizontal and vertical alignment,
     144             :         // but no vertical mode: we use T->B, R->L instead.
     145             :         // As a result, we need to set horizontal adjustment here to 'right',
     146             :         // that will result in vertical 'top' after writing mode is applied,
     147             :         // which matches the VML behavior.
     148           2 :         xProperties->setPropertyValue("TextHorizontalAdjust", uno::makeAny(drawing::TextHorizontalAdjust_RIGHT));
     149             : 
     150           2 :         xProperties->setPropertyValue( "TextWritingMode", uno::makeAny( text::WritingMode_TB_RL ) );
     151         182 :     }
     152         182 : }
     153             : 
     154             : } // namespace vml
     155             : } // namespace oox
     156             : 
     157             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11