Debian Codegraph @

src/lib/Canvas5StyleManager.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 /*
35 * Parser to Canvas v5-v11 text document ( style part )
36 *
37 */
38 #ifndef CANVAS5_STYLE_MANAGER
39 # define CANVAS5_STYLE_MANAGER
40
41 #include <string>
42 #include <utility>
43 #include <vector>
44
45 #include <librevenge/librevenge.h>
46
47 #include "libmwaw_internal.hxx"
48
49 #include "MWAWDebug.hxx"
50 #include "MWAWFont.hxx"
51 #include "MWAWGraphicStyle.hxx"
52 #include "MWAWInputStream.hxx"
53 #include "MWAWParagraph.hxx"
54 #include "MWAWPosition.hxx"
55
56 class MWAWFont;
57
58 namespace Canvas5Structure
59 {
60 struct Stream;
61 }
62
63 namespace Canvas5StyleManagerInternal
64 {
65 struct ColorStyle;
66 struct PenStyle;
67
68 struct State;
69 }
70
71 namespace Canvas5ImageInternal
72 {
73 struct VKFLImage;
74 }
75
76 class Canvas5Graph;
77 class Canvas5Image;
78 class Canvas5Parser;
79
80 /** \brief the main class to read the style part of Canvas 5 file
81 *
82 *
83 *
84 */
85 class Canvas5StyleManager
86 {
87 friend class Canvas5Graph;
88 friend class Canvas5Parser;
89
90 public:
91 //! a structure use to store a character style
92 struct CharStyle {
93 //! constructor
94 CharStyle()
95 : m_font()
96 , m_paragraphId(0)
97 , m_linkId(0)
98 {
99 }
100 //! the font
101 MWAWFont m_font;
102 //! the paragraph id
103 int m_paragraphId;
104 //! the link id
105 int m_linkId;
106 };
107
108 //! a structure use to store a list of styles
109 struct StyleList {
110 //! constructor
111 StyleList()
112 : m_fonts()
113 , m_paragraphs()
114 {
115 }
116 //! the fonts, the paragraph id and the link id
117 std::vector<CharStyle> m_fonts;
118 //! the paragraph list and the tab id
119 std::vector<std::pair<MWAWParagraph, int> > m_paragraphs;
120 };
121
122 //! constructor
123 explicit Canvas5StyleManager(Canvas5Parser &parser);
124 //! destructor
125 virtual ~Canvas5StyleManager();
126
127 /** returns the file version */
128 int version() const;
129 /** returns the image parser */
130 std::shared_ptr<Canvas5Image> getImageParser() const;
131
132 //! try to read a color style
133 std::shared_ptr<Canvas5StyleManagerInternal::ColorStyle> readColorStyle(std::shared_ptr<Canvas5Structure::Stream> stream, unsigned type, long len);
134 //! try to update the line color given a color style
135 bool updateLineColor(Canvas5StyleManagerInternal::ColorStyle const &color, MWAWGraphicStyle &style);
136 //! try to update the surface color given a color style
137 bool updateSurfaceColor(Canvas5StyleManagerInternal::ColorStyle const &color, MWAWGraphicStyle &style);
138
139 //! try to read a pen style
140 std::shared_ptr<Canvas5StyleManagerInternal::PenStyle> readPenStyle(Canvas5Structure::Stream &stream, unsigned type, long len);
141 //! try to update the line color given a color style
142 bool updateLine(Canvas5StyleManagerInternal::PenStyle const &pen, MWAWGraphicStyle &style, int &numLines, int lineId, float *offset);
143
144 //! try to read an arrow
145 bool readArrow(std::shared_ptr<Canvas5Structure::Stream> stream, MWAWGraphicStyle::Arrow &arrow, unsigned type, long len);
146 //! try to read a character style, returns a font, a paragraph id and it potential link id
147 bool readCharStyle(Canvas5Structure::Stream &stream, int id, CharStyle &fontIds, bool useFileColors=true);
148 //! try to read a dash's array
149 bool readDash(Canvas5Structure::Stream &stream, std::vector<float> &dashes, unsigned type, long len);
150 //! try to read the second part of a style which contains minor paragraph styles, hyphen, ...
151 bool readStyleEnd(std::shared_ptr<Canvas5Structure::Stream> stream, MWAWFont *font=nullptr, MWAWParagraph *para=nullptr);
152
153 protected:
154 // interface
155
156 /** try to update the line style given the stroke id and returns the number of lines(plin)
157
158 \note in case of plin, after retrieving the number of lines, use lineId to define the line's style to set
159 and give a offset pointer to retrieve this line offset
160 */
161 bool updateLineStyle(int sId, MWAWGraphicStyle &style, int &numLines, int lineId=-1, float *offset=nullptr);
162 //! try to update the line color given the color id
163 bool updateLineColor(int cId, MWAWGraphicStyle &style);
164 //! try to update the surface color given the color id
165 bool updateSurfaceColor(int cId, MWAWGraphicStyle &style);
166
167 //
168 // Intermediate level
169 //
170
171 //! try to read the arrows zones
172 bool readArrows(std::shared_ptr<Canvas5Structure::Stream> stream);
173 //! try to read the character styles
174 bool readCharStyles(std::shared_ptr<Canvas5Structure::Stream> stream);
175 //! try to read the ink color zones
176 bool readInks(std::shared_ptr<Canvas5Structure::Stream> stream);
177 //! try to read the ink color zones: v9
178 bool readInks9(std::shared_ptr<Canvas5Structure::Stream> stream);
179 //! try to read a color: 12 unknown 4 components followed by a type
180 bool readColor(Canvas5Structure::Stream &stream, MWAWVariable<MWAWColor> &color, std::string &extra);
181 //! try to read the dashes
182 bool readDashes(std::shared_ptr<Canvas5Structure::Stream> stream);
183 //! try to read the frame zones: stroke, pen style, arrow, dashes: v9
184 bool readFrameStyles9(std::shared_ptr<Canvas5Structure::Stream> stream);
185 //! try to read the fonts names
186 bool readFonts(std::shared_ptr<Canvas5Structure::Stream> stream, int numFonts);
187 //! read the list of formats, mainly an unit's conversion table
188 bool readFormats(std::shared_ptr<Canvas5Structure::Stream> stream);
189 //! read the pen size (header file)
190 bool readPenSize(std::shared_ptr<Canvas5Structure::Stream> stream);
191 //! read the pen styles
192 bool readPenStyles(std::shared_ptr<Canvas5Structure::Stream> stream);
193 //! try to read the stroke styles
194 bool readStrokes(std::shared_ptr<Canvas5Structure::Stream> stream);
195 //! try to read a paragraph style
196 bool readParaStyle(std::shared_ptr<Canvas5Structure::Stream> stream, int id, StyleList *styles=nullptr);
197 //! try to read the paragraph styles
198 bool readParaStyles(std::shared_ptr<Canvas5Structure::Stream> stream);
199
200 //
201 // Windows RSRC
202 //
203
204 //
205 // Low level
206 //
207
208 //! try to read a gradient zone: OBFL
209 bool readGradient(std::shared_ptr<Canvas5Structure::Stream> stream, long len, MWAWGraphicStyle::Gradient &gradient);
210 //! try to read a hatch zone: htch
211 bool readHatch(std::shared_ptr<Canvas5Structure::Stream> stream, long len, MWAWGraphicStyle::Hatch &hatch,
212 MWAWVariable<MWAWColor> &backColor);
213 //! try to read a symbol zone: vkfl/TXUR
214 std::shared_ptr<Canvas5ImageInternal::VKFLImage> readSymbol(std::shared_ptr<Canvas5Structure::Stream> stream, long len,
215 MWAWVariable<MWAWColor> &backColor);
216
217 private:
218 Canvas5StyleManager(Canvas5StyleManager const &orig) = delete;
219 Canvas5StyleManager &operator=(Canvas5StyleManager const &orig) = delete;
220
221 protected:
222 //
223 // data
224 //
225 //! the parser state
226 MWAWParserStatePtr m_parserState;
227
228 //! the state
229 std::shared_ptr<Canvas5StyleManagerInternal::State> m_state;
230
231 //! the main parser;
232 Canvas5Parser *m_mainParser;
233 };
234 #endif
235 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: