[cairo] Correction of '_cairo_quartz_ucs4_to_index'.

Andrea Canciani ranma42 at gmail.com
Sat Mar 18 09:25:35 UTC 2017


On Wed, Mar 15, 2017 at 12:14 PM, Clerk Ma <clerkma at gmail.com> wrote:

> I found that '_cairo_quartz_ucs4_to_index' in cairo-quartz-font.c was
> broken
> (ucs4 was cast to uint16_t/UniChar). A workable patch is here:
>
> static unsigned long
> _cairo_quartz_ucs4_to_index (void *abstract_font,
>                  uint32_t ucs4)
> {
>     cairo_quartz_scaled_font_t *font = (cairo_quartz_scaled_font_t*)
> abstract_font;
>     cairo_quartz_font_face_t *ffont = _cairo_quartz_scaled_to_face(font);
>     CGGlyph glyph[2];
>     UniChar utf16[2];
>
>     size_t len = CFStringGetSurrogatePairForLongCharacter (ucs4, utf16) ?
> 2 : 1;
>     CGFontGetGlyphsForUnicharsPtr (ffont->cgFont, utf16, glyph, len);
>
>     return glyph[0];
> }
>

The lack of documentation on CGFontGetGlyphsForUnichars() (and its older
implementation CGFontGetGlyphsForUnicodes()) left me wondering if it is
actually able to handle surrogate pairs or not.
I wrote a test (attached) that confirms they both work as expected :D
Even on 10.4 you can get the glyphs for surrogate pairs using
CGFontGetGlyphsForUnicodes()

Unfortunately CFStringGetSurrogatePairForLongCharacter() is only available
since 10.6.
Luckily it is easy to refactor the UCS4 to UTF16 conversion from
cairo-unicode.c into a separate function and reuse it :)

I published a branch that should fix this at
https://cgit.freedesktop.org/~ranma42/cairo/log/?h=quartz-ucs4-to-utf16
Can you confirm it fixes the issue?

A better fix would probably involve CTFontGetGlyphsForCharacters(), but
that is probably best suited for the (much desired, but not really a high
priority in my todo-list) CoreText-based font backend.

Andrea
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20170318/610f1c12/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: minitest.c
Type: text/x-csrc
Size: 1061 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20170318/610f1c12/attachment.c>


More information about the cairo mailing list