WPSListener.h Source File documentation

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

WPSListener.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwps
3 * Version: MPL 2.0 / LGPLv2.1+
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 * Major Contributor(s):
10 * Copyright (C) 2006, 2007 Andrew Ziem
11 * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
12 * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
13 * Copyright (C) 2003 Marc Maurer (uwog@uwog.net)
14 *
15 * For minor contributions see the git repository.
16 *
17 * Alternatively, the contents of this file may be used under the terms
18 * of the GNU Lesser General Public License Version 2.1 or later
19 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
20 * applicable instead of those above.
21 *
22 * For further information visit http://libwps.sourceforge.net
23 */
24
25 #ifndef WPSLISTENER_H
26 #define WPSLISTENER_H
27
28 #include <librevenge/librevenge.h>
29
30 #include "libwps_internal.h"
31
32 struct WPSParagraph;
33 struct WPSTabStop;
34
36 class WPSListener
37 {
38 public:
39 WPSListener() {}
40 virtual ~WPSListener() {}
41
42 virtual void setDocumentLanguage(int lcid)=0;
43
44 // ------ text data -----------
45
47 virtual void insertCharacter(uint8_t character)=0;
51 virtual void insertUnicode(uint32_t character)=0;
53 virtual void insertUnicodeString(librevenge::RVNGString const &str)=0;
55 static void appendUnicode(uint32_t val, librevenge::RVNGString &buffer)
56 {
57 if (val < 0x20)
58 {
59 WPS_DEBUG_MSG(("WPSListener::appendUnicode: find an old char %x, skip it\n", val));
60 return;
61 }
62 uint8_t first;
63 int len;
64 if (val < 0x80)
65 {
66 first = 0;
67 len = 1;
68 }
69 else if (val < 0x800)
70 {
71 first = 0xc0;
72 len = 2;
73 }
74 else if (val < 0x10000)
75 {
76 first = 0xe0;
77 len = 3;
78 }
79 else if (val < 0x200000)
80 {
81 first = 0xf0;
82 len = 4;
83 }
84 else if (val < 0x4000000)
85 {
86 first = 0xf8;
87 len = 5;
88 }
89 else
90 {
91 first = 0xfc;
92 len = 6;
93 }
94
95 uint8_t outbuf[6] = { 0, 0, 0, 0, 0, 0 };
96 int i;
97 for (i = len - 1; i > 0; --i)
98 {
99 outbuf[i] = uint8_t((val & 0x3f) | 0x80);
100 val >>= 6;
101 }
102 outbuf[0] = uint8_t(val | first);
103 for (i = 0; i < len; i++) buffer.append(char(outbuf[i]));
104 }
105
106 virtual void insertTab()=0;
107 virtual void insertEOL(bool softBreak=false)=0;
108 virtual void insertBreak(const uint8_t breakType)=0;
109
110 // ------ text format -----------
112 virtual void setFont(const WPSFont &font)=0;
114 virtual WPSFont const &getFont() const=0;
115
116 // ------ paragraph format -----------
118 virtual bool isParagraphOpened() const=0;
120 virtual void setParagraph(const WPSParagraph &para)=0;
122 virtual WPSParagraph const &getParagraph() const=0;
123
124 // ------- fields ----------------
126 enum FieldType { None, PageNumber, Date, Time, Title, Link, Database };
128 virtual void insertField(FieldType type) = 0;
130 virtual void insertDateTimeField(char const *format)=0;
131 };
132
133 #endif
134 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
WPSParagraph
class to store the paragraph properties
Definition: WPSParagraph.h:55
WPSListener::insertUnicode
virtual void insertUnicode(uint32_t character)=0
adds an unicode character
WPSFont
define the font properties
Definition: WPSFont.h:37
WPSListener::Time
Definition: WPSListener.h:126
WPSListener::insertTab
virtual void insertTab()=0
WPSListener
virtual class for content listener
Definition: WPSListener.h:36
WPSListener::insertBreak
virtual void insertBreak(const uint8_t breakType)=0
WPSListener::WPSListener
WPSListener()
Definition: WPSListener.h:39
WPSListener::insertCharacter
virtual void insertCharacter(uint8_t character)=0
adds a basic character, ..
WPSListener::getParagraph
virtual WPSParagraph const & getParagraph() const =0
returns the actual paragraph
WPSListener::~WPSListener
virtual ~WPSListener()
Definition: WPSListener.h:40
libwps_internal.h
WPSListener::insertField
virtual void insertField(FieldType type)=0
adds a field type
WPSListener::PageNumber
Definition: WPSListener.h:126
WPSListener::setFont
virtual void setFont(const WPSFont &font)=0
set the actual font
WPSListener::insertDateTimeField
virtual void insertDateTimeField(char const *format)=0
insert a date/time field with given format (see strftime)
WPSListener::Database
Definition: WPSListener.h:126
WPSListener::Title
Definition: WPSListener.h:126
WPSListener::isParagraphOpened
virtual bool isParagraphOpened() const =0
returns true if a paragraph or a list is opened
WPSListener::FieldType
FieldType
Defines some basic type for field.
Definition: WPSListener.h:126
WPS_DEBUG_MSG
#define WPS_DEBUG_MSG(M)
Definition: libwps_internal.h:115
WPSListener::Date
Definition: WPSListener.h:126
WPSListener::getFont
virtual WPSFont const & getFont() const =0
returns the actual font
WPSListener::appendUnicode
static void appendUnicode(uint32_t val, librevenge::RVNGString &buffer)
adds an unicode character to a string ( with correct encoding ).
Definition: WPSListener.h:55
WPSListener::setParagraph
virtual void setParagraph(const WPSParagraph &para)=0
sets the actual paragraph
WPSListener::None
Definition: WPSListener.h:126
WPSListener::setDocumentLanguage
virtual void setDocumentLanguage(int lcid)=0
WPSTabStop
Definition: WPSParagraph.h:38
WPSListener::insertUnicodeString
virtual void insertUnicodeString(librevenge::RVNGString const &str)=0
adds a unicode string
WPSListener::Link
Definition: WPSListener.h:126
WPSListener::insertEOL
virtual void insertEOL(bool softBreak=false)=0