MSWText.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
00002 
00003 /* libmwaw
00004 * Version: MPL 2.0 / LGPLv2+
00005 *
00006 * The contents of this file are subject to the Mozilla Public License Version
00007 * 2.0 (the "License"); you may not use this file except in compliance with
00008 * the License or as specified alternatively below. You may obtain a copy of
00009 * the License at http://www.mozilla.org/MPL/
00010 *
00011 * Software distributed under the License is distributed on an "AS IS" basis,
00012 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 * for the specific language governing rights and limitations under the
00014 * License.
00015 *
00016 * Major Contributor(s):
00017 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00018 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00019 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00020 * Copyright (C) 2006, 2007 Andrew Ziem
00021 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
00022 *
00023 *
00024 * All Rights Reserved.
00025 *
00026 * For minor contributions see the git repository.
00027 *
00028 * Alternatively, the contents of this file may be used under the terms of
00029 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00030 * in which case the provisions of the LGPLv2+ are applicable
00031 * instead of those above.
00032 */
00033 
00034 /*
00035  * Parser to Microsoft Word text document
00036  *
00037  */
00038 #ifndef MSW_MWAW_TEXT
00039 #  define MSW_MWAW_TEXT
00040 
00041 #include <map>
00042 #include <string>
00043 #include <vector>
00044 
00045 #include "libmwaw_internal.hxx"
00046 
00047 #include "MWAWEntry.hxx"
00048 
00049 #include "MWAWDebug.hxx"
00050 
00051 #include "MSWTextStyles.hxx"
00052 
00053 namespace MSWTextInternal
00054 {
00055 struct State;
00056 struct Table;
00057 }
00058 
00059 struct MSWEntry;
00060 class MSWParser;
00061 class MSWTextStyles;
00062 
00064 class MSWText
00065 {
00066   friend class MSWParser;
00067   friend class MSWTextStyles;
00068 public:
00070   struct PLC {
00071     enum Type { TextPosition, HeaderFooter, Page, Section, ParagraphInfo, Paragraph, Font, Footnote, FootnoteDef, Field, Object };
00072     PLC(Type type, int id=0) : m_type(type), m_id(id), m_extra("") {
00073     }
00075     friend std::ostream &operator<<(std::ostream &o, PLC const &plc);
00077     struct ltstr {
00078       bool operator()(PLC const &s1, PLC const &s2) const {
00079         if (s1.m_type != s2.m_type)
00080           return int(s1.m_type) < int(s2.m_type);
00081         if (s1.m_id != s2.m_id)
00082           return s1.m_id < s2.m_id;
00083         return false;
00084       }
00085     };
00087     Type m_type;
00089     int m_id;
00091     std::string m_extra;
00092   };
00093 public:
00095   MSWText(MSWParser &parser);
00097   virtual ~MSWText();
00098 
00100   int version() const;
00101 
00103   int numPages() const;
00104 
00106   MWAWEntry getHeader() const;
00107 
00109   MWAWEntry getFooter() const;
00110 protected:
00112   shared_ptr<MWAWParserState> &getParserState() {
00113     return m_parserState;
00114   }
00115 
00117   bool sendMainText();
00118 
00120   bool sendText(MWAWEntry const &textEntry, bool mainZone, bool tableCell=false);
00122   bool sendSection(int sectionId);
00124   bool readHeaderTextLength();
00125 
00127   bool createZones(long bot);
00128 
00130   bool readTextStruct(MSWEntry &entry);
00131 
00133   bool readPageBreak(MSWEntry &entry);
00134 
00136   bool readParagraphInfo(MSWEntry entry);
00137 
00139   bool readFields(MSWEntry &entry, std::vector<long> const &fieldPos);
00140 
00142   bool sendFieldComment(int id);
00143 
00145   bool readFootnotesPos(MSWEntry &entry, std::vector<long> const &noteDef);
00146 
00148   bool readFootnotesData(MSWEntry &entry);
00149 
00151   bool sendFootnote(int id);
00152 
00154   bool readFontNames(MSWEntry &entry);
00155 
00157   void flushExtra();
00158 
00160   bool sendTable(MSWTextInternal::Table const &table);
00161 
00162   // interface with MSWTextStyles
00163 
00165   long getMainTextLength() const;
00167   std::multimap<long, MSWText::PLC> &getTextPLCMap();
00169   std::multimap<long, MSWText::PLC> &getFilePLCMap();
00170 
00171   //
00172   // low level
00173   //
00174 
00176   void prepareData();
00177 
00179   void prepareLines();
00181   void convertFilePLCPos();
00183   void prepareParagraphProperties();
00185   void prepareFontProperties();
00186 
00188   void prepareTableLimits();
00190   bool updateTableBeginnningAt(long cPos, long &nextCPos);
00191 
00193   bool readLongZone(MSWEntry &entry, int sz, std::vector<long> &list);
00194 
00195 private:
00196   MSWText(MSWText const &orig);
00197   MSWText &operator=(MSWText const &orig);
00198 
00199 protected:
00200   //
00201   // data
00202   //
00204   MWAWParserStatePtr m_parserState;
00205 
00207   shared_ptr<MSWTextInternal::State> m_state;
00208 
00210   shared_ptr<MSWTextStyles> m_stylesManager;
00211 
00213   MSWParser *m_mainParser;
00214 };
00215 #endif
00216 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: