GNOME Bugzilla – Bug 478865
Drastically reduce number of PangoFont objects created for rotating text
Last modified: 2007-10-24 20:58:42 UTC
Currently rotating or resizing text totally breaks down with pango calling FcFontSort() at each rotation/size... We'll deal with size later. For rotation, if metrics hinting is off, pangofc-fontmap.c should ignore rotation. That is, rotate the matrix such that x,0 maps to x',0, and then use that matrix in hash lookup... The resulting font has the same metrics as the desired font, but a scaled_font with a different ctm. Fortunately that's not a problem as cairo_set_scaled_font() ignores scaled_font's ctm. Toshok is telling me that an optimization to this effect has given them a boost from 20fps to 60fps in a rotating-text demo in Moonlight.
Created attachment 95932 [details] [review] Patch from toshok Unfortunately this doesn't work. With hinted metrics, we cannot use the same font for different angles. It can be made to work when metrics hinting is off though. But even then the matrix should not be ignored, it may have a shear, etc... pango_cairo_font_get_scaled_font() docs need to be updated to say that the ctm in the scaled_font may not match that of user's.
we aren't using the same font, but the same FcPattern. Those seem to be completely independent of everything in the matrix except for the scale. I just noticed a potential problem, in that maybe we should make the hash/equal methods use something like: double scaled_size = key.size * scale_factor / PANGO_SCALE; instead of just using scale_factor. The creation of the fonts themselves still takes place as it should - and you do still get different fonts for different angles of rotations, with their own hinting/etc. This takes place as usual in pango_fc_font_map_load_fontset (or rather in pango_fc_font_map_new_font - the place where the full matrix is applied to the FcPattern.) The optimization just keeps us from creating new FcPatterns for each rotation. The code to create the fontset doesn't use any part of the matrix except the scale, so there's no reason to use more than that in the hash functions. Note that the font hash functions still use the entire matrix. Only the fontset ones are changed.
2007-10-24 Behdad Esfahbod <behdad@gnome.org> Bug 478865 – Drastically reduce number of PangoFont objects created for rotating text * pango/pangofc-fontmap.c (fontset_hash_key_equal), (fontset_hash_key_hash), (fontset_hash_key_copy), (get_scaled_size), (pango_fc_font_map_get_patterns): Only keep scaled-size in fontset hash, instead of unscaled-size and context matrix.
Created attachment 97796 [details] [review] Committed patch Here is what I committed.
2007-10-24 Behdad Esfahbod <behdad@gnome.org> Bug 478865 – Drastically reduce number of PangoFont objects created for rotating text * pango/pangofc-fontmap.c (fontset_hash_key_hash), (get_scaled_size), (pango_fc_font_map_get_patterns): Use a Pango-unit int for scaled-size instead of double. Merges even more queries...