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 #ifndef MW_PRO_STRUCTURES 00035 # define MW_PRO_STRUCTURES 00036 00037 #include <list> 00038 #include <string> 00039 #include <vector> 00040 00041 #include "MWAWPosition.hxx" 00042 00043 #include "MWAWEntry.hxx" 00044 00045 #include "MWAWDebug.hxx" 00046 #include "MWAWInputStream.hxx" 00047 00048 class WPXBinaryData; 00049 00050 class MWProParser; 00051 00052 namespace MWProParserInternal 00053 { 00054 class SubDocument; 00055 } 00056 00057 namespace MWProStructuresInternal 00058 { 00059 struct Block; 00060 struct Cell; 00061 struct Font; 00062 struct Paragraph; 00063 struct Section; 00064 struct State; 00065 class SubDocument; 00066 } 00067 00068 class MWProStructures; 00069 00072 class MWProStructuresListenerState 00073 { 00074 public: 00076 MWProStructuresListenerState(shared_ptr<MWProStructures> structures, bool mainZone); 00078 ~MWProStructuresListenerState(); 00079 00081 bool isSent(int blockId); 00083 bool send(int blockId); 00084 00086 void sendSection(int numSection); 00088 bool sendFont(int id); 00090 bool sendParagraph(int id); 00092 void sendChar(char c); 00093 00095 bool resendAll(); 00096 00098 int numSection() const { 00099 if (!m_isMainZone) { 00100 MWAW_DEBUG_MSG(("MWProStructuresListenerState::numSection: not called in main zone\n")); 00101 return 0; 00102 } 00103 return m_section; 00104 } 00105 00107 std::vector<int> getPageBreaksPos() const; 00109 void insertSoftPageBreak(); 00110 00112 std::string getFontDebugString(int fontId); 00113 00115 std::string getParagraphDebugString(int paraId); 00116 00117 protected: 00119 bool newPage(bool softBreak=false); 00120 00122 void sendFont(MWProStructuresInternal::Font const &font); 00124 void sendParagraph(MWProStructuresInternal::Paragraph const ¶); 00125 00126 // true if this is the mainZone 00127 bool m_isMainZone; 00128 // the actual page 00129 int m_actPage; 00130 // the actual tab 00131 int m_actTab; 00132 // the number of tab 00133 int m_numTab; 00134 // the actual section ( if mainZone ) 00135 int m_section; 00136 // the actual number of columns 00137 int m_numCols; 00138 // a flag to know if a new page has just been open 00139 bool m_newPageDone; 00140 // the main structure parser 00141 shared_ptr<MWProStructures> m_structures; 00142 // the current font 00143 shared_ptr<MWProStructuresInternal::Font> m_font; 00144 // the current paragraph 00145 shared_ptr<MWProStructuresInternal::Paragraph> m_paragraph; 00146 }; 00147 00153 class MWProStructures 00154 { 00155 friend class MWProParser; 00156 friend class MWProParserInternal::SubDocument; 00157 friend struct MWProStructuresInternal::Cell; 00158 friend class MWProStructuresListenerState; 00159 public: 00161 MWProStructures(MWProParser &mainParser); 00163 virtual ~MWProStructures(); 00164 00168 int version() const; 00169 00171 void setAsciiName(char const *name) { 00172 m_asciiName = name; 00173 } 00174 00175 protected: 00177 void init(); 00178 00180 bool createZones(); 00181 00186 bool createZonesV2(); 00187 00189 int numPages() const; 00190 00192 bool sendMainZone(); 00193 00195 int getHeaderId(int page, int &numSimillar) const; 00197 int getFooterId(int page, int &numSimillar) const; 00198 00200 void flushExtra(); 00201 00203 void buildPageStructures(); 00204 00206 void buildTableStructures(); 00207 00208 // 00209 // low level 00210 // 00211 00213 bool readStyles(); 00214 00216 bool readStyle(int styleId); 00217 00219 bool readCharStyles(); 00220 00222 bool readParagraphs(); 00223 00225 bool readParagraph(MWProStructuresInternal::Paragraph ¶); 00226 00228 int getEndBlockSize(); 00229 00231 shared_ptr<MWProStructuresInternal::Block> readBlock(); 00232 00234 shared_ptr<MWProStructuresInternal::Block> readBlockV2(int id); 00235 00237 bool readBlocksList(); 00238 00240 bool readFontsName(); 00241 00243 bool readFontsDef(); 00244 00246 bool readFont(MWProStructuresInternal::Font &font); 00247 00249 bool readSections(std::vector<MWProStructuresInternal::Section> §ions); 00250 00252 bool readSelection(); 00253 00255 bool readStructB(); 00256 00258 static bool readString(MWAWInputStreamPtr input, std::string &res); 00259 00261 bool getColor(int colId, MWAWColor &color) const; 00262 00264 bool getPattern(int patId, float &patternPercent) const; 00265 00267 bool getColor(int colId, int patId, MWAWColor &color) const; 00268 00270 bool isSent(int blockId); 00271 00276 bool send(int blockId, bool mainZone=false); 00277 00279 MWAWContentListenerPtr &getListener(); 00280 00282 libmwaw::DebugFile &ascii() { 00283 return m_asciiFile; 00284 } 00285 00287 std::string const &asciiName() const { 00288 return m_asciiName; 00289 } 00290 00291 protected: 00292 // 00293 // data 00294 // 00295 00297 MWAWParserStatePtr m_parserState; 00298 00300 MWAWInputStreamPtr m_input; 00301 00303 MWProParser &m_mainParser; 00304 00306 shared_ptr<MWProStructuresInternal::State> m_state; 00307 00309 libmwaw::DebugFile m_asciiFile; 00310 00312 std::string m_asciiName; 00313 }; 00314 #endif 00315 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: