fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / oox / source / vml / vmltextbox.cxx
blobfbd8217278836775eed33e7909e8ba3110def545
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "oox/vml/vmltextbox.hxx"
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>
31 namespace oox {
32 namespace vml {
34 using namespace com::sun::star;
36 TextFontModel::TextFontModel()
40 TextPortionModel::TextPortionModel( const TextParagraphModel& rParagraph, const TextFontModel& rFont, const OUString& rText ) :
41 maParagraph( rParagraph ),
42 maFont( rFont ),
43 maText( rText )
47 TextBox::TextBox(ShapeTypeModel& rTypeModel)
48 : mrTypeModel(rTypeModel)
49 , borderDistanceSet( false )
50 , borderDistanceLeft(0)
51 , borderDistanceTop(0)
52 , borderDistanceRight(0)
53 , borderDistanceBottom(0)
57 void TextBox::appendPortion( const TextParagraphModel& rParagraph, const TextFontModel& rFont, const OUString& rText )
59 maPortions.push_back( TextPortionModel( rParagraph, rFont, rText ) );
62 const TextFontModel* TextBox::getFirstFont() const
64 return maPortions.empty() ? 0 : &maPortions.front().maFont;
67 OUString TextBox::getText() const
69 OUStringBuffer aBuffer;
70 for( PortionVector::const_iterator aIt = maPortions.begin(), aEnd = maPortions.end(); aIt != aEnd; ++aIt )
71 aBuffer.append( aIt->maText );
72 return aBuffer.makeStringAndClear();
75 void TextBox::convert(uno::Reference<drawing::XShape> xShape) const
77 uno::Reference<text::XTextAppend> xTextAppend(xShape, uno::UNO_QUERY);
78 for (PortionVector::const_iterator aIt = maPortions.begin(), aEnd = maPortions.end(); aIt != aEnd; ++aIt)
80 beans::PropertyValue aPropertyValue;
81 std::vector<beans::PropertyValue> aPropVec;
82 const TextParagraphModel& rParagraph = aIt->maParagraph;
83 const TextFontModel& rFont = aIt->maFont;
84 if (rFont.mobBold.has())
86 aPropertyValue.Name = "CharWeight";
87 aPropertyValue.Value = uno::makeAny(rFont.mobBold.get() ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL);
88 aPropVec.push_back(aPropertyValue);
90 if (rFont.monSize.has())
92 aPropertyValue.Name = "CharHeight";
93 aPropertyValue.Value = uno::makeAny(double(rFont.monSize.get()) / 2.);
94 aPropVec.push_back(aPropertyValue);
96 if (rFont.monSpacing.has())
98 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 aPropertyValue.Value = uno::makeAny(sal_Int16(rFont.monSpacing.get()));
103 aPropVec.push_back(aPropertyValue);
105 if (rParagraph.moParaAdjust.has())
107 style::ParagraphAdjust eAdjust = style::ParagraphAdjust_LEFT;
108 if (rParagraph.moParaAdjust.get() == "center")
109 eAdjust = style::ParagraphAdjust_CENTER;
110 else if (rParagraph.moParaAdjust.get() == "right")
111 eAdjust = style::ParagraphAdjust_RIGHT;
113 aPropertyValue.Name = "ParaAdjust";
114 aPropertyValue.Value = uno::makeAny(eAdjust);
115 aPropVec.push_back(aPropertyValue);
117 if (rFont.moColor.has())
119 aPropertyValue.Name = "CharColor";
120 aPropertyValue.Value = uno::makeAny(rFont.moColor.get().toUInt32(16));
121 aPropVec.push_back(aPropertyValue);
123 uno::Sequence<beans::PropertyValue> aPropSeq(aPropVec.size());
124 beans::PropertyValue* pValues = aPropSeq.getArray();
125 for (std::vector<beans::PropertyValue>::iterator i = aPropVec.begin(); i != aPropVec.end(); ++i)
126 *pValues++ = *i;
127 xTextAppend->appendTextPortion(aIt->maText, aPropSeq);
130 // Remove the last character of the shape text, if it would be a newline.
131 uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursor();
132 xCursor->gotoEnd(false);
133 xCursor->goLeft(1, true);
134 if (xCursor->getString() == "\n")
135 xCursor->setString("");
137 if ( maLayoutFlow == "vertical" )
139 uno::Reference<beans::XPropertySet> xProperties(xShape, uno::UNO_QUERY);
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 xProperties->setPropertyValue("TextHorizontalAdjust", uno::makeAny(drawing::TextHorizontalAdjust_RIGHT));
150 xProperties->setPropertyValue( "TextWritingMode", uno::makeAny( text::WritingMode_TB_RL ) );
154 } // namespace vml
155 } // namespace oox
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */