bump product version to 7.6.3.2-android
[LibreOffice.git] / drawinglayer / source / primitive2d / textlineprimitive2d.cxx
blob2c7978772a278020d37506d2d7c35f35a8674d04
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/transformprimitive2d.hxx>
26 #include <drawinglayer/primitive2d/PolygonWavePrimitive2D.hxx>
27 #include <utility>
30 namespace drawinglayer::primitive2d
32 void TextLinePrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*rViewInformation*/) const
34 if(TEXT_LINE_NONE == getTextLine())
35 return;
37 bool bDoubleLine(false);
38 bool bWaveLine(false);
39 bool bBoldLine(false);
40 const int* pDotDashArray(nullptr);
41 basegfx::B2DLineJoin eLineJoin(basegfx::B2DLineJoin::NONE);
42 double fOffset(getOffset());
43 double fHeight(getHeight());
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
51 // get decomposition
52 basegfx::B2DVector aScale, aTranslate;
53 double fRotate, fShearX;
54 getObjectTransformation().decompose(aScale, aTranslate, fRotate, fShearX);
56 switch(getTextLine())
58 default: // case TEXT_LINE_SINGLE:
60 break;
62 case TEXT_LINE_DOUBLE:
64 bDoubleLine = true;
65 break;
67 case TEXT_LINE_DOTTED:
69 pDotDashArray = aDottedArray;
70 break;
72 case TEXT_LINE_DASH:
74 pDotDashArray = aDashedArray;
75 break;
77 case TEXT_LINE_LONGDASH:
79 pDotDashArray = aLongDashArray;
80 break;
82 case TEXT_LINE_DASHDOT:
84 pDotDashArray = aDotDashArray;
85 break;
87 case TEXT_LINE_DASHDOTDOT:
89 pDotDashArray = aDashDotDotArray;
90 break;
92 case TEXT_LINE_SMALLWAVE:
94 bWaveLine = true;
95 break;
97 case TEXT_LINE_WAVE:
99 bWaveLine = true;
100 break;
102 case TEXT_LINE_DOUBLEWAVE:
104 bDoubleLine = true;
105 bWaveLine = true;
106 break;
108 case TEXT_LINE_BOLD:
110 bBoldLine = true;
111 break;
113 case TEXT_LINE_BOLDDOTTED:
115 bBoldLine = true;
116 pDotDashArray = aDottedArray;
117 break;
119 case TEXT_LINE_BOLDDASH:
121 bBoldLine = true;
122 pDotDashArray = aDashedArray;
123 break;
125 case TEXT_LINE_BOLDLONGDASH:
127 bBoldLine = true;
128 pDotDashArray = aLongDashArray;
129 break;
131 case TEXT_LINE_BOLDDASHDOT:
133 bBoldLine = true;
134 pDotDashArray = aDotDashArray;
135 break;
137 case TEXT_LINE_BOLDDASHDOTDOT:
139 bBoldLine = true;
140 pDotDashArray = aDashDotDotArray;
141 break;
143 case TEXT_LINE_BOLDWAVE:
145 bWaveLine = true;
146 bBoldLine = true;
147 break;
151 if(bBoldLine)
153 fHeight *= 2.0;
156 if(bDoubleLine)
158 fOffset -= 0.50 * fHeight;
159 fHeight *= 0.64;
162 if(bWaveLine)
164 eLineJoin = basegfx::B2DLineJoin::Round;
165 fHeight *= 0.25;
168 // prepare Line and Stroke Attributes
169 const attribute::LineAttribute aLineAttribute(getLineColor(), fHeight, eLineJoin);
170 attribute::StrokeAttribute aStrokeAttribute;
172 if(pDotDashArray)
174 std::vector< double > aDoubleArray;
176 for(const int* p = pDotDashArray; *p; ++p)
178 aDoubleArray.push_back(static_cast<double>(*p) * fHeight);
181 aStrokeAttribute = attribute::StrokeAttribute(std::move(aDoubleArray));
184 // create base polygon and new primitive
185 basegfx::B2DPolygon aLine;
186 Primitive2DReference aNewPrimitive;
188 aLine.append(basegfx::B2DPoint(0.0, fOffset));
189 aLine.append(basegfx::B2DPoint(getWidth(), fOffset));
191 const basegfx::B2DHomMatrix aUnscaledTransform(
192 basegfx::utils::createShearXRotateTranslateB2DHomMatrix(
193 fShearX, fRotate, aTranslate));
195 aLine.transform(aUnscaledTransform);
197 if(bWaveLine)
199 double fWaveWidth(10.6 * fHeight);
201 if(TEXT_LINE_SMALLWAVE == getTextLine())
203 fWaveWidth *= 0.7;
205 else if(TEXT_LINE_WAVE == getTextLine())
207 // extra multiply to get the same WaveWidth as with the bold version
208 fWaveWidth *= 2.0;
211 aNewPrimitive = Primitive2DReference(new PolygonWavePrimitive2D(aLine, aLineAttribute, aStrokeAttribute, fWaveWidth, fWaveWidth * 0.5));
213 else
215 aNewPrimitive = Primitive2DReference(new PolygonStrokePrimitive2D(std::move(aLine), aLineAttribute, std::move(aStrokeAttribute)));
218 // add primitive
219 rContainer.push_back(aNewPrimitive);
221 if(!bDoubleLine)
222 return;
224 // double line, create 2nd primitive with offset using TransformPrimitive based on
225 // already created NewPrimitive
226 double fLineDist(2.3 * fHeight);
228 if(bWaveLine)
230 fLineDist = 6.3 * fHeight;
233 // move base point of text to 0.0 and de-rotate
234 basegfx::B2DHomMatrix aTransform(basegfx::utils::createTranslateB2DHomMatrix(
235 -aTranslate.getX(), -aTranslate.getY()));
236 aTransform.rotate(-fRotate);
238 // translate in Y by offset
239 aTransform.translate(0.0, fLineDist);
241 // move back and rotate
242 aTransform.rotate(fRotate);
243 aTransform.translate(aTranslate.getX(), aTranslate.getY());
245 // add transform primitive
246 Primitive2DContainer aContent { aNewPrimitive };
247 rContainer.push_back( new TransformPrimitive2D(aTransform, std::move(aContent)) );
250 TextLinePrimitive2D::TextLinePrimitive2D(
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)
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 sal_uInt32 TextLinePrimitive2D::getPrimitive2DID() const
286 return PRIMITIVE2D_ID_TEXTLINEPRIMITIVE2D;
289 } // end of namespace
291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */