[cairo-bugs] [Bug 5495] Need cairo_scaled_font_text_extents

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Thu Jan 5 17:19:19 PST 2006


Please do not reply to this email: if you want to comment on the bug, go to    
       
the URL shown below and enter yourcomments there.     
   
https://bugs.freedesktop.org/show_bug.cgi?id=5495          
     




------- Additional Comments From cworth at cworth.org  2006-01-06 12:15 -------
I have had a note in the cairo TODO for quite a while:

    * cairo_text_glyphs:

        It would function as a sort of bridge between the toy and the
        real text APIs:

        >       void
        >       cairo_text_glyphs (cairo_t *cr, const unsigned char *utf8,
        >                          cairo_glyph_t *glyphs, int *num_glyphs);
        >
        > with num_glyphs as an input-output parameter. The behavior of this
        > function would be such that calling:
        >
        >       cairo_text_glyphs (cr, string, glyphs, &num_glyphs);
        >       cairo_show_glyphs (cr, glyphs, num_glyphs);
        >
        > would be equivalent too:
        >
        >       cairo_show_text (cr, string);
        >
        > as long as the original size of glyphs/num_glyphs was large
        > enough.

I've always liked this idea as it would allow for doing things such as
text-on-a-path while still interacting with the cairo API at the "toy" level of
text, not glyphs.

However, as it turns out, the semantics I defined above, (the sequence of
cairo_text_glyphs; cairo_show_glyphs being equivalent to cairo_show_text), looks
infeasible. The problem is that the cairo_glyph_t structure does not reference a
font, so it's inadequate for implementing any chars-to-glyph function that
references multiple fonts. (The original proposal for cairo_glyph_t did have a
font in it, but I think we removed it since it was regarded as wasteful since
pango would only call cairo_show_glyphs with the same font in every glyph).

I guess the chars-to-glyphs function could return a list of font,glyph-list
pairs, but that gets to be pretty awkward in a C API.

So, those are the current frustrations I'm having with the function I originally
wanted. (Meanwhile, Owen had other objections to a chars-to-glyphs function in
cairo, but I don't currently recall what they were.)

But back to your needs. It appears that any chars-to-glyphs function that
requires a cairo_t wouldn't help you very much, since you already have a
separate solution that does not require chars-to-glyphs but does require a dummy
cairo_t. Correct?

So, another possibility would be a public version of an existing internal
function in cairo:

cairo_status_t
_cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t *scaled_font,
                                   double               x,
                                   double               y,
                                   const char          *utf8,
                                   cairo_glyph_t      **glyphs,
                                   int                 *num_glyphs)

This interface is obviously restricted to a single font, so it avoids the
font-merging problems of my desired cairo_text_glyphs function described above.

And it would be a rather simple change to make an appropriately modified public
interface to this. I'm open to suggestions on what the interface should look
like. Should it be exactly as above?

We generally try to stash status values in the object being acted upon, but we
also avoid doing that for functions that nominally are not modifiers of that
object. So this might be one of the rare cases where we actually return a status
value and expect the user to check in. Since this is off in the
already-"hard"-to-use scaled-font piece of cairo's API, I think I would be fine
with that decision.

Alternately, given that this function already exists in cairo, along with
cairo_scaled_font_glyph_extents, it doesn't look like it would be too hard to
implement cairo_scaled_font_text_extents instead. It probably should take an x,y
pair in contrast to cairo_text_extents (which gets the x,y from the path's
current point).

Anyway, there are some thoughts from me. Let's get a patch together and look at
it on the list. (Or if the various cairo_scaled_font_get_* functions from bug
#5496 give you a not-too-ugly solution in pango, then we can avoid making a
decision here.)

-Carl
          
     
     
--           
Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email         
     
------- You are receiving this mail because: -------
You are the QA contact for the bug, or are watching the QA contact.


More information about the cairo-bugs mailing list