diff options
author | Owen Taylor <otaylor@redhat.com> | 2004-12-16 19:08:36 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2004-12-16 19:08:36 +0000 |
commit | 72672341918128556cc486afcd6e9af0f1507379 (patch) | |
tree | 772d47a235b29a54c66bba4d1846a725ad9829d0 | |
parent | 9f334f6aa7f9a47c6d77a0165b32c6ce90de79e2 (diff) | |
download | pango-72672341918128556cc486afcd6e9af0f1507379.tar.gz |
Add short and long descriptions.pango-1-8-branchpoint
Thu Dec 16 14:03:32 2004 Owen Taylor <otaylor@redhat.com>
* docs/tmpl/pango-renderer.sgml: Add short and long descriptions.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | ChangeLog.pre-1-10 | 4 | ||||
-rw-r--r-- | ChangeLog.pre-1-8 | 4 | ||||
-rw-r--r-- | docs/tmpl/pango-renderer.sgml | 8 | ||||
-rw-r--r-- | pango/pangofc-fontmap.c | 153 | ||||
-rw-r--r-- | pango/pangofc-fontmap.h | 6 |
6 files changed, 155 insertions, 24 deletions
@@ -1,3 +1,7 @@ +Thu Dec 16 14:03:32 2004 Owen Taylor <otaylor@redhat.com> + + * docs/tmpl/pango-renderer.sgml: Add short and long descriptions. + Wed Dec 15 23:49:14 2004 Owen Taylor <otaylor@redhat.com> * === Released 1.8.0 === diff --git a/ChangeLog.pre-1-10 b/ChangeLog.pre-1-10 index 4d4bab3f..68d3e713 100644 --- a/ChangeLog.pre-1-10 +++ b/ChangeLog.pre-1-10 @@ -1,3 +1,7 @@ +Thu Dec 16 14:03:32 2004 Owen Taylor <otaylor@redhat.com> + + * docs/tmpl/pango-renderer.sgml: Add short and long descriptions. + Wed Dec 15 23:49:14 2004 Owen Taylor <otaylor@redhat.com> * === Released 1.8.0 === diff --git a/ChangeLog.pre-1-8 b/ChangeLog.pre-1-8 index 4d4bab3f..68d3e713 100644 --- a/ChangeLog.pre-1-8 +++ b/ChangeLog.pre-1-8 @@ -1,3 +1,7 @@ +Thu Dec 16 14:03:32 2004 Owen Taylor <otaylor@redhat.com> + + * docs/tmpl/pango-renderer.sgml: Add short and long descriptions. + Wed Dec 15 23:49:14 2004 Owen Taylor <otaylor@redhat.com> * === Released 1.8.0 === diff --git a/docs/tmpl/pango-renderer.sgml b/docs/tmpl/pango-renderer.sgml index ff4334ae..adb8f555 100644 --- a/docs/tmpl/pango-renderer.sgml +++ b/docs/tmpl/pango-renderer.sgml @@ -2,11 +2,15 @@ PangoRenderer <!-- ##### SECTION Short_Description ##### --> - +Rendering driver base class <!-- ##### SECTION Long_Description ##### --> <para> - +#PangoRenderer is a base class that contains the necessary logic for +rendering a PangoLayout or PangoLayoutLine. By subclassing +PangoRenderer and overriding operations such as @draw_glyphs and +@draw_rectangle, renderers for particular font backends and +destinations can be created. </para> <!-- ##### SECTION See_Also ##### --> diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c index a7e9f375..6f50e0f4 100644 --- a/pango/pangofc-fontmap.c +++ b/pango/pangofc-fontmap.c @@ -22,6 +22,8 @@ /* Size of fontset cache */ #define FONTSET_CACHE_SIZE 16 +#include <math.h> + #include "pango-context.h" #include "pangofc-fontmap.h" #include "pangofc-private.h" @@ -233,12 +235,56 @@ pango_fc_coverage_key_equal (PangoFcCoverageKey *key1, } typedef struct _FontsetHashListNode FontsetHashListNode; +typedef struct _FontsetHashKey FontsetHashKey; struct _FontsetHashListNode { GHashTable *fontset_hash; PangoLanguage *language; }; +struct _FontsetHashKey { + PangoFontDescription *desc; + int x_size; + int y_size; +}; + +static gboolean +fontset_hash_key_equal (const FontsetHashKey *key_a, + const FontsetHashKey *key_b) +{ + if (key_a->x_size == key_b->x_size && + key_a->y_size == key_b->y_size && + pango_font_description_equal (key_a->desc, key_b->desc)) + return TRUE; + else + return FALSE; +} + +static guint +fontset_hash_key_hash (const FontsetHashKey *key) +{ + return (key->x_size << 16) ^ (key->y_size) ^ pango_font_description_hash (key->desc); +} + +static void +fontset_hash_key_free (FontsetHashKey *key) +{ + pango_font_description_free (key->desc); + g_free (key); +} + +static FontsetHashKey * +fontset_hash_key_copy (FontsetHashKey *old) +{ + FontsetHashKey *key = g_new (FontsetHashKey, 1); + + key->x_size = old->x_size; + key->y_size = old->y_size; + key->desc = pango_font_description_copy (old->desc); + + return key; +} + /* Get the description => fontset map for a particular * language tag. */ @@ -280,9 +326,9 @@ pango_fc_get_fontset_hash (PangoFcFontMap *fcfontmap, priv->fontset_hash_list = g_list_prepend (priv->fontset_hash_list, node); node->fontset_hash = - g_hash_table_new_full ((GHashFunc)pango_font_description_hash, - (GEqualFunc)pango_font_description_equal, - (GDestroyNotify)pango_font_description_free, + g_hash_table_new_full ((GHashFunc)fontset_hash_key_hash, + (GEqualFunc)fontset_hash_key_equal, + (GDestroyNotify)fontset_hash_key_free, (GDestroyNotify)pango_fc_pattern_set_free); node->language = language; @@ -745,11 +791,66 @@ pango_fc_default_substitute (PangoFcFontMap *fontmap, PANGO_FC_FONT_MAP_GET_CLASS (fontmap)->default_substitute (fontmap, pattern); } +static double +transformed_length (const PangoMatrix *matrix, + double dx, + double dy) +{ + double tx = (dx * matrix->xx + dy * matrix->xy); + double ty = (dx * matrix->yx + dy * matrix->yy); + + return sqrt (tx * tx + ty * ty); +} + +static gboolean +pango_fc_font_map_get_rendered_size (PangoFcFontMap *fcfontmap, + PangoContext *context, + const PangoFontDescription *desc, + int *x_size, + int *y_size) +{ + if (PANGO_FC_FONT_MAP_GET_CLASS (fcfontmap)->get_rendered_size) + return PANGO_FC_FONT_MAP_GET_CLASS (fcfontmap)->get_rendered_size (fcfontmap, context, desc, x_size, y_size); + else + { + int size = pango_font_description_get_size (desc); + const PangoMatrix *matrix; + gboolean retval = TRUE; + + if (context) + matrix = pango_context_get_matrix (context); + else + matrix = NULL; + + *x_size = size; + *y_size = size; + + if (matrix) + { + double xl = transformed_length (matrix, 1., 0.); + double yl = transformed_length (matrix, 0., 1.); + + if (xl != 0. && yl != 0.) + { + *x_size = (int)(xl * *x_size + 0.5); + *y_size = (int)(yl * *y_size + 0.5); + + retval = (matrix->yx / xl < 1 / 65536. && matrix->xy / yl < 1 / 65536.); + } + else + retval = FALSE; + } + + return retval; + } +} + static PangoFcPatternSet * pango_fc_font_map_get_patterns (PangoFontMap *fontmap, - PangoContext *context, - const PangoFontDescription *desc, - PangoLanguage *language) + PangoContext *context, + const PangoFontDescription *desc, + PangoLanguage *language, + gboolean *cache_out) { PangoFcFontMap *fcfontmap = (PangoFcFontMap *)fontmap; FcPattern *pattern, *font_pattern; @@ -758,12 +859,21 @@ pango_fc_font_map_get_patterns (PangoFontMap *fontmap, PangoFcPatternSet *patterns; FcFontSet *font_patterns; GHashTable *fontset_hash; + FontsetHashKey key; + gboolean cache; if (!language && context) language = pango_context_get_language (context); fontset_hash = pango_fc_get_fontset_hash (fcfontmap, language); - patterns = g_hash_table_lookup (fontset_hash, desc); + key.desc = pango_font_description_copy_static (desc); + pango_font_description_unset_fields (key.desc, PANGO_FONT_MASK_SIZE); + + cache = pango_fc_font_map_get_rendered_size (fcfontmap, context, desc, &key.x_size, &key.y_size); + if (cache_out) + *cache_out = cache; + + patterns = g_hash_table_lookup (fontset_hash, &key); if (patterns == NULL) { @@ -820,10 +930,12 @@ pango_fc_font_map_get_patterns (PangoFontMap *fontmap, FcFontSetSortDestroy (font_patterns); g_hash_table_insert (fontset_hash, - pango_font_description_copy (desc), + fontset_hash_key_copy (&key), patterns); } + pango_font_description_free (key.desc); + return patterns; } @@ -832,7 +944,7 @@ pango_fc_font_map_load_font (PangoFontMap *fontmap, PangoContext *context, const PangoFontDescription *description) { - PangoFcPatternSet *patterns = pango_fc_font_map_get_patterns (fontmap, context, description, NULL); + PangoFcPatternSet *patterns = pango_fc_font_map_get_patterns (fontmap, context, description, NULL, NULL); if (!patterns) return NULL; @@ -903,28 +1015,27 @@ pango_fc_font_map_load_fontset (PangoFontMap *fontmap, const PangoFontDescription *desc, PangoLanguage *language) { - PangoFcPatternSet *patterns = pango_fc_font_map_get_patterns (fontmap, context, desc, language); + gboolean cache; + PangoFcPatternSet *patterns = pango_fc_font_map_get_patterns (fontmap, context, desc, language, &cache); PangoFcFontMap *fcfontmap = PANGO_FC_FONT_MAP (fontmap); PangoFcFontMapPrivate *priv = fcfontmap->priv; PangoFontset *result; - const PangoMatrix *matrix; int i; if (!patterns) return NULL; - if (context) - matrix = pango_context_get_matrix (context); - else - matrix = NULL; - - /* We never cache fontsets when a transformation is in place - */ - if (!patterns->fontset || matrix) + if (!patterns->fontset || !cache) { PangoFontsetSimple *simple; + const PangoMatrix *matrix; simple = pango_fontset_simple_new (language); result = PANGO_FONTSET (simple); + + if (context) + matrix = pango_context_get_matrix (context); + else + matrix = NULL; for (i = 0; i < patterns->n_patterns; i++) { @@ -935,7 +1046,7 @@ pango_fc_font_map_load_fontset (PangoFontMap *fontmap, pango_fontset_simple_append (simple, font); } - if (!matrix) + if (cache) { patterns->fontset = PANGO_FONTSET (simple); g_object_add_weak_pointer (G_OBJECT (patterns->fontset), @@ -945,7 +1056,7 @@ pango_fc_font_map_load_fontset (PangoFontMap *fontmap, else result = g_object_ref (patterns->fontset); - if (!matrix && + if (cache && (!patterns->cache_link || patterns->cache_link != priv->fontset_cache->head)) pango_fc_font_map_cache_fontset (fcfontmap, patterns); diff --git a/pango/pangofc-fontmap.h b/pango/pangofc-fontmap.h index f5d193be..318ad03c 100644 --- a/pango/pangofc-fontmap.h +++ b/pango/pangofc-fontmap.h @@ -82,13 +82,17 @@ struct _PangoFcFontMapClass PangoFcFont *(*new_font) (PangoFcFontMap *fontmap, FcPattern *pattern); + gboolean (*get_rendered_size) (PangoFcFontMap *fcfontmap, + PangoContext *context, + const PangoFontDescription *desc, + int *xsize, + int *ysize); /*< private >*/ /* Padding for future expansion */ void (*_pango_reserved1) (void); void (*_pango_reserved2) (void); void (*_pango_reserved3) (void); - void (*_pango_reserved4) (void); }; PangoContext * pango_fc_font_map_create_context (PangoFcFontMap *fcfontmap); |