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 
51 
52 namespace RagTime5StyleManagerInternal
53 {
54 struct State;
55 }
56 
57 class RagTime5Parser;
58 
61 {
62  friend class RagTime5Parser;
63 public:
65  explicit RagTime5StyleManager(RagTime5Parser &parser);
68 
69  struct GraphicStyle;
70  struct TextStyle;
71 
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 {
113  m_position(-1), m_cap(1), m_mitter(-1), m_limitPercent(-1), m_hidden(false), m_extra("")
114  {
117  m_colorsAlpha[0]=m_colorsAlpha[1]=-1;
118  }
120  virtual ~GraphicStyle()
121  {
122  }
124  bool isDefault() const
125  {
126  return m_parentId<=-1000 && m_width<0 && !m_dash.isSet() && !m_pattern &&
127  m_gradient<0 && m_gradientRotation<=-1000 && !m_gradientCenter.isSet() &&
128  m_position<0 && m_cap<0 && m_mitter<0 &&
129  !m_colors[0].isSet() && !m_colors[1].isSet() && m_colorsAlpha[0]<0 && m_colorsAlpha[1]<0 &&
130  m_limitPercent<0 && !m_hidden.isSet() && m_extra.empty();
131  }
133  friend std::ostream &operator<<(std::ostream &o, GraphicStyle const &style);
135  void insert(GraphicStyle const &childStyle);
137  bool read(MWAWInputStreamPtr &input, RagTime5StructManager::Field const &field, std::vector<MWAWColor> const &colorList);
141  float m_width;
145  float m_colorsAlpha[2];
149  shared_ptr<MWAWGraphicStyle::Pattern> m_pattern;
159  int m_cap;
161  int m_mitter;
167  std::string m_extra;
168  };
170  struct TextStyle {
175  m_numColumns(-1), m_columnGap(-1), m_extra("")
176  {
177  m_parentId[0]=m_parentId[1]=-1;
178  m_fontFlags[0]=m_fontFlags[1]=0;
179  for (int i=0; i<3; ++i) {
180  m_margins[i]=-1;
181  m_spacings[i]=-1;
182  m_spacingUnits[i]=-1;
183  }
184  for (int i=0; i<4; ++i) m_letterSpacings[i]=0;
185  }
187  virtual ~TextStyle()
188  {
189  }
191  bool isDefault() const
192  {
193  if (m_parentId[0]>=0 || m_parentId[1]>=0 || !m_linkIdList.empty() ||
195  m_keepWithNext.isSet() || m_justify>=0 || m_breakMethod>=0 || !m_tabList.empty() ||
196  !m_fontName.empty() || m_fontId>=0 || m_fontSize>=0 || m_fontFlags[0] || m_fontFlags[1] || m_scriptPosition.isSet() ||
197  m_fontScaling>=0 || m_underline>=0 || m_caps>=0 || m_language>=0 || m_widthStreching>=0 ||
198  m_numColumns>=0 || m_columnGap>=0 || !m_extra.empty())
199  return false;
200  for (int i=0; i<3; ++i) {
201  if (m_margins[i]>=0 || m_spacings[i]>=0 || m_spacingUnits[i]>=0)
202  return false;
203  }
204  for (int i=0; i<4; ++i) {
205  if (m_letterSpacings[i]>0 || m_letterSpacings[i]<0)
206  return false;
207  }
208  return true;
209  }
211  static std::string getLanguageLocale(int id);
212 
214  friend std::ostream &operator<<(std::ostream &o, TextStyle const &style);
216  void insert(TextStyle const &childStyle);
218  bool read(RagTime5StructManager::Field const &field);
220  int m_parentId[2];
222  std::vector<int> m_linkIdList;
229 
230  // paragraph
231 
237  double m_spacings[3];
243  double m_margins[3];
245  std::vector<RagTime5StructManager::TabStop> m_tabList;
246 
247  // character
248 
250  librevenge::RVNGString m_fontName;
252  int m_fontId;
254  float m_fontSize;
256  uint32_t m_fontFlags[2];
264  int m_caps;
268  double m_letterSpacings[4];
271 
272  // column
273 
277  double m_columnGap;
278 
280  std::string m_extra;
281  };
282 
283 protected:
284  //
285  // data
286  //
287 
292 
294  shared_ptr<RagTime5StyleManagerInternal::State> m_state;
295 
296 private:
299 };
300 
301 #endif
302 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Tue Mar 1 2016 23:42:53 for libmwaw by doxygen 1.8.4