scimesh 0.3.4
Headless CPU-only 3D software renderer for scientific mesh visualization
Loading...
Searching...
No Matches
font.h File Reference

TrueType font loading, glyph rasterization and text measurement. More...

#include <scimesh/types.h>
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
Include dependency graph for font.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  scimesh::FontMetrics
 Vertical metrics of a font at a given pixel size. More...
 
struct  scimesh::GlyphBitmap
 One rasterized glyph: an 8-bit coverage bitmap plus placement info. More...
 
class  scimesh::Font
 A TrueType font, loaded at a fixed pixel size, with a glyph cache. More...
 

Namespaces

namespace  scimesh
 

Functions

std::string scimesh::resolve_font_path (const std::string &path)
 Turn a possibly empty font path into a path that exists.
 
std::string scimesh::default_font_path ()
 Path of the bundled default font, or as overridden by the SCIMESH_FONT environment variable.
 
Font scimesh::cached_font (const std::string &path, float pixel_size)
 Load a font, re-using an already loaded one when possible.
 
void scimesh::clear_font_cache ()
 Drop all fonts from the process-wide font cache.
 

Detailed Description

TrueType font loading, glyph rasterization and text measurement.

scimesh draws text labels by rasterizing glyphs with stb_truetype (a single-header, public-domain TrueType parser) and blending the resulting 8-bit coverage bitmaps into the output image. No system font, font server or graphics stack is involved, so text rendering works headless exactly like the rest of the renderer.

The package bundles Inter-Regular.ttf (SIL Open Font License 1.1), see default_font_path(), so labels work out of the box. Any other .ttf file can be used instead — pass its path to TextLayer::font_file, or set the SCIMESH_FONT environment variable to override the default.

This header is the low-level font API: loading, metrics, glyph coverage bitmaps and text measurement. Text placement (world vs. screen space, anchoring, depth testing, halos) lives in TextLayer, see text.h.

Example
scimesh::Font font = scimesh::cached_font("", 18.0f); // "" = bundled font
float w = font.measure("anterior");
const scimesh::GlyphBitmap *glyph = font.glyph('A');
A TrueType font, loaded at a fixed pixel size, with a glyph cache.
Definition font.h:143
Font cached_font(const std::string &path, float pixel_size)
Load a font, re-using an already loaded one when possible.
Definition font.cpp:405
One rasterized glyph: an 8-bit coverage bitmap plus placement info.
Definition font.h:91
int x
Left edge of the bitmap, in image pixels.
Definition text.cpp:223
Note
Font sizes are in output pixels of the final image. The renderer scales them internally by the supersampling factor, so a label keeps its physical size when anti-aliasing is enabled.
Warning
stb_truetype performs no range checking on the font data. Only load font files you trust, see the warning in the stb_truetype header.
See also
TextLayer, draw_text(), text.h
Since
0.4.0

Definition in file font.h.