| 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 FREEHAND_PARSER |
| 35 |
# define FREEHAND_PARSER |
| 36 |
|
| 37 |
#include <string> |
| 38 |
#include <vector> |
| 39 |
|
| 40 |
#include <librevenge/librevenge.h> |
| 41 |
|
| 42 |
#include "MWAWDebug.hxx" |
| 43 |
#include "MWAWInputStream.hxx" |
| 44 |
|
| 45 |
#include "MWAWParser.hxx" |
| 46 |
|
| 47 |
namespace FreeHandParserInternal |
| 48 |
{ |
| 49 |
struct Shape; |
| 50 |
struct ShapeHeader; |
| 51 |
struct StyleHeader; |
| 52 |
struct ScreenMode; |
| 53 |
struct Textbox; |
| 54 |
struct State; |
| 55 |
|
| 56 |
class SubDocument; |
| 57 |
} |
| 58 |
|
| 59 |
/** \brief the main class to read a FreeHand v0,v1 file |
| 60 |
* |
| 61 |
*/ |
| 62 |
class FreeHandParser final : public MWAWGraphicParser |
| 63 |
{ |
| 64 |
friend class FreeHandParserInternal::SubDocument; |
| 65 |
public: |
| 66 |
//! constructor |
| 67 |
FreeHandParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header); |
| 68 |
//! destructor |
| 69 |
~FreeHandParser() final; |
| 70 |
|
| 71 |
//! checks if the document header is correct (or not) |
| 72 |
bool checkHeader(MWAWHeader *header, bool strict=false) final; |
| 73 |
|
| 74 |
// the main parse function |
| 75 |
void parse(librevenge::RVNGDrawingInterface *documentInterface) final; |
| 76 |
|
| 77 |
protected: |
| 78 |
//! inits all internal variables |
| 79 |
void init(); |
| 80 |
|
| 81 |
//! creates the listener which will be associated to the document |
| 82 |
void createDocument(librevenge::RVNGDrawingInterface *documentInterface); |
| 83 |
|
| 84 |
protected: |
| 85 |
//! finds the different objects zones |
| 86 |
bool createZones(); |
| 87 |
//! try to read a zone: version 1 |
| 88 |
bool readZoneV1(int zId); |
| 89 |
//! try to read a zone: version 2 |
| 90 |
bool readZoneV2(int zId); |
| 91 |
|
| 92 |
//! try to read a special scren mode |
| 93 |
bool readScreenMode(FreeHandParserInternal::ScreenMode &screen); |
| 94 |
//! try to read a style header |
| 95 |
bool readStyleHeader(FreeHandParserInternal::StyleHeader &style); |
| 96 |
//! try to read a color zone |
| 97 |
bool readColor(int zId); |
| 98 |
//! try to read the dash zone |
| 99 |
bool readDash(int zId); |
| 100 |
//! try to read a fill zone |
| 101 |
bool readFillStyle(int zId); |
| 102 |
//! try to read a line style zone |
| 103 |
bool readLineStyle(int zId); |
| 104 |
//! try to read a postscript zone |
| 105 |
bool readPostscriptStyle(int zId); |
| 106 |
|
| 107 |
//! try to read the list of group |
| 108 |
bool readRootGroup(int zId); |
| 109 |
//! try to read a style group zone |
| 110 |
bool readStyleGroup(int zId); |
| 111 |
//! try to read a group zone: version 1 |
| 112 |
bool readGroupV1(int zId); |
| 113 |
//! try to read a group zone: version 2 |
| 114 |
bool readGroupV2(int zId); |
| 115 |
//! try to read a join zone (used to put text around path) |
| 116 |
bool readJoinGroup(int zId); |
| 117 |
//! try to read a node which contain the group transformation |
| 118 |
bool readTransformGroup(int zId); |
| 119 |
//! try to read a label/font name zone |
| 120 |
bool readStringZone(int zId); |
| 121 |
|
| 122 |
//! try to read a shape header |
| 123 |
bool readShapeHeader(FreeHandParserInternal::ShapeHeader &shape); |
| 124 |
//! try to read a data zone |
| 125 |
bool readDataZone(int zId); |
| 126 |
|
| 127 |
//! try to read a background picture zone |
| 128 |
bool readBackgroundPicture(int zId); |
| 129 |
//! try to read a picture node |
| 130 |
bool readPictureZone(int zId); |
| 131 |
//! try to read a shape |
| 132 |
bool readShape(int zId); |
| 133 |
//! try to read a textbox zone: version 1 |
| 134 |
bool readTextboxV1(int zId); |
| 135 |
//! try to read a textbox zone: version 2 |
| 136 |
bool readTextboxV2(int zId); |
| 137 |
|
| 138 |
//! try to send a zone |
| 139 |
bool sendZone(int zId, MWAWTransformation const &transform); |
| 140 |
//! try to send a group shape |
| 141 |
bool sendGroup(FreeHandParserInternal::Shape const &group, MWAWTransformation const &transform); |
| 142 |
//! try to send a background picture |
| 143 |
bool sendBackgroundPicture(FreeHandParserInternal::Shape const &picture, MWAWTransformation const &transform); |
| 144 |
//! try to send a picture |
| 145 |
bool sendPicture(FreeHandParserInternal::Shape const &picture, MWAWTransformation const &transform); |
| 146 |
//! try to send a basic shape |
| 147 |
bool sendShape(FreeHandParserInternal::Shape const &shape, MWAWTransformation const &transform); |
| 148 |
//! try to send a basic textbox |
| 149 |
bool sendTextbox(FreeHandParserInternal::Textbox const &textbox, MWAWTransformation const &transform); |
| 150 |
//! try to send the text of a text box |
| 151 |
bool sendText(int zId); |
| 152 |
//! try to open a layer |
| 153 |
bool openLayer(int zId); |
| 154 |
//! try to close a layer |
| 155 |
void closeLayer(); |
| 156 |
//! sends the data which have not yet been sent to the listener |
| 157 |
void flushExtra(); |
| 158 |
|
| 159 |
/** try to decompose the matrix in a rotation + scaling/translation matrix. |
| 160 |
|
| 161 |
Note: because of the y-symetry this function is different from MWAWTransformation::decompose */ |
| 162 |
static bool decomposeMatrix(MWAWTransformation const &matrix, float &rotation, MWAWTransformation &transform, MWAWVec2f const ¢er); |
| 163 |
|
| 164 |
//! the state |
| 165 |
std::shared_ptr<FreeHandParserInternal::State> m_state; |
| 166 |
}; |
| 167 |
#endif |
| 168 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |