118 return coverage[
static_cast<size_t>(
y) *
static_cast<size_t>(
width) +
119 static_cast<size_t>(
x)];
166 bool valid()
const {
return static_cast<bool>(impl_); }
237 std::shared_ptr<Impl> impl_;
A TrueType font, loaded at a fixed pixel size, with a glyph cache.
static size_t line_count(const std::string &text)
Number of lines in a string (newline-separated, at least 1).
std::string family_name() const
Family name of the font, e.g. "Inter" (empty if unavailable).
static std::vector< uint32_t > decode_utf8(const std::string &text)
Decode a UTF-8 string into Unicode code points.
static Font from_file(const std::string &path, float pixel_size)
Load a TrueType font from a file.
FontMetrics metrics() const
Vertical metrics (ascent, descent, line gap) in pixels.
Font with_pixel_size(float new_pixel_size) const
A font handle for the same typeface at a different pixel size.
float advance(uint32_t codepoint) const
Pen advance of one code point in pixels.
std::string source_path() const
Path this font was loaded from, or an empty string for from_memory() fonts.
float pixel_size() const
Em size of this font in pixels (0 for an invalid font).
Font()=default
Construct an empty (invalid) font. See valid().
float measure(const std::string &text) const
Width of a single line of text in pixels, including kerning.
const GlyphBitmap * glyph(uint32_t codepoint) const
The rasterized glyph for a code point, rasterizing it on first use.
bool valid() const
Whether this handle refers to a loaded font.
float kerning(uint32_t first, uint32_t second) const
Kerning adjustment between two code points, in pixels.
static Font from_memory(std::vector< uint8_t > data, float pixel_size)
Create a font from TTF data already in memory.
std::string resolve_font_path(const std::string &path)
Turn a possibly empty font path into a path that exists.
void clear_font_cache()
Drop all fonts from the process-wide font cache.
std::string default_font_path()
Path of the bundled default font, or as overridden by the SCIMESH_FONT environment variable.
Font cached_font(const std::string &path, float pixel_size)
Load a font, re-using an already loaded one when possible.
Vertical metrics of a font at a given pixel size.
float line_height() const
Total height of one line, in pixels (ascent + descent + line_gap).
float ascent
Distance from the baseline to the top of the line, in pixels.
float line_gap
Recommended extra spacing between two lines, in pixels.
float box_height() const
Height of the glyph box of one line, in pixels (ascent + descent).
float descent
Distance from the baseline to the bottom of the line, in pixels.
One rasterized glyph: an 8-bit coverage bitmap plus placement info.
uint8_t at(int x, int y) const
Coverage value at pixel (x, y), 0-255. No bounds checking.
float advance
Pen advance for this glyph, in pixels.
int x_offset
Horizontal offset from the pen position to the bitmap's left edge.
int y_offset
Vertical offset from the baseline to the bitmap's top edge.
int height
Bitmap height in pixels.
bool empty() const
Whether this glyph has no pixels to draw (e.g. a space).
std::vector< uint8_t > coverage
Coverage values, row-major, width * height entries.
int width
Bitmap width in pixels.
int y
Top edge of the bitmap, in image pixels.
int x
Left edge of the bitmap, in image pixels.
Fundamental types used throughout the scimesh rendering engine.