[cairo] Another possible issue with Cairo / Pango
Behdad Esfahbod
behdad at behdad.org
Fri Jan 4 13:57:28 PST 2008
On Fri, 2008-01-04 at 12:09 -0500, Kieran McCusker wrote:
> Hi
>
> 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 :-
Umm, what kind of horrible language and indentation is this? I can't
read the code without my eyes hurting. I'll be happy to review your C
or Python snippet though.
> def measure_text(text,width = @body_rect.width,alignment =
> Pango::Layout::ALIGN_LEFT)
> @layout.markup = text
> @layout.alignment = alignment
> @layout.width = width * Pango::SCALE
> @layout.font_description =
> Pango::FontDescription.new(@current_style.font_name)
> @cr.update_pango_layout(@layout)
> 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
> @cr.update_pango_layout(@layout)
> 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
> end
> end
> Rectangle.new(logical_rect.width+extra,logical_rect.height)
> end
>
> 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
>
> Kieran
>
> P.s.
>
> Behdad if you read this, have you had any time to look at the
> overkerning issue (Bug 341481 – pangocairo kerning problem with
> nonidentity scaling)
Sigh, no.
--
behdad
http://behdad.org/
"Those who would give up Essential Liberty to purchase a little
Temporary Safety, deserve neither Liberty nor Safety."
-- Benjamin Franklin, 1759
More information about the cairo
mailing list