LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / canvas / source / vcl / canvashelper.hxx
blobba385110bf71973f58139c28f280e169581bc409
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include <com/sun/star/geometry/IntegerPoint2D.hpp>
23 #include <com/sun/star/geometry/IntegerRectangle2D.hpp>
24 #include <com/sun/star/rendering/IntegerBitmapLayout.hpp>
25 #include <com/sun/star/rendering/XCanvas.hpp>
27 #include "cachedbitmap.hxx"
28 #include "outdevprovider.hxx"
31 namespace vclcanvas
33 class SpriteCanvas;
35 /** Helper class for basic canvas functionality. Also offers
36 optional backbuffer painting, when providing it with a second
37 OutputDevice to render into.
39 class CanvasHelper
41 public:
42 /** Create canvas helper
44 CanvasHelper();
46 /// make noncopyable
47 CanvasHelper(const CanvasHelper&) = delete;
48 const CanvasHelper& operator=(const CanvasHelper&) = delete;
50 /// Release all references
51 void disposing();
53 /** Initialize canvas helper
55 This method late-initializes the canvas helper, providing
56 it with the necessary device and output objects. Note that
57 the CanvasHelper does <em>not</em> take ownership of the
58 passed rDevice reference, nor does it perform any
59 reference counting. Thus, to prevent the reference counted
60 SpriteCanvas object from deletion, the user of this class
61 is responsible for holding ref-counted references itself!
63 @param rDevice
64 Reference device this canvas is associated with
66 @param rOutDev
67 Set primary output device for this canvas. That's where
68 all content is output to.
70 @param bProtect
71 When true, all output operations preserve outdev
72 state. When false, outdev state might change at any time.
74 @param bHaveAlpha
75 When true, hasAlpha() will always return true, otherwise, false.
77 void init( css::rendering::XGraphicDevice& rDevice,
78 const OutDevProviderSharedPtr& rOutDev,
79 bool bProtect,
80 bool bHaveAlpha );
82 /** Set primary output device
84 This changes the primary output device, where rendering is
85 sent to.
87 void setOutDev( const OutDevProviderSharedPtr& rOutDev,
88 bool bProtect);
90 /** Set secondary output device
92 Used for sprites, to generate mask bitmap.
94 void setBackgroundOutDev( const OutDevProviderSharedPtr& rOutDev );
97 // CanvasHelper functionality
98 // ==========================
100 // XCanvas (only providing, not implementing the
101 // interface. Also note subtle method parameter differences)
102 void clear();
103 void drawLine( const css::rendering::XCanvas* rCanvas,
104 const css::geometry::RealPoint2D& aStartPoint,
105 const css::geometry::RealPoint2D& aEndPoint,
106 const css::rendering::ViewState& viewState,
107 const css::rendering::RenderState& renderState );
108 void drawBezier( const css::rendering::XCanvas* rCanvas,
109 const css::geometry::RealBezierSegment2D& aBezierSegment,
110 const css::geometry::RealPoint2D& aEndPoint,
111 const css::rendering::ViewState& viewState,
112 const css::rendering::RenderState& renderState );
113 css::uno::Reference< css::rendering::XCachedPrimitive >
114 drawPolyPolygon( const css::rendering::XCanvas* rCanvas,
115 const css::uno::Reference<
116 css::rendering::XPolyPolygon2D >& xPolyPolygon,
117 const css::rendering::ViewState& viewState,
118 const css::rendering::RenderState& renderState );
119 css::uno::Reference< css::rendering::XCachedPrimitive >
120 strokePolyPolygon( const css::rendering::XCanvas* rCanvas,
121 const css::uno::Reference<
122 css::rendering::XPolyPolygon2D >& xPolyPolygon,
123 const css::rendering::ViewState& viewState,
124 const css::rendering::RenderState& renderState,
125 const css::rendering::StrokeAttributes& strokeAttributes );
126 css::uno::Reference< css::rendering::XCachedPrimitive >
127 strokeTexturedPolyPolygon( const css::rendering::XCanvas* rCanvas,
128 const css::uno::Reference<
129 css::rendering::XPolyPolygon2D >& xPolyPolygon,
130 const css::rendering::ViewState& viewState,
131 const css::rendering::RenderState& renderState,
132 const css::uno::Sequence<
133 css::rendering::Texture >& textures,
134 const css::rendering::StrokeAttributes& strokeAttributes );
135 css::uno::Reference< css::rendering::XCachedPrimitive >
136 strokeTextureMappedPolyPolygon( const css::rendering::XCanvas* rCanvas,
137 const css::uno::Reference<
138 css::rendering::XPolyPolygon2D >& xPolyPolygon,
139 const css::rendering::ViewState& viewState,
140 const css::rendering::RenderState& renderState,
141 const css::uno::Sequence<
142 css::rendering::Texture >& textures,
143 const css::uno::Reference<
144 css::geometry::XMapping2D >& xMapping,
145 const css::rendering::StrokeAttributes& strokeAttributes );
146 css::uno::Reference< css::rendering::XPolyPolygon2D >
147 queryStrokeShapes( const css::rendering::XCanvas* rCanvas,
148 const css::uno::Reference<
149 css::rendering::XPolyPolygon2D >& xPolyPolygon,
150 const css::rendering::ViewState& viewState,
151 const css::rendering::RenderState& renderState,
152 const css::rendering::StrokeAttributes& strokeAttributes );
153 css::uno::Reference< css::rendering::XCachedPrimitive >
154 fillPolyPolygon( const css::rendering::XCanvas* rCanvas,
155 const css::uno::Reference<
156 css::rendering::XPolyPolygon2D >& xPolyPolygon,
157 const css::rendering::ViewState& viewState,
158 const css::rendering::RenderState& renderState );
159 css::uno::Reference< css::rendering::XCachedPrimitive >
160 fillTexturedPolyPolygon( const css::rendering::XCanvas* rCanvas,
161 const css::uno::Reference<
162 css::rendering::XPolyPolygon2D >& xPolyPolygon,
163 const css::rendering::ViewState& viewState,
164 const css::rendering::RenderState& renderState,
165 const css::uno::Sequence<
166 css::rendering::Texture >& textures );
167 css::uno::Reference< css::rendering::XCachedPrimitive >
168 fillTextureMappedPolyPolygon( const css::rendering::XCanvas* rCanvas,
169 const css::uno::Reference<
170 css::rendering::XPolyPolygon2D >& xPolyPolygon,
171 const css::rendering::ViewState& viewState,
172 const css::rendering::RenderState& renderState,
173 const css::uno::Sequence<
174 css::rendering::Texture >& textures,
175 const css::uno::Reference<
176 css::geometry::XMapping2D >& xMapping );
178 css::uno::Reference< css::rendering::XCanvasFont >
179 createFont( const css::rendering::XCanvas* rCanvas,
180 const css::rendering::FontRequest& fontRequest,
181 const css::uno::Sequence<
182 css::beans::PropertyValue >& extraFontProperties,
183 const css::geometry::Matrix2D& fontMatrix );
185 css::uno::Sequence< css::rendering::FontInfo >
186 queryAvailableFonts( const css::rendering::XCanvas* rCanvas,
187 const css::rendering::FontInfo& aFilter,
188 const css::uno::Sequence<
189 css::beans::PropertyValue >& aFontProperties );
191 css::uno::Reference< css::rendering::XCachedPrimitive >
192 drawText( const css::rendering::XCanvas* rCanvas,
193 const css::rendering::StringContext& text,
194 const css::uno::Reference<
195 css::rendering::XCanvasFont >& xFont,
196 const css::rendering::ViewState& viewState,
197 const css::rendering::RenderState& renderState,
198 sal_Int8 textDirection );
200 css::uno::Reference< css::rendering::XCachedPrimitive >
201 drawTextLayout( const css::rendering::XCanvas* rCanvas,
202 const css::uno::Reference<
203 css::rendering::XTextLayout >& laidOutText,
204 const css::rendering::ViewState& viewState,
205 const css::rendering::RenderState& renderState );
207 css::uno::Reference< css::rendering::XCachedPrimitive >
208 drawBitmap( const css::rendering::XCanvas* rCanvas,
209 const css::uno::Reference<
210 css::rendering::XBitmap >& xBitmap,
211 const css::rendering::ViewState& viewState,
212 const css::rendering::RenderState& renderState );
213 css::uno::Reference< css::rendering::XCachedPrimitive >
214 drawBitmapModulated( const css::rendering::XCanvas* rCanvas,
215 const css::uno::Reference<
216 css::rendering::XBitmap >& xBitmap,
217 const css::rendering::ViewState& viewState,
218 const css::rendering::RenderState& renderState );
219 // cast away const, need to change refcount (as this is
220 // ~invisible to client code, still logically const)
221 css::uno::Reference< css::rendering::XGraphicDevice >
222 getDevice() { return css::uno::Reference< css::rendering::XGraphicDevice >(mpDevice); }
225 // BitmapCanvasHelper functionality
226 // ================================
228 css::geometry::IntegerSize2D getSize();
230 css::uno::Reference< css::rendering::XBitmap >
231 getScaledBitmap( const css::geometry::RealSize2D& newSize,
232 bool beFast );
234 css::uno::Sequence< sal_Int8 >
235 getData( css::rendering::IntegerBitmapLayout& bitmapLayout,
236 const css::geometry::IntegerRectangle2D& rect );
238 css::uno::Sequence< sal_Int8 >
239 getPixel( css::rendering::IntegerBitmapLayout& bitmapLayout,
240 const css::geometry::IntegerPoint2D& pos );
242 css::rendering::IntegerBitmapLayout getMemoryLayout();
244 /// Repaint a cached bitmap
245 bool repaint( const GraphicObjectSharedPtr& rGrf,
246 const css::rendering::ViewState& viewState,
247 const css::rendering::RenderState& renderState,
248 const ::Point& rPt,
249 const ::Size& rSz,
250 const GraphicAttr& rAttr ) const;
252 /** Flush drawing queue.
254 This only works for Window canvases, and ensures that all
255 pending render operations are flushed to the
256 driver/hardware.
258 void flush() const;
260 enum ColorType
262 LINE_COLOR, FILL_COLOR, TEXT_COLOR, IGNORE_COLOR
265 // returns alpha of color
266 int setupOutDevState( const css::rendering::ViewState& viewState,
267 const css::rendering::RenderState& renderState,
268 ColorType eColorType ) const;
270 bool hasAlpha() const { return mbHaveAlpha; }
272 protected:
273 /** Phyical output device
275 Deliberately not a refcounted reference, because of
276 potential circular references for spritecanvas.
278 css::rendering::XGraphicDevice* mpDevice;
280 /// Rendering to this outdev preserves its state
281 OutDevProviderSharedPtr mpProtectedOutDevProvider;
283 /// Rendering to this outdev does not preserve its state
284 OutDevProviderSharedPtr mpOutDevProvider;
286 /// Rendering to this outdev does not preserve its state
287 OutDevProviderSharedPtr mp2ndOutDevProvider;
289 /// When true, content is able to represent alpha
290 bool mbHaveAlpha;
292 private:
293 css::uno::Reference< css::rendering::XCachedPrimitive >
294 implDrawBitmap( const css::rendering::XCanvas* rCanvas,
295 const css::uno::Reference<
296 css::rendering::XBitmap >& xBitmap,
297 const css::rendering::ViewState& viewState,
298 const css::rendering::RenderState& renderState,
299 bool bModulateColors );
301 bool setupTextOutput( ::Point& o_rOutPos,
302 const css::rendering::ViewState& viewState,
303 const css::rendering::RenderState& renderState,
304 const css::uno::Reference< css::rendering::XCanvasFont >& xFont ) const;
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */