27#ifndef EASY3D_RENDERER_TEXT_RENDERER_H
28#define EASY3D_RENDERER_TEXT_RENDERER_H
33#include <easy3d/core/types.h>
60 explicit TextRenderer(
float dpi_scale = 1.0f,
int texture_size = 512,
bool mipmaps =
false);
72 bool add_font(
const std::string &font_file);
78 std::size_t
num_fonts()
const {
return font_ids_.size(); }
84 const std::vector<std::string> &
font_names()
const {
return font_names_; }
102 float draw(
const std::string &text,
float x,
float y,
float font_size,
103 int font_id = 0,
const vec3 &font_color =
vec3(0, 0, 0),
bool upper_left =
true
134 Rect draw(
const std::string &text,
float x,
float y,
float font_size,
Align align,
135 int font_id = 0,
const vec3 &font_color =
vec3(0, 0, 0),
136 float line_spacing = 0.0f,
bool upper_left =
true
180 float string_width(
const std::string& str,
float font_size)
const;
188 float string_height(
const std::string& str,
float font_size)
const;
202 void flush_draw(
const vec3 &font_color)
const;
205 Rect _get_bbox(
const std::string &text,
float size,
float x,
float y,
Align align,
float line_spacing)
const;
210 std::vector<int> font_ids_;
211 std::vector<std::string> font_names_;
float string_height(const std::string &str, float font_size) const
Query the height of a string.
Definition text_renderer.cpp:806
float draw(const std::string &text, float x, float y, float font_size, int font_id=0, const vec3 &font_color=vec3(0, 0, 0), bool upper_left=true) const
Draw the text.
Definition text_renderer.cpp:817
bool kerning() const
Query the kerning behavior. Kerning is disabled by default.
Definition text_renderer.cpp:781
~TextRenderer()
Definition text_renderer.cpp:736
bool add_font(const std::string &font_file)
Add a font from a file. This function must be called at least once to add a font.
Definition text_renderer.cpp:741
void set_kerning(bool kerning)
Set kerning.
Definition text_renderer.cpp:775
Rect string_bounding_rect(const std::string &str, float x, float y, float font_size) const
Query the bounding rectangle of a string (treated as if with no space between characters).
Definition text_renderer.cpp:812
void set_character_spacing(float spacing)
Set the spacing between consecutive characters. The default character spacing is 0.
Definition text_renderer.cpp:761
float string_width(const std::string &str, float font_size) const
Query the width of a string (treated as if with no space between characters).
Definition text_renderer.cpp:800
Align
Horizontal alignment.
Definition text_renderer.h:111
@ ALIGN_CENTER
Align text to the center.
Definition text_renderer.h:114
@ ALIGN_LEFT
Align text to the left.
Definition text_renderer.h:112
@ ALIGN_RIGHT
Align text to the right.
Definition text_renderer.h:113
float character_spacing() const
Query the spacing between consecutive characters.
Definition text_renderer.cpp:767
const std::vector< std::string > & font_names() const
The names of available fonts.
Definition text_renderer.h:84
TextRenderer(float dpi_scale=1.0f, int texture_size=512, bool mipmaps=false)
Constructor.
Definition text_renderer.cpp:723
float font_height(float font_size) const
Query the height of the font.
Definition text_renderer.cpp:789
std::size_t num_fonts() const
The number of available fonts.
Definition text_renderer.h:78
Definition collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
GenericRect< float > Rect
A 2D axis-aligned rectangle of float type.
Definition types.h:111