RagTime5StyleManager.hxx
Go to the documentation of this file.
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 (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
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 RAG_TIME_5_STYLE_MANAGER
35 # define RAG_TIME_5_STYLE_MANAGER
36
37 #include <map>
38 #include <ostream>
39 #include <sstream>
40 #include <set>
41 #include <string>
42 #include <vector>
43
44 #include "libmwaw_internal.hxx"
45 #include "MWAWDebug.hxx"
46 #include "MWAWEntry.hxx"
47 #include "MWAWGraphicStyle.hxx"
48
49 #include "RagTime5ClusterManager.hxx"
50 #include "RagTime5StructManager.hxx"
51
52 namespace RagTime5StyleManagerInternal
53 {
54 struct State;
55 }
56
57 class RagTime5Parser;
58
60 class RagTime5StyleManager
61 {
62 friend class RagTime5Parser;
63 public:
65 explicit RagTime5StyleManager(RagTime5Parser &parser);
67 ~RagTime5StyleManager();
68
69 struct GraphicStyle;
70 struct TextStyle;
71
73 bool readGraphicColors(RagTime5ClusterManager::Cluster &cluster);
75 bool readGraphicStyles(RagTime5ClusterManager::Cluster &cluster);
77 bool readTextStyles(RagTime5ClusterManager::Cluster &cluster);
79 bool readFormats(RagTime5ClusterManager::Cluster &cluster);
80
82 bool updateSurfaceStyle(int graphicId, MWAWGraphicStyle &surfaceStyle) const;
84 bool updateBorderStyle(int graphicId, MWAWGraphicStyle &borderStyle, bool isLine) const;
86 bool getLineColor(int graphicId, MWAWColor &color) const;
88 bool updateTextStyles(int textId, MWAWFont &font, MWAWParagraph &para) const;
90 bool getCellBorder(int graphicId, MWAWBorder &border) const;
92 bool getCellBackgroundColor(int graphicId, MWAWColor &color) const;
94 bool updateCellFormat(int formatId, MWAWCell &cell) const;
95
96 protected:
98 void updateTextStyles(size_t id, RagTime5StyleManager::TextStyle const &style,
99 std::vector<RagTime5StyleManager::TextStyle> const &listReadStyles,
100 std::multimap<size_t, size_t> const &idToChildIpMap,
101 std::set<size_t> &seens);
103 void updateGraphicStyles(size_t id, RagTime5StyleManager::GraphicStyle const &style,
104 std::vector<RagTime5StyleManager::GraphicStyle> const &listReadStyles,
105 std::multimap<size_t, size_t> const &idToChildIpMap,
106 std::set<size_t> &seens);
107
108 public:
110 struct GraphicStyle {
112 GraphicStyle()
113 : m_parentId(-1000)
114 , m_width(-1)
115 , m_dash()
116 , m_pattern()
117 , m_gradient(-1)
118 , m_gradientRotation(-1000)
119 , m_gradientCenter(MWAWVec2f(0.5f,0.5f))
120 , m_position(-1)
121 , m_cap(1)
122 , m_mitter(-1)
123 , m_limitPercent(-1)
124 , m_hidden(false)
125 , m_extra("")
126 {
127 m_colors[0]=MWAWVariable<MWAWColor>(MWAWColor::black());
128 m_colors[1]=MWAWVariable<MWAWColor>(MWAWColor::white());
129 for (auto &alpha : m_colorsAlpha) alpha=-1;
130 }
132 virtual ~GraphicStyle();
134 bool isDefault() const
135 {
136 return m_parentId<=-1000 && m_width<0 && !m_dash.isSet() && !m_pattern &&
137 m_gradient<0 && m_gradientRotation<=-1000 && !m_gradientCenter.isSet() &&
138 m_position<0 && m_cap<0 && m_mitter<0 &&
139 !m_colors[0].isSet() && !m_colors[1].isSet() && m_colorsAlpha[0]<0 && m_colorsAlpha[1]<0 &&
140 m_limitPercent<0 && !m_hidden.isSet() && m_extra.empty();
141 }
143 friend std::ostream &operator<<(std::ostream &o, GraphicStyle const &style);
145 void insert(GraphicStyle const &childStyle);
147 bool read(MWAWInputStreamPtr &input, RagTime5StructManager::Field const &field, std::vector<MWAWColor> const &colorList);
149 int m_parentId;
151 float m_width;
153 MWAWVariable<MWAWColor> m_colors[2];
155 float m_colorsAlpha[2];
157 MWAWVariable<std::vector<long> > m_dash;
159 std::shared_ptr<MWAWGraphicStyle::Pattern> m_pattern;
161 int m_gradient;
163 float m_gradientRotation;
165 MWAWVariable<MWAWVec2f> m_gradientCenter;
167 int m_position;
169 int m_cap;
171 int m_mitter;
173 float m_limitPercent;
175 MWAWVariable<bool> m_hidden;
177 std::string m_extra;
178
179 GraphicStyle(GraphicStyle const &)=default; // removeme
180 GraphicStyle(GraphicStyle &&)=default;
181 GraphicStyle &operator=(GraphicStyle const &)=default; // removeme
182 GraphicStyle &operator=(GraphicStyle &&)=default;
183 };
185 struct TextStyle {
187 TextStyle()
188 : m_linkIdList()
189 , m_dateStyleId(-1)
190 , m_graphStyleId(-1)
191 , m_graphLineStyleId(-1)
192 , m_keepWithNext(false)
193 , m_justify(-1)
194 , m_breakMethod(-1)
195 , m_tabList()
196 , m_fontName("")
197 , m_fontId(-1)
198 , m_fontSize(-1)
199 , m_scriptPosition(0)
200 , m_fontScaling(-1)
201 , m_underline(-1)
202 , m_caps(-1)
203 , m_language(-1)
204 , m_widthStreching(-1)
205 , m_numColumns(-1)
206 , m_columnGap(-1)
207 , m_extra("")
208 {
209 for (auto &parentId : m_parentId) parentId=-1;
210 for (auto &fontFlag : m_fontFlags) fontFlag=0;
211 for (auto &margin : m_margins) margin=-1;
212 for (auto &spacing : m_spacings) spacing=-1;
213 for (auto &spacingUnit : m_spacingUnits) spacingUnit=-1;
214 for (auto &letterSpacing : m_letterSpacings) letterSpacing=0;
215 }
217 virtual ~TextStyle();
219 bool isDefault() const
220 {
221 if (m_parentId[0]>=0 || m_parentId[1]>=0 || !m_linkIdList.empty() ||
222 m_dateStyleId>=0 || m_graphStyleId>=0 || m_graphLineStyleId>=0 ||
223 m_keepWithNext.isSet() || m_justify>=0 || m_breakMethod>=0 || !m_tabList.empty() ||
224 !m_fontName.empty() || m_fontId>=0 || m_fontSize>=0 || m_fontFlags[0] || m_fontFlags[1] || m_scriptPosition.isSet() ||
225 m_fontScaling>=0 || m_underline>=0 || m_caps>=0 || m_language>=0 || m_widthStreching>=0 ||
226 m_numColumns>=0 || m_columnGap>=0 || !m_extra.empty())
227 return false;
228 for (int i=0; i<3; ++i) {
229 if (m_margins[i]>=0 || m_spacings[i]>=0 || m_spacingUnits[i]>=0)
230 return false;
231 }
232 for (auto spacing : m_letterSpacings) {
233 if (spacing>0 || spacing<0)
234 return false;
235 }
236 return true;
237 }
239 static std::string getLanguageLocale(int id);
240
242 friend std::ostream &operator<<(std::ostream &o, TextStyle const &style);
244 void insert(TextStyle const &childStyle);
246 bool read(RagTime5StructManager::Field const &field);
248 int m_parentId[2];
250 std::vector<int> m_linkIdList;
252 int m_dateStyleId;
254 int m_graphStyleId;
256 int m_graphLineStyleId;
257
258 // paragraph
259
261 MWAWVariable<bool> m_keepWithNext;
263 int m_justify;
265 double m_spacings[3];
267 int m_spacingUnits[3];
269 int m_breakMethod;
271 double m_margins[3];
273 std::vector<RagTime5StructManager::TabStop> m_tabList;
274
275 // character
276
278 librevenge::RVNGString m_fontName;
280 int m_fontId;
282 float m_fontSize;
284 uint32_t m_fontFlags[2];
286 MWAWVariable<float> m_scriptPosition;
288 float m_fontScaling;
290 int m_underline;
292 int m_caps;
294 int m_language;
296 double m_letterSpacings[4];
298 double m_widthStreching;
299
300 // column
301
303 int m_numColumns;
305 double m_columnGap;
306
308 std::string m_extra;
309
310 TextStyle(TextStyle const &)=default; // removeme
311 TextStyle(TextStyle &&)=default;
312 TextStyle &operator=(TextStyle const &)=default; // removeme
313 TextStyle &operator=(TextStyle &&)=default;
314 };
315
316 protected:
317 //
318 // data
319 //
320
322 RagTime5Parser &m_mainParser;
324 MWAWParserStatePtr m_parserState;
325
327 std::shared_ptr<RagTime5StyleManagerInternal::State> m_state;
328
329 private:
330 RagTime5StyleManager(RagTime5StyleManager const &orig) = delete;
331 RagTime5StyleManager operator=(RagTime5StyleManager const &orig) = delete;
332 };
333
334 #endif
335 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
RagTime5StyleManager::GraphicStyle::m_hidden
MWAWVariable< bool > m_hidden
flag to know if we need to print the shape
Definition: RagTime5StyleManager.hxx:175
RagTime5StyleManager::TextStyle::m_fontId
int m_fontId
the font id
Definition: RagTime5StyleManager.hxx:280
RagTime5StyleManager::TextStyle::m_caps
int m_caps
caps : none, all caps, lower caps, inital caps + other lowers
Definition: RagTime5StyleManager.hxx:292
MWAWParserStatePtr
std::shared_ptr< MWAWParserState > MWAWParserStatePtr
a smart pointer of MWAWParserState
Definition: libmwaw_internal.hxx:553
RagTime5StyleManager::GraphicStyle::m_gradient
int m_gradient
the gradient 0: none, normal, radial
Definition: RagTime5StyleManager.hxx:161
RagTime5StyleManager::GraphicStyle::m_extra
std::string m_extra
extra data
Definition: RagTime5StyleManager.hxx:177
BeagleWksDRParserInternal::operator<<
std::ostream & operator<<(std::ostream &o, Shape const &shape)
Definition: BeagleWksDRParser.cxx:107
RagTime5StyleManager::GraphicStyle::m_dash
MWAWVariable< std::vector< long > > m_dash
the line dash/...
Definition: RagTime5StyleManager.hxx:157
MWAWEntry.hxx
libmwaw_internal.hxx
MWAWColor::white
static MWAWColor white()
return the white color
Definition: libmwaw_internal.hxx:250
RagTime5StyleManager::GraphicStyle::m_gradientCenter
MWAWVariable< MWAWVec2f > m_gradientCenter
the rotation center(checkme)
Definition: RagTime5StyleManager.hxx:165
RagTime5StyleManager::TextStyle::m_graphLineStyleId
int m_graphLineStyleId
the graphic line style id
Definition: RagTime5StyleManager.hxx:256
MWAWColor::black
static MWAWColor black()
return the back color
Definition: libmwaw_internal.hxx:245
MWAWGraphicStyle
a structure used to define a picture style
Definition: MWAWGraphicStyle.hxx:47
RagTime5StyleManager::TextStyle::m_numColumns
int m_numColumns
the number of columns
Definition: RagTime5StyleManager.hxx:303
RagTime5StyleManager::TextStyle::m_fontName
librevenge::RVNGString m_fontName
the font name
Definition: RagTime5StyleManager.hxx:278
RagTime5StructManager.hxx
RagTime5StyleManager
basic class used to read/store RagTime 5/6 styles
Definition: RagTime5StyleManager.hxx:60
RagTime5StyleManager::TextStyle::m_breakMethod
int m_breakMethod
the break method 0: asIs, next container, next page, next even page, next odd page ...
Definition: RagTime5StyleManager.hxx:269
MWAWCell
a structure used to define a cell and its format
Definition: MWAWCell.hxx:52
MWAWColor
the class to store a color
Definition: libmwaw_internal.hxx:192
RagTime5StyleManager::TextStyle::m_dateStyleId
int m_dateStyleId
the date style id
Definition: RagTime5StyleManager.hxx:252
RagTime5StyleManager::TextStyle::m_language
int m_language
the language
Definition: RagTime5StyleManager.hxx:294
RagTime5StyleManager::TextStyle::m_graphStyleId
int m_graphStyleId
the graphic style id
Definition: RagTime5StyleManager.hxx:254
RagTime5StyleManager::TextStyle::isDefault
bool isDefault() const
returns true if the line style is default
Definition: RagTime5StyleManager.hxx:219
RagTime5StyleManager::m_parserState
MWAWParserStatePtr m_parserState
the parser state
Definition: RagTime5StyleManager.hxx:324
RagTime5StyleManager::TextStyle::m_keepWithNext
MWAWVariable< bool > m_keepWithNext
the keep with next flag
Definition: RagTime5StyleManager.hxx:261
MWAWFont
Class to store font.
Definition: MWAWFont.hxx:43
MWAWBorder
a border
Definition: libmwaw_internal.hxx:333
RagTime5StyleManager::GraphicStyle::m_width
float m_width
the line width (in point)
Definition: RagTime5StyleManager.hxx:151
RagTime5StyleManager::GraphicStyle::m_cap
int m_cap
the line caps ( normal=1, round, square)
Definition: RagTime5StyleManager.hxx:169
RagTime5StyleManager::TextStyle::m_widthStreching
double m_widthStreching
the width streching
Definition: RagTime5StyleManager.hxx:298
RagTime5StyleManager::TextStyle::m_extra
std::string m_extra
extra data
Definition: RagTime5StyleManager.hxx:308
RagTime5StyleManager::TextStyle::m_justify
int m_justify
justify 0: left, 1:center, 2:right, 3:full, 4:full all
Definition: RagTime5StyleManager.hxx:263
RagTime5StyleManager::m_state
std::shared_ptr< RagTime5StyleManagerInternal::State > m_state
the state
Definition: RagTime5StyleManager.hxx:327
RagTime5StyleManager::GraphicStyle::m_limitPercent
float m_limitPercent
the line limit
Definition: RagTime5StyleManager.hxx:173
RagTime5Parser
the main class to read a RagTime v5 file
Definition: RagTime5Parser.hxx:73
RagTime5StructManager::Field
a field of RagTime 5/6 structures
Definition: RagTime5StructManager.hxx:235
RagTime5StyleManager::TextStyle::m_columnGap
double m_columnGap
the gap between columns
Definition: RagTime5StyleManager.hxx:305
RagTime5Parser::RagTime5StyleManager
friend class RagTime5StyleManager
Definition: RagTime5Parser.hxx:83
RagTime5StyleManager::TextStyle::m_tabList
std::vector< RagTime5StructManager::TabStop > m_tabList
the tabulations
Definition: RagTime5StyleManager.hxx:273
RagTime5StyleManager::TextStyle::m_scriptPosition
MWAWVariable< float > m_scriptPosition
the font script position ( in percent)
Definition: RagTime5StyleManager.hxx:286
RagTime5StyleManager::TextStyle::TextStyle
TextStyle()
constructor
Definition: RagTime5StyleManager.hxx:187
MWAWDebug.hxx
MWAWInputStreamPtr
std::shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:547
RagTime5StyleManager::GraphicStyle::m_mitter
int m_mitter
the line mitter ( triangle=1, round, out)
Definition: RagTime5StyleManager.hxx:171
RagTime5StyleManager::TextStyle::m_fontScaling
float m_fontScaling
the font script position ( in percent)
Definition: RagTime5StyleManager.hxx:288
MWAWParagraph
class to store the paragraph properties
Definition: MWAWParagraph.hxx:84
RagTime5StyleManager::GraphicStyle::GraphicStyle
GraphicStyle()
constructor
Definition: RagTime5StyleManager.hxx:112
RagTime5StyleManager::m_mainParser
RagTime5Parser & m_mainParser
the parser
Definition: RagTime5StyleManager.hxx:322
RagTime5StyleManager::GraphicStyle::isDefault
bool isDefault() const
returns true if the line style is default
Definition: RagTime5StyleManager.hxx:134
RagTime5StyleManager::GraphicStyle
the graphic style of a RagTime v5-v6 document
Definition: RagTime5StyleManager.hxx:110
RagTime5StyleManager::GraphicStyle::m_parentId
int m_parentId
the parent id
Definition: RagTime5StyleManager.hxx:149
RagTime5StyleManager::GraphicStyle::m_pattern
std::shared_ptr< MWAWGraphicStyle::Pattern > m_pattern
the line pattern
Definition: RagTime5StyleManager.hxx:159
RagTime5StyleManager::TextStyle
the text style of a RagTime v5-v6 document
Definition: RagTime5StyleManager.hxx:185
RagTime5ClusterManager.hxx
MWAWVariable< MWAWColor >
RagTime5StyleManagerInternal
Internal: the structures of a RagTime5Style.
Definition: RagTime5StyleManager.cxx:51
RagTime5StyleManager::TextStyle::m_fontSize
float m_fontSize
the font size
Definition: RagTime5StyleManager.hxx:282
MWAWGraphicStyle.hxx
RagTime5StyleManager::TextStyle::m_linkIdList
std::vector< int > m_linkIdList
the link id list
Definition: RagTime5StyleManager.hxx:250
RagTime5StyleManager::TextStyle::m_underline
int m_underline
underline : none, single, double
Definition: RagTime5StyleManager.hxx:290
MWAWVec2
small class which defines a vector with 2 elements
Definition: libmwaw_internal.hxx:651
RagTime5StyleManager::GraphicStyle::m_gradientRotation
float m_gradientRotation
the gradient rotation(checkme)
Definition: RagTime5StyleManager.hxx:163
RagTime5StyleManager::GraphicStyle::m_position
int m_position
the line position inside=1/normal/outside/round
Definition: RagTime5StyleManager.hxx:167
RagTime5ClusterManager::Cluster
the cluster data
Definition: RagTime5ClusterManager.hxx:221