Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
layout.cc
Go to the documentation of this file.
1 
18 #include "ion/text/layout.h"
19 
20 namespace ion {
21 namespace text {
22 
23 bool Layout::AddGlyph(const Glyph& glyph) {
24  if (glyph.glyph_index) {
25  glyphs_.push_back(glyph);
26  return true;
27  }
28  return false;
29 }
30 
31 size_t Layout::GetGlyphCount() const { return glyphs_.size(); }
32 
33 void Layout::Reserve(size_t s) { glyphs_.reserve(s); }
34 
35 const Layout::Glyph& Layout::GetGlyph(size_t i) const {
36  return i < glyphs_.size() ? glyphs_[i] : base::InvalidReference<Glyph>();
37 }
38 
39 bool Layout::ReplaceGlyph(size_t i, const Glyph& new_glyph) {
40  if (i < glyphs_.size() && new_glyph.glyph_index) {
41  glyphs_[i] = new_glyph;
42  return true;
43  }
44  return false;
45 }
46 
47 void Layout::GetGlyphSet(GlyphSet* glyphs) const {
48  for (size_t i = 0; i < glyphs_.size(); ++i)
49  glyphs->insert(glyphs_[i].glyph_index);
50 }
51 
53  return line_advance_height_;
54 }
55 
56 void Layout::SetLineAdvanceHeight(float line_advance) {
57  line_advance_height_ = line_advance;
58 }
59 
61 std::ostream& operator<<(std::ostream& out, const Layout::Quad& q) {
62  return out << "QUAD { "
63  << q.points[0] << ", "
64  << q.points[1] << ", "
65  << q.points[2] << ", "
66  << q.points[3] << " }";
67 }
68 
69 std::ostream& operator<<(std::ostream& out, const Layout::Glyph& g) {
70  return out << "GLYPH { " << g.glyph_index << ": " << g.quad << " }";
71 }
72 
73 std::ostream& operator<<(std::ostream& os, const Layout& layout) {
74  os << "LAYOUT { ";
75  for (size_t i = 0; i < layout.GetGlyphCount(); ++i)
76  os << layout.GetGlyph(i) << ", ";
77  os << "}";
78  return os;
79 }
80 
81 } // namespace text
82 } // namespace ion
void SetLineAdvanceHeight(float line_advance)
Sets the vertical distance between successive baselines.
Definition: layout.cc:56
bool AddGlyph(const Glyph &glyph)
Adds a Glyph to the layout.
Definition: layout.cc:23
std::ostream & operator<<(std::ostream &out, const Layout::Quad &q)
Helpers for logging Layouts/Glyphs/Quads.
Definition: layout.cc:61
math::Point3f points[4]
Definition: layout.h:154
std::string text
float GetLineAdvanceHeight() const
Returns the vertical distance between successive baselines in multiline text, scaled to the same unit...
Definition: layout.cc:52
A Quad represents a 3D quadrilateral onto which a character glyph in the layout will be drawn...
Definition: layout.h:132
void GetGlyphSet(GlyphSet *glyphs) const
Populates glyphs with the glyph indexes appearing in this Layout.
Definition: layout.cc:47
const Glyph & GetGlyph(size_t i) const
Returns the indexed glyph.
Definition: layout.cc:35
void Reserve(size_t s)
Reserves space for at least s glyphs.
Definition: layout.cc:33
bool ReplaceGlyph(size_t i, const Glyph &new_glyph)
Modifies the indexed glyph.
Definition: layout.cc:39
size_t GetGlyphCount() const
Returns the number of glyphs added to the layout.
Definition: layout.cc:31
A Layout instance specifies how glyphs are arranged to form text.
Definition: layout.h:127
GlyphIndex glyph_index
Definition: layout.h:173
A Glyph represents one character glyph in the layout.
Definition: layout.h:160