Debian Codegraph @

src/lib/ApplePictParser.hxx

raw
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 APPLEPICT_PARSER
35 # define APPLEPICT_PARSER
36
37 #include <string>
38 #include <vector>
39
40 #include <librevenge/librevenge.h>
41
42 #include "MWAWDebug.hxx"
43 #include "MWAWGraphicStyle.hxx"
44 #include "MWAWInputStream.hxx"
45
46 #include "MWAWParser.hxx"
47
48 namespace ApplePictParserInternal
49 {
50 struct Bitmap;
51 struct Pixmap;
52 struct Region;
53 struct State;
54
55 class SubDocument;
56 }
57
58 /** \brief the main class to read a ApplePict file
59 *
60 */
61 class ApplePictParser final: public MWAWGraphicParser
62 {
63 friend class ApplePictParserInternal::SubDocument;
64 public:
65 /** the drawing method: frame, paint, ... */
66 enum DrawingMethod {
67 D_FRAME, D_PAINT, D_ERASE, D_INVERT, D_FILL,
68 D_TEXT, D_UNDEFINED
69 };
70
71 //! constructor
72 ApplePictParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header);
73 //! destructor
74 ~ApplePictParser() final;
75
76 //! checks if the document header is correct (or not)
77 bool checkHeader(MWAWHeader *header, bool strict=false) final;
78
79 //! the main parse function
80 void parse(librevenge::RVNGDrawingInterface *documentInterface) final;
81
82 protected:
83 //! try to read a zone
84 bool readZone();
85
86 //! inits all internal variables
87 void init();
88
89 //! creates the listener which will be associated to the document
90 void createDocument(librevenge::RVNGDrawingInterface *documentInterface);
91
92 protected:
93 //! finds the different objects zones
94 bool createZones();
95
96 //
97 // low level
98 //
99
100 //! draw a line from current position to position
101 void drawLine(MWAWVec2i const &pt);
102 //! read the current rectangle and draw it
103 bool readAndDrawRectangle(DrawingMethod method);
104 //! draw the current rectangle
105 void drawRectangle(DrawingMethod method);
106 //! read the current round rectangle and draw it
107 bool readAndDrawRoundRectangle(DrawingMethod method);
108 //! draw the current round rectangle
109 void drawRoundRectangle(DrawingMethod method);
110 //! read the current circle and draw it
111 bool readAndDrawCircle(DrawingMethod method);
112 //! draw the current circle
113 void drawCircle(DrawingMethod method);
114 //! read the current pie and draw it
115 bool readAndDrawPie(DrawingMethod method);
116 //! draw the current circle
117 void drawPie(DrawingMethod method, int startAngle, int dAngle);
118 //! read the current polygon and draw it
119 bool readAndDrawPolygon(DrawingMethod method);
120 //! draw the current polygon
121 void drawPolygon(DrawingMethod method);
122 //! read the current text and draw it
123 bool readAndDrawText(std::string &text);
124 //! draw a current text
125 void drawText(MWAWEntry const &entry);
126
127 //! draw a bitmap
128 void drawBitmap(ApplePictParserInternal::Bitmap const &bitmap);
129 //! draw a pixmap
130 void drawPixmap(ApplePictParserInternal::Pixmap const &pixmap);
131
132 //! try to read a rgb color
133 bool readRGBColor(MWAWColor &color);
134 //! try to read a bw pattern
135 bool readBWPattern(MWAWGraphicStyle::Pattern &pattern);
136 //! try to read a color pattern
137 bool readColorPattern(MWAWGraphicStyle::Pattern &pattern);
138 //! try to read a region
139 bool readRegion(ApplePictParserInternal::Region &region);
140 //! read a bitmap
141 bool readBitmap(ApplePictParserInternal::Bitmap &bitmap, bool isPacked, bool hasRgn);
142 //! read a pixmap
143 bool readPixmap(ApplePictParserInternal::Pixmap &pixmap, bool isPacked, bool haColorTable, bool hasRectMode, bool hasRgn);
144 //! try to read a quicktime zone
145 bool readQuicktime(MWAWEmbeddedObject &object, MWAWBox2f &bdBox);
146
147 //! debug function to print a drawing method
148 static std::string getDrawingName(DrawingMethod method)
149 {
150 switch (method) {
151 case D_FRAME:
152 return "frame";
153 case D_PAINT:
154 return "paint";
155 case D_ERASE:
156 return "erase";
157 case D_INVERT:
158 return "invert";
159 case D_FILL:
160 return "fill";
161 case D_TEXT:
162 return "text";
163 case D_UNDEFINED:
164 #if !defined(__clang__)
165 default:
166 #endif
167 break;
168 }
169 return "";
170 }
171 //! debug function to print a mode name
172 static std::string getModeName(int mode);
173 //
174 // data
175 //
176 //! the state
177 std::shared_ptr<ApplePictParserInternal::State> m_state;
178 };
179 #endif
180 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: