📄 gtkfontsel.c
字号:
if (gtk_font_selection_style_visible(fontsel, font, style)) { styles[style].flags &= ~GTK_FONT_DISPLAYED; if (charset_index == -1) charset_index = styles[style].properties[CHARSET]; else if (charset_index != styles[style].properties[CHARSET]) show_charset = TRUE; } else styles[style].flags |= GTK_FONT_DISPLAYED; } /* Step through the undisplayed styles, finding the next charset which hasn't been displayed yet. Then display the charset on one line, if necessary, and the visible styles indented beneath it. */ inactive_fg = &fontsel->font_style_clist->style->fg[GTK_STATE_INSENSITIVE]; inactive_bg = &fontsel->font_style_clist->style->bg[GTK_STATE_INSENSITIVE]; for (style = 0; style < font->nstyles; style++) { if (styles[style].flags & GTK_FONT_DISPLAYED) continue; if (show_charset) { charset_index = styles[style].properties[CHARSET]; charset = fontsel_info->properties[CHARSET] [charset_index]; row = gtk_clist_append(GTK_CLIST(fontsel->font_style_clist), &charset); gtk_clist_set_row_data(GTK_CLIST(fontsel->font_style_clist), row, (gpointer) -1); if (GTK_WIDGET_REALIZED (fontsel->font_style_clist)) { gtk_clist_set_foreground(GTK_CLIST(fontsel->font_style_clist), row, inactive_fg); gtk_clist_set_background(GTK_CLIST(fontsel->font_style_clist), row, inactive_bg); } } for (tmpstyle = style; tmpstyle < font->nstyles; tmpstyle++) { if (styles[tmpstyle].flags & GTK_FONT_DISPLAYED || charset_index != styles[tmpstyle].properties[CHARSET]) continue; styles[tmpstyle].flags |= GTK_FONT_DISPLAYED; weight_index = styles[tmpstyle].properties[WEIGHT]; slant_index = styles[tmpstyle].properties[SLANT]; set_width_index = styles[tmpstyle].properties[SET_WIDTH]; spacing_index = styles[tmpstyle].properties[SPACING]; weight = fontsel_info->properties[WEIGHT] [weight_index]; slant = fontsel_info->properties[SLANT] [slant_index]; set_width = fontsel_info->properties[SET_WIDTH][set_width_index]; spacing = fontsel_info->properties[SPACING] [spacing_index]; /* Convert '(nil)' weights to 'regular', since it looks nicer. */ if (!g_strcasecmp(weight, N_("(nil)"))) weight = N_("regular"); /* We don't show default values or (nil) in the other properties. */ if (!g_strcasecmp(slant, "r")) slant = NULL; else if (!g_strcasecmp(slant, "(nil)")) slant = NULL; else if (!g_strcasecmp(slant, "i")) slant = N_("italic"); else if (!g_strcasecmp(slant, "o")) slant = N_("oblique"); else if (!g_strcasecmp(slant, "ri")) slant = N_("reverse italic"); else if (!g_strcasecmp(slant, "ro")) slant = N_("reverse oblique"); else if (!g_strcasecmp(slant, "ot")) slant = N_("other"); if (!g_strcasecmp(set_width, "normal")) set_width = NULL; else if (!g_strcasecmp(set_width, "(nil)")) set_width = NULL; if (!g_strcasecmp(spacing, "p")) spacing = NULL; else if (!g_strcasecmp(spacing, "(nil)")) spacing = NULL; else if (!g_strcasecmp(spacing, "m")) spacing = N_("[M]"); else if (!g_strcasecmp(spacing, "c")) spacing = N_("[C]"); /* Add the strings together, making sure there is 1 space between them */ strcpy(buffer, _(weight)); if (slant) { strcat(buffer, " "); strcat(buffer, _(slant)); } if (set_width) { strcat(buffer, " "); strcat(buffer, _(set_width)); } if (spacing) { strcat(buffer, " "); strcat(buffer, _(spacing)); } new_item = buffer; row = gtk_clist_append(GTK_CLIST(fontsel->font_style_clist), &new_item); if (show_charset) gtk_clist_set_shift(GTK_CLIST(fontsel->font_style_clist), row, 0, 0, 4); gtk_clist_set_row_data(GTK_CLIST(fontsel->font_style_clist), row, GINT_TO_POINTER (tmpstyle)); } } gtk_clist_thaw (GTK_CLIST(fontsel->font_style_clist));}/* This selects a style when the user selects a font. It just uses the first available style at present. I was thinking of trying to maintain the selected style, e.g. bold italic, when the user selects different fonts. However, the interface is so easy to use now I'm not sure it's worth it. Note: This will load a font. */static voidgtk_font_selection_select_best_style(GtkFontSelection *fontsel, gboolean use_first){ FontInfo *font; FontStyle *styles; gint row, prop, style, matched; gint best_matched = -1, best_style = -1, best_row = -1; #ifdef FONTSEL_DEBUG g_message("In select_best_style\n");#endif font = &fontsel_info->font_info[fontsel->font_index]; styles = &fontsel_info->font_styles[font->style_index]; for (row = 0; row < GTK_CLIST(fontsel->font_style_clist)->rows; row++) { style = GPOINTER_TO_INT (gtk_clist_get_row_data (GTK_CLIST (fontsel->font_style_clist), row)); /* Skip charset rows. */ if (style == -1) continue; /* If we just want the first style, we've got it. */ if (use_first) { best_style = style; best_row = row; break; } matched = 0; for (prop = 0; prop < GTK_NUM_STYLE_PROPERTIES; prop++) { if (fontsel->property_values[prop] == styles[style].properties[prop]) matched++; } if (matched > best_matched) { best_matched = matched; best_style = style; best_row = row; } } g_return_if_fail (best_style != -1); g_return_if_fail (best_row != -1); fontsel->style = best_style; for (prop = 0; prop < GTK_NUM_STYLE_PROPERTIES; prop++) fontsel->property_values[prop] = styles[fontsel->style].properties[prop]; gtk_clist_select_row(GTK_CLIST(fontsel->font_style_clist), best_row, 0); if (gtk_clist_row_is_visible(GTK_CLIST(fontsel->font_style_clist), best_row) != GTK_VISIBILITY_FULL) gtk_clist_moveto(GTK_CLIST(fontsel->font_style_clist), best_row, -1, 0.5, 0); gtk_font_selection_show_available_sizes (fontsel); gtk_font_selection_select_best_size (fontsel);}/* This is called when a style is selected in the list. */static voidgtk_font_selection_select_style (GtkWidget *w, gint row, gint column, GdkEventButton *bevent, gpointer data){ GtkFontSelection *fontsel; FontInfo *font_info; FontInfo *font; FontStyle *styles; gint style, prop; gchar *text; #ifdef FONTSEL_DEBUG g_message("In select_style\n");#endif fontsel = GTK_FONT_SELECTION(data); font_info = fontsel_info->font_info; font = &font_info[fontsel->font_index]; styles = &fontsel_info->font_styles[font->style_index]; if (bevent && !GTK_WIDGET_HAS_FOCUS (w)) gtk_widget_grab_focus (w); /* The style index is stored in the row data, so we just need to copy the style values into the fontsel and reload the font. */ style = GPOINTER_TO_INT (gtk_clist_get_row_data(GTK_CLIST(fontsel->font_style_clist), row)); /* Don't allow selection of charset rows. */ if (style == -1) { gtk_clist_unselect_row(GTK_CLIST(fontsel->font_style_clist), row, 0); return; } gtk_clist_get_text(GTK_CLIST(fontsel->font_style_clist), row, 0, &text); gtk_entry_set_text(GTK_ENTRY(fontsel->font_style_entry), text); for (prop = 0; prop < GTK_NUM_STYLE_PROPERTIES; prop++) fontsel->property_values[prop] = styles[style].properties[prop]; if (fontsel->style == style) return; fontsel->style = style; gtk_font_selection_show_available_sizes (fontsel); gtk_font_selection_select_best_size (fontsel);}/* This shows all the available sizes in the size clist, according to the current metric and the current font & style. */static voidgtk_font_selection_show_available_sizes (GtkFontSelection *fontsel){ FontInfo *font; FontStyle *styles, *style; const guint16 *standard_sizes; guint16 *bitmapped_sizes; gint nstandard_sizes, nbitmapped_sizes; gchar buffer[16], *size; gfloat bitmap_size_float = 0.; guint16 bitmap_size = 0; gboolean can_match; gint type_filter; #ifdef FONTSEL_DEBUG g_message("In show_available_sizes\n");#endif font = &fontsel_info->font_info[fontsel->font_index]; styles = &fontsel_info->font_styles[font->style_index]; style = &styles[fontsel->style]; standard_sizes = font_sizes; nstandard_sizes = sizeof(font_sizes) / sizeof(font_sizes[0]); if (fontsel->metric == GTK_FONT_METRIC_POINTS) { bitmapped_sizes = &fontsel_info->point_sizes[style->point_sizes_index]; nbitmapped_sizes = style->npoint_sizes; } else { bitmapped_sizes = &fontsel_info->pixel_sizes[style->pixel_sizes_index]; nbitmapped_sizes = style->npixel_sizes; } /* Only show the standard sizes if a scalable font is available. */ type_filter = fontsel->filters[GTK_FONT_FILTER_BASE].font_type & fontsel->filters[GTK_FONT_FILTER_USER].font_type; if (!((style->flags & GTK_FONT_SCALABLE_BITMAP && type_filter & GTK_FONT_SCALABLE_BITMAP) || (style->flags & GTK_FONT_SCALABLE && type_filter & GTK_FONT_SCALABLE))) nstandard_sizes = 0; gtk_clist_freeze (GTK_CLIST(fontsel->size_clist)); gtk_clist_clear (GTK_CLIST(fontsel->size_clist)); /* Interleave the standard sizes with the bitmapped sizes so we get a list of ascending sizes. If the metric is points, we have to convert the decipoints to points. */ while (nstandard_sizes || nbitmapped_sizes) { can_match = TRUE; if (nbitmapped_sizes) { if (fontsel->metric == GTK_FONT_METRIC_POINTS) { if (*bitmapped_sizes % 10 != 0) can_match = FALSE; bitmap_size = *bitmapped_sizes / 10; bitmap_size_float = *bitmapped_sizes / 10; } else { bitmap_size = *bitmapped_sizes; bitmap_size_float = *bitmapped_sizes; } } if (can_match && nstandard_sizes && nbitmapped_sizes && *standard_sizes == bitmap_size) { sprintf(buffer, "%i *", *standard_sizes); standard_sizes++; nstandard_sizes--; bitmapped_sizes++; nbitmapped_sizes--; } else if (nstandard_sizes && (!nbitmapped_sizes || (gfloat)*standard_sizes < bitmap_size_float)) { sprintf(buffer, "%i", *standard_sizes); standard_sizes++; nstandard_sizes--; } else { if (fontsel->metric == GTK_FONT_METRIC_POINTS) { if (*bitmapped_sizes % 10 == 0) sprintf(buffer, "%i *", *bitmapped_sizes / 10); else sprintf(buffer, "%i.%i *", *bitmapped_sizes / 10, *bitmapped_sizes % 10); } else { sprintf(buffer, "%i *", *bitmapped_sizes); } bitmapped_sizes++; nbitmapped_sizes--; } size = buffer; gtk_clist_append(GTK_CLIST(fontsel->size_clist), &size); } gtk_clist_thaw (GTK_CLIST(fontsel->size_clist));}/* If the user hits return in the font size entry, we change to the new font size. */static gintgtk_font_selection_size_key_press (GtkWidget *w, GdkEventKey *event, gpointer data){ GtkFontSelection *fontsel; gint new_size; gfloat new_size_float; gchar *text; #ifdef FONTSEL_DEBUG g_message("In size_key_press\n");#endif fontsel = GTK_FONT_SELECTION(data); if (event->keyval == GDK_Return) { text = gtk_entry_get_text (GTK_ENTRY (fontsel->size_entry)); if (fontsel->metric == GTK_FONT_METRIC_PIXELS) { new_size = atoi (text); if (new_size < 2) new_size = 2; } else { new_size_float = atof (text) * 10; new_size = (gint) new_size_float; if (new_size < 20) new_size = 20; } /* Remember that this size was set explicitly. */ fontsel->selected_size = new_size; /* Check if the font size has changed, and return if it hasn't. */ if (fontsel->size == new_size) return TRUE; fontsel->size = new_size;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -