entry: which invisible character the font has is found once per style and font map, not by laying out the candidates for every entry at its start and at every new style
This commit is contained in:
parent
8ca795ac37
commit
86f24665ef
1 changed files with 58 additions and 4 deletions
|
|
@ -2218,12 +2218,20 @@ gtk_entry_get_property (GObject *object,
|
|||
}
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gunichar wanted; /* the invisible-char style property */
|
||||
PangoFontMap *font_map; /* not a reference: only compared */
|
||||
gunichar found;
|
||||
} InvisibleCharFound;
|
||||
|
||||
static gunichar find_invisible_char_in_font (GtkWidget *widget,
|
||||
gunichar *invisible_chars,
|
||||
gint n_chars);
|
||||
|
||||
static gunichar
|
||||
find_invisible_char (GtkWidget *widget)
|
||||
{
|
||||
PangoLayout *layout;
|
||||
PangoAttrList *attr_list;
|
||||
gint i;
|
||||
gunichar invisible_chars [] = {
|
||||
0,
|
||||
0x25cf, /* BLACK CIRCLE */
|
||||
|
|
@ -2232,11 +2240,57 @@ find_invisible_char (GtkWidget *widget)
|
|||
0x273a /* SIXTEEN POINTED ASTERISK */
|
||||
};
|
||||
|
||||
static GQuark quark_found;
|
||||
InvisibleCharFound *found = NULL;
|
||||
PangoFontMap *font_map;
|
||||
gunichar result;
|
||||
|
||||
if (widget->style)
|
||||
gtk_widget_style_get (widget,
|
||||
"invisible-char", &invisible_chars[0],
|
||||
NULL);
|
||||
|
||||
/* Which of the characters the font has depends on the style, which
|
||||
* many entries share, and the font map; finding out takes laying
|
||||
* them out, at the start of each entry and at every new style */
|
||||
font_map = pango_context_get_font_map (gtk_widget_get_pango_context (widget));
|
||||
if (widget->style)
|
||||
{
|
||||
if (!quark_found)
|
||||
quark_found = g_quark_from_static_string ("gtk-entry-invisible-char-found");
|
||||
found = g_object_get_qdata (G_OBJECT (widget->style), quark_found);
|
||||
if (found &&
|
||||
found->wanted == invisible_chars[0] &&
|
||||
found->font_map == font_map)
|
||||
return found->found;
|
||||
}
|
||||
|
||||
result = find_invisible_char_in_font (widget, invisible_chars, G_N_ELEMENTS (invisible_chars));
|
||||
|
||||
if (widget->style)
|
||||
{
|
||||
if (!found)
|
||||
{
|
||||
found = g_new (InvisibleCharFound, 1);
|
||||
g_object_set_qdata_full (G_OBJECT (widget->style), quark_found, found, g_free);
|
||||
}
|
||||
found->wanted = invisible_chars[0];
|
||||
found->font_map = font_map;
|
||||
found->found = result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static gunichar
|
||||
find_invisible_char_in_font (GtkWidget *widget,
|
||||
gunichar *invisible_chars,
|
||||
gint n_chars)
|
||||
{
|
||||
PangoLayout *layout;
|
||||
PangoAttrList *attr_list;
|
||||
gint i;
|
||||
|
||||
layout = gtk_widget_create_pango_layout (widget, NULL);
|
||||
|
||||
attr_list = pango_attr_list_new ();
|
||||
|
|
@ -2245,7 +2299,7 @@ find_invisible_char (GtkWidget *widget)
|
|||
pango_layout_set_attributes (layout, attr_list);
|
||||
pango_attr_list_unref (attr_list);
|
||||
|
||||
for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
|
||||
for (i = (invisible_chars[0] != 0 ? 0 : 1); i < n_chars; i++)
|
||||
{
|
||||
gchar text[7] = { 0, };
|
||||
gint len, count;
|
||||
|
|
|
|||
Loading…
Reference in a new issue