1.1.0
render-result.hpp
1 #ifndef FONT_CHEF_RENDER_RESULT_HPP
2 #define FONT_CHEF_RENDER_RESULT_HPP
3 
4 #include "font-chef/character-mapping.h"
5 #include "font-chef/font.h"
6 #include <vector>
7 
8 
14 namespace fc {
15 
29  struct FONT_CHEF_EXPORT render_result {
33  std::vector<::fc_character_mapping> mapping;
34 
38  uint32_t line_count;
39 
44 
55  render_result(fc_font * font = nullptr, std::vector<fc_character_mapping> && mapping = {}) //NOLINT
56  : mapping(mapping), font(font), line_count(0) {
57  };
58 
63  render_result(render_result && other) noexcept
64  : mapping(std::move(other.mapping)), font(other.font), line_count(other.line_count) {
65  other.font = nullptr;
66  };
67 
73  render_result & operator=(render_result && other) noexcept {
74  if (this == &other) return *this;
75  this->mapping = std::move(other.mapping);
76  this->font = other.font;
77  this->line_count = other.line_count;
78  other.font = nullptr;
79  return *this;
80  }
81 
87  render_result & operator=(render_result const & other) noexcept {
88  this->font = other.font;
89  if (this == &other) return *this;
90  return *this;
91  }
92 
114  render_result &
115  wrap(float line_width, float line_height_multiplier = 1.0f, fc_alignment alignment = fc_align_left) & {
116  if (!font) return *this;
117  fc_size space_metrics = fc_get_space_metrics(font);
118  this->line_count = fc_wrap(
119  mapping.data(),
120  mapping.size(),
121  line_width,
122  space_metrics.height,
123  space_metrics.width * line_height_multiplier,
124  alignment
125  );
126  return *this;
127  }
128 
149  render_result &&
150  wrap(float line_width, float line_height_multiplier = 1.0f, fc_alignment alignment = fc_align_left) && {
151  return std::move(wrap(line_width, line_height_multiplier, alignment));
152  }
153 
154 
169  render_result & move(float left = 0.0f, float baseline = 0.0f) & {
170  fc_move(mapping.data(), mapping.size(), left, baseline);
171  return *this;
172  }
173 
188  render_result && move(float left = 0.0f, float baseline = 0.0f) && {
189  return std::move(move(left, baseline));
190  }
191 
196  std::vector<::fc_character_mapping>::iterator begin() {
197  return mapping.begin();
198  }
199 
204  std::vector<::fc_character_mapping>::iterator end() {
205  return mapping.end();
206  }
207 
212  size_t size() const {
213  return mapping.size();
214  }
215  };
216 }
217 
218 #endif
fc::render_result
Wraps a std::vector<fc_character_mapping>.
Definition: render-result.hpp:29
fc::render_result::wrap
render_result & wrap(float line_width, float line_height_multiplier=1.0f, fc_alignment alignment=fc_align_left) &
Calls fc_wrap on the vector of character mappings.
Definition: render-result.hpp:115
fc_alignment
fc_alignment
Specifies an aligment to be used when rendering wrapped text.
Definition: character-mapping.h:57
fc_size::height
float height
The height value.
Definition: size.h:29
fc::render_result::wrap
render_result && wrap(float line_width, float line_height_multiplier=1.0f, fc_alignment alignment=fc_align_left) &&
Calls fc_wrap on the vector of character mappings.
Definition: render-result.hpp:150
fc::render_result::operator=
render_result & operator=(render_result const &other) noexcept
Copy assignment operator for fc::render_result.
Definition: render-result.hpp:87
fc_size
Contains width and height as floats.
Definition: size.h:24
fc::render_result::render_result
render_result(fc_font *font=nullptr, std::vector< fc_character_mapping > &&mapping={})
Constructs a fc::render_result instance with a font and with a mapping vector.
Definition: render-result.hpp:55
fc::render_result::move
render_result & move(float left=0.0f, float baseline=0.0f) &
This is a wrapper to fc_move. Consult its documentation for more information.
Definition: render-result.hpp:169
fc::render_result::size
size_t size() const
Returns the size of the mapping vector (i.e, the number of mappings)
Definition: render-result.hpp:212
fc::font
A wrapper class for fc_font.
Definition: font.hpp:29
fc::render_result::begin
std::vector<::fc_character_mapping >::iterator begin()
Returns an iterator pointing to the first character mapping.
Definition: render-result.hpp:196
fc_font
A fc_font struct represents all data and metadata about a font.
fc::render_result::font
fc_font * font
A pointer to the fc_font used to generate this mapping.
Definition: render-result.hpp:43
fc::font::font
font(font &&other) noexcept
Move constructor.
Definition: font.hpp:38
fc_size::width
float width
The width value.
Definition: size.h:26
fc::render_result::operator=
render_result & operator=(render_result &&other) noexcept
Move assignment operator for fc::render_result.
Definition: render-result.hpp:73
fc::render_result::render_result
render_result(render_result &&other) noexcept
Move constructor of fc::render_result.
Definition: render-result.hpp:63
fc_get_space_metrics
struct fc_size fc_get_space_metrics(struct fc_font const *font)
Returns the space glyph width and height for this font at its specified size.
fc::render_result::line_count
uint32_t line_count
How many lines were produced.
Definition: render-result.hpp:38
fc_wrap
uint32_t fc_wrap(struct fc_character_mapping mapping[], size_t count, float line_width, float line_height, float space_width, enum fc_alignment alignment)
Word-wraps characters in an array of fc_character_mapping.
fc::render_result::move
render_result && move(float left=0.0f, float baseline=0.0f) &&
This is a wrapper to fc_move. Consult its documentation for more information.
Definition: render-result.hpp:188
fc::render_result::end
std::vector<::fc_character_mapping >::iterator end()
Returns an iterator pointing to the end+1 character mapping.
Definition: render-result.hpp:204
fc_move
void fc_move(struct fc_character_mapping *mapping, size_t count, float left, float baseline)
Moves all the target rectangles by left pixels horizontally and baseline pixels vertically.
fc::render_result::mapping
std::vector<::fc_character_mapping > mapping
A vector of character mappings produced after calling fc::font::render.
Definition: render-result.hpp:33