pub struct Text {
pub ol: Outline,
pub gp: Gp,
pub path: Path,
pub ras: Raster,
pub png_decode: Option<PngDecode>,
pub img_scale: Option<ImgScale>,
/* private fields */
}Fields§
§ol: Outlinethe outline buffer of runtime / derived fonts
gp: Gpthe glyph transform used by glyph_path
path: Path§ras: Raster§png_decode: Option<PngDecode>PNG decoder and bilinear scaler for CBDT colour bitmaps (set by the app / ui)
img_scale: Option<ImgScale>Implementations§
Source§impl Text
impl Text
Sourcepub fn set_system_fallback(&mut self, on: bool)
pub fn set_system_fallback(&mut self, on: bool)
look for missing characters in system fonts too (after set_fallback_fonts’ chain)
Sourcepub fn set_fallback_lang(&mut self, tag: &str)
pub fn set_fallback_lang(&mut self, tag: &str)
the language whose fonts the system fallback tries first (“” none)
Sourcepub fn system_fallback(&self) -> bool
pub fn system_fallback(&self) -> bool
whether system fonts are searched for missing characters
Sourcepub fn fallback_active(&self) -> bool
pub fn fallback_active(&self) -> bool
whether run / shaping look for fallback fonts at all
Sourcepub fn fallback_for(&mut self, cp: u32) -> Option<u32>
pub fn fallback_for(&mut self, cp: u32) -> Option<u32>
the first font of the fallback chain that has cp (None: none has it)
Source§impl Text
impl Text
Sourcepub fn gc_usage(&self) -> (usize, usize, usize, usize)
pub fn gc_usage(&self) -> (usize, usize, usize, usize)
gc_usage() -> (entries, the entries at which it starts over, bytes, its arena’s bytes)
Sourcepub fn gc_scale(&self, font: u32, size_fx: i32) -> (f32, f32)
pub fn gc_scale(&self, font: u32, size_fx: i32) -> (f32, f32)
gc_scale(font, size_fx) -> (sx, sy): pixels per font unit, sy snapped so the x-height is whole up to 24 px
Sourcepub fn gc_box(
&mut self,
font: u32,
g: u32,
size: i32,
phase: i32,
) -> Option<[i32; 4]>
pub fn gc_box( &mut self, font: u32, g: u32, size: i32, phase: i32, ) -> Option<[i32; 4]>
gc_box(font, glyph, size_fx, phase) -> {left, top, w, h} (not cached)
Sourcepub fn set_antialias(&mut self, on: bool)
pub fn set_antialias(&mut self, on: bool)
smoothed glyph masks (true, the default) or black-and-white ones (the system’s font smoothing off); a change empties the cache
Sourcepub fn gc_get(&mut self, font: u32, g: u32, size: i32, phase: i32) -> GcRef<'_>
pub fn gc_get(&mut self, font: u32, g: u32, size: i32, phase: i32) -> GcRef<'_>
gc_get(font, glyph, size_fx, phase): the cached mask, rendered on first use
Sourcepub fn gc_get_lcd(
&mut self,
font: u32,
g: u32,
size: i32,
phase: i32,
vertical: bool,
) -> GcRef<'_>
pub fn gc_get_lcd( &mut self, font: u32, g: u32, size: i32, phase: i32, vertical: bool, ) -> GcRef<'_>
gc_get_lcd(font, glyph, size_fx, phase, vertical): the cached subpixel mask (w x h pixels of 3 coverage bytes: left to right, or top to bottom when vertical), rendered on first use; Direct when it is too large for the cache (draw the glyph greyscale)
Source§impl Text
impl Text
Sourcepub fn set_subpixel(&mut self, order: u8)
pub fn set_subpixel(&mut self, order: u8)
the subpixel order of the display (SUBPIXEL_*): RGB / BGR / VRGB / VBGR draw glyphs on opaque (FMT_XRGB) targets with subpixel smoothing, NONE (the default) in greyscale; see lcd.rs for where it applies
Sourcepub fn lcd_tables_exact(&mut self) -> bool
pub fn lcd_tables_exact(&mut self) -> bool
(tests) every byte survives the trip through linear light unchanged
Source§impl Text
impl Text
Sourcepub fn record_n(
&mut self,
rec: &mut GlyphRec,
dc: &mut Dc,
sf: &mut Surface,
x: i32,
y: i32,
s: &[u8],
len: usize,
) -> bool
pub fn record_n( &mut self, rec: &mut GlyphRec, dc: &mut Dc, sf: &mut Surface, x: i32, y: i32, s: &[u8], len: usize, ) -> bool
draw_n’s glyphs appended to rec instead of blended (record.rs); false: one of them cannot be blended from the cache, draw that text with draw_n
Source§impl Text
impl Text
Sourcepub fn font_raster(&self, font: u32) -> FontRaster
pub fn font_raster(&self, font: u32) -> FontRaster
Raster policy of a registered face. Unknown ids follow the fallback face.
Sourcepub fn set_font_raster(&mut self, font: u32, raster: FontRaster) -> bool
pub fn set_font_raster(&mut self, font: u32, raster: FontRaster) -> bool
Change only this face’s rasterization; invalidate cached masks on change. Returns false for an unregistered id. Measuring and caret advances are unchanged.
Source§impl Text
impl Text
Sourcepub fn set_embedded(
&mut self,
fonts: [&'static [u8]; 4],
names: [[&'static str; 5]; 4],
)
pub fn set_embedded( &mut self, fonts: [&'static [u8]; 4], names: [[&'static str; 5]; 4], )
replace the embedded fonts 0..3 (SGF1 or TrueType / OpenType; a style switched at run time): the ids keep their meaning, fonts derived from them (style) take the new metrics, cached glyphs are dropped; each face starts with the legacy raster policy
Sourcepub fn face_count(data: &[u8]) -> i32
pub fn face_count(data: &[u8]) -> i32
font_face_count(data) -> faces (1 for a plain sfnt, n for a TTC / OTC) / ERR_*
Sourcepub fn load_mem(&mut self, data: &[u8], face: u32) -> i32
pub fn load_mem(&mut self, data: &[u8], face: u32) -> i32
font_load_mem(data, face) -> id / ERR_* (the data is copied)
Sourcepub fn load_file(&mut self, path: &str, face: u32) -> i32
pub fn load_file(&mut self, path: &str, face: u32) -> i32
font_load_file(path, face) -> id / ERR_* (ERR_IO when it cannot be read)
Sourcepub fn hdr(&self, font: u32) -> Hdr
pub fn hdr(&self, font: u32) -> Hdr
font_data: the SGF1-compatible header (an unknown id gives font 0)
pub fn upem(&self, font: u32) -> i32
Sourcepub fn glyph(&self, font: u32, cp: u32) -> u32
pub fn glyph(&self, font: u32, cp: u32) -> u32
font_glyph(font, cp) -> glyph (SGF1: fallback glyph, runtime: 0 = .notdef)
Sourcepub fn adv(&self, font: u32, g: u32) -> i32
pub fn adv(&self, font: u32, g: u32) -> i32
font_adv(font, glyph): advance in font units (synthetic bold included)
Sourcepub fn kern(&self, font: u32, g1: u32, g2: u32) -> i32
pub fn kern(&self, font: u32, g1: u32, g2: u32) -> i32
font_kern(font, g1, g2): kerning in font units (signed)
Sourcepub fn kern_table(&self, font: u32, g1: u32, g2: u32) -> i32
pub fn kern_table(&self, font: u32, g1: u32, g2: u32) -> i32
font_kern_table: the ‘kern’ table only (runtime fonts; others: font_kern)
Sourcepub fn layers(&self, font: u32, g: u32, cap: usize, out: &mut Vec<(u32, u32)>)
pub fn layers(&self, font: u32, g: u32, cap: usize, out: &mut Vec<(u32, u32)>)
font_layers(font, glyph, cap) into out: {glyph | LAYER_FG, argb}; empty = draw it normally
Sourcepub fn name(&self, font: u32, which: u32) -> &[u8] ⓘ
pub fn name(&self, font: u32, which: u32) -> &[u8] ⓘ
font_name(font, FN_*) -> UTF-8 (“” when unknown)
Sourcepub fn metrics(&self, font: u32) -> Option<Metrics>
pub fn metrics(&self, font: u32) -> Option<Metrics>
font_metrics(font) -> FONTMETRICS (None when no font exists)
Sourcepub fn metric(&self, font: u32, field: u32) -> i32
pub fn metric(&self, font: u32, field: u32) -> i32
font_metric(font, FM_*) -> one FONTMETRICS field
Sourcepub fn glyph_box(&mut self, font: u32, g: u32) -> Option<[i32; 4]>
pub fn glyph_box(&mut self, font: u32, g: u32) -> Option<[i32; 4]>
glyph_box(font, glyph) -> {xmin, ymin, xmax, ymax} (font units, control box); None = empty. Runtime fonts leave the glyph’s outline in the outline buffer.
Sourcepub fn glyph_path(&mut self, font: u32, g: u32)
pub fn glyph_path(&mut self, font: u32, g: u32)
glyph_path(font, glyph): append the outline to the path, transformed by gp (origin x / y in float pixels, sx / sy float pixels per unit)
Sourcepub fn var_axes(&self, font: u32) -> Vec<VarAxis>
pub fn var_axes(&self, font: u32) -> Vec<VarAxis>
the variation axes of a font (fvar; empty: not a variable font); instances and the fonts derived from them report their variable font’s
Sourcepub fn var_instances(&self, font: u32) -> Vec<VarInstance>
pub fn var_instances(&self, font: u32) -> Vec<VarInstance>
the named instances of a variable font (fvar; empty: none or not variable)
Sourcepub fn var_values(&self, font: u32) -> Vec<f32>
pub fn var_values(&self, font: u32) -> Vec<f32>
the axis values of a font in user units, one per axis of var_axes (an instance’s own, else the defaults)
Sourcepub fn var_coords(&self, font: u32) -> Vec<i16>
pub fn var_coords(&self, font: u32) -> Vec<i16>
the normalized coordinates of an instance: F2Dot14 bits per axis with avar applied (what HarfBuzz’s hb_font_get_var_coords_normalized reports); empty for a variable font itself (its default instance) and for fonts that are not variable
Sourcepub fn vary(&mut self, font: u32, values: &[([u8; 4], f32)]) -> i32
pub fn vary(&mut self, font: u32, values: &[([u8; 4], f32)]) -> i32
an instance of a variable font with axis values in user units (tag, value): axes not named keep font’s values (an instance’s, else the defaults); values are clamped to their axis, unknown tags ignored -> font id / ERR_*. All-default coordinates give the variable font itself, the same coordinates the same id; synthetic styles of font (style) carry over; a font that is not variable gives itself. Each instance has its own glyph cache entries and metrics (MVAR); unloading the variable font unloads its instances.
Sourcepub fn vary_named(&mut self, font: u32, i: usize) -> i32
pub fn vary_named(&mut self, font: u32, i: usize) -> i32
named instance i of a variable font (var_instances) -> id / ERR_* (ERR_FAIL: no such instance)
Source§impl Text
impl Text
Sourcepub fn set_shaping(&mut self, enabled: bool) -> bool
pub fn set_shaping(&mut self, enabled: bool) -> bool
Enable OpenType shaping for measure, draw, hit testing and carets. Returns the previous state so callers can scope this to a document’s text tool.
pub fn set_fallback_fonts(&mut self, fonts: &[u32])
Source§impl Text
impl Text
Sourcepub fn new(fonts: [&'static [u8]; 4], names: [[&'static str; 5]; 4]) -> Text
pub fn new(fonts: [&'static [u8]; 4], names: [[&'static str; 5]; 4]) -> Text
font_init: register FONT_REG, FONT_SEMI, FONT_BOLD, FONT_ICON (the style’s embedded fonts, SGF1 or TrueType/OpenType) with their names (family, style, full, typographic family / style). Each face starts with the legacy raster policy.
Sourcepub fn measure(&mut self, s: &str) -> i32
pub fn measure(&mut self, s: &str) -> i32
text_measure: advance of the run (24.8), up to NUL / newline
pub fn width_n(&mut self, s: &[u8], len: usize) -> i32
Sourcepub fn draw(
&mut self,
dc: &mut Dc,
sf: &mut Surface,
x: i32,
y: i32,
s: &[u8],
) -> i32
pub fn draw( &mut self, dc: &mut Dc, sf: &mut Surface, x: i32, y: i32, s: &[u8], ) -> i32
text_draw(x, y = baseline, s) -> width px
Sourcepub fn draw_n(
&mut self,
dc: &mut Dc,
sf: &mut Surface,
x: i32,
y: i32,
s: &[u8],
len: usize,
) -> i32
pub fn draw_n( &mut self, dc: &mut Dc, sf: &mut Surface, x: i32, y: i32, s: &[u8], len: usize, ) -> i32
text_draw_n(x, y, s, len) -> width px
Sourcepub fn caret_x(&mut self, s: &[u8], index: usize) -> i32
pub fn caret_x(&mut self, s: &[u8], index: usize) -> i32
text_caret_x(s, index) -> x px (rounded) of the caret before byte index
Sourcepub fn hit(&mut self, s: &[u8], len: Option<usize>, x: i32) -> usize
pub fn hit(&mut self, s: &[u8], len: Option<usize>, x: i32) -> usize
text_hit(s, len, x) -> byte index whose caret position is closest to x (len None: up to NUL)