Skip to content

cairo toy text API non-functional: textExtents()/fontExtents() return {} (empty) #466

Description

@romgrk

The cairo "toy" text API is non-functional through node-gtk's bundled cairo bindings. Context.textExtents() and Context.fontExtents() return an empty object {} (none of the width / height / x_advance / ascent / … fields), so text can't be measured, and showText() renders nothing. PangoCairo works and is currently the only way to measure/draw text.

Minimal repro

import cairo from 'gi:cairo-1.0'

const surface = new cairo.ImageSurface(cairo.Format.ARGB32, 200, 100)
const cr = new cairo.Context(surface)
cr.selectFontFace('sans-serif', cairo.FontSlant.NORMAL, cairo.FontWeight.NORMAL)
cr.setFontSize(24)

console.log('textExtents:', JSON.stringify(cr.textExtents('Hello World')))
console.log('fontExtents:', JSON.stringify(cr.fontExtents()))

Actual

textExtents: {}
fontExtents: {}

showText('Hello') likewise produces no glyphs.

Expected

  • textExtents('Hello World') returns a cairo_text_extents_t-shaped object with non-zero width / height / x_advance / x_bearing / …
  • fontExtents() returns ascent / descent / height / max_x_advance / max_y_advance
  • showText() renders glyphs.

Looks like the cairo_text_extents_t / cairo_font_extents_t out-structs aren't being converted to JS (an empty object is returned regardless of input).

Environment

  • node-gtk 3.0.0 (commit 9741a54)
  • Node.js v22.22.3, ESM (node --import node-gtk/register)
  • GTK 4.22.4, Linux x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions