Felipe Sanches wrote:
I also heard something about cairo's user font support. I wish somebody could explain this to me. This part of my SoC proposal can be improved once I figure out these things clearer.
Currently cairo has three font backends: FreeType, Win32, and Quartz. There is a fourth, the toy font backend, but that exists only to provides a simple interface to one of the other font backends (depending on your platform) to be used for simple demos and examples.
Cairo can only use the fonts that are supported by these font backends which basically means that only TrueType, OpenType, and Type 1 fonts are supported. Some less common formats are also supported by some font backends.
The user-font support allows applications to provide cairo with a callback function for rendering fonts. The application receives the call to render each glyph and uses the cairo API to draw the glyph.
A simplified view of the API is:
cairo_public cairo_font_face_t * cairo_user_font_face_create (void);
This creates a new user-font.
typedef cairo_status_t (*cairo_user_scaled_font_render_glyph_func_t) (cairo_scaled_font_t *scaled_font, unsigned long glyph, cairo_t *cr, cairo_text_extents_t *extents);
This is the render function that the application must implement. When cairo needs to draw a user-font glyph it calls this function with the glyph id of the glyph to render. The font size can be obtained from scaled_font with cairo_scaled_font_get_font_matrix(). The application draws the glyph onto the supplied cairo content.
cairo_public void cairo_user_font_face_set_render_glyph_func ( cairo_font_face_t *font_face, cairo_user_scaled_font_render_glyph_func_t render_glyph_func);
This sets the render function for the user-font with font_face.
=== future ideas (not to be implemented for SoC'08) === Here I include some ideas that I would possibly work on after I finish the SoC tasks.
- SVG Fonts to TrueType (or other font formats) conversion and vice-versa
You may want to look at the TrueType subsetting code in cairo so see how it pulls apart and re-assembles a TrueType font. Although one difference is the cairo subsetter is designed copy the original glyphs in the GLYF table into the subset to preserve the hinting. A SVG to TTF converter would need to generate the GLYF table from the SVG outlines.
One problem with converting SVG fonts to TrueType is that SVG glyphs can have cubic Bézier curves while the TrueType format only supports quadratic Bézier curves. For this reason converting to Type 1 or OpenType with PostScript outlines is easier. Cairo has code for creating Type 1 or CFF fonts from outlines. CFF fonts are the PostScript outlines in OpenType/PS fonts.