[cairo] Custom logical / inked rect for PangoRenderer subclass?
pcjc2 at cam.ac.uk
Tue Dec 23 08:38:20 PST 2008
On Tue, 2008-12-23 at 00:43 -0500, Behdad Esfahbod wrote:
> Peter Clifton wrote:
> > Hi,
> > Another noob-pango-user question I'm afraid..
> > I've got a custom PangoRenderer which adds an attribute for drawing
> > overbars on some text in CAD drawings. What concerns me now is that I
> > need an accurate way to measure the text for invalidating on-screen
> > regions, and recording just were the text objects are on our canvas (so
> > we know what to repaint when we get an expose event).
> > It wasn't obvious to me that I could provide new information for the
> > inked / logical rectangles retrieved with
> > pango_layout_get_extents() or pango_layout_get_pixel_extents().
> You currently can't. I'll look into fixing that if you open a bug.
Thanks Behdad, filed as http://bugzilla.gnome.org/show_bug.cgi?id=565478
I'm not entirely sure what the interface I'm asking for ought to look
like, so please forgive my vagueness.
> > For now, it seems to work, since I'm (mostly by luck) keeping the
> > overbars inside the logical extents of the rendered text.
> > Is it always the case that the logical extents are the same or larger
> > than the inked extents? (Or is it possible that inked extents exceed
> > logical extents?). For now, I'm basically just invalidating the logical
> > extents.
> No, definitely not.
No - should have guessed as much. I guess I'll take the
bounding-rectangle of the inked and logical extents and invalidate that
for now. My metric for placing the overbar is w.r.t the logical extents,
so I ought to be able to ensure the overbar remains within those.
In any case, I already add a few pixels slack around each invalidate
request, as I'm using that as a cheat to avoid having to track the
markers we draw where lines intersect, and rubber-banding grips on the
end of lines. That ought to help keep me free of rendering artifacts,
even if it leaves something to be desired in terms of correctness.
W.r.t. positioning overbars, I guess its about the same case as where
you might add an accent to a capitalised character - not sure if there
is some better metric to use for this purpose - or if I should be
attempting to measure the cap height of the given font.
I don't know how that would work if you didn't have a latin character
set though. (Nor for that matter whether drawing an "overbar" over a
signal name is common practice to mean "inverted signal" in other
languages). Hmm.. what is an overbar in a vertical layout?!
> > Behdad, you mentioned bug #457990 before.. is pango_layout_get_extents()
> > affected by that bug?
> It is, but very marginally. In that the height of empty lines does not scale
> with ctm.
> > I'm having difficulty getting sensible bounds from
> > that when I have a non identity CTM. Setting cairo_set_font_matrix ()
> > with my world to device scaling factors didn't seem to affect its output
> > either.
I think I was (and probably still am) doing something wrong. cairo_scale
followed by pango_cairo_update_layout () didn't seem to want to produce
me a different glyph size. I had some luck with
pango_cairo_context_set_resolution (), but still can't seem to get
hinting to behave.
Our font size is basically defined in points (which can be translated to
our internal coordinate system of mils. (inch/1000).
Our cairo CTM is identity, since due to the legacy rendering code, and
the fact we're hinting to a pixel grid anyway, that made sense.
How do I best specify to cairo / pango that I want an "X" pt sized font,
tell it enough about my cairo setup and desired "X" pt -> pixels
scaling, that I can produce uniform positioning when hinting is turned
I tried specifying font sizes in raw pixels to start with, (adding px to
the size quoted to pango_font_description_from_string (), but this
seemed to give layout consistency issues due to rounding of the size in
pixels. (Although I tried specifying the size with floating point as
well as integers)
I'm still seeing layout consistency issues with the way I'm specifying
things now. I think I have hinting turned off:
/* Switch off metric hinting */
options = cairo_font_options_create ();
cairo_get_font_options (cr, options);
cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_OFF);
cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_NONE);
cairo_set_font_options (cr, options);
This is before I use pango_cairo_create_layout (cr) in my bounds
measuring routine, and in the rendering routine, before a
pango_cairo_update_layout () (the layout / context is cached).
PS. Code is here:
(Old way, specifying font size in pixels)
(Attempt at a new way - commitdiff)
Thanks for your help!
Electrical Engineering Division,
University of Cambridge,
9, JJ Thomson Avenue,
Tel: +44 (0)7729 980173 - (No signal in the lab!)
More information about the cairo