MWProStructures.hxx
Go to the documentation of this file.
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
/* libmwaw
* Version: MPL 2.0 / LGPLv2+
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
*
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
* in which case the provisions of the LGPLv2+ are applicable
* instead of those above.
*/
#ifndef MW_PRO_STRUCTURES
# define MW_PRO_STRUCTURES
#include <list>
#include <string>
#include <vector>
#include "MWAWPosition.hxx"
#include "MWAWEntry.hxx"
#include "MWAWDebug.hxx"
#include "MWAWInputStream.hxx"
class WPXBinaryData;
class MWProParser;
namespace MWProParserInternal
{
class SubDocument;
}
namespace MWProStructuresInternal
{
struct Block;
struct Cell;
struct Font;
struct Paragraph;
struct Section;
struct State;
class SubDocument;
}
class MWProStructures;
class MWProStructuresListenerState
{
public:
MWProStructuresListenerState(shared_ptr<MWProStructures> structures, bool mainZone);
~MWProStructuresListenerState();
bool isSent(int blockId);
bool send(int blockId);
void sendSection(int numSection);
bool sendFont(int id);
bool sendParagraph(int id);
void sendChar(char c);
bool resendAll();
int numSection() const {
if (!m_isMainZone) {
MWAW_DEBUG_MSG(("MWProStructuresListenerState::numSection: not called in main zone\n"));
return 0;
}
return m_section;
}
std::vector<int> getPageBreaksPos() const;
void insertSoftPageBreak();
std::string getFontDebugString(int fontId);
std::string getParagraphDebugString(int paraId);
protected:
bool newPage(bool softBreak=false);
void sendFont(MWProStructuresInternal::Font const &font);
void sendParagraph(MWProStructuresInternal::Paragraph const &para);
// true if this is the mainZone
bool m_isMainZone;
// the actual page
int m_actPage;
// the actual tab
int m_actTab;
// the number of tab
int m_numTab;
// the actual section ( if mainZone )
int m_section;
// the actual number of columns
int m_numCols;
// a flag to know if a new page has just been open
bool m_newPageDone;
// the main structure parser
shared_ptr<MWProStructures> m_structures;
// the current font
shared_ptr<MWProStructuresInternal::Font> m_font;
// the current paragraph
shared_ptr<MWProStructuresInternal::Paragraph> m_paragraph;
};
class MWProStructures
{
friend class MWProParser;
friend class MWProParserInternal::SubDocument;
friend struct MWProStructuresInternal::Cell;
friend class MWProStructuresListenerState;
public:
MWProStructures(MWProParser &mainParser);
virtual ~MWProStructures();
int version() const;
void setAsciiName(char const *name) {
m_asciiName = name;
}
protected:
void init();
bool createZones();
bool createZonesV2();
int numPages() const;
bool sendMainZone();
int getHeaderId(int page, int &numSimillar) const;
int getFooterId(int page, int &numSimillar) const;
void flushExtra();
void buildPageStructures();
void buildTableStructures();
//
// low level
//
bool readStyles();
bool readStyle(int styleId);
bool readCharStyles();
bool readParagraphs();
bool readParagraph(MWProStructuresInternal::Paragraph &para);
int getEndBlockSize();
shared_ptr<MWProStructuresInternal::Block> readBlock();
shared_ptr<MWProStructuresInternal::Block> readBlockV2(int id);
bool readBlocksList();
bool readFontsName();
bool readFontsDef();
bool readFont(MWProStructuresInternal::Font &font);
bool readSections(std::vector<MWProStructuresInternal::Section> &sections);
bool readSelection();
bool readStructB();
static bool readString(MWAWInputStreamPtr input, std::string &res);
bool getColor(int colId, MWAWColor &color) const;
bool getPattern(int patId, float &patternPercent) const;
bool getColor(int colId, int patId, MWAWColor &color) const;
bool isSent(int blockId);
bool send(int blockId, bool mainZone=false);
MWAWContentListenerPtr &getListener();
libmwaw::DebugFile &ascii() {
return m_asciiFile;
}
std::string const &asciiName() const {
return m_asciiName;
}
protected:
//
// data
//
MWAWParserStatePtr m_parserState;
MWAWInputStreamPtr m_input;
MWProParser &m_mainParser;
shared_ptr<MWProStructuresInternal::State> m_state;
libmwaw::DebugFile m_asciiFile;
std::string m_asciiName;
};
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWProStructuresInternal::Font
Internal: the fonts.
Definition: MWProStructures.cxx:288
MWProStructuresInternal::Paragraph
Internal: class to store the paragraph properties.
Definition: MWProStructures.cxx:322
MWProStructuresListenerState
an interface to transmit the info of MWProStructures to a listener
Definition: MWProStructures.hxx:72
MWProParserInternal::SubDocument
Internal: the subdocument of a MWProParser.
Definition: MWProParser.cxx:233
MWProStructures::init
void init()
inits all internal variables
Definition: MWProStructures.cxx:545
MWProStructures
the main class to read the structures part of MacWrite Pro file
Definition: MWProStructures.hxx:153
MWProStructures::m_mainParser
MWProParser & m_mainParser
the main parser
Definition: MWProStructures.hxx:303
MWProStructures::send
bool send(int blockId, bool mainZone=false)
try to send a block which corresponds to blockid
Definition: MWProStructures.cxx:2462
MWProStructuresListenerState::isSent
bool isSent(int blockId)
returns true if the block is already sent ( or does not exists)
Definition: MWProStructures.cxx:2595
MWAWEntry.hxx
MWProStructuresListenerState::send
bool send(int blockId)
try to send a block which corresponds to blockid
Definition: MWProStructures.cxx:2601
MWProStructures::getEndBlockSize
int getEndBlockSize()
returns the size of the block end data
Definition: MWProStructures.cxx:1797
MWProStructuresListenerState::m_numCols
int m_numCols
Definition: MWProStructures.hxx:137
MWProStructuresListenerState::numSection
int numSection() const
returns the actual section
Definition: MWProStructures.hxx:98
MWProStructures::m_state
shared_ptr< MWProStructuresInternal::State > m_state
the state
Definition: MWProStructures.hxx:306
libmwaw::DebugFile
an interface used to insert comment in a binary file, written in ascii form (if debug_with_files is n...
Definition: MWAWDebug.hxx:67
MWProStructures::readParagraph
bool readParagraph(MWProStructuresInternal::Paragraph &para)
try to read a paragraph
Definition: MWProStructures.cxx:1346
MWProStructuresListenerState::getPageBreaksPos
std::vector< int > getPageBreaksPos() const
return a list of page break position ( as some page break are soft )
Definition: MWProStructures.cxx:2638
MWProStructures::readBlocksList
bool readBlocksList()
try to read the list of block entries
Definition: MWProStructures.cxx:1729
MWProStructuresListenerState::insertSoftPageBreak
void insertSoftPageBreak()
insert a page break ( if we are not on a new page )
Definition: MWProStructures.cxx:2608
MWProStructures::ascii
libmwaw::DebugFile & ascii()
returns the debug file
Definition: MWProStructures.hxx:282
MWProStructures::numPages
int numPages() const
returns the number of pages
Definition: MWProStructures.cxx:563
MWProStructuresListenerState::sendFont
bool sendFont(int id)
try to send a character style
Definition: MWProStructures.cxx:2734
MWProStructuresListenerState::m_numTab
int m_numTab
Definition: MWProStructures.hxx:133
MWProStructures::m_asciiFile
libmwaw::DebugFile m_asciiFile
the debug file
Definition: MWProStructures.hxx:309
MWProStructures::readBlock
shared_ptr< MWProStructuresInternal::Block > readBlock()
try to read a block entry
Definition: MWProStructures.cxx:1936
MWProStructuresListenerState::m_section
int m_section
Definition: MWProStructures.hxx:135
MWProStructuresListenerState::~MWProStructuresListenerState
~MWProStructuresListenerState()
the destructor
Definition: MWProStructures.cxx:2591
MWProStructures::readStyle
bool readStyle(int styleId)
try to read a style
Definition: MWProStructures.cxx:1634
MWProStructures::createZones
bool createZones()
finds the different objects zones
Definition: MWProStructures.cxx:696
MWProStructures::getPattern
bool getPattern(int patId, float &patternPercent) const
try to return the pattern corresponding to patId
Definition: MWProStructures.cxx:655
MWProStructuresListenerState::sendParagraph
bool sendParagraph(int id)
try to send a paragraph
Definition: MWProStructures.cxx:2780
MWProStructuresListenerState::getParagraphDebugString
std::string getParagraphDebugString(int paraId)
debug function which returns a string corresponding to a paragrapId
Definition: MWProStructures.cxx:2803
MWAWColor
the class to store a color
Definition: libmwaw_internal.hxx:161
MWProStructures::readParagraphs
bool readParagraphs()
try to read a list of paragraph
Definition: MWProStructures.cxx:1292
MWProParser
the main class to read a MacWrite II and MacWrite Pro file
Definition: MWProParser.hxx:68
MWProStructures::readFontsName
bool readFontsName()
try to read the fonts zone
Definition: MWProStructures.cxx:1082
MWAW_DEBUG_MSG
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:111
MWProStructures::readFont
bool readFont(MWProStructuresInternal::Font &font)
try to read a font
Definition: MWProStructures.cxx:1205
MWProStructures::readSelection
bool readSelection()
try to read a 16 bytes the zone which follow the char styles zone ( the selection?)
Definition: MWProStructures.cxx:2324
MWProStructures::readBlockV2
shared_ptr< MWProStructuresInternal::Block > readBlockV2(int id)
try to read a block entry
Definition: MWProStructures.cxx:1809
MWProStructures::readSections
bool readSections(std::vector< MWProStructuresInternal::Section > &sections)
try to read the section info ?
Definition: MWProStructures.cxx:2206
MWProStructuresListenerState::m_structures
shared_ptr< MWProStructures > m_structures
Definition: MWProStructures.hxx:141
MWProStructures::isSent
bool isSent(int blockId)
returns true if the block is already sent ( or does not exists)
Definition: MWProStructures.cxx:2443
MWProStructures::getColor
bool getColor(int colId, MWAWColor &color) const
try to return the color corresponding to colId
Definition: MWProStructures.cxx:598
MWProStructures::m_asciiName
std::string m_asciiName
the debug file name
Definition: MWProStructures.hxx:312
MWProStructuresListenerState::newPage
bool newPage(bool softBreak=false)
create a new page
Definition: MWProStructures.cxx:2614
MWProStructuresListenerState::m_isMainZone
bool m_isMainZone
Definition: MWProStructures.hxx:127
MWProStructures::readStyles
bool readStyles()
try to read the paragraph styles zone which begins at address 0x200
Definition: MWProStructures.cxx:1593
MWProStructures::asciiName
std::string const & asciiName() const
return the ascii file name
Definition: MWProStructures.hxx:287
MWProStructures::~MWProStructures
virtual ~MWProStructures()
destructor
Definition: MWProStructures.cxx:540
MWProStructuresListenerState::resendAll
bool resendAll()
force resent data : font + paragraph
Definition: MWProStructures.cxx:2725
MWProStructures::m_input
MWAWInputStreamPtr m_input
the main input
Definition: MWProStructures.hxx:300
MWProStructures::setAsciiName
void setAsciiName(char const *name)
Debugging: change the default ascii file (by default struct )
Definition: MWProStructures.hxx:171
MWProStructures::createZonesV2
bool createZonesV2()
finds the different objects zones in a MacWriteII file
Definition: MWProStructures.cxx:814
MWProStructures::sendMainZone
bool sendMainZone()
send the main zone
Definition: MWProStructures.cxx:924
MWProStructures::flushExtra
void flushExtra()
flush not send zones
Definition: MWProStructures.cxx:2531
MWAWInputStreamPtr
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:336
MWProStructures::getHeaderId
int getHeaderId(int page, int &numSimillar) const
return the header blockid ( or 0)
Definition: MWProStructures.cxx:570
MWProStructures::version
int version() const
returns the file version.
Definition: MWProStructures.cxx:551
MWProStructuresListenerState::m_newPageDone
bool m_newPageDone
Definition: MWProStructures.hxx:139
MWProStructures::m_parserState
MWAWParserStatePtr m_parserState
the parser state
Definition: MWProStructures.hxx:297
MWProStructures::readFontsDef
bool readFontsDef()
try to read the list of fonts
Definition: MWProStructures.cxx:1153
MWProStructures::buildPageStructures
void buildPageStructures()
look for pages structures
Definition: MWProStructures.cxx:955
MWAWInputStream.hxx
MWAWDebug.hxx
MWProStructuresListenerState::m_font
shared_ptr< MWProStructuresInternal::Font > m_font
Definition: MWProStructures.hxx:143
MWProStructuresListenerState::m_actTab
int m_actTab
Definition: MWProStructures.hxx:131
MWProStructuresListenerState::MWProStructuresListenerState
MWProStructuresListenerState(shared_ptr< MWProStructures > structures, bool mainZone)
the constructor
Definition: MWProStructures.cxx:2575
MWProStructuresListenerState::getFontDebugString
std::string getFontDebugString(int fontId)
debug function which returns a string corresponding to a fontId
Definition: MWProStructures.cxx:2757
MWProStructuresListenerState::m_actPage
int m_actPage
Definition: MWProStructures.hxx:129
MWAWContentListenerPtr
shared_ptr< MWAWContentListener > MWAWContentListenerPtr
a smart pointer of MWAWContentListener
Definition: libmwaw_internal.hxx:330
MWProStructures::getListener
MWAWContentListenerPtr & getListener()
returns the actual listener
Definition: MWProStructures.cxx:558
MWProStructures::buildTableStructures
void buildTableStructures()
look for tables structures and if so, prepare data
Definition: MWProStructures.cxx:1024
MWProStructuresListenerState::sendSection
void sendSection(int numSection)
try to send the i^th section
Definition: MWProStructures.cxx:2820
MWAWPosition.hxx
MWAWParserStatePtr
shared_ptr< MWAWParserState > MWAWParserStatePtr
a smart pointer of MWAWParserState
Definition: libmwaw_internal.hxx:342
MWProStructuresListenerState::m_paragraph
shared_ptr< MWProStructuresInternal::Paragraph > m_paragraph
Definition: MWProStructures.hxx:145
MWProStructures::MWProStructures
MWProStructures(MWProParser &mainParser)
constructor
Definition: MWProStructures.cxx:533
MWProStructures::readString
static bool readString(MWAWInputStreamPtr input, std::string &res)
try to read a string
Definition: MWProStructures.cxx:2364
MWProStructures::getFooterId
int getFooterId(int page, int &numSimillar) const
return the footer blockid ( or 0)
Definition: MWProStructures.cxx:583
MWProStructures::readStructB
bool readStructB()
try to read a zone which follow the fonts zone(checkme)
Definition: MWProStructures.cxx:2399
MWProStructuresInternal::Cell
Internal: the cell of a WNProStructure.
Definition: MWProStructures.cxx:338
MWProStructuresListenerState::sendChar
void sendChar(char c)
send a character
Definition: MWProStructures.cxx:2651
MWProStructures::readCharStyles
bool readCharStyles()
try to read the character styles zone
Definition: MWProStructures.cxx:1507