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 
44 class MWAWFont
45 {
46 public:
48  struct Line {
52  enum Type { Single, Double, Triple };
54  Line(Style style=None, Type type=Single, bool wordFlag=false, float w=1.0) :
55  m_style(style), m_type(type), m_word(wordFlag), m_width(w), m_color(MWAWColor::black()) { }
57  bool isSet() const
58  {
59  return m_style != None && m_width>0;
60  }
62  void addTo(librevenge::RVNGPropertyList &propList, std::string const &type) const;
64  friend std::ostream &operator<<(std::ostream &o, Line const &line);
66  bool operator==(Line const &oth) const
67  {
68  return cmp(oth)==0;
69  }
71  bool operator!=(Line const &oth) const
72  {
73  return cmp(oth)!=0;
74  }
76  int cmp(Line const &oth) const
77  {
78  if (m_style != oth.m_style) return int(m_style)-int(oth.m_style);
79  if (m_type != oth.m_type) return int(m_type)-int(oth.m_type);
80  if (m_word != oth.m_word) return m_word ? -1 : 1;
81  if (m_width < oth.m_width) return -1;
82  if (m_width > oth.m_width) return 1;
83  if (m_color.isSet() != oth.m_color.isSet())
84  return m_color.isSet();
85  if (m_color.get() < oth.m_color.get()) return -1;
86  if (m_color.get() > oth.m_color.get()) return 1;
87  return 0;
88  }
94  bool m_word;
96  float m_width;
99  };
101  struct Script {
103  Script(float delta=0, librevenge::RVNGUnit deltaUnit=librevenge::RVNG_PERCENT, int scale=100) :
104  m_delta(delta), m_deltaUnit(deltaUnit), m_scale(scale)
105  {
106  }
108  bool isSet() const
109  {
110  return *this != Script();
111  }
113  static Script sub()
114  {
115  return Script(-33,librevenge::RVNG_PERCENT,58);
116  }
118  static Script sub100()
119  {
120  return Script(-20);
121  }
123  static Script super()
124  {
125  return Script(33,librevenge::RVNG_PERCENT,58);
126  }
128  static Script super100()
129  {
130  return Script(20);
131  }
133  std::string str(float fSize) const;
134 
136  bool operator==(Script const &oth) const
137  {
138  return cmp(oth)==0;
139  }
141  bool operator!=(Script const &oth) const
142  {
143  return cmp(oth)!=0;
144  }
146  bool operator<(Script const &oth) const
147  {
148  return cmp(oth)<0;
149  }
151  bool operator<=(Script const &oth) const
152  {
153  return cmp(oth)<=0;
154  }
156  bool operator>(Script const &oth) const
157  {
158  return cmp(oth)>0;
159  }
161  bool operator>=(Script const &oth) const
162  {
163  return cmp(oth)>=0;
164  }
166  int cmp(Script const &oth) const
167  {
168  if (m_delta > oth.m_delta) return -1;
169  if (m_delta < oth.m_delta) return 1;
170  if (m_deltaUnit != oth.m_deltaUnit) return int(m_deltaUnit)-int(oth.m_deltaUnit);
171  if (m_scale != oth.m_scale) return m_scale-oth.m_scale;
172  return 0;
173  }
175  float m_delta;
177  librevenge::RVNGUnit m_deltaUnit;
179  int m_scale;
180  };
181 
184  hiddenBit=0x20, outlineBit=0x40, shadowBit=0x80,
186  lowercaseBit=0x800, boxedBit=0x1000, boxedRoundedBit=0x2000,
188  };
194  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(),
195  m_flags(f), m_overline(Line::None), m_strikeoutline(Line::None), m_underline(Line::None),
196  m_color(MWAWColor::black()), m_backgroundColor(MWAWColor::white()), m_language(""), m_extra("")
197  {
198  resetColor();
199  };
201  bool isSet() const
202  {
203  return m_id.isSet();
204  }
206  void insert(MWAWFont const &ft)
207  {
208  m_id.insert(ft.m_id);
209  m_size.insert(ft.m_size);
213  if (ft.m_flags.isSet()) {
214  if (m_flags.isSet())
215  setFlags(flags()| ft.flags());
216  else
217  m_flags = ft.m_flags;
218  }
219  m_overline.insert(ft.m_overline);
220  m_strikeoutline.insert(ft.m_strikeoutline);
221  m_underline.insert(ft.m_underline);
222  m_color.insert(ft.m_color);
223  m_extra += ft.m_extra;
224  }
226  void setFont(int newId)
227  {
228  resetColor();
229  m_id=newId;
230  }
231 
233  int id() const
234  {
235  return m_id.get();
236  }
238  void setId(int newId)
239  {
240  m_id = newId;
241  }
242 
244  float size() const
245  {
246  return m_size.get();
247  }
249  void setSize(float sz)
250  {
251  m_size = sz;
252  }
253 
255  float deltaLetterSpacing() const
256  {
257  return m_deltaSpacing.get();
258  }
260  void setDeltaLetterSpacing(float d)
261  {
262  m_deltaSpacing=d;
263  }
265  float texteWidthScaling() const
266  {
267  return m_texteWidthScaling.get();
268  }
270  void setTexteWidthScaling(float scale=1.0)
271  {
272  m_texteWidthScaling = scale;
273  }
275  Script const &script() const
276  {
277  return m_scriptPosition.get();
278  }
279 
281  void set(Script const &newscript)
282  {
283  m_scriptPosition = newscript;
284  }
285 
287  uint32_t flags() const
288  {
289  return m_flags.get();
290  }
292  void setFlags(uint32_t fl)
293  {
294  m_flags = fl;
295  }
296 
298  bool hasColor() const
299  {
300  return m_color.isSet() && !m_color.get().isBlack();
301  }
303  void getColor(MWAWColor &c) const
304  {
305  c = m_color.get();
306  }
308  void setColor(MWAWColor color)
309  {
310  m_color = color;
311  }
312 
315  {
316  c = m_backgroundColor.get();
317  }
320  {
321  m_backgroundColor = color;
322  }
324  void resetColor()
325  {
328  }
329 
331  bool hasDecorationLines() const
332  {
333  return (m_overline.isSet() && m_overline->isSet()) ||
334  (m_strikeoutline.isSet() && m_strikeoutline->isSet()) ||
335  (m_underline.isSet() && m_underline->isSet());
336  }
339  {
340  if (m_overline.isSet()) m_overline=Line(Line::None);
342  if (m_underline.isSet()) m_underline=Line(Line::None);
343  }
345  Line const &getOverline() const
346  {
347  return m_overline.get();
348  }
350  void setOverline(Line const &line)
351  {
352  m_overline = line;
353  }
355  void setOverlineStyle(Line::Style style=Line::None, bool doReset=true)
356  {
357  if (doReset)
358  m_overline = Line(style);
359  else
360  m_overline->m_style = style;
361  }
364  {
365  m_overline->m_type = type;
366  }
368  void setOverlineWordFlag(bool wordFlag=false)
369  {
370  m_overline->m_word = wordFlag;
371  }
373  void setOverlineWidth(float w)
374  {
375  m_overline->m_width = w;
376  }
378  void setOverlineColor(MWAWColor const &color)
379  {
380  m_overline->m_color = color;
381  }
382 
384  Line const &getStrikeOut() const
385  {
386  return m_strikeoutline.get();
387  }
389  void setStrikeOut(Line const &line)
390  {
391  m_strikeoutline = line;
392  }
394  void setStrikeOutStyle(Line::Style style=Line::None, bool doReset=true)
395  {
396  if (doReset)
397  m_strikeoutline = Line(style);
398  else
399  m_strikeoutline->m_style = style;
400  }
403  {
404  m_strikeoutline->m_type = type;
405  }
407  void setStrikeOutWordFlag(bool wordFlag=false)
408  {
409  m_strikeoutline->m_word = wordFlag;
410  }
412  void setStrikeOutWidth(float w)
413  {
414  m_strikeoutline->m_width = w;
415  }
417  void setStrikeOutColor(MWAWColor const &color)
418  {
419  m_strikeoutline->m_color = color;
420  }
421 
423  Line const &getUnderline() const
424  {
425  return m_underline.get();
426  }
428  void setUnderline(Line const &line)
429  {
430  m_underline = line;
431  }
433  void setUnderlineStyle(Line::Style style=Line::None, bool doReset=true)
434  {
435  if (doReset)
436  m_underline = Line(style);
437  else
438  m_underline->m_style = style;
439  }
442  {
443  m_underline->m_type = type;
444  }
446  void setUnderlineWordFlag(bool wordFlag=false)
447  {
448  m_underline->m_word = wordFlag;
449  }
451  void setUnderlineWidth(float w)
452  {
453  m_underline->m_width = w;
454  }
456  void setUnderlineColor(MWAWColor const &color)
457  {
458  m_underline->m_color = color;
459  }
460 
462  std::string const &language() const
463  {
464  return m_language.get();
465  }
467  void setLanguage(std::string const &lang)
468  {
469  m_language=lang;
470  }
472  void addTo(librevenge::RVNGPropertyList &propList, shared_ptr<MWAWFontConverter> fontConverter) const;
473 
475  std::string getDebugString(shared_ptr<MWAWFontConverter> &converter) const;
476 
478  bool operator==(MWAWFont const &f) const
479  {
480  return cmp(f) == 0;
481  }
483  bool operator!=(MWAWFont const &f) const
484  {
485  return cmp(f) != 0;
486  }
487 
489  int cmp(MWAWFont const &oth) const
490  {
491  int diff = id() - oth.id();
492  if (diff != 0) return diff;
493  if (size() < oth.size()) return -1;
494  if (size() > oth.size()) return -1;
495  if (flags() < oth.flags()) return -1;
496  if (flags() > oth.flags()) return 1;
497  if (m_deltaSpacing.get() < oth.m_deltaSpacing.get()) return -1;
498  if (m_deltaSpacing.get() > oth.m_deltaSpacing.get()) return 1;
499  if (m_texteWidthScaling.get() < oth.m_texteWidthScaling.get()) return -1;
500  if (m_texteWidthScaling.get() > oth.m_texteWidthScaling.get()) return 1;
501  diff = script().cmp(oth.script());
502  if (diff != 0) return diff;
503  diff = m_overline.get().cmp(oth.m_overline.get());
504  if (diff != 0) return diff;
505  diff = m_strikeoutline.get().cmp(oth.m_strikeoutline.get());
506  if (diff != 0) return diff;
507  diff = m_underline.get().cmp(oth.m_underline.get());
508  if (diff != 0) return diff;
509  if (m_color.get() < oth.m_color.get()) return -1;
510  if (m_color.get() > oth.m_color.get()) return 1;
511  if (m_backgroundColor.get() < oth.m_backgroundColor.get()) return -1;
512  if (m_backgroundColor.get() > oth.m_backgroundColor.get()) return 1;
513  if (m_language.get() < oth.m_language.get()) return -1;
514  if (m_language.get() > oth.m_language.get()) return 1;
515  return diff;
516  }
517 
518 protected:
531 public:
533  std::string m_extra;
534 };
535 
536 
537 #endif
538 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
Definition: MWAWFont.hxx:50
void set(Script const &newscript)
sets the script position
Definition: MWAWFont.hxx:281
void setStrikeOutColor(MWAWColor const &color)
sets the strikeoutline color
Definition: MWAWFont.hxx:417
MWAWVariable< MWAWColor > m_color
font color
Definition: MWAWFont.hxx:528
void setFont(int newId)
sets the font id and resets size to the previous size for this font
Definition: MWAWFont.hxx:226
Script const & script() const
returns the script position
Definition: MWAWFont.hxx:275
Definition: MWAWFont.hxx:185
void setUnderlineType(Line::Type type=Line::Single)
sets the underline type
Definition: MWAWFont.hxx:441
void setDeltaLetterSpacing(float d)
sets the letter spacing ( delta value in point )
Definition: MWAWFont.hxx:260
Definition: MWAWFont.hxx:50
Type
the line style
Definition: MWAWFont.hxx:52
MWAWVariable< MWAWColor > m_color
the color ( if not set, we use the font color )
Definition: MWAWFont.hxx:98
Definition: MWAWFont.hxx:183
void resetColor()
resets the font color to black and the background color to white
Definition: MWAWFont.hxx:324
std::string str(float fSize) const
return a string which correspond to style:text-position
Definition: MWAWFont.cxx:141
int cmp(Script const &oth) const
small comparison function
Definition: MWAWFont.hxx:166
Definition: MWAWFont.hxx:185
bool hasDecorationLines() const
return true if the font has decorations line (overline, strikeout, underline)
Definition: MWAWFont.hxx:331
Definition: MWAWFont.hxx:52
Definition: MWAWFont.hxx:50
static MWAWColor white()
return the white color
Definition: libmwaw_internal.hxx:226
void setStrikeOutStyle(Line::Style style=Line::None, bool doReset=true)
sets the strikeoutline style ( by default, we also reset the style)
Definition: MWAWFont.hxx:394
void setOverlineStyle(Line::Style style=Line::None, bool doReset=true)
sets the overline style ( by default, we also reset the style)
Definition: MWAWFont.hxx:355
void addTo(librevenge::RVNGPropertyList &propList, shared_ptr< MWAWFontConverter > fontConverter) const
add to the propList
Definition: MWAWFont.cxx:230
bool operator<=(Script const &oth) const
operator<=
Definition: MWAWFont.hxx:151
bool hasColor() const
returns true if the font color is not black
Definition: MWAWFont.hxx:298
MWAWVariable< Line > m_overline
overline attributes
Definition: MWAWFont.hxx:525
std::string m_extra
extra data
Definition: MWAWFont.hxx:533
Type m_type
the type
Definition: MWAWFont.hxx:92
float deltaLetterSpacing() const
returns the condensed(negative)/extended(positive) width
Definition: MWAWFont.hxx:255
FontBits
the different font bit
Definition: MWAWFont.hxx:183
T const & get() const
return the current value
Definition: libmwaw_internal.hxx:517
static MWAWColor black()
return the back color
Definition: libmwaw_internal.hxx:221
int id() const
returns the font id
Definition: MWAWFont.hxx:233
void insert(MWAWVariable const &orig)
update the current value if orig is set
Definition: libmwaw_internal.hxx:487
Definition: MWAWFont.hxx:184
Definition: MWAWFont.hxx:183
Definition: MWAWFont.hxx:50
void resetDecorationLines()
reset the decoration
Definition: MWAWFont.hxx:338
void setUnderlineColor(MWAWColor const &color)
sets the underline color
Definition: MWAWFont.hxx:456
bool isSet() const
return true if the line is not empty
Definition: MWAWFont.hxx:57
friend std::ostream & operator<<(std::ostream &o, Line const &line)
operator<<
Definition: MWAWFont.cxx:48
static Script super()
return a yposition which correspond to a basic superscript
Definition: MWAWFont.hxx:123
Definition: MWAWFont.hxx:52
Definition: MWAWFont.hxx:183
Definition: MWAWFont.hxx:187
the class to store a color
Definition: libmwaw_internal.hxx:177
Definition: MWAWFont.hxx:186
Style m_style
the style
Definition: MWAWFont.hxx:90
static Script sub()
return a yposition which correspond to a basic subscript
Definition: MWAWFont.hxx:113
Definition: MWAWFont.hxx:184
void setColor(MWAWColor color)
sets the font color
Definition: MWAWFont.hxx:308
bool isSet() const
return true if the position is not default
Definition: MWAWFont.hxx:108
bool operator>=(Script const &oth) const
operator>=
Definition: MWAWFont.hxx:161
Definition: MWAWFont.hxx:183
bool operator==(Line const &oth) const
operator==
Definition: MWAWFont.hxx:66
Style
the line style
Definition: MWAWFont.hxx:50
Definition: MWAWFont.hxx:52
void setStrikeOutType(Line::Type type=Line::Single)
sets the strikeoutline type
Definition: MWAWFont.hxx:402
Class to store font.
Definition: MWAWFont.hxx:44
void getColor(MWAWColor &c) const
returns the font color
Definition: MWAWFont.hxx:303
void setUnderline(Line const &line)
sets the underline
Definition: MWAWFont.hxx:428
void setSize(float sz)
sets the font size
Definition: MWAWFont.hxx:249
static Script super100()
return a yposition which correspond to a basic superscript100
Definition: MWAWFont.hxx:128
MWAWVariable< std::string > m_language
the language if set
Definition: MWAWFont.hxx:530
void setId(int newId)
sets the font id
Definition: MWAWFont.hxx:238
bool operator==(Script const &oth) const
operator==
Definition: MWAWFont.hxx:136
static Script sub100()
return a yposition which correspond to a basic subscript100
Definition: MWAWFont.hxx:118
void setOverline(Line const &line)
sets the overline
Definition: MWAWFont.hxx:350
MWAWFont(int newId=-1, float sz=12, uint32_t f=0)
constructor
Definition: MWAWFont.hxx:194
MWAWVariable< float > m_deltaSpacing
expand(> 0), condensed(< 0) depl in point
Definition: MWAWFont.hxx:521
Line const & getOverline() const
returns the overline
Definition: MWAWFont.hxx:345
int cmp(MWAWFont const &oth) const
a comparison function
Definition: MWAWFont.hxx:489
MWAWVariable< int > m_id
font identificator
Definition: MWAWFont.hxx:519
MWAWVariable< Line > m_strikeoutline
overline attributes
Definition: MWAWFont.hxx:526
MWAWVariable< Line > m_underline
underline attributes
Definition: MWAWFont.hxx:527
Definition: MWAWFont.hxx:186
bool operator==(MWAWFont const &f) const
operator==
Definition: MWAWFont.hxx:478
void setUnderlineWidth(float w)
sets the underline width
Definition: MWAWFont.hxx:451
Line(Style style=None, Type type=Single, bool wordFlag=false, float w=1.0)
constructor
Definition: MWAWFont.hxx:54
float m_delta
the ydelta
Definition: MWAWFont.hxx:175
MWAWVariable< MWAWColor > m_backgroundColor
font background color
Definition: MWAWFont.hxx:529
bool operator!=(Line const &oth) const
operator!=
Definition: MWAWFont.hxx:71
int m_scale
the font scaling ( in percent )
Definition: MWAWFont.hxx:179
float m_width
the width in point
Definition: MWAWFont.hxx:96
void setOverlineWidth(float w)
sets the overline width
Definition: MWAWFont.hxx:373
std::string const & language() const
returns the language
Definition: MWAWFont.hxx:462
bool operator!=(MWAWFont const &f) const
operator!=
Definition: MWAWFont.hxx:483
uint32_t flags() const
returns the font flags
Definition: MWAWFont.hxx:287
MWAWVariable< Script > m_scriptPosition
the sub/super script definition
Definition: MWAWFont.hxx:523
bool operator!=(Script const &oth) const
operator!=
Definition: MWAWFont.hxx:141
MWAWVariable< float > m_size
font size
Definition: MWAWFont.hxx:520
Definition: MWAWFont.hxx:183
void setOverlineType(Line::Type type=Line::Single)
sets the overline type
Definition: MWAWFont.hxx:363
std::string getDebugString(shared_ptr< MWAWFontConverter > &converter) const
returns a string which can be used for debugging
Definition: MWAWFont.cxx:174
void setOverlineColor(MWAWColor const &color)
sets the overline color
Definition: MWAWFont.hxx:378
int cmp(Line const &oth) const
small comparison function
Definition: MWAWFont.hxx:76
float texteWidthScaling() const
returns the text width scaling
Definition: MWAWFont.hxx:265
bool m_word
word or not word line
Definition: MWAWFont.hxx:94
void setUnderlineWordFlag(bool wordFlag=false)
sets the underline word flag
Definition: MWAWFont.hxx:446
void setStrikeOutWidth(float w)
sets the strikeoutline width
Definition: MWAWFont.hxx:412
MWAWVariable< float > m_texteWidthScaling
the texte width scaling
Definition: MWAWFont.hxx:522
a small struct to define a line in MWAWFont
Definition: MWAWFont.hxx:48
Script(float delta=0, librevenge::RVNGUnit deltaUnit=librevenge::RVNG_PERCENT, int scale=100)
constructor
Definition: MWAWFont.hxx:103
void setOverlineWordFlag(bool wordFlag=false)
sets the overline word flag
Definition: MWAWFont.hxx:368
Definition: MWAWFont.hxx:50
bool operator<(Script const &oth) const
operator<
Definition: MWAWFont.hxx:146
void getBackgroundColor(MWAWColor &c) const
returns the font background color
Definition: MWAWFont.hxx:314
Line const & getUnderline() const
returns the underline
Definition: MWAWFont.hxx:423
bool operator>(Script const &oth) const
operator>
Definition: MWAWFont.hxx:156
void setBackgroundColor(MWAWColor color)
sets the font background color
Definition: MWAWFont.hxx:319
librevenge::RVNGUnit m_deltaUnit
the ydelta unit ( point or percent )
Definition: MWAWFont.hxx:177
void setStrikeOutWordFlag(bool wordFlag=false)
sets the strikeoutline word flag
Definition: MWAWFont.hxx:407
float size() const
returns the font size
Definition: MWAWFont.hxx:244
void setFlags(uint32_t fl)
sets the font attributes bold, ...
Definition: MWAWFont.hxx:292
void setStrikeOut(Line const &line)
sets the strikeoutline
Definition: MWAWFont.hxx:389
Definition: MWAWFont.hxx:50
bool isSet() const
return true if the variable is set
Definition: libmwaw_internal.hxx:522
MWAWVariable< uint32_t > m_flags
font attributes
Definition: MWAWFont.hxx:524
void setTexteWidthScaling(float scale=1.0)
sets the text width scaling
Definition: MWAWFont.hxx:270
void insert(MWAWFont const &ft)
inserts the set value in the current font
Definition: MWAWFont.hxx:206
Definition: MWAWFont.hxx:186
bool isSet() const
returns true if the font id is initialized
Definition: MWAWFont.hxx:201
Definition: MWAWFont.hxx:185
void setLanguage(std::string const &lang)
set the language ( in the for en_US, en_GB, en, ...)
Definition: MWAWFont.hxx:467
void setUnderlineStyle(Line::Style style=Line::None, bool doReset=true)
sets the underline style ( by default, we also reset the style)
Definition: MWAWFont.hxx:433
void addTo(librevenge::RVNGPropertyList &propList, std::string const &type) const
add a line to the propList knowing the type (line-through, underline, overline )
Definition: MWAWFont.cxx:91
Definition: MWAWFont.hxx:184
Line const & getStrikeOut() const
returns the strikeoutline
Definition: MWAWFont.hxx:384
a small struct to define the script position in MWAWFont
Definition: MWAWFont.hxx:101

Generated on Thu Jul 9 2015 20:26:36 for libmwaw by doxygen 1.8.8