Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #ifndef _CPPCANVAS_CANVASGRAPHIC_HXX
21 : : #define _CPPCANVAS_CANVASGRAPHIC_HXX
22 : :
23 : : #include <sal/types.h>
24 : :
25 : : #include <boost/shared_ptr.hpp>
26 : : #include <cppcanvas/color.hxx>
27 : : #include <cppcanvas/canvas.hxx>
28 : :
29 : : namespace basegfx
30 : : {
31 : : class B2DHomMatrix;
32 : : class B2DPolyPolygon;
33 : : }
34 : :
35 : :
36 : : /* Definition of CanvasGraphic interface */
37 : :
38 : : namespace cppcanvas
39 : : {
40 : : // forward declaration, since PolyPolygon also derives from CanvasGraphic
41 : : typedef ::boost::shared_ptr< class PolyPolygon > PolyPolygonSharedPtr;
42 : :
43 : :
44 : : /** This interface defines basic properties of
45 : : objects that can be painted on a Canvas
46 : : */
47 : : class CanvasGraphic
48 : : {
49 : : public:
50 : :
51 : : /** These enums determine how the primitive color is combined
52 : : with the background. When performing this calculations, it
53 : : is assumed that all color values are premultiplied with
54 : : the corresponding alpha values (if no alpha is specified,
55 : : 1.0 is assumed). Then, the following general compositing
56 : : operation is performed:
57 : :
58 : : C = Ca * Fa + Cb * Fb
59 : :
60 : : where C is the result color, Ca and Cb are the input
61 : : colors, premultiplied with alpha, and Fa and Fb are
62 : : described for the different composite modes (wherein Aa
63 : : and Ab denote source and destination alpha, respectively).
64 : : */
65 : : enum CompositeOp
66 : : {
67 : : /// Clear destination. Fa = Fb = 0.
68 : : CLEAR,
69 : :
70 : : /// Copy source as-is to destination. Fa = 1, Fb = 0.
71 : : SOURCE,
72 : :
73 : : /// Leave destination as-is. Fa = 0, Fb = 1.
74 : : DESTINATION,
75 : :
76 : : /// Copy source over destination. Fa = 1, Fb = 1-Aa.
77 : : OVER,
78 : :
79 : : /// Copy source under destination. Fa = 1-Ab, Fb = 1.
80 : : UNDER,
81 : :
82 : : /// Copy source to destination, but limited to where the destination is. Fa = Ab, Fb = 0.
83 : : INSIDE,
84 : :
85 : : /// Leave destination as is, but only where source was. Fa = 0, Fb = Aa.
86 : : INSIDE_REVERSE,
87 : :
88 : : /// Copy source to destination, but limited to where destination is not. Fa = 1-Ab, Fb = 0.
89 : : OUTSIDE,
90 : :
91 : : /// Leave destination as is, but only where source has not been. Fa = 0, Fb = 1-Aa.
92 : : OUTSIDE_REVERSE,
93 : :
94 : : /// Copy source over destination, but only where destination is. Keep destination. Fa = Ab, Fb = 1-Aa.
95 : : ATOP,
96 : :
97 : : /// Copy destination over source, but only where source is. Keep source. Fa = 1-Ab, Fb = Aa.
98 : : ATOP_REVERSE,
99 : :
100 : : /// Take only parts where either source or destination, but not both are. Fa = 1-Ab, Fb = 1-Aa.
101 : : XOR,
102 : :
103 : : /** simply add contributions of both source and destination. The
104 : : resulting color values are limited to the permissible color
105 : : range, and clipped to the maximal value, if exceeded. Fa = 1, Fb = 1.
106 : : */
107 : : ADD,
108 : :
109 : : /// Fa = min(1,(1-Ab)/Aa), Fb = 1
110 : : SATURATE
111 : : };
112 : :
113 [ # # ]: 0 : virtual ~CanvasGraphic() {}
114 : :
115 : : /** Set object transformation matrix
116 : : */
117 : : virtual void setTransformation( const ::basegfx::B2DHomMatrix& rMatrix ) = 0;
118 : : /** Get object transformation matrix
119 : : */
120 : : virtual ::basegfx::B2DHomMatrix getTransformation() const = 0;
121 : :
122 : : /** Set object clipping polygon
123 : : */
124 : : virtual void setClip( const ::basegfx::B2DPolyPolygon& rClipPoly ) = 0;
125 : : /** Clear object clipping polygon
126 : : */
127 : : virtual void setClip() = 0;
128 : : /** Get object clipping polygon
129 : :
130 : : @return NULL, if no clip is set; otherwise, the current clip poly-polygon is returned
131 : : */
132 : : virtual ::basegfx::B2DPolyPolygon const* getClip() const = 0;
133 : :
134 : : /** Set object color
135 : : */
136 : : virtual void setRGBAColor( Color::IntSRGBA ) = 0;
137 : : /** Get object color
138 : : */
139 : : virtual Color::IntSRGBA getRGBAColor() const = 0;
140 : :
141 : : /** Set object composite mode
142 : : */
143 : : virtual void setCompositeOp( CompositeOp aOp ) = 0;
144 : : /** Get object composite mode
145 : : */
146 : : virtual CompositeOp getCompositeOp() const = 0;
147 : :
148 : : /** Render to parent canvas
149 : :
150 : : This method renders the content to the parent canvas,
151 : : i.e. the canvas this object was constructed for.
152 : :
153 : : @return whether the rendering finished successfully.
154 : : */
155 : : virtual bool draw() const = 0;
156 : :
157 : : };
158 : :
159 : : typedef ::boost::shared_ptr< ::cppcanvas::CanvasGraphic > CanvasGraphicSharedPtr;
160 : : }
161 : :
162 : : #endif /* _CPPCANVAS_CANVASGRAPHIC_HXX */
163 : :
164 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|