Exemple #1
0
HFONT
_pango_win32_font_get_hfont (PangoFont *font)
{
  PangoWin32Font *win32font = (PangoWin32Font *)font;
  PangoWin32FontCache *cache;

  if (!win32font)
    return NULL;

  if (!win32font->hfont)
    {
      cache = pango_win32_font_map_get_font_cache (win32font->fontmap);
      if (G_UNLIKELY (!cache))
        return NULL;

      win32font->hfont = pango_win32_font_cache_loadw (cache, &win32font->logfontw);
      if (!win32font->hfont)
	{
	  gchar *face_utf8 = g_utf16_to_utf8 (win32font->logfontw.lfFaceName,
					      -1, NULL, NULL, NULL);
	  g_warning ("Cannot load font '%s\n", face_utf8);
	  g_free (face_utf8);
	  return NULL;
	}
    }

  return win32font->hfont;
}
/**
 * pango_win32_font_cache_load:
 * @cache: a #PangoWin32FontCache
 * @logfont: a pointer to a LOGFONTA structure describing the font to load.
 *
 * Creates a HFONT from a LOGFONTA. The
 * result may be newly loaded, or it may have been previously
 * stored
 *
 * Return value: The font structure, or %NULL if the font could
 * not be loaded. In order to free this structure, you must call
 * pango_win32_font_cache_unload().
 **/
HFONT
pango_win32_font_cache_load (PangoWin32FontCache *cache,
			     const LOGFONTA      *lfp)
{
  LOGFONTW lf;

  /* We know that the lfFaceName is the last member in the structs */
  *(LOGFONTA *)&lf = *lfp;
  
  if (!MultiByteToWideChar (CP_ACP, MB_ERR_INVALID_CHARS,
			    lfp->lfFaceName, -1,
			    lf.lfFaceName, G_N_ELEMENTS (lf.lfFaceName)))
    return NULL;

  return pango_win32_font_cache_loadw (cache, &lf);
}