LibreOffice Module cppcanvas (master) 1
textlineshelper.cxx
Go to the documentation of this file.
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>
15#include <outdevstate.hxx>
16#include <utility>
17#include "textlineshelper.hxx"
18#include "mtftools.hxx"
19
20using namespace ::com::sun::star;
21
22namespace
23{
24void 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
32namespace cppcanvas::internal
33{
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
47void TextLinesHelper::init(double nLineWidth, const tools::TextLineInfo& rLineInfo)
48{
49 ::basegfx::B2DRange aRange; // default is empty.
50 ::basegfx::B2DPolyPolygon aOverline, aUnderline, aStrikeout;
51 tools::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(::basegfx::utils::getRange(aOverline));
63 mxOverline = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(xDevice, aOverline);
64 }
65
66 if (aUnderline.count())
67 {
68 aRange.expand(::basegfx::utils::getRange(aUnderline));
69 mxUnderline = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(xDevice, aUnderline);
70 }
71
72 if (aStrikeout.count())
73 {
74 aRange.expand(::basegfx::utils::getRange(aStrikeout));
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
85void TextLinesHelper::render(const rendering::RenderState& rRenderState, bool bNormalText) const
86{
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;
91
92 if (mxOverline.is())
93 {
94 rendering::RenderState aLocalState(rRenderState);
95 if (bNormalText && mbIsOverlineColorSet)
96 aLocalState.DeviceColor = maOverlineColor;
97
99 {
100 aStrokeAttributes.StrokeWidth = mbOverlineWavelineBold ? 2.0 : 1.0;
101 xCanvas->strokePolyPolygon(mxOverline, rViewState, aLocalState, aStrokeAttributes);
102 }
103 else
104 xCanvas->fillPolyPolygon(mxOverline, rViewState, aLocalState);
105 }
106
107 if (mxUnderline.is())
108 {
109 rendering::RenderState aLocalState(rRenderState);
110 if (bNormalText && mbIsUnderlineColorSet)
111 aLocalState.DeviceColor = maUnderlineColor;
113 {
114 aStrokeAttributes.StrokeWidth = mbUnderlineWavelineBold ? 2.0 : 1.0;
115 xCanvas->strokePolyPolygon(mxUnderline, rViewState, aLocalState, aStrokeAttributes);
116 }
117 else
118 xCanvas->fillPolyPolygon(mxUnderline, rViewState, aLocalState);
119 }
120
121 if (mxStrikeout.is())
122 xCanvas->fillPolyPolygon(mxStrikeout, rViewState, rRenderState);
123}
124}
125/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
sal_Int32 nLineWidth
CanvasSharedPtr mpCanvas
sal_uInt32 count() const
B2DVector getRange() const
void expand(const Tuple2D< TYPE > &rTuple)
TYPE getX() const
TYPE getY() const
TextLinesHelper(CanvasSharedPtr xCanvas, const OutDevState &rState)
const css::uno::Sequence< double > maOverlineColor
css::uno::Reference< css::rendering::XPolyPolygon2D > mxStrikeout
css::uno::Reference< css::rendering::XPolyPolygon2D > mxOverline
void init(double nLineWidth, const tools::TextLineInfo &rLineInfo)
Init textlines with specified linewidth and TextLineInfo.
void render(const css::rendering::RenderState &rRenderState, bool bNormalText) const
Fill the textlines with colors.
css::uno::Reference< css::rendering::XPolyPolygon2D > mxUnderline
const css::uno::Sequence< double > maUnderlineColor
LINESTYLE_BOLDWAVE
LINESTYLE_DOUBLEWAVE
LINESTYLE_SMALLWAVE
LINESTYLE_WAVE
::basegfx::B2DPolyPolygon createTextLinesPolyPolygon(const ::basegfx::B2DPoint &rStartPos, const double &rLineWidth, const TextLineInfo &rTextLineInfo)
Definition: mtftools.cxx:615
std::shared_ptr< Canvas > CanvasSharedPtr