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/transformprimitive2d.hxx>
26 #include <drawinglayer/primitive2d/PolygonWavePrimitive2D.hxx>
30 namespace drawinglayer::primitive2d
32 void TextLinePrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& /*rViewInformation*/) const
34 if(TEXT_LINE_NONE
== getTextLine())
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
52 basegfx::B2DVector aScale
, aTranslate
;
53 double fRotate
, fShearX
;
54 getObjectTransformation().decompose(aScale
, aTranslate
, fRotate
, fShearX
);
58 default: // case TEXT_LINE_SINGLE:
62 case TEXT_LINE_DOUBLE
:
67 case TEXT_LINE_DOTTED
:
69 pDotDashArray
= aDottedArray
;
74 pDotDashArray
= aDashedArray
;
77 case TEXT_LINE_LONGDASH
:
79 pDotDashArray
= aLongDashArray
;
82 case TEXT_LINE_DASHDOT
:
84 pDotDashArray
= aDotDashArray
;
87 case TEXT_LINE_DASHDOTDOT
:
89 pDotDashArray
= aDashDotDotArray
;
92 case TEXT_LINE_SMALLWAVE
:
102 case TEXT_LINE_DOUBLEWAVE
:
113 case TEXT_LINE_BOLDDOTTED
:
116 pDotDashArray
= aDottedArray
;
119 case TEXT_LINE_BOLDDASH
:
122 pDotDashArray
= aDashedArray
;
125 case TEXT_LINE_BOLDLONGDASH
:
128 pDotDashArray
= aLongDashArray
;
131 case TEXT_LINE_BOLDDASHDOT
:
134 pDotDashArray
= aDotDashArray
;
137 case TEXT_LINE_BOLDDASHDOTDOT
:
140 pDotDashArray
= aDashDotDotArray
;
143 case TEXT_LINE_BOLDWAVE
:
158 fOffset
-= 0.50 * fHeight
;
164 eLineJoin
= basegfx::B2DLineJoin::Round
;
168 // prepare Line and Stroke Attributes
169 const attribute::LineAttribute
aLineAttribute(getLineColor(), fHeight
, eLineJoin
);
170 attribute::StrokeAttribute aStrokeAttribute
;
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
);
199 double fWaveWidth(10.6 * fHeight
);
201 if(TEXT_LINE_SMALLWAVE
== getTextLine())
205 else if(TEXT_LINE_WAVE
== getTextLine())
207 // extra multiply to get the same WaveWidth as with the bold version
211 aNewPrimitive
= Primitive2DReference(new PolygonWavePrimitive2D(aLine
, aLineAttribute
, aStrokeAttribute
, fWaveWidth
, fWaveWidth
* 0.5));
215 aNewPrimitive
= Primitive2DReference(new PolygonStrokePrimitive2D(std::move(aLine
), aLineAttribute
, std::move(aStrokeAttribute
)));
219 rContainer
.push_back(aNewPrimitive
);
224 // double line, create 2nd primitive with offset using TransformPrimitive based on
225 // already created NewPrimitive
226 double fLineDist(2.3 * fHeight
);
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
,
256 const basegfx::BColor
& rLineColor
)
257 : maObjectTransformation(std::move(aObjectTransformation
)),
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 sal_uInt32
TextLinePrimitive2D::getPrimitive2DID() const
286 return PRIMITIVE2D_ID_TEXTLINEPRIMITIVE2D
;
289 } // end of namespace
291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */