⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtkfontsel.c

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 C
📖 第 1 页 / 共 5 页
字号:
      gtk_font_selection_select_best_size (fontsel);      return TRUE;    }    return FALSE;}/* This tries to select the closest size to the current size, though it   may have to change the size if only unscaled bitmaps are available.   Note: this will load a font. */static voidgtk_font_selection_select_best_size(GtkFontSelection *fontsel){  FontInfo *font;  FontStyle *styles, *style;  gchar *text;  gint row, best_row = 0, size, size_fraction, best_size = 0, nmatched;  gboolean found = FALSE;  gchar buffer[32];  GList *selection;  gint type_filter;  #ifdef FONTSEL_DEBUG  g_message("In select_best_size\n");#endif  font = &fontsel_info->font_info[fontsel->font_index];  styles = &fontsel_info->font_styles[font->style_index];  style = &styles[fontsel->style];    /* Find the closest size available in the size clist. If the exact size is     in the list set found to TRUE. */  for (row = 0; row < GTK_CLIST(fontsel->size_clist)->rows; row++)    {      gtk_clist_get_text(GTK_CLIST(fontsel->size_clist), row, 0, &text);      nmatched = sscanf(text, "%i.%i", &size, &size_fraction);      if (fontsel->metric == GTK_FONT_METRIC_POINTS)	{	  size *= 10;	  if (nmatched == 2)	    size += size_fraction;	}            if (size == fontsel->selected_size)	{	  found = TRUE;	  best_size = size;	  best_row = row;	  break;	}      else if (best_size == 0	       || abs(size - fontsel->selected_size)	       < (abs(best_size - fontsel->selected_size)))	{	  best_size = size;	  best_row = row;	}    }    /* If we aren't scaling bitmapped fonts and this is a bitmapped font, we     need to use the closest size found. */  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)))    found = TRUE;    if (found)    {      fontsel->size = best_size;      gtk_clist_moveto(GTK_CLIST(fontsel->size_clist), best_row, -1, 0.5, 0);      gtk_clist_select_row(GTK_CLIST(fontsel->size_clist), best_row, 0);    }  else    {      fontsel->size = fontsel->selected_size;      selection = GTK_CLIST(fontsel->size_clist)->selection;      if (selection)	gtk_clist_unselect_row(GTK_CLIST(fontsel->size_clist),			       GPOINTER_TO_INT (selection->data), 0);      gtk_clist_moveto(GTK_CLIST(fontsel->size_clist), best_row, -1, 0.5, 0);            /* Show the size in the size entry. */      if (fontsel->metric == GTK_FONT_METRIC_PIXELS)	sprintf(buffer, "%i", fontsel->size);      else	{	  if (fontsel->size % 10 == 0)	    sprintf(buffer, "%i", fontsel->size / 10);	  else	    sprintf(buffer, "%i.%i", fontsel->size / 10, fontsel->size % 10);	}      gtk_entry_set_text (GTK_ENTRY (fontsel->size_entry), buffer);    }  gtk_font_selection_load_font (fontsel);}/* This is called when a size is selected in the list. */static voidgtk_font_selection_select_size (GtkWidget      *w,				gint	        row,				gint	        column,				GdkEventButton *bevent,				gpointer        data){  GtkFontSelection *fontsel;  gint new_size;  gchar *text;  gchar buffer[16];  gint i;  #ifdef FONTSEL_DEBUG  g_message("In select_size\n");#endif  fontsel = GTK_FONT_SELECTION(data);    if (bevent && !GTK_WIDGET_HAS_FOCUS (w))    gtk_widget_grab_focus (w);    /* Copy the size from the clist to the size entry, but without the bitmapped     marker ('*'). */  gtk_clist_get_text(GTK_CLIST(fontsel->size_clist), row, 0, &text);  i = 0;  while (i < 15 && (text[i] == '.' || (text[i] >= '0' && text[i] <= '9')))    {      buffer[i] = text[i];      i++;    }  buffer[i] = '\0';  gtk_entry_set_text(GTK_ENTRY(fontsel->size_entry), buffer);    /* Check if the font size has changed, and return if it hasn't. */  new_size = atoi(text);  if (fontsel->metric == GTK_FONT_METRIC_POINTS)    new_size *= 10;    if (fontsel->size == new_size)    return;    /* If the size was selected by the user we set the selected_size. */  fontsel->selected_size = new_size;    fontsel->size = new_size;  gtk_font_selection_load_font (fontsel);}/* This is called when the pixels or points radio buttons are pressed. */static voidgtk_font_selection_metric_callback (GtkWidget *w,				    gpointer   data){  GtkFontSelection *fontsel = GTK_FONT_SELECTION(data);  #ifdef FONTSEL_DEBUG  g_message("In metric_callback\n");#endif  if (GTK_TOGGLE_BUTTON(fontsel->pixels_button)->active)    {      if (fontsel->metric == GTK_FONT_METRIC_PIXELS)	return;      fontsel->metric = GTK_FONT_METRIC_PIXELS;      fontsel->size = (fontsel->size + 5) / 10;      fontsel->selected_size = (fontsel->selected_size + 5) / 10;    }  else    {      if (fontsel->metric == GTK_FONT_METRIC_POINTS)	return;      fontsel->metric = GTK_FONT_METRIC_POINTS;      fontsel->size *= 10;      fontsel->selected_size *= 10;    }  if (fontsel->font_index != -1)    {      gtk_font_selection_show_available_sizes (fontsel);      gtk_font_selection_select_best_size (fontsel);    }}/* This searches the given property table and returns the index of the given   string, or 0, which is the wildcard '*' index, if it's not found. */static guint16gtk_font_selection_field_to_index (gchar **table,				   gint    ntable,				   gchar  *field){  gint i;    for (i = 0; i < ntable; i++)    if (strcmp (field, table[i]) == 0)      return i;    return 0;}/* This attempts to load the current font, and returns TRUE if it succeeds. */static gbooleangtk_font_selection_load_font (GtkFontSelection *fontsel){  GdkFont *font;  gchar *fontname, *label_text;    if (fontsel->font)    gdk_font_unref (fontsel->font);  fontsel->font = NULL;    /* If no family has been selected yet, just return FALSE. */  if (fontsel->font_index == -1)    return FALSE;    fontname = gtk_font_selection_get_font_name (fontsel);  if (fontname)    {#ifdef FONTSEL_DEBUG      g_message("Loading: %s\n", fontname);#endif      font = gdk_font_load (fontname);      g_free(fontname);            if (font)	{	  fontsel->font = font;	  /* Make sure the message label is empty, but don't change it unless	     it's necessary as it results in a resize of the whole window! */	  gtk_label_get(GTK_LABEL(fontsel->message_label), &label_text);	  if (strcmp(label_text, ""))	    gtk_label_set_text(GTK_LABEL(fontsel->message_label), "");	  gtk_font_selection_update_preview (fontsel);	  return TRUE;	}      else 	{	  gtk_label_set_text(GTK_LABEL(fontsel->message_label),			     _("The selected font is not available."));	}    }  else    {      gtk_label_set_text(GTK_LABEL(fontsel->message_label),			 _("The selected font is not a valid font."));    }    return FALSE;}/* This sets the font in the preview entry to the selected font, and tries to   make sure that the preview entry is a reasonable size, i.e. so that the   text can be seen with a bit of space to spare. But it tries to avoid   resizing the entry every time the font changes.   This also used to shrink the preview if the font size was decreased, but   that made it awkward if the user wanted to resize the window themself. */static voidgtk_font_selection_update_preview (GtkFontSelection *fontsel){  GtkWidget *preview_entry;  GtkStyle *style;  gint text_height, new_height;  gchar *text;  XFontStruct *xfs;  #ifdef FONTSEL_DEBUG  g_message("In update_preview\n");#endif  style = gtk_style_new ();  gdk_font_unref (style->font);  style->font = fontsel->font;  gdk_font_ref (style->font);    preview_entry = fontsel->preview_entry;  gtk_widget_set_style (preview_entry, style);  gtk_style_unref(style);    text_height = preview_entry->style->font->ascent    + preview_entry->style->font->descent;  /* We don't ever want to be over MAX_PREVIEW_HEIGHT pixels high. */  new_height = text_height + 20;  if (new_height < INITIAL_PREVIEW_HEIGHT)    new_height = INITIAL_PREVIEW_HEIGHT;  if (new_height > MAX_PREVIEW_HEIGHT)    new_height = MAX_PREVIEW_HEIGHT;    if ((preview_entry->requisition.height < text_height + 10)      || (preview_entry->requisition.height > text_height + 40))    gtk_widget_set_usize(preview_entry, -1, new_height);    /* This sets the preview text, if it hasn't been set already. */  text = gtk_entry_get_text(GTK_ENTRY(fontsel->preview_entry));  if (strlen(text) == 0)    gtk_entry_set_text(GTK_ENTRY(fontsel->preview_entry), PREVIEW_TEXT);  gtk_entry_set_position(GTK_ENTRY(fontsel->preview_entry), 0);    /* If this is a 2-byte font display a message to say it may not be     displayed properly. */  xfs = GDK_FONT_XFONT(fontsel->font);  if (xfs->min_byte1 != 0 || xfs->max_byte1 != 0)    gtk_label_set_text(GTK_LABEL(fontsel->message_label),		       _("This is a 2-byte font and may not be displayed correctly."));}static voidgtk_font_selection_switch_page (GtkWidget       *w,				GtkNotebookPage *page,				gint             page_num,				gpointer         data){  GtkFontSelection *fontsel = GTK_FONT_SELECTION(data);    /* This function strangely gets called when the window is destroyed,     so we check here to see if the notebook is visible. */  if (!GTK_WIDGET_VISIBLE(w))    return;    if (page_num == 0)    gtk_font_selection_update_filter(fontsel);  else if (page_num == 1)    gtk_font_selection_show_font_info(fontsel);}static voidgtk_font_selection_show_font_info (GtkFontSelection *fontsel){  Atom font_atom, atom;  Bool status;  char *name;  gchar *fontname;  gchar field_buffer[XLFD_MAX_FIELD_LEN];  gchar *field;  gint i;  gboolean shown_actual_fields = FALSE;    fontname = gtk_font_selection_get_font_name(fontsel);  gtk_entry_set_text(GTK_ENTRY(fontsel->requested_font_name),		     fontname ? fontname : "");    gtk_clist_freeze (GTK_CLIST(fontsel->info_clist));  for (i = 0; i < GTK_XLFD_NUM_FIELDS; i++)    {      if (fontname)	field = gtk_font_selection_get_xlfd_field (fontname, i, field_buffer);      else	field = NULL;      if (field)	{	  if (i == XLFD_SLANT)	    field = gtk_font_selection_expand_slant_code(field);	  else if (i == XLFD_SPACING)	    field = gtk_font_selection_expand_spacing_code(field);	}      gtk_clist_set_text(GTK_CLIST(fontsel->info_clist), i, 1,			 field ? field : "");    }    if (fontsel->font)    {      font_atom = XInternAtom(GDK_DISPLAY(), "FONT", True);      if (font_atom != None)	{	  status = XGetFontProperty(GDK_FONT_XFONT(fontsel->font), font_atom,				    &atom);	  if (status == True)	    {	      name = XGetAtomName(GDK_DISPLAY(), atom);	      gtk_entry_set_text(GTK_ENTRY(fontsel->actual_font_name), name);	      	      for (i = 0; i < GTK_XLFD_NUM_FIELDS; i++)		{		  field = gtk_font_selection_get_xlfd_field (name, i,							     field_buffer);		  if (i == XLFD_SLANT)		    field = gtk_font_selection_expand_slant_code(field);		  else if (i == XLFD_SPACING)		    field

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -