[Cairo] Text APIs round 2

Keith Packard keithp at keithp.com
Wed Aug 13 16:49:54 PDT 2003


I think we've converged on the class of acceptable solutions for cairo 
text.  Here's a specific example of both the FreeType/Fontconfig APIs and 
the generic (aka 'toy') APIs:

OS-independent functions:

	/* "toy" API to select a font */
	void
	cairo_select_font (cairo_t *ct, char *family, int slant, int weight);

	void
	cairo_set_font (cairo_t *ct, cairo_font_t *font);

	void
	cairo_show_text (cairo_t *ct, const unsigned char *utf8);

	void
	cairo_text_extents (cairo_t *ct,
	                    const unsigned char *utf8,
	                    double *x, double *y,
	                    double *width, double *height,
	                    double *dx, double *dy);

	typedef struct cairo_glyph {
	    cairo_font_t *font;
	    FT_UInt      id;
	    double x;
	    double y;
	} cairo_glyph_t;

	void
	cairo_show_glyphs (cairo_t *ct, cairo_glyph_t *glyphs, int num_glyphs);

	void
	cairo_text_path  (cairo_t *ct, const unsigned char *utf8);

	void
	cairo_glyph_path (cairo_t *ct, cairo_glyph_t *glyphs, int num_glyphs);

	double
	cairo_font_ascent (cairo_font_t *font);

	double
	cairo_font_descent (cairo_font_t *font);

	double
	cairo_font_height (cairo_font_t *font);

	double
	cairo_font_max_advance_width (cairo_font_t *font);

Note that the "toy" font names are explicitly not Fontconfig-specific any 
longer.  This maps reasonably well to Fontconfig and Win32; I don't know 
about OS X.

Fontconfig/FreeType API:

	cairo_ft_font_t *
	cairo_ft_font_create (FcPattern *pattern);

	cairo_ft_font_t *
	cairo_ft_font_create_scale (FcPattern *pattern, double scale);

	cairo_ft_font_t *
	cairo_ft_font_create_transform (FcPattern *pattern, cairo_matrix_t *transform);

	cairo_ft_font_t *
	cairo_ft_font_create_for_ft_face (FT_Face face);

	void
	cairo_ft_font_destroy (cairo_ft_font_t *ft_font);

	cairo_font_t *
	cairo_font_from_ft_font (cairo_ft_font_t *ft_font);

	FT_Face
	cairo_ft_font_face (cairo_ft_font_t *ft_font);

	FcPattern *
	cairo_ft_font_pattern (cairo_ft_font_t  *ft_font);

Win32 API:
	cairo_win32_font_t *
	cairo_win32_font_create (LOGFONT *logfont);

	cairo_win32_font_t *
	cairo_win32_font_create_scale (LOGFONT *logfont, double scale);

	cairo_win32_font_t *
	cairo_win32_font_create_transform (LOGFONT *logfont, cairo_matrix_t *transform);

	cairo_win32_font_t *
	cairo_win32_font_create_for_hfont (HFONT hfont);

	void
	cairo_win32_font_destroy (cairo_win32_font_t *win32_font);

	cairo_font_t *
	cairo_font_from_win32_font (cairo_win32_font_t *win32_font);

	HFONT
	cairo_win32_font_hfont (cairo_win32_font_t *win32_font);

	LOGFONT *
	cairo_win32_font_logfont (cairo_win32_font_t  *win32_font);

Questions:

	Should the os-dependent code be limited to functions accepting 
	pre-generated font objects?  This would make those APIs much 
	simpler.

	Should the various scale/transform functions be os-independent and
	take a cairo_font_t and manipulate it?  That could reduce 
	os-dependent code a bit, or it might just make applications mix
	up the calls and confuse everyone.

	Should we support bitmap fonts at all?

-keith






More information about the cairo mailing list