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 INCLUDED_WRITERFILTER_INC_DMAPPER_RESOURCEMODEL_HXX
21 : #define INCLUDED_WRITERFILTER_INC_DMAPPER_RESOURCEMODEL_HXX
22 :
23 : #include <string>
24 : #include <memory>
25 : #include <sal/types.h>
26 : #include <com/sun/star/drawing/XShape.hpp>
27 : #include <com/sun/star/uno/Any.hxx>
28 : /**
29 : @file resourcemodel.hxx
30 :
31 : The classes in this file define the interfaces for the resource
32 : model of the DocTokenizer:
33 :
34 : @image html doctok.png
35 :
36 : A resource is a set of events that describe an object. A resource
37 : is only an abstract concept. It is not instantiated to a class.
38 :
39 : A reference to a resource represents the object that the resource
40 : describes. The reference can be resolved thereby generating the
41 : events of the resource.
42 :
43 : A handler receives the events generated by resolving a
44 : reference. There are several types of handlers each accepting their
45 : specific set of events.
46 :
47 : References always have a parameter determining the kind of handler
48 : they send the events they generate to. The set of events generated
49 : by resolving the reference is a subset of the events received by
50 : the handler.
51 : */
52 :
53 :
54 : typedef sal_uInt32 Id;
55 :
56 : namespace writerfilter {
57 :
58 : /**
59 : Reference to an resource that generates events and sends them to a
60 : handler.
61 :
62 : The reference can be resolved, i.e. the resource generates its
63 : events. The events must be suitable for the handler type given by
64 : the template parameter.
65 :
66 : @attention The parameter of the template does not determine the
67 : type of the reference's target. It determines the type of the handler!
68 :
69 : Example:
70 :
71 : A Word document can be represented as a stream of events. Event
72 : types in a Word document are text, properties, tables, starts and
73 : ends of groups. These can be handled by a stream handler (@see
74 : Stream). Thus a reference to a Word document is resolved by
75 : sending these events to a stream handler.
76 : */
77 :
78 : template <class T>
79 2337541 : class SAL_DLLPUBLIC_TEMPLATE Reference
80 : {
81 : public:
82 : /**
83 : Pointer to reference
84 :
85 : @attention The ownership of a reference is transferred when
86 : the reference is passed.
87 : */
88 : typedef std::shared_ptr< Reference<T> > Pointer_t;
89 :
90 : /**
91 : Resolves the reference.
92 :
93 : The events of the references target resource are generated and
94 : send to a handler.
95 :
96 : @param rHandler handler which receives the events
97 : */
98 : virtual void resolve(T & rHandler) = 0;
99 :
100 : protected:
101 2337541 : ~Reference() {}
102 : };
103 :
104 : class Value;
105 : class Sprm;
106 :
107 : /**
108 : Handler for properties.
109 : */
110 308189 : class Properties
111 : {
112 : public:
113 : /**
114 : Receives an attribute.
115 :
116 : @param name name of the attribute
117 : @param val value of the attribute
118 : */
119 : virtual void attribute(Id name, Value & val) = 0;
120 :
121 : /**
122 : Receives a SPRM.
123 :
124 : @param sprm the SPRM received
125 : */
126 : virtual void sprm(Sprm & sprm) = 0;
127 :
128 : protected:
129 308189 : ~Properties() {}
130 : };
131 :
132 : /**
133 : Handler for tables.
134 : */
135 10935 : class Table
136 : {
137 : public:
138 : typedef std::shared_ptr<Table> Pointer_t;
139 :
140 : /**
141 : Receives an entry of the table.
142 :
143 : @param pos position of the entry in the table
144 : @param ref reference to properties of the entry
145 : */
146 : virtual void entry(int pos, writerfilter::Reference<Properties>::Pointer_t ref) = 0;
147 :
148 : protected:
149 10935 : ~Table() {}
150 : };
151 :
152 : /**
153 : Handler for binary objects.
154 : */
155 3358 : class BinaryObj
156 : {
157 : public:
158 : /**
159 : Receives binary data of the object.
160 :
161 : @param buf pointer to buffer containing the data
162 : @param len size of buffer
163 : @param ref reference to properties of binary object
164 : */
165 : virtual void data(const sal_uInt8* buf, size_t len,
166 : writerfilter::Reference<Properties>::Pointer_t ref) = 0;
167 :
168 : protected:
169 3358 : ~BinaryObj() {}
170 : };
171 :
172 : const sal_uInt8 cFieldStart = 0x13;
173 : const sal_uInt8 cFieldSep = 0x14;
174 : const sal_uInt8 cFieldEnd = 0x15;
175 :
176 : /**
177 : Handler for a stream.
178 : */
179 5105 : class Stream
180 : {
181 : public:
182 :
183 : /**
184 : Pointer to this stream.
185 : */
186 : typedef std::shared_ptr<Stream> Pointer_t;
187 :
188 : /**
189 : Receives start mark for group with the same section properties.
190 : */
191 : virtual void startSectionGroup() = 0;
192 :
193 : /**
194 : Receives end mark for group with the same section properties.
195 : */
196 : virtual void endSectionGroup() = 0;
197 :
198 : /// The current section is the last one in this body text.
199 0 : virtual void markLastSectionGroup( ) { };
200 :
201 : /**
202 : Receives start mark for group with the same paragraph properties.
203 : */
204 : virtual void startParagraphGroup() = 0;
205 :
206 : /**
207 : Receives end mark for group with the same paragraph properties.
208 : */
209 : virtual void endParagraphGroup() = 0;
210 :
211 0 : virtual void markLastParagraphInSection( ) { };
212 :
213 : /**
214 : Receives start mark for group with the same character properties.
215 : */
216 : virtual void startCharacterGroup() = 0;
217 :
218 : /**
219 : Receives end mark for group with the same character properties.
220 : */
221 : virtual void endCharacterGroup() = 0;
222 :
223 : /**
224 : Receives a shape.
225 : */
226 : virtual void startShape(css::uno::Reference<css::drawing::XShape> const& xShape) = 0;
227 :
228 : virtual void endShape( ) = 0;
229 :
230 : /**
231 : Receives 8-bit per character text.
232 :
233 : @param data buffer containing the text
234 : @param len number of characters in the text
235 : */
236 : virtual void text(const sal_uInt8 * data, size_t len) = 0;
237 :
238 : /**
239 : Receives 16-bit per character text.
240 :
241 : @param data buffer containing the text
242 : @param len number of characters in the text.
243 : */
244 : virtual void utext(const sal_uInt8 * data, size_t len) = 0;
245 :
246 : /**
247 : * Offset in EMUs for a shape.
248 : *
249 : * Call *before* an ooxml::CT_PosH/V_posOffset sprm is sent.
250 : */
251 : virtual void positionOffset(const OUString& rText, bool bVertical) = 0;
252 : /// Returns the last set offsets of a shape in HMM.
253 : virtual css::awt::Point getPositionOffset() = 0;
254 : /**
255 : * Horizontal and vertical alignment for a shape.
256 : *
257 : * Call *before* an ooxml:CT_PosH/V_align sprm is sent.
258 : */
259 : virtual void align(const OUString& rText, bool bVertical) = 0;
260 : virtual void positivePercentage(const OUString& rText) = 0;
261 :
262 : /**
263 : Receives properties of the current run of text.
264 :
265 : @param ref reference to the properties
266 : */
267 : virtual void props(writerfilter::Reference<Properties>::Pointer_t ref) = 0;
268 :
269 : /**
270 : Receives table.
271 :
272 : @param name name of the table
273 : @param ref referecne to the table
274 : */
275 : virtual void table(Id name,
276 : writerfilter::Reference<Table>::Pointer_t ref) = 0;
277 :
278 : /**
279 : Receives a substream.
280 :
281 : @param name name of the substream
282 : @param ref reference to the substream
283 : */
284 : virtual void substream(Id name,
285 : writerfilter::Reference<Stream>::Pointer_t ref) = 0;
286 :
287 :
288 : /**
289 : Debugging: Receives information about current point in stream.
290 :
291 : @param info the information
292 : */
293 : virtual void info(const std::string & info) = 0;
294 :
295 : protected:
296 5105 : ~Stream() {}
297 : };
298 :
299 : /**
300 : A value.
301 :
302 : The methods of this class may throw exceptions if a certain aspect
303 : makes no sense for a certain value, e.g. the integer value of a
304 : string.
305 : */
306 8053539 : class Value
307 : {
308 : public:
309 : /**
310 : Pointer to a value.
311 : */
312 : typedef std::unique_ptr<Value> Pointer_t;
313 :
314 8053539 : virtual ~Value() {}
315 :
316 : /**
317 : Returns integer representation of the value.
318 : */
319 : virtual int getInt() const = 0;
320 :
321 : /**
322 : Returns string representation of the value.
323 : */
324 : virtual OUString getString() const = 0;
325 :
326 : /**
327 : Returns representation of the value as uno::Any.
328 : */
329 : virtual css::uno::Any getAny() const = 0;
330 :
331 : /**
332 : Returns properties of this value.
333 : */
334 : virtual writerfilter::Reference<Properties>::Pointer_t getProperties() = 0;
335 :
336 : /**
337 : Returns stream of this value.
338 : */
339 : virtual writerfilter::Reference<Stream>::Pointer_t getStream() = 0;
340 :
341 : /**
342 : Returns binary object of this value.
343 : */
344 : virtual writerfilter::Reference<BinaryObj>::Pointer_t getBinary() = 0;
345 :
346 : /**
347 : Returns string representation of this value.
348 : */
349 : #ifdef DEBUG_WRITERFILTER
350 : virtual std::string toString() const = 0;
351 : #endif
352 : };
353 :
354 : /**
355 : An SPRM.
356 :
357 : */
358 3783943 : class Sprm
359 : {
360 : public:
361 : typedef std::unique_ptr<Sprm> Pointer_t;
362 :
363 : /**
364 : Returns id of the SPRM.
365 : */
366 : virtual sal_uInt32 getId() const = 0;
367 :
368 : /**
369 : Returns value of the SPRM.
370 : */
371 : virtual Value::Pointer_t getValue() = 0;
372 :
373 : /**
374 : Returns reference to binary object contained in the SPRM.
375 : */
376 : virtual writerfilter::Reference<BinaryObj>::Pointer_t getBinary() = 0;
377 :
378 : /**
379 : Returns reference to stream associated with the SPRM.
380 : */
381 : virtual writerfilter::Reference<Stream>::Pointer_t getStream() = 0;
382 :
383 : /**
384 : Returns reference to properties contained in the SPRM.
385 :
386 : */
387 : virtual writerfilter::Reference<Properties>::Pointer_t getProps() = 0;
388 :
389 : /**
390 : Returns name of sprm.
391 : */
392 : #ifdef DEBUG_WRITERFILTER
393 : virtual std::string getName() const = 0;
394 : #endif
395 :
396 : /**
397 : Returns string repesentation of sprm.
398 : */
399 : #ifdef DEBUG_WRITERFILTER
400 : virtual std::string toString() const = 0;
401 : #endif
402 :
403 : protected:
404 3783943 : ~Sprm() {}
405 : };
406 :
407 : typedef sal_Int32 Token_t;
408 :
409 : }
410 :
411 : #endif // INCLUDED_WRITERFILTER_INC_DMAPPER_RESOURCEMODEL_HXX
412 :
413 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|