summaryrefslogtreecommitdiff
path: root/pango/pangocairo-fcfont.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2006-08-15 11:51:37 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2006-08-15 11:51:37 +0000
commit8de44f9dc7712a7ce258b70a7b8283b3ebca094e (patch)
treef19a8eeb43df4d8f0ec8ffda31f6f2c0ad29bece /pango/pangocairo-fcfont.c
parenta79ad88362620acce4cdbebac12f049b83a1a396 (diff)
downloadpango-8de44f9dc7712a7ce258b70a7b8283b3ebca094e.tar.gz
Support --gravity.
2006-08-15 Behdad Esfahbod <behdad@gnome.org> * examples/renderdemo.c (do_output), (parse_gravity), (parse_options): Support --gravity. * pango/pangocairo-fcfont.c (pango_cairo_fc_font_get_scaled_font), (compute_glyph_extents), (_pango_cairo_fc_font_new): Load rotated scaled_fonts to handle gravity. * pango/pangofc-fontmap.c (pango_fc_make_pattern), (pango_fc_font_map_get_patterns), (pango_fc_font_map_load_fontset): Set FC_VERTICAL_LAYOUT on West and East gravity.
Diffstat (limited to 'pango/pangocairo-fcfont.c')
-rw-r--r--pango/pangocairo-fcfont.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/pango/pangocairo-fcfont.c b/pango/pangocairo-fcfont.c
index 10be3c36..41699306 100644
--- a/pango/pangocairo-fcfont.c
+++ b/pango/pangocairo-fcfont.c
@@ -46,7 +46,7 @@ typedef struct _GlyphExtentsCacheEntry GlyphExtentsCacheEntry;
#define GLYPH_CACHE_NUM_ENTRIES 256 /* should be power of two */
#define GLYPH_CACHE_MASK (GLYPH_CACHE_NUM_ENTRIES - 1)
-#define PANGO_UNITS(Double) ((int)((Double) * PANGO_SCALE + 0.49999))
+#define PANGO_UNITS(Double) ((int)floor((Double) * PANGO_SCALE + 0.5))
/* An entry in the fixed-size cache for the glyph -> ink_rect mapping.
* The cache is indexed by the lower N bits of the glyph (see
@@ -69,6 +69,7 @@ struct _PangoCairoFcFont
cairo_matrix_t font_matrix;
cairo_matrix_t ctm;
cairo_font_options_t *options;
+ PangoGravity gravity;
PangoRectangle font_extents;
GlyphExtentsCacheEntry *glyph_extents_cache;
@@ -132,6 +133,43 @@ pango_cairo_fc_font_get_scaled_font (PangoCairoFont *font)
*/
if (!cffont->scaled_font)
return NULL;
+
+ if (cffont->gravity != PANGO_GRAVITY_NORTH)
+ {
+ cairo_font_extents_t metrics;
+ cairo_matrix_t matrix;
+
+ cairo_scaled_font_extents (cffont->scaled_font, &metrics);
+ cairo_scaled_font_destroy (cffont->scaled_font);
+ cffont->scaled_font = NULL;
+
+ cairo_matrix_init_identity (&matrix);
+
+ switch (cffont->gravity)
+ {
+ case PANGO_GRAVITY_NORTH:
+ default:
+ break;
+ case PANGO_GRAVITY_SOUTH:
+ cairo_matrix_rotate(&matrix, M_PI);
+ break;
+ case PANGO_GRAVITY_WEST:
+ cairo_matrix_rotate(&matrix, -M_PI_2);
+ break;
+ case PANGO_GRAVITY_EAST:
+ cairo_matrix_rotate(&matrix, +M_PI_2);
+ break;
+ }
+ cairo_matrix_multiply(&cffont->font_matrix, &cffont->font_matrix, &matrix);
+
+ cffont->scaled_font = cairo_scaled_font_create (font_face,
+ &cffont->font_matrix,
+ &cffont->ctm,
+ cffont->options);
+
+ if (!cffont->scaled_font)
+ return NULL;
+ }
}
return cffont->scaled_font;
@@ -468,6 +506,9 @@ _pango_cairo_fc_font_new (PangoCairoFcFontMap *cffontmap,
"pattern", pattern,
NULL);
+ /* FIXME: support per-item gravity */
+ cffont->gravity = pango_context_get_base_gravity (context);
+
if (FcPatternGetMatrix (pattern,
FC_MATRIX, 0, &fc_matrix) == FcResultMatch)
{
@@ -488,6 +529,11 @@ _pango_cairo_fc_font_new (PangoCairoFcFontMap *cffontmap,
cairo_matrix_scale (&cffont->font_matrix,
size / PANGO_SCALE, size / PANGO_SCALE);
+ /* Note: the ->font_matrix at this point is not final yet. We
+ * will adjust it to the gravity later as it needs the scaled_font
+ * to be loaded first.
+ */
+
if (pango_ctm)
cairo_matrix_init (&cffont->ctm,
pango_ctm->xx,