blip  0.1
Font.hpp
Go to the documentation of this file.
1 #ifndef __blip_Font_hpp
2 #define __blip_Font_hpp
3 
4 #include <blip/Blip.hpp>
5 #include <blip/Size.hpp>
6 
7 #include <commonc++/DynamicCache.h++>
8 #include <commonc++/ScopedPtr.h++>
9 
10 struct FT_FaceRec_;
11 struct FT_GlyphSlotRec_;
12 struct FT_StreamRec_;
13 
14 namespace blip {
15 
16 class Font;
17 class FontManager;
18 class Pixmap;
19 
24 class FontGlyph
25 {
26  friend class Font;
27 
28  public:
29 
31  ~FontGlyph();
32 
36  inline const Pixmap& getPixmap() const
37  { return(*_pixmap); }
38 
40  inline int getAdvance() const
41  { return(_advance); }
42 
44  inline int getLeft() const
45  { return(_left); }
46 
48  inline int getTop() const
49  { return(_top); }
50 
52  int getAscent() const;
53 
55  int getDescent() const;
56 
57  private:
58 
59  FontGlyph(FT_GlyphSlotRec_* glyph);
60 
61  ccxx::ScopedPtr<Pixmap> _pixmap;
62  int _advance;
63  int _left;
64  int _top;
65 
66  CCXX_COPY_DECLS(FontGlyph);
67 };
68 
74 class Font
75 {
76  friend class FontManager;
77 
78  public:
79 
81  ~Font();
82 
84  static const int PLAIN;
85 
87  static const int BOLD;
88 
90  static const int ITALIC;
91 
93  const char* getName() const;
94 
96  inline int getSize() const
97  { return(_size); }
98 
101  int getStyle() const;
102 
104  bool isBold() const;
105 
107  bool isItalic() const;
108 
110  int getGlyphCount() const;
111 
118  const FontGlyph* getGlyph(char16_t c) const;
119 
126  inline const FontGlyph* getGlyph(char c) const
127  { return(getGlyph(static_cast<char16_t>(c))); }
128 
135  inline const FontGlyph* getGlyph(int c) const
136  { return(getGlyph(static_cast<char16_t>(c & 0xFFFF))); }
137 
139  inline int getAscent() const
140  { return(_ascent); }
141 
143  inline int getDescent() const
144  { return(_descent); }
145 
147  inline int getHeight() const
148  { return(_height); }
149 
151  inline int getMaxAdvance() const
152  { return(_maxAdvance); }
153 
155  const Size& getBoundingBox() const
156  { return(_boundingBox); }
157 
158  private:
159 
160  Font(FT_FaceRec_* face, FT_StreamRec_* stream, int size,
161  uint_t glyphCacheSize);
162 
163  FT_FaceRec_* _face;
164  FT_StreamRec_* _stream;
165  int _size;
166  int _ascent;
167  int _descent;
168  int _height;
169  int _maxAdvance;
170  mutable ccxx::DynamicCache<char16_t, FontGlyph> _cache;
171  Size _boundingBox;
172 
173  CCXX_COPY_DECLS(Font);
174 };
175 
176 } // namespace blip
177 
178 #endif // __blip_Font_hpp
const Pixmap & getPixmap() const
Get the Pixmap which contains the glyph, rendered as an 8-bit alpha image.
Definition: Font.hpp:36
static const int ITALIC
Style constant indicating italic font.
Definition: Font.hpp:90
int getHeight() const
Get the font&#39;s height, in pixels.
Definition: Font.hpp:147
int getAdvance() const
Get the glyph&#39;s advance, in pixels.
Definition: Font.hpp:40
A rectangular size that has a width and a height.
Definition: Size.hpp:13
int getMaxAdvance() const
Get the font&#39;s maximum advance, in pixels.
Definition: Font.hpp:151
A class for loading and caching TrueType fonts.
Definition: FontManager.hpp:25
A TrueType font.
Definition: Font.hpp:74
int getDescent() const
Get the font&#39;s descent, in pixels.
Definition: Font.hpp:143
static const int BOLD
Style constant indicating bold font.
Definition: Font.hpp:87
int getLeft() const
Get the glyph&#39;s left bearing, in pixels.
Definition: Font.hpp:44
WAV file format details at: https://ccrma.stanford.edu/courses/422/projects/WaveFormat/.
Definition: AccelerometerSensorEvent.cpp:3
const FontGlyph * getGlyph(int c) const
Get the glyph for the given Unicode character.
Definition: Font.hpp:135
~FontGlyph()
Destructor.
Definition: Font.cpp:41
const Size & getBoundingBox() const
Get the font&#39;s global (maximum) glyph bounding box, in pixels.
Definition: Font.hpp:155
const FontGlyph * getGlyph(char c) const
Get the glyph for the given ASCII character.
Definition: Font.hpp:126
int getAscent() const
Get the glyph&#39;s ascent, in pixels.
Definition: Font.cpp:48
A TrueType font character glyph.
Definition: Font.hpp:24
friend class Font
Definition: Font.hpp:26
int getSize() const
Get the font point size.
Definition: Font.hpp:96
A buffer for two-dimensional pixel data, stored in inverted row order (bottom row first...
Definition: Pixmap.hpp:58
static const int PLAIN
Style constant indicating plain font.
Definition: Font.hpp:84
int getAscent() const
Get the font&#39;s ascent, in pixels.
Definition: Font.hpp:139
int getTop() const
Get the glyph&#39;s top bearing, in pixels.
Definition: Font.hpp:48
int getDescent() const
Get the glyph&#39;s descent, in pixels.
Definition: Font.cpp:56