1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
30 #include <comphelper/sequence.hxx>
35 using namespace com::sun::star
;
37 TextFontModel::TextFontModel()
41 TextPortionModel::TextPortionModel( const TextParagraphModel
& rParagraph
, const TextFontModel
& rFont
, const OUString
& rText
) :
42 maParagraph( rParagraph
),
48 TextBox::TextBox(ShapeTypeModel
& rTypeModel
)
49 : mrTypeModel(rTypeModel
)
50 , borderDistanceSet( false )
51 , borderDistanceLeft(0)
52 , borderDistanceTop(0)
53 , borderDistanceRight(0)
54 , borderDistanceBottom(0)
58 void TextBox::appendPortion( const TextParagraphModel
& rParagraph
, const TextFontModel
& rFont
, const OUString
& rText
)
60 maPortions
.emplace_back( rParagraph
, rFont
, rText
);
63 const TextFontModel
* TextBox::getFirstFont() const
65 return maPortions
.empty() ? nullptr : &maPortions
.front().maFont
;
68 OUString
TextBox::getText() const
70 OUStringBuffer aBuffer
;
71 for (auto const& portion
: maPortions
)
72 aBuffer
.append( portion
.maText
);
73 return aBuffer
.makeStringAndClear();
76 void TextBox::convert(const uno::Reference
<drawing::XShape
>& xShape
) const
78 uno::Reference
<text::XTextAppend
> xTextAppend(xShape
, uno::UNO_QUERY
);
79 for (auto const& portion
: maPortions
)
81 beans::PropertyValue aPropertyValue
;
82 std::vector
<beans::PropertyValue
> aPropVec
;
83 const TextParagraphModel
& rParagraph
= portion
.maParagraph
;
84 const TextFontModel
& rFont
= portion
.maFont
;
85 if (rFont
.moName
.has())
87 aPropertyValue
.Name
= "CharFontName";
88 aPropertyValue
.Value
<<= rFont
.moName
.get();
89 aPropVec
.push_back(aPropertyValue
);
91 aPropertyValue
.Name
= "CharFontNameAsian";
92 aPropertyValue
.Value
<<= rFont
.moNameAsian
.get();
93 aPropVec
.push_back(aPropertyValue
);
95 aPropertyValue
.Name
= "CharFontNameComplex";
96 aPropertyValue
.Value
<<= rFont
.moNameComplex
.get();
97 aPropVec
.push_back(aPropertyValue
);
99 if (rFont
.mobBold
.has())
101 aPropertyValue
.Name
= "CharWeight";
102 aPropertyValue
.Value
<<= rFont
.mobBold
.get() ? awt::FontWeight::BOLD
: awt::FontWeight::NORMAL
;
103 aPropVec
.push_back(aPropertyValue
);
105 if (rFont
.monSize
.has())
107 aPropertyValue
.Name
= "CharHeight";
108 aPropertyValue
.Value
<<= double(rFont
.monSize
.get()) / 2.;
109 aPropVec
.push_back(aPropertyValue
);
111 if (rFont
.monSpacing
.has())
113 aPropertyValue
.Name
= "CharKerning";
114 // Value is not converted to mm100: SvxKerningItem::PutValue() gets
115 // called with nMemberId = 0, so no mm100 -> twips conversion will
117 aPropertyValue
.Value
<<= sal_Int16(rFont
.monSpacing
.get());
118 aPropVec
.push_back(aPropertyValue
);
120 if (rParagraph
.moParaAdjust
.has())
122 style::ParagraphAdjust eAdjust
= style::ParagraphAdjust_LEFT
;
123 if (rParagraph
.moParaAdjust
.get() == "center")
124 eAdjust
= style::ParagraphAdjust_CENTER
;
125 else if (rParagraph
.moParaAdjust
.get() == "right")
126 eAdjust
= style::ParagraphAdjust_RIGHT
;
128 aPropertyValue
.Name
= "ParaAdjust";
129 aPropertyValue
.Value
<<= eAdjust
;
130 aPropVec
.push_back(aPropertyValue
);
132 if (rFont
.moColor
.has())
134 aPropertyValue
.Name
= "CharColor";
135 aPropertyValue
.Value
<<= rFont
.moColor
.get().toUInt32(16);
136 aPropVec
.push_back(aPropertyValue
);
138 xTextAppend
->appendTextPortion(portion
.maText
, comphelper::containerToSequence(aPropVec
));
141 // Remove the last character of the shape text, if it would be a newline.
142 uno::Reference
< text::XTextCursor
> xCursor
= xTextAppend
->createTextCursor();
143 xCursor
->gotoEnd(false);
144 xCursor
->goLeft(1, true);
145 if (xCursor
->getString() == "\n")
146 xCursor
->setString("");
148 if ( maLayoutFlow
== "vertical" )
150 uno::Reference
<beans::XPropertySet
> xProperties(xShape
, uno::UNO_QUERY
);
152 // VML has the text horizontally aligned to left (all the time),
153 // v-text-anchor for vertical alignment, and vertical mode to swap the
154 // two. drawinglayer supports both horizontal and vertical alignment,
155 // but no vertical mode: we use T->B, R->L instead.
156 // As a result, we need to set horizontal adjustment here to 'right',
157 // that will result in vertical 'top' after writing mode is applied,
158 // which matches the VML behavior.
159 xProperties
->setPropertyValue("TextHorizontalAdjust", uno::makeAny(drawing::TextHorizontalAdjust_RIGHT
));
161 xProperties
->setPropertyValue( "TextWritingMode", uno::makeAny( text::WritingMode_TB_RL
) );
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */