1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
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>
17 #include "textlineshelper.hxx"
18 #include "mtftools.hxx"
20 using namespace ::com::sun::star
;
24 void initLineStyleWaveline(sal_uInt32 nLineStyle
, bool& bIsWaveline
, bool& bIsBold
)
26 bIsWaveline
= nLineStyle
== LINESTYLE_DOUBLEWAVE
|| nLineStyle
== LINESTYLE_SMALLWAVE
27 || nLineStyle
== LINESTYLE_BOLDWAVE
|| nLineStyle
== LINESTYLE_WAVE
;
28 bIsBold
= nLineStyle
== LINESTYLE_BOLDWAVE
;
32 namespace cppcanvas::internal
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)
47 void TextLinesHelper::init(double nLineWidth
, const tools::TextLineInfo
& rLineInfo
)
49 ::basegfx::B2DRange aRange
; // default is empty.
50 ::basegfx::B2DPolyPolygon aOverline
, aUnderline
, aStrikeout
;
51 tools::createTextLinesPolyPolygon(0.0, nLineWidth
, rLineInfo
, aOverline
, aUnderline
,
58 uno::Reference
<rendering::XGraphicDevice
> xDevice
= mpCanvas
->getUNOCanvas()->getDevice();
60 if (aOverline
.count())
62 aRange
.expand(::basegfx::utils::getRange(aOverline
));
63 mxOverline
= ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(xDevice
, aOverline
);
66 if (aUnderline
.count())
68 aRange
.expand(::basegfx::utils::getRange(aUnderline
));
69 mxUnderline
= ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(xDevice
, aUnderline
);
72 if (aStrikeout
.count())
74 aRange
.expand(::basegfx::utils::getRange(aStrikeout
));
75 mxStrikeout
= ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(xDevice
, aStrikeout
);
78 maOverallSize
= basegfx::B2DSize(aRange
.getRange().getX(), aRange
.getRange().getY());
80 initLineStyleWaveline(rLineInfo
.mnOverlineStyle
, mbOverlineWaveline
, mbOverlineWavelineBold
);
82 initLineStyleWaveline(rLineInfo
.mnUnderlineStyle
, mbUnderlineWaveline
, mbUnderlineWavelineBold
);
85 void TextLinesHelper::render(const rendering::RenderState
& rRenderState
, bool bNormalText
) const
87 const rendering::ViewState
& rViewState(mpCanvas
->getViewState());
88 const uno::Reference
<rendering::XCanvas
>& xCanvas(mpCanvas
->getUNOCanvas());
89 rendering::StrokeAttributes aStrokeAttributes
;
90 aStrokeAttributes
.JoinType
= rendering::PathJoinType::ROUND
;
94 rendering::RenderState
aLocalState(rRenderState
);
95 if (bNormalText
&& mbIsOverlineColorSet
)
96 aLocalState
.DeviceColor
= maOverlineColor
;
98 if (mbOverlineWaveline
)
100 aStrokeAttributes
.StrokeWidth
= mbOverlineWavelineBold
? 2.0 : 1.0;
101 xCanvas
->strokePolyPolygon(mxOverline
, rViewState
, aLocalState
, aStrokeAttributes
);
104 xCanvas
->fillPolyPolygon(mxOverline
, rViewState
, aLocalState
);
107 if (mxUnderline
.is())
109 rendering::RenderState
aLocalState(rRenderState
);
110 if (bNormalText
&& mbIsUnderlineColorSet
)
111 aLocalState
.DeviceColor
= maUnderlineColor
;
112 if (mbUnderlineWaveline
)
114 aStrokeAttributes
.StrokeWidth
= mbUnderlineWavelineBold
? 2.0 : 1.0;
115 xCanvas
->strokePolyPolygon(mxUnderline
, rViewState
, aLocalState
, aStrokeAttributes
);
118 xCanvas
->fillPolyPolygon(mxUnderline
, rViewState
, aLocalState
);
121 if (mxStrikeout
.is())
122 xCanvas
->fillPolyPolygon(mxStrikeout
, rViewState
, rRenderState
);
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */