Debian Codegraph @

cppcanvas/source/mtfrenderer/textlineshelper.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
10 #include <com/sun/star/rendering/XCanvas.hpp>
11 #include <com/sun/star/rendering/StrokeAttributes.hpp>
12 #include <com/sun/star/rendering/PathJoinType.hpp>
13 #include <basegfx/polygon/b2dpolypolygontools.hxx>
14 #include <basegfx/utils/canvastools.hxx>
15 #include <outdevstate.hxx>
16 #include <utility>
17 #include "textlineshelper.hxx"
18 #include "mtftools.hxx"
19
20 using namespace ::com::sun::star;
21
22 namespace
23 {
24 void initLineStyleWaveline(sal_uInt32 nLineStyle, bool& bIsWaveline, bool& bIsBold)
25 {
26 bIsWaveline = nLineStyle == LINESTYLE_DOUBLEWAVE || nLineStyle == LINESTYLE_SMALLWAVE
27 || nLineStyle == LINESTYLE_BOLDWAVE || nLineStyle == LINESTYLE_WAVE;
28 bIsBold = nLineStyle == LINESTYLE_BOLDWAVE;
29 }
30 }
31
32 namespace cppcanvas::internal
33 {
34 TextLinesHelper::TextLinesHelper(CanvasSharedPtr xCanvas, const OutDevState& rState)
35 : mpCanvas(std::move(xCanvas))
36 , mbIsOverlineColorSet(rState.isTextOverlineColorSet)
37 , maOverlineColor(rState.textOverlineColor)
38 , mbIsUnderlineColorSet(rState.isTextLineColorSet)
39 , maUnderlineColor(rState.textLineColor)
40 , mbOverlineWaveline(false)
41 , mbUnderlineWaveline(false)
42 , mbOverlineWavelineBold(false)
43 , mbUnderlineWavelineBold(false)
44 {
45 }
46
47 void TextLinesHelper::init(double nLineWidth, const cppcanvastools::TextLineInfo& rLineInfo)
48 {
49 ::basegfx::B2DRange aRange; // default is empty.
50 ::basegfx::B2DPolyPolygon aOverline, aUnderline, aStrikeout;
51 cppcanvastools::createTextLinesPolyPolygon(0.0, nLineWidth, rLineInfo, aOverline, aUnderline,
52 aStrikeout);
53
54 mxOverline.clear();
55 mxUnderline.clear();
56 mxStrikeout.clear();
57
58 uno::Reference<rendering::XGraphicDevice> xDevice = mpCanvas->getUNOCanvas()->getDevice();
59
60 if (aOverline.count())
61 {
62 aRange.expand(aOverline.getB2DRange());
63 mxOverline = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(xDevice, aOverline);
64 }
65
66 if (aUnderline.count())
67 {
68 aRange.expand(aUnderline.getB2DRange());
69 mxUnderline = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(xDevice, aUnderline);
70 }
71
72 if (aStrikeout.count())
73 {
74 aRange.expand(aStrikeout.getB2DRange());
75 mxStrikeout = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(xDevice, aStrikeout);
76 }
77
78 maOverallSize = basegfx::B2DSize(aRange.getRange().getX(), aRange.getRange().getY());
79
80 initLineStyleWaveline(rLineInfo.mnOverlineStyle, mbOverlineWaveline, mbOverlineWavelineBold);
81
82 initLineStyleWaveline(rLineInfo.mnUnderlineStyle, mbUnderlineWaveline, mbUnderlineWavelineBold);
83 }
84
85 void TextLinesHelper::render(const rendering::RenderState& rRenderState, bool bNormalText) const
86 {
87 const rendering::ViewState aViewState(mpCanvas->getViewState());
88 const uno::Reference<rendering::XCanvas> xCanvas(mpCanvas->getUNOCanvas());
89 rendering::StrokeAttributes aStrokeAttributes;
90 aStrokeAttributes.JoinType = rendering::PathJoinType::ROUND;
91
92 if (mxOverline.is())
93 {
94 rendering::RenderState aLocalState(rRenderState);
95 if (bNormalText && mbIsOverlineColorSet)
96 aLocalState.DeviceColor = maOverlineColor;
97
98 if (mbOverlineWaveline)
99 {
100 aStrokeAttributes.StrokeWidth = mbOverlineWavelineBold ? 2.0 : 1.0;
101 xCanvas->strokePolyPolygon(mxOverline, aViewState, aLocalState, aStrokeAttributes);
102 }
103 else
104 xCanvas->fillPolyPolygon(mxOverline, aViewState, aLocalState);
105 }
106
107 if (mxUnderline.is())
108 {
109 rendering::RenderState aLocalState(rRenderState);
110 if (bNormalText && mbIsUnderlineColorSet)
111 aLocalState.DeviceColor = maUnderlineColor;
112 if (mbUnderlineWaveline)
113 {
114 aStrokeAttributes.StrokeWidth = mbUnderlineWavelineBold ? 2.0 : 1.0;
115 xCanvas->strokePolyPolygon(mxUnderline, aViewState, aLocalState, aStrokeAttributes);
116 }
117 else
118 xCanvas->fillPolyPolygon(mxUnderline, aViewState, aLocalState);
119 }
120
121 if (mxStrikeout.is())
122 xCanvas->fillPolyPolygon(mxStrikeout, aViewState, rRenderState);
123 }
124 }
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */