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>
16 #include "textlineshelper.hxx"
17 #include "mtftools.hxx"
19 using namespace ::com::sun::star
;
23 void initLineStyleWaveline(sal_uInt32 nLineStyle
, bool& bIsWaveline
, bool& bIsBold
)
25 bIsWaveline
= nLineStyle
== LINESTYLE_DOUBLEWAVE
|| nLineStyle
== LINESTYLE_SMALLWAVE
26 || nLineStyle
== LINESTYLE_BOLDWAVE
|| nLineStyle
== LINESTYLE_WAVE
;
27 bIsBold
= nLineStyle
== LINESTYLE_BOLDWAVE
;
31 namespace cppcanvas::internal
33 TextLinesHelper::TextLinesHelper(const CanvasSharedPtr
& rCanvas
, const OutDevState
& rState
)
35 , mbIsOverlineColorSet(rState
.isTextOverlineColorSet
)
36 , maOverlineColor(rState
.textOverlineColor
)
37 , mbIsUnderlineColorSet(rState
.isTextLineColorSet
)
38 , maUnderlineColor(rState
.textLineColor
)
39 , mbOverlineWaveline(false)
40 , mbUnderlineWaveline(false)
41 , mbOverlineWavelineBold(false)
42 , mbUnderlineWavelineBold(false)
46 void TextLinesHelper::init(double nLineWidth
, const tools::TextLineInfo
& rLineInfo
)
48 ::basegfx::B2DRange aRange
; // default is empty.
49 ::basegfx::B2DPolyPolygon aOverline
, aUnderline
, aStrikeout
;
50 tools::createTextLinesPolyPolygon(0.0, nLineWidth
, rLineInfo
, aOverline
, aUnderline
,
57 uno::Reference
<rendering::XGraphicDevice
> xDevice
= mpCanvas
->getUNOCanvas()->getDevice();
59 if (aOverline
.count())
61 aRange
.expand(::basegfx::utils::getRange(aOverline
));
62 mxOverline
= ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(xDevice
, aOverline
);
65 if (aUnderline
.count())
67 aRange
.expand(::basegfx::utils::getRange(aUnderline
));
68 mxUnderline
= ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(xDevice
, aUnderline
);
71 if (aStrikeout
.count())
73 aRange
.expand(::basegfx::utils::getRange(aStrikeout
));
74 mxStrikeout
= ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(xDevice
, aStrikeout
);
77 maOverallSize
= aRange
.getRange();
79 initLineStyleWaveline(rLineInfo
.mnOverlineStyle
, mbOverlineWaveline
, mbOverlineWavelineBold
);
81 initLineStyleWaveline(rLineInfo
.mnUnderlineStyle
, mbUnderlineWaveline
, mbUnderlineWavelineBold
);
84 void TextLinesHelper::render(const rendering::RenderState
& rRenderState
, bool bNormalText
) const
86 const rendering::ViewState
& rViewState(mpCanvas
->getViewState());
87 const uno::Reference
<rendering::XCanvas
>& xCanvas(mpCanvas
->getUNOCanvas());
88 rendering::StrokeAttributes aStrokeAttributes
;
89 aStrokeAttributes
.JoinType
= rendering::PathJoinType::ROUND
;
93 rendering::RenderState
aLocalState(rRenderState
);
94 if (bNormalText
&& mbIsOverlineColorSet
)
95 aLocalState
.DeviceColor
= maOverlineColor
;
97 if (mbOverlineWaveline
)
99 aStrokeAttributes
.StrokeWidth
= mbOverlineWavelineBold
? 2.0 : 1.0;
100 xCanvas
->strokePolyPolygon(mxOverline
, rViewState
, aLocalState
, aStrokeAttributes
);
103 xCanvas
->fillPolyPolygon(mxOverline
, rViewState
, aLocalState
);
106 if (mxUnderline
.is())
108 rendering::RenderState
aLocalState(rRenderState
);
109 if (bNormalText
&& mbIsUnderlineColorSet
)
110 aLocalState
.DeviceColor
= maUnderlineColor
;
111 if (mbUnderlineWaveline
)
113 aStrokeAttributes
.StrokeWidth
= mbUnderlineWavelineBold
? 2.0 : 1.0;
114 xCanvas
->strokePolyPolygon(mxUnderline
, rViewState
, aLocalState
, aStrokeAttributes
);
117 xCanvas
->fillPolyPolygon(mxUnderline
, rViewState
, aLocalState
);
120 if (mxStrikeout
.is())
121 xCanvas
->fillPolyPolygon(mxStrikeout
, rViewState
, rRenderState
);
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */