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 <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())
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
51 basegfx::B2DVector aScale
, aTranslate
;
52 double fRotate
, fShearX
;
53 getObjectTransformation().decompose(aScale
, aTranslate
, fRotate
, fShearX
);
57 default: // case TEXT_LINE_SINGLE:
61 case TEXT_LINE_DOUBLE
:
66 case TEXT_LINE_DOTTED
:
68 pDotDashArray
= aDottedArray
;
73 pDotDashArray
= aDashedArray
;
76 case TEXT_LINE_LONGDASH
:
78 pDotDashArray
= aLongDashArray
;
81 case TEXT_LINE_DASHDOT
:
83 pDotDashArray
= aDotDashArray
;
86 case TEXT_LINE_DASHDOTDOT
:
88 pDotDashArray
= aDashDotDotArray
;
91 case TEXT_LINE_SMALLWAVE
:
101 case TEXT_LINE_DOUBLEWAVE
:
112 case TEXT_LINE_BOLDDOTTED
:
115 pDotDashArray
= aDottedArray
;
118 case TEXT_LINE_BOLDDASH
:
121 pDotDashArray
= aDashedArray
;
124 case TEXT_LINE_BOLDLONGDASH
:
127 pDotDashArray
= aLongDashArray
;
130 case TEXT_LINE_BOLDDASHDOT
:
133 pDotDashArray
= aDotDashArray
;
136 case TEXT_LINE_BOLDDASHDOTDOT
:
139 pDotDashArray
= aDashDotDotArray
;
142 case TEXT_LINE_BOLDWAVE
:
157 fOffset
-= 0.50 * fHeight
;
163 eLineJoin
= basegfx::B2DLineJoin::Round
;
167 // prepare Line and Stroke Attributes
168 const attribute::LineAttribute
aLineAttribute(getLineColor(), fHeight
, eLineJoin
);
169 attribute::StrokeAttribute aStrokeAttribute
;
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
);
198 double fWaveWidth(10.6 * fHeight
);
200 if(TEXT_LINE_SMALLWAVE
== getTextLine())
204 else if(TEXT_LINE_WAVE
== getTextLine())
206 // extra multiply to get the same WaveWidth as with the bold version
210 aNewPrimitive
= Primitive2DReference(new PolygonWavePrimitive2D(aLine
, aLineAttribute
, aStrokeAttribute
, fWaveWidth
, fWaveWidth
* 0.5));
214 aNewPrimitive
= Primitive2DReference(new PolygonStrokePrimitive2D(aLine
, aLineAttribute
, aStrokeAttribute
));
218 rContainer
.push_back(aNewPrimitive
);
223 // double line, create 2nd primitive with offset using TransformPrimitive based on
224 // already created NewPrimitive
225 double fLineDist(2.3 * fHeight
);
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
,
255 const basegfx::BColor
& rLineColor
)
256 : BufferedDecompositionPrimitive2D(),
257 maObjectTransformation(rObjectTransformation
),
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());
284 ImplPrimitive2DIDBlock(TextLinePrimitive2D
, PRIMITIVE2D_ID_TEXTLINEPRIMITIVE2D
)
286 } // end of namespace
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */