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