nsSystemFontsQt::nsSystemFontsQt() : mDefaultFontName(NS_LITERAL_STRING("sans-serif")) , mButtonFontName(NS_LITERAL_STRING("sans-serif")) , mFieldFontName(NS_LITERAL_STRING("sans-serif")) , mMenuFontName(NS_LITERAL_STRING("sans-serif")) { // What about using QFontInfo? is it faster or what? GetSystemFontInfo("Qlabel", &mDefaultFontName, &mDefaultFontStyle); GetSystemFontInfo("QlineEdit", &mFieldFontName, &mFieldFontStyle); GetSystemFontInfo("QAction", &mMenuFontName, &mMenuFontStyle); GetSystemFontInfo("QPushButton", &mButtonFontName, &mButtonFontStyle); }
nsSystemFontsGTK2::nsSystemFontsGTK2() : mDefaultFontName(NS_LITERAL_STRING("sans-serif")) , mButtonFontName(NS_LITERAL_STRING("sans-serif")) , mFieldFontName(NS_LITERAL_STRING("sans-serif")) , mMenuFontName(NS_LITERAL_STRING("sans-serif")) { InitPangoLib(); /* * Much of the widget creation code here is similar to the code in * nsLookAndFeel::InitColors(). */ // mDefaultFont GtkWidget *label = gtk_label_new("M"); GtkWidget *parent = gtk_fixed_new(); GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP); gtk_container_add(GTK_CONTAINER(parent), label); gtk_container_add(GTK_CONTAINER(window), parent); gtk_widget_ensure_style(label); GetSystemFontInfo(label, &mDefaultFontName, &mDefaultFontStyle); gtk_widget_destroy(window); // no unref, windows are different // mFieldFont GtkWidget *entry = gtk_entry_new(); parent = gtk_fixed_new(); window = gtk_window_new(GTK_WINDOW_POPUP); gtk_container_add(GTK_CONTAINER(parent), entry); gtk_container_add(GTK_CONTAINER(window), parent); gtk_widget_ensure_style(entry); GetSystemFontInfo(entry, &mFieldFontName, &mFieldFontStyle); gtk_widget_destroy(window); // no unref, windows are different // mMenuFont GtkWidget *accel_label = gtk_accel_label_new("M"); GtkWidget *menuitem = gtk_menu_item_new(); GtkWidget *menu = gtk_menu_new(); g_object_ref_sink(GTK_OBJECT(menu)); gtk_container_add(GTK_CONTAINER(menuitem), accel_label); gtk_menu_shell_append((GtkMenuShell *)GTK_MENU(menu), menuitem); gtk_widget_ensure_style(accel_label); GetSystemFontInfo(accel_label, &mMenuFontName, &mMenuFontStyle); g_object_unref(menu); // mButtonFont parent = gtk_fixed_new(); GtkWidget *button = gtk_button_new(); label = gtk_label_new("M"); window = gtk_window_new(GTK_WINDOW_POPUP); gtk_container_add(GTK_CONTAINER(button), label); gtk_container_add(GTK_CONTAINER(parent), button); gtk_container_add(GTK_CONTAINER(window), parent); gtk_widget_ensure_style(label); GetSystemFontInfo(label, &mButtonFontName, &mButtonFontStyle); gtk_widget_destroy(window); // no unref, windows are different }
bool nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName, gfxFontStyle& aFontStyle, float aDevPixPerCSSPixel) { const char *className = NULL; nsString *cachedFontName = NULL; gfxFontStyle *cachedFontStyle = NULL; bool *isCached = NULL; switch (aID) { case eFont_Menu: // css2 case eFont_PullDownMenu: // css3 cachedFontName = &mMenuFontName; cachedFontStyle = &mMenuFontStyle; isCached = &mMenuFontCached; className = "QAction"; break; case eFont_Field: // css3 case eFont_List: // css3 cachedFontName = &mFieldFontName; cachedFontStyle = &mFieldFontStyle; isCached = &mFieldFontCached; className = "QlineEdit"; break; case eFont_Button: // css3 cachedFontName = &mButtonFontName; cachedFontStyle = &mButtonFontStyle; isCached = &mButtonFontCached; className = "QPushButton"; break; case eFont_Caption: // css2 case eFont_Icon: // css2 case eFont_MessageBox: // css2 case eFont_SmallCaption: // css2 case eFont_StatusBar: // css2 case eFont_Window: // css3 case eFont_Document: // css3 case eFont_Workspace: // css3 case eFont_Desktop: // css3 case eFont_Info: // css3 case eFont_Dialog: // css3 case eFont_Tooltips: // moz case eFont_Widget: // moz cachedFontName = &mDefaultFontName; cachedFontStyle = &mDefaultFontStyle; isCached = &mDefaultFontCached; className = "Qlabel"; break; } if (!*isCached) { GetSystemFontInfo(className, cachedFontName, cachedFontStyle); *isCached = true; } aFontName = *cachedFontName; aFontStyle = *cachedFontStyle; return true; }