pangowin32-fontmap.c

来自「GTK+-2.0源码之pango-1.15.6.tar.gz」· C语言 代码 · 共 1,154 行 · 第 1/3 页

C
1,154
字号
 */static voidpango_win32_insert_font (PangoWin32FontMap *win32fontmap,			 LOGFONT           *lfp){  LOGFONT *lfp2 = NULL;  PangoFontDescription *description;  PangoWin32Family *font_family;  PangoWin32Face *win32face;  PangoWin32SizeInfo *size_info;  GSList *tmp_list;  gint i;  PING(("face=%s,charset=%d,it=%d,wt=%ld,ht=%ld",lfp->lfFaceName,lfp->lfCharSet,lfp->lfItalic,lfp->lfWeight,lfp->lfHeight));  /* Ignore Symbol fonts (which don't have any Unicode mapping   * table). We could also be fancy and use the PostScript glyph name   * table for such if present, and build a Unicode map by mapping   * each PostScript glyph name to Unicode character. Oh well.   */  if (lfp->lfCharSet == SYMBOL_CHARSET)    return;  /* First insert the LOGFONT into the list of LOGFONTs for the typeface name   */  size_info = g_hash_table_lookup (win32fontmap->size_infos, lfp);  if (!size_info)    {      PING(("SizeInfo not found"));      size_info = g_new (PangoWin32SizeInfo, 1);      size_info->logfonts = NULL;      lfp2 = g_new (LOGFONT, 1);      *lfp2 = *lfp;      g_hash_table_insert (win32fontmap->size_infos, lfp2, size_info);    }  else    {      /* Don't store logfonts that differ only in charset       */      tmp_list = size_info->logfonts;      while (tmp_list)	{	  LOGFONT *rover = tmp_list->data;	  /* We know that lfWeight, lfItalic and lfFaceName match.  We	   * don't check lfHeight and lfWidth, those are used	   * when creating a font.	   */	  if (rover->lfEscapement == lfp->lfEscapement &&	      rover->lfOrientation == lfp->lfOrientation &&	      rover->lfUnderline == lfp->lfUnderline &&	      rover->lfStrikeOut == lfp->lfStrikeOut)	    {	      PING(("already have it"));	      return;	    }	  tmp_list = tmp_list->next;	}    }  if (lfp2 == NULL)    {      lfp2 = g_new (LOGFONT, 1);      *lfp2 = *lfp;    }  size_info->logfonts = g_slist_prepend (size_info->logfonts, lfp2);  PING(("g_slist_length(size_info->logfonts)=%d", g_slist_length(size_info->logfonts)));  description = pango_win32_font_description_from_logfont (lfp2);  /* In some cases, extracting a name for a font can fail; such fonts   * aren't usable for us   */  if (!pango_font_description_get_family (description))    {      pango_font_description_free (description);      return;    }  win32face = g_object_new (PANGO_WIN32_TYPE_FACE, NULL);  win32face->description = description;  win32face->cached_fonts = NULL;  for (i = 0; i < PANGO_WIN32_N_COVERAGES; i++)     win32face->coverages[i] = NULL;  win32face->logfont = *lfp;  win32face->cmap_format = 0;  win32face->cmap = NULL;  font_family =    pango_win32_get_font_family (win32fontmap,				 pango_font_description_get_family (win32face->description));  font_family->font_entries = g_slist_append (font_family->font_entries, win32face);  PING(("g_slist_length(font_family->font_entries)=%d", g_slist_length(font_family->font_entries)));  win32fontmap->n_fonts++;#if 1 /* Thought pango.aliases would make this code unnecessary, but no. */  /*   * There are magic family names coming from the X implementation.   * They can be simply mapped to lfPitchAndFamily flag of the logfont   * struct. These additional entries should probably only be references   * to the respective entry created above. Thy are simply using the   * same entry at the moment and it isn't crashing on g_free () ???   * Maybe a memory leak ...   */  switch (lfp->lfPitchAndFamily & 0xF0)    {    case FF_MODERN : /* monospace */      PING(("monospace"));      font_family->is_monospace = TRUE; /* modify before reuse */      font_family = pango_win32_get_font_family (win32fontmap, "monospace");      font_family->font_entries = g_slist_append (font_family->font_entries, win32face);      win32fontmap->n_fonts++;      break;    case FF_ROMAN : /* serif */      PING(("serif"));      font_family = pango_win32_get_font_family (win32fontmap, "serif");      font_family->font_entries = g_slist_append (font_family->font_entries, win32face);      win32fontmap->n_fonts++;      break;    case  FF_SWISS  : /* sans */      PING(("sans"));      font_family = pango_win32_get_font_family (win32fontmap, "sans");      font_family->font_entries = g_slist_append (font_family->font_entries, win32face);      win32fontmap->n_fonts++;      break;    }  /* Some other magic names */  /* Recognize just "courier" for "courier new" */  if (g_ascii_strcasecmp (win32face->logfont.lfFaceName, "courier new") == 0)    {      font_family = pango_win32_get_font_family (win32fontmap, "courier");      font_family->font_entries = g_slist_append (font_family->font_entries, win32face);      win32fontmap->n_fonts++;    }#endif}/* Given a LOGFONT and size, make a matching LOGFONT corresponding to * an installed font. */voidpango_win32_make_matching_logfont (PangoFontMap  *fontmap,				   const LOGFONT *lfp,				   int            size,				   LOGFONT       *out){  PangoWin32FontMap *win32fontmap;  GSList *tmp_list;  PangoWin32SizeInfo *size_info;  LOGFONT *closest_match = NULL;  gint match_distance = 0;  PING(("lfp.face=%s,wt=%ld,ht=%ld,size:%d",lfp->lfFaceName,lfp->lfWeight,lfp->lfHeight,size));  win32fontmap = PANGO_WIN32_FONT_MAP (fontmap);  size_info = g_hash_table_lookup (win32fontmap->size_infos, lfp);  if (!size_info)    {      PING(("SizeInfo not found"));      return;    }  tmp_list = size_info->logfonts;  while (tmp_list)    {      LOGFONT *tmp_logfont = tmp_list->data;      int font_size = abs (tmp_logfont->lfHeight);      if (size != -1)	{	  int new_distance = (font_size == 0) ? 0 : abs (font_size - size);	  if (!closest_match ||	      new_distance < match_distance ||	      (new_distance < PANGO_SCALE && font_size != 0))	    {	      closest_match = tmp_logfont;	      match_distance = new_distance;	    }	}      tmp_list = tmp_list->next;    }  if (closest_match)    {      /* OK, we have a match; let's modify it to fit this size */      *out = *closest_match;      out->lfHeight = -(int)((double)size / win32fontmap->resolution + 0.5);      out->lfWidth = 0;    }  else    *out = *lfp; /* Whatever. We need to pass something... */}gintpango_win32_coverage_language_classify (PangoLanguage *lang){  if (pango_language_matches (lang, "zh-tw"))    return PANGO_WIN32_COVERAGE_ZH_TW;  else if (pango_language_matches (lang, "zh-cn"))    return PANGO_WIN32_COVERAGE_ZH_CN;  else if (pango_language_matches (lang, "ja"))    return PANGO_WIN32_COVERAGE_JA;  else if (pango_language_matches (lang, "ko"))    return PANGO_WIN32_COVERAGE_KO;  else if (pango_language_matches (lang, "vi"))    return PANGO_WIN32_COVERAGE_VI;  else    return PANGO_WIN32_COVERAGE_UNSPEC;}voidpango_win32_font_entry_set_coverage (PangoWin32Face *face,				     PangoCoverage  *coverage,				     PangoLanguage  *lang){  face->coverages[pango_win32_coverage_language_classify (lang)] = pango_coverage_ref (coverage);}static PangoFontDescription *pango_win32_face_describe (PangoFontFace *face){  PangoWin32Face *win32face = PANGO_WIN32_FACE (face);  return pango_font_description_copy (win32face->description);}static const char *pango_win32_face_get_face_name (PangoFontFace *face){  PangoWin32Face *win32face = PANGO_WIN32_FACE (face);  if (!win32face->face_name)    {      PangoFontDescription *desc = pango_font_face_describe (face);      pango_font_description_unset_fields (desc,					   PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_SIZE);      win32face->face_name = pango_font_description_to_string (desc);      pango_font_description_free (desc);    }  return win32face->face_name;}static voidpango_win32_face_class_init (PangoFontFaceClass *class){  class->describe = pango_win32_face_describe;  class->get_face_name = pango_win32_face_get_face_name;  class->list_sizes = pango_win32_face_list_sizes;}static voidpango_win32_face_list_sizes (PangoFontFace  *face,			     int           **sizes,			     int            *n_sizes){  /*   * for scalable fonts it's simple, and currently we only have such   * see : pango_win32_enum_proc(), TRUETYPE_FONTTYPE   */  *sizes = NULL;  *n_sizes = 0;}GTypepango_win32_face_get_type (void){  static GType object_type = 0;  if (!object_type)    {      const GTypeInfo object_info =      {	sizeof (PangoFontFaceClass),	(GBaseInitFunc) NULL,	(GBaseFinalizeFunc) NULL,	(GClassInitFunc) pango_win32_face_class_init,	NULL,           /* class_finalize */	NULL,           /* class_data */	sizeof (PangoWin32Face),	0,              /* n_preallocs */	(GInstanceInitFunc) NULL,      };      object_type = g_type_register_static (PANGO_TYPE_FONT_FACE,					    I_("PangoWin32Face"),					    &object_info, 0);    }  return object_type;}PangoCoverage *pango_win32_font_entry_get_coverage (PangoWin32Face *face,				     PangoLanguage  *lang){  gint i = pango_win32_coverage_language_classify (lang);  if (face->coverages[i])    {      pango_coverage_ref (face->coverages[i]);      return face->coverages[i];    }  return NULL;}voidpango_win32_font_entry_remove (PangoWin32Face *face,			       PangoFont      *font){  face->cached_fonts = g_slist_remove (face->cached_fonts, font);}/** * pango_win32_font_map_get_font_cache: * @font_map: a #PangoWin32FontMap. * * Obtains the font cache associated with the given font map. * * Return value: the #PangoWin32FontCache of @font_map. **/PangoWin32FontCache *pango_win32_font_map_get_font_cache (PangoFontMap *font_map){  g_return_val_if_fail (font_map != NULL, NULL);  g_return_val_if_fail (PANGO_WIN32_IS_FONT_MAP (font_map), NULL);  return PANGO_WIN32_FONT_MAP (font_map)->font_cache;}voidpango_win32_fontmap_cache_add (PangoFontMap   *fontmap,			       PangoWin32Font *win32font){  PangoWin32FontMap *win32fontmap = PANGO_WIN32_FONT_MAP (fontmap);  if (win32fontmap->freed_fonts->length == MAX_FREED_FONTS)    {      PangoWin32Font *old_font = g_queue_pop_tail (win32fontmap->freed_fonts);      g_object_unref (old_font);    }  g_object_ref (win32font);  g_queue_push_head (win32fontmap->freed_fonts, win32font);  win32font->in_cache = TRUE;}voidpango_win32_fontmap_cache_remove (PangoFontMap   *fontmap,				  PangoWin32Font *win32font){  PangoWin32FontMap *win32fontmap = PANGO_WIN32_FONT_MAP (fontmap);  GList *link = g_queue_find (win32fontmap->freed_fonts, win32font);  if (link)    g_queue_delete_link (win32fontmap->freed_fonts, link);  win32font->in_cache = FALSE;  g_object_unref (win32font);}static voidpango_win32_fontmap_cache_clear (PangoWin32FontMap *win32fontmap){  g_list_foreach (win32fontmap->freed_fonts->head, (GFunc)g_object_unref, NULL);  g_queue_free (win32fontmap->freed_fonts);  win32fontmap->freed_fonts = g_queue_new ();}

⌨️ 快捷键说明

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