The gnocl::cairo command is not intended to be some form of canvas object, but a means of drawing onto images for display on screen used perhaps in the creation of widgets or images. Bearing in mind the relatively small number of actions required for this task, it's reasonable to assume that the overhead of making multiple calls to the gnocl::cairo command is a worthwhile compromise.
In response to the problem of how to get the extents of rendered text back from Cairo I came up with the solution highlighted in the following code:
set pb(1) [gnocl::pixBuf new -width 256 -height 256]
set myString "Peter Piper picked a peck of pickled peppers."
set actions "
select_font_face {Sans normal bold}
set_font_size 15.0
text_extents $myString"
array set extents [gnocl::cairo $pb(1) -actions $actions]
In the example above, the following values were obtained.
extents(height) = 14.0
extents(width) = 320.0
extents(x_advance) = 322.0
extents(x_bearing) = 1.0
extents(y_advance) = 0.0
extents(y_bearing) = -11.0
In response to the problem of how to get the extents of rendered text back from Cairo I came up with the solution highlighted in the following code:
set pb(1) [gnocl::pixBuf new -width 256 -height 256]
set myString "Peter Piper picked a peck of pickled peppers."
set actions "
select_font_face {Sans normal bold}
set_font_size 15.0
text_extents $myString"
array set extents [gnocl::cairo $pb(1) -actions $actions]
In the example above, the following values were obtained.
extents(height) = 14.0
extents(width) = 320.0
extents(x_advance) = 322.0
extents(x_bearing) = 1.0
extents(y_advance) = 0.0
extents(y_bearing) = -11.0
Comments