Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
freetypefont.h
Go to the documentation of this file.
1 
18 #ifndef ION_TEXT_FREETYPEFONT_H_
19 #define ION_TEXT_FREETYPEFONT_H_
20 
21 #include <memory>
22 #include <string>
23 
24 #include "ion/math/vector.h"
25 #include "ion/text/font.h"
26 
27 #if defined(ION_USE_ICU)
28 #include "third_party/iculx_hb/include/layout/ParagraphLayout.h"
29 #endif // ION_USE_ICU
30 
31 namespace ion {
32 namespace text {
33 
35 class ION_API FreeTypeFont : public Font {
36  public:
40  struct GlyphMetrics {
43  : size(0.f, 0.f), bitmap_offset(0.f, 0.f), advance(0.f, 0.f) {}
44 
46  bool IsZeroSize() const { return size[0] == 0.0f || size[1] == 0.0f; }
47 
49  math::Vector2f size;
50 
54  math::Vector2f bitmap_offset;
55 
57  math::Vector2f advance;
58  };
59 
64  FreeTypeFont(const std::string& name, size_t size_in_pixels,
65  size_t sdf_padding, const void* data, size_t data_size);
66 
69  const GlyphMetrics& GetGlyphMetrics(GlyphIndex glyph_index) const;
70 
73  const math::Vector2f GetKerning(CharIndex char_index0,
74  CharIndex char_index1) const;
75 
76 #if defined(ION_USE_ICU)
77  void GetFontRunsForText(icu::UnicodeString chars,
80  iculx::FontRuns* runs) const;
81  GlyphIndex GlyphIndexForICUFont(const icu::LEFontInstance* icu_font,
82  int32 glyph_id) const;
83 #endif // ION_USE_ICU
84 
86  GlyphIndex GetDefaultGlyphForChar(CharIndex char_index) const override;
87  const Layout BuildLayout(const std::string& text,
88  const LayoutOptions& options) const override;
89  void AddFallbackFont(const FontPtr& fallback) override;
90 
91  protected:
95  FreeTypeFont(const std::string& name, size_t size_in_pixels,
96  size_t sdf_padding);
97 
100  ~FreeTypeFont() override;
101 
103  bool LoadGlyphGrid(GlyphIndex glyph_index,
104  GlyphGrid* glyph_grid) const override;
105 
106  private:
108  class Helper;
109  std::shared_ptr<Helper> helper_;
110 };
111 
114 
115 } // namespace text
116 } // namespace ion
117 
118 #endif // ION_TEXT_FREETYPEFONT_H_
math::Vector2f size
Width and height of the glyph, in pixels.
Definition: freetypefont.h:49
This derived Font class represents a FreeType2 font.
Definition: freetypefont.h:35
std::string text
bool IsZeroSize() const
Returns true if glyph x- or y-size is zero.
Definition: freetypefont.h:46
uint32 CharIndex
Typedef for a Unicode index of a character.
Definition: font.h:35
This struct defines parameters affecting layout of a single text string when passed to BuildLayout()...
Definition: layout.h:101
base::ReferentPtr< FreeTypeFont >::Type FreeTypeFontPtr
Convenience typedef for shared pointer to a FreeTypeFont.
Definition: freetypefont.h:113
math::Vector2f advance
Number of pixels to advance in X and Y to draw the next glyph after this.
Definition: freetypefont.h:57
std::string name
Definition: printer.cc:324
GlyphMetrics()
The default constructor initializes everything to 0.
Definition: freetypefont.h:42
A Layout instance specifies how glyphs are arranged to form text.
Definition: layout.h:127
math::Vector2f bitmap_offset
Distance in X and Y from the baseline to the top left pixel of the glyph bitmap, in pixels...
Definition: freetypefont.h:54
This struct represents the metrics for a single glyph.
Definition: freetypefont.h:40
A grid representing a rendered glyph, with each grid pixel representing pixel coverage in the range (...
Definition: font.h:48
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
Definition: sharedptr.h:60
Font is a base class for implementation-specific representations of fonts.
Definition: font.h:43