bug 195868
GTK2: GetSystemFontInfo() needs to return valid font r=blizzard, sr=rbs
This commit is contained in:
Родитель
62fba60f00
Коммит
5fb73c8a9b
|
@ -68,6 +68,8 @@
|
|||
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
#include <pango/pango.h>
|
||||
#include <pango/pangox.h>
|
||||
#include <pango/pango-fontmap.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_ENABLE_XFT
|
||||
|
@ -776,6 +778,8 @@ ListFontProps(XFontStruct *aFont, Display *aDisplay)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(MOZ_ENABLE_COREXFONTS) || defined(MOZ_WIDGET_GTK)
|
||||
|
||||
#define LOCATE_MINUS(pos, str) { \
|
||||
pos = str.FindChar('-'); \
|
||||
if (pos < 0) \
|
||||
|
@ -787,8 +791,6 @@ ListFontProps(XFontStruct *aFont, Display *aDisplay)
|
|||
return ; \
|
||||
}
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK
|
||||
|
||||
static void
|
||||
AppendFontFFREName(nsString& aString, const char* aXLFDName)
|
||||
{
|
||||
|
@ -817,7 +819,9 @@ AppendFontFFREName(nsString& aString, const char* aXLFDName)
|
|||
|
||||
aString.AppendWithConversion(nameStr.get());
|
||||
}
|
||||
#endif /* MOZ_ENABLE_COREXFONTS || MOZ_WIDGET_GTK*/
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK
|
||||
static void
|
||||
AppendFontName(XFontStruct* aFontStruct, nsString& aString, Display *aDisplay)
|
||||
{
|
||||
|
@ -945,6 +949,13 @@ nsSystemFontsGTK::GetSystemFontInfo(GtkWidget *aWidget, nsFont* aFont,
|
|||
#endif /* MOZ_WIDGET_GTK */
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
|
||||
#ifdef MOZ_ENABLE_COREXFONTS
|
||||
static void xlfd_from_pango_font_description(GtkWidget *aWidget,
|
||||
const PangoFontDescription *aFontDesc,
|
||||
nsString& aFontName);
|
||||
#endif /* MOZ_ENABLE_COREXFONTS */
|
||||
|
||||
nsresult
|
||||
nsSystemFontsGTK::GetSystemFontInfo(GtkWidget *aWidget, nsFont* aFont,
|
||||
float aPixelsToTwips) const
|
||||
|
@ -961,7 +972,18 @@ nsSystemFontsGTK::GetSystemFontInfo(GtkWidget *aWidget, nsFont* aFont,
|
|||
desc = pango_font_description_from_string(fontname);
|
||||
|
||||
aFont->name.Truncate();
|
||||
aFont->name.AppendWithConversion(pango_font_description_get_family(desc));
|
||||
#ifdef MOZ_ENABLE_XFT
|
||||
if (NS_IsXftEnabled()) {
|
||||
aFont->name.AppendWithConversion(pango_font_description_get_family(desc));
|
||||
}
|
||||
#endif /* MOZ_ENABLE_XFT */
|
||||
|
||||
#ifdef MOZ_ENABLE_COREXFONTS
|
||||
// if name already set by Xft, do nothing
|
||||
if (!aFont->name.Length()) {
|
||||
xlfd_from_pango_font_description(aWidget, desc, aFont->name);
|
||||
}
|
||||
#endif /* MOZ_ENABLE_COREXFONTS */
|
||||
aFont->weight = pango_font_description_get_weight(desc);
|
||||
|
||||
gint size;
|
||||
|
@ -1052,3 +1074,126 @@ GetXftDPI(void)
|
|||
return 0;
|
||||
}
|
||||
#endif /* MOZ_ENABLE_XFT */
|
||||
|
||||
#if defined(MOZ_WIDGET_GTK2) && defined(MOZ_ENABLE_COREXFONTS)
|
||||
// xlfd_from_pango_font_description copied from vte, which was
|
||||
// written by nalin@redhat.com, and added some codes.
|
||||
static void
|
||||
xlfd_from_pango_font_description(GtkWidget *aWidget,
|
||||
const PangoFontDescription *aFontDesc,
|
||||
nsString& aFontName)
|
||||
{
|
||||
char *spec;
|
||||
PangoContext *context;
|
||||
PangoFont *font;
|
||||
PangoXSubfont *subfont_ids;
|
||||
PangoFontMap *fontmap;
|
||||
int *subfont_charsets, i, count = 0;
|
||||
char *tmp, *subfont;
|
||||
char *encodings[] = {
|
||||
"ascii-0",
|
||||
"big5-0",
|
||||
"dos-437",
|
||||
"dos-737",
|
||||
"gb18030.2000-0",
|
||||
"gb18030.2000-1",
|
||||
"gb2312.1980-0",
|
||||
"iso8859-1",
|
||||
"iso8859-2",
|
||||
"iso8859-3",
|
||||
"iso8859-4",
|
||||
"iso8859-5",
|
||||
"iso8859-7",
|
||||
"iso8859-8",
|
||||
"iso8859-9",
|
||||
"iso8859-10",
|
||||
"iso8859-15",
|
||||
"iso10646-0",
|
||||
"iso10646-1",
|
||||
"jisx0201.1976-0",
|
||||
"jisx0208.1983-0",
|
||||
"jisx0208.1990-0",
|
||||
"jisx0208.1997-0",
|
||||
"jisx0212.1990-0",
|
||||
"jisx0213.2000-1",
|
||||
"jisx0213.2000-2",
|
||||
"koi8-r",
|
||||
"koi8-u",
|
||||
"koi8-ub",
|
||||
"ksc5601.1987-0",
|
||||
"ksc5601.1992-3",
|
||||
"tis620-0",
|
||||
"iso8859-13",
|
||||
"microsoft-cp1251"
|
||||
"misc-fontspecific",
|
||||
};
|
||||
#if XlibSpecificationRelease >= 6
|
||||
XOM xom;
|
||||
#endif
|
||||
if (!aFontDesc) {
|
||||
return;
|
||||
}
|
||||
|
||||
context = gtk_widget_get_pango_context(GTK_WIDGET(aWidget));
|
||||
|
||||
pango_context_set_language (context, gtk_get_default_language ());
|
||||
fontmap = pango_x_font_map_for_display(GDK_DISPLAY());
|
||||
|
||||
if (!fontmap) {
|
||||
return;
|
||||
}
|
||||
|
||||
font = pango_font_map_load_font(fontmap, context, aFontDesc);
|
||||
if (!font) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if XlibSpecificationRelease >= 6
|
||||
xom = XOpenOM (GDK_DISPLAY(), NULL, NULL, NULL);
|
||||
if (xom) {
|
||||
XOMCharSetList cslist;
|
||||
int n_encodings = 0;
|
||||
cslist.charset_count = 0;
|
||||
XGetOMValues (xom,
|
||||
XNRequiredCharSet, &cslist,
|
||||
NULL);
|
||||
n_encodings = cslist.charset_count;
|
||||
if (n_encodings) {
|
||||
char **xom_encodings = (char**) g_malloc (sizeof(char*) * n_encodings);
|
||||
|
||||
for (i = 0; i < n_encodings; i++) {
|
||||
xom_encodings[i] = g_ascii_strdown (cslist.charset_list[i], -1);
|
||||
}
|
||||
count = pango_x_list_subfonts(font, xom_encodings, n_encodings,
|
||||
&subfont_ids, &subfont_charsets);
|
||||
|
||||
for(i = 0; i < n_encodings; i++) {
|
||||
g_free (xom_encodings[i]);
|
||||
}
|
||||
g_free (xom_encodings);
|
||||
}
|
||||
XCloseOM (xom);
|
||||
}
|
||||
#endif
|
||||
if (count == 0) {
|
||||
count = pango_x_list_subfonts(font, encodings, G_N_ELEMENTS(encodings),
|
||||
&subfont_ids, &subfont_charsets);
|
||||
}
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
subfont = pango_x_font_subfont_xlfd(font, subfont_ids[i]);
|
||||
AppendFontFFREName(aFontName, subfont);
|
||||
aFontName.Append(PRUnichar(','));
|
||||
}
|
||||
|
||||
spec = pango_font_description_to_string(aFontDesc);
|
||||
|
||||
if (subfont_ids != NULL) {
|
||||
g_free(subfont_ids);
|
||||
}
|
||||
if (subfont_charsets != NULL) {
|
||||
g_free(subfont_charsets);
|
||||
}
|
||||
g_free(spec);
|
||||
}
|
||||
#endif /* MOZ_WIDGET_GTK2 && MOZ_ENABLE_COREXFONTS */
|
||||
|
|
Загрузка…
Ссылка в новой задаче