Flutter Impeller
text_run.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <vector>
8 
12 
13 namespace impeller {
14 
15 //------------------------------------------------------------------------------
16 /// @brief Represents a collection of positioned glyphs from a specific
17 /// font.
18 ///
19 class TextRun {
20  public:
21  struct GlyphPosition {
24 
25  GlyphPosition(Glyph p_glyph, Point p_position)
26  : glyph(p_glyph), position(p_position) {}
27  };
28 
29  //----------------------------------------------------------------------------
30  /// @brief Create an empty text run with the specified font.
31  ///
32  /// @param[in] font The font
33  ///
34  explicit TextRun(const Font& font);
35 
36  TextRun(const Font& font, std::vector<GlyphPosition>& glyphs);
37 
38  ~TextRun();
39 
40  bool IsValid() const;
41 
42  //----------------------------------------------------------------------------
43  /// @brief Add a glyph at the specified position to the run.
44  ///
45  /// @param[in] glyph The glyph
46  /// @param[in] position The position
47  ///
48  /// @return If the glyph could be added to the run.
49  ///
50  bool AddGlyph(Glyph glyph, Point position);
51 
52  //----------------------------------------------------------------------------
53  /// @brief Get the number of glyphs in the run.
54  ///
55  /// @return The glyph count.
56  ///
57  size_t GetGlyphCount() const;
58 
59  //----------------------------------------------------------------------------
60  /// @brief Get a reference to all the glyph positions within the run.
61  ///
62  /// @return The glyph positions.
63  ///
64  const std::vector<GlyphPosition>& GetGlyphPositions() const;
65 
66  //----------------------------------------------------------------------------
67  /// @brief Get the font for this run.
68  ///
69  /// @return The font.
70  ///
71  const Font& GetFont() const;
72 
73  private:
74  Font font_;
75  std::vector<GlyphPosition> glyphs_;
76  bool is_valid_ = false;
77 };
78 
79 } // namespace impeller
impeller::Font
Describes a typeface along with any modifications to its intrinsic properties.
Definition: font.h:21
impeller::TextRun::GlyphPosition::GlyphPosition
GlyphPosition(Glyph p_glyph, Point p_position)
Definition: text_run.h:25
impeller::TextRun
Represents a collection of positioned glyphs from a specific font.
Definition: text_run.h:19
impeller::TextRun::GetFont
const Font & GetFont() const
Get the font for this run.
Definition: text_run.cc:43
matrix.h
impeller::Glyph
The glyph index in the typeface.
Definition: glyph.h:19
glyph.h
impeller::TextRun::TextRun
TextRun(const Font &font)
Create an empty text run with the specified font.
Definition: text_run.cc:9
font.h
impeller::TextRun::~TextRun
~TextRun()
impeller::TextRun::AddGlyph
bool AddGlyph(Glyph glyph, Point position)
Add a glyph at the specified position to the run.
Definition: text_run.cc:26
impeller::TextRun::GetGlyphCount
size_t GetGlyphCount() const
Get the number of glyphs in the run.
Definition: text_run.cc:39
impeller::TextRun::GlyphPosition::glyph
Glyph glyph
Definition: text_run.h:22
impeller::TPoint< Scalar >
impeller::TextRun::GlyphPosition
Definition: text_run.h:21
impeller::TextRun::IsValid
bool IsValid() const
Definition: text_run.cc:31
impeller::TextRun::GetGlyphPositions
const std::vector< GlyphPosition > & GetGlyphPositions() const
Get a reference to all the glyph positions within the run.
Definition: text_run.cc:35
impeller
Definition: aiks_context.cc:10
impeller::TextRun::GlyphPosition::position
Point position
Definition: text_run.h:23