WPSListener.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* libwps
00003  * Version: MPL 2.0 / LGPLv2.1+
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * Major Contributor(s):
00010  * Copyright (C) 2006, 2007 Andrew Ziem
00011  * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00012  * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
00013  * Copyright (C) 2003 Marc Maurer (uwog@uwog.net)
00014  *
00015  * For minor contributions see the git repository.
00016  *
00017  * Alternatively, the contents of this file may be used under the terms
00018  * of the GNU Lesser General Public License Version 2.1 or later
00019  * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
00020  * applicable instead of those above.
00021  *
00022  * For further information visit http://libwps.sourceforge.net
00023  */
00024 
00025 #ifndef WPSLISTENER_H
00026 #define WPSLISTENER_H
00027 
00028 #include <librevenge/librevenge.h>
00029 
00030 #include "libwps_internal.h"
00031 
00032 struct WPSParagraph;
00033 struct WPSTabStop;
00034 
00036 class WPSListener
00037 {
00038 public:
00039         WPSListener() {}
00040         virtual ~WPSListener() {}
00041 
00042         virtual void setDocumentLanguage(int lcid)=0;
00043 
00044         // ------ text data -----------
00045 
00047         virtual void insertCharacter(uint8_t character)=0;
00051         virtual void insertUnicode(uint32_t character)=0;
00053         virtual void insertUnicodeString(librevenge::RVNGString const &str)=0;
00055         static void appendUnicode(uint32_t val, librevenge::RVNGString &buffer)
00056         {
00057                 if (val < 0x20)
00058                 {
00059                         WPS_DEBUG_MSG(("WPSListener::appendUnicode: find an old char %x, skip it\n", val));
00060                         return;
00061                 }
00062                 uint8_t first;
00063                 int len;
00064                 if (val < 0x80)
00065                 {
00066                         first = 0;
00067                         len = 1;
00068                 }
00069                 else if (val < 0x800)
00070                 {
00071                         first = 0xc0;
00072                         len = 2;
00073                 }
00074                 else if (val < 0x10000)
00075                 {
00076                         first = 0xe0;
00077                         len = 3;
00078                 }
00079                 else if (val < 0x200000)
00080                 {
00081                         first = 0xf0;
00082                         len = 4;
00083                 }
00084                 else if (val < 0x4000000)
00085                 {
00086                         first = 0xf8;
00087                         len = 5;
00088                 }
00089                 else
00090                 {
00091                         first = 0xfc;
00092                         len = 6;
00093                 }
00094 
00095                 uint8_t outbuf[6] = { 0, 0, 0, 0, 0, 0 };
00096                 int i;
00097                 for (i = len - 1; i > 0; --i)
00098                 {
00099                         outbuf[i] = uint8_t((val & 0x3f) | 0x80);
00100                         val >>= 6;
00101                 }
00102                 outbuf[0] = uint8_t(val | first);
00103                 for (i = 0; i < len; i++) buffer.append(char(outbuf[i]));
00104         }
00105 
00106         virtual void insertTab()=0;
00107         virtual void insertEOL(bool softBreak=false)=0;
00108         virtual void insertBreak(const uint8_t breakType)=0;
00109 
00110         // ------ text format -----------
00112         virtual void setFont(const WPSFont &font)=0;
00114         virtual WPSFont const &getFont() const=0;
00115 
00116         // ------ paragraph format -----------
00118         virtual bool isParagraphOpened() const=0;
00120         virtual void setParagraph(const WPSParagraph &para)=0;
00122         virtual WPSParagraph const &getParagraph() const=0;
00123 
00124         // ------- fields ----------------
00126         enum FieldType { None, PageNumber, Date, Time, Title, Link, Database };
00128         virtual void insertField(FieldType type) = 0;
00130         virtual void insertDateTimeField(char const *format)=0;
00131 };
00132 
00133 #endif
00134 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */