After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 347237 - (cairo_font_face_t) Making Pango use a given cairo_font_face_t
(cairo_font_face_t)
Making Pango use a given cairo_font_face_t
Status: RESOLVED WONTFIX
Product: pango
Classification: Platform
Component: general
unspecified
Other Linux
: Normal enhancement
: Small API
Assigned To: pango-maint
pango-maint
Depends on: 337593 347236
Blocks: 353293 598695
 
 
Reported: 2006-07-11 16:18 UTC by Behdad Esfahbod
Modified: 2015-05-12 19:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
ugly initial patch (16.47 KB, patch)
2007-07-05 15:14 UTC, Behdad Esfahbod
none Details | Review

Description Behdad Esfahbod 2006-07-11 16:18:33 UTC
The feature request is to let a given font be used to render text, instead of Pango searching for suitable fonts.

The solution I came up is:

Add a new PangoCairoFontMap implementation that uses a single font face:

PangoFontMap *
pango_cairo_font_map_create_for_cairo_font_face (cairo_font_face_t *);

Such a font map then can be used to create a context and then a layout that will only use the specificed font face.  Backend-specific cairo API can be used to create a cairo_font_face_t for a variety of uses.  Given a PangoCairoFont, pango_cairo_font_get_scaled_font() can be used to fetch the scaled font and then from that the cairo_font_face_t and passed to this proposed function.  So, given a PangoFont (cairo backend only), you can create a layout that only uses that font.
Comment 1 Behdad Esfahbod 2007-06-13 23:07:16 UTC
So Owen and I discussed this further.  Owen had the idea to create PangoAttrFontset and then something like pango_cairo_font_map_create_font_set_for_face() or something, but that doesn't work because PangoFontSet has PangoFonts inside and a PangoFont is fixed in size.  That puts a lot of burden on the user.

What becomes obvious then is that we want a special kind of PangoFontDescription that when reaches the pangocairo fontmaps creates a font that uses the provided cairo font face.  This makes sense, but there are two main obstacles implementing it:

  * PFD is not a GObject.  So adding needed flexibility requires some nasty hacks.  My current approach is something called pango_font_description_set_domain(), but as I go further implementing it, I get to dislike it more.  We'll seee.

  * Even when the above is done, we've got to punch all abstract fontmaps (fc, win32, atsui) to pass-through this special PFD to the fontmap object that will interpret it.  Clumsy.
Comment 2 Behdad Esfahbod 2007-07-05 15:14:38 UTC
Created attachment 91249 [details] [review]
ugly initial patch

I was doing a quick cruel hack to get this working but was stuck at handling coverage.
Comment 3 Behdad Esfahbod 2007-08-29 21:55:42 UTC
FcFreeTypeQueryFace() may be helpful.
Comment 4 Behdad Esfahbod 2007-09-15 03:52:57 UTC
Ok, progress.  Reading about int QFontDatabase::addApplicationFont [1] I figured we need a way to do that too.  

So, here is how to do it.  We add:

void
pango_cairo_font_map_add_application_font (PangoFontDescription *desc,
                                           cairo_font_face_t    *font_face);

Then all cairo font maps will (using some helper function) first check any load_font requests against all application fonts and if the font description of the request font is equal to one of the application fonts in all the attributes set by both, the application font face is returned.

We still need to somehow tricks, but we don't need to virtualize PFD anymore and the whole thing is a lot easier as the cairo fontmaps intercept the request before their parent fontmaps.

Other calls to go with it will be remove_application_font() and either remove_all_application_fonts() or list_application_fonts().


Obvious question is why should this be a pangocairo thing in the first place.  Well, because backend-neutral cairo_font_face_t is already there...  But I also noticed that to be really useful we would need backend-neutral  cairo_font_face_create_from_data() and cairo_font_face_create_from_file().  But if one can write those, they can be duped in pango too... So, not sure.



[1] http://doc.trolltech.com/4.3/qfontdatabase.html#addApplicationFont
Comment 5 Behdad Esfahbod 2007-09-15 04:04:34 UTC
Requested helper cairo API: http://lists.freedesktop.org/archives/cairo/2007-September/011416.html
Comment 6 Jeffrey Stedfast 2007-09-20 23:29:35 UTC
Moonlight needs to be able to load a font face from a specified file

so this is my +1



I had started writing my own font rendering text-layout code for Moonlight to work around problems we've been facing using pango (this being one of them, the others being glyphs rendering at different distances from the "baseline" when text was rendered in a rotation and overall "slowness" which have now been worked around (arguably our own fault and not pango's problems?))

anyways... I had liked PangoFontDescriptions so I mimicked the same idea in my code. Basically, since I noticed that FontConfig allowed setting a filename on an FcPattern, I just added [g,s]et_filename() methods to my own FontDescription which roughly translated to setting that filename in the FcPattern if set.

Imho, this is the simplest approach from the perspective of a consumer of the pango APIs.

Is there some fundamental reason this can't be done in pango like this?
Comment 7 Behdad Esfahbod 2007-10-15 20:26:00 UTC
So, updates from discussing this with Owen again at Boston Summit this year.  We are talking about two separate features:

  - Add font file and/or cairo font face to catalog.  Do we need a font-dir version too?  This is useful to add fonts from your application / font embedded in flash / etc to catalog and then use pango normally.  Font backend should inspect the font and act as if it was a normal font installed on the system.

  - Assign font file and/or cairo font face to a specific font description.  This is needed for font viewers.

Both can be combined in a single API that takes a possibly null font description, and a boolean for whether to add it to catalog.

The cairo font face version is needed regardless of font-file api, to support cairo user fonts when we have them for example.

Font file API of course needs a from_data equivalent too.
Comment 8 Benjamin Otte (Company) 2007-10-15 20:36:29 UTC
Adding myself to CC as I want to use Pango for text management in Swfdec and there is currently no method to use the fonts embedded in a Flash file inside Pango.
Comment 9 Sven Herzberg 2008-01-21 16:29:23 UTC
And I'd like to implement this one top of pango for webkit.
Comment 10 Behdad Esfahbod 2008-01-21 16:42:55 UTC
Sven, you can greatly help if you can provide Win32/ATSUI implementations for this.  See: http://lists.cairographics.org/archives/cairo/2007-September/011416.html

Thanks.
Comment 11 Tomáš Znamenáček 2008-06-03 07:38:42 UTC
(In reply to comment #6)

> Basically, since I noticed that FontConfig allowed setting a filename on
> an FcPattern, I just added [g,s]et_filename() methods to my own FontDescription
> which roughly translated to setting that filename in the FcPattern if set.

This is at least a nice hack to get it working for somebody who really needs it. But the Fontconfig users’ manual says: “Fontconfig provides a textual representation for patterns that the library can both accept and generate. The representation is in three parts, first a list of family names, second a list of point sizes and finally a list of additional properties.” Which sounds as if – even though there IS a FC_FILE field – the Fontconfig did not support matching on file names. Did You really got it working this way? (I’ve tried, very briefly, and it does not seem to work.)
Comment 12 Jeffrey Stedfast 2008-06-03 11:26:08 UTC
I think you may be right about font-config not respecting the FC_FILE property on a FcPattern, but I don't use an FcPattern in moonlight if a file path was specified.

and the way I had implemented a patch for pango was similar in that it didn't call out to font-config if a filename was specified.

Anyways, I'm happy with the way Behdad is implementing this feature... via cairo_font_face_t :)
Comment 13 Behdad Esfahbod 2008-06-03 15:12:58 UTC
Jeff, have that Pango patch?  I've been lazy figuring out where I need to shortcircuit in the pangofc-fontmap.  If you did the analysis already, I can use that as a starting point.

Cheers,
Comment 14 Jeffrey Stedfast 2008-06-03 15:33:33 UTC
Looks like I don't have it anymore :(

I'm not sure it was correct anyway, tbh - I don't think I ever did any testing, it was more "it compiles! ship it!" ;-)

Once Owen pointed me at this bug, I stopped hacking on the patch :)
Comment 15 Michael Lawrence 2008-06-25 23:19:28 UTC
Adding to CC list, as I am developing a clutter-based plotting application that aims to use their caching pango-cairo-based renderer to draw custom plot glyphs efficiently. This would rely on the user font support coming in cairo 1.8, and fixing this bug seems necessary for rendering cairo user fonts with pango.
Comment 16 Antoine van Gelder 2008-09-11 10:49:33 UTC
Adding to CC list, I'm building a cross-platform standalone app that has to run from a memory stick and need to use truetype fonts that I cannot register with the respective platform's font management systems.
Comment 17 Jeffrey Stedfast 2009-06-05 20:03:21 UTC
Unfortunately with Silverlight 2.0, Moonlight now has more requirements in this area :-(


Firstly (and most importantly), Silverlight 2 allows you to specify a list of font families that the text renderer needs to use to find a font that will render each glyph.

For example, a developer might specify in XAML: FontFamily="Georgia, Arial"

In this scenario, the text renderer should use Georgia to render any glyphs that are available in that font, but fallback to using Arial for anything Georgia lacks (like ♥♦♪♫ and such).

Currently PangoFontDescription does handle this if it is using the FontConfig backend (from what I understand), so some logic is already there for this font fallback, but we'll need it to work for a cairo_font_face_t backend as well.
Comment 18 Sebastian Dröge (slomo) 2009-10-22 08:25:44 UTC
We need to be able to paint a normal Pango FontDescription with fancy effects for GStreamer... well, not really fance, just white text with black outline and a shadow. Using pango_cairo_layout_path() + cairo_stroke() is just too slow (it's >10x slower than calling pango_cairo_show_layout()).

See bug #598695.

The solution proposed by Cairo developers was to create a Cairo user font and do the outline-shadow-text painting from the render_glyph function.
Comment 19 Behdad Esfahbod 2009-10-22 18:06:37 UTC
Sebastian:

User fonts may help, though you still need to draw the layout three times...  And wouldn't work for cursive scripts or fonts.

Is the text in question changing all the time?  If not, caching the rendering should be enough.
Comment 20 Benjamin Otte (Company) 2009-10-22 18:46:47 UTC
The element does caching - And for subtitles, it probably works well enough.
But there are some usecases - like the element that displays the timestamp - where it changes all the time. In that case, there's only 12 glyphs displayed at all (0-9, dot and colon), so having a custom font with the outlined glyphs that caches them sounds like quite a good solution.
Comment 21 Matej Knopp 2011-05-24 03:27:10 UTC
Has there been an progress on this?
Comment 22 Behdad Esfahbod 2011-05-24 16:49:10 UTC
Unfortunately not.  I've been busy with HarfBuzz :(.
Comment 23 Matej Knopp 2011-05-24 16:54:39 UTC
That's too bad. It looks like fixing this would not be a trivial change. As a workaround I'll try to temporarily register fonts for each platform (i.e. CTFontManagerRegisterGraphicsFont and AddFontResourceEx), but I'm guessing the unregistering will have to also flush pango font map caches. The inability to register custom font has caught me by surprise I must admit, wasn't expecting that given the maturity of Pango. Anyway, thanks a lot for the feedback!
Comment 24 Miro Keller 2011-09-27 10:33:01 UTC
Hi there! I'm using Cairo and Pango in the prototype of the rendering engine for the AXR Project (http://axr.vg). I'm interested in this feature request, because I'll need to load font files that are part of a site, just like with @font-face in CSS.

If there is anything that I can do to help you implement this, please let me know...

On the other hand, is there anything in Pango's roadmap regarding WOFF fonts?
Comment 25 Behdad Esfahbod 2014-05-08 18:49:52 UTC
Some comments that may help others work around this bug:
==================

I have an idea of how to do this easily in Pango.  Give it a try.  The
main limitation is that it only works for actual files on the filesystem.  But
you may be able to wire it up through ~/.gvfs filenames?

1. FcConfigCreate()
2. FcConfigAppFontAddFile()
3. pango_cairo_font_map_new_for_font_type()
4. Use that PangoFontMap to create your context, etc.
5. Every time you want to use Pango with that context, FcConfigSetCurrent the
above config.  Then reset it back to whatever it was before.

This way, Pango will only see that single font.


Misc bugs that would help make this easier in the future:

  https://bugs.freedesktop.org/show_bug.cgi?id=78450
  https://bugs.freedesktop.org/show_bug.cgi?id=78452
  https://bugs.freedesktop.org/show_bug.cgi?id=64766

  https://bugzilla.gnome.org/show_bug.cgi?id=547671
Comment 26 Behdad Esfahbod 2015-05-12 19:25:30 UTC
For reference, I discussed using custom fonts with pango+fontconfig in detail here:
http://mces.blogspot.ca/2015/05/how-to-use-custom-application-fonts.html
Comment 27 Behdad Esfahbod 2015-05-12 19:25:51 UTC
Don't think this will happen, so closing for now.