Index: app/text/gimptext.c =================================================================== --- app/text/gimptext.c (revision 23659) +++ app/text/gimptext.c (working copy) @@ -44,6 +44,7 @@ enum PROP_0, PROP_TEXT, PROP_FONT, + PROP_FONT_DESC, PROP_FONT_SIZE, PROP_UNIT, PROP_HINTING, @@ -116,6 +117,10 @@ gimp_text_class_init (GimpTextClass *kla "font", NULL, "Sans", GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_FONT_DESC, + "font-desc", NULL, + NULL, + GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_FONT_SIZE, "font-size", NULL, 0.0, 8192.0, 18.0, @@ -251,6 +256,11 @@ gimp_text_finalize (GObject *object) g_free (text->font); text->font = NULL; } + if (text->font_desc) + { + g_free (text->font_desc); + text->font_desc = NULL; + } if (text->language) { g_free (text->language); @@ -276,6 +286,9 @@ gimp_text_get_property (GObject *ob case PROP_FONT: g_value_set_string (value, text->font); break; + case PROP_FONT_DESC: + g_value_set_string (value, text->font_desc); + break; case PROP_FONT_SIZE: g_value_set_double (value, text->font_size); break; @@ -382,6 +395,10 @@ gimp_text_set_property (GObject *ob } } break; + case PROP_FONT_DESC: + g_free (text->font_desc); + text->font_desc = g_value_dup_string (value); + break; case PROP_FONT_SIZE: text->font_size = g_value_get_double (value); break; @@ -470,6 +487,9 @@ gimp_text_get_memsize (GimpObject *objec if (text->font) memsize += strlen (text->font) + 1; + if (text->font_desc) + memsize += strlen (text->font_desc) + 1; + if (text->language) memsize += strlen (text->language) + 1; Index: app/text/gimptext.h =================================================================== --- app/text/gimptext.h (revision 23659) +++ app/text/gimptext.h (working copy) @@ -43,6 +43,7 @@ struct _GimpText gchar *text; gchar *font; + gchar *font_desc; GimpUnit unit; gdouble font_size; gboolean hinting; Index: app/text/gimpfontlist.c =================================================================== --- app/text/gimpfontlist.c (revision 23659) +++ app/text/gimpfontlist.c (working copy) @@ -54,7 +54,8 @@ typedef char * (* GimpFontDescToStringFu static void gimp_font_list_add_font (GimpFontList *list, PangoContext *context, - PangoFontDescription *desc); + PangoFontDescription *desc, + FcPattern *fc_pattern); static void gimp_font_list_load_names (GimpFontList *list, PangoFontMap *fontmap, @@ -145,10 +146,12 @@ gimp_font_list_restore (GimpFontList *li static void gimp_font_list_add_font (GimpFontList *list, PangoContext *context, - PangoFontDescription *desc) + PangoFontDescription *desc, + FcPattern *fc_pattern) { GimpFont *font; gchar *name; + gchar *fc_desc = NULL; gsize len; if (! desc) @@ -156,6 +159,9 @@ gimp_font_list_add_font (GimpFontList name = font_desc_to_string (desc); + if (fc_pattern) + fc_desc = (gchar *) FcNameUnparse (fc_pattern); + len = strlen (name); if (! g_utf8_validate (name, len, NULL)) @@ -173,9 +179,12 @@ gimp_font_list_add_font (GimpFontList font = g_object_new (GIMP_TYPE_FONT, "name", name, "pango-context", context, + "font-desc", fc_desc, NULL); g_free (name); + if (fc_desc) + g_free (fc_desc); gimp_container_add (GIMP_CONTAINER (list), GIMP_OBJECT (font)); g_object_unref (font); @@ -206,7 +215,7 @@ gimp_font_list_make_alias (GimpFontList PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch (desc, PANGO_STRETCH_NORMAL); - gimp_font_list_add_font (list, context, desc); + gimp_font_list_add_font (list, context, desc, NULL); pango_font_description_free (desc); } @@ -253,7 +262,7 @@ gimp_font_list_load_names (GimpFontList PangoFontDescription *desc; desc = pango_fc_font_description_from_pattern (fontset->fonts[i], FALSE); - gimp_font_list_add_font (list, context, desc); + gimp_font_list_add_font (list, context, desc, fontset->fonts[i]); pango_font_description_free (desc); } @@ -288,7 +297,7 @@ gimp_font_list_load_names (GimpFontList PangoFontDescription *desc; desc = pango_font_face_describe (faces[j]); - gimp_font_list_add_font (list, context, desc); + gimp_font_list_add_font (list, context, desc, NULL); pango_font_description_free (desc); } } Index: app/text/gimptextlayout.c =================================================================== --- app/text/gimptextlayout.c (revision 23659) +++ app/text/gimptextlayout.c (working copy) @@ -305,7 +305,32 @@ static void gimp_text_ft2_subst_func (FcPattern *pattern, gpointer data) { - GimpText *text = GIMP_TEXT (data); + GimpText *text = GIMP_TEXT (data); + FcPattern *fontpat; + FcValue value; + + if (text->font_desc) + { + /* we don't trust the Pango generated pattern */ + fontpat = FcNameParse ((FcChar8 *) text->font_desc); + + if (FcPatternGet(fontpat, FC_FAMILY, 0, &value) == FcResultMatch) + FcPatternAdd (pattern, FC_FAMILY, value, FcFalse); + + if (FcPatternGet(fontpat, FC_STYLE, 0, &value) == FcResultMatch) + FcPatternAdd (pattern, FC_STYLE, value, FcFalse); + + if (FcPatternGet(fontpat, FC_SLANT, 0, &value) == FcResultMatch) + FcPatternAdd (pattern, FC_SLANT, value, FcFalse); + + if (FcPatternGet(fontpat, FC_WEIGHT, 0, &value) == FcResultMatch) + FcPatternAdd (pattern, FC_WEIGHT, value, FcFalse); + + if (FcPatternGet(fontpat, FC_WIDTH, 0, &value) == FcResultMatch) + FcPatternAdd (pattern, FC_WIDTH, value, FcFalse); + + FcPatternDestroy (fontpat); + } FcPatternAddBool (pattern, FC_HINTING, text->hinting); FcPatternAddBool (pattern, FC_AUTOHINT, text->autohint); Index: app/text/gimpfont.c =================================================================== --- app/text/gimpfont.c (revision 23659) +++ app/text/gimpfont.c (working copy) @@ -48,7 +48,8 @@ enum { PROP_0, - PROP_PANGO_CONTEXT + PROP_PANGO_CONTEXT, + PROP_FONT_DESC }; @@ -57,6 +58,7 @@ struct _GimpFont GimpViewable parent_instance; PangoContext *pango_context; + gchar *font_desc; PangoLayout *popup_layout; gint popup_width; @@ -74,6 +76,10 @@ static void gimp_font_set_property guint property_id, const GValue *value, GParamSpec *pspec); +static void gimp_font_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); static void gimp_font_get_preview_size (GimpViewable *viewable, gint size, @@ -109,6 +115,7 @@ gimp_font_class_init (GimpFontClass *kla object_class->finalize = gimp_font_finalize; object_class->set_property = gimp_font_set_property; + object_class->get_property = gimp_font_get_property; viewable_class->get_preview_size = gimp_font_get_preview_size; viewable_class->get_popup_size = gimp_font_get_popup_size; @@ -121,6 +128,11 @@ gimp_font_class_init (GimpFontClass *kla NULL, NULL, PANGO_TYPE_CONTEXT, GIMP_PARAM_WRITABLE)); + g_object_class_install_property (object_class, PROP_FONT_DESC, + g_param_spec_string ("font-desc", + NULL, NULL, + NULL, + GIMP_PARAM_READWRITE)); } static void @@ -165,6 +177,32 @@ gimp_font_set_property (GObject *o font->pango_context = (PangoContext *) g_value_dup_object (value); break; + case PROP_FONT_DESC: + if (font->font_desc) + g_free (font->font_desc); + font->font_desc = g_value_dup_string (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gimp_font_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + GimpFont *font = GIMP_FONT (object); + + switch (property_id) + { + case PROP_FONT_DESC: + g_value_set_string (value, font->font_desc); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -226,6 +264,38 @@ gimp_font_get_popup_size (GimpViewable * return TRUE; } +static void +gimp_font_ft2_subst_func (FcPattern *pattern, + gpointer data) +{ + GimpFont *font = GIMP_FONT (data); + FcPattern *fontpat; + FcValue value; + + if (font->font_desc) + { + /* we don't trust the Pango generated pattern */ + fontpat = FcNameParse ((FcChar8 *) font->font_desc); + + if (FcPatternGet(fontpat, FC_FAMILY, 0, &value) == FcResultMatch) + FcPatternAdd (pattern, FC_FAMILY, value, FcFalse); + + if (FcPatternGet(fontpat, FC_STYLE, 0, &value) == FcResultMatch) + FcPatternAdd (pattern, FC_STYLE, value, FcFalse); + + if (FcPatternGet(fontpat, FC_SLANT, 0, &value) == FcResultMatch) + FcPatternAdd (pattern, FC_SLANT, value, FcFalse); + + if (FcPatternGet(fontpat, FC_WEIGHT, 0, &value) == FcResultMatch) + FcPatternAdd (pattern, FC_WEIGHT, value, FcFalse); + + if (FcPatternGet(fontpat, FC_WIDTH, 0, &value) == FcResultMatch) + FcPatternAdd (pattern, FC_WIDTH, value, FcFalse); + + FcPatternDestroy (fontpat); + } +} + static TempBuf * gimp_font_get_new_preview (GimpViewable *viewable, GimpContext *context, @@ -251,6 +321,7 @@ gimp_font_get_new_preview (GimpViewable if (! font->popup_layout || font->popup_width != width || font->popup_height != height) { + PangoFontMap *fontmap; PangoFontDescription *font_desc; const gchar *name; @@ -264,6 +335,11 @@ gimp_font_get_new_preview (GimpViewable pango_font_description_set_size (font_desc, PANGO_SCALE * height * 2.0 / 3.0); + fontmap = pango_context_get_font_map (font->pango_context); + pango_ft2_font_map_set_default_substitute (PANGO_FT2_FONT_MAP (fontmap), + gimp_font_ft2_subst_func, + g_object_ref (font), + (GDestroyNotify) g_object_unref); layout = pango_layout_new (font->pango_context); pango_layout_set_font_description (layout, font_desc); Index: app/tools/gimptextoptions.c =================================================================== --- app/tools/gimptextoptions.c (revision 23659) +++ app/tools/gimptextoptions.c (working copy) @@ -301,11 +301,24 @@ gimp_text_options_notify_font (GimpConte GParamSpec *pspec, GimpText *text) { + GimpFont *font; + g_signal_handlers_block_by_func (text, gimp_text_options_notify_text_font, context); g_object_set (text, "font", gimp_context_get_font_name (context), NULL); + font = gimp_context_get_font (context); + if (font) + { + gchar *font_desc = NULL; + + g_object_get (font, "font-desc", &font_desc, NULL); + g_object_set (text, "font-desc", font_desc, NULL); + + if (font_desc) + g_free (font_desc); + } g_signal_handlers_unblock_by_func (text, gimp_text_options_notify_text_font,