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