filters

libmswrite.h

00001 /* This file is part of the LibMSWrite Library
00002    Copyright (C) 2001-2003 Clarence Dang <clarencedang@users.sourceforge.net>
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 Version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License Version 2 for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    Version 2 along with this library; see the file COPYING.LIB.  If not,
00015    write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016  * Boston, MA 02110-1301, USA.
00017 
00018    LibMSWrite Project Website:
00019    http://sourceforge.net/projects/libmswrite/
00020 */
00021 
00022 #ifndef __LIBMSWRITE_H__
00023 #define __LIBMSWRITE_H__
00024 
00025 #include "structures.h"
00026 #include "structures_private.h"
00027 
00028 namespace MSWrite
00029 {
00030 #if 0
00031     class DocumentInfo
00032     {
00033     private:
00034         Word m_numObjects;
00035         bool m_hasHeader;
00036         bool m_hasFooter;
00037         bool m_hasHeaderOnFirstPage;
00038         bool m_hasFooterOnFirstPage;
00039 
00040     public:
00041         DocumentInfo ()
00042         {
00043             m_numObjects = 0;
00044             m_hasHeader = m_hasFooter = false;
00045             m_hasHeaderOnFirstPage = m_hasFooterOnFirstPage = false;
00046         }
00047 
00048         Word getNumObjects (void) const {   return m_numObjects;    }
00049         void setNumObjects (const Word numObjects)  {   m_numObjects = numObjects;  }
00050 
00051         bool getHasHeader (void) const  {   return m_hasHeader; }
00052         void setHasHeader (const bool hasHeader)    {   m_hasHeader = hasHeader;    }
00053 
00054         bool getHasFooter (void) const  {   return m_hasFooter; }
00055         void setHasFooter (const bool hasFooter)    {   m_hasFooter = hasFooter;    }
00056 
00057         bool getHasHeaderOnFirstPage (void) const   {   return m_hasHeaderOnFirstPage;  }
00058         void setHasHeaderOnFirstPage (const bool hasHeaderOnFirstPage)  {   m_hasHeader = hasHeaderOnFirstPage; }
00059 
00060         bool getHasFooterOnFirstPage (void) const   {   return m_hasFooterOnFirstPage;  }
00061         void setHasFooterOnFirstPage (const bool hasFooterOnFirstPage)  {   m_hasFooterOnFirstPage = hasFooterOnFirstPage;  }
00062     };
00063 #endif
00064 
00065 
00066     // [PRIVATE] don't use
00067     class FormatInfo : public NeedsDevice, public NeedsHeader
00068     {
00069     private:
00070         List <FormatInfoPage> m_formatInfoPageList;
00071         List <FormatInfoPage>::Iterator m_formatInfoPageIterator;
00072         DWord m_nextChar;
00073 
00074         enum FormatInfoPageTypes m_type;
00075 
00076         friend class InternalParser;
00077         friend class InternalGenerator;
00078             Word m_leftMargin, m_rightMargin;   // for ParaType only
00079             FontTable *m_fontTable; // for CharType only
00080             void setMargins (const Word leftMargin, const Word rightMargin)
00081             {
00082                 m_leftMargin = leftMargin, m_rightMargin = rightMargin;
00083             }
00084             void setFontTable (FontTable *fontTable)    {   m_fontTable = fontTable;    }
00085 
00086         FormatInfo &operator= (const FormatInfo &rhs);  // TODO
00087     public:
00088         FormatInfo ();
00089         virtual ~FormatInfo ();
00090 
00091         void setType (const enum FormatInfoPageTypes t) {   m_type = t; }
00092 
00093         bool readFromDevice (void);
00094         bool writeToDevice (const void *defaultProperty);
00095 
00096         void *begin (void);
00097         void *next (void);
00098         bool end (void) /*const*/;
00099 
00100         bool add (const void *property, const bool force = false);
00101     };
00102 
00103 
00104     class Generator;
00105     class Parser
00106     {
00107     protected:
00108         Generator *m_generator;
00109 
00110     public:
00111         Parser (Generator *generator = NULL)
00112         {
00113             setGenerator (generator);
00114         }
00115         
00116         virtual ~Parser ()
00117         {
00118         }
00119 
00120         void setGenerator (Generator *generator)
00121         {
00122             m_generator = generator;
00123         }
00124 
00125         virtual bool parse (void) = 0;
00126     };
00127 
00128 
00129     class Generator
00130     {
00131     public:
00132         Generator ();
00133         virtual ~Generator ();
00134 
00140         virtual bool writeDocumentBegin (const Word format, const PageLayout *pageLayout) = 0;
00141         virtual bool writeDocumentEnd (const Word format, const PageLayout *pageLayout) = 0;
00142 
00148         virtual bool writeFooterBegin (void)    {   return true;    }
00149         virtual bool writeFooterEnd(void)   {   return true;    }
00150 
00151         virtual bool writeHeaderBegin (void)    {   return true;    }
00152         virtual bool writeHeaderEnd (void)  {   return true;    }
00153 
00154         virtual bool writeBodyBegin (void) = 0;
00155         virtual bool writeBodyEnd (void)    = 0;
00156 
00162         virtual bool writeParaInfoBegin (const FormatParaProperty * /*paraProperty*/,
00163                                                     const OLE * /*ole*/ = NULL,
00164                                                     const Image * /*image*/ = NULL) {   return true;    }
00165         virtual bool writeParaInfoEnd (const FormatParaProperty * /*paraProperty*/,
00166                                                     const OLE * /*ole*/ = NULL,
00167                                                     const Image * /*image*/ = NULL) {   return true;    }
00168 
00174         virtual bool writeCharInfoBegin (const FormatCharProperty * /*charProperty*/)   {   return true;    }
00175         virtual bool writeCharInfoEnd (const FormatCharProperty * /*charProperty*/,
00176                                                     const bool /*endOfParagraph*/ = false)  {   return true;    }
00177 
00178 
00184         virtual bool writeBinary (const Byte * /*buffer*/, const DWord /*length*/)  {   return true;    }
00185 
00186 
00187         /*
00188          *
00189          * Text output
00190          *
00191          */
00192 
00198         bool processText (const Byte *string, bool willReachEndOfParagraph);
00199         virtual bool writeText (const Byte *string) = 0;
00200 
00201 
00207         virtual bool writePageNew (const int /*pageNumberClaimed*/ = 0)
00208         {
00209             return true;
00210         };
00211         virtual bool writePageBreak (void)
00212         {
00213             return writeText ((const Byte *) "\xc");    // i.e. (char)12
00214         }
00215         virtual bool writePageNumber (void)
00216         {
00217             return writeText ((const Byte *) "\x1");    // i.e. (char)1
00218         }
00219         virtual bool writeCarriageReturn (void)
00220         {
00221             return writeText ((const Byte *) "\xd");    // i.e. (char)13
00222         }
00223         virtual bool writeNewLine (const bool /*endOfParagraph*/ = true)
00224         {
00225             return writeText ((const Byte *) "\n"); // i.e. (char)10
00226         }
00227         virtual bool writeOptionalHyphen (void)
00228         {
00229             return writeText ((const Byte *) "-");
00230         }
00231 
00238         virtual void sigProgress (const int /*value*/)  {}
00239     };
00240 
00241 
00242     class InternalParser : public Parser, public NeedsDevice
00243     {
00244     private:
00245         Header *m_header;
00246         SectionTable *m_sectionTable;
00247         PageLayout *m_pageLayout;
00248         PageTable *m_pageTable;
00249         FontTable *m_fontTable;
00250         FormatInfo *m_paragraphInfo, *m_characterInfo;
00251 
00252         Image *m_image;
00253         OLE *m_ole;
00254 
00255     public:
00256         InternalParser ();
00257         virtual ~InternalParser ();
00258 
00259         bool parse (void);
00260     };
00261 
00262 
00263     class InternalGenerator : public Generator, public NeedsDevice
00264     {
00265     private:
00266         Header *m_header;
00267         SectionTable *m_sectionTable;
00268         PageLayout *m_pageLayout;
00269         PageTable *m_pageTable;
00270         FontTable *m_fontTable;
00271         FormatInfo *m_paragraphInfo, *m_characterInfo;
00272 
00273         Image *m_image;
00274         OLE *m_ole;
00275         
00276         bool seekNextPage (void);
00277         
00278     public:
00279         InternalGenerator ();
00280         virtual ~InternalGenerator ();
00281 
00282         bool writeDocumentBegin (const Word format, const PageLayout *pageLayout);
00283         bool writeDocumentEnd (const Word format, const PageLayout *pageLayout);
00284 
00285         bool writeFooterBegin (void)
00286         {
00287             // don't care
00288             return true;
00289         }
00290         bool writeFooterEnd(void)
00291         {
00292             // don't care
00293             return true;
00294         }
00295 
00296         bool writeHeaderBegin (void)
00297         {
00298             // don't care
00299             return true;
00300         }
00301         bool writeHeaderEnd (void)
00302         {
00303             // don't care
00304             return true;
00305         }
00306 
00307         bool writeBodyBegin (void)
00308         {
00309             // don't care
00310             return true;
00311         }
00312 
00313         bool writeBodyEnd (void)
00314         {
00315             // don't care
00316             return true;
00317         }
00318 
00319 
00325         bool writeParaInfoBegin (const FormatParaProperty *paraProperty,
00326                                             const OLE *oleHeader = NULL,
00327                                             const Image *imageHeader = NULL);
00328         bool writeParaInfoEnd (const FormatParaProperty *paraProperty,
00329                                         const OLE *oleHeader = NULL,
00330                                         const Image *imageHeader = NULL);
00331 
00332         bool writeCharInfoBegin (const FormatCharProperty *charProperty);
00333         bool writeCharInfoEnd (const FormatCharProperty *charProperty,
00334                                         const bool endOfParagraph = false);
00335 
00336 
00337         bool writeBinary (const Byte *buffer, const DWord length);
00338 
00339 
00340         bool writeText (const Byte *string);
00341 
00342 
00343         bool writePageNew (const int pageNumberClaimed = 0);
00344 
00345         bool writePageBreak (void)
00346         {
00347             return writeText ((const Byte *) "\xC");    // i.e. (char)12
00348         }
00349         bool writePageNumber (void)
00350         {
00351             return writeText ((const Byte *) "\x1");    // i.e. (char)1
00352         }
00353         bool writeCarriageReturn (void)
00354         {
00355             // it's DOS/Windows(r) which has \r\n newlines
00356             return writeText ((const Byte *) "\xD");    // i.e. (char)13
00357         }
00358         bool writeNewLine (const bool)
00359         {
00360             return writeText ((const Byte *) "\n"); // i.e. (char)10
00361         }
00362         bool writeOptionalHyphen (void)
00363         {
00364             return writeText ((const Byte *) "\x1F");   // i.e. (char)31
00365         }
00366 
00367         void sigProgress (const int)
00368         {
00369             // don't care
00370             return;
00371         }
00372 
00373     };
00374 }   // namespace MSWrite    {
00375 
00376 #endif  // __LIBMSWRITE_H__
00377 
00378 // end of libmswrite.h
KDE Home | KDE Accessibility Home | Description of Access Keys