Skip to main content

Text

Struct Text 

Source
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: Outline

the outline buffer of runtime / derived fonts

§gp: Gp

the 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

Source

pub fn set_system_fallback(&mut self, on: bool)

look for missing characters in system fonts too (after set_fallback_fonts’ chain)

Source

pub fn set_fallback_lang(&mut self, tag: &str)

the language whose fonts the system fallback tries first (“” none)

Source

pub fn system_fallback(&self) -> bool

whether system fonts are searched for missing characters

Source

pub fn fallback_active(&self) -> bool

whether run / shaping look for fallback fonts at all

Source

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

Source

pub fn gc_flush(&mut self)

gc_flush(): forget every cached glyph

Source

pub fn gc_usage(&self) -> (usize, usize, usize, usize)

gc_usage() -> (entries, the entries at which it starts over, bytes, its arena’s bytes)

Source

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

Source

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)

Source

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

Source

pub fn antialias(&self) -> bool

whether glyph masks are smoothed

Source

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

Source

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

pub fn gc_get_bitmap( &mut self, font: u32, g: u32, size: i32, ) -> Option<&GcEntry>

gc_get_bitmap(font, glyph, size_fx): the PARGB colour bitmap entry or None

Source§

impl Text

Source

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

Source

pub fn subpixel(&self) -> u8

the subpixel order in use (SUBPIXEL_*)

Source

pub fn lcd_tables_exact(&mut self) -> bool

(tests) every byte survives the trip through linear light unchanged

Source§

impl Text

Source

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

pub fn record_icon( &mut self, rec: &mut GlyphRec, dc: &mut Dc, sf: &mut Surface, cp: u32, x: i32, y: i32, size_fx: i32, ) -> bool

icon_draw’s glyph appended to rec (record_n)

Source

pub fn glyphs(&self) -> GlyphView<'_>

the glyph cache read-only, for blending recorded glyphs on other threads

Source§

impl Text

Source

pub fn font_raster(&self, font: u32) -> FontRaster

Raster policy of a registered face. Unknown ids follow the fallback face.

Source

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

Source

pub fn register(&mut self, data: &'static [u8]) -> i32

font_register(data) -> id / -1

Source

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

Source

pub fn face_count(data: &[u8]) -> i32

font_face_count(data) -> faces (1 for a plain sfnt, n for a TTC / OTC) / ERR_*

Source

pub fn load_mem(&mut self, data: &[u8], face: u32) -> i32

font_load_mem(data, face) -> id / ERR_* (the data is copied)

Source

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)

Source

pub fn unload(&mut self, id: u32) -> i32

font_unload(id) -> 0 / -1

Source

pub fn count(&self) -> u32

font_count() -> ids in use are below this value

Source

pub fn valid(&self, id: u32) -> bool

font_valid(id): the id names a registered font

Source

pub fn hdr(&self, font: u32) -> Hdr

font_data: the SGF1-compatible header (an unknown id gives font 0)

Source

pub fn upem(&self, font: u32) -> i32

Source

pub fn glyph(&self, font: u32, cp: u32) -> u32

font_glyph(font, cp) -> glyph (SGF1: fallback glyph, runtime: 0 = .notdef)

Source

pub fn has(&self, font: u32, cp: u32) -> bool

font_has(font, cp)

Source

pub fn adv(&self, font: u32, g: u32) -> i32

font_adv(font, glyph): advance in font units (synthetic bold included)

Source

pub fn kern(&self, font: u32, g1: u32, g2: u32) -> i32

font_kern(font, g1, g2): kerning in font units (signed)

Source

pub fn kern_table(&self, font: u32, g1: u32, g2: u32) -> i32

font_kern_table: the ‘kern’ table only (runtime fonts; others: font_kern)

Source

pub fn is_color(&self, font: u32) -> bool

font_is_color: COLR layers or CBDT bitmaps

Source

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

Source

pub fn name(&self, font: u32, which: u32) -> &[u8] ⓘ

font_name(font, FN_*) -> UTF-8 (“” when unknown)

Source

pub fn metrics(&self, font: u32) -> Option<Metrics>

font_metrics(font) -> FONTMETRICS (None when no font exists)

Source

pub fn metric(&self, font: u32, field: u32) -> i32

font_metric(font, FM_*) -> one FONTMETRICS field

Source

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.

Source

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)

Source

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

Source

pub fn var_instances(&self, font: u32) -> Vec<VarInstance>

the named instances of a variable font (fvar; empty: none or not variable)

Source

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)

Source

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

Source

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.

Source

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

pub fn style(&mut self, font: u32, flags: u32) -> i32

font_style(font, FS_) -> id / ERR_

Source§

impl Text

Source

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.

Source

pub fn set_fallback_fonts(&mut self, fonts: &[u32])

Source

pub fn selection_spans( &mut self, text: &[u8], start: usize, end: usize, ) -> Vec<(i32, i32)>

Visual spans for a logical UTF-8 selection. Mixed bidi text may require disjoint rectangles; the two endpoint carets alone are not sufficient.

Source§

impl Text

Source

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.

Source

pub fn set_font(&mut self, font: u32, size_fx: i32)

text_font(font, size_fx)

Source

pub fn get_font(&self) -> (u32, i32)

text_get_font() -> (font, size_fx)

Source

pub fn ascent(&self) -> i32

ceil(ascender px)

Source

pub fn descent(&self) -> i32

ceil(descender px), positive

Source

pub fn line_h(&self) -> i32

round((asc - desc + gap) px)

Source

pub fn measure(&mut self, s: &str) -> i32

text_measure: advance of the run (24.8), up to NUL / newline

Source

pub fn measure_n(&mut self, s: &[u8], len: usize) -> i32

text_measure_n(s, len)

Source

pub fn width(&mut self, s: &str) -> i32

text_width: px, rounded up

Source

pub fn width_n(&mut self, s: &[u8], len: usize) -> i32

Source

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

Source

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

Source

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

Source

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)

Source

pub fn decor( &self, dc: &Dc, sf: &mut Surface, x: i32, y: i32, w: i32, flags: u32, )

text_decor(x, y, w, flags): underline / strikeout rectangles of the current font and size (filled from x, w px long; y = baseline)

Source

pub fn icon_draw( &mut self, dc: &mut Dc, sf: &mut Surface, cp: u32, x: i32, y: i32, size_fx: i32, )

icon_draw(cp, x, y, size_fx): the icon’s em box has its top-left corner at x, y

Auto Trait Implementations§

§

impl !RefUnwindSafe for Text

§

impl !UnwindSafe for Text

§

impl Forget for Text

§

impl Freeze for Text

§

impl Send for Text

§

impl Sync for Text

§

impl Unpin for Text

§

impl UnsafeUnpin for Text

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.