MWAWFont.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 MWAW_FONT
35 # define MWAW_FONT
36 
37 #include <assert.h>
38 #include <string>
39 #include <vector>
40 
41 #include "libmwaw_internal.hxx"
42 
43 class MWAWFontConverter;
44 class WPXPropertyList;
45 
47 class MWAWFont
48 {
49 public:
51  struct Line {
55  enum Type { Single, Double, Triple };
57  Line(Style style=None, Type type=Single, bool wordFlag=false, float w=1.0) :
58  m_style(style), m_type(type), m_word(wordFlag), m_width(w), m_color(MWAWColor::black()) { }
60  bool isSet() const {
61  return m_style != None && m_width>0;
62  }
64  void addTo(WPXPropertyList &propList, std::string const &type) const;
66  friend std::ostream &operator<<(std::ostream &o, Line const &line);
68  bool operator==(Line const &oth) const {
69  return cmp(oth)==0;
70  }
72  bool operator!=(Line const &oth) const {
73  return cmp(oth)!=0;
74  }
76  int cmp(Line const &oth) const {
77  if (m_style != oth.m_style) return int(m_style)-int(oth.m_style);
78  if (m_type != oth.m_type) return int(m_type)-int(oth.m_type);
79  if (m_word != oth.m_word) return m_word ? -1 : 1;
80  if (m_width < oth.m_width) return -1;
81  if (m_width > oth.m_width) return 1;
82  if (m_color.isSet() != oth.m_color.isSet())
83  return m_color.isSet();
84  if (m_color.get() < oth.m_color.get()) return -1;
85  if (m_color.get() > oth.m_color.get()) return 1;
86  return 0;
87  }
93  bool m_word;
95  float m_width;
98  };
100  struct Script {
102  Script(float delta=0, WPXUnit deltaUnit=WPX_PERCENT, int scale=100) :
103  m_delta(delta), m_deltaUnit(deltaUnit), m_scale(scale) {
104  }
106  bool isSet() const {
107  return *this != Script();
108  }
110  static Script sub() {
111  return Script(-33,WPX_PERCENT,58);
112  }
114  static Script sub100() {
115  return Script(-20);
116  }
118  static Script super() {
119  return Script(33,WPX_PERCENT,58);
120  }
122  static Script super100() {
123  return Script(20);
124  }
126  std::string str(float fSize) const;
127 
129  bool operator==(Script const &oth) const {
130  return cmp(oth)==0;
131  }
133  bool operator!=(Script const &oth) const {
134  return cmp(oth)!=0;
135  }
137  bool operator<(Script const &oth) const {
138  return cmp(oth)<0;
139  }
141  bool operator<=(Script const &oth) const {
142  return cmp(oth)<=0;
143  }
145  bool operator>(Script const &oth) const {
146  return cmp(oth)>0;
147  }
149  bool operator>=(Script const &oth) const {
150  return cmp(oth)>=0;
151  }
153  int cmp(Script const &oth) const {
154  if (m_delta > oth.m_delta) return -1;
155  if (m_delta < oth.m_delta) return 1;
156  if (m_deltaUnit != oth.m_deltaUnit) return int(m_deltaUnit)-int(oth.m_deltaUnit);
157  if (m_scale != oth.m_scale) return m_scale-oth.m_scale;
158  return 0;
159  }
161  float m_delta;
163  WPXUnit m_deltaUnit;
165  int m_scale;
166  };
167 
170  hiddenBit=0x20, outlineBit=0x40, shadowBit=0x80,
172  lowercaseBit=0x800, boxedBit=0x1000, boxedRoundedBit=0x2000,
174  };
180  MWAWFont(int newId=-1, float sz=12, uint32_t f = 0) : m_id(newId), m_size(sz), m_deltaSpacing(0), m_texteWidthScaling(1.0), m_scriptPosition(),
181  m_flags(f), m_overline(Line::None), m_strikeoutline(Line::None), m_underline(Line::None),
182  m_color(MWAWColor::black()), m_backgroundColor(MWAWColor::white()), m_language(""), m_extra("") {
183  resetColor();
184  };
186  bool isSet() const {
187  return m_id.isSet();
188  }
190  void insert(MWAWFont const &ft) {
191  m_id.insert(ft.m_id);
192  m_size.insert(ft.m_size);
196  if (ft.m_flags.isSet()) {
197  if (m_flags.isSet())
198  setFlags(flags()| ft.flags());
199  else
200  m_flags = ft.m_flags;
201  }
202  m_overline.insert(ft.m_overline);
203  m_strikeoutline.insert(ft.m_strikeoutline);
204  m_underline.insert(ft.m_underline);
205  m_color.insert(ft.m_color);
206  m_extra += ft.m_extra;
207  }
209  void setFont(int newId) {
210  resetColor();
211  m_id=newId;
212  }
213 
215  int id() const {
216  return m_id.get();
217  }
219  void setId(int newId) {
220  m_id = newId;
221  }
222 
224  float size() const {
225  return m_size.get();
226  }
228  void setSize(float sz) {
229  m_size = sz;
230  }
231 
233  float deltaLetterSpacing() const {
234  return m_deltaSpacing.get();
235  }
237  void setDeltaLetterSpacing(float d) {
238  m_deltaSpacing=d;
239  }
241  float texteWidthScaling() const {
242  return m_texteWidthScaling.get();
243  }
245  void setTexteWidthScaling(float scale=1.0) {
246  m_texteWidthScaling = scale;
247  }
249  Script const &script() const {
250  return m_scriptPosition.get();
251  }
252 
254  void set(Script const &newscript) {
255  m_scriptPosition = newscript;
256  }
257 
259  uint32_t flags() const {
260  return m_flags.get();
261  }
263  void setFlags(uint32_t fl) {
264  m_flags = fl;
265  }
266 
268  bool hasColor() const {
269  return m_color.isSet() && !m_color.get().isBlack();
270  }
272  void getColor(MWAWColor &c) const {
273  c = m_color.get();
274  }
276  void setColor(MWAWColor color) {
277  m_color = color;
278  }
279 
281  void getBackgroundColor(MWAWColor &c) const {
282  c = m_backgroundColor.get();
283  }
286  m_backgroundColor = color;
287  }
289  void resetColor() {
292  }
293 
295  bool hasDecorationLines() const {
296  return (m_overline.isSet() && m_overline->isSet()) ||
297  (m_strikeoutline.isSet() && m_strikeoutline->isSet()) ||
298  (m_underline.isSet() && m_underline->isSet());
299  }
302  if (m_overline.isSet()) m_overline=Line(Line::None);
304  if (m_underline.isSet()) m_underline=Line(Line::None);
305  }
307  Line const &getOverline() const {
308  return m_overline.get();
309  }
311  void setOverline(Line const &line) {
312  m_overline = line;
313  }
315  void setOverlineStyle(Line::Style style=Line::None, bool doReset=true) {
316  if (doReset)
317  m_overline = Line(style);
318  else
319  m_overline->m_style = style;
320  }
323  m_overline->m_type = type;
324  }
326  void setOverlineWordFlag(bool wordFlag=false) {
327  m_overline->m_word = wordFlag;
328  }
330  void setOverlineWidth(float w) {
331  m_overline->m_width = w;
332  }
334  void setOverlineColor(MWAWColor const &color) {
335  m_overline->m_color = color;
336  }
337 
339  Line const &getStrikeOut() const {
340  return m_strikeoutline.get();
341  }
343  void setStrikeOut(Line const &line) {
344  m_strikeoutline = line;
345  }
347  void setStrikeOutStyle(Line::Style style=Line::None, bool doReset=true) {
348  if (doReset)
349  m_strikeoutline = Line(style);
350  else
351  m_strikeoutline->m_style = style;
352  }
355  m_strikeoutline->m_type = type;
356  }
358  void setStrikeOutWordFlag(bool wordFlag=false) {
359  m_strikeoutline->m_word = wordFlag;
360  }
362  void setStrikeOutWidth(float w) {
363  m_strikeoutline->m_width = w;
364  }
366  void setStrikeOutColor(MWAWColor const &color) {
367  m_strikeoutline->m_color = color;
368  }
369 
371  Line const &getUnderline() const {
372  return m_underline.get();
373  }
375  void setUnderline(Line const &line) {
376  m_underline = line;
377  }
379  void setUnderlineStyle(Line::Style style=Line::None, bool doReset=true) {
380  if (doReset)
381  m_underline = Line(style);
382  else
383  m_underline->m_style = style;
384  }
387  m_underline->m_type = type;
388  }
390  void setUnderlineWordFlag(bool wordFlag=false) {
391  m_underline->m_word = wordFlag;
392  }
394  void setUnderlineWidth(float w) {
395  m_underline->m_width = w;
396  }
398  void setUnderlineColor(MWAWColor const &color) {
399  m_underline->m_color = color;
400  }
401 
403  std::string const &language() const {
404  return m_language.get();
405  }
407  void setLanguage(std::string const &lang) {
408  m_language=lang;
409  }
411  void addTo(WPXPropertyList &propList, shared_ptr<MWAWFontConverter> fontConverter) const;
412 
414  std::string getDebugString(shared_ptr<MWAWFontConverter> &converter) const;
415 
417  bool operator==(MWAWFont const &f) const {
418  return cmp(f) == 0;
419  }
421  bool operator!=(MWAWFont const &f) const {
422  return cmp(f) != 0;
423  }
424 
426  int cmp(MWAWFont const &oth) const {
427  int diff = id() - oth.id();
428  if (diff != 0) return diff;
429  if (size() < oth.size()) return -1;
430  if (size() > oth.size()) return -1;
431  if (flags() < oth.flags()) return -1;
432  if (flags() > oth.flags()) return 1;
433  if (m_deltaSpacing.get() < oth.m_deltaSpacing.get()) return -1;
434  if (m_deltaSpacing.get() > oth.m_deltaSpacing.get()) return 1;
435  if (m_texteWidthScaling.get() < oth.m_texteWidthScaling.get()) return -1;
436  if (m_texteWidthScaling.get() > oth.m_texteWidthScaling.get()) return 1;
437  diff = script().cmp(oth.script());
438  if (diff != 0) return diff;
439  diff = m_overline.get().cmp(oth.m_overline.get());
440  if (diff != 0) return diff;
441  diff = m_strikeoutline.get().cmp(oth.m_strikeoutline.get());
442  if (diff != 0) return diff;
443  diff = m_underline.get().cmp(oth.m_underline.get());
444  if (diff != 0) return diff;
445  if (m_color.get() < oth.m_color.get()) return -1;
446  if (m_color.get() > oth.m_color.get()) return 1;
447  if (m_backgroundColor.get() < oth.m_backgroundColor.get()) return -1;
448  if (m_backgroundColor.get() > oth.m_backgroundColor.get()) return 1;
449  if (m_language.get() < oth.m_language.get()) return -1;
450  if (m_language.get() > oth.m_language.get()) return 1;
451  return diff;
452  }
453 
454 protected:
467 public:
469  std::string m_extra;
470 };
471 
472 
473 #endif
474 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
Definition: MWAWFont.hxx:53
void set(Script const &newscript)
sets the script position
Definition: MWAWFont.hxx:254
void setStrikeOutColor(MWAWColor const &color)
sets the strikeoutline color
Definition: MWAWFont.hxx:366
void setFont(int newId)
sets the font id and resets size to the previous size for this font
Definition: MWAWFont.hxx:209
Script const & script() const
returns the script position
Definition: MWAWFont.hxx:249
Definition: MWAWFont.hxx:171
void setUnderlineType(Line::Type type=Line::Single)
sets the underline type
Definition: MWAWFont.hxx:386
Variable< uint32_t > m_flags
font attributes
Definition: MWAWFont.hxx:460
void setDeltaLetterSpacing(float d)
set the letter spacing ( delta value in point )
Definition: MWAWFont.hxx:237
Definition: MWAWFont.hxx:53
Type
the line style
Definition: MWAWFont.hxx:55
Definition: MWAWFont.hxx:169
void resetColor()
resets the font color to black and the background color to white
Definition: MWAWFont.hxx:289
std::string str(float fSize) const
return a string which correspond to style:text-position
Definition: MWAWFont.cxx:143
int cmp(Script const &oth) const
small comparison function
Definition: MWAWFont.hxx:153
Definition: MWAWFont.hxx:171
bool hasDecorationLines() const
return true if the font has decorations line (overline, strikeout, underline)
Definition: MWAWFont.hxx:295
Definition: MWAWFont.hxx:55
Definition: MWAWFont.hxx:53
Variable< MWAWColor > m_color
the color ( if not set, we use the font color )
Definition: MWAWFont.hxx:97
void insert(Variable const &orig)
update the current value if orig is set
Definition: libmwaw_internal.hxx:339
Variable< Line > m_underline
underline attributes
Definition: MWAWFont.hxx:463
static MWAWColor white()
return the white color
Definition: libmwaw_internal.hxx:179
void addTo(WPXPropertyList &propList, shared_ptr< MWAWFontConverter > fontConverter) const
add to the propList
Definition: MWAWFont.cxx:233
void setStrikeOutStyle(Line::Style style=Line::None, bool doReset=true)
sets the strikeoutline style ( by default, we also reset the style)
Definition: MWAWFont.hxx:347
void setOverlineStyle(Line::Style style=Line::None, bool doReset=true)
sets the overline style ( by default, we also reset the style)
Definition: MWAWFont.hxx:315
bool operator<=(Script const &oth) const
operator&lt;=
Definition: MWAWFont.hxx:141
bool hasColor() const
returns true if the font color is not black
Definition: MWAWFont.hxx:268
std::string m_extra
extra data
Definition: MWAWFont.hxx:469
Type m_type
the type
Definition: MWAWFont.hxx:91
Variable< Script > m_scriptPosition
the sub/super script definition
Definition: MWAWFont.hxx:459
float deltaLetterSpacing() const
returns the condensed(negative)/extended(positive) width
Definition: MWAWFont.hxx:233
FontBits
the different font bit
Definition: MWAWFont.hxx:169
static MWAWColor black()
return the back color
Definition: libmwaw_internal.hxx:175
int id() const
returns the font id
Definition: MWAWFont.hxx:215
bool isSet() const
return true if the variable is set
Definition: libmwaw_internal.hxx:368
Variable< std::string > m_language
the language if set
Definition: MWAWFont.hxx:466
Definition: MWAWFont.hxx:170
Definition: MWAWFont.hxx:169
Definition: MWAWFont.hxx:53
void resetDecorationLines()
reset the decoration
Definition: MWAWFont.hxx:301
void setUnderlineColor(MWAWColor const &color)
sets the underline color
Definition: MWAWFont.hxx:398
bool isSet() const
return true if the line is not empty
Definition: MWAWFont.hxx:60
friend std::ostream & operator<<(std::ostream &o, Line const &line)
operator&lt;&lt;
Definition: MWAWFont.cxx:49
static Script super()
return a yposition which correspond to a basic superscript
Definition: MWAWFont.hxx:118
Definition: MWAWFont.hxx:55
Definition: MWAWFont.hxx:169
Definition: MWAWFont.hxx:173
the class to store a color
Definition: libmwaw_internal.hxx:161
Script(float delta=0, WPXUnit deltaUnit=WPX_PERCENT, int scale=100)
constructor
Definition: MWAWFont.hxx:102
Definition: MWAWFont.hxx:172
Style m_style
the style
Definition: MWAWFont.hxx:89
static Script sub()
return a yposition which correspond to a basic subscript
Definition: MWAWFont.hxx:110
Definition: MWAWFont.hxx:170
void setColor(MWAWColor color)
sets the font color
Definition: MWAWFont.hxx:276
Variable< MWAWColor > m_color
font color
Definition: MWAWFont.hxx:464
bool isSet() const
return true if the position is not default
Definition: MWAWFont.hxx:106
Variable< Line > m_strikeoutline
overline attributes
Definition: MWAWFont.hxx:462
bool operator>=(Script const &oth) const
operator&gt;=
Definition: MWAWFont.hxx:149
Definition: MWAWFont.hxx:169
bool operator==(Line const &oth) const
operator==
Definition: MWAWFont.hxx:68
Style
the line style
Definition: MWAWFont.hxx:53
Definition: MWAWFont.hxx:55
Variable< int > m_id
font identificator
Definition: MWAWFont.hxx:455
void setStrikeOutType(Line::Type type=Line::Single)
sets the strikeoutline type
Definition: MWAWFont.hxx:354
Class to store font.
Definition: MWAWFont.hxx:47
void getColor(MWAWColor &c) const
returns the font color
Definition: MWAWFont.hxx:272
void setUnderline(Line const &line)
sets the underline
Definition: MWAWFont.hxx:375
void setSize(float sz)
sets the font size
Definition: MWAWFont.hxx:228
static Script super100()
return a yposition which correspond to a basic superscript100
Definition: MWAWFont.hxx:122
Variable< float > m_deltaSpacing
expand(&gt;0), condensed(&lt;0) depl in point
Definition: MWAWFont.hxx:457
void setId(int newId)
sets the font id
Definition: MWAWFont.hxx:219
Variable< float > m_texteWidthScaling
the texte width scaling
Definition: MWAWFont.hxx:458
bool operator==(Script const &oth) const
operator==
Definition: MWAWFont.hxx:129
static Script sub100()
return a yposition which correspond to a basic subscript100
Definition: MWAWFont.hxx:114
void setOverline(Line const &line)
sets the overline
Definition: MWAWFont.hxx:311
MWAWFont(int newId=-1, float sz=12, uint32_t f=0)
constructor
Definition: MWAWFont.hxx:180
Line const & getOverline() const
returns the overline
Definition: MWAWFont.hxx:307
int cmp(MWAWFont const &oth) const
a comparison function
Definition: MWAWFont.hxx:426
Definition: MWAWFont.hxx:172
bool operator==(MWAWFont const &f) const
operator==
Definition: MWAWFont.hxx:417
void setUnderlineWidth(float w)
sets the underline width
Definition: MWAWFont.hxx:394
Line(Style style=None, Type type=Single, bool wordFlag=false, float w=1.0)
constructor
Definition: MWAWFont.hxx:57
float m_delta
the ydelta
Definition: MWAWFont.hxx:161
bool operator!=(Line const &oth) const
operator!=
Definition: MWAWFont.hxx:72
int m_scale
the font scaling ( in percent )
Definition: MWAWFont.hxx:165
float m_width
the width in point
Definition: MWAWFont.hxx:95
void setOverlineWidth(float w)
sets the overline width
Definition: MWAWFont.hxx:330
std::string const & language() const
return the language
Definition: MWAWFont.hxx:403
T const & get() const
return the current value
Definition: libmwaw_internal.hxx:364
a namespace used to convert Mac font characters in unicode
Definition: MWAWFontConverter.hxx:66
bool operator!=(MWAWFont const &f) const
operator!=
Definition: MWAWFont.hxx:421
uint32_t flags() const
returns the font flags
Definition: MWAWFont.hxx:259
bool operator!=(Script const &oth) const
operator!=
Definition: MWAWFont.hxx:133
Variable< Line > m_overline
overline attributes
Definition: MWAWFont.hxx:461
WPXUnit m_deltaUnit
the ydelta unit ( point or percent )
Definition: MWAWFont.hxx:163
Definition: MWAWFont.hxx:169
void setOverlineType(Line::Type type=Line::Single)
sets the overline type
Definition: MWAWFont.hxx:322
std::string getDebugString(shared_ptr< MWAWFontConverter > &converter) const
returns a string which can be used for debugging
Definition: MWAWFont.cxx:177
void setOverlineColor(MWAWColor const &color)
sets the overline color
Definition: MWAWFont.hxx:334
int cmp(Line const &oth) const
small comparison function
Definition: MWAWFont.hxx:76
float texteWidthScaling() const
returns the texte width scaling
Definition: MWAWFont.hxx:241
Variable< MWAWColor > m_backgroundColor
font background color
Definition: MWAWFont.hxx:465
bool m_word
word or not word line
Definition: MWAWFont.hxx:93
void setUnderlineWordFlag(bool wordFlag=false)
sets the underline word flag
Definition: MWAWFont.hxx:390
void setStrikeOutWidth(float w)
sets the strikeoutline width
Definition: MWAWFont.hxx:362
a small struct to define a line in MWAWFont
Definition: MWAWFont.hxx:51
void setOverlineWordFlag(bool wordFlag=false)
sets the overline word flag
Definition: MWAWFont.hxx:326
Definition: MWAWFont.hxx:53
bool operator<(Script const &oth) const
operator&lt;
Definition: MWAWFont.hxx:137
void getBackgroundColor(MWAWColor &c) const
returns the font background color
Definition: MWAWFont.hxx:281
Line const & getUnderline() const
returns the underline
Definition: MWAWFont.hxx:371
bool operator>(Script const &oth) const
operator&gt;
Definition: MWAWFont.hxx:145
void setBackgroundColor(MWAWColor color)
sets the font background color
Definition: MWAWFont.hxx:285
void setStrikeOutWordFlag(bool wordFlag=false)
sets the strikeoutline word flag
Definition: MWAWFont.hxx:358
float size() const
returns the font size
Definition: MWAWFont.hxx:224
void setFlags(uint32_t fl)
sets the font attributes bold, ...
Definition: MWAWFont.hxx:263
void setStrikeOut(Line const &line)
sets the strikeoutline
Definition: MWAWFont.hxx:343
Definition: MWAWFont.hxx:53
void setTexteWidthScaling(float scale=1.0)
set the texte width scaling
Definition: MWAWFont.hxx:245
void insert(MWAWFont const &ft)
inserts the set value in the current font
Definition: MWAWFont.hxx:190
Definition: MWAWFont.hxx:172
Variable< float > m_size
font size
Definition: MWAWFont.hxx:456
bool isSet() const
returns true if the font id is initialized
Definition: MWAWFont.hxx:186
Definition: MWAWFont.hxx:171
void setLanguage(std::string const &lang)
set the language ( in the for en_US, en_GB, en, ...)
Definition: MWAWFont.hxx:407
void addTo(WPXPropertyList &propList, std::string const &type) const
add a line to the propList knowing the type (line-through, underline, overline )
Definition: MWAWFont.cxx:92
void setUnderlineStyle(Line::Style style=Line::None, bool doReset=true)
sets the underline style ( by default, we also reset the style)
Definition: MWAWFont.hxx:379
Definition: MWAWFont.hxx:170
Line const & getStrikeOut() const
returns the strikeoutline
Definition: MWAWFont.hxx:339
a small struct to define the script position in MWAWFont
Definition: MWAWFont.hxx:100

Generated for libmwaw by doxygen 1.8.5