[cairo] Another possible issue with Cairo / Pango

Kieran McCusker kieran.mccusker at kwest.info
Fri Jan 4 09:09:35 PST 2008


I am using Cairo/Pango to produce graphs and what I do is measure text 
elements before drawing to calculate graph sizes.

What I find is that if I use the size reported by Pango to draw the text 
will sometimes wrap. To get around it I am having to use the following 
code :-

def measure_text(text,width = @body_rect.width,alignment = 
@layout.markup = text
@layout.alignment = alignment
@layout.width = width * Pango::SCALE
@layout.font_description = 
ink_rect, logical_rect = @layout.pixel_extents
height = logical_rect.height
extra = 0
if width > logical_rect.width
width = logical_rect.width
while true
@layout.width = (width+extra) * Pango::SCALE
ink_rect, logical_rect = @layout.pixel_extents
break if height == logical_rect.height || extra > 20
RAILS_DEFAULT_LOGGER.warn("Need extra> #{width} #{extra} #{height} 
#{logical_rect.height} #{text}")
extra += 1

Using 'Luxi Sans 9' with no scaling what I get (for example) is

Need extra> 77 0 30 45 Problems with neighbours
Need extra> 77 1 30 45 Problems with neighbours
Need extra> 77 2 30 45 Problems with neighbours

I am using fc7.x86_64 with cairo 1.4.10 and pango 1.16.4. If needed I 
can write a full test program.

Many thanks



Behdad if you read this, have you had any time to look at the 
overkerning issue (Bug 341481 – pangocairo kerning problem with 
nonidentity scaling)

More information about the cairo mailing list