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 MAC_WRT_PRO_STRUCTURES 00035 # define MAC_WRT_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 MacWrtProParser; 00049 00050 namespace MacWrtProParserInternal 00051 { 00052 class SubDocument; 00053 } 00054 00055 namespace MacWrtProStructuresInternal 00056 { 00057 struct Block; 00058 struct Cell; 00059 struct Font; 00060 struct Paragraph; 00061 struct Section; 00062 struct State; 00063 class SubDocument; 00064 } 00065 00066 class MacWrtProStructures; 00067 00070 class MacWrtProStructuresListenerState 00071 { 00072 public: 00074 MacWrtProStructuresListenerState(shared_ptr<MacWrtProStructures> structures, bool mainZone); 00076 ~MacWrtProStructuresListenerState(); 00077 00079 bool isSent(int blockId); 00081 bool send(int blockId); 00082 00084 void sendSection(int numSection); 00086 bool sendFont(int id); 00088 bool sendParagraph(int id); 00090 void sendChar(char c); 00091 00093 bool resendAll(); 00094 00096 int numSection() const 00097 { 00098 if (!m_isMainZone) { 00099 MWAW_DEBUG_MSG(("MacWrtProStructuresListenerState::numSection: not called in main zone\n")); 00100 return 0; 00101 } 00102 return m_section; 00103 } 00104 00106 std::vector<int> getPageBreaksPos() const; 00108 void insertSoftPageBreak(); 00109 00111 std::string getFontDebugString(int fontId); 00112 00114 std::string getParagraphDebugString(int paraId); 00115 00116 protected: 00118 bool newPage(bool softBreak=false); 00119 00121 void sendFont(MacWrtProStructuresInternal::Font const &font); 00123 void sendParagraph(MacWrtProStructuresInternal::Paragraph const ¶); 00124 00125 // true if this is the mainZone 00126 bool m_isMainZone; 00127 // the actual page 00128 int m_actPage; 00129 // the actual tab 00130 int m_actTab; 00131 // the number of tab 00132 int m_numTab; 00133 // the actual section ( if mainZone ) 00134 int m_section; 00135 // the actual number of columns 00136 int m_numCols; 00137 // a flag to know if a new page has just been open 00138 bool m_newPageDone; 00139 // the main structure parser 00140 shared_ptr<MacWrtProStructures> m_structures; 00141 // the current font 00142 shared_ptr<MacWrtProStructuresInternal::Font> m_font; 00143 // the current paragraph 00144 shared_ptr<MacWrtProStructuresInternal::Paragraph> m_paragraph; 00145 }; 00146 00152 class MacWrtProStructures 00153 { 00154 friend class MacWrtProParser; 00155 friend class MacWrtProParserInternal::SubDocument; 00156 friend struct MacWrtProStructuresInternal::Cell; 00157 friend class MacWrtProStructuresListenerState; 00158 public: 00160 MacWrtProStructures(MacWrtProParser &mainParser); 00162 virtual ~MacWrtProStructures(); 00163 00167 int version() const; 00168 00170 void setAsciiName(char const *name) 00171 { 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(MacWrtProStructuresInternal::Paragraph ¶); 00226 00228 int getEndBlockSize(); 00229 00231 shared_ptr<MacWrtProStructuresInternal::Block> readBlock(); 00232 00234 shared_ptr<MacWrtProStructuresInternal::Block> readBlockV2(int id); 00235 00237 bool readBlocksList(); 00238 00240 bool readFontsName(); 00241 00243 bool readFontsDef(); 00244 00246 bool readFont(MacWrtProStructuresInternal::Font &font); 00247 00249 bool readSections(std::vector<MacWrtProStructuresInternal::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 MWAWTextListenerPtr &getTextListener(); 00280 00282 libmwaw::DebugFile &ascii() 00283 { 00284 return m_asciiFile; 00285 } 00286 00288 std::string const &asciiName() const 00289 { 00290 return m_asciiName; 00291 } 00292 00293 protected: 00294 // 00295 // data 00296 // 00297 00299 MWAWParserStatePtr m_parserState; 00300 00302 MWAWInputStreamPtr m_input; 00303 00305 MacWrtProParser &m_mainParser; 00306 00308 shared_ptr<MacWrtProStructuresInternal::State> m_state; 00309 00311 libmwaw::DebugFile m_asciiFile; 00312 00314 std::string m_asciiName; 00315 }; 00316 #endif 00317 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: