1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _CPPCANVAS_CANVASGRAPHIC_HXX 25 #define _CPPCANVAS_CANVASGRAPHIC_HXX 26 27 #include <sal/types.h> 28 29 #include <boost/shared_ptr.hpp> 30 #include <cppcanvas/color.hxx> 31 #include <cppcanvas/canvas.hxx> 32 33 namespace basegfx 34 { 35 class B2DHomMatrix; 36 class B2DPolyPolygon; 37 } 38 39 40 /* Definition of CanvasGraphic interface */ 41 42 namespace cppcanvas 43 { 44 // forward declaration, since PolyPolygon also derives from CanvasGraphic 45 typedef ::boost::shared_ptr< class PolyPolygon > PolyPolygonSharedPtr; 46 47 48 /** This interface defines basic properties of 49 objects that can be painted on a Canvas 50 */ 51 class CanvasGraphic 52 { 53 public: 54 55 /** These enums determine how the primitive color is combined 56 with the background. When performing this calculations, it 57 is assumed that all color values are premultiplied with 58 the corresponding alpha values (if no alpha is specified, 59 1.0 is assumed). Then, the following general compositing 60 operation is performed: 61 62 C = Ca * Fa + Cb * Fb 63 64 where C is the result color, Ca and Cb are the input 65 colors, premultiplied with alpha, and Fa and Fb are 66 described for the different composite modes (wherein Aa 67 and Ab denote source and destination alpha, respectively). 68 */ 69 enum CompositeOp 70 { 71 /// Clear destination. Fa = Fb = 0. 72 CLEAR, 73 74 /// Copy source as-is to destination. Fa = 1, Fb = 0. 75 SOURCE, 76 77 /// Leave destination as-is. Fa = 0, Fb = 1. 78 DESTINATION, 79 80 /// Copy source over destination. Fa = 1, Fb = 1-Aa. 81 OVER, 82 83 /// Copy source under destination. Fa = 1-Ab, Fb = 1. 84 UNDER, 85 86 /// Copy source to destination, but limited to where the destination is. Fa = Ab, Fb = 0. 87 INSIDE, 88 89 /// Leave destination as is, but only where source was. Fa = 0, Fb = Aa. 90 INSIDE_REVERSE, 91 92 /// Copy source to destination, but limited to where destination is not. Fa = 1-Ab, Fb = 0. 93 OUTSIDE, 94 95 /// Leave destination as is, but only where source has not been. Fa = 0, Fb = 1-Aa. 96 OUTSIDE_REVERSE, 97 98 /// Copy source over destination, but only where destination is. Keep destination. Fa = Ab, Fb = 1-Aa. 99 ATOP, 100 101 /// Copy destination over source, but only where source is. Keep source. Fa = 1-Ab, Fb = Aa. 102 ATOP_REVERSE, 103 104 /// Take only parts where either source or destination, but not both are. Fa = 1-Ab, Fb = 1-Aa. 105 XOR, 106 107 /** simply add contributions of both source and destination. The 108 resulting color values are limited to the permissible color 109 range, and clipped to the maximal value, if exceeded. Fa = 1, Fb = 1. 110 */ 111 ADD, 112 113 /// Fa = min(1,(1-Ab)/Aa), Fb = 1 114 SATURATE 115 }; 116 ~CanvasGraphic()117 virtual ~CanvasGraphic() {} 118 119 /** Set object transformation matrix 120 */ 121 virtual void setTransformation( const ::basegfx::B2DHomMatrix& rMatrix ) = 0; 122 /** Get object transformation matrix 123 */ 124 virtual ::basegfx::B2DHomMatrix getTransformation() const = 0; 125 126 /** Set object clipping polygon 127 */ 128 virtual void setClip( const ::basegfx::B2DPolyPolygon& rClipPoly ) = 0; 129 /** Clear object clipping polygon 130 */ 131 virtual void setClip() = 0; 132 /** Get object clipping polygon 133 134 @return NULL, if no clip is set; otherwise, the current clip poly-polygon is returned 135 */ 136 virtual ::basegfx::B2DPolyPolygon const* getClip() const = 0; 137 138 /** Set object color 139 */ 140 virtual void setRGBAColor( Color::IntSRGBA ) = 0; 141 /** Get object color 142 */ 143 virtual Color::IntSRGBA getRGBAColor() const = 0; 144 145 /** Set object composite mode 146 */ 147 virtual void setCompositeOp( CompositeOp aOp ) = 0; 148 /** Get object composite mode 149 */ 150 virtual CompositeOp getCompositeOp() const = 0; 151 152 /** Render to parent canvas 153 154 This method renders the content to the parent canvas, 155 i.e. the canvas this object was constructed for. 156 157 @return whether the rendering finished successfully. 158 */ 159 virtual bool draw() const = 0; 160 161 }; 162 163 typedef ::boost::shared_ptr< ::cppcanvas::CanvasGraphic > CanvasGraphicSharedPtr; 164 } 165 166 #endif /* _CPPCANVAS_CANVASGRAPHIC_HXX */ 167