MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
GlyphOutline.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "FontFace.hpp"
4
5#include <glm/vec2.hpp>
6
8
9/**
10 * @struct GlyphOutline
11 * @brief Vector outline for a single glyph as a flat polyline sequence.
12 *
13 * Each contour in the glyph outline is appended in order. Contour boundaries
14 * are recorded in @p contour_ends: contour_ends[i] is the exclusive end index
15 * into @p points for contour i. Points within a contour are in the winding
16 * order specified by the font (counter-clockwise for filled regions, clockwise
17 * for holes in TrueType; the caller interprets winding as needed).
18 *
19 * All coordinates are in pixels at the pixel_size passed to decompose_glyph(),
20 * with Y increasing downward (matching GlyphQuad convention). The origin is the
21 * glyph's pen origin: (0, 0) is the advance origin on the baseline.
22 *
23 * advance_x mirrors GlyphMetrics::advance_x for layout without a GlyphAtlas.
24 */
26 uint32_t codepoint { 0 };
27 std::vector<glm::vec2> points;
28 std::vector<uint32_t> contour_ends;
29 int32_t advance_x { 0 };
30};
31
32/**
33 * @brief Decompose a Unicode codepoint into a tessellated polyline outline.
34 *
35 * Loads the glyph via FT_LOAD_NO_BITMAP, walks the FT_Outline with
36 * FT_Outline_Decompose, and flattens conic and cubic Bezier segments into
37 * line segments at the given flatness tolerance.
38 *
39 * The returned outline may be empty (points and contour_ends both empty) for
40 * whitespace codepoints or when the codepoint has no outline (e.g. space, tab).
41 * advance_x is still populated in that case so layout can proceed.
42 *
43 * @param face Loaded FontFace. Must outlive this call.
44 * @param codepoint Unicode codepoint.
45 * @param pixel_size Glyph size in pixels. Passed to FT_Set_Pixel_Sizes.
46 * @param tolerance Flatness tolerance in pixels. Smaller values produce
47 * more segments and higher fidelity curves.
48 * @return GlyphOutline with pixel-space polyline data.
49 */
50[[nodiscard]] MAYAFLUX_API GlyphOutline decompose_glyph(
51 FontFace& face,
52 uint32_t codepoint,
53 uint32_t pixel_size,
54 float tolerance = 0.5F);
55
56/**
57 * @brief Decompose a Unicode codepoint using the default atlas pixel size.
58 *
59 * Convenience overload that reads pixel_size from TypeFaceFoundry's default
60 * atlas. Requires set_default_font() to have been called.
61 *
62 * @param codepoint Unicode codepoint.
63 * @param tolerance Flatness tolerance in pixels.
64 * @return GlyphOutline, or empty outline on failure.
65 */
66[[nodiscard]] MAYAFLUX_API GlyphOutline decompose_glyph(
67 uint32_t codepoint,
68 float tolerance = 0.5F);
69
70} // namespace MayaFlux::Portal::Text
float tolerance
GlyphOutline decompose_glyph(FontFace &face, uint32_t codepoint, uint32_t pixel_size, float tolerance)
Decompose a Unicode codepoint into a tessellated polyline outline.
std::vector< glm::vec2 > points
std::vector< uint32_t > contour_ends
Vector outline for a single glyph as a flat polyline sequence.