LCOV - code coverage report
Current view: top level - oox/source/vml - vmltextbox.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 67 0.0 %
Date: 2014-04-14 Functions: 0 7 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/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           0 : TextFontModel::TextFontModel()
      37             : {
      38           0 : }
      39             : 
      40           0 : TextPortionModel::TextPortionModel( const TextParagraphModel& rParagraph, const TextFontModel& rFont, const OUString& rText ) :
      41             :     maParagraph( rParagraph ),
      42             :     maFont( rFont ),
      43           0 :     maText( rText )
      44             : {
      45           0 : }
      46             : 
      47           0 : TextBox::TextBox(ShapeTypeModel& rTypeModel)
      48             :     : mrTypeModel(rTypeModel)
      49             :     , borderDistanceSet( false )
      50             :     , borderDistanceLeft(0)
      51             :     , borderDistanceTop(0)
      52             :     , borderDistanceRight(0)
      53           0 :     , borderDistanceBottom(0)
      54             : {
      55           0 : }
      56             : 
      57           0 : void TextBox::appendPortion( const TextParagraphModel& rParagraph, const TextFontModel& rFont, const OUString& rText )
      58             : {
      59           0 :     maPortions.push_back( TextPortionModel( rParagraph, rFont, rText ) );
      60           0 : }
      61             : 
      62           0 : const TextFontModel* TextBox::getFirstFont() const
      63             : {
      64           0 :     return maPortions.empty() ? 0 : &maPortions.front().maFont;
      65             : }
      66             : 
      67           0 : OUString TextBox::getText() const
      68             : {
      69           0 :     OUStringBuffer aBuffer;
      70           0 :     for( PortionVector::const_iterator aIt = maPortions.begin(), aEnd = maPortions.end(); aIt != aEnd; ++aIt )
      71           0 :         aBuffer.append( aIt->maText );
      72           0 :     return aBuffer.makeStringAndClear();
      73             : }
      74             : 
      75           0 : void TextBox::convert(uno::Reference<drawing::XShape> xShape) const
      76             : {
      77           0 :     uno::Reference<text::XTextAppend> xTextAppend(xShape, uno::UNO_QUERY);
      78           0 :     for (PortionVector::const_iterator aIt = maPortions.begin(), aEnd = maPortions.end(); aIt != aEnd; ++aIt)
      79             :     {
      80           0 :         beans::PropertyValue aPropertyValue;
      81           0 :         std::vector<beans::PropertyValue> aPropVec;
      82           0 :         const TextParagraphModel& rParagraph = aIt->maParagraph;
      83           0 :         const TextFontModel& rFont = aIt->maFont;
      84           0 :         if (rFont.mobBold.has())
      85             :         {
      86           0 :             aPropertyValue.Name = "CharWeight";
      87           0 :             aPropertyValue.Value = uno::makeAny(rFont.mobBold.get() ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL);
      88           0 :             aPropVec.push_back(aPropertyValue);
      89             :         }
      90           0 :         if (rFont.monSize.has())
      91             :         {
      92           0 :             aPropertyValue.Name = "CharHeight";
      93           0 :             aPropertyValue.Value = uno::makeAny(double(rFont.monSize.get()) / 2.);
      94           0 :             aPropVec.push_back(aPropertyValue);
      95             :         }
      96           0 :         if (rFont.monSpacing.has())
      97             :         {
      98           0 :             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           0 :             aPropertyValue.Value = uno::makeAny(sal_Int16(rFont.monSpacing.get()));
     103           0 :             aPropVec.push_back(aPropertyValue);
     104             :         }
     105           0 :         if (rParagraph.moParaAdjust.has())
     106             :         {
     107           0 :             style::ParagraphAdjust eAdjust = style::ParagraphAdjust_LEFT;
     108           0 :             if (rParagraph.moParaAdjust.get() == "center")
     109           0 :                 eAdjust = style::ParagraphAdjust_CENTER;
     110           0 :             else if (rParagraph.moParaAdjust.get() == "right")
     111           0 :                 eAdjust = style::ParagraphAdjust_RIGHT;
     112             : 
     113           0 :             aPropertyValue.Name = "ParaAdjust";
     114           0 :             aPropertyValue.Value = uno::makeAny(eAdjust);
     115           0 :             aPropVec.push_back(aPropertyValue);
     116             :         }
     117           0 :         if (rFont.moColor.has())
     118             :         {
     119           0 :             aPropertyValue.Name = "CharColor";
     120           0 :             aPropertyValue.Value = uno::makeAny(rFont.moColor.get().toUInt32(16));
     121           0 :             aPropVec.push_back(aPropertyValue);
     122             :         }
     123           0 :         uno::Sequence<beans::PropertyValue> aPropSeq(aPropVec.size());
     124           0 :         beans::PropertyValue* pValues = aPropSeq.getArray();
     125           0 :         for (std::vector<beans::PropertyValue>::iterator i = aPropVec.begin(); i != aPropVec.end(); ++i)
     126           0 :             *pValues++ = *i;
     127           0 :         xTextAppend->appendTextPortion(aIt->maText, aPropSeq);
     128           0 :     }
     129             : 
     130             :     // Remove the last character of the shape text, if it would be a newline.
     131           0 :     uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursor();
     132           0 :     xCursor->gotoEnd(false);
     133           0 :     xCursor->goLeft(1, true);
     134           0 :     if (xCursor->getString() == "\n")
     135           0 :         xCursor->setString("");
     136             : 
     137           0 :     if ( maLayoutFlow == "vertical" )
     138             :     {
     139           0 :         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           0 :         xProperties->setPropertyValue("TextHorizontalAdjust", uno::makeAny(drawing::TextHorizontalAdjust_RIGHT));
     149             : 
     150           0 :         xProperties->setPropertyValue( "TextWritingMode", uno::makeAny( text::WritingMode_TB_RL ) );
     151           0 :     }
     152           0 : }
     153             : 
     154             : } // namespace vml
     155             : } // namespace oox
     156             : 
     157             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10