bump product version to 6.3.0.0.beta1
[LibreOffice.git] / cppcanvas / source / mtfrenderer / textlineshelper.cxx
blobdb88e5cb5ee79bdf5c3aab07e89e5cf50916a9fd
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.
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 */
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;
21 namespace
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
33 namespace internal
35 TextLinesHelper::TextLinesHelper(const CanvasSharedPtr& rCanvas, const OutDevState& rState)
36 : mpCanvas(rCanvas)
37 , mbIsOverlineColorSet(rState.isTextOverlineColorSet)
38 , maOverlineColor(rState.textOverlineColor)
39 , mbIsUnderlineColorSet(rState.isTextLineColorSet)
40 , maUnderlineColor(rState.textLineColor)
41 , mbOverlineWaveline(false)
42 , mbUnderlineWaveline(false)
43 , mbOverlineWavelineBold(false)
44 , mbUnderlineWavelineBold(false)
48 void TextLinesHelper::init(double nLineWidth, const tools::TextLineInfo& rLineInfo)
50 ::basegfx::B2DRange aRange; // default is empty.
51 ::basegfx::B2DPolyPolygon aOverline, aUnderline, aStrikeout;
52 tools::createTextLinesPolyPolygon(0.0, nLineWidth, rLineInfo, aOverline, aUnderline,
53 aStrikeout);
55 mxOverline.clear();
56 mxUnderline.clear();
57 mxStrikeout.clear();
59 uno::Reference<rendering::XGraphicDevice> xDevice = mpCanvas->getUNOCanvas()->getDevice();
61 if (aOverline.count())
63 aRange.expand(::basegfx::utils::getRange(aOverline));
64 mxOverline = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(xDevice, aOverline);
67 if (aUnderline.count())
69 aRange.expand(::basegfx::utils::getRange(aUnderline));
70 mxUnderline = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(xDevice, aUnderline);
73 if (aStrikeout.count())
75 aRange.expand(::basegfx::utils::getRange(aStrikeout));
76 mxStrikeout = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(xDevice, aStrikeout);
79 maOverallSize = aRange.getRange();
81 initLineStyleWaveline(rLineInfo.mnOverlineStyle, mbOverlineWaveline, mbOverlineWavelineBold);
83 initLineStyleWaveline(rLineInfo.mnUnderlineStyle, mbUnderlineWaveline, mbUnderlineWavelineBold);
86 void TextLinesHelper::render(const rendering::RenderState& rRenderState, bool bNormalText) const
88 const rendering::ViewState& rViewState(mpCanvas->getViewState());
89 const uno::Reference<rendering::XCanvas>& xCanvas(mpCanvas->getUNOCanvas());
90 rendering::StrokeAttributes aStrokeAttributes;
91 aStrokeAttributes.JoinType = rendering::PathJoinType::ROUND;
93 if (mxOverline.is())
95 rendering::RenderState aLocalState(rRenderState);
96 if (bNormalText && mbIsOverlineColorSet)
97 aLocalState.DeviceColor = maOverlineColor;
99 if (mbOverlineWaveline)
101 aStrokeAttributes.StrokeWidth = mbOverlineWavelineBold ? 2.0 : 1.0;
102 xCanvas->strokePolyPolygon(mxOverline, rViewState, aLocalState, aStrokeAttributes);
104 else
105 xCanvas->fillPolyPolygon(mxOverline, rViewState, aLocalState);
108 if (mxUnderline.is())
110 rendering::RenderState aLocalState(rRenderState);
111 if (bNormalText && mbIsUnderlineColorSet)
112 aLocalState.DeviceColor = maUnderlineColor;
113 if (mbUnderlineWaveline)
115 aStrokeAttributes.StrokeWidth = mbUnderlineWavelineBold ? 2.0 : 1.0;
116 xCanvas->strokePolyPolygon(mxUnderline, rViewState, aLocalState, aStrokeAttributes);
118 else
119 xCanvas->fillPolyPolygon(mxUnderline, rViewState, aLocalState);
122 if (mxStrikeout.is())
123 xCanvas->fillPolyPolygon(mxStrikeout, rViewState, rRenderState);
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */