+
+ /* Update the main notebook page. */
+ gtk_widget_set_sensitive(fontsel->filter_button, FALSE);
+ gtk_label_set_text(GTK_LABEL(fontsel->font_label), _("Font:"));
+
+ gtk_font_selection_show_available_fonts(fontsel);
+}
+
+
+void
+gtk_font_selection_set_filter (GtkFontSelection *fontsel,
+ GtkFontFilterType filter_type,
+ GtkFontType font_type,
+ gchar **foundries,
+ gchar **weights,
+ gchar **slants,
+ gchar **setwidths,
+ gchar **spacings,
+ gchar **charsets)
+{
+ GtkFontFilter *filter;
+ gchar **filter_strings [GTK_NUM_FONT_PROPERTIES];
+ gchar *filter_string;
+ gchar *property, *property_alt;
+ gint prop, nfilters, i, j, num_found;
+ gint base_font_type, user_font_type;
+ gboolean filter_set;
+
+ /* Put them into an array so we can use a simple loop. */
+ filter_strings[FOUNDRY] = foundries;
+ filter_strings[WEIGHT] = weights;
+ filter_strings[SLANT] = slants;
+ filter_strings[SET_WIDTH] = setwidths;
+ filter_strings[SPACING] = spacings;
+ filter_strings[CHARSET] = charsets;
+
+ filter = &fontsel->filters[filter_type];
+ filter->font_type = font_type;
+
+ /* Free the old filter data, and insert the new. */
+ for (prop = 0; prop < GTK_NUM_FONT_PROPERTIES; prop++)
+ {
+ g_free(filter->property_filters[prop]);
+ filter->property_filters[prop] = NULL;
+ filter->property_nfilters[prop] = 0;
+
+ if (filter_strings[prop])
+ {
+ /* Count how many items in the new array. */
+ nfilters = 0;
+ while (filter_strings[prop][nfilters])
+ nfilters++;
+
+ filter->property_filters[prop] = g_new(guint16, nfilters);
+ filter->property_nfilters[prop] = 0;
+
+ /* Now convert the strings to property indices. */
+ num_found = 0;
+ for (i = 0; i < nfilters; i++)
+ {
+ filter_string = filter_strings[prop][i];
+ for (j = 0; j < fontsel_info->nproperties[prop]; j++)
+ {
+ property = _(fontsel_info->properties[prop][j]);
+ property_alt = NULL;
+ if (prop == SLANT)
+ property_alt = gtk_font_selection_expand_slant_code(property);
+ else if (prop == SPACING)
+ property_alt = gtk_font_selection_expand_spacing_code(property);
+ if (!strcmp (filter_string, property)
+ || (property_alt && !strcmp (filter_string, property_alt)))
+ {
+ filter->property_filters[prop][num_found] = j;
+ num_found++;
+ break;
+ }
+ }
+ }
+ filter->property_nfilters[prop] = num_found;
+ }
+ }
+
+ /* Now set the clists on the filter page according to the new filter. */
+ gtk_font_selection_update_filter_lists (fontsel);
+
+ if (filter_type == GTK_FONT_FILTER_BASE)
+ {
+ user_font_type = fontsel->filters[GTK_FONT_FILTER_USER].font_type;
+ if (font_type & GTK_FONT_BITMAP)
+ {
+ gtk_widget_set_sensitive (fontsel->type_bitmaps_button, TRUE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fontsel->type_bitmaps_button), user_font_type & GTK_FONT_BITMAP);
+ }
+ else
+ {
+ gtk_widget_set_sensitive (fontsel->type_bitmaps_button, FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fontsel->type_bitmaps_button), FALSE);
+ }
+
+ if (font_type & GTK_FONT_SCALABLE)
+ {
+ gtk_widget_set_sensitive (fontsel->type_scalable_button, TRUE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fontsel->type_scalable_button), user_font_type & GTK_FONT_SCALABLE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive (fontsel->type_scalable_button, FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fontsel->type_scalable_button), FALSE);
+ }
+
+ if (font_type & GTK_FONT_SCALABLE_BITMAP)
+ {
+ gtk_widget_set_sensitive (fontsel->type_scaled_bitmaps_button, TRUE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fontsel->type_scaled_bitmaps_button), user_font_type & GTK_FONT_SCALABLE_BITMAP);
+ }
+ else
+ {
+ gtk_widget_set_sensitive (fontsel->type_scaled_bitmaps_button, FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fontsel->type_scaled_bitmaps_button), FALSE);
+ }
+ }
+ else
+ {
+ base_font_type = fontsel->filters[GTK_FONT_FILTER_BASE].font_type;
+ if (base_font_type & GTK_FONT_BITMAP)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fontsel->type_bitmaps_button), font_type & GTK_FONT_BITMAP);
+
+ if (base_font_type & GTK_FONT_SCALABLE)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fontsel->type_scalable_button), font_type & GTK_FONT_SCALABLE);
+
+ if (base_font_type & GTK_FONT_SCALABLE_BITMAP)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fontsel->type_scaled_bitmaps_button), font_type & GTK_FONT_SCALABLE_BITMAP);
+
+ /* If the user filter is not the default, make the 'Reset Filter' button
+ sensitive. */
+ filter_set = FALSE;
+ if (font_type != (GTK_FONT_BITMAP | GTK_FONT_SCALABLE))
+ filter_set = TRUE;
+ for (prop = 0; prop < GTK_NUM_FONT_PROPERTIES; prop++)
+ {
+ if (filter->property_nfilters[prop] != 0)
+ filter_set = TRUE;
+ }
+ if (filter_set)
+ gtk_widget_set_sensitive (fontsel->filter_button, TRUE);
+ }
+
+ gtk_font_selection_show_available_fonts (fontsel);
+}
+
+
+/* This sets the colour of each property in the filter clists according to
+ the base filter. i.e. Filtered properties are shown as insensitive. */
+static void
+gtk_font_selection_update_filter_lists (GtkFontSelection *fontsel)
+{
+ GtkWidget *clist;
+ GdkColor *inactive_fg, *inactive_bg, *fg, *bg;
+ gint prop, row, index;
+
+ /* We have to make sure the clist is realized to use the colours. */
+ for (prop = 0; prop < GTK_NUM_FONT_PROPERTIES; prop++)
+ {
+ clist = fontsel->filter_clists[prop];
+ gtk_widget_realize (clist);
+ inactive_fg = &clist->style->fg[GTK_STATE_INSENSITIVE];
+ inactive_bg = &clist->style->bg[GTK_STATE_INSENSITIVE];
+ for (row = 1; row < GTK_CLIST(clist)->rows; row++)
+ {
+ index = GPOINTER_TO_INT (gtk_clist_get_row_data(GTK_CLIST(clist),
+ row));
+ /* Set the colour according to the base filter. */
+ if (gtk_font_selection_filter_state (fontsel, GTK_FONT_FILTER_BASE,
+ prop, index) == NOT_FILTERED)
+ {
+ fg = inactive_fg;
+ bg = inactive_bg;
+ }
+ else
+ {
+ fg = NULL;
+ bg = NULL;
+ }
+ gtk_clist_set_foreground(GTK_CLIST(clist), row, fg);
+ gtk_clist_set_background(GTK_CLIST(clist), row, bg);
+
+ /* Set the selection state according to the user filter. */
+ if (gtk_font_selection_filter_state (fontsel, GTK_FONT_FILTER_USER,
+ prop, index) == FILTERED
+ && fg == NULL)
+ gtk_clist_select_row (GTK_CLIST (clist), row, 0);
+ else
+ gtk_clist_unselect_row (GTK_CLIST (clist), row, 0);
+ }
+ }
+}
+
+
+/* Returns whether a property value is in the filter or not, or if the
+ property has no filter set. */
+static GtkFontPropertyFilterState
+gtk_font_selection_filter_state (GtkFontSelection *fontsel,
+ GtkFontFilterType filter_type,
+ gint property,
+ gint index)
+{
+ GtkFontFilter *filter;
+ gint i;
+
+ filter = &fontsel->filters[filter_type];
+ if (filter->property_nfilters[property] == 0)
+ return NOT_SET;
+
+ for (i = 0; i < filter->property_nfilters[property]; i++)
+ {
+ if (filter->property_filters[property][i] == index)
+ return FILTERED;
+ }
+ return NOT_FILTERED;
+}
+
+
+#ifdef GDK_WINDOWING_WIN32
+
+static gint num_fonts;
+static gint font_names_size;
+static gchar **xfontnames;
+static HDC hdc;
+
+static char *
+logfont_to_xlfd (const LOGFONT *lfp,
+ int size,
+ int res,
+ int avg_width)
+{
+ const gchar *weight;
+ const gchar *registry, *encoding;
+ int point_size;
+ static int logpixelsy = 0;
+ gchar facename[LF_FACESIZE*3];
+ gchar *p;
+ const gchar *q;
+
+ if (logpixelsy == 0)
+ {
+ HDC hdc = GetDC (NULL);
+ logpixelsy = GetDeviceCaps (hdc, LOGPIXELSY);
+ ReleaseDC (NULL, hdc);
+ }
+
+ /* Don't use _() here, only N_(), the actual translation is done elsewhere */
+ if (lfp->lfWeight >= FW_HEAVY)
+ weight = N_("heavy");
+ else if (lfp->lfWeight >= FW_EXTRABOLD)
+ weight = N_("extrabold");
+ else if (lfp->lfWeight >= FW_BOLD)
+ weight = N_("bold");
+#ifdef FW_DEMIBOLD
+ else if (lfp->lfWeight >= FW_DEMIBOLD)
+ weight = N_("demibold");
+#endif
+ else if (lfp->lfWeight >= FW_MEDIUM)
+ weight = N_("medium");
+ else if (lfp->lfWeight >= FW_NORMAL)
+ weight = N_("normal");
+ else if (lfp->lfWeight >= FW_LIGHT)
+ weight = N_("light");
+ else if (lfp->lfWeight >= FW_EXTRALIGHT)
+ weight = N_("extralight");
+ else if (lfp->lfWeight >= FW_THIN)
+ weight = N_("thin");
+ else
+ weight = N_("regular");
+
+ if (lfp->lfCharSet == ANSI_CHARSET)
+ {
+ registry = "iso8859";
+ encoding = "1";
+ }
+ else
+ {
+ registry = "windows";
+ if (lfp->lfCharSet == DEFAULT_CHARSET)
+ encoding = "default";
+ else if (lfp->lfCharSet == SYMBOL_CHARSET)
+ encoding = "symbol";
+ else if (lfp->lfCharSet == SHIFTJIS_CHARSET)
+ encoding = "shiftjis";
+ else if (lfp->lfCharSet == GB2312_CHARSET)
+ encoding = "gb2312";
+ else if (lfp->lfCharSet == HANGEUL_CHARSET)
+ encoding = "hangeul";
+ else if (lfp->lfCharSet == CHINESEBIG5_CHARSET)
+ encoding = "chinesebig5";
+ else if (lfp->lfCharSet == OEM_CHARSET)
+ encoding = "oem";
+#ifdef JOHAB_CHARSET
+ else if (lfp->lfCharSet == JOHAB_CHARSET)
+ encoding = "johab";
+#endif
+ else if (lfp->lfCharSet == HEBREW_CHARSET)
+ encoding = "hebrew";
+ else if (lfp->lfCharSet == ARABIC_CHARSET)
+ encoding = "arabic";
+ else if (lfp->lfCharSet == GREEK_CHARSET)
+ encoding = "greek";
+ else if (lfp->lfCharSet == TURKISH_CHARSET)
+ encoding = "turkish";
+ else if (lfp->lfCharSet == THAI_CHARSET)
+ encoding = "thai";
+ else if (lfp->lfCharSet == EASTEUROPE_CHARSET)
+ encoding = "easteurope";
+ else if (lfp->lfCharSet == RUSSIAN_CHARSET)
+ encoding = "russian";
+ else if (lfp->lfCharSet == MAC_CHARSET)
+ encoding = "mac";
+ else if (lfp->lfCharSet == BALTIC_CHARSET)
+ encoding = "baltic";
+ else
+ encoding = "unknown";
+ }
+
+ point_size = (int) (((double) size/logpixelsy) * 720.);