struct

Tryst::FontHandle

Inherits Struct < Value < Object

A font resolved once, for the duration of a measurement pass - the batch counterpart to Interp#text_width/#font_metrics/#measure_chars, which each pay their own Tk_GetFont/Tk_FreeFont pair per call. A per-glyph layout loop doing that once per glyph is exactly the cost #with_font exists to amortize: resolve the font once, measure many glyphs against this handle, free it once.

app.with_font("TkDefaultFont") do |handle|
  text.each_char.sum { |char| handle.text_width(char.to_s) }
end

Never construct directly - only valid for the lifetime of the #with_font block it was yielded to, since the underlying Tk_Font is freed the moment that block returns.

Constructors

new(tkfont : LibTk::Font)

@api private - construct via Interp#with_font/App#with_font.

Source

Instance methods

font_metrics

See Interp#font_metrics.

Source
measure_chars(text : String, max_pixels : Int32, partial_ok : Bool = false, whole_words : Bool = false, at_least_one : Bool = false) : NamedTuple(bytes: Int32, width: Int32)

See Interp#measure_chars.

Source
text_width(text : String) : Int32

See Interp#text_width.

Source