| 1 |
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
| 2 |
|
| 3 |
/* libmwaw |
| 4 |
* Version: MPL 2.0 / LGPLv2+ |
| 5 |
* |
| 6 |
* The contents of this file are subject to the Mozilla Public License Version |
| 7 |
* 2.0 (the "License"); you may not use this file except in compliance with |
| 8 |
* the License or as specified alternatively below. You may obtain a copy of |
| 9 |
* the License at http://www.mozilla.org/MPL/ |
| 10 |
* |
| 11 |
* Software distributed under the License is distributed on an "AS IS" basis, |
| 12 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 13 |
* for the specific language governing rights and limitations under the |
| 14 |
* License. |
| 15 |
* |
| 16 |
* Major Contributor(s): |
| 17 |
* Copyright (C) 2002 William Lachance ([email protected]) |
| 18 |
* Copyright (C) 2002,2004 Marc Maurer ([email protected]) |
| 19 |
* Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 20 |
* Copyright (C) 2006, 2007 Andrew Ziem |
| 21 |
* Copyright (C) 2011, 2012 Alonso Laurent ([email protected]) |
| 22 |
* |
| 23 |
* |
| 24 |
* All Rights Reserved. |
| 25 |
* |
| 26 |
* For minor contributions see the git repository. |
| 27 |
* |
| 28 |
* Alternatively, the contents of this file may be used under the terms of |
| 29 |
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), |
| 30 |
* in which case the provisions of the LGPLv2+ are applicable |
| 31 |
* instead of those above. |
| 32 |
*/ |
| 33 |
|
| 34 |
#ifndef MACDRAWPRO_PARSER |
| 35 |
# define MACDRAWPRO_PARSER |
| 36 |
|
| 37 |
#include <map> |
| 38 |
#include <string> |
| 39 |
#include <vector> |
| 40 |
|
| 41 |
#include <librevenge/librevenge.h> |
| 42 |
|
| 43 |
#include "MWAWDebug.hxx" |
| 44 |
#include "MWAWInputStream.hxx" |
| 45 |
|
| 46 |
#include "MWAWParser.hxx" |
| 47 |
|
| 48 |
namespace MacDrawProParserInternal |
| 49 |
{ |
| 50 |
struct Layer; |
| 51 |
struct Library; |
| 52 |
struct Shape; |
| 53 |
struct State; |
| 54 |
|
| 55 |
class SubDocument; |
| 56 |
} |
| 57 |
|
| 58 |
class MacDrawProStyleManager; |
| 59 |
|
| 60 |
/** \brief the main class to read a MacDraw II file |
| 61 |
* |
| 62 |
*/ |
| 63 |
class MacDrawProParser final : public MWAWGraphicParser |
| 64 |
{ |
| 65 |
friend class MacDrawProStyleManager; |
| 66 |
friend class MacDrawProParserInternal::SubDocument; |
| 67 |
public: |
| 68 |
//! constructor |
| 69 |
MacDrawProParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header); |
| 70 |
//! destructor |
| 71 |
~MacDrawProParser() final; |
| 72 |
|
| 73 |
//! checks if the document header is correct (or not) |
| 74 |
bool checkHeader(MWAWHeader *header, bool strict=false) final; |
| 75 |
|
| 76 |
// the main parse function |
| 77 |
void parse(librevenge::RVNGDrawingInterface *documentInterface) final; |
| 78 |
|
| 79 |
protected: |
| 80 |
//! inits all internal variables |
| 81 |
void init(); |
| 82 |
|
| 83 |
//! creates the listener which will be associated to the document |
| 84 |
void createDocument(librevenge::RVNGDrawingInterface *documentInterface); |
| 85 |
|
| 86 |
protected: |
| 87 |
//! finds the different objects zones |
| 88 |
bool createZones(); |
| 89 |
|
| 90 |
// Intermediate level |
| 91 |
|
| 92 |
//! tries to read the print info zone |
| 93 |
bool readPrintInfo(); |
| 94 |
//! tries to the header info zone ( print info + some information about content + prefs ?) |
| 95 |
bool readHeaderInfo(); |
| 96 |
//! tries to the layer info zone |
| 97 |
bool readLayersInfo(); |
| 98 |
//! tries to the layer library correspondance zone |
| 99 |
bool readLayerLibraryCorrespondance(); |
| 100 |
//! tries to read the library name info zone |
| 101 |
bool readLibrariesInfo(); |
| 102 |
//! finds the objet's data/text positions |
| 103 |
bool findObjectPositions(bool dataZone); |
| 104 |
//! computes the layers and libraries bounding box |
| 105 |
bool computeLayersAndLibrariesBoundingBox(); |
| 106 |
|
| 107 |
//! tries to read a structured zone header |
| 108 |
bool readStructuredHeaderZone(MWAWEntry const &entry, std::map<int, long> &idToDeltaPosMap); |
| 109 |
|
| 110 |
// |
| 111 |
// low level |
| 112 |
// |
| 113 |
|
| 114 |
//! tries to read an object and returns the object id (-1 if error ) |
| 115 |
int readObject(); |
| 116 |
//! tries to read an object data |
| 117 |
bool readObjectData(MacDrawProParserInternal::Shape &shape, int zId); |
| 118 |
//! tries to read the rotation |
| 119 |
bool readRotationInObjectData(MacDrawProParserInternal::Shape &shape, long endPos, std::string &extra); |
| 120 |
//! tries to update the basic geometric data |
| 121 |
bool updateGeometryShape(MacDrawProParserInternal::Shape &shape, float cornerWidth); |
| 122 |
//! tries to read a bitmap data |
| 123 |
bool readBitmap(MacDrawProParserInternal::Shape &shape, MWAWEntry const &entry); |
| 124 |
//! tries to read a text object data in MacDraw II file |
| 125 |
bool readTextII(MacDrawProParserInternal::Shape &shape, MWAWEntry const &entry); |
| 126 |
//! tries to read a text object data in MacDraw pro file |
| 127 |
bool readTextPro(MacDrawProParserInternal::Shape &shape, MWAWEntry const &entry); |
| 128 |
//! tries to read a basic geometric object data ( line, rect, arc,... ) |
| 129 |
bool readGeometryShapeData(MacDrawProParserInternal::Shape &shape, MWAWEntry const &entry); |
| 130 |
|
| 131 |
// send functions |
| 132 |
|
| 133 |
//! tries to create a master page if needed |
| 134 |
bool sendMasterPage(); |
| 135 |
//! tries to send the layer corresponding a page |
| 136 |
bool sendPage(int page); |
| 137 |
//! tries to send a library (not functionnal) |
| 138 |
bool send(MacDrawProParserInternal::Library const &library); |
| 139 |
//! tries to send a layer |
| 140 |
bool send(MacDrawProParserInternal::Layer const &layer); |
| 141 |
//! tries to send a shape |
| 142 |
bool send(MacDrawProParserInternal::Shape const &shape, MWAWVec2f const &orig); |
| 143 |
//! tries to send a bitmap to the listener |
| 144 |
bool sendBitmap(MacDrawProParserInternal::Shape const &shape, MWAWPosition const &pos); |
| 145 |
//! tries to send a text zone to the listener |
| 146 |
bool sendText(int zoneId); |
| 147 |
//! tries to send a line measure to the listener |
| 148 |
bool sendMeasure(MWAWEntry const &entry); |
| 149 |
//! sends the data which have not yet been sent to the listener |
| 150 |
void flushExtra(); |
| 151 |
|
| 152 |
// |
| 153 |
// data |
| 154 |
// |
| 155 |
//! the state |
| 156 |
std::shared_ptr<MacDrawProParserInternal::State> m_state; |
| 157 |
|
| 158 |
//! the style manager state |
| 159 |
std::shared_ptr<MacDrawProStyleManager> m_styleManager; |
| 160 |
}; |
| 161 |
#endif |
| 162 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |