[cairo] On the behaviour of cairo_scaled_font_create with regards to font options

Behdad Esfahbod behdad at behdad.org
Sat Jul 7 17:52:48 PDT 2007


On Fri, 2007-02-23 at 04:10 -0500, David Turner wrote: 
> Hello everyone,
> 
> I'm reaching completion of my changes to Cairo's FreeType/FontConfig backend; The code
> runs well but there is a notable difference from the current implementation that I don't
> know how to interpret correctly.
> 
> In the current implementation, if I use cairo_ft_font_face_create_for_pattern() with a
> source pattern that has FC_ANTIALIAS set to FALSE, this setting is recorded internally,
> and cannot be overriden later in scaled fonts. What I mean is this:
> 
>     //  create FcPattern without anti-aliasing and the corresponding font face
> 
>     .. create 'pattern'
>     FcPatternDel (pattern, FC_ANTIALIAS)
>     FcPatternAdd (pattern, FC_ANTIALIAS, FC_FALSE);
> 
>     font_face = cairo_ft_font_face_create_for_pattern (pattern);
> 
>     // create a scaled font using CAIRO_ANTIALIAS_GRAY as an option
>     font_options = cairo_font_options_create ();
>     cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
> 
>     scaled_font = cairo_scaled_font_create (font_face, &some_matrix, &some_ctm, font_options);
> 
>     // rendering will NOT be ANTIALIASED !!
> 
> I find it very strange since none of the other font backends seem to ignore the
> used-provided font options when creating a scaled font.
> 
> Is this a bug, or even desirable. I find it extremely confusing, and an un-needed special-case.
> 
> It seems the only alternative is to explicitely alter the pattern depending on your
> desired font options, *before* creating the font_face itself. This is exactly what the
> test "ft-text-antialias-none" does, with something that looks like:
> 
>     FcConfigSubstitute (NULL, pattern, FcMatchPattern);
> 
>     cairo_ft_font_options_substitute (font_options, pattern);
> 
>     FcDefaultSubstitute (pattern);
>     resolved = FcFontMatch (NULL, pattern, &result);
> 
> it also seems that cairo_ft_font_options_substitute's raison-d'être is only to support
> this weird special-case.
> 
> So, should we keep this behaviour as is, or should we fix it ?

Hi David,

I'm trying to get back to reviewing your cairo-ft rewrite, so we need to
resolve this issue first.

>From my understanding the reason for the skewed pattern is that
cairo_font_face_t is built for a fontconfig pattern and the pattern is
never touched anymore during scaled_font creation.  So, to have the
fontconfig configuration stuff work properly, one needs to know all the
font options before creating font_face_t.

What you suggest (to override pattern options with font-options during
scaled font creation) works, except that some fontconfig configurations
won't work anymore.

Given the way fontconfig works (that you can totally choose different
fonts based on anything (size, etc...)), I don't see how this can be
fixed without regression.


> Thanks in advance,
> 
> - David Turner
> - The FreeType Project  (www.freetype.org)
-- 
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