nss: upgrade to release 3.73
[LibreOffice.git] / drawinglayer / source / primitive2d / textlineprimitive2d.cxx
blob2238fc383d5c9517c1f1c2391a6ebc55ef7b7071
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 <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>
29 namespace drawinglayer::primitive2d
31 void TextLinePrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*rViewInformation*/) const
33 if(TEXT_LINE_NONE == getTextLine())
34 return;
36 bool bDoubleLine(false);
37 bool bWaveLine(false);
38 bool bBoldLine(false);
39 const int* pDotDashArray(nullptr);
40 basegfx::B2DLineJoin eLineJoin(basegfx::B2DLineJoin::NONE);
41 double fOffset(getOffset());
42 double fHeight(getHeight());
44 static const int aDottedArray[] = { 1, 1, 0}; // DOTTED LINE
45 static const int aDotDashArray[] = { 1, 1, 4, 1, 0}; // DASHDOT
46 static const int aDashDotDotArray[] = { 1, 1, 1, 1, 4, 1, 0}; // DASHDOTDOT
47 static const int aDashedArray[] = { 5, 2, 0}; // DASHED LINE
48 static const int aLongDashArray[] = { 7, 2, 0}; // LONGDASH
50 // get decomposition
51 basegfx::B2DVector aScale, aTranslate;
52 double fRotate, fShearX;
53 getObjectTransformation().decompose(aScale, aTranslate, fRotate, fShearX);
55 switch(getTextLine())
57 default: // case TEXT_LINE_SINGLE:
59 break;
61 case TEXT_LINE_DOUBLE:
63 bDoubleLine = true;
64 break;
66 case TEXT_LINE_DOTTED:
68 pDotDashArray = aDottedArray;
69 break;
71 case TEXT_LINE_DASH:
73 pDotDashArray = aDashedArray;
74 break;
76 case TEXT_LINE_LONGDASH:
78 pDotDashArray = aLongDashArray;
79 break;
81 case TEXT_LINE_DASHDOT:
83 pDotDashArray = aDotDashArray;
84 break;
86 case TEXT_LINE_DASHDOTDOT:
88 pDotDashArray = aDashDotDotArray;
89 break;
91 case TEXT_LINE_SMALLWAVE:
93 bWaveLine = true;
94 break;
96 case TEXT_LINE_WAVE:
98 bWaveLine = true;
99 break;
101 case TEXT_LINE_DOUBLEWAVE:
103 bDoubleLine = true;
104 bWaveLine = true;
105 break;
107 case TEXT_LINE_BOLD:
109 bBoldLine = true;
110 break;
112 case TEXT_LINE_BOLDDOTTED:
114 bBoldLine = true;
115 pDotDashArray = aDottedArray;
116 break;
118 case TEXT_LINE_BOLDDASH:
120 bBoldLine = true;
121 pDotDashArray = aDashedArray;
122 break;
124 case TEXT_LINE_BOLDLONGDASH:
126 bBoldLine = true;
127 pDotDashArray = aLongDashArray;
128 break;
130 case TEXT_LINE_BOLDDASHDOT:
132 bBoldLine = true;
133 pDotDashArray = aDotDashArray;
134 break;
136 case TEXT_LINE_BOLDDASHDOTDOT:
138 bBoldLine = true;
139 pDotDashArray = aDashDotDotArray;
140 break;
142 case TEXT_LINE_BOLDWAVE:
144 bWaveLine = true;
145 bBoldLine = true;
146 break;
150 if(bBoldLine)
152 fHeight *= 2.0;
155 if(bDoubleLine)
157 fOffset -= 0.50 * fHeight;
158 fHeight *= 0.64;
161 if(bWaveLine)
163 eLineJoin = basegfx::B2DLineJoin::Round;
164 fHeight *= 0.25;
167 // prepare Line and Stroke Attributes
168 const attribute::LineAttribute aLineAttribute(getLineColor(), fHeight, eLineJoin);
169 attribute::StrokeAttribute aStrokeAttribute;
171 if(pDotDashArray)
173 std::vector< double > aDoubleArray;
175 for(const int* p = pDotDashArray; *p; ++p)
177 aDoubleArray.push_back(static_cast<double>(*p) * fHeight);
180 aStrokeAttribute = attribute::StrokeAttribute(aDoubleArray);
183 // create base polygon and new primitive
184 basegfx::B2DPolygon aLine;
185 Primitive2DReference aNewPrimitive;
187 aLine.append(basegfx::B2DPoint(0.0, fOffset));
188 aLine.append(basegfx::B2DPoint(getWidth(), fOffset));
190 const basegfx::B2DHomMatrix aUnscaledTransform(
191 basegfx::utils::createShearXRotateTranslateB2DHomMatrix(
192 fShearX, fRotate, aTranslate));
194 aLine.transform(aUnscaledTransform);
196 if(bWaveLine)
198 double fWaveWidth(10.6 * fHeight);
200 if(TEXT_LINE_SMALLWAVE == getTextLine())
202 fWaveWidth *= 0.7;
204 else if(TEXT_LINE_WAVE == getTextLine())
206 // extra multiply to get the same WaveWidth as with the bold version
207 fWaveWidth *= 2.0;
210 aNewPrimitive = Primitive2DReference(new PolygonWavePrimitive2D(aLine, aLineAttribute, aStrokeAttribute, fWaveWidth, fWaveWidth * 0.5));
212 else
214 aNewPrimitive = Primitive2DReference(new PolygonStrokePrimitive2D(aLine, aLineAttribute, aStrokeAttribute));
217 // add primitive
218 rContainer.push_back(aNewPrimitive);
220 if(!bDoubleLine)
221 return;
223 // double line, create 2nd primitive with offset using TransformPrimitive based on
224 // already created NewPrimitive
225 double fLineDist(2.3 * fHeight);
227 if(bWaveLine)
229 fLineDist = 6.3 * fHeight;
232 // move base point of text to 0.0 and de-rotate
233 basegfx::B2DHomMatrix aTransform(basegfx::utils::createTranslateB2DHomMatrix(
234 -aTranslate.getX(), -aTranslate.getY()));
235 aTransform.rotate(-fRotate);
237 // translate in Y by offset
238 aTransform.translate(0.0, fLineDist);
240 // move back and rotate
241 aTransform.rotate(fRotate);
242 aTransform.translate(aTranslate.getX(), aTranslate.getY());
244 // add transform primitive
245 const Primitive2DContainer aContent { aNewPrimitive };
246 rContainer.push_back( new TransformPrimitive2D(aTransform, aContent) );
249 TextLinePrimitive2D::TextLinePrimitive2D(
250 const basegfx::B2DHomMatrix& rObjectTransformation,
251 double fWidth,
252 double fOffset,
253 double fHeight,
254 TextLine eTextLine,
255 const basegfx::BColor& rLineColor)
256 : BufferedDecompositionPrimitive2D(),
257 maObjectTransformation(rObjectTransformation),
258 mfWidth(fWidth),
259 mfOffset(fOffset),
260 mfHeight(fHeight),
261 meTextLine(eTextLine),
262 maLineColor(rLineColor)
266 bool TextLinePrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const
268 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
270 const TextLinePrimitive2D& rCompare = static_cast<const TextLinePrimitive2D&>(rPrimitive);
272 return (getObjectTransformation() == rCompare.getObjectTransformation()
273 && getWidth() == rCompare.getWidth()
274 && getOffset() == rCompare.getOffset()
275 && getHeight() == rCompare.getHeight()
276 && getTextLine() == rCompare.getTextLine()
277 && getLineColor() == rCompare.getLineColor());
280 return false;
283 // provide unique ID
284 ImplPrimitive2DIDBlock(TextLinePrimitive2D, PRIMITIVE2D_ID_TEXTLINEPRIMITIVE2D)
286 } // end of namespace
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */