| 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 #ifndef FLUTTER_IMPELLER_TYPOGRAPHER_TEXT_RUN_H_
6 #define FLUTTER_IMPELLER_TYPOGRAPHER_TEXT_RUN_H_
7
8 #include <vector>
9
10 #include "impeller/geometry/point.h"
11 #include "impeller/typographer/font.h"
12 #include "impeller/typographer/glyph.h"
13
14 namespace impeller {
15
16 //------------------------------------------------------------------------------
17 /// @brief Represents a collection of positioned glyphs from a specific
18 /// font.
19 ///
20 class TextRun {
21 public:
22 struct GlyphPosition {
23 Glyph glyph;
24 Point position;
25
26 GlyphPosition(Glyph p_glyph, Point p_position)
27 : glyph(p_glyph), position(p_position) {}
28 };
29
30 //----------------------------------------------------------------------------
31 /// @brief Create an empty text run with the specified font.
32 ///
33 /// @param[in] font The font
34 ///
35 explicit TextRun(const Font& font);
36
37 TextRun(const Font& font, std::vector<GlyphPosition>& glyphs);
38
39 ~TextRun();
40
41 bool IsValid() const;
42
43 //----------------------------------------------------------------------------
44 /// @brief Add a glyph at the specified position to the run.
45 ///
46 /// @param[in] glyph The glyph
47 /// @param[in] position The position
48 ///
49 /// @return If the glyph could be added to the run.
50 ///
51 bool AddGlyph(Glyph glyph, Point position);
52
53 //----------------------------------------------------------------------------
54 /// @brief Get the number of glyphs in the run.
55 ///
56 /// @return The glyph count.
57 ///
58 size_t GetGlyphCount() const;
59
60 //----------------------------------------------------------------------------
61 /// @brief Get a reference to all the glyph positions within the run.
62 ///
63 /// @return The glyph positions.
64 ///
65 const std::vector<GlyphPosition>& GetGlyphPositions() const;
66
67 //----------------------------------------------------------------------------
68 /// @brief Get the font for this run.
69 ///
70 /// @return The font.
71 ///
72 const Font& GetFont() const;
73
74 private:
75 Font font_;
76 std::vector<GlyphPosition> glyphs_;
77 bool is_valid_ = false;
78 };
79
80 } // namespace impeller
81
82 #endif // FLUTTER_IMPELLER_TYPOGRAPHER_TEXT_RUN_H_
impeller::Font
Describes a typeface along with any modifications to its intrinsic properties.
Definition: font.h:35
impeller::TextRun
Represents a collection of positioned glyphs from a specific font.
Definition: text_run.h:20
impeller::TextRun::~TextRun
~TextRun()
impeller::TextRun::GetGlyphCount
size_t GetGlyphCount() const
Get the number of glyphs in the run.
Definition: text_run.cc:39
impeller::TextRun::IsValid
bool IsValid() const
Definition: text_run.cc:31
impeller::TextRun::GetFont
const Font & GetFont() const
Get the font for this run.
Definition: text_run.cc:43
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::TextRun
TextRun(const Font &font)
Create an empty text run with the specified font.
Definition: text_run.cc:9
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
font.h
glyph.h
impeller
Definition: allocation.cc:12
point.h
impeller::Glyph
The glyph index in the typeface.
Definition: glyph.h:16
impeller::TPoint< Scalar >
impeller::TextRun::GlyphPosition
Definition: text_run.h:22
impeller::TextRun::GlyphPosition::position
Point position
Definition: text_run.h:24
impeller::TextRun::GlyphPosition::glyph
Glyph glyph
Definition: text_run.h:23
impeller::TextRun::GlyphPosition::GlyphPosition
GlyphPosition(Glyph p_glyph, Point p_position)
Definition: text_run.h:26