Module: graphics.font.ttf
Source: ./graphics/font/ttf.reef
Overview
graphics/font/ttf.reef - TrueType font parser Part of reef-stdlib graphics module
This module provides TrueType font loading and glyph extraction. It parses TTF files and converts glyph outlines to paths for rendering.
Types
TableEntry
Table directory entry
Fields:
| Name | Type |
|---|---|
tag |
string |
checksum |
int |
offset |
int |
length |
int |
HeadTable
Head table data
Fields:
| Name | Type |
|---|---|
units_per_em |
int |
x_min |
int |
y_min |
int |
x_max |
int |
y_max |
int |
index_to_loc_format |
int |
HheaTable
Hhea table data (horizontal header)
Fields:
| Name | Type |
|---|---|
ascender |
int |
descender |
int |
line_gap |
int |
advance_width_max |
int |
num_of_long_hor_metrics |
int |
MaxpTable
Maxp table data
Fields:
| Name | Type |
|---|---|
num_glyphs |
int |
CmapFormat4
Cmap subtable for format 4 (most common for BMP characters)
Fields:
| Name | Type |
|---|---|
seg_count |
int |
end_codes |
[int] |
start_codes |
[int] |
id_deltas |
[int] |
id_range_offsets |
[int] |
glyph_ids |
[int] |
glyph_ids_offset |
int |
HmtxEntry
Horizontal metrics entry
Fields:
| Name | Type |
|---|---|
advance_width |
int |
left_side_bearing |
int |
GlyphPoint
Glyph point (for outline)
Fields:
| Name | Type |
|---|---|
x |
int |
y |
int |
on_curve |
bool |
GlyphContour
Glyph contour
Fields:
| Name | Type |
|---|---|
points |
[GlyphPoint] |
GlyphData
Parsed glyph data
Fields:
| Name | Type |
|---|---|
num_contours |
int |
x_min |
int |
y_min |
int |
x_max |
int |
y_max |
int |
contours |
[GlyphContour] |
is_compound |
bool |
component_indices |
[int] |
component_transforms |
[GlyphTransform] |
GlyphTransform
Transform for compound glyph components
Fields:
| Name | Type |
|---|---|
a |
float |
b |
float |
c |
float |
d |
float |
e |
float |
f |
float |
KernPair
Kerning pair
Fields:
| Name | Type |
|---|---|
left |
int |
right |
int |
value |
int |
TTFFont
Fields:
| Name | Type |
|---|---|
valid |
bool |
data |
[int] |
num_tables |
int |
tables |
[TableEntry] |
head |
HeadTable |
hhea |
HheaTable |
maxp |
MaxpTable |
cmap |
CmapFormat4 |
hmtx |
[HmtxEntry] |
glyph_offsets |
[int] |
glyf_offset |
int |
kern_pairs |
[KernPair] |
family_name |
string |
Functions
fn read_u16(data: [int], offset: int): int
Read unsigned 16-bit big-endian
fn read_i16(data: [int], offset: int): int
Read signed 16-bit big-endian
fn read_u32(data: [int], offset: int): int
Read unsigned 32-bit big-endian
fn read_tag(data: [int], offset: int): string
Read 4-character tag
fn chars_to_string(chars: [char], len: int): string
Convert char array to string
fn find_table(f: TTFFont, tag: string): int
fn find_table_entry(f: TTFFont, tag: string): int
fn string_equals(a: string, b: string): bool
Simple string equality
fn load_ttf(filepath: string): TTFFont
fn load_ttf_bytes(data: [int]): TTFFont
fn invalid_font(): TTFFont
fn string_to_bytes(s: string): [int]
fn parse_head(f: TTFFont): bool
fn parse_hhea(f: TTFFont): bool
fn parse_maxp(f: TTFFont): bool
fn parse_cmap(f: TTFFont): bool
fn parse_hmtx(f: TTFFont): bool
fn parse_loca(f: TTFFont): bool
fn parse_kern(f: TTFFont): bool
fn parse_name(f: TTFFont): bool
fn read_utf16be_string(data: [int], offset: int, byte_length: int): string
fn ttf_font_valid(f: TTFFont): bool
fn ttf_font_family(f: TTFFont): string
fn ttf_font_units_per_em(f: TTFFont): int
fn ttf_font_num_glyphs(f: TTFFont): int
fn ttf_font_ascender(f: TTFFont): int
fn ttf_font_descender(f: TTFFont): int
fn ttf_font_line_gap(f: TTFFont): int
fn ttf_glyph_index(f: TTFFont, codepoint: int): int
fn ttf_glyph_advance(f: TTFFont, glyph_index: int): int
fn ttf_glyph_lsb(f: TTFFont, glyph_index: int): int
fn ttf_scaled_ascender(f: TTFFont, size: float): float
fn ttf_scaled_descender(f: TTFFont, size: float): float
fn ttf_scaled_line_height(f: TTFFont, size: float): float
fn ttf_scaled_advance(f: TTFFont, glyph_index: int, size: float): float
fn ttf_kern_advance(f: TTFFont, left_glyph: int, right_glyph: int): int
fn ttf_glyph_path(f: TTFFont, glyph_index: int, scale: float): path.Path
fn ttf_glyph_path_depth(f: TTFFont, glyph_index: int, scale: float, depth: int): path.Path
Procedures
proc parse_simple_glyph(f: TTFFont, pb: path.PathBuilder, offset: int, num_contours: int, scale: float)
proc parse_compound_glyph(f: TTFFont, pb: path.PathBuilder, offset: int, scale: float, depth: int)
Generated by reefc doc