dymokomi/luce-browser-render
Source of release 0.6.1
0.6.1 / src / web_fonts / sk_font.lucb
#==============================================================================================
#
# sk_font - the parts of Skia's SkFont that LibGfx uses: font metrics, measuring text, glyph
# paths and text-blob bounds, with Skia's FreeType backend's numbers
#
# DESCRIPTION:
# New code of the luce-browser port (DESIGN.md §6.7, §7.1). Gfx::Font asks an SkFont for
# its metrics (SkFont::getMetrics), the advance of "0" (SkFont::measureText) and glyph
# paths (SkFont::getPath); GlyphRun asks SkTextBlob for its bounds. Ladybird's test mode
# forces Skia's FontConfig font manager, so these are the numbers of Skia's FreeType
# scaler context (SkFontHost_FreeType.cpp), which luce-fonts' opentype module reproduces
# float for float (its scaler.lucb and glyf.lucb): an SkFont here is a face and a size.
#
#==============================================================================================
## An SkFont over `typeface` at `size` pixels.
pub func sk_font_make(typeface: const SkTypeface*, size: f32) -> SkFont:
return SkFont(typeface = typeface, size = size)
## SkFont::getMetrics (the fields LibGfx and the display list read).
pub func sk_font_get_metrics(font: const SkFont*) -> opentype.SfntMetrics:
let typeface = font.typeface else return opentype.SfntMetrics()
return opentype.sfnt_face_metrics(typeface.face, font.size)
## The advance of `glyph` in pixels as Skia's glyph cache has it for the font.
pub func sk_font_glyph_advance(font: const SkFont*, glyph: u32) -> f32:
let typeface = font.typeface else return 0.0
return opentype.sfnt_face_hinted_advance(typeface.face, glyph, font.size)
## SkFont::measureText of `text` (UTF-8 bytes of ASCII here): the sum of the glyph advances.
pub func sk_font_measure_ascii(font: const SkFont*, text: const u8[]) -> f32:
let typeface = font.typeface else return 0.0
return opentype.sfnt_face_measure_ascii(typeface.face, font.size, text)
## SkFont::getPath: the outline of `glyph` at the font's size (free it with its release).
pub func sk_font_get_path(font: const SkFont*, glyph: u32) -> opentype.GlyphPath:
let typeface = font.typeface else return opentype.GlyphPath()
return opentype.sfnt_face_glyph_path(typeface.face, glyph, font.size)
## SkFontPriv::GetFontBounds: the face's bounding box (head) at the font's size, in Skia's
## y-down coordinates: (left, top, right, bottom).
pub func sk_font_bounds(font: const SkFont*) -> (f32, f32, f32, f32):
let typeface = font.typeface else return (0.0, 0.0, 0.0, 0.0)
return opentype.sfnt_face_bounds(typeface.face, font.size)