filters

parser.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Ariya Hidayat <ariyahidayat@yahoo.de>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 
00021 #ifndef __WP_PARSER_H
00022 #define __WP_PARSER_H
00023 
00024 #include <qptrlist.h>
00025 #include <qmemarray.h>
00026 #include <qstring.h>
00027 
00028 namespace WP
00029 {
00030 
00036   class Token
00037   {
00038 
00039   public:
00040 
00041     enum Type
00042     {
00043       Unknown, Function, Text, Lang,
00044       SoftSpace, HardSpace, HardHyphen, ExtChar,
00045       SoftReturn, HardReturn, DormantHardReturn,
00046       AttrOn, AttrOff, UnderlineMode,
00047       MarkTocStart, MarkTocEnd,
00048       LeftMargin, RightMargin, TopMargin, BottomMargin,
00049       Linespace, Justification, ParagraphIndent, LeftMarginAdjust,
00050         RightMarginAdjust,
00051       TabSet, TabLeft, TabHardFlushRight,
00052       FontColor, FontSize, FontFace, HighlightOn, HighlightOff,
00053       TableOn, TableColumn, TableEnd, TableCell, TableRow, TableOff
00054     };
00055 
00056     enum Attr
00057     {
00058       None, ExtraLarge, VeryLarge, Large, Small, Fine,
00059       Bold, Italic, Underline, DoubleUnderline, Subscript, Superscript,
00060       StrikedOut, Redline, Shadow, Outline, SmallCaps, Blink
00061     };
00062 
00063     enum Align
00064     { Left, Right, Center, Full, All };
00065 
00066     enum TabType
00067     { LeftTab, CenterTab, RightTab, DecimalTab, VerticalTab };
00068 
00069     class Tab
00070     {
00071     public:
00072       TabType type;
00073       int pos;
00074         Tab (TabType t, int p)
00075       {
00076         type = t;
00077         pos = p;
00078       }
00079     };
00080 
00081     Token () { m_type = Unknown; }
00082 
00083     Token (Type type) { m_type = type; }
00084 
00085     Token (const QString & text) { m_type = Text; m_text = text;  }
00086 
00087     Token (Type type, Attr attr) { m_type = type;  m_attr = attr; }
00088 
00089     Token (Type type, int value) { m_type = type;  m_value = value; }
00090 
00091     Token (Type type, Align align){ m_type = type;  m_align = align;  }
00092 
00093     Token (Type type, int charset, int charcode)
00094     {
00095       m_type = type;
00096       m_charset = charset;
00097       m_charcode = charcode;
00098     }
00099 
00100     Token (Type type, int red, int green, int blue)
00101     {
00102       m_type = type;
00103       m_red = red;
00104       m_green = green;
00105       m_blue = blue;
00106     }
00107 
00108     Token (Type type, QString fontface){ m_type = FontFace; m_fontface = fontface;  }
00109 
00110     Token (const QPtrList < Tab > &tabs)
00111     {
00112       m_type = TabSet;
00113       m_tabs = tabs;
00114     }
00115 
00116     Type type (){ return m_type; }
00117 
00118     int value (){ return m_value; }
00119 
00120     QString text (){ return m_text; }
00121 
00122     Attr attr (){ return m_attr; }
00123 
00124     Align align (){ return m_align; }
00125 
00126     int red (){ return m_red; }
00127     int green (){ return m_green; }
00128     int blue (){ return m_blue; }
00129 
00130     QString fontface (){ return m_fontface; }
00131     int charset (){ return m_charset; }
00132     int charcode (){ return m_charcode; }
00133     QPtrList < Tab > tabs (){  return m_tabs; }
00134 
00135 
00136   private:
00137 
00138     Type m_type;
00139     int m_value;
00140     QString m_text;
00141     Attr m_attr;
00142     Align m_align;
00143     int m_red, m_green, m_blue;
00144     QString m_fontface;
00145     int m_charset, m_charcode;
00146     QPtrList < Tab > m_tabs;
00147 
00148 
00149 
00150   };
00151 
00152   class Packet
00153   {
00154     public:
00155       unsigned type, size, pos;
00156       QMemArray<Q_UINT8> data;
00157   };
00158 
00165   class Parser
00166   {
00167 
00168   public:
00169     Parser ();
00170 
00176     bool parse (const QString & filename);
00177 
00178     // high byte is major version, 0=WP 5.x, 2=WP 6/7/8
00179     int version;
00180 
00181     QString docTitle, docAuthor, docAbstract;
00182 
00183     QPtrList<Token> tokens;
00184     QPtrList<Packet> packets;
00185 
00193     static unsigned int ExtCharToUnicode (int charset, int charcode);
00194 
00195   protected:
00196 
00197   private:
00198 
00199     void handleTab ( QMemArray <Q_UINT8> data );
00200 
00201     void parsePacketWP5( const QString & filename );
00202     void parseDocWP5( const QString & filename, int start );
00203 
00204     void parsePacketWP6( const QString & filename );
00205     void parseDocWP6( const QString & filename, int start );
00206 
00207   };
00208 
00209 }
00210 
00211 
00212 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys