Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef INCLUDED_DRAWINGLAYER_PROCESSOR2D_BASEPROCESSOR2D_HXX
30 : : #define INCLUDED_DRAWINGLAYER_PROCESSOR2D_BASEPROCESSOR2D_HXX
31 : :
32 : : #include <drawinglayer/drawinglayerdllapi.h>
33 : :
34 : : #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
35 : : #include <drawinglayer/geometry/viewinformation2d.hxx>
36 : :
37 : : //////////////////////////////////////////////////////////////////////////////
38 : :
39 : : namespace drawinglayer
40 : : {
41 : : namespace processor2d
42 : : {
43 : : /** BaseProcessor2D class
44 : :
45 : : Baseclass for all C++ implementations of instances which process
46 : : primitives.
47 : :
48 : : Instances which process primitives can be renderers, but also stuff
49 : : for HitTests, BoundRect calculations and/or animation processing. The
50 : : main usage are renderers, but they are supposed to handle any primitive
51 : : processing.
52 : :
53 : : The base implementation is constructed with a ViewInformation2D which
54 : : is accessible throughout the processor implementations. The idea is
55 : : to construct any processor with a given ViewInformation2D. To be able
56 : : to handle primitives which need to change the current transformation
57 : : (as e.g. TransformPrimitive2D) it is allowed for the processor implementation
58 : : to change tis local value using updateViewInformation.
59 : :
60 : : The basic processing method is process(..) which gets handed over the
61 : : sequence of primitives to process. For convenience of the C++ implementations,
62 : : the default implementation of process(..) maps all accesses to primitives to
63 : : single calls to processBasePrimitive2D(..) where the primitive in question is
64 : : already casted to the C++ implementation class.
65 : :
66 : : The process(..) implementation makes a complete iteration over the given
67 : : sequence of primitives. If the Primitive is not derived from BasePrimitive2D
68 : : and thus not part of the C++ implementations, it converts ViewInformation2D
69 : : to the corresponding API implementation (an uno::Sequence< beans::PropertyValue >)
70 : : and recursively calls the method process(..) at the primitive with the decomposition
71 : : derived from that primitive. This is the preparation to handle unknown implementations
72 : : of the com::sun::star::graphic::XPrimitive2D interface in the future.
73 : :
74 : : So, to implement a basic processor, it is necessary to overload and implement the
75 : : processBasePrimitive2D(..) method. A minimal renderer has to support the
76 : : Basic Primitives (see baseprimitive2d.hxx) and the Grouping Primitives (see
77 : : groupprimitive2d.hxx). These are (currently):
78 : :
79 : : Basic Primitives:
80 : :
81 : : - BitmapPrimitive2D (bitmap data, evtl. with transparence)
82 : : - PointArrayPrimitive2D (single points)
83 : : - PolygonHairlinePrimitive2D (hairline curves/polygons)
84 : : - PolyPolygonColorPrimitive2D (colored polygons)
85 : :
86 : : Grouping Primitives:
87 : :
88 : : - TransparencePrimitive2D (objects with freely defined transparence)
89 : : - InvertPrimitive2D (for XOR)
90 : : - MaskPrimitive2D (for masking)
91 : : - ModifiedColorPrimitive2D (for a stack of color modifications)
92 : : - TransformPrimitive2D (for a transformation stack)
93 : :
94 : : A processor doing so is a minimal processor. Of course a processor may
95 : : handle any higher-level prmitive (that has a decomposition implementation)
96 : : for more direct data access or performance reasons, too.
97 : :
98 : : The main part of a processBasePrimitive2D implementation is a switch..case
99 : : construct, looking like the following:
100 : :
101 : : void foo::processBasePrimitive2D(const BasePrimitive2D& rCandidate)
102 : : {
103 : : switch(rCandidate.getPrimitive2DID())
104 : : {
105 : : case PRIMITIVE2D_ID_??? :
106 : : {
107 : : // process PRIMITIVE2D_ID_??? here...
108 : :
109 : : ...
110 : :
111 : : break;
112 : : }
113 : :
114 : : ...
115 : :
116 : : default :
117 : : {
118 : : // process recursively
119 : : process(rCandidate.get2DDecomposition(getViewInformation2D()));
120 : : break;
121 : : }
122 : : }
123 : : }
124 : :
125 : : The default case makes the processor work with all complex primitives
126 : : by recursively using their decomposition.
127 : :
128 : : You can also add a case for ignoring primitives by using:
129 : :
130 : : case PRIMITIVE2D_ID_...IGNORE.A.. :
131 : : case PRIMITIVE2D_ID_...IGNORE.B.. :
132 : : case PRIMITIVE2D_ID_...IGNORE.C.. :
133 : : {
134 : : // ignore these primitives by neither processing nor
135 : : // recursively processing their decomposition
136 : : break;
137 : : }
138 : :
139 : : Another useful case is embedding the processing of a complex primitive by
140 : : bracketing it with some actions:
141 : :
142 : : case PRIMITIVE2D_ID_SOME_TEXT :
143 : : {
144 : : // encapsulate e.g. with changing local varibles, e.g.
145 : : // sometimes it's good to know if a basic primitive is
146 : : // part of a text, especially when not handling the text
147 : : // self but by purpose want to handle the decomposed
148 : : // geometries in the processor
149 : : startText();
150 : : process(rCandidate.get2DDecomposition(getViewInformation2D()));
151 : : endText();
152 : : break;
153 : : }
154 : :
155 : : As an example a processor collecting the outlines of a sequence of primitives
156 : : only needs to handle some Basic Primitives and create outline and collect
157 : : outline polygons e.g. for primitives with area like BitmapPrimitive2D (a
158 : : rectangle) and PolyPolygonColorPrimitive2D. When also handling the Grouping
159 : : Primitives MaskPrimitive2D (e.g. ignoring it's content, using the mask polyPolygon)
160 : : and TransformPrimitive2D (to have the correct local transformation), a processor
161 : : creating the outline can be written using just four (4) primitives. As a tipp, it can
162 : : be helpful to add many for the purpose not interesting higher level primitives
163 : : to not force their decomposition to be created and/or parsed.
164 : : */
165 : : class DRAWINGLAYER_DLLPUBLIC BaseProcessor2D
166 : : {
167 : : private:
168 : : /// The ViewInformation2D itself. It's private to isolate accesses to it
169 : : geometry::ViewInformation2D maViewInformation2D;
170 : :
171 : : protected:
172 : : /* access method to allow the implementations to change the current
173 : : ViewInformation2D if needed. This allows isolating these accesses
174 : : later if needed
175 : : */
176 : 8712 : void updateViewInformation(const geometry::ViewInformation2D& rViewInformation2D)
177 : : {
178 : 8712 : maViewInformation2D = rViewInformation2D;
179 : 8712 : }
180 : :
181 : : /* as tooling, the process() implementation takes over API handling and calls this
182 : : virtual render method when the primitive implementation is BasePrimitive2D-based.
183 : : Default implementation does nothing
184 : : */
185 : : virtual void processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate);
186 : :
187 : : public:
188 : : /// constructor/destructor
189 : : explicit BaseProcessor2D(const geometry::ViewInformation2D& rViewInformation);
190 : : virtual ~BaseProcessor2D();
191 : :
192 : : /// the central processing method
193 : : virtual void process(const primitive2d::Primitive2DSequence& rSource);
194 : :
195 : : /// data read access
196 : 291623 : const geometry::ViewInformation2D& getViewInformation2D() const { return maViewInformation2D; }
197 : : };
198 : : } // end of namespace processor2d
199 : : } // end of namespace drawinglayer
200 : :
201 : : //////////////////////////////////////////////////////////////////////////////
202 : :
203 : : #endif //INCLUDED_DRAWINGLAYER_PROCESSOR2D_BASEPROCESSOR2D_HXX
204 : :
205 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|