1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_WRITERFILTER_INC_DMAPPER_RESOURCEMODEL_HXX
21 #define INCLUDED_WRITERFILTER_INC_DMAPPER_RESOURCEMODEL_HXX
24 #include <sal/types.h>
25 #include <com/sun/star/drawing/XShape.hpp>
26 #include <com/sun/star/uno/Any.hxx>
27 #include <tools/ref.hxx>
30 @file resourcemodel.hxx
32 The classes in this file define the interfaces for the resource
33 model of the DocTokenizer:
35 @image html doctok.png
37 A resource is a set of events that describe an object. A resource
38 is only an abstract concept. It is not instantiated to a class.
40 A reference to a resource represents the object that the resource
41 describes. The reference can be resolved thereby generating the
42 events of the resource.
44 A handler receives the events generated by resolving a
45 reference. There are several types of handlers each accepting their
46 specific set of events.
48 References always have a parameter determining the kind of handler
49 they send the events they generate to. The set of events generated
50 by resolving the reference is a subset of the events received by
54 typedef sal_uInt32 Id
;
56 namespace writerfilter
59 Reference to a resource that generates events and sends them to a
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.
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!
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.
78 template <class T
> class SAL_DLLPUBLIC_TEMPLATE Reference
: public virtual SvRefBase
84 @attention The ownership of a reference is transferred when
85 the reference is passed.
87 typedef tools::SvRef
<Reference
<T
>> Pointer_t
;
90 Resolves the reference.
92 The events of the references target resource are generated and
95 @param rHandler handler which receives the events
97 virtual void resolve(T
& rHandler
) = 0;
99 Reference() = default;
100 Reference(Reference
const&) = default;
101 Reference(Reference
&&) = default;
102 Reference
& operator=(Reference
const&) = default;
103 Reference
& operator=(Reference
&&) = default;
106 ~Reference() override
{}
113 Handler for properties.
115 class Properties
: public virtual SvRefBase
119 Receives an attribute.
121 @param name name of the attribute
122 @param val value of the attribute
124 virtual void attribute(Id name
, Value
& val
) = 0;
129 @param sprm the SPRM received
131 virtual void sprm(Sprm
& sprm
) = 0;
134 ~Properties() override
{}
140 class Table
: public virtual SvRefBase
143 typedef tools::SvRef
<Table
> Pointer_t
;
146 Receives an entry of the table.
148 @param pos position of the entry in the table
149 @param ref reference to properties of the entry
151 virtual void entry(int pos
, writerfilter::Reference
<Properties
>::Pointer_t ref
) = 0;
158 Handler for binary objects.
164 Receives binary data of the object.
166 @param buf pointer to buffer containing the data
167 @param len size of buffer
169 virtual void data(const sal_uInt8
* buf
, size_t len
) = 0;
175 const sal_uInt8 cFieldStart
= 0x13;
176 const sal_uInt8 cFieldSep
= 0x14;
177 const sal_uInt8 cFieldEnd
= 0x15;
180 Handler for a stream.
182 class Stream
: public virtual SvRefBase
186 Pointer to this stream.
188 typedef tools::SvRef
<Stream
> Pointer_t
;
191 Receives start mark for group with the same section properties.
193 virtual void startSectionGroup() = 0;
196 Receives end mark for group with the same section properties.
198 virtual void endSectionGroup() = 0;
200 /// The current section is the last one in this body text.
201 virtual void markLastSectionGroup(){};
204 Receives start mark for group with the same paragraph properties.
206 virtual void startParagraphGroup() = 0;
209 Receives end mark for group with the same paragraph properties.
211 virtual void endParagraphGroup() = 0;
213 virtual void markLastParagraphInSection(){};
216 Receives start mark for group with the same character properties.
218 virtual void startCharacterGroup() = 0;
221 Receives end mark for group with the same character properties.
223 virtual void endCharacterGroup() = 0;
228 virtual void startShape(css::uno::Reference
<css::drawing::XShape
> const& xShape
) = 0;
230 virtual void endShape() = 0;
233 Receives 8-bit per character text.
235 @param data buffer containing the text
236 @param len number of characters in the text
238 virtual void text(const sal_uInt8
* data
, size_t len
) = 0;
241 Receives 16-bit per character text.
243 @param data buffer containing the text
244 @param len number of characters in the text.
246 virtual void utext(const sal_uInt8
* data
, size_t len
) = 0;
249 * Offset in EMUs for a shape.
251 * Call *before* an ooxml::CT_PosH/V_posOffset sprm is sent.
253 virtual void positionOffset(const OUString
& rText
, bool bVertical
) = 0;
254 /// Returns the last set offsets of a shape in HMM.
255 virtual css::awt::Point
getPositionOffset() = 0;
257 * Horizontal and vertical alignment for a shape.
259 * Call *before* an ooxml:CT_PosH/V_align sprm is sent.
261 virtual void align(const OUString
& rText
, bool bVertical
) = 0;
262 virtual void positivePercentage(const OUString
& rText
) = 0;
265 Receives properties of the current run of text.
267 @param ref reference to the properties
269 virtual void props(writerfilter::Reference
<Properties
>::Pointer_t ref
) = 0;
274 @param name name of the table
275 @param ref reference to the table
277 virtual void table(Id name
, writerfilter::Reference
<Table
>::Pointer_t ref
) = 0;
280 Receives a substream.
282 @param name name of the substream
283 @param ref reference to the substream
285 virtual void substream(Id name
, writerfilter::Reference
<Stream
>::Pointer_t ref
) = 0;
288 Debugging: Receives information about current point in stream.
290 @param info the information
292 virtual void info(const std::string
& info
) = 0;
294 /// Receives start mark for glossary document entry.
295 virtual void startGlossaryEntry() = 0;
297 /// Receives end mark for glossary document entry.
298 virtual void endGlossaryEntry() = 0;
301 ~Stream() override
{}
307 The methods of this class may throw exceptions if a certain aspect
308 makes no sense for a certain value, e.g. the integer value of a
311 class Value
: public virtual SvRefBase
317 typedef tools::SvRef
<Value
> Pointer_t
;
320 Returns integer representation of the value.
322 virtual int getInt() const = 0;
325 Returns string representation of the value.
327 virtual OUString
getString() const = 0;
330 Returns representation of the value as uno::Any.
332 virtual css::uno::Any
getAny() const = 0;
335 Returns properties of this value.
337 virtual writerfilter::Reference
<Properties
>::Pointer_t
getProperties() = 0;
340 Returns binary object of this value.
342 virtual writerfilter::Reference
<BinaryObj
>::Pointer_t
getBinary() = 0;
345 Returns string representation of this value.
348 virtual std::string
toString() const = 0;
353 An SPRM: Section, Paragraph and Run Modifier
356 class Sprm
: public virtual SvRefBase
359 typedef tools::SvRef
<Sprm
> Pointer_t
;
362 Returns id of the SPRM.
364 virtual sal_uInt32
getId() const = 0;
367 Returns value of the SPRM.
369 virtual Value::Pointer_t
getValue() = 0;
372 Returns reference to properties contained in the SPRM.
375 virtual writerfilter::Reference
<Properties
>::Pointer_t
getProps() = 0;
378 Returns name of sprm.
381 virtual std::string
getName() const = 0;
385 Returns string representation of sprm.
388 virtual std::string
toString() const = 0;
395 typedef sal_Int32 Token_t
;
398 #endif // INCLUDED_WRITERFILTER_INC_DMAPPER_RESOURCEMODEL_HXX
400 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */