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 <drawinglayer/primitive2d/textlineprimitive2d.hxx>
21 : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
22 : #include <drawinglayer/attribute/strokeattribute.hxx>
23 : #include <drawinglayer/attribute/lineattribute.hxx>
24 : #include <basegfx/matrix/b2dhommatrixtools.hxx>
25 : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
26 : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
27 :
28 : //////////////////////////////////////////////////////////////////////////////
29 :
30 : namespace drawinglayer
31 : {
32 : namespace primitive2d
33 : {
34 0 : Primitive2DSequence TextLinePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
35 : {
36 0 : Primitive2DSequence xRetval;
37 :
38 0 : if(TEXT_LINE_NONE != getTextLine())
39 : {
40 0 : bool bDoubleLine(false);
41 0 : bool bWaveLine(false);
42 0 : bool bBoldLine(false);
43 0 : const int* pDotDashArray(0);
44 0 : basegfx::B2DLineJoin eLineJoin(basegfx::B2DLINEJOIN_NONE);
45 0 : double fOffset(getOffset());
46 0 : double fHeight(getHeight());
47 :
48 : static const int aDottedArray[] = { 1, 1, 0}; // DOTTED LINE
49 : static const int aDotDashArray[] = { 1, 1, 4, 1, 0}; // DASHDOT
50 : static const int aDashDotDotArray[] = { 1, 1, 1, 1, 4, 1, 0}; // DASHDOTDOT
51 : static const int aDashedArray[] = { 5, 2, 0}; // DASHED LINE
52 : static const int aLongDashArray[] = { 7, 2, 0}; // LONGDASH
53 :
54 : // get decomposition
55 0 : basegfx::B2DVector aScale, aTranslate;
56 : double fRotate, fShearX;
57 0 : getObjectTransformation().decompose(aScale, aTranslate, fRotate, fShearX);
58 :
59 0 : switch(getTextLine())
60 : {
61 : default: // case TEXT_LINE_SINGLE:
62 : {
63 0 : break;
64 : }
65 : case TEXT_LINE_DOUBLE:
66 : {
67 0 : bDoubleLine = true;
68 0 : break;
69 : }
70 : case TEXT_LINE_DOTTED:
71 : {
72 0 : pDotDashArray = aDottedArray;
73 0 : break;
74 : }
75 : case TEXT_LINE_DASH:
76 : {
77 0 : pDotDashArray = aDashedArray;
78 0 : break;
79 : }
80 : case TEXT_LINE_LONGDASH:
81 : {
82 0 : pDotDashArray = aLongDashArray;
83 0 : break;
84 : }
85 : case TEXT_LINE_DASHDOT:
86 : {
87 0 : pDotDashArray = aDotDashArray;
88 0 : break;
89 : }
90 : case TEXT_LINE_DASHDOTDOT:
91 : {
92 0 : pDotDashArray = aDashDotDotArray;
93 0 : break;
94 : }
95 : case TEXT_LINE_SMALLWAVE:
96 : {
97 0 : bWaveLine = true;
98 0 : break;
99 : }
100 : case TEXT_LINE_WAVE:
101 : {
102 0 : bWaveLine = true;
103 0 : break;
104 : }
105 : case TEXT_LINE_DOUBLEWAVE:
106 : {
107 0 : bDoubleLine = true;
108 0 : bWaveLine = true;
109 0 : break;
110 : }
111 : case TEXT_LINE_BOLD:
112 : {
113 0 : bBoldLine = true;
114 0 : break;
115 : }
116 : case TEXT_LINE_BOLDDOTTED:
117 : {
118 0 : bBoldLine = true;
119 0 : pDotDashArray = aDottedArray;
120 0 : break;
121 : }
122 : case TEXT_LINE_BOLDDASH:
123 : {
124 0 : bBoldLine = true;
125 0 : pDotDashArray = aDashedArray;
126 0 : break;
127 : }
128 : case TEXT_LINE_BOLDLONGDASH:
129 : {
130 0 : bBoldLine = true;
131 0 : pDotDashArray = aLongDashArray;
132 0 : break;
133 : }
134 : case TEXT_LINE_BOLDDASHDOT:
135 : {
136 0 : bBoldLine = true;
137 0 : pDotDashArray = aDotDashArray;
138 0 : break;
139 : }
140 : case TEXT_LINE_BOLDDASHDOTDOT:
141 : {
142 0 : bBoldLine = true;
143 0 : pDotDashArray = aDashDotDotArray;
144 0 : break;
145 : }
146 : case TEXT_LINE_BOLDWAVE:
147 : {
148 0 : bWaveLine = true;
149 0 : bBoldLine = true;
150 0 : break;
151 : }
152 : }
153 :
154 0 : if(bBoldLine)
155 : {
156 0 : fHeight *= 2.0;
157 : }
158 :
159 0 : if(bDoubleLine)
160 : {
161 0 : fOffset -= 0.50 * fHeight;
162 0 : fHeight *= 0.64;
163 : }
164 :
165 0 : if(bWaveLine)
166 : {
167 0 : eLineJoin = basegfx::B2DLINEJOIN_ROUND;
168 0 : fHeight *= 0.25;
169 : }
170 :
171 : // prepare Line and Stroke Attributes
172 0 : const attribute::LineAttribute aLineAttribute(getLineColor(), fHeight, eLineJoin);
173 0 : attribute::StrokeAttribute aStrokeAttribute;
174 :
175 0 : if(pDotDashArray)
176 : {
177 0 : ::std::vector< double > aDoubleArray;
178 :
179 0 : for(const int* p = pDotDashArray; *p; ++p)
180 : {
181 0 : aDoubleArray.push_back((double)(*p) * fHeight);
182 : }
183 :
184 0 : aStrokeAttribute = attribute::StrokeAttribute(aDoubleArray);
185 : }
186 :
187 : // create base polygon and new primitive
188 0 : basegfx::B2DPolygon aLine;
189 0 : Primitive2DReference aNewPrimitive;
190 :
191 0 : aLine.append(basegfx::B2DPoint(0.0, fOffset));
192 0 : aLine.append(basegfx::B2DPoint(getWidth(), fOffset));
193 :
194 : const basegfx::B2DHomMatrix aUnscaledTransform(
195 : basegfx::tools::createShearXRotateTranslateB2DHomMatrix(
196 0 : fShearX, fRotate, aTranslate));
197 :
198 0 : aLine.transform(aUnscaledTransform);
199 :
200 0 : if(bWaveLine)
201 : {
202 0 : double fWaveWidth(10.6 * fHeight);
203 :
204 0 : if(TEXT_LINE_SMALLWAVE == getTextLine())
205 : {
206 0 : fWaveWidth *= 0.7;
207 : }
208 0 : else if(TEXT_LINE_WAVE == getTextLine())
209 : {
210 : // extra multiply to get the same WaveWidth as with the bold version
211 0 : fWaveWidth *= 2.0;
212 : }
213 :
214 0 : aNewPrimitive = Primitive2DReference(new PolygonWavePrimitive2D(aLine, aLineAttribute, aStrokeAttribute, fWaveWidth, fWaveWidth * 0.5));
215 : }
216 : else
217 : {
218 0 : aNewPrimitive = Primitive2DReference(new PolygonStrokePrimitive2D(aLine, aLineAttribute, aStrokeAttribute));
219 : }
220 :
221 : // add primitive
222 0 : appendPrimitive2DReferenceToPrimitive2DSequence(xRetval, aNewPrimitive);
223 :
224 0 : if(bDoubleLine)
225 : {
226 : // double line, create 2nd primitive with offset using TransformPrimitive based on
227 : // already created NewPrimitive
228 0 : double fLineDist(2.3 * fHeight);
229 :
230 0 : if(bWaveLine)
231 : {
232 0 : fLineDist = 6.3 * fHeight;
233 : }
234 :
235 : // move base point of text to 0.0 and de-rotate
236 : basegfx::B2DHomMatrix aTransform(basegfx::tools::createTranslateB2DHomMatrix(
237 0 : -aTranslate.getX(), -aTranslate.getY()));
238 0 : aTransform.rotate(-fRotate);
239 :
240 : // translate in Y by offset
241 0 : aTransform.translate(0.0, fLineDist);
242 :
243 : // move back and rotate
244 0 : aTransform.rotate(fRotate);
245 0 : aTransform.translate(aTranslate.getX(), aTranslate.getY());
246 :
247 : // add transform primitive
248 0 : const Primitive2DSequence aContent(&aNewPrimitive, 1);
249 : appendPrimitive2DReferenceToPrimitive2DSequence(xRetval,
250 0 : Primitive2DReference(new TransformPrimitive2D(aTransform, aContent)));
251 0 : }
252 : }
253 :
254 0 : return xRetval;
255 : }
256 :
257 0 : TextLinePrimitive2D::TextLinePrimitive2D(
258 : const basegfx::B2DHomMatrix& rObjectTransformation,
259 : double fWidth,
260 : double fOffset,
261 : double fHeight,
262 : TextLine eTextLine,
263 : const basegfx::BColor& rLineColor)
264 : : BufferedDecompositionPrimitive2D(),
265 : maObjectTransformation(rObjectTransformation),
266 : mfWidth(fWidth),
267 : mfOffset(fOffset),
268 : mfHeight(fHeight),
269 : meTextLine(eTextLine),
270 0 : maLineColor(rLineColor)
271 : {
272 0 : }
273 :
274 0 : bool TextLinePrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const
275 : {
276 0 : if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
277 : {
278 0 : const TextLinePrimitive2D& rCompare = (TextLinePrimitive2D&)rPrimitive;
279 :
280 0 : return (getObjectTransformation() == rCompare.getObjectTransformation()
281 0 : && getWidth() == rCompare.getWidth()
282 0 : && getOffset() == rCompare.getOffset()
283 0 : && getHeight() == rCompare.getHeight()
284 0 : && getTextLine() == rCompare.getTextLine()
285 0 : && getLineColor() == rCompare.getLineColor());
286 : }
287 :
288 0 : return false;
289 : }
290 :
291 : // provide unique ID
292 0 : ImplPrimitrive2DIDBlock(TextLinePrimitive2D, PRIMITIVE2D_ID_TEXTLINEPRIMITIVE2D)
293 :
294 : } // end of namespace primitive2d
295 : } // end of namespace drawinglayer
296 :
297 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|