#ui/font
Xu 0.13.1 API
import: #ui/font
counts: 15 functions, 31 methods, 19 types, 3 constants, 0 method sets
Standard library package `#ui/font`.
struct AtlasEntry
pub struct AtlasEntry {
pub font_id int
pub glyph_id int
pub px_size_q int
pub x int
pub y int
pub w int
pub h int
pub offset_x int
pub offset_y int
pub advance_x f64
pub u0 f64
pub v0 f64
pub u1 f64
pub v1 f64
pub has_ink bool
}
Purpose
Structure encapsulating font_id, glyph_id, px_size_q, x, y.
Public fields
font_id int- field (int)
glyph_id int- field (int)
px_size_q int- field (int)
x int- value
y int- value
w int- writer or width
h int- height or handle
offset_x int- field (int)
offset_y int- field (int)
advance_x f64- field (f64)
u0 f64- field (f64)
v0 f64- field (f64)
u1 f64- field (f64)
v1 f64- field (f64)
has_ink bool- field (bool)
struct GlyphAtlas
pub struct GlyphAtlas {
pub width int
pub height int
pub max_width int
pub max_height int
pub revision int
pub pixels []u8
pub entries []AtlasEntry
}
Purpose
Structure encapsulating width, height, max_width, max_height, revision.
Public fields
width int- field (int)
height int- field (int)
max_width int- field (int)
max_height int- field (int)
revision int- field (int)
pixels []u8- field ([]u8)
entries []AtlasEntry- field ([]AtlasEntry)
quantize_px_size
pub fn quantize_px_size(px_size f64) int
Purpose
Quantize px size. Throws on failure; handle the error or propagate it to the caller.
Parameters
px_size f64- px_size (f64)
Returns
int — a value of this type
new_glyph_atlas
pub fn new_glyph_atlas(width int, height int, max_width int, max_height int) GlyphAtlas
Purpose
Construct glyph atlas. Throws on failure; handle the error or propagate it to the caller.
Parameters
width int- width (int)
height int- height (int)
max_width int- max_width (int)
max_height int- max_height (int)
Returns
GlyphAtlas — a value of this type
default_glyph_atlas
pub fn default_glyph_atlas() GlyphAtlas
Purpose
Default glyph atlas. Throws on failure; handle the error or propagate it to the caller.
Parameters
No arguments are required.
Returns
GlyphAtlas — a value of this type
($&GlyphAtlas) clear
pub fn (atlas $&GlyphAtlas) clear()
Purpose
Clear all buffered or stored entries and internal state.
Parameters
atlas $&GlyphAtlas- The
GlyphAtlas instance used by this call (exclusive borrow).
Returns
This call does not return a value.
(&GlyphAtlas) entry_index
pub fn (atlas &GlyphAtlas) entry_index(font_id int, glyph_id int, px_size f64) int
Purpose
Operation on &GlyphAtlas: entry index. Returns -1 if not found.
Parameters
atlas &GlyphAtlas- The
GlyphAtlas instance used by this call (borrow).
font_id int- font_id (int)
glyph_id int- glyph_id (int)
px_size f64- px_size (f64)
Returns
int — index; see the description for its range and special values
($&GlyphAtlas) insert_bitmap
pub fn (atlas $&GlyphAtlas) insert_bitmap(glyph ResolvedGlyph, px_size f64, bmp &GlyphBitmap) AtlasEntry
Purpose
Operation on $&GlyphAtlas: insert bitmap. Throws on failure; handle the error or propagate it to the caller.
Parameters
atlas $&GlyphAtlas- The
GlyphAtlas instance used by this call (exclusive borrow).
glyph ResolvedGlyph- glyph (ResolvedGlyph)
px_size f64- px_size (f64)
bmp &GlyphBitmap- bmp (read-only borrow; caller keeps the original; type &GlyphBitmap)
Returns
AtlasEntry — a value of this type
($&GlyphAtlas) get_or_rasterize
pub fn (atlas $&GlyphAtlas) get_or_rasterize(stack &FontStack, glyph ResolvedGlyph, px_size f64) AtlasEntry
Purpose
Operation on $&GlyphAtlas: read or rasterize. Throws on failure; handle the error or propagate it to the caller.
Parameters
atlas $&GlyphAtlas- The
GlyphAtlas instance used by this call (exclusive borrow).
stack &FontStack- stack (read-only borrow; caller keeps the original; type &FontStack)
glyph ResolvedGlyph- glyph (ResolvedGlyph)
px_size f64- px_size (f64)
Returns
AtlasEntry — a value of this type
($&GlyphAtlas) get_codepoint
pub fn (atlas $&GlyphAtlas) get_codepoint(stack &FontStack, codepoint int, px_size f64) AtlasEntry
Purpose
Operation on $&GlyphAtlas: read codepoint. Throws on failure; handle the error or propagate it to the caller.
Parameters
atlas $&GlyphAtlas- The
GlyphAtlas instance used by this call (exclusive borrow).
stack &FontStack- stack (read-only borrow; caller keeps the original; type &FontStack)
codepoint int- codepoint (int)
px_size f64- px_size (f64)
Returns
AtlasEntry — a value of this type
(&GlyphAtlas) entry_count
pub fn (atlas &GlyphAtlas) entry_count() int
Purpose
Operation on &GlyphAtlas: entry count.
Parameters
atlas &GlyphAtlas- The
GlyphAtlas instance used by this call (borrow).
Returns
int — a value of this type
(&GlyphAtlas) sample_alpha
pub fn (atlas &GlyphAtlas) sample_alpha(px int, py int) int
Purpose
Operation on &GlyphAtlas: sample alpha.
Parameters
atlas &GlyphAtlas- The
GlyphAtlas instance used by this call (borrow).
px int- px (int)
py int- py (int)
Returns
int — a value of this type
(&GlyphAtlas) to_rgba8_white
pub fn (atlas &GlyphAtlas) to_rgba8_white() []u8
Purpose
Operation on &GlyphAtlas: convert to rgba8 white.
Parameters
atlas &GlyphAtlas- The
GlyphAtlas instance used by this call (borrow).
Returns
[]u8 — slice result
builtin_font
pub fn builtin_font(face_id int) FontFace
Purpose
Builtin font.
Parameters
face_id int- face_id (int)
Returns
FontFace — a value of this type
builtin_glyph_index
pub fn builtin_glyph_index(codepoint int) int
Purpose
Builtin glyph index.
Parameters
codepoint int- codepoint (int)
Returns
int — index; see the description for its range and special values
builtin_glyph_metrics
pub fn builtin_glyph_metrics(glyph_id int) GlyphMetrics
Purpose
Builtin glyph metrics.
Parameters
glyph_id int- glyph_id (int)
Returns
GlyphMetrics — a value of this type
builtin_glyph_outline
pub fn builtin_glyph_outline(glyph_id int) GlyphOutline
Purpose
Builtin glyph outline.
Parameters
glyph_id int- glyph_id (int)
Returns
GlyphOutline — a value of this type
const TEXT_LEFT
Purpose
Constant TEXT_LEFT, defining protocol or algorithm parameters.
const TEXT_CENTER
pub const TEXT_CENTER = 1
Purpose
Constant TEXT_CENTER, defining protocol or algorithm parameters.
const TEXT_RIGHT
Purpose
Constant TEXT_RIGHT, defining protocol or algorithm parameters.
struct LayoutOptions
pub struct LayoutOptions {
pub size f64
pub width f64
pub align int
pub line_height f64
pub masked bool
pub disable_kerning bool
}
Purpose
Font Configuration parameters and options set.
Public fields
size f64- field (f64)
width f64- field (f64)
align int- field (int)
line_height f64- field (f64)
masked bool- field (bool)
disable_kerning bool- field (bool)
default_options
pub fn default_options(size f64) LayoutOptions
Purpose
Default options.
Parameters
size f64- size (f64)
Returns
LayoutOptions — a value of this type
wrapped_options
pub fn wrapped_options(size f64, width f64, align int) LayoutOptions
Purpose
Wrapped options.
Parameters
size f64- size (f64)
width f64- width (f64)
align int- align (int)
Returns
LayoutOptions — a value of this type
struct TextMetrics
pub struct TextMetrics {
pub width f64
pub height f64
pub baseline f64
pub lines int
pub ink_x f64
pub ink_y f64
pub ink_width f64
pub ink_height f64
}
Purpose
Structure encapsulating width, height, baseline, lines, ink_x.
Public fields
width f64- field (f64)
height f64- field (f64)
baseline f64- field (f64)
lines int- field (int)
ink_x f64- field (f64)
ink_y f64- field (f64)
ink_width f64- field (f64)
ink_height f64- field (f64)
struct TextHit
pub struct TextHit {
pub index int
pub length int
pub trailing bool
pub inside bool
pub x f64
pub y f64
pub height f64
}
Purpose
Structure encapsulating index, length, trailing, inside, x.
Public fields
index int- field (int)
length int- field (int)
trailing bool- field (bool)
inside bool- field (bool)
x f64- value
y f64- value
height f64- field (f64)
(&TextHit) byte_index
pub fn (hit &TextHit) byte_index() int
Purpose
Operation on &TextHit: byte index.
Parameters
hit &TextHit- The
TextHit instance used by this call (borrow).
Returns
int — index; see the description for its range and special values
struct TextRect
pub struct TextRect {
pub x f64
pub y f64
pub width f64
pub height f64
}
Purpose
Structure encapsulating x, y, width, height.
Public fields
x f64- value
y f64- value
width f64- field (f64)
height f64- field (f64)
struct PositionedGlyph
pub struct PositionedGlyph {
pub byte_index int
pub byte_length int
pub codepoint int
pub render_codepoint int
pub face_index int
pub font_id int
pub glyph_id int
pub x f64
pub y f64
pub baseline_y f64
pub advance f64
pub line_index int
pub is_newline bool
pub is_space bool
}
Purpose
Structure encapsulating byte_index, byte_length, codepoint, render_codepoint, face_index.
Public fields
byte_index int- field (int)
byte_length int- field (int)
codepoint int- field (int)
render_codepoint int- field (int)
face_index int- field (int)
font_id int- field (int)
glyph_id int- field (int)
x f64- value
y f64- value
baseline_y f64- field (f64)
advance f64- field (f64)
line_index int- field (int)
is_newline bool- field (bool)
is_space bool- field (bool)
struct LineBox
pub struct LineBox {
pub line_index int
pub start_item int
pub end_item int
pub byte_start int
pub byte_end int
pub byte_end_with_newline int
pub x f64
pub y f64
pub baseline_y f64
pub width f64
pub height f64
}
Purpose
Structure encapsulating line_index, start_item, end_item, byte_start, byte_end.
Public fields
line_index int- field (int)
start_item int- field (int)
end_item int- field (int)
byte_start int- field (int)
byte_end int- field (int)
byte_end_with_newline int- field (int)
x f64- value
y f64- value
baseline_y f64- field (f64)
width f64- field (f64)
height f64- field (f64)
struct TextLayout
pub struct TextLayout {
pub metrics TextMetrics
pub size f64
pub width f64
pub align int
pub line_height f64
pub text_len int
pub masked bool
pub glyphs []PositionedGlyph
pub lines []LineBox
}
Purpose
Structure encapsulating metrics, size, width, align, line_height.
Public fields
metrics TextMetrics- field (TextMetrics)
size f64- field (f64)
width f64- field (f64)
align int- field (int)
line_height f64- field (f64)
text_len int- field (int)
masked bool- field (bool)
glyphs []PositionedGlyph- field ([]PositionedGlyph)
lines []LineBox- field ([]LineBox)
layout_text
pub fn layout_text(stack &FontStack, text &string, options &LayoutOptions) TextLayout
Purpose
Layout text. Throws on failure; handle the error or propagate it to the caller.
Parameters
stack &FontStack- stack (read-only borrow; caller keeps the original; type &FontStack)
text &string- text (read-only borrow; caller keeps the original; type &string)
options &LayoutOptions- options (read-only borrow; caller keeps the original; type &LayoutOptions)
Returns
TextLayout — a value of this type
(&TextLayout) glyph_count
pub fn (layout &TextLayout) glyph_count() int
Purpose
Operation on &TextLayout: glyph count.
Parameters
layout &TextLayout- The
TextLayout instance used by this call (borrow).
Returns
int — a value of this type
(&TextLayout) glyph_at
pub fn (layout &TextLayout) glyph_at(i int) PositionedGlyph
Purpose
Operation on &TextLayout: glyph at.
Parameters
layout &TextLayout- The
TextLayout instance used by this call (borrow).
i int- index or integer (int)
Returns
PositionedGlyph — a value of this type
(&TextLayout) line_count
pub fn (layout &TextLayout) line_count() int
Purpose
Operation on &TextLayout: line count.
Parameters
layout &TextLayout- The
TextLayout instance used by this call (borrow).
Returns
int — a value of this type
(&TextLayout) line_at
pub fn (layout &TextLayout) line_at(i int) LineBox
Purpose
Operation on &TextLayout: line at.
Parameters
layout &TextLayout- The
TextLayout instance used by this call (borrow).
i int- index or integer (int)
Returns
LineBox — a value of this type
(&TextLayout) populate_atlas
pub fn (layout &TextLayout) populate_atlas(atlas $&GlyphAtlas, stack &FontStack) int
Purpose
Operation on &TextLayout: populate atlas. Throws on failure; handle the error or propagate it to the caller.
Parameters
layout &TextLayout- The
TextLayout instance used by this call (borrow).
atlas $&GlyphAtlas- atlas (exclusive borrow; may modify the original; type $&GlyphAtlas)
stack &FontStack- stack (read-only borrow; caller keeps the original; type &FontStack)
Returns
int — a value of this type
(&TextLayout) caret
pub fn (layout &TextLayout) caret(byte_index int, trailing bool) TextHit
Purpose
Execute caret on &TextLayout. Throws on failure; handle the error or propagate it to the caller.
Parameters
layout &TextLayout- The
TextLayout instance used by this call (borrow).
byte_index int- byte_index (int)
trailing bool- trailing (bool)
Returns
TextHit — a value of this type
(&TextLayout) hit_test
pub fn (layout &TextLayout) hit_test(x f64, y f64) TextHit
Purpose
Operation on &TextLayout: hit test. Throws on failure; handle the error or propagate it to the caller.
Parameters
layout &TextLayout- The
TextLayout instance used by this call (borrow).
x f64- value (f64)
y f64- value (f64)
Returns
TextHit — a value of this type
(&TextLayout) selection_rects
pub fn (layout &TextLayout) selection_rects(start_byte int, end_byte int) []TextRect
Purpose
Operation on &TextLayout: selection rects. Throws on failure; handle the error or propagate it to the caller.
Parameters
layout &TextLayout- The
TextLayout instance used by this call (borrow).
start_byte int- start_byte (int)
end_byte int- end_byte (int)
Returns
[]TextRect — slice result
struct GlyphBitmap
pub struct GlyphBitmap {
pub width int
pub height int
pub offset_x int
pub offset_y int
pub advance_x f64
pub pixels []u8
}
Purpose
Structure encapsulating width, height, offset_x, offset_y, advance_x.
Public fields
width int- field (int)
height int- field (int)
offset_x int- field (int)
offset_y int- field (int)
advance_x f64- field (f64)
pixels []u8- field ([]u8)
rasterize_outline
pub fn rasterize_outline(outline &GlyphOutline, px_size f64) GlyphBitmap
Purpose
Rasterize outline. Throws on failure; handle the error or propagate it to the caller.
Parameters
outline &GlyphOutline- outline (read-only borrow; caller keeps the original; type &GlyphOutline)
px_size f64- px_size (f64)
Returns
GlyphBitmap — a value of this type
struct ResolvedGlyph
pub struct ResolvedGlyph {
pub face_index int
pub font_id int
pub glyph_id int
}
Purpose
Structure encapsulating face_index, font_id, glyph_id.
Public fields
face_index int- field (int)
font_id int- field (int)
glyph_id int- field (int)
struct LineMetrics
pub struct LineMetrics {
pub ascent f64
pub descent f64
pub line_gap f64
pub line_height f64
}
Purpose
Structure encapsulating ascent, descent, line_gap, line_height.
Public fields
ascent f64- field (f64)
descent f64- field (f64)
line_gap f64- field (f64)
line_height f64- field (f64)
struct FontStack
pub struct FontStack {
pub faces []FontFace
}
Purpose
Structure encapsulating faces.
Public fields
faces []FontFace- field ([]FontFace)
new_font_stack
pub fn new_font_stack() FontStack
Purpose
Construct font stack.
Parameters
No arguments are required.
Returns
FontStack — a value of this type
($&FontStack) add_face
pub fn (stack $&FontStack) add_face(face FontFace) int
Purpose
Operation on $&FontStack: add face.
Parameters
stack $&FontStack- The
FontStack instance used by this call (exclusive borrow).
face FontFace- face (FontFace)
Returns
int — a value of this type
($&FontStack) ensure_builtin_fallback
pub fn (stack $&FontStack) ensure_builtin_fallback(face_id int) int
Purpose
Operation on $&FontStack: ensure builtin fallback.
Parameters
stack $&FontStack- The
FontStack instance used by this call (exclusive borrow).
face_id int- face_id (int)
Returns
int — a value of this type
(&FontStack) face_count
pub fn (stack &FontStack) face_count() int
Purpose
Operation on &FontStack: face count.
Parameters
stack &FontStack- The
FontStack instance used by this call (borrow).
Returns
int — a value of this type
(&FontStack) clone
pub fn (stack &FontStack) clone() FontStack
Purpose
Operation on &FontStack: copy into a new independent string.
Parameters
stack &FontStack- The
FontStack instance used by this call (borrow).
Returns
FontStack — a value of this type
(&FontStack) line_metrics
pub fn (stack &FontStack) line_metrics(px_size f64) LineMetrics
Purpose
Operation on &FontStack: line metrics. Throws on failure; handle the error or propagate it to the caller.
Parameters
stack &FontStack- The
FontStack instance used by this call (borrow).
px_size f64- px_size (f64)
Returns
LineMetrics — a value of this type
(&FontStack) resolve
pub fn (stack &FontStack) resolve(codepoint int) ResolvedGlyph
Purpose
Operation on &FontStack: resolve. Throws on failure; handle the error or propagate it to the caller.
Parameters
stack &FontStack- The
FontStack instance used by this call (borrow).
codepoint int- codepoint (int)
Returns
ResolvedGlyph — a value of this type
(&FontStack) advance_px
pub fn (stack &FontStack) advance_px(glyph ResolvedGlyph, px_size f64) f64
Purpose
Operation on &FontStack: advance px. Throws on failure; handle the error or propagate it to the caller.
Parameters
stack &FontStack- The
FontStack instance used by this call (borrow).
glyph ResolvedGlyph- glyph (ResolvedGlyph)
px_size f64- px_size (f64)
Returns
f64 — a value of this type
(&FontStack) kerning_px
pub fn (stack &FontStack) kerning_px(left ResolvedGlyph, right ResolvedGlyph, px_size f64) f64
Purpose
Operation on &FontStack: kerning px.
Parameters
stack &FontStack- The
FontStack instance used by this call (borrow).
left ResolvedGlyph- left (ResolvedGlyph)
right ResolvedGlyph- right (ResolvedGlyph)
px_size f64- px_size (f64)
Returns
f64 — a value of this type
(&FontStack) rasterize
pub fn (stack &FontStack) rasterize(glyph ResolvedGlyph, px_size f64) GlyphBitmap
Purpose
Execute rasterize on &FontStack. Throws on failure; handle the error or propagate it to the caller.
Parameters
stack &FontStack- The
FontStack instance used by this call (borrow).
glyph ResolvedGlyph- glyph (ResolvedGlyph)
px_size f64- px_size (f64)
Returns
GlyphBitmap — a value of this type
struct FontMetrics
pub struct FontMetrics {
pub units_per_em int
pub ascent int
pub descent int
pub line_gap int
pub x_min int
pub y_min int
pub x_max int
pub y_max int
pub num_glyphs int
}
Purpose
Structure encapsulating units_per_em, ascent, descent, line_gap, x_min.
Public fields
units_per_em int- field (int)
ascent int- field (int)
descent int- field (int)
line_gap int- field (int)
x_min int- field (int)
y_min int- field (int)
x_max int- field (int)
y_max int- field (int)
num_glyphs int- field (int)
struct GlyphMetrics
pub struct GlyphMetrics {
pub glyph_id int
pub advance_width int
pub left_side_bearing int
}
Purpose
Structure encapsulating glyph_id, advance_width, left_side_bearing.
Public fields
glyph_id int- field (int)
advance_width int- field (int)
left_side_bearing int- field (int)
struct ContourPoint
pub struct ContourPoint {
pub x f64
pub y f64
pub on_curve bool
}
Purpose
Structure encapsulating x, y, on_curve.
Public fields
x f64- value
y f64- value
on_curve bool- field (bool)
struct GlyphOutline
pub struct GlyphOutline {
pub points []ContourPoint
pub contour_ends []int
pub units_per_em f64
pub advance_width f64
pub left_side_bearing f64
pub x_min f64
pub y_min f64
pub x_max f64
pub y_max f64
}
Purpose
Structure encapsulating points, contour_ends, units_per_em, advance_width, left_side_bearing.
Public fields
points []ContourPoint- field ([]ContourPoint)
contour_ends []int- field ([]int)
units_per_em f64- field (f64)
advance_width f64- field (f64)
left_side_bearing f64- field (f64)
x_min f64- field (f64)
y_min f64- field (f64)
x_max f64- field (f64)
y_max f64- field (f64)
struct KernPair
pub struct KernPair {
pub key int
pub value int
}
Purpose
Structure encapsulating key, value.
Public fields
key int- key
value int- field (int)
struct FontFace
pub struct FontFace {
pub id int
pub metrics FontMetrics
pub is_builtin bool
}
Purpose
Structure encapsulating id, metrics, is_builtin.
Public fields
id int- field (int)
metrics FontMetrics- field (FontMetrics)
is_builtin bool- field (bool)
(&FontFace) clone
pub fn (face &FontFace) clone() FontFace
Purpose
Operation on &FontFace: copy into a new independent string.
Parameters
face &FontFace- The
FontFace instance used by this call (borrow).
Returns
FontFace — a value of this type
bytes_from_string
pub fn bytes_from_string(s &string) []u8
Purpose
Bytes from string.
Parameters
s &string- source string (read-only borrow; caller keeps the original; type &string)
Returns
[]u8 — slice result
ttc_font_count
pub fn ttc_font_count(data &[]u8) int
Purpose
Ttc font count. Throws on failure; handle the error or propagate it to the caller.
Parameters
data &[]u8- data (read-only borrow; caller keeps the original; type &[]u8)
Returns
int — a value of this type
parse_ttf
pub fn parse_ttf(data &[]u8, font_index int, face_id int) FontFace
Purpose
Parse as ttf. Throws on failure; handle the error or propagate it to the caller.
Parameters
data &[]u8- data (read-only borrow; caller keeps the original; type &[]u8)
font_index int- font_index (int)
face_id int- face_id (int)
Returns
FontFace — a value of this type
(&FontFace) glyph_index
pub fn (face &FontFace) glyph_index(codepoint int) int
Purpose
Operation on &FontFace: glyph index.
Parameters
face &FontFace- The
FontFace instance used by this call (borrow).
codepoint int- codepoint (int)
Returns
int — index; see the description for its range and special values
(&FontFace) glyph_metrics
pub fn (face &FontFace) glyph_metrics(glyph_id int) GlyphMetrics
Purpose
Operation on &FontFace: glyph metrics. Throws on failure; handle the error or propagate it to the caller.
Parameters
face &FontFace- The
FontFace instance used by this call (borrow).
glyph_id int- glyph_id (int)
Returns
GlyphMetrics — a value of this type
(&FontFace) kerning
pub fn (face &FontFace) kerning(left_gid int, right_gid int) int
Purpose
Execute kerning on &FontFace.
Parameters
face &FontFace- The
FontFace instance used by this call (borrow).
left_gid int- left_gid (int)
right_gid int- right_gid (int)
Returns
int — a value of this type
(&FontFace) glyph_outline
pub fn (face &FontFace) glyph_outline(glyph_id int) GlyphOutline
Purpose
Operation on &FontFace: glyph outline. Throws on failure; handle the error or propagate it to the caller.
Parameters
face &FontFace- The
FontFace instance used by this call (borrow).
glyph_id int- glyph_id (int)
Returns
GlyphOutline — a value of this type