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/.
12 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
13 #include <basegfx/color/bcolormodifier.hxx>
14 #include <tools/long.hxx>
15 #include <sal/config.h>
20 namespace drawinglayer::primitive2d
22 class PolyPolygonColorPrimitive2D
;
23 class PolygonHairlinePrimitive2D
;
24 class BitmapPrimitive2D
;
25 class UnifiedTransparencePrimitive2D
;
26 class BackgroundColorPrimitive2D
;
27 class TransparencePrimitive2D
;
28 class InvertPrimitive2D
;
29 class MaskPrimitive2D
;
30 class ModifiedColorPrimitive2D
;
31 class TransformPrimitive2D
;
32 class PointArrayPrimitive2D
;
33 class MarkerArrayPrimitive2D
;
34 class PolygonStrokePrimitive2D
;
35 class LineRectanglePrimitive2D
;
36 class FilledRectanglePrimitive2D
;
37 class SingleLinePrimitive2D
;
38 class FillGradientPrimitive2D
;
39 class PolyPolygonRGBAGradientPrimitive2D
;
40 class FillGraphicPrimitive2D
;
41 class PolyPolygonRGBAPrimitive2D
;
42 class PolyPolygonAlphaGradientPrimitive2D
;
43 class BitmapAlphaPrimitive2D
;
44 class TextSimplePortionPrimitive2D
;
45 class TextDecoratedPortionPrimitive2D
;
46 class TextLayouterDevice
;
47 class SvgLinearGradientPrimitive2D
;
48 class SvgRadialGradientPrimitive2D
;
49 class SvgGradientHelper
;
57 namespace basegfx::utils
59 class B2DHomMatrixBufferedOnDemandDecompose
;
65 namespace drawinglayer::processor2d
67 class UNLESS_MERGELIBS(DRAWINGLAYER_DLLPUBLIC
) CairoPixelProcessor2D final
: public BaseProcessor2D
69 // the modifiedColorPrimitive stack
70 basegfx::BColorModifierStack maBColorModifierStack
;
72 // cairo_surface_t created when initial clip from the constructor
73 // parameters is requested, or by the constructor that creates an
75 cairo_surface_t
* mpOwnedSurface
;
77 // cairo specific data, the render target
80 // get text render config settings
81 bool mbRenderSimpleTextDirect
;
82 bool mbRenderDecoratedTextDirect
;
84 // recursion counter for CairoPixelProcessor2D::processMaskPrimitive2D,
86 sal_uInt16 mnClipRecursionCount
;
88 // helpers for direct paints
89 void paintPolyPoylgonRGBA(const basegfx::B2DPolyPolygon
& rPolyPolygon
,
90 const basegfx::BColor
& rColor
, double fTransparency
= 0.0);
91 void processPolygonHairlinePrimitive2D(
92 const primitive2d::PolygonHairlinePrimitive2D
& rPolygonHairlinePrimitive2D
);
93 void processPolyPolygonColorPrimitive2D(
94 const primitive2d::PolyPolygonColorPrimitive2D
& rPolyPolygonColorPrimitive2D
);
95 void processBitmapPrimitive2D(const primitive2d::BitmapPrimitive2D
& rBitmapCandidate
);
97 processTransparencePrimitive2D(const primitive2d::TransparencePrimitive2D
& rTransCandidate
);
98 void processInvertPrimitive2D(const primitive2d::InvertPrimitive2D
& rTransCandidate
);
99 void processUnifiedTransparencePrimitive2D(
100 const primitive2d::UnifiedTransparencePrimitive2D
& rTransCandidate
);
101 void processMaskPrimitive2D(const primitive2d::MaskPrimitive2D
& rMaskCandidate
);
102 void processModifiedColorPrimitive2D(
103 const primitive2d::ModifiedColorPrimitive2D
& rModifiedCandidate
);
104 void processTransformPrimitive2D(const primitive2d::TransformPrimitive2D
& rTransformCandidate
);
106 processPointArrayPrimitive2D(const primitive2d::PointArrayPrimitive2D
& rPointArrayCandidate
);
108 processMarkerArrayPrimitive2D(const primitive2d::MarkerArrayPrimitive2D
& rMarkerArrayCandidate
);
109 void processBackgroundColorPrimitive2D(
110 const primitive2d::BackgroundColorPrimitive2D
& rBackgroundColorCandidate
);
111 void processPolygonStrokePrimitive2D(
112 const primitive2d::PolygonStrokePrimitive2D
& rPolygonStrokeCandidate
);
113 void processLineRectanglePrimitive2D(
114 const primitive2d::LineRectanglePrimitive2D
& rLineRectanglePrimitive2D
);
115 void processFilledRectanglePrimitive2D(
116 const primitive2d::FilledRectanglePrimitive2D
& rFilledRectanglePrimitive2D
);
118 processSingleLinePrimitive2D(const primitive2d::SingleLinePrimitive2D
& rSingleLinePrimitive2D
);
119 void processFillGradientPrimitive2D(
120 const primitive2d::FillGradientPrimitive2D
& rFillGradientPrimitive2D
);
121 void processFillGraphicPrimitive2D(
122 const primitive2d::FillGraphicPrimitive2D
& rFillGraphicPrimitive2D
);
123 void processPolyPolygonRGBAPrimitive2D(
124 const primitive2d::PolyPolygonRGBAPrimitive2D
& rPolyPolygonRGBAPrimitive2D
);
125 void processPolyPolygonAlphaGradientPrimitive2D(
126 const primitive2d::PolyPolygonAlphaGradientPrimitive2D
&
127 rPolyPolygonAlphaGradientPrimitive2D
);
128 void paintBitmapAlpha(const BitmapEx
& rBitmapEx
, const basegfx::B2DHomMatrix
& rTransform
,
129 double fTransparency
= 0.0);
130 void processBitmapAlphaPrimitive2D(
131 const primitive2d::BitmapAlphaPrimitive2D
& rBitmapAlphaPrimitive2D
);
133 void processTextSimplePortionPrimitive2D(
134 const primitive2d::TextSimplePortionPrimitive2D
& rCandidate
);
135 void processTextDecoratedPortionPrimitive2D(
136 const primitive2d::TextDecoratedPortionPrimitive2D
& rCandidate
);
138 // helpers for text rendering
139 void renderTextSimpleOrDecoratedPortionPrimitive2D(
140 const primitive2d::TextSimplePortionPrimitive2D
& rTextCandidate
,
141 const primitive2d::TextDecoratedPortionPrimitive2D
* pDecoratedCandidate
);
142 void renderTextBackground(const primitive2d::TextSimplePortionPrimitive2D
& rTextCandidate
,
143 double fAscent
, double fDescent
,
144 const basegfx::B2DHomMatrix
& rTransform
, double fTextWidth
);
145 void renderSalLayout(const std::unique_ptr
<SalLayout
>& rSalLayout
,
146 const basegfx::BColor
& rTextColor
, const basegfx::B2DHomMatrix
& rTransform
,
147 bool bAntiAliase
) const;
148 void renderTextDecorationWithOptionalTransformAndColor(
149 const primitive2d::TextDecoratedPortionPrimitive2D
& rDecoratedCandidate
,
150 const basegfx::utils::B2DHomMatrixBufferedOnDemandDecompose
& rDecTrans
,
151 const basegfx::B2DHomMatrix
* pOptionalObjectTransform
= nullptr,
152 const basegfx::BColor
* pReplacementColor
= nullptr);
154 // support for SVG gradients
155 void processSvgLinearGradientPrimitive2D(
156 const primitive2d::SvgLinearGradientPrimitive2D
& rCandidate
);
157 void processSvgRadialGradientPrimitive2D(
158 const primitive2d::SvgRadialGradientPrimitive2D
& rCandidate
);
159 bool handleSvgGradientHelper(const primitive2d::SvgGradientHelper
& rCandidate
);
161 /* the local processor for BasePrimitive2D-Implementation based primitives,
162 called from the common process()-implementation
164 virtual void processBasePrimitive2D(const primitive2d::BasePrimitive2D
& rCandidate
) override
;
166 // helpers for gradients
167 void processFillGradientPrimitive2D_fallback_decompose(
168 const primitive2d::FillGradientPrimitive2D
& rFillGradientPrimitive2D
);
169 void processFillGradientPrimitive2D_drawOutputRange(
170 const primitive2d::FillGradientPrimitive2D
& rFillGradientPrimitive2D
);
171 bool processFillGradientPrimitive2D_isCompletelyBordered(
172 const primitive2d::FillGradientPrimitive2D
& rFillGradientPrimitive2D
);
173 void processFillGradientPrimitive2D_linear_axial(
174 const primitive2d::FillGradientPrimitive2D
& rFillGradientPrimitive2D
);
175 void processFillGradientPrimitive2D_radial_elliptical(
176 const primitive2d::FillGradientPrimitive2D
& rFillGradientPrimitive2D
);
177 void processFillGradientPrimitive2D_square_rect(
178 const primitive2d::FillGradientPrimitive2D
& rFillGradientPrimitive2D
);
181 bool hasError() const { return cairo_status(mpRT
) != CAIRO_STATUS_SUCCESS
; }
182 bool hasRenderTarget() const { return nullptr != mpRT
; }
185 bool valid() const { return hasRenderTarget() && !hasError(); }
187 // constructor to create a CairoPixelProcessor2D which
188 // allocates and owns a cairo surface of given size. You
189 // should check the result using valid()
190 CairoPixelProcessor2D(
192 // the initial ViewInformation
193 const geometry::ViewInformation2D
& rViewInformation
,
196 tools::Long nWidthPixel
, tools::Long nHeightPixel
,
198 // define RGBA (true) or RGB (false)
201 // constructor to create a CairoPixelProcessor2D for
202 // the given cairo_surface_t pTarget. pTarget will not
203 // be owned and not destroyed, but be used as render
204 // target. If needed you can define a sub-rectangle
205 // to which the rendering will be limited (clipped).
206 // You should check the result using valid()
207 CairoPixelProcessor2D(
209 // the initial ViewInformation
210 const geometry::ViewInformation2D
& rViewInformation
,
212 // the cairo render target
213 cairo_surface_t
* pTarget
,
215 // optional: possibility to add an initial clip relative to
216 // the real pixel dimensions of the target surface
217 tools::Long nOffsetPixelX
= 0, tools::Long nOffsetPixelY
= 0, tools::Long nWidthPixel
= 0,
218 tools::Long nHeightPixel
= 0);
220 virtual ~CairoPixelProcessor2D() override
;
222 // access to BColorModifierStack
223 const basegfx::BColorModifierStack
& getBColorModifierStack() const
225 return maBColorModifierStack
;
227 void setBColorModifierStack(const basegfx::BColorModifierStack
& rStack
)
229 maBColorModifierStack
= rStack
;
232 // try to extract current content as BitmapEx
233 BitmapEx
extractBitmapEx() const;
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */