diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | ChangeLog.pre-1-10 | 10 | ||||
-rw-r--r-- | ChangeLog.pre-1-4 | 10 | ||||
-rw-r--r-- | ChangeLog.pre-1-6 | 10 | ||||
-rw-r--r-- | ChangeLog.pre-1-8 | 10 | ||||
-rw-r--r-- | docs/pango_markup.sgml | 10 | ||||
-rw-r--r-- | docs/tmpl/text-attributes.sgml | 1 | ||||
-rw-r--r-- | pango/pango-attributes.c | 27 | ||||
-rw-r--r-- | pango/pango-attributes.h | 4 | ||||
-rw-r--r-- | pango/pango-context.c | 59 | ||||
-rw-r--r-- | pango/pango-markup.c | 25 |
11 files changed, 170 insertions, 6 deletions
@@ -1,3 +1,13 @@ +2003-02-29 Noah Levitt <nlevitt@columbia.edu> + + * docs/pango_markup.sgml: + * docs/tmpl/text-attributes.sgml: + * pango/pango-attributes.c: + * pango/pango-attributes.h: + * pango/pango-context.c: + * pango/pango-markup.c: New attribute to turn font fallback on or off. + (#105553) + Sun Feb 29 10:54:55 2004 Owen Taylor <otaylor@redhat.com> * modules/arabic/arabic-ot.c (arabic): Add joining diff --git a/ChangeLog.pre-1-10 b/ChangeLog.pre-1-10 index 1d5b533a..54b51c5b 100644 --- a/ChangeLog.pre-1-10 +++ b/ChangeLog.pre-1-10 @@ -1,3 +1,13 @@ +2003-02-29 Noah Levitt <nlevitt@columbia.edu> + + * docs/pango_markup.sgml: + * docs/tmpl/text-attributes.sgml: + * pango/pango-attributes.c: + * pango/pango-attributes.h: + * pango/pango-context.c: + * pango/pango-markup.c: New attribute to turn font fallback on or off. + (#105553) + Sun Feb 29 10:54:55 2004 Owen Taylor <otaylor@redhat.com> * modules/arabic/arabic-ot.c (arabic): Add joining diff --git a/ChangeLog.pre-1-4 b/ChangeLog.pre-1-4 index 1d5b533a..54b51c5b 100644 --- a/ChangeLog.pre-1-4 +++ b/ChangeLog.pre-1-4 @@ -1,3 +1,13 @@ +2003-02-29 Noah Levitt <nlevitt@columbia.edu> + + * docs/pango_markup.sgml: + * docs/tmpl/text-attributes.sgml: + * pango/pango-attributes.c: + * pango/pango-attributes.h: + * pango/pango-context.c: + * pango/pango-markup.c: New attribute to turn font fallback on or off. + (#105553) + Sun Feb 29 10:54:55 2004 Owen Taylor <otaylor@redhat.com> * modules/arabic/arabic-ot.c (arabic): Add joining diff --git a/ChangeLog.pre-1-6 b/ChangeLog.pre-1-6 index 1d5b533a..54b51c5b 100644 --- a/ChangeLog.pre-1-6 +++ b/ChangeLog.pre-1-6 @@ -1,3 +1,13 @@ +2003-02-29 Noah Levitt <nlevitt@columbia.edu> + + * docs/pango_markup.sgml: + * docs/tmpl/text-attributes.sgml: + * pango/pango-attributes.c: + * pango/pango-attributes.h: + * pango/pango-context.c: + * pango/pango-markup.c: New attribute to turn font fallback on or off. + (#105553) + Sun Feb 29 10:54:55 2004 Owen Taylor <otaylor@redhat.com> * modules/arabic/arabic-ot.c (arabic): Add joining diff --git a/ChangeLog.pre-1-8 b/ChangeLog.pre-1-8 index 1d5b533a..54b51c5b 100644 --- a/ChangeLog.pre-1-8 +++ b/ChangeLog.pre-1-8 @@ -1,3 +1,13 @@ +2003-02-29 Noah Levitt <nlevitt@columbia.edu> + + * docs/pango_markup.sgml: + * docs/tmpl/text-attributes.sgml: + * pango/pango-attributes.c: + * pango/pango-attributes.h: + * pango/pango-context.c: + * pango/pango-markup.c: New attribute to turn font fallback on or off. + (#105553) + Sun Feb 29 10:54:55 2004 Owen Taylor <otaylor@redhat.com> * modules/arabic/arabic-ot.c (arabic): Add joining diff --git a/docs/pango_markup.sgml b/docs/pango_markup.sgml index e988e1d2..56f2ddae 100644 --- a/docs/pango_markup.sgml +++ b/docs/pango_markup.sgml @@ -135,6 +135,16 @@ subscript, positive for superscript. </para></listitem> </varlistentry> +<varlistentry><term>fallback</term> +<listitem><para> +'true' or 'false' whether to enable fallback. If disabled, then characters +will only be used from the closest matching font on the system. No fallback +will be done to other fonts on the system that might contain the characters +in the text. Fallback is enabled by default. Most applications should not +disable fallback. +</para></listitem> +</varlistentry> + <varlistentry><term>lang</term> <listitem><para> A language code, indicating the text language diff --git a/docs/tmpl/text-attributes.sgml b/docs/tmpl/text-attributes.sgml index ce2c5f64..4707232f 100644 --- a/docs/tmpl/text-attributes.sgml +++ b/docs/tmpl/text-attributes.sgml @@ -43,6 +43,7 @@ attribute is listed in parentheses after the description. @PANGO_ATTR_RISE: baseline displacement (#PangoAttrInt) @PANGO_ATTR_SHAPE: shape (#PangoAttrShape) @PANGO_ATTR_SCALE: font size scale factor (#PangoAttrScale) +@PANGO_ATTR_FALLBACK: whether fallback is enabled (#PangoAttrInt) <!-- ##### MACRO PANGO_TYPE_ATTR_TYPE ##### --> <para> diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c index e2441ac9..57017cb8 100644 --- a/pango/pango-attributes.c +++ b/pango/pango-attributes.c @@ -643,6 +643,33 @@ pango_attr_scale_new (double scale_factor) return pango_attr_float_new (&klass, scale_factor); } +/** + * pango_attr_fallback_new: + * @enable_fallback: %TRUE if we should fall back on other fonts + * for characters the active font is missing. + * + * Create a new font fallback attribute. + * + * If fallback is disabled, characters will only be used from the + * closest matching font on the system. No fallback will be done to + * other fonts on the system that might contain the characters in the + * text. + * + * Return value: the new #PangoAttribute. + **/ +PangoAttribute * +pango_attr_fallback_new (gboolean enable_fallback) +{ + static const PangoAttrClass klass = { + PANGO_ATTR_FALLBACK, + pango_attr_int_copy, + pango_attr_int_destroy, + pango_attr_int_equal, + }; + + return pango_attr_int_new (&klass, (int)enable_fallback); +} + static PangoAttribute * pango_attr_shape_copy (const PangoAttribute *attr) { diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h index 5a29f706..30a2fb24 100644 --- a/pango/pango-attributes.h +++ b/pango/pango-attributes.h @@ -80,7 +80,8 @@ typedef enum PANGO_ATTR_STRIKETHROUGH, /* PangoAttrInt */ PANGO_ATTR_RISE, /* PangoAttrInt */ PANGO_ATTR_SHAPE, /* PangoAttrShape */ - PANGO_ATTR_SCALE /* PangoAttrFloat */ + PANGO_ATTR_SCALE, /* PangoAttrFloat */ + PANGO_ATTR_FALLBACK, /* PangoAttrInt */ } PangoAttrType; typedef enum { @@ -179,6 +180,7 @@ PangoAttribute *pango_attr_rise_new (int rise); PangoAttribute *pango_attr_shape_new (const PangoRectangle *ink_rect, const PangoRectangle *logical_rect); PangoAttribute *pango_attr_scale_new (double scale_factor); +PangoAttribute *pango_attr_fallback_new (gboolean enable_fallback); GType pango_attr_list_get_type (void) G_GNUC_CONST; PangoAttrList * pango_attr_list_new (void); diff --git a/pango/pango-context.c b/pango/pango-context.c index 520ddff1..e0c67879 100644 --- a/pango/pango-context.c +++ b/pango/pango-context.c @@ -515,6 +515,8 @@ struct _ItemizeState PangoFontset *current_fonts; ShaperFontCache *cache; + PangoFont *base_font; + gboolean enable_fallback; GSList *exact_engines; GSList *fallback_engines; @@ -534,10 +536,24 @@ update_embedding_end (ItemizeState *state) state->changed |= EMBEDDING_CHANGED; } +static PangoAttribute * +find_attribute (GSList *attr_list, + PangoAttrType type) +{ + GSList *node; + + for (node = attr_list; node; node = node->next) + if (((PangoAttribute *) node->data)->klass->type == type) + return (PangoAttribute *) node->data; + + return NULL; +} + static void update_attr_iterator (ItemizeState *state) { PangoLanguage *old_lang; + PangoAttribute *fallback; int end_index; pango_attr_iterator_range (state->attr_iter, NULL, &end_index); @@ -554,6 +570,9 @@ update_attr_iterator (ItemizeState *state) &state->lang, &state->extra_attrs); state->copy_extra_attrs = FALSE; + fallback = find_attribute (state->extra_attrs, PANGO_ATTR_FALLBACK); + state->enable_fallback = (fallback == NULL || ((PangoAttrInt *)fallback)->value); + state->changed |= FONT_CHANGED; if (state->lang != old_lang) state->changed |= LANG_CHANGED; @@ -639,6 +658,7 @@ itemize_state_init (ItemizeState *state, state->cache = NULL; state->exact_engines = NULL; state->fallback_engines = NULL; + state->base_font = NULL; state->changed = EMBEDDING_CHANGED | SCRIPT_CHANGED | LANG_CHANGED | FONT_CHANGED; } @@ -813,6 +833,16 @@ get_shaper_and_font_foreach (PangoFontset *fontset, return FALSE; } +static PangoFont * +get_base_font (ItemizeState *state) +{ + if (!state->base_font) + state->base_font = pango_font_map_load_font (state->context->font_map, + state->context, + state->font_desc); + return state->base_font; +} + static gboolean get_shaper_and_font (ItemizeState *state, gunichar wc, @@ -821,7 +851,9 @@ get_shaper_and_font (ItemizeState *state, { GetShaperFontInfo info; - if (shaper_font_cache_get (state->cache, wc, shape_engine, font)) + /* We'd need a separate cache when fallback is disabled, but since lookup + * with fallback disabled is faster anyways, we just skip caching */ + if (state->enable_fallback && shaper_font_cache_get (state->cache, wc, shape_engine, font)) return *shape_engine != NULL; if (!state->exact_engines && !state->fallback_engines) @@ -834,24 +866,35 @@ get_shaper_and_font (ItemizeState *state, info.font = NULL; info.engines = state->exact_engines; - pango_fontset_foreach (state->current_fonts, get_shaper_and_font_foreach, &info); + if (state->enable_fallback) + pango_fontset_foreach (state->current_fonts, get_shaper_and_font_foreach, &info); + else + get_shaper_and_font_foreach (NULL, get_base_font (state), &info); + if (info.shape_engine) { *shape_engine = info.shape_engine; *font = info.font; - shaper_font_cache_insert (state->cache, wc, *shape_engine, *font); + /* skip caching if fallback disabled (see above) */ + if (state->enable_fallback) + shaper_font_cache_insert (state->cache, wc, *shape_engine, *font); return TRUE; } info.engines = state->fallback_engines; - pango_fontset_foreach (state->current_fonts, get_shaper_and_font_foreach, &info); + if (state->enable_fallback) + pango_fontset_foreach (state->current_fonts, get_shaper_and_font_foreach, &info); + else + get_shaper_and_font_foreach (NULL, get_base_font (state), &info); *shape_engine = info.shape_engine; *font = info.font; - shaper_font_cache_insert (state->cache, wc, *shape_engine, *font); + /* skip caching if fallback disabled (see above) */ + if (state->enable_fallback) + shaper_font_cache_insert (state->cache, wc, *shape_engine, *font); return *shape_engine != NULL; } @@ -945,6 +988,12 @@ itemize_state_update_for_new_run (ItemizeState *state) state->derived_lang); state->cache = get_shaper_font_cache (state->current_fonts); } + + if ((state->changed & FONT_CHANGED) && state->base_font) + { + g_object_unref (state->base_font); + state->base_font = NULL; + } } static void diff --git a/pango/pango-markup.c b/pango/pango-markup.c index a0697380..3764fdcb 100644 --- a/pango/pango-markup.c +++ b/pango/pango-markup.c @@ -858,6 +858,7 @@ span_parse_func (MarkupData *md, const char *strikethrough = NULL; const char *rise = NULL; const char *lang = NULL; + const char *fallback = NULL; g_markup_parse_context_get_position (context, &line_number, &char_number); @@ -932,6 +933,11 @@ span_parse_func (MarkupData *md, CHECK_DUPLICATE (lang); lang = values[i]; } + else if (strcmp (names[i], "fallback") == 0) + { + CHECK_DUPLICATE (fallback); + fallback = values[i]; + } else { g_set_error (error, G_MARKUP_ERROR, @@ -1182,6 +1188,25 @@ span_parse_func (MarkupData *md, } } + if (fallback) + { + if (strcmp (fallback, "true") == 0) + add_attribute (tag, pango_attr_fallback_new (TRUE)); + else if (strcmp (fallback, "false") == 0) + add_attribute (tag, pango_attr_fallback_new (FALSE)); + else + { + g_set_error (error, + G_MARKUP_ERROR, + G_MARKUP_ERROR_INVALID_CONTENT, + _("'fallback' attribute on <span> tag " + "line %d should have one of the values " + "'true' or 'false': '%s' is not valid"), + line_number, fallback); + goto error; + } + } + if (rise) { char *end = NULL; |