LibreOffice Module drawinglayer (master) 1
textlineprimitive2d.cxx
Go to the documentation of this file.
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
27#include <utility>
28
29
31{
33 {
35 return;
36
37 bool bDoubleLine(false);
38 bool bWaveLine(false);
39 bool bBoldLine(false);
40 const int* pDotDashArray(nullptr);
42 double fOffset(getOffset());
43 double fHeight(getHeight());
44
45 static const int aDottedArray[] = { 1, 1, 0}; // DOTTED LINE
46 static const int aDotDashArray[] = { 1, 1, 4, 1, 0}; // DASHDOT
47 static const int aDashDotDotArray[] = { 1, 1, 1, 1, 4, 1, 0}; // DASHDOTDOT
48 static const int aDashedArray[] = { 5, 2, 0}; // DASHED LINE
49 static const int aLongDashArray[] = { 7, 2, 0}; // LONGDASH
50
51 // get decomposition
52 basegfx::B2DVector aScale, aTranslate;
53 double fRotate, fShearX;
54 getObjectTransformation().decompose(aScale, aTranslate, fRotate, fShearX);
55
56 switch(getTextLine())
57 {
58 default: // case TEXT_LINE_SINGLE:
59 {
60 break;
61 }
63 {
64 bDoubleLine = true;
65 break;
66 }
68 {
69 pDotDashArray = aDottedArray;
70 break;
71 }
72 case TEXT_LINE_DASH:
73 {
74 pDotDashArray = aDashedArray;
75 break;
76 }
78 {
79 pDotDashArray = aLongDashArray;
80 break;
81 }
83 {
84 pDotDashArray = aDotDashArray;
85 break;
86 }
88 {
89 pDotDashArray = aDashDotDotArray;
90 break;
91 }
93 {
94 bWaveLine = true;
95 break;
96 }
97 case TEXT_LINE_WAVE:
98 {
99 bWaveLine = true;
100 break;
101 }
103 {
104 bDoubleLine = true;
105 bWaveLine = true;
106 break;
107 }
108 case TEXT_LINE_BOLD:
109 {
110 bBoldLine = true;
111 break;
112 }
114 {
115 bBoldLine = true;
116 pDotDashArray = aDottedArray;
117 break;
118 }
120 {
121 bBoldLine = true;
122 pDotDashArray = aDashedArray;
123 break;
124 }
126 {
127 bBoldLine = true;
128 pDotDashArray = aLongDashArray;
129 break;
130 }
132 {
133 bBoldLine = true;
134 pDotDashArray = aDotDashArray;
135 break;
136 }
138 {
139 bBoldLine = true;
140 pDotDashArray = aDashDotDotArray;
141 break;
142 }
144 {
145 bWaveLine = true;
146 bBoldLine = true;
147 break;
148 }
149 }
150
151 if(bBoldLine)
152 {
153 fHeight *= 2.0;
154 }
155
156 if(bDoubleLine)
157 {
158 fOffset -= 0.50 * fHeight;
159 fHeight *= 0.64;
160 }
161
162 if(bWaveLine)
163 {
164 eLineJoin = basegfx::B2DLineJoin::Round;
165 fHeight *= 0.25;
166 }
167
168 // prepare Line and Stroke Attributes
169 const attribute::LineAttribute aLineAttribute(getLineColor(), fHeight, eLineJoin);
170 attribute::StrokeAttribute aStrokeAttribute;
171
172 if(pDotDashArray)
173 {
174 std::vector< double > aDoubleArray;
175
176 for(const int* p = pDotDashArray; *p; ++p)
177 {
178 aDoubleArray.push_back(static_cast<double>(*p) * fHeight);
179 }
180
181 aStrokeAttribute = attribute::StrokeAttribute(std::move(aDoubleArray));
182 }
183
184 // create base polygon and new primitive
186 Primitive2DReference aNewPrimitive;
187
188 aLine.append(basegfx::B2DPoint(0.0, fOffset));
189 aLine.append(basegfx::B2DPoint(getWidth(), fOffset));
190
191 const basegfx::B2DHomMatrix aUnscaledTransform(
193 fShearX, fRotate, aTranslate));
194
195 aLine.transform(aUnscaledTransform);
196
197 if(bWaveLine)
198 {
199 double fWaveWidth(10.6 * fHeight);
200
202 {
203 fWaveWidth *= 0.7;
204 }
205 else if(TEXT_LINE_WAVE == getTextLine())
206 {
207 // extra multiply to get the same WaveWidth as with the bold version
208 fWaveWidth *= 2.0;
209 }
210
211 aNewPrimitive = Primitive2DReference(new PolygonWavePrimitive2D(aLine, aLineAttribute, aStrokeAttribute, fWaveWidth, fWaveWidth * 0.5));
212 }
213 else
214 {
215 aNewPrimitive = Primitive2DReference(new PolygonStrokePrimitive2D(std::move(aLine), aLineAttribute, std::move(aStrokeAttribute)));
216 }
217
218 // add primitive
219 rContainer.push_back(aNewPrimitive);
220
221 if(!bDoubleLine)
222 return;
223
224 // double line, create 2nd primitive with offset using TransformPrimitive based on
225 // already created NewPrimitive
226 double fLineDist(2.3 * fHeight);
227
228 if(bWaveLine)
229 {
230 fLineDist = 6.3 * fHeight;
231 }
232
233 // move base point of text to 0.0 and de-rotate
235 -aTranslate.getX(), -aTranslate.getY()));
236 aTransform.rotate(-fRotate);
237
238 // translate in Y by offset
239 aTransform.translate(0.0, fLineDist);
240
241 // move back and rotate
242 aTransform.rotate(fRotate);
243 aTransform.translate(aTranslate.getX(), aTranslate.getY());
244
245 // add transform primitive
246 Primitive2DContainer aContent { aNewPrimitive };
247 rContainer.push_back( new TransformPrimitive2D(aTransform, std::move(aContent)) );
248 }
249
251 basegfx::B2DHomMatrix aObjectTransformation,
252 double fWidth,
253 double fOffset,
254 double fHeight,
255 TextLine eTextLine,
256 const basegfx::BColor& rLineColor)
257 : maObjectTransformation(std::move(aObjectTransformation)),
258 mfWidth(fWidth),
259 mfOffset(fOffset),
260 mfHeight(fHeight),
261 meTextLine(eTextLine),
262 maLineColor(rLineColor)
263 {
264 }
265
266 bool TextLinePrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const
267 {
268 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
269 {
270 const TextLinePrimitive2D& rCompare = static_cast<const TextLinePrimitive2D&>(rPrimitive);
271
273 && getWidth() == rCompare.getWidth()
274 && getOffset() == rCompare.getOffset()
275 && getHeight() == rCompare.getHeight()
276 && getTextLine() == rCompare.getTextLine()
277 && getLineColor() == rCompare.getLineColor());
278 }
279
280 return false;
281 }
282
283 // provide unique ID
285 {
287 }
288
289} // end of namespace
290
291/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool decompose(B2DTuple &rScale, B2DTuple &rTranslate, double &rRotate, double &rShearX) const
void rotate(double fRadiant)
void translate(double fX, double fY)
void transform(const basegfx::B2DHomMatrix &rMatrix)
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
TYPE getX() const
TYPE getY() const
TextLinePrimitive2D(basegfx::B2DHomMatrix aObjectTransformation, double fWidth, double fOffset, double fHeight, TextLine eTextLine, const basegfx::BColor &rLineColor)
constructor
virtual sal_uInt32 getPrimitive2DID() const override
provide unique ID
const basegfx::B2DHomMatrix & getObjectTransformation() const
data read access
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &rViewInformation) const override
local decomposition.
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
compare operator
#define PRIMITIVE2D_ID_TEXTLINEPRIMITIVE2D
void * p
B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY)
B2DHomMatrix createShearXRotateTranslateB2DHomMatrix(double fShearX, double fRadiant, double fTranslateX, double fTranslateY)
rtl::Reference< BasePrimitive2D > Primitive2DReference
Definition: CommonTypes.hxx:27