mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 96971: Move GetSystemFont from nsDeviceContext to mozilla::LookAndFeel. r=roc
This commit is contained in:
parent
f464cea60c
commit
58cb765cfa
@ -54,7 +54,7 @@ XPIDLSRCS = \
|
||||
nsIFontEnumerator.idl \
|
||||
nsIScriptableRegion.idl \
|
||||
$(NULL)
|
||||
|
||||
|
||||
EXPORTS = \
|
||||
gfxCore.h \
|
||||
gfxCrashReporterUtils.h \
|
||||
@ -103,34 +103,6 @@ ifdef MOZ_X11
|
||||
CPPSRCS += X11Util.cpp
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),android)
|
||||
CPPSRCS += nsSystemFontsAndroid.cpp
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),gonk)
|
||||
CPPSRCS += nsSystemFontsAndroid.cpp
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
||||
CMMSRCS = nsSystemFontsMac.mm
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
|
||||
CPPSRCS += nsSystemFontsGTK2.cpp
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
CPPSRCS += nsSystemFontsOS2.cpp
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),qt)
|
||||
CPPSRCS += nsSystemFontsQt.cpp
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
|
||||
CPPSRCS += nsSystemFontsWin.cpp
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
CXXFLAGS += $(TK_CFLAGS) $(MOZ_CAIRO_CFLAGS)
|
||||
|
@ -54,39 +54,18 @@
|
||||
|
||||
#include "gfxImageSurface.h"
|
||||
|
||||
#if !XP_MACOSX
|
||||
#include "gfxPDFSurface.h"
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_ENABLE_GTK2
|
||||
#include "nsSystemFontsGTK2.h"
|
||||
#include "gfxPDFSurface.h"
|
||||
#include "gfxPSSurface.h"
|
||||
static nsSystemFontsGTK2 *gSystemFonts = nsnull;
|
||||
#elif XP_WIN
|
||||
#include "nsSystemFontsWin.h"
|
||||
#include "gfxWindowsSurface.h"
|
||||
#include "gfxPDFSurface.h"
|
||||
static nsSystemFontsWin *gSystemFonts = nsnull;
|
||||
#elif defined(XP_OS2)
|
||||
#include "nsSystemFontsOS2.h"
|
||||
#include "gfxOS2Surface.h"
|
||||
#include "gfxPDFSurface.h"
|
||||
static nsSystemFontsOS2 *gSystemFonts = nsnull;
|
||||
#elif XP_MACOSX
|
||||
#include "nsSystemFontsMac.h"
|
||||
#include "gfxQuartzSurface.h"
|
||||
static nsSystemFontsMac *gSystemFonts = nsnull;
|
||||
#elif defined(MOZ_WIDGET_QT)
|
||||
#include "nsSystemFontsQt.h"
|
||||
#include "gfxPDFSurface.h"
|
||||
static nsSystemFontsQt *gSystemFonts = nsnull;
|
||||
#elif defined(MOZ_WIDGET_ANDROID)
|
||||
#include "nsSystemFontsAndroid.h"
|
||||
#include "gfxPDFSurface.h"
|
||||
static nsSystemFontsAndroid *gSystemFonts = nsnull;
|
||||
#elif defined(MOZ_WIDGET_GONK)
|
||||
#include "nsSystemFontsAndroid.h"
|
||||
#include "gfxPDFSurface.h"
|
||||
static nsSystemFontsAndroid *gSystemFonts = nsnull;
|
||||
#else
|
||||
#error Need to declare gSystemFonts!
|
||||
#endif
|
||||
|
||||
using namespace mozilla;
|
||||
@ -452,55 +431,6 @@ nsDeviceContext::CreateRenderingContext(nsRenderingContext *&aContext)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
nsDeviceContext::ClearCachedSystemFonts()
|
||||
{
|
||||
if (gSystemFonts) {
|
||||
delete gSystemFonts;
|
||||
gSystemFonts = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDeviceContext::GetSystemFont(nsSystemFontID aID, nsFont *aFont) const
|
||||
{
|
||||
if (!gSystemFonts) {
|
||||
#ifdef MOZ_ENABLE_GTK2
|
||||
gSystemFonts = new nsSystemFontsGTK2();
|
||||
#elif XP_WIN
|
||||
gSystemFonts = new nsSystemFontsWin();
|
||||
#elif XP_OS2
|
||||
gSystemFonts = new nsSystemFontsOS2();
|
||||
#elif XP_MACOSX
|
||||
gSystemFonts = new nsSystemFontsMac();
|
||||
#elif defined(MOZ_WIDGET_QT)
|
||||
gSystemFonts = new nsSystemFontsQt();
|
||||
#elif defined(ANDROID)
|
||||
gSystemFonts = new nsSystemFontsAndroid();
|
||||
#else
|
||||
#error Need to know how to create gSystemFonts, fix me!
|
||||
#endif
|
||||
}
|
||||
|
||||
nsString fontName;
|
||||
gfxFontStyle fontStyle;
|
||||
nsresult rv = gSystemFonts->GetSystemFont(aID, &fontName, &fontStyle);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
aFont->name = fontName;
|
||||
aFont->style = fontStyle.style;
|
||||
aFont->systemFont = fontStyle.systemFont;
|
||||
aFont->variant = NS_FONT_VARIANT_NORMAL;
|
||||
aFont->weight = fontStyle.weight;
|
||||
aFont->stretch = fontStyle.stretch;
|
||||
aFont->decorations = NS_FONT_DECORATION_NONE;
|
||||
aFont->size = NSFloatPixelsToAppUnits(fontStyle.size, UnscaledAppUnitsPerDevPixel());
|
||||
//aFont->langGroup = fontStyle.langGroup;
|
||||
aFont->sizeAdjust = fontStyle.sizeAdjust;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDeviceContext::GetDepth(PRUint32& aDepth)
|
||||
{
|
||||
|
@ -51,29 +51,6 @@ class nsIAtom;
|
||||
class nsFontCache;
|
||||
class gfxUserFontSet;
|
||||
|
||||
typedef enum {
|
||||
eSystemFont_Caption, // css2
|
||||
eSystemFont_Icon,
|
||||
eSystemFont_Menu,
|
||||
eSystemFont_MessageBox,
|
||||
eSystemFont_SmallCaption,
|
||||
eSystemFont_StatusBar,
|
||||
|
||||
eSystemFont_Window, // css3
|
||||
eSystemFont_Document,
|
||||
eSystemFont_Workspace,
|
||||
eSystemFont_Desktop,
|
||||
eSystemFont_Info,
|
||||
eSystemFont_Dialog,
|
||||
eSystemFont_Button,
|
||||
eSystemFont_PullDownMenu,
|
||||
eSystemFont_List,
|
||||
eSystemFont_Field,
|
||||
|
||||
eSystemFont_Tooltips, // moz
|
||||
eSystemFont_Widget
|
||||
} nsSystemFontID;
|
||||
|
||||
class nsDeviceContext
|
||||
{
|
||||
public:
|
||||
@ -150,22 +127,6 @@ public:
|
||||
PRInt32 UnscaledAppUnitsPerDevPixel() const
|
||||
{ return mAppUnitsPerDevNotScaledPixel; }
|
||||
|
||||
/**
|
||||
* Fill in an nsFont based on the ID of a system font. This function
|
||||
* may or may not fill in the size, so the size should be set to a
|
||||
* reasonable default before calling.
|
||||
*
|
||||
* @param aID The system font ID.
|
||||
* @param aInfo The font structure to be filled in.
|
||||
* @return error status
|
||||
*/
|
||||
nsresult GetSystemFont(nsSystemFontID aID, nsFont *aFont) const;
|
||||
|
||||
/**
|
||||
* Clear cached system fonts (refresh from theme when requested).
|
||||
*/
|
||||
static void ClearCachedSystemFonts();
|
||||
|
||||
/**
|
||||
* Get the nsFontMetrics that describe the properties of
|
||||
* an nsFont.
|
||||
|
@ -1,111 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Android port
|
||||
*
|
||||
* The Initial Developer of the Original Code is mozilla.org.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir@pobox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsSystemFontsAndroid.h"
|
||||
#include "gfxPlatform.h"
|
||||
|
||||
#define DEFAULT_FONT "Droid Sans"
|
||||
|
||||
nsSystemFontsAndroid::nsSystemFontsAndroid()
|
||||
: mDefaultFontName(NS_LITERAL_STRING(DEFAULT_FONT))
|
||||
, mButtonFontName(NS_LITERAL_STRING(DEFAULT_FONT))
|
||||
, mFieldFontName(NS_LITERAL_STRING(DEFAULT_FONT))
|
||||
, mMenuFontName(NS_LITERAL_STRING(DEFAULT_FONT))
|
||||
{
|
||||
}
|
||||
|
||||
nsSystemFontsAndroid::~nsSystemFontsAndroid()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSystemFontsAndroid::GetSystemFontInfo(const char *aClassName, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const
|
||||
{
|
||||
aFontStyle->style = FONT_STYLE_NORMAL;
|
||||
aFontStyle->systemFont = true;
|
||||
*aFontName = NS_LITERAL_STRING("Droid Sans");
|
||||
aFontStyle->weight = 400;
|
||||
aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
|
||||
aFontStyle->size = 9.0 * 96.0f / 72.0f;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsSystemFontsAndroid::GetSystemFont(nsSystemFontID anID, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const
|
||||
{
|
||||
switch (anID) {
|
||||
case eSystemFont_Menu: // css2
|
||||
case eSystemFont_PullDownMenu: // css3
|
||||
*aFontName = mMenuFontName;
|
||||
*aFontStyle = mMenuFontStyle;
|
||||
break;
|
||||
|
||||
case eSystemFont_Field: // css3
|
||||
case eSystemFont_List: // css3
|
||||
*aFontName = mFieldFontName;
|
||||
*aFontStyle = mFieldFontStyle;
|
||||
break;
|
||||
|
||||
case eSystemFont_Button: // css3
|
||||
*aFontName = mButtonFontName;
|
||||
*aFontStyle = mButtonFontStyle;
|
||||
break;
|
||||
|
||||
case eSystemFont_Caption: // css2
|
||||
case eSystemFont_Icon: // css2
|
||||
case eSystemFont_MessageBox: // css2
|
||||
case eSystemFont_SmallCaption: // css2
|
||||
case eSystemFont_StatusBar: // css2
|
||||
case eSystemFont_Window: // css3
|
||||
case eSystemFont_Document: // css3
|
||||
case eSystemFont_Workspace: // css3
|
||||
case eSystemFont_Desktop: // css3
|
||||
case eSystemFont_Info: // css3
|
||||
case eSystemFont_Dialog: // css3
|
||||
case eSystemFont_Tooltips: // moz
|
||||
case eSystemFont_Widget: // moz
|
||||
*aFontName = mDefaultFontName;
|
||||
*aFontStyle = mDefaultFontStyle;
|
||||
break;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1,79 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Android port
|
||||
*
|
||||
* The Initial Developer of the Original Code is mozilla.org.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir@pobox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _NS_SYSTEMFONTSANDROID_H_
|
||||
#define _NS_SYSTEMFONTSANDROID_H_
|
||||
|
||||
#include "gfxFont.h"
|
||||
#include "nsDeviceContext.h"
|
||||
|
||||
class nsSystemFontsAndroid
|
||||
{
|
||||
public:
|
||||
nsSystemFontsAndroid();
|
||||
~nsSystemFontsAndroid();
|
||||
|
||||
nsresult GetSystemFont(nsSystemFontID anID, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const;
|
||||
|
||||
private:
|
||||
|
||||
nsresult GetSystemFontInfo(const char *aClassName, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const;
|
||||
|
||||
/*
|
||||
* The following system font constants exist:
|
||||
*
|
||||
* css2: http://www.w3.org/TR/REC-CSS2/fonts.html#x27
|
||||
* eSystemFont_Caption, eSystemFont_Icon, eSystemFont_Menu,
|
||||
* eSystemFont_MessageBox, eSystemFont_SmallCaption,
|
||||
* eSystemFont_StatusBar,
|
||||
* // css3
|
||||
* eSystemFont_Window, eSystemFont_Document,
|
||||
* eSystemFont_Workspace, eSystemFont_Desktop,
|
||||
* eSystemFont_Info, eSystemFont_Dialog,
|
||||
* eSystemFont_Button, eSystemFont_PullDownMenu,
|
||||
* eSystemFont_List, eSystemFont_Field,
|
||||
* // moz
|
||||
* eSystemFont_Tooltips, eSystemFont_Widget
|
||||
*/
|
||||
nsString mDefaultFontName, mButtonFontName, mFieldFontName, mMenuFontName;
|
||||
gfxFontStyle mDefaultFontStyle, mButtonFontStyle, mFieldFontStyle, mMenuFontStyle;
|
||||
};
|
||||
|
||||
#endif /* _NS_SYSTEMFONTSANDROID_H_ */
|
||||
|
@ -1,287 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is thebes gfx
|
||||
*
|
||||
* The Initial Developer of the Original Code is mozilla.org.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir@pobox.com>
|
||||
* Stuart Parmenter <pavlov@pavlov.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
// for strtod()
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "nsSystemFontsGTK2.h"
|
||||
#include "prlink.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#ifdef MOZ_PANGO
|
||||
#include <pango/pango.h>
|
||||
#include <pango/pango-fontmap.h>
|
||||
#endif
|
||||
|
||||
#include <fontconfig/fontconfig.h>
|
||||
#include "gfxPlatformGtk.h"
|
||||
|
||||
// Glue to avoid build/runtime dependencies on Pango > 1.6
|
||||
#if defined(MOZ_PANGO) && !defined(THEBES_USE_PANGO_CAIRO)
|
||||
static gboolean
|
||||
(* PTR_pango_font_description_get_size_is_absolute)(PangoFontDescription*)
|
||||
= nsnull;
|
||||
|
||||
static void InitPangoLib()
|
||||
{
|
||||
static bool initialized = false;
|
||||
if (initialized)
|
||||
return;
|
||||
initialized = true;
|
||||
|
||||
PRLibrary *pangoLib = nsnull;
|
||||
PTR_pango_font_description_get_size_is_absolute =
|
||||
(gboolean (*)(PangoFontDescription*))
|
||||
PR_FindFunctionSymbolAndLibrary("pango_font_description_get_size_is_absolute",
|
||||
&pangoLib);
|
||||
if (pangoLib)
|
||||
PR_UnloadLibrary(pangoLib);
|
||||
}
|
||||
|
||||
static void
|
||||
ShutdownPangoLib()
|
||||
{
|
||||
}
|
||||
|
||||
static gboolean
|
||||
MOZ_pango_font_description_get_size_is_absolute(PangoFontDescription *desc)
|
||||
{
|
||||
if (PTR_pango_font_description_get_size_is_absolute) {
|
||||
return PTR_pango_font_description_get_size_is_absolute(desc);
|
||||
}
|
||||
|
||||
// In old versions of pango, this was always false.
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
static inline void InitPangoLib()
|
||||
{
|
||||
}
|
||||
|
||||
static inline void ShutdownPangoLib()
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef MOZ_PANGO
|
||||
static inline gboolean
|
||||
MOZ_pango_font_description_get_size_is_absolute(PangoFontDescription *desc)
|
||||
{
|
||||
pango_font_description_get_size_is_absolute(desc);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
nsSystemFontsGTK2::~nsSystemFontsGTK2()
|
||||
{
|
||||
ShutdownPangoLib();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSystemFontsGTK2::GetSystemFontInfo(GtkWidget *aWidget, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const
|
||||
{
|
||||
#ifdef MOZ_PANGO
|
||||
GtkSettings *settings = gtk_widget_get_settings(aWidget);
|
||||
|
||||
aFontStyle->style = FONT_STYLE_NORMAL;
|
||||
|
||||
gchar *fontname;
|
||||
g_object_get(settings, "gtk-font-name", &fontname, NULL);
|
||||
|
||||
PangoFontDescription *desc;
|
||||
desc = pango_font_description_from_string(fontname);
|
||||
|
||||
aFontStyle->systemFont = true;
|
||||
|
||||
g_free(fontname);
|
||||
|
||||
NS_NAMED_LITERAL_STRING(quote, "\"");
|
||||
NS_ConvertUTF8toUTF16 family(pango_font_description_get_family(desc));
|
||||
*aFontName = quote + family + quote;
|
||||
|
||||
aFontStyle->weight = pango_font_description_get_weight(desc);
|
||||
|
||||
// FIXME: Set aFontStyle->stretch correctly!
|
||||
aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
|
||||
|
||||
float size = float(pango_font_description_get_size(desc)) / PANGO_SCALE;
|
||||
|
||||
// |size| is now either pixels or pango-points (not Mozilla-points!)
|
||||
|
||||
if (!MOZ_pango_font_description_get_size_is_absolute(desc)) {
|
||||
// |size| is in pango-points, so convert to pixels.
|
||||
size *= float(gfxPlatformGtk::GetDPI()) / POINTS_PER_INCH_FLOAT;
|
||||
}
|
||||
|
||||
// |size| is now pixels
|
||||
|
||||
aFontStyle->size = size;
|
||||
|
||||
pango_font_description_free(desc);
|
||||
|
||||
#else
|
||||
/* FIXME: DFB FT2 Hardcoding the system font info for now.. */
|
||||
aFontStyle->style = FONT_STYLE_NORMAL;
|
||||
aFontStyle->systemFont = true;
|
||||
|
||||
NS_NAMED_LITERAL_STRING(fontname, "\"Sans\"");
|
||||
*aFontName = fontname;
|
||||
aFontStyle->weight = 400;
|
||||
aFontStyle->size = 40/3;
|
||||
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSystemFontsGTK2::GetSystemFont(nsSystemFontID anID, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const
|
||||
{
|
||||
switch (anID) {
|
||||
case eSystemFont_Menu: // css2
|
||||
case eSystemFont_PullDownMenu: // css3
|
||||
*aFontName = mMenuFontName;
|
||||
*aFontStyle = mMenuFontStyle;
|
||||
break;
|
||||
|
||||
case eSystemFont_Field: // css3
|
||||
case eSystemFont_List: // css3
|
||||
*aFontName = mFieldFontName;
|
||||
*aFontStyle = mFieldFontStyle;
|
||||
break;
|
||||
|
||||
case eSystemFont_Button: // css3
|
||||
*aFontName = mButtonFontName;
|
||||
*aFontStyle = mButtonFontStyle;
|
||||
break;
|
||||
|
||||
case eSystemFont_Caption: // css2
|
||||
case eSystemFont_Icon: // css2
|
||||
case eSystemFont_MessageBox: // css2
|
||||
case eSystemFont_SmallCaption: // css2
|
||||
case eSystemFont_StatusBar: // css2
|
||||
case eSystemFont_Window: // css3
|
||||
case eSystemFont_Document: // css3
|
||||
case eSystemFont_Workspace: // css3
|
||||
case eSystemFont_Desktop: // css3
|
||||
case eSystemFont_Info: // css3
|
||||
case eSystemFont_Dialog: // css3
|
||||
case eSystemFont_Tooltips: // moz
|
||||
case eSystemFont_Widget: // moz
|
||||
*aFontName = mDefaultFontName;
|
||||
*aFontStyle = mDefaultFontStyle;
|
||||
break;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is thebes gfx
|
||||
*
|
||||
* The Initial Developer of the Original Code is mozilla.org.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir@pobox.com>
|
||||
* Stuart Parmenter <pavlov@pavlov.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _NS_SYSTEMFONTSGTK2_H_
|
||||
#define _NS_SYSTEMFONTSGTK2_H_
|
||||
|
||||
#include "gfxFont.h"
|
||||
#include "nsDeviceContext.h"
|
||||
|
||||
typedef struct _GtkWidget GtkWidget;
|
||||
|
||||
class nsSystemFontsGTK2
|
||||
{
|
||||
public:
|
||||
nsSystemFontsGTK2();
|
||||
~nsSystemFontsGTK2();
|
||||
|
||||
nsresult GetSystemFont(nsSystemFontID anID, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const;
|
||||
|
||||
private:
|
||||
|
||||
nsresult GetSystemFontInfo(GtkWidget *aWidget, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const;
|
||||
|
||||
/*
|
||||
* The following system font constants exist:
|
||||
*
|
||||
* css2: http://www.w3.org/TR/REC-CSS2/fonts.html#x27
|
||||
* eSystemFont_Caption, eSystemFont_Icon, eSystemFont_Menu,
|
||||
* eSystemFont_MessageBox, eSystemFont_SmallCaption,
|
||||
* eSystemFont_StatusBar,
|
||||
* // css3
|
||||
* eSystemFont_Window, eSystemFont_Document,
|
||||
* eSystemFont_Workspace, eSystemFont_Desktop,
|
||||
* eSystemFont_Info, eSystemFont_Dialog,
|
||||
* eSystemFont_Button, eSystemFont_PullDownMenu,
|
||||
* eSystemFont_List, eSystemFont_Field,
|
||||
* // moz
|
||||
* eSystemFont_Tooltips, eSystemFont_Widget
|
||||
*/
|
||||
nsString mDefaultFontName, mButtonFontName, mFieldFontName, mMenuFontName;
|
||||
gfxFontStyle mDefaultFontStyle, mButtonFontStyle, mFieldFontStyle, mMenuFontStyle;
|
||||
};
|
||||
|
||||
#endif /* _NS_SYSTEMFONTSGTK2_H_ */
|
@ -1,52 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Corporation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir@pobox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _NS_SYSTEMFONTSMAC_H_
|
||||
#define _NS_SYSTEMFONTSMAC_H_
|
||||
|
||||
#include "gfxFont.h"
|
||||
#include "nsDeviceContext.h"
|
||||
|
||||
class nsSystemFontsMac
|
||||
{
|
||||
public:
|
||||
nsSystemFontsMac();
|
||||
nsresult GetSystemFont(nsSystemFontID anID, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const;
|
||||
};
|
||||
|
||||
#endif /* _NS_SYSTEMFONTSMAC_H_ */
|
@ -1,167 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Corporation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006-2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir@pobox.com>
|
||||
* Jonathan Kew <jfkthame@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsSystemFontsMac.h"
|
||||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
nsSystemFontsMac::nsSystemFontsMac()
|
||||
{
|
||||
}
|
||||
|
||||
// copied from gfxQuartzFontCache.mm, maybe should go in a Cocoa utils file somewhere
|
||||
static void GetStringForNSString(const NSString *aSrc, nsAString& aDest)
|
||||
{
|
||||
aDest.SetLength([aSrc length]);
|
||||
[aSrc getCharacters:aDest.BeginWriting()];
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSystemFontsMac::GetSystemFont(nsSystemFontID aID, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const
|
||||
{
|
||||
// hack for now
|
||||
if (aID == eSystemFont_Window ||
|
||||
aID == eSystemFont_Document)
|
||||
{
|
||||
aFontStyle->style = FONT_STYLE_NORMAL;
|
||||
aFontStyle->weight = FONT_WEIGHT_NORMAL;
|
||||
aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
|
||||
|
||||
aFontName->AssignLiteral("sans-serif");
|
||||
aFontStyle->size = 14;
|
||||
aFontStyle->systemFont = true;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* possibilities, see NSFont Class Reference:
|
||||
[NSFont boldSystemFontOfSize: 0.0]
|
||||
[NSFont controlContentFontOfSize: 0.0]
|
||||
[NSFont labelFontOfSize: 0.0]
|
||||
[NSFont menuBarFontOfSize: 0.0]
|
||||
[NSFont menuFontOfSize: 0.0]
|
||||
[NSFont messageFontOfSize: 0.0]
|
||||
[NSFont paletteFontOfSize: 0.0]
|
||||
[NSFont systemFontOfSize: 0.0]
|
||||
[NSFont titleBarFontOfSize: 0.0]
|
||||
[NSFont toolTipsFontOfSize: 0.0]
|
||||
[NSFont userFixedPitchFontOfSize: 0.0]
|
||||
[NSFont userFontOfSize: 0.0]
|
||||
[NSFont systemFontOfSize: [NSFont smallSystemFontSize]]
|
||||
[NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]]
|
||||
*/
|
||||
|
||||
NSFont *font = nsnull;
|
||||
switch (aID) {
|
||||
// css2
|
||||
case eSystemFont_Caption:
|
||||
font = [NSFont systemFontOfSize:0.0];
|
||||
break;
|
||||
case eSystemFont_Icon: // used in urlbar; tried labelFont, but too small
|
||||
font = [NSFont controlContentFontOfSize:0.0];
|
||||
break;
|
||||
case eSystemFont_Menu:
|
||||
font = [NSFont systemFontOfSize:0.0];
|
||||
break;
|
||||
case eSystemFont_MessageBox:
|
||||
font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
|
||||
break;
|
||||
case eSystemFont_SmallCaption:
|
||||
font = [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]];
|
||||
break;
|
||||
case eSystemFont_StatusBar:
|
||||
font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
|
||||
break;
|
||||
// css3
|
||||
//case eSystemFont_Window: = 'sans-serif'
|
||||
//case eSystemFont_Document: = 'sans-serif'
|
||||
case eSystemFont_Workspace:
|
||||
font = [NSFont controlContentFontOfSize:0.0];
|
||||
break;
|
||||
case eSystemFont_Desktop:
|
||||
font = [NSFont controlContentFontOfSize:0.0];
|
||||
break;
|
||||
case eSystemFont_Info:
|
||||
font = [NSFont controlContentFontOfSize:0.0];
|
||||
break;
|
||||
case eSystemFont_Dialog:
|
||||
font = [NSFont systemFontOfSize:0.0];
|
||||
break;
|
||||
case eSystemFont_Button:
|
||||
font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
|
||||
break;
|
||||
case eSystemFont_PullDownMenu:
|
||||
font = [NSFont menuBarFontOfSize:0.0];
|
||||
break;
|
||||
case eSystemFont_List:
|
||||
font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
|
||||
break;
|
||||
case eSystemFont_Field:
|
||||
font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
|
||||
break;
|
||||
// moz
|
||||
case eSystemFont_Tooltips:
|
||||
font = [NSFont toolTipsFontOfSize:0.0];
|
||||
break;
|
||||
case eSystemFont_Widget:
|
||||
font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
|
||||
break;
|
||||
default:
|
||||
// should never hit this
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_ASSERTION(font != nsnull, "failed to find a system font!");
|
||||
|
||||
GetStringForNSString([font familyName], *aFontName);
|
||||
aFontStyle->size = [font pointSize];
|
||||
|
||||
NSFontSymbolicTraits traits = [[font fontDescriptor] symbolicTraits];
|
||||
if (traits & NSFontBoldTrait)
|
||||
aFontStyle->weight = FONT_WEIGHT_BOLD;
|
||||
if (traits & NSFontItalicTrait)
|
||||
aFontStyle->style = FONT_STYLE_ITALIC;
|
||||
aFontStyle->stretch =
|
||||
(traits & NSFontExpandedTrait) ?
|
||||
NS_FONT_STRETCH_EXPANDED : (traits & NSFontCondensedTrait) ?
|
||||
NS_FONT_STRETCH_CONDENSED : NS_FONT_STRETCH_NORMAL;
|
||||
|
||||
aFontStyle->systemFont = true;
|
||||
|
||||
return NS_OK;
|
||||
}
|
@ -1,275 +0,0 @@
|
||||
/* vim: set sw=4 sts=4 et cin: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is OS/2 system font code in Thebes.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Peter Weilbacher <mozilla@Weilbacher.org>.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Developers of code taken from nsDeviceContextOS2:
|
||||
* John Fairhurst, <john_fairhurst@iname.com>
|
||||
* Henry Sobotka <sobotka@axess.com>
|
||||
* IBM Corp.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsSystemFontsOS2.h"
|
||||
|
||||
#define INCL_WINWINDOWMGR
|
||||
#define INCL_WINSHELLDATA
|
||||
#define INCL_DOSNLS
|
||||
#define INCL_DOSERRORS
|
||||
#include <os2.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/************************
|
||||
* Helper functions *
|
||||
************************/
|
||||
static BOOL bIsDBCS;
|
||||
static BOOL bIsDBCSSet = FALSE;
|
||||
|
||||
/* Helper function to determine if we are running on DBCS */
|
||||
BOOL IsDBCS()
|
||||
{
|
||||
if (!bIsDBCSSet) {
|
||||
// the following lines of code determine whether the system is a DBCS country
|
||||
APIRET rc;
|
||||
COUNTRYCODE ctrycodeInfo = {0};
|
||||
CHAR achDBCSInfo[12] = {0}; // DBCS environmental vector
|
||||
ctrycodeInfo.country = 0; // current country
|
||||
ctrycodeInfo.codepage = 0; // current codepage
|
||||
|
||||
rc = DosQueryDBCSEnv(sizeof(achDBCSInfo), &ctrycodeInfo, achDBCSInfo);
|
||||
if (rc == NO_ERROR) {
|
||||
// Non-DBCS countries will have four bytes in the first four bytes of the
|
||||
// DBCS environmental vector
|
||||
if (achDBCSInfo[0] != 0 || achDBCSInfo[1] != 0 ||
|
||||
achDBCSInfo[2] != 0 || achDBCSInfo[3] != 0)
|
||||
{
|
||||
bIsDBCS = TRUE;
|
||||
} else {
|
||||
bIsDBCS = FALSE;
|
||||
}
|
||||
} else {
|
||||
bIsDBCS = FALSE;
|
||||
} /* endif */
|
||||
bIsDBCSSet = TRUE;
|
||||
} /* endif */
|
||||
return bIsDBCS;
|
||||
}
|
||||
|
||||
/* Helper function to query font from INI file */
|
||||
void QueryFontFromINI(char* fontType, char* fontName, ULONG ulLength)
|
||||
{
|
||||
ULONG ulMaxNameL = ulLength;
|
||||
|
||||
/* We had to switch to using PrfQueryProfileData because */
|
||||
/* some users have binary font data in their INI files */
|
||||
BOOL rc = PrfQueryProfileData(HINI_USER, (PCSZ)"PM_SystemFonts", (PCSZ)fontType,
|
||||
fontName, &ulMaxNameL);
|
||||
/* If there was no entry in the INI, default to something */
|
||||
if (rc == FALSE) {
|
||||
/* Different values for DBCS vs. SBCS */
|
||||
/* WarpSans is only available on Warp 4, we exclude Warp 3 now */
|
||||
if (!IsDBCS()) {
|
||||
strcpy(fontName, "9.WarpSans");
|
||||
} else {
|
||||
strcpy(fontName, "9.WarpSans Combined");
|
||||
}
|
||||
} else {
|
||||
/* null terminate fontname */
|
||||
fontName[ulMaxNameL] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
/************************/
|
||||
|
||||
nsSystemFontsOS2::nsSystemFontsOS2()
|
||||
{
|
||||
#ifdef DEBUG_thebes
|
||||
printf("nsSystemFontsOS2::nsSystemFontsOS2()\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Query the font used for various CSS properties (aID) from the system.
|
||||
* For OS/2, only very few fonts are defined in the system, so most of the IDs
|
||||
* resolve to the same system font.
|
||||
* The font queried will give back a string like
|
||||
* 9.WarpSans Bold
|
||||
* 12.Times New Roman Bold Italic
|
||||
* 10.Times New Roman.Strikeout.Underline
|
||||
* 20.Bitstream Vera Sans Mono Obli
|
||||
* (always restricted to 32 chars, at least before the second dot)
|
||||
* We use the value before the dot as the font size (in pt, and convert it to
|
||||
* px using the screen resolution) and then try to use the rest of the string
|
||||
* to determine the font style from it.
|
||||
*/
|
||||
nsresult nsSystemFontsOS2::GetSystemFont(nsSystemFontID aID, nsString* aFontName,
|
||||
gfxFontStyle *aFontStyle) const
|
||||
{
|
||||
#ifdef DEBUG_thebes
|
||||
printf("nsSystemFontsOS2::GetSystemFont: ");
|
||||
#endif
|
||||
char szFontNameSize[MAXNAMEL];
|
||||
|
||||
switch (aID)
|
||||
{
|
||||
case eSystemFont_Icon:
|
||||
QueryFontFromINI("IconText", szFontNameSize, MAXNAMEL);
|
||||
#ifdef DEBUG_thebes
|
||||
printf("IconText ");
|
||||
#endif
|
||||
break;
|
||||
|
||||
case eSystemFont_Menu:
|
||||
QueryFontFromINI("Menus", szFontNameSize, MAXNAMEL);
|
||||
#ifdef DEBUG_thebes
|
||||
printf("Menus ");
|
||||
#endif
|
||||
break;
|
||||
|
||||
case eSystemFont_Caption:
|
||||
case eSystemFont_MessageBox:
|
||||
case eSystemFont_SmallCaption:
|
||||
case eSystemFont_StatusBar:
|
||||
case eSystemFont_Tooltips:
|
||||
case eSystemFont_Widget:
|
||||
|
||||
case eSystemFont_Window: // css3
|
||||
case eSystemFont_Document:
|
||||
case eSystemFont_Workspace:
|
||||
case eSystemFont_Desktop:
|
||||
case eSystemFont_Info:
|
||||
case eSystemFont_Dialog:
|
||||
case eSystemFont_Button:
|
||||
case eSystemFont_PullDownMenu:
|
||||
case eSystemFont_List:
|
||||
case eSystemFont_Field:
|
||||
QueryFontFromINI("WindowText", szFontNameSize, MAXNAMEL);
|
||||
#ifdef DEBUG_thebes
|
||||
printf("WindowText ");
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
NS_WARNING("None of the listed font types, using WarpSans");
|
||||
if (!IsDBCS()) {
|
||||
strcpy(szFontNameSize, "9.WarpSans");
|
||||
} else {
|
||||
strcpy(szFontNameSize, "9.WarpSans Combined");
|
||||
}
|
||||
} // switch
|
||||
#ifdef DEBUG_thebes
|
||||
printf(" (%s)\n", szFontNameSize);
|
||||
#endif
|
||||
|
||||
char *szFacename = strchr(szFontNameSize, '.');
|
||||
if (!szFacename || (*(szFacename++) == '\0'))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// local DPI for size will be taken into account below
|
||||
aFontStyle->size = atof(szFontNameSize);
|
||||
|
||||
// determine DPI resolution of screen device to compare compute
|
||||
// font size in pixels
|
||||
HPS ps = WinGetScreenPS(HWND_DESKTOP);
|
||||
HDC dc = GpiQueryDevice(ps);
|
||||
// effective vertical resolution in DPI
|
||||
LONG vertScreenRes = 120; // assume 120 dpi as default
|
||||
DevQueryCaps(dc, CAPS_VERTICAL_FONT_RES, 1, &vertScreenRes);
|
||||
WinReleasePS(ps);
|
||||
|
||||
// now scale to make pixels from points (1 pt = 1/72in)
|
||||
aFontStyle->size *= vertScreenRes / 72.0;
|
||||
|
||||
NS_ConvertUTF8toUTF16 fontFace(szFacename);
|
||||
int pos = 0;
|
||||
|
||||
// this is a system font in any case
|
||||
aFontStyle->systemFont = true;
|
||||
|
||||
// bold fonts should have " Bold" in their names, at least we hope that they
|
||||
// do, otherwise it's bad luck
|
||||
NS_NAMED_LITERAL_CSTRING(spcBold, " Bold");
|
||||
if ((pos = fontFace.Find(spcBold.get(), false, 0, -1)) > -1) {
|
||||
aFontStyle->weight = FONT_WEIGHT_BOLD;
|
||||
// strip the attribute, now that we have set it in the gfxFontStyle
|
||||
fontFace.Cut(pos, spcBold.Length());
|
||||
} else {
|
||||
aFontStyle->weight = FONT_WEIGHT_NORMAL;
|
||||
}
|
||||
|
||||
// FIXME: Set aFontStyle->stretch correctly!
|
||||
aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
|
||||
|
||||
// similar hopes for italic and oblique fonts...
|
||||
NS_NAMED_LITERAL_CSTRING(spcItalic, " Italic");
|
||||
NS_NAMED_LITERAL_CSTRING(spcOblique, " Oblique");
|
||||
NS_NAMED_LITERAL_CSTRING(spcObli, " Obli");
|
||||
if ((pos = fontFace.Find(spcItalic.get(), false, 0, -1)) > -1) {
|
||||
aFontStyle->style = FONT_STYLE_ITALIC;
|
||||
fontFace.Cut(pos, spcItalic.Length());
|
||||
} else if ((pos = fontFace.Find(spcOblique.get(), false, 0, -1)) > -1) {
|
||||
// oblique fonts are rare on OS/2 and not specially supported by
|
||||
// the GPI system, but at least we are trying...
|
||||
aFontStyle->style = FONT_STYLE_OBLIQUE;
|
||||
fontFace.Cut(pos, spcOblique.Length());
|
||||
} else if ((pos = fontFace.Find(spcObli.get(), false, 0, -1)) > -1) {
|
||||
// especially oblique often gets cut by the 32 char limit to "Obli",
|
||||
// so search for that, too (anything shorter would be ambiguous)
|
||||
aFontStyle->style = FONT_STYLE_OBLIQUE;
|
||||
// In this case, assume that this is the last property in the line
|
||||
// and cut off everything else, too
|
||||
// This is needed in case it was really Obliq or Obliqu...
|
||||
fontFace.Cut(pos, fontFace.Length());
|
||||
} else {
|
||||
aFontStyle->style = FONT_STYLE_NORMAL;
|
||||
}
|
||||
|
||||
// just throw away any modifiers that are separated by dots (which are either
|
||||
// .Strikeout, .Underline, or .Outline, none of which have a corresponding
|
||||
// gfxFont property)
|
||||
if ((pos = fontFace.Find(".", false, 0, -1)) > -1) {
|
||||
fontFace.Cut(pos, fontFace.Length());
|
||||
}
|
||||
|
||||
#ifdef DEBUG_thebes
|
||||
printf(" after=%s\n", NS_LossyConvertUTF16toASCII(fontFace).get());
|
||||
printf(" style: %s %s %s\n",
|
||||
(aFontStyle->weight == FONT_WEIGHT_BOLD) ? "BOLD" : "",
|
||||
(aFontStyle->style == FONT_STYLE_ITALIC) ? "ITALIC" : "",
|
||||
(aFontStyle->style == FONT_STYLE_OBLIQUE) ? "OBLIQUE" : "");
|
||||
#endif
|
||||
NS_NAMED_LITERAL_STRING(quote, "\""); // seems like we need quotes around the font name
|
||||
*aFontName = quote + fontFace + quote;
|
||||
|
||||
return NS_OK;
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/* vim: set sw=4 sts=4 et cin: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is OS/2 system font code in Thebes.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Peter Weilbacher <mozilla@Weilbacher.org>.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* John Fairhurst, <john_fairhurst@iname.com> } original developers of
|
||||
* Henry Sobotka <sobotka@axess.com> } code taken from
|
||||
* IBM Corp. } nsDeviceContextOS2
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _NS_SYSTEMFONTSOS2_H_
|
||||
#define _NS_SYSTEMFONTSOS2_H_
|
||||
|
||||
#include "gfxFont.h"
|
||||
#include "nsDeviceContext.h"
|
||||
|
||||
class nsSystemFontsOS2
|
||||
{
|
||||
public:
|
||||
nsSystemFontsOS2();
|
||||
nsresult GetSystemFont(nsSystemFontID aID, nsString* aFontName,
|
||||
gfxFontStyle *aFontStyle) const;
|
||||
};
|
||||
|
||||
#endif /* _NS_SYSTEMFONTSOS2_H_ */
|
@ -1,134 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is thebes gfx
|
||||
*
|
||||
* The Initial Developer of the Original Code is mozilla.org.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir@pobox.com>
|
||||
* Stuart Parmenter <pavlov@pavlov.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
// Qt headers must be included before anything that might pull in our
|
||||
// malloc wrappers.
|
||||
#include <QApplication>
|
||||
#include <QFont>
|
||||
|
||||
#include "nsSystemFontsQt.h"
|
||||
#include "gfxQtPlatform.h"
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
nsSystemFontsQt::~nsSystemFontsQt()
|
||||
{
|
||||
// No implementation needed
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSystemFontsQt::GetSystemFontInfo(const char *aClassName, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const
|
||||
{
|
||||
QFont qFont = QApplication::font(aClassName);
|
||||
|
||||
aFontStyle->style = FONT_STYLE_NORMAL;
|
||||
aFontStyle->systemFont = true;
|
||||
NS_NAMED_LITERAL_STRING(quote, "\"");
|
||||
nsString family((PRUnichar*)qFont.family().data());
|
||||
*aFontName = quote + family + quote;
|
||||
aFontStyle->weight = qFont.weight();
|
||||
// FIXME: Set aFontStyle->stretch correctly!
|
||||
aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
|
||||
// use pixel size directly if it is set, otherwise compute from point size
|
||||
if (qFont.pixelSize() != -1) {
|
||||
aFontStyle->size = qFont.pixelSize();
|
||||
} else {
|
||||
aFontStyle->size = qFont.pointSizeF() * 96.0f / 72.0f;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsSystemFontsQt::GetSystemFont(nsSystemFontID anID, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const
|
||||
{
|
||||
switch (anID) {
|
||||
case eSystemFont_Menu: // css2
|
||||
case eSystemFont_PullDownMenu: // css3
|
||||
*aFontName = mMenuFontName;
|
||||
*aFontStyle = mMenuFontStyle;
|
||||
break;
|
||||
|
||||
case eSystemFont_Field: // css3
|
||||
case eSystemFont_List: // css3
|
||||
*aFontName = mFieldFontName;
|
||||
*aFontStyle = mFieldFontStyle;
|
||||
break;
|
||||
|
||||
case eSystemFont_Button: // css3
|
||||
*aFontName = mButtonFontName;
|
||||
*aFontStyle = mButtonFontStyle;
|
||||
break;
|
||||
|
||||
case eSystemFont_Caption: // css2
|
||||
case eSystemFont_Icon: // css2
|
||||
case eSystemFont_MessageBox: // css2
|
||||
case eSystemFont_SmallCaption: // css2
|
||||
case eSystemFont_StatusBar: // css2
|
||||
case eSystemFont_Window: // css3
|
||||
case eSystemFont_Document: // css3
|
||||
case eSystemFont_Workspace: // css3
|
||||
case eSystemFont_Desktop: // css3
|
||||
case eSystemFont_Info: // css3
|
||||
case eSystemFont_Dialog: // css3
|
||||
case eSystemFont_Tooltips: // moz
|
||||
case eSystemFont_Widget: // moz
|
||||
*aFontName = mDefaultFontName;
|
||||
*aFontStyle = mDefaultFontStyle;
|
||||
break;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1,80 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is thebes gfx
|
||||
*
|
||||
* The Initial Developer of the Original Code is mozilla.org.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir@pobox.com>
|
||||
* Stuart Parmenter <pavlov@pavlov.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _NS_SYSTEMFONTSQT_H_
|
||||
#define _NS_SYSTEMFONTSQT_H_
|
||||
|
||||
#include "gfxFont.h"
|
||||
#include "nsDeviceContext.h"
|
||||
|
||||
class nsSystemFontsQt
|
||||
{
|
||||
public:
|
||||
nsSystemFontsQt();
|
||||
~nsSystemFontsQt();
|
||||
|
||||
nsresult GetSystemFont(nsSystemFontID anID, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const;
|
||||
|
||||
private:
|
||||
|
||||
nsresult GetSystemFontInfo(const char *aClassName, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const;
|
||||
|
||||
/*
|
||||
* The following system font constants exist:
|
||||
*
|
||||
* css2: http://www.w3.org/TR/REC-CSS2/fonts.html#x27
|
||||
* eSystemFont_Caption, eSystemFont_Icon, eSystemFont_Menu,
|
||||
* eSystemFont_MessageBox, eSystemFont_SmallCaption,
|
||||
* eSystemFont_StatusBar,
|
||||
* // css3
|
||||
* eSystemFont_Window, eSystemFont_Document,
|
||||
* eSystemFont_Workspace, eSystemFont_Desktop,
|
||||
* eSystemFont_Info, eSystemFont_Dialog,
|
||||
* eSystemFont_Button, eSystemFont_PullDownMenu,
|
||||
* eSystemFont_List, eSystemFont_Field,
|
||||
* // moz
|
||||
* eSystemFont_Tooltips, eSystemFont_Widget
|
||||
*/
|
||||
nsString mDefaultFontName, mButtonFontName, mFieldFontName, mMenuFontName;
|
||||
gfxFontStyle mDefaultFontStyle, mButtonFontStyle, mFieldFontStyle, mMenuFontStyle;
|
||||
};
|
||||
|
||||
#endif /* _NS_SYSTEMFONTSQT_H_ */
|
||||
|
@ -1,246 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is thebes gfx
|
||||
*
|
||||
* The Initial Developer of the Original Code is mozilla.org.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir@pobox.com>
|
||||
* Stuart Parmenter <pavlov@pavlov.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsSystemFontsWin.h"
|
||||
#include "gfxWindowsSurface.h"
|
||||
|
||||
nsresult nsSystemFontsWin::CopyLogFontToNSFont(HDC* aHDC, const LOGFONTW* ptrLogFont,
|
||||
nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const
|
||||
{
|
||||
PRUnichar name[LF_FACESIZE];
|
||||
name[0] = 0;
|
||||
memcpy(name, ptrLogFont->lfFaceName, LF_FACESIZE*sizeof(PRUnichar));
|
||||
*aFontName = name;
|
||||
|
||||
// Do Style
|
||||
aFontStyle->style = FONT_STYLE_NORMAL;
|
||||
if (ptrLogFont->lfItalic)
|
||||
{
|
||||
aFontStyle->style = FONT_STYLE_ITALIC;
|
||||
}
|
||||
// XXX What about oblique?
|
||||
|
||||
// Do Weight
|
||||
aFontStyle->weight = (ptrLogFont->lfWeight == FW_BOLD ?
|
||||
FONT_WEIGHT_BOLD : FONT_WEIGHT_NORMAL);
|
||||
|
||||
// FIXME: Set aFontStyle->stretch correctly!
|
||||
aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
|
||||
|
||||
// XXX mPixelScale is currently hardcoded to 1 in thebes gfx...
|
||||
float mPixelScale = 1.0f;
|
||||
// Do Point Size
|
||||
//
|
||||
// The lfHeight is in pixel and it needs to be adjusted for the
|
||||
// device it will be "displayed" on
|
||||
// Screens and Printers will differe in DPI
|
||||
//
|
||||
// So this accounts for the difference in the DeviceContexts
|
||||
// The mPixelScale will be a "1" for the screen and could be
|
||||
// any value when going to a printer, for example mPixleScale is
|
||||
// 6.25 when going to a 600dpi printer.
|
||||
// round, but take into account whether it is negative
|
||||
float pixelHeight = -ptrLogFont->lfHeight;
|
||||
if (pixelHeight < 0) {
|
||||
HFONT hFont = ::CreateFontIndirectW(ptrLogFont);
|
||||
if (!hFont)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
HGDIOBJ hObject = ::SelectObject(*aHDC, hFont);
|
||||
TEXTMETRIC tm;
|
||||
::GetTextMetrics(*aHDC, &tm);
|
||||
::SelectObject(*aHDC, hObject);
|
||||
::DeleteObject(hFont);
|
||||
pixelHeight = tm.tmAscent;
|
||||
}
|
||||
|
||||
pixelHeight *= mPixelScale;
|
||||
|
||||
// we have problem on Simplified Chinese system because the system
|
||||
// report the default font size is 8 points. but if we use 8, the text
|
||||
// display very ugly. force it to be at 9 points (12 pixels) on that
|
||||
// system (cp936), but leave other sizes alone.
|
||||
if ((pixelHeight < 12) &&
|
||||
(936 == ::GetACP()))
|
||||
pixelHeight = 12;
|
||||
|
||||
aFontStyle->size = pixelHeight;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsSystemFontsWin::GetSysFontInfo(HDC aHDC, nsSystemFontID anID,
|
||||
nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const
|
||||
{
|
||||
HGDIOBJ hGDI;
|
||||
|
||||
LOGFONTW logFont;
|
||||
LOGFONTW* ptrLogFont = NULL;
|
||||
|
||||
NONCLIENTMETRICSW ncm;
|
||||
|
||||
BOOL status;
|
||||
if (anID == eSystemFont_Icon)
|
||||
{
|
||||
status = ::SystemParametersInfoW(SPI_GETICONTITLELOGFONT,
|
||||
sizeof(logFont),
|
||||
(PVOID)&logFont,
|
||||
0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncm.cbSize = sizeof(NONCLIENTMETRICSW);
|
||||
status = ::SystemParametersInfoW(SPI_GETNONCLIENTMETRICS,
|
||||
sizeof(ncm),
|
||||
(PVOID)&ncm,
|
||||
0);
|
||||
}
|
||||
|
||||
if (!status)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
switch (anID)
|
||||
{
|
||||
// Caption in CSS is NOT the same as Caption on Windows
|
||||
//case eSystemFont_Caption:
|
||||
// ptrLogFont = &ncm.lfCaptionFont;
|
||||
// break;
|
||||
|
||||
case eSystemFont_Icon:
|
||||
ptrLogFont = &logFont;
|
||||
break;
|
||||
|
||||
case eSystemFont_Menu:
|
||||
ptrLogFont = &ncm.lfMenuFont;
|
||||
break;
|
||||
|
||||
case eSystemFont_MessageBox:
|
||||
ptrLogFont = &ncm.lfMessageFont;
|
||||
break;
|
||||
|
||||
case eSystemFont_SmallCaption:
|
||||
ptrLogFont = &ncm.lfSmCaptionFont;
|
||||
break;
|
||||
|
||||
case eSystemFont_StatusBar:
|
||||
case eSystemFont_Tooltips:
|
||||
ptrLogFont = &ncm.lfStatusFont;
|
||||
break;
|
||||
|
||||
case eSystemFont_Widget:
|
||||
|
||||
case eSystemFont_Window: // css3
|
||||
case eSystemFont_Document:
|
||||
case eSystemFont_Workspace:
|
||||
case eSystemFont_Desktop:
|
||||
case eSystemFont_Info:
|
||||
case eSystemFont_Dialog:
|
||||
case eSystemFont_Button:
|
||||
case eSystemFont_PullDownMenu:
|
||||
case eSystemFont_List:
|
||||
case eSystemFont_Field:
|
||||
case eSystemFont_Caption:
|
||||
hGDI = ::GetStockObject(DEFAULT_GUI_FONT);
|
||||
if (hGDI != NULL)
|
||||
{
|
||||
if (::GetObjectW(hGDI, sizeof(logFont), &logFont) > 0)
|
||||
{
|
||||
ptrLogFont = &logFont;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} // switch
|
||||
|
||||
if (nsnull == ptrLogFont)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
aFontStyle->systemFont = true;
|
||||
|
||||
return CopyLogFontToNSFont(&aHDC, ptrLogFont, aFontName, aFontStyle);
|
||||
}
|
||||
|
||||
nsresult nsSystemFontsWin::GetSystemFont(nsSystemFontID anID,
|
||||
nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const
|
||||
{
|
||||
nsresult status = NS_OK;
|
||||
|
||||
switch (anID) {
|
||||
case eSystemFont_Caption:
|
||||
case eSystemFont_Icon:
|
||||
case eSystemFont_Menu:
|
||||
case eSystemFont_MessageBox:
|
||||
case eSystemFont_SmallCaption:
|
||||
case eSystemFont_StatusBar:
|
||||
case eSystemFont_Tooltips:
|
||||
case eSystemFont_Widget:
|
||||
|
||||
case eSystemFont_Window: // css3
|
||||
case eSystemFont_Document:
|
||||
case eSystemFont_Workspace:
|
||||
case eSystemFont_Desktop:
|
||||
case eSystemFont_Info:
|
||||
case eSystemFont_Dialog:
|
||||
case eSystemFont_Button:
|
||||
case eSystemFont_PullDownMenu:
|
||||
case eSystemFont_List:
|
||||
case eSystemFont_Field:
|
||||
{
|
||||
HWND hwnd = nsnull;
|
||||
HDC tdc = GetDC(hwnd);
|
||||
|
||||
status = GetSysFontInfo(tdc, anID, aFontName, aFontStyle);
|
||||
|
||||
ReleaseDC(hwnd, tdc);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
nsSystemFontsWin::nsSystemFontsWin()
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -1,61 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is thebes gfx
|
||||
*
|
||||
* The Initial Developer of the Original Code is mozilla.org.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir@pobox.com>
|
||||
* Stuart Parmenter <pavlov@pavlov.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _NS_SYSTEMFONTSWIN_H_
|
||||
#define _NS_SYSTEMFONTSWIN_H_
|
||||
|
||||
#include "gfxFont.h"
|
||||
#include "nsDeviceContext.h"
|
||||
#include <windows.h> // need HDC and LOGFONTW
|
||||
|
||||
class nsSystemFontsWin
|
||||
{
|
||||
public:
|
||||
nsSystemFontsWin();
|
||||
|
||||
nsresult GetSystemFont(nsSystemFontID anID, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const;
|
||||
private:
|
||||
nsresult CopyLogFontToNSFont(HDC* aHDC, const LOGFONTW* ptrLogFont,
|
||||
nsString *aFontName, gfxFontStyle *aFontStyle) const;
|
||||
nsresult GetSysFontInfo(HDC aHDC, nsSystemFontID anID,
|
||||
nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const;
|
||||
};
|
||||
|
||||
#endif /* _NS_SYSTEMFONTSWIN_H_ */
|
@ -43,7 +43,6 @@
|
||||
#include "nsThebesFontEnumerator.h"
|
||||
#include "nsScriptableRegion.h"
|
||||
|
||||
#include "nsDeviceContext.h"
|
||||
#include "gfxPlatform.h"
|
||||
|
||||
// This class doesn't do anything; its only purpose is to give
|
||||
@ -100,7 +99,6 @@ static const mozilla::Module::ContractIDEntry kThebesContracts[] = {
|
||||
static void
|
||||
nsThebesGfxModuleDtor()
|
||||
{
|
||||
nsDeviceContext::ClearCachedSystemFonts();
|
||||
gfxPlatform::Shutdown();
|
||||
}
|
||||
|
||||
|
@ -475,22 +475,22 @@ static inline mozilla::css::Side operator++(mozilla::css::Side& side, int) {
|
||||
#define NS_STYLE_FONT_STRETCH_ULTRA_EXPANDED NS_FONT_STRETCH_ULTRA_EXPANDED
|
||||
|
||||
// See nsStyleFont - system fonts
|
||||
#define NS_STYLE_FONT_CAPTION 1 // css2
|
||||
#define NS_STYLE_FONT_CAPTION 1 // css2
|
||||
#define NS_STYLE_FONT_ICON 2
|
||||
#define NS_STYLE_FONT_MENU 3
|
||||
#define NS_STYLE_FONT_MESSAGE_BOX 4
|
||||
#define NS_STYLE_FONT_SMALL_CAPTION 5
|
||||
#define NS_STYLE_FONT_STATUS_BAR 6
|
||||
#define NS_STYLE_FONT_WINDOW 7 // css3
|
||||
#define NS_STYLE_FONT_DOCUMENT 8
|
||||
#define NS_STYLE_FONT_WORKSPACE 9
|
||||
#define NS_STYLE_FONT_DESKTOP 10
|
||||
#define NS_STYLE_FONT_INFO 11
|
||||
#define NS_STYLE_FONT_DIALOG 12
|
||||
#define NS_STYLE_FONT_BUTTON 13
|
||||
#define NS_STYLE_FONT_PULL_DOWN_MENU 14
|
||||
#define NS_STYLE_FONT_LIST 15
|
||||
#define NS_STYLE_FONT_FIELD 16
|
||||
#define NS_STYLE_FONT_WINDOW 7 // css3
|
||||
#define NS_STYLE_FONT_DOCUMENT 8
|
||||
#define NS_STYLE_FONT_WORKSPACE 9
|
||||
#define NS_STYLE_FONT_DESKTOP 10
|
||||
#define NS_STYLE_FONT_INFO 11
|
||||
#define NS_STYLE_FONT_DIALOG 12
|
||||
#define NS_STYLE_FONT_BUTTON 13
|
||||
#define NS_STYLE_FONT_PULL_DOWN_MENU 14
|
||||
#define NS_STYLE_FONT_LIST 15
|
||||
#define NS_STYLE_FONT_FIELD 16
|
||||
|
||||
// defaults per MathML spec
|
||||
#define NS_MATHML_DEFAULT_SCRIPT_SIZE_MULTIPLIER 0.71f
|
||||
|
@ -2681,71 +2681,74 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
|
||||
aFont->mLanguage);
|
||||
|
||||
// -moz-system-font: enum (never inherit!)
|
||||
nsFont systemFont;
|
||||
PR_STATIC_ASSERT(
|
||||
NS_STYLE_FONT_CAPTION == LookAndFeel::eFont_Caption &&
|
||||
NS_STYLE_FONT_ICON == LookAndFeel::eFont_Icon &&
|
||||
NS_STYLE_FONT_MENU == LookAndFeel::eFont_Menu &&
|
||||
NS_STYLE_FONT_MESSAGE_BOX == LookAndFeel::eFont_MessageBox &&
|
||||
NS_STYLE_FONT_SMALL_CAPTION == LookAndFeel::eFont_SmallCaption &&
|
||||
NS_STYLE_FONT_STATUS_BAR == LookAndFeel::eFont_StatusBar &&
|
||||
NS_STYLE_FONT_WINDOW == LookAndFeel::eFont_Window &&
|
||||
NS_STYLE_FONT_DOCUMENT == LookAndFeel::eFont_Document &&
|
||||
NS_STYLE_FONT_WORKSPACE == LookAndFeel::eFont_Workspace &&
|
||||
NS_STYLE_FONT_DESKTOP == LookAndFeel::eFont_Desktop &&
|
||||
NS_STYLE_FONT_INFO == LookAndFeel::eFont_Info &&
|
||||
NS_STYLE_FONT_DIALOG == LookAndFeel::eFont_Dialog &&
|
||||
NS_STYLE_FONT_BUTTON == LookAndFeel::eFont_Button &&
|
||||
NS_STYLE_FONT_PULL_DOWN_MENU == LookAndFeel::eFont_PullDownMenu &&
|
||||
NS_STYLE_FONT_LIST == LookAndFeel::eFont_List &&
|
||||
NS_STYLE_FONT_FIELD == LookAndFeel::eFont_Field);
|
||||
|
||||
// Fall back to defaultVariableFont.
|
||||
nsFont systemFont = *defaultVariableFont;
|
||||
const nsCSSValue* systemFontValue = aRuleData->ValueForSystemFont();
|
||||
if (eCSSUnit_Enumerated == systemFontValue->GetUnit()) {
|
||||
nsSystemFontID sysID;
|
||||
switch (systemFontValue->GetIntValue()) {
|
||||
case NS_STYLE_FONT_CAPTION: sysID = eSystemFont_Caption; break; // css2
|
||||
case NS_STYLE_FONT_ICON: sysID = eSystemFont_Icon; break;
|
||||
case NS_STYLE_FONT_MENU: sysID = eSystemFont_Menu; break;
|
||||
case NS_STYLE_FONT_MESSAGE_BOX: sysID = eSystemFont_MessageBox; break;
|
||||
case NS_STYLE_FONT_SMALL_CAPTION: sysID = eSystemFont_SmallCaption; break;
|
||||
case NS_STYLE_FONT_STATUS_BAR: sysID = eSystemFont_StatusBar; break;
|
||||
case NS_STYLE_FONT_WINDOW: sysID = eSystemFont_Window; break; // css3
|
||||
case NS_STYLE_FONT_DOCUMENT: sysID = eSystemFont_Document; break;
|
||||
case NS_STYLE_FONT_WORKSPACE: sysID = eSystemFont_Workspace; break;
|
||||
case NS_STYLE_FONT_DESKTOP: sysID = eSystemFont_Desktop; break;
|
||||
case NS_STYLE_FONT_INFO: sysID = eSystemFont_Info; break;
|
||||
case NS_STYLE_FONT_DIALOG: sysID = eSystemFont_Dialog; break;
|
||||
case NS_STYLE_FONT_BUTTON: sysID = eSystemFont_Button; break;
|
||||
case NS_STYLE_FONT_PULL_DOWN_MENU:sysID = eSystemFont_PullDownMenu; break;
|
||||
case NS_STYLE_FONT_LIST: sysID = eSystemFont_List; break;
|
||||
case NS_STYLE_FONT_FIELD: sysID = eSystemFont_Field; break;
|
||||
}
|
||||
|
||||
// GetSystemFont sets the font face but not necessarily the size
|
||||
// XXX Or at least it used to -- no longer true for thebes. Maybe
|
||||
// it should be again, though.
|
||||
systemFont.size = defaultVariableFont->size;
|
||||
|
||||
if (NS_FAILED(aPresContext->DeviceContext()->GetSystemFont(sysID,
|
||||
&systemFont))) {
|
||||
systemFont.name = defaultVariableFont->name;
|
||||
}
|
||||
|
||||
// XXXldb All of this platform-specific stuff should be in the
|
||||
// nsDeviceContext implementations, not here.
|
||||
gfxFontStyle fontStyle;
|
||||
LookAndFeel::FontID fontID =
|
||||
(LookAndFeel::FontID)systemFontValue->GetIntValue();
|
||||
if (LookAndFeel::GetFont(fontID, systemFont.name, fontStyle)) {
|
||||
systemFont.style = fontStyle.style;
|
||||
systemFont.systemFont = fontStyle.systemFont;
|
||||
systemFont.variant = NS_FONT_VARIANT_NORMAL;
|
||||
systemFont.weight = fontStyle.weight;
|
||||
systemFont.stretch = fontStyle.stretch;
|
||||
systemFont.decorations = NS_FONT_DECORATION_NONE;
|
||||
systemFont.size = NSFloatPixelsToAppUnits(fontStyle.size,
|
||||
aPresContext->DeviceContext()->
|
||||
UnscaledAppUnitsPerDevPixel());
|
||||
//systemFont.langGroup = fontStyle.langGroup;
|
||||
systemFont.sizeAdjust = fontStyle.sizeAdjust;
|
||||
|
||||
#ifdef XP_WIN
|
||||
//
|
||||
// As far as I can tell the system default fonts and sizes for
|
||||
// on MS-Windows for Buttons, Listboxes/Comboxes and Text Fields are
|
||||
// all pre-determined and cannot be changed by either the control panel
|
||||
// or programmtically.
|
||||
//
|
||||
switch (sysID) {
|
||||
// Fields (text fields)
|
||||
// Button and Selects (listboxes/comboboxes)
|
||||
// We use whatever font is defined by the system. Which it appears
|
||||
// (and the assumption is) it is always a proportional font. Then we
|
||||
// always use 2 points smaller than what the browser has defined as
|
||||
// the default proportional font.
|
||||
case eSystemFont_Field:
|
||||
case eSystemFont_Button:
|
||||
case eSystemFont_List:
|
||||
// XXXldb This platform-specific stuff should be in the
|
||||
// LookAndFeel implementation, not here.
|
||||
// XXXzw Should we even still *have* this code? It looks to be making
|
||||
// old, probably obsolete assumptions.
|
||||
|
||||
// As far as I can tell the system default fonts and sizes
|
||||
// on MS-Windows for Buttons, Listboxes/Comboxes and Text Fields are
|
||||
// all pre-determined and cannot be changed by either the control panel
|
||||
// or programmtically.
|
||||
switch (fontID) {
|
||||
// Fields (text fields)
|
||||
// Button and Selects (listboxes/comboboxes)
|
||||
// We use whatever font is defined by the system. Which it appears
|
||||
// (and the assumption is) it is always a proportional font. Then we
|
||||
// always use 2 points smaller than what the browser has defined as
|
||||
// the default proportional font.
|
||||
case LookAndFeel::eFont_Field:
|
||||
case LookAndFeel::eFont_Button:
|
||||
case LookAndFeel::eFont_List:
|
||||
// Assumption: system defined font is proportional
|
||||
systemFont.size =
|
||||
NS_MAX(defaultVariableFont->size - nsPresContext::CSSPointsToAppUnits(2), 0);
|
||||
NS_MAX(defaultVariableFont->size -
|
||||
nsPresContext::CSSPointsToAppUnits(2), 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
// In case somebody explicitly used -moz-use-system-font.
|
||||
systemFont = *defaultVariableFont;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// font-family: string list, enum, inherit
|
||||
const nsCSSValue* familyValue = aRuleData->ValueForFontFamily();
|
||||
NS_ASSERTION(eCSSUnit_Enumerated != familyValue->GetUnit(),
|
||||
|
@ -45,8 +45,7 @@
|
||||
#include "nsDebug.h"
|
||||
#include "nsColor.h"
|
||||
|
||||
// for |#ifdef NS_DEBUG|
|
||||
struct nsSize;
|
||||
struct gfxFontStyle;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
@ -434,6 +433,31 @@ public:
|
||||
eFloatID_CaretAspectRatio
|
||||
};
|
||||
|
||||
// These constants must be kept in 1:1 correspondence with the
|
||||
// NS_STYLE_FONT_* system font constants.
|
||||
enum FontID {
|
||||
eFont_Caption = 1, // css2
|
||||
eFont_Icon,
|
||||
eFont_Menu,
|
||||
eFont_MessageBox,
|
||||
eFont_SmallCaption,
|
||||
eFont_StatusBar,
|
||||
|
||||
eFont_Window, // css3
|
||||
eFont_Document,
|
||||
eFont_Workspace,
|
||||
eFont_Desktop,
|
||||
eFont_Info,
|
||||
eFont_Dialog,
|
||||
eFont_Button,
|
||||
eFont_PullDownMenu,
|
||||
eFont_List,
|
||||
eFont_Field,
|
||||
|
||||
eFont_Tooltips, // moz
|
||||
eFont_Widget
|
||||
};
|
||||
|
||||
/**
|
||||
* GetColor() return a native color value (might be overwritten by prefs) for
|
||||
* aID. Some platforms don't return an error even if the index doesn't
|
||||
@ -489,6 +513,17 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the name and style of a system-theme font. Returns true
|
||||
* if the system theme specifies this font, false if a default should
|
||||
* be used. In the latter case neither aName nor aStyle is modified.
|
||||
*
|
||||
* @param aID Which system-theme font is wanted.
|
||||
* @param aName The name of the font to use.
|
||||
* @param aStyle Styling to apply to the font.
|
||||
*/
|
||||
static bool GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle);
|
||||
|
||||
/**
|
||||
* GetPasswordCharacter() returns a unicode character which should be used
|
||||
* for a masked character in password editor. E.g., '*'.
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
#include "nsLookAndFeel.h"
|
||||
#include "gfxFont.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using mozilla::dom::ContentChild;
|
||||
@ -471,6 +472,20 @@ nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*virtual*/
|
||||
bool
|
||||
nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle)
|
||||
{
|
||||
aFontName.AssignLiteral("\"Droid Sans\"");
|
||||
aFontStyle.style = NS_FONT_STYLE_NORMAL;
|
||||
aFontStyle.weight = NS_FONT_WEIGHT_NORMAL;
|
||||
aFontStyle.stretch = NS_FONT_STRETCH_NORMAL;
|
||||
aFontStyle.size = 9.0 * 96.0f / 72.0f;
|
||||
aFontStyle.systemFont = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*virtual*/
|
||||
bool
|
||||
nsLookAndFeel::GetEchoPasswordImpl()
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult);
|
||||
virtual nsresult GetIntImpl(IntID aID, PRInt32 &aResult);
|
||||
virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
|
||||
virtual bool GetFontImpl(FontID aID, nsString& aName, gfxFontStyle& aStyle);
|
||||
virtual bool GetEchoPasswordImpl();
|
||||
|
||||
protected:
|
||||
|
@ -47,6 +47,8 @@ public:
|
||||
virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult);
|
||||
virtual nsresult GetIntImpl(IntID aID, PRInt32 &aResult);
|
||||
virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
|
||||
virtual bool GetFontImpl(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle);
|
||||
virtual PRUnichar GetPasswordCharacterImpl()
|
||||
{
|
||||
// unicode value for the bullet character, used for password textfields.
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsNativeThemeColors.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "gfxFont.h"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@ -468,3 +469,122 @@ nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// copied from gfxQuartzFontCache.mm, maybe should go in a Cocoa utils
|
||||
// file somewhere
|
||||
static void GetStringForNSString(const NSString *aSrc, nsAString& aDest)
|
||||
{
|
||||
aDest.SetLength([aSrc length]);
|
||||
[aSrc getCharacters:aDest.BeginWriting()];
|
||||
}
|
||||
|
||||
bool
|
||||
nsLookAndFeel::GetFontImpl(FontID aID, nsString &aFontName,
|
||||
gfxFontStyle &aFontStyle)
|
||||
{
|
||||
// hack for now
|
||||
if (aID == eFont_Window || aID == eFont_Document) {
|
||||
aFontStyle.style = FONT_STYLE_NORMAL;
|
||||
aFontStyle.weight = FONT_WEIGHT_NORMAL;
|
||||
aFontStyle.stretch = NS_FONT_STRETCH_NORMAL;
|
||||
aFontStyle.size = 14;
|
||||
aFontStyle.systemFont = true;
|
||||
|
||||
aFontName.AssignLiteral("sans-serif");
|
||||
return true;
|
||||
}
|
||||
|
||||
/* possibilities, see NSFont Class Reference:
|
||||
[NSFont boldSystemFontOfSize: 0.0]
|
||||
[NSFont controlContentFontOfSize: 0.0]
|
||||
[NSFont labelFontOfSize: 0.0]
|
||||
[NSFont menuBarFontOfSize: 0.0]
|
||||
[NSFont menuFontOfSize: 0.0]
|
||||
[NSFont messageFontOfSize: 0.0]
|
||||
[NSFont paletteFontOfSize: 0.0]
|
||||
[NSFont systemFontOfSize: 0.0]
|
||||
[NSFont titleBarFontOfSize: 0.0]
|
||||
[NSFont toolTipsFontOfSize: 0.0]
|
||||
[NSFont userFixedPitchFontOfSize: 0.0]
|
||||
[NSFont userFontOfSize: 0.0]
|
||||
[NSFont systemFontOfSize: [NSFont smallSystemFontSize]]
|
||||
[NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]]
|
||||
*/
|
||||
|
||||
NSFont *font = nsnull;
|
||||
switch (aID) {
|
||||
// css2
|
||||
case eFont_Caption:
|
||||
font = [NSFont systemFontOfSize:0.0];
|
||||
break;
|
||||
case eFont_Icon: // used in urlbar; tried labelFont, but too small
|
||||
font = [NSFont controlContentFontOfSize:0.0];
|
||||
break;
|
||||
case eFont_Menu:
|
||||
font = [NSFont systemFontOfSize:0.0];
|
||||
break;
|
||||
case eFont_MessageBox:
|
||||
font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
|
||||
break;
|
||||
case eFont_SmallCaption:
|
||||
font = [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]];
|
||||
break;
|
||||
case eFont_StatusBar:
|
||||
font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
|
||||
break;
|
||||
// css3
|
||||
//case eFont_Window: = 'sans-serif'
|
||||
//case eFont_Document: = 'sans-serif'
|
||||
case eFont_Workspace:
|
||||
font = [NSFont controlContentFontOfSize:0.0];
|
||||
break;
|
||||
case eFont_Desktop:
|
||||
font = [NSFont controlContentFontOfSize:0.0];
|
||||
break;
|
||||
case eFont_Info:
|
||||
font = [NSFont controlContentFontOfSize:0.0];
|
||||
break;
|
||||
case eFont_Dialog:
|
||||
font = [NSFont systemFontOfSize:0.0];
|
||||
break;
|
||||
case eFont_Button:
|
||||
font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
|
||||
break;
|
||||
case eFont_PullDownMenu:
|
||||
font = [NSFont menuBarFontOfSize:0.0];
|
||||
break;
|
||||
case eFont_List:
|
||||
font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
|
||||
break;
|
||||
case eFont_Field:
|
||||
font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
|
||||
break;
|
||||
// moz
|
||||
case eFont_Tooltips:
|
||||
font = [NSFont toolTipsFontOfSize:0.0];
|
||||
break;
|
||||
case eFont_Widget:
|
||||
font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
|
||||
break;
|
||||
}
|
||||
|
||||
if (!font) {
|
||||
NS_WARNING("failed to find a system font!");
|
||||
return false;
|
||||
}
|
||||
|
||||
NSFontSymbolicTraits traits = [[font fontDescriptor] symbolicTraits];
|
||||
aFontStyle.style =
|
||||
(traits & NSFontItalicTrait) ? FONT_STYLE_ITALIC : FONT_STYLE_NORMAL;
|
||||
aFontStyle.weight =
|
||||
(traits & NSFontBoldTrait) ? FONT_WEIGHT_BOLD : FONT_WEIGHT_NORMAL;
|
||||
aFontStyle.stretch =
|
||||
(traits & NSFontExpandedTrait) ?
|
||||
NS_FONT_STRETCH_EXPANDED : (traits & NSFontCondensedTrait) ?
|
||||
NS_FONT_STRETCH_CONDENSED : NS_FONT_STRETCH_NORMAL;
|
||||
aFontStyle.size = [font pointSize];
|
||||
aFontStyle.systemFont = true;
|
||||
|
||||
GetStringForNSString([font familyName], aFontName);
|
||||
return true;
|
||||
}
|
||||
|
@ -37,6 +37,7 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsLookAndFeel.h"
|
||||
#include "gfxFont.h"
|
||||
|
||||
nsLookAndFeel::nsLookAndFeel()
|
||||
: nsXPLookAndFeel()
|
||||
@ -316,4 +317,16 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/*virtual*/
|
||||
bool
|
||||
nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle)
|
||||
{
|
||||
aFontName.AssignLiteral("\"Droid Sans\"");
|
||||
aFontStyle.style = NS_FONT_STYLE_NORMAL;
|
||||
aFontStyle.weight = NS_FONT_WEIGHT_NORMAL;
|
||||
aFontStyle.stretch = NS_FONT_STRETCH_NORMAL;
|
||||
aFontStyle.size = 9.0 * 96.0f / 72.0f;
|
||||
aFontStyle.systemFont = true;
|
||||
return true;
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ public:
|
||||
nsLookAndFeel();
|
||||
virtual ~nsLookAndFeel();
|
||||
|
||||
virtual bool GetFontImpl(FontID aID, nsString& aName, gfxFontStyle& aStyle);
|
||||
|
||||
protected:
|
||||
virtual nsresult NativeGetColor(ColorID aID, nscolor &aColor);
|
||||
};
|
||||
|
@ -38,8 +38,21 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
// for strtod()
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "nsLookAndFeel.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#ifdef MOZ_PANGO
|
||||
#include <pango/pango.h>
|
||||
#include <pango/pango-fontmap.h>
|
||||
#endif
|
||||
|
||||
#include <fontconfig/fontconfig.h>
|
||||
#include "gfxPlatformGtk.h"
|
||||
|
||||
#include "gtkdrawing.h"
|
||||
#include "nsStyleConsts.h"
|
||||
@ -50,6 +63,8 @@
|
||||
#include "nsLiteralString.h"
|
||||
#endif
|
||||
|
||||
using mozilla::LookAndFeel;
|
||||
|
||||
#define GDK_COLOR_TO_NS_RGB(c) \
|
||||
((nscolor) NS_RGB(c.red>>8, c.green>>8, c.blue>>8))
|
||||
|
||||
@ -73,14 +88,12 @@ PRUnichar nsLookAndFeel::sInvisibleCharacter = PRUnichar('*');
|
||||
float nsLookAndFeel::sCaretRatio = 0;
|
||||
bool nsLookAndFeel::sMenuSupportsDrag = false;
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Query interface implementation
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
|
||||
nsLookAndFeel::nsLookAndFeel()
|
||||
: nsXPLookAndFeel(),
|
||||
mStyle(nsnull),
|
||||
mDefaultFontCached(false), mButtonFontCached(false),
|
||||
mFieldFontCached(false), mMenuFontCached(false)
|
||||
{
|
||||
mStyle = nsnull;
|
||||
InitWidget();
|
||||
|
||||
static bool sInitialized = false;
|
||||
@ -617,6 +630,189 @@ nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
|
||||
return res;
|
||||
}
|
||||
|
||||
#ifdef MOZ_PANGO
|
||||
static void
|
||||
GetSystemFontInfo(GtkWidget *aWidget,
|
||||
nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle)
|
||||
{
|
||||
GtkSettings *settings = gtk_widget_get_settings(aWidget);
|
||||
|
||||
aFontStyle->style = FONT_STYLE_NORMAL;
|
||||
|
||||
gchar *fontname;
|
||||
g_object_get(settings, "gtk-font-name", &fontname, NULL);
|
||||
|
||||
PangoFontDescription *desc;
|
||||
desc = pango_font_description_from_string(fontname);
|
||||
|
||||
aFontStyle->systemFont = true;
|
||||
|
||||
g_free(fontname);
|
||||
|
||||
NS_NAMED_LITERAL_STRING(quote, "\"");
|
||||
NS_ConvertUTF8toUTF16 family(pango_font_description_get_family(desc));
|
||||
*aFontName = quote + family + quote;
|
||||
|
||||
aFontStyle->weight = pango_font_description_get_weight(desc);
|
||||
|
||||
// FIXME: Set aFontStyle->stretch correctly!
|
||||
aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
|
||||
|
||||
float size = float(pango_font_description_get_size(desc)) / PANGO_SCALE;
|
||||
|
||||
// |size| is now either pixels or pango-points (not Mozilla-points!)
|
||||
|
||||
if (!pango_font_description_get_size_is_absolute(desc)) {
|
||||
// |size| is in pango-points, so convert to pixels.
|
||||
size *= float(gfxPlatformGtk::GetDPI()) / POINTS_PER_INCH_FLOAT;
|
||||
}
|
||||
|
||||
// |size| is now pixels
|
||||
|
||||
aFontStyle->size = size;
|
||||
|
||||
pango_font_description_free(desc);
|
||||
}
|
||||
|
||||
static void
|
||||
GetSystemFontInfo(LookAndFeel::FontID aID,
|
||||
nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle)
|
||||
{
|
||||
if (aID == LookAndFeel::eFont_Widget) {
|
||||
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, aFontName, aFontStyle);
|
||||
gtk_widget_destroy(window); // no unref, windows are different
|
||||
|
||||
} else if (aID == LookAndFeel::eFont_Button) {
|
||||
GtkWidget *label = gtk_label_new("M");
|
||||
GtkWidget *parent = gtk_fixed_new();
|
||||
GtkWidget *button = gtk_button_new();
|
||||
GtkWidget *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, aFontName, aFontStyle);
|
||||
gtk_widget_destroy(window); // no unref, windows are different
|
||||
|
||||
} else if (aID == LookAndFeel::eFont_Field) {
|
||||
GtkWidget *entry = gtk_entry_new();
|
||||
GtkWidget *parent = gtk_fixed_new();
|
||||
GtkWidget *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, aFontName, aFontStyle);
|
||||
gtk_widget_destroy(window); // no unref, windows are different
|
||||
|
||||
} else {
|
||||
NS_ABORT_IF_FALSE(aID == LookAndFeel::eFont_Menu, "unexpected font ID");
|
||||
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, aFontName, aFontStyle);
|
||||
g_object_unref(menu);
|
||||
}
|
||||
}
|
||||
|
||||
#else // not MOZ_PANGO
|
||||
|
||||
static void
|
||||
GetSystemFontInfo(LookAndFeel::FontID /*unused */,
|
||||
nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle)
|
||||
{
|
||||
/* FIXME: DFB FT2 Hardcoding the system font info for now. */
|
||||
aFontStyle->style = FONT_STYLE_NORMAL;
|
||||
aFontStyle->weight = 400;
|
||||
aFontStyle->size = 40/3;
|
||||
aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
|
||||
aFontStyle->systemFont = true;
|
||||
aFontName->AssignLiteral("\"Sans\"");
|
||||
}
|
||||
|
||||
#endif // not MOZ_PANGO
|
||||
|
||||
bool
|
||||
nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle)
|
||||
{
|
||||
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;
|
||||
aID = eFont_Menu;
|
||||
break;
|
||||
|
||||
case eFont_Field: // css3
|
||||
case eFont_List: // css3
|
||||
cachedFontName = &mFieldFontName;
|
||||
cachedFontStyle = &mFieldFontStyle;
|
||||
isCached = &mFieldFontCached;
|
||||
aID = eFont_Field;
|
||||
break;
|
||||
|
||||
case eFont_Button: // css3
|
||||
cachedFontName = &mButtonFontName;
|
||||
cachedFontStyle = &mButtonFontStyle;
|
||||
isCached = &mButtonFontCached;
|
||||
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;
|
||||
aID = eFont_Widget;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!*isCached) {
|
||||
GetSystemFontInfo(aID, cachedFontName, cachedFontStyle);
|
||||
*isCached = true;
|
||||
}
|
||||
|
||||
aFontName = *cachedFontName;
|
||||
aFontStyle = *cachedFontStyle;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
nsLookAndFeel::InitLookAndFeel()
|
||||
{
|
||||
@ -799,6 +995,31 @@ nsLookAndFeel::InitLookAndFeel()
|
||||
gtk_widget_destroy(window);
|
||||
}
|
||||
|
||||
void
|
||||
nsLookAndFeel::InitWidget()
|
||||
{
|
||||
NS_ASSERTION(!mStyle, "already initialized");
|
||||
// GtkInvisibles come with a refcount that is not floating
|
||||
// (since their initialization code calls g_object_ref_sink) and
|
||||
// their destroy code releases that reference (which means they
|
||||
// have to be explicitly destroyed, since calling unref enough
|
||||
// to cause destruction would lead to *another* unref).
|
||||
// However, this combination means that it's actually still ok
|
||||
// to use the normal pattern, which is to g_object_ref_sink
|
||||
// after construction, and then destroy *and* unref when we're
|
||||
// done. (Though we could skip the g_object_ref_sink and the
|
||||
// corresponding g_object_unref, but that's particular to
|
||||
// GtkInvisibles and GtkWindows.)
|
||||
GtkWidget *widget = gtk_invisible_new();
|
||||
g_object_ref_sink(widget); // effectively g_object_ref (see above)
|
||||
|
||||
gtk_widget_ensure_style(widget);
|
||||
mStyle = gtk_style_copy(gtk_widget_get_style(widget));
|
||||
|
||||
gtk_widget_destroy(widget);
|
||||
g_object_unref(widget);
|
||||
}
|
||||
|
||||
// virtual
|
||||
PRUnichar
|
||||
nsLookAndFeel::GetPasswordCharacterImpl()
|
||||
@ -811,9 +1032,14 @@ nsLookAndFeel::RefreshImpl()
|
||||
{
|
||||
nsXPLookAndFeel::RefreshImpl();
|
||||
|
||||
mDefaultFontCached = false;
|
||||
mButtonFontCached = false;
|
||||
mFieldFontCached = false;
|
||||
mMenuFontCached = false;
|
||||
|
||||
g_object_unref(mStyle);
|
||||
mStyle = nsnull;
|
||||
|
||||
|
||||
InitWidget();
|
||||
InitLookAndFeel();
|
||||
}
|
||||
|
@ -39,9 +39,12 @@
|
||||
|
||||
#ifndef __nsLookAndFeel
|
||||
#define __nsLookAndFeel
|
||||
|
||||
#include "nsXPLookAndFeel.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include <gtk/gtk.h>
|
||||
#include "gfxFont.h"
|
||||
|
||||
struct _GtkStyle;
|
||||
|
||||
class nsLookAndFeel: public nsXPLookAndFeel {
|
||||
public:
|
||||
@ -51,12 +54,29 @@ public:
|
||||
virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult);
|
||||
virtual nsresult GetIntImpl(IntID aID, PRInt32 &aResult);
|
||||
virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
|
||||
virtual bool GetFontImpl(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle);
|
||||
|
||||
virtual void RefreshImpl();
|
||||
virtual PRUnichar GetPasswordCharacterImpl();
|
||||
virtual bool GetEchoPasswordImpl();
|
||||
|
||||
protected:
|
||||
GtkStyle *mStyle;
|
||||
struct _GtkStyle *mStyle;
|
||||
|
||||
// Cached fonts
|
||||
bool mDefaultFontCached;
|
||||
bool mButtonFontCached;
|
||||
bool mFieldFontCached;
|
||||
bool mMenuFontCached;
|
||||
nsString mDefaultFontName;
|
||||
nsString mButtonFontName;
|
||||
nsString mFieldFontName;
|
||||
nsString mMenuFontName;
|
||||
gfxFontStyle mDefaultFontStyle;
|
||||
gfxFontStyle mButtonFontStyle;
|
||||
gfxFontStyle mFieldFontStyle;
|
||||
gfxFontStyle mMenuFontStyle;
|
||||
|
||||
// Cached colors, we have to create a dummy widget to actually
|
||||
// get the style
|
||||
@ -82,28 +102,7 @@ protected:
|
||||
static bool sMenuSupportsDrag;
|
||||
|
||||
static void InitLookAndFeel();
|
||||
void InitWidget() {
|
||||
NS_ASSERTION(!mStyle, "already initialized");
|
||||
// GtkInvisibles come with a refcount that is not floating
|
||||
// (since their initialization code calls g_object_ref_sink) and
|
||||
// their destroy code releases that reference (which means they
|
||||
// have to be explicitly destroyed, since calling unref enough
|
||||
// to cause destruction would lead to *another* unref).
|
||||
// However, this combination means that it's actually still ok
|
||||
// to use the normal pattern, which is to g_object_ref_sink
|
||||
// after construction, and then destroy *and* unref when we're
|
||||
// done. (Though we could skip the g_object_ref_sink and the
|
||||
// corresponding g_object_unref, but that's particular to
|
||||
// GtkInvisibles and GtkWindows.)
|
||||
GtkWidget *widget = gtk_invisible_new();
|
||||
g_object_ref_sink(widget); // effectively g_object_ref (see above)
|
||||
|
||||
gtk_widget_ensure_style(widget);
|
||||
mStyle = gtk_style_copy(gtk_widget_get_style(widget));
|
||||
|
||||
gtk_widget_destroy(widget);
|
||||
g_object_unref(widget);
|
||||
}
|
||||
void InitWidget();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1317,8 +1317,6 @@ nsNativeThemeGTK::WidgetStateChanged(nsIFrame* aFrame, PRUint8 aWidgetType,
|
||||
NS_IMETHODIMP
|
||||
nsNativeThemeGTK::ThemeChanged()
|
||||
{
|
||||
nsDeviceContext::ClearCachedSystemFonts();
|
||||
|
||||
memset(mDisabledWidgetTypes, 0, sizeof(mDisabledWidgetTypes));
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -39,12 +39,21 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#define INCL_WIN
|
||||
#define INCL_WINWINDOWMGR
|
||||
#define INCL_WINSHELLDATA
|
||||
#define INCL_DOSNLS
|
||||
#define INCL_DOSERRORS
|
||||
#include <os2.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "nsLookAndFeel.h"
|
||||
#include "nsFont.h"
|
||||
#include "nsSize.h"
|
||||
#include "nsStyleConsts.h"
|
||||
|
||||
static bool bIsDBCS;
|
||||
static bool bIsDBCSSet = false;
|
||||
|
||||
nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
|
||||
{
|
||||
}
|
||||
@ -70,7 +79,7 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
|
||||
idx = SYSCLR_BUTTONMIDDLE;
|
||||
break;
|
||||
case eColorID_WidgetForeground:
|
||||
idx = SYSCLR_WINDOWTEXT;
|
||||
idx = SYSCLR_WINDOWTEXT;
|
||||
break;
|
||||
case eColorID_WidgetSelectBackground:
|
||||
idx = SYSCLR_HILITEBACKGROUND;
|
||||
@ -272,7 +281,7 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsLookAndFeel::GetIntImpl(IntID aID, PRInt32 &aResult)
|
||||
{
|
||||
@ -384,3 +393,189 @@ nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Helper function to determine if we are running on DBCS */
|
||||
static bool
|
||||
IsDBCS()
|
||||
{
|
||||
if (!bIsDBCSSet) {
|
||||
APIRET rc;
|
||||
COUNTRYCODE ctrycodeInfo = {0};
|
||||
CHAR achDBCSInfo[12] = {0}; // DBCS environmental vector
|
||||
ctrycodeInfo.country = 0; // current country
|
||||
ctrycodeInfo.codepage = 0; // current codepage
|
||||
|
||||
rc = DosQueryDBCSEnv(sizeof(achDBCSInfo), &ctrycodeInfo, achDBCSInfo);
|
||||
if (rc == NO_ERROR) {
|
||||
// DBCS countries will have at least one nonzero byte in the
|
||||
// first four bytes of the DBCS environmental vector
|
||||
bIsDBCS = (achDBCSInfo[0] != 0 || achDBCSInfo[1] != 0 ||
|
||||
achDBCSInfo[2] != 0 || achDBCSInfo[3] != 0);
|
||||
} else {
|
||||
bIsDBCS = false;
|
||||
}
|
||||
bIsDBCSSet = true;
|
||||
}
|
||||
return bIsDBCS;
|
||||
}
|
||||
|
||||
/* Helper function to query font from INI file */
|
||||
static void
|
||||
QueryFontFromINI(char* fontType, char* fontName, ULONG ulLength)
|
||||
{
|
||||
ULONG ulMaxNameL = ulLength;
|
||||
|
||||
// We must use PrfQueryProfileData here, because some users have
|
||||
// binary font data in their INI files.
|
||||
if (PrfQueryProfileData(HINI_USER,
|
||||
(PCSZ)"PM_SystemFonts",
|
||||
(PCSZ)fontType,
|
||||
fontName, &ulMaxNameL)) {
|
||||
// PrfQueryProfileData does not nul-terminate for us.
|
||||
fontName[ulMaxNameL] = '\0';
|
||||
} else {
|
||||
// If there was no entry in the INI, default to something sensible.
|
||||
// Make sure to use a DBCS-capable font in a DBCS-capable environment.
|
||||
if (IsDBCS()) {
|
||||
strcpy(fontName, "9.WarpSans Combined");
|
||||
} else {
|
||||
strcpy(fontName, "9.WarpSans");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Query the font used for various CSS properties (aID) from the system.
|
||||
* For OS/2, only very few fonts are defined in the system, so most of the IDs
|
||||
* resolve to the same system font.
|
||||
* The font queried will give back a string like
|
||||
* 9.WarpSans Bold
|
||||
* 12.Times New Roman Bold Italic
|
||||
* 10.Times New Roman.Strikeout.Underline
|
||||
* 20.Bitstream Vera Sans Mono Obli
|
||||
* (always restricted to 32 chars, at least before the second dot)
|
||||
* We use the value before the dot as the font size (in pt, and convert it to
|
||||
* px using the screen resolution) and then try to use the rest of the string
|
||||
* to determine the font style from it.
|
||||
*/
|
||||
bool
|
||||
nsLookAndFeel::GetFont(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle)
|
||||
{
|
||||
char szFontNameSize[MAXNAMEL];
|
||||
|
||||
switch (aID)
|
||||
{
|
||||
case eFont_Icon:
|
||||
QueryFontFromINI("IconText", szFontNameSize, MAXNAMEL);
|
||||
break;
|
||||
|
||||
case eFont_Menu:
|
||||
QueryFontFromINI("Menus", szFontNameSize, MAXNAMEL);
|
||||
break;
|
||||
|
||||
case eFont_Caption:
|
||||
case eFont_MessageBox:
|
||||
case eFont_SmallCaption:
|
||||
case eFont_StatusBar:
|
||||
case eFont_Tooltips:
|
||||
case eFont_Widget:
|
||||
|
||||
case eFont_Window: // css3
|
||||
case eFont_Document:
|
||||
case eFont_Workspace:
|
||||
case eFont_Desktop:
|
||||
case eFont_Info:
|
||||
case eFont_Dialog:
|
||||
case eFont_Button:
|
||||
case eFont_PullDownMenu:
|
||||
case eFont_List:
|
||||
case eFont_Field:
|
||||
QueryFontFromINI("WindowText", szFontNameSize, MAXNAMEL);
|
||||
break;
|
||||
|
||||
default:
|
||||
NS_WARNING("None of the listed font types, using WarpSans");
|
||||
if (!IsDBCS()) {
|
||||
strcpy(szFontNameSize, "9.WarpSans");
|
||||
} else {
|
||||
strcpy(szFontNameSize, "9.WarpSans Combined");
|
||||
}
|
||||
}
|
||||
|
||||
char *szFacename = strchr(szFontNameSize, '.');
|
||||
if (!szFacename || (*(szFacename++) == '\0'))
|
||||
return false;
|
||||
|
||||
// local DPI for size will be taken into account below
|
||||
aFontStyle.size = atof(szFontNameSize);
|
||||
|
||||
// determine DPI resolution of screen device to compare compute
|
||||
// font size in pixels
|
||||
HPS ps = WinGetScreenPS(HWND_DESKTOP);
|
||||
HDC dc = GpiQueryDevice(ps);
|
||||
// effective vertical resolution in DPI
|
||||
LONG vertScreenRes = 120; // assume 120 dpi as default
|
||||
DevQueryCaps(dc, CAPS_VERTICAL_FONT_RES, 1, &vertScreenRes);
|
||||
WinReleasePS(ps);
|
||||
|
||||
// now scale to make pixels from points (1 pt = 1/72in)
|
||||
aFontStyle.size *= vertScreenRes / 72.0;
|
||||
|
||||
NS_ConvertUTF8toUTF16 fontFace(szFacename);
|
||||
int pos = 0;
|
||||
|
||||
// this is a system font in any case
|
||||
aFontStyle.systemFont = true;
|
||||
|
||||
// bold fonts should have " Bold" in their names, at least we hope that they
|
||||
// do, otherwise it's bad luck
|
||||
NS_NAMED_LITERAL_CSTRING(spcBold, " Bold");
|
||||
if ((pos = fontFace.Find(spcBold.get(), false, 0, -1)) > -1) {
|
||||
aFontStyle.weight = FONT_WEIGHT_BOLD;
|
||||
// strip the attribute, now that we have set it in the gfxFontStyle
|
||||
fontFace.Cut(pos, spcBold.Length());
|
||||
} else {
|
||||
aFontStyle.weight = FONT_WEIGHT_NORMAL;
|
||||
}
|
||||
|
||||
// FIXME: Set aFontStyle.stretch correctly!
|
||||
aFontStyle.stretch = NS_FONT_STRETCH_NORMAL;
|
||||
|
||||
// similar hopes for italic and oblique fonts...
|
||||
NS_NAMED_LITERAL_CSTRING(spcItalic, " Italic");
|
||||
NS_NAMED_LITERAL_CSTRING(spcOblique, " Oblique");
|
||||
NS_NAMED_LITERAL_CSTRING(spcObli, " Obli");
|
||||
if ((pos = fontFace.Find(spcItalic.get(), false, 0, -1)) > -1) {
|
||||
aFontStyle.style = FONT_STYLE_ITALIC;
|
||||
fontFace.Cut(pos, spcItalic.Length());
|
||||
} else if ((pos = fontFace.Find(spcOblique.get(), false, 0, -1)) > -1) {
|
||||
// oblique fonts are rare on OS/2 and not specially supported by
|
||||
// the GPI system, but at least we are trying...
|
||||
aFontStyle.style = FONT_STYLE_OBLIQUE;
|
||||
fontFace.Cut(pos, spcOblique.Length());
|
||||
} else if ((pos = fontFace.Find(spcObli.get(), false, 0, -1)) > -1) {
|
||||
// especially oblique often gets cut by the 32 char limit to "Obli",
|
||||
// so search for that, too (anything shorter would be ambiguous)
|
||||
aFontStyle.style = FONT_STYLE_OBLIQUE;
|
||||
// In this case, assume that this is the last property in the line
|
||||
// and cut off everything else, too
|
||||
// This is needed in case it was really Obliq or Obliqu...
|
||||
fontFace.Cut(pos, fontFace.Length());
|
||||
} else {
|
||||
aFontStyle.style = FONT_STYLE_NORMAL;
|
||||
}
|
||||
|
||||
// just throw away any modifiers that are separated by dots (which are either
|
||||
// .Strikeout, .Underline, or .Outline, none of which have a corresponding
|
||||
// gfxFont property)
|
||||
if ((pos = fontFace.Find(".", false, 0, -1)) > -1) {
|
||||
fontFace.Cut(pos, fontFace.Length());
|
||||
}
|
||||
|
||||
// seems like we need quotes around the font name
|
||||
NS_NAMED_LITERAL_STRING(quote, "\"");
|
||||
aFontName = quote + fontFace + quote;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ public:
|
||||
virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult);
|
||||
virtual nsresult GetIntImpl(IntID aID, PRInt32 &aResult);
|
||||
virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
|
||||
virtual bool GetFontImpl(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
@ -38,24 +38,30 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <QPalette>
|
||||
// Qt headers must be included before anything that might pull in our
|
||||
// malloc wrappers.
|
||||
#include <QApplication>
|
||||
#include <QFont>
|
||||
#include <QPalette>
|
||||
#include <QStyle>
|
||||
|
||||
#include "nsLookAndFeel.h"
|
||||
#include "nsStyleConsts.h"
|
||||
|
||||
#include <qglobal.h>
|
||||
|
||||
#undef NS_LOOKANDFEEL_DEBUG
|
||||
#ifdef NS_LOOKANDFEEL_DEBUG
|
||||
#include <QDebug>
|
||||
#endif
|
||||
|
||||
#define QCOLOR_TO_NS_RGB(c) \
|
||||
((nscolor)NS_RGB(c.red(),c.green(),c.blue()))
|
||||
#include "nsLookAndFeel.h"
|
||||
#include "nsStyleConsts.h"
|
||||
|
||||
nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
|
||||
#include <qglobal.h>
|
||||
|
||||
#define QCOLOR_TO_NS_RGB(c) \
|
||||
((nscolor)NS_RGB(c.red(),c.green(),c.blue()))
|
||||
|
||||
nsLookAndFeel::nsLookAndFeel()
|
||||
: nsXPLookAndFeel(),
|
||||
mDefaultFontCached(false), mButtonFontCached(false),
|
||||
mFieldFontCached(false), mMenuFontCached(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -259,8 +265,8 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
|
||||
aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Normal, QPalette::Text));
|
||||
break;
|
||||
|
||||
// from the CSS3 working draft (not yet finalized)
|
||||
// http://www.w3.org/tr/2000/wd-css3-userint-20000216.html#color
|
||||
// from the CSS3 working draft (not yet finalized)
|
||||
// http://www.w3.org/tr/2000/wd-css3-userint-20000216.html#color
|
||||
|
||||
case eColorID__moz_buttondefault:
|
||||
aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Normal, QPalette::Button));
|
||||
@ -307,36 +313,36 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
|
||||
|
||||
#ifdef NS_LOOKANDFEEL_DEBUG
|
||||
static const char *metricToString[] = {
|
||||
"eIntID_CaretBlinkTime",
|
||||
"eIntID_CaretWidth",
|
||||
"eIntID_ShowCaretDuringSelection",
|
||||
"eIntID_SelectTextfieldsOnKeyFocus",
|
||||
"eIntID_SubmenuDelay",
|
||||
"eIntID_MenusCanOverlapOSBar",
|
||||
"eIntID_SkipNavigatingDisabledMenuItem",
|
||||
"eIntID_DragThresholdX",
|
||||
"eIntID_DragThresholdY",
|
||||
"eIntID_UseAccessibilityTheme",
|
||||
"eIntID_ScrollArrowStyle",
|
||||
"eIntID_ScrollSliderStyle",
|
||||
"eIntID_ScrollButtonLeftMouseButtonAction",
|
||||
"eIntID_ScrollButtonMiddleMouseButtonAction",
|
||||
"eIntID_ScrollButtonRightMouseButtonAction",
|
||||
"eIntID_TreeOpenDelay",
|
||||
"eIntID_TreeCloseDelay",
|
||||
"eIntID_TreeLazyScrollDelay",
|
||||
"eIntID_TreeScrollDelay",
|
||||
"eIntID_TreeScrollLinesMax",
|
||||
"eIntID_TabFocusModel",
|
||||
"eIntID_WindowsDefaultTheme",
|
||||
"eIntID_AlertNotificationOrigin",
|
||||
"eIntID_ScrollToClick",
|
||||
"eIntID_IMERawInputUnderlineStyle",
|
||||
"eIntID_IMESelectedRawTextUnderlineStyle",
|
||||
"eIntID_IMEConvertedTextUnderlineStyle",
|
||||
"eIntID_IMESelectedConvertedTextUnderline",
|
||||
"eIntID_ImagesInMenus"
|
||||
};
|
||||
"eIntID_CaretBlinkTime",
|
||||
"eIntID_CaretWidth",
|
||||
"eIntID_ShowCaretDuringSelection",
|
||||
"eIntID_SelectTextfieldsOnKeyFocus",
|
||||
"eIntID_SubmenuDelay",
|
||||
"eIntID_MenusCanOverlapOSBar",
|
||||
"eIntID_SkipNavigatingDisabledMenuItem",
|
||||
"eIntID_DragThresholdX",
|
||||
"eIntID_DragThresholdY",
|
||||
"eIntID_UseAccessibilityTheme",
|
||||
"eIntID_ScrollArrowStyle",
|
||||
"eIntID_ScrollSliderStyle",
|
||||
"eIntID_ScrollButtonLeftMouseButtonAction",
|
||||
"eIntID_ScrollButtonMiddleMouseButtonAction",
|
||||
"eIntID_ScrollButtonRightMouseButtonAction",
|
||||
"eIntID_TreeOpenDelay",
|
||||
"eIntID_TreeCloseDelay",
|
||||
"eIntID_TreeLazyScrollDelay",
|
||||
"eIntID_TreeScrollDelay",
|
||||
"eIntID_TreeScrollLinesMax",
|
||||
"eIntID_TabFocusModel",
|
||||
"eIntID_WindowsDefaultTheme",
|
||||
"eIntID_AlertNotificationOrigin",
|
||||
"eIntID_ScrollToClick",
|
||||
"eIntID_IMERawInputUnderlineStyle",
|
||||
"eIntID_IMESelectedRawTextUnderlineStyle",
|
||||
"eIntID_IMEConvertedTextUnderlineStyle",
|
||||
"eIntID_IMESelectedConvertedTextUnderline",
|
||||
"eIntID_ImagesInMenus"
|
||||
};
|
||||
#endif
|
||||
|
||||
nsresult
|
||||
@ -348,7 +354,7 @@ nsLookAndFeel::GetIntImpl(IntID aID, PRInt32 &aResult)
|
||||
|
||||
nsresult res = nsXPLookAndFeel::GetIntImpl(aID, aResult);
|
||||
if (NS_SUCCEEDED(res))
|
||||
return res;
|
||||
return res;
|
||||
|
||||
res = NS_OK;
|
||||
|
||||
@ -425,7 +431,7 @@ nsLookAndFeel::GetIntImpl(IntID aID, PRInt32 &aResult)
|
||||
|
||||
#ifdef NS_LOOKANDFEEL_DEBUG
|
||||
static const char *floatMetricToString[] = {
|
||||
"eFloatID_IMEUnderlineRelativeSize"
|
||||
"eFloatID_IMEUnderlineRelativeSize"
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -438,7 +444,7 @@ nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
|
||||
|
||||
nsresult res = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
|
||||
if (NS_SUCCEEDED(res))
|
||||
return res;
|
||||
return res;
|
||||
res = NS_OK;
|
||||
|
||||
switch (aID) {
|
||||
@ -457,3 +463,99 @@ nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static void
|
||||
GetSystemFontInfo(const char *aClassName, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle)
|
||||
{
|
||||
QFont qFont = QApplication::font(aClassName);
|
||||
|
||||
NS_NAMED_LITERAL_STRING(quote, "\"");
|
||||
nsString family((PRUnichar*)qFont.family().data());
|
||||
*aFontName = quote + family + quote;
|
||||
|
||||
aFontStyle->systemFont = true;
|
||||
aFontStyle->style = FONT_STYLE_NORMAL;
|
||||
aFontStyle->weight = qFont.weight();
|
||||
// FIXME: Set aFontStyle->stretch correctly!
|
||||
aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
|
||||
// use pixel size directly if it is set, otherwise compute from point size
|
||||
if (qFont.pixelSize() != -1) {
|
||||
aFontStyle->size = qFont.pixelSize();
|
||||
} else {
|
||||
aFontStyle->size = qFont.pointSizeF() * 96.0f / 72.0f;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
void
|
||||
nsLookAndFeel::RefreshImpl()
|
||||
{
|
||||
nsXPLookAndFeel::RefreshImpl();
|
||||
mDefaultFontCached = false;
|
||||
mButtonFontCached = false;
|
||||
mFieldFontCached = false;
|
||||
mMenuFontCached = false;
|
||||
}
|
||||
|
@ -40,6 +40,7 @@
|
||||
#define __nsLookAndFeel
|
||||
|
||||
#include "nsXPLookAndFeel.h"
|
||||
#include "gfxFont.h"
|
||||
|
||||
class nsLookAndFeel: public nsXPLookAndFeel
|
||||
{
|
||||
@ -50,6 +51,23 @@ public:
|
||||
virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult);
|
||||
virtual nsresult GetIntImpl(IntID aID, PRInt32 &aResult);
|
||||
virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
|
||||
virtual bool GetFontImpl(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle);
|
||||
virtual void RefreshImpl();
|
||||
|
||||
private:
|
||||
bool mDefaultFontCached;
|
||||
bool mButtonFontCached;
|
||||
bool mFieldFontCached;
|
||||
bool mMenuFontCached;
|
||||
nsString mDefaultFontName;
|
||||
nsString mButtonFontName;
|
||||
nsString mFieldFontName;
|
||||
nsString mMenuFontName;
|
||||
gfxFontStyle mDefaultFontStyle;
|
||||
gfxFontStyle mButtonFontStyle;
|
||||
gfxFontStyle mFieldFontStyle;
|
||||
gfxFontStyle mMenuFontStyle;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -46,9 +46,11 @@
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsUXThemeData.h"
|
||||
#include "nsUXThemeConstants.h"
|
||||
#include "gfxFont.h"
|
||||
#include "WinUtils.h"
|
||||
|
||||
using namespace mozilla::widget;
|
||||
using mozilla::LookAndFeel;
|
||||
|
||||
typedef UINT (CALLBACK *SHAppBarMessagePtr)(DWORD, PAPPBARDATA);
|
||||
SHAppBarMessagePtr gSHAppBarMessage = NULL;
|
||||
@ -521,6 +523,143 @@ nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
|
||||
return res;
|
||||
}
|
||||
|
||||
static bool
|
||||
GetSysFontInfo(HDC aHDC, LookAndFeel::FontID anID,
|
||||
nsString &aFontName,
|
||||
gfxFontStyle &aFontStyle)
|
||||
{
|
||||
LOGFONTW* ptrLogFont = NULL;
|
||||
LOGFONTW logFont;
|
||||
NONCLIENTMETRICSW ncm;
|
||||
HGDIOBJ hGDI;
|
||||
PRUnichar name[LF_FACESIZE];
|
||||
|
||||
// Depending on which stock font we want, there are three different
|
||||
// places we might have to look it up.
|
||||
switch (anID) {
|
||||
case LookAndFeel::eFont_Icon:
|
||||
if (!::SystemParametersInfoW(SPI_GETICONTITLELOGFONT,
|
||||
sizeof(logFont), (PVOID)&logFont, 0))
|
||||
return false;
|
||||
|
||||
ptrLogFont = &logFont;
|
||||
break;
|
||||
|
||||
case LookAndFeel::eFont_Menu:
|
||||
case LookAndFeel::eFont_MessageBox:
|
||||
case LookAndFeel::eFont_SmallCaption:
|
||||
case LookAndFeel::eFont_StatusBar:
|
||||
case LookAndFeel::eFont_Tooltips:
|
||||
ncm.cbSize = sizeof(NONCLIENTMETRICSW);
|
||||
if (!::SystemParametersInfoW(SPI_GETNONCLIENTMETRICS,
|
||||
sizeof(ncm), (PVOID)&ncm, 0))
|
||||
return false;
|
||||
|
||||
switch (anID) {
|
||||
case LookAndFeel::eFont_Menu:
|
||||
ptrLogFont = &ncm.lfMenuFont;
|
||||
break;
|
||||
case LookAndFeel::eFont_MessageBox:
|
||||
ptrLogFont = &ncm.lfMessageFont;
|
||||
break;
|
||||
case LookAndFeel::eFont_SmallCaption:
|
||||
ptrLogFont = &ncm.lfSmCaptionFont;
|
||||
break;
|
||||
case LookAndFeel::eFont_StatusBar:
|
||||
case LookAndFeel::eFont_Tooltips:
|
||||
ptrLogFont = &ncm.lfStatusFont;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LookAndFeel::eFont_Widget:
|
||||
case LookAndFeel::eFont_Window: // css3
|
||||
case LookAndFeel::eFont_Document:
|
||||
case LookAndFeel::eFont_Workspace:
|
||||
case LookAndFeel::eFont_Desktop:
|
||||
case LookAndFeel::eFont_Info:
|
||||
case LookAndFeel::eFont_Dialog:
|
||||
case LookAndFeel::eFont_Button:
|
||||
case LookAndFeel::eFont_PullDownMenu:
|
||||
case LookAndFeel::eFont_List:
|
||||
case LookAndFeel::eFont_Field:
|
||||
case LookAndFeel::eFont_Caption:
|
||||
hGDI = ::GetStockObject(DEFAULT_GUI_FONT);
|
||||
if (!hGDI)
|
||||
return false;
|
||||
|
||||
if (::GetObjectW(hGDI, sizeof(logFont), &logFont) <= 0)
|
||||
return false;
|
||||
|
||||
ptrLogFont = &logFont;
|
||||
break;
|
||||
}
|
||||
|
||||
// FIXME?: mPixelScale is currently hardcoded to 1.
|
||||
float mPixelScale = 1.0f;
|
||||
|
||||
// The lfHeight is in pixels, and it needs to be adjusted for the
|
||||
// device it will be displayed on.
|
||||
// Screens and Printers will differ in DPI
|
||||
//
|
||||
// So this accounts for the difference in the DeviceContexts
|
||||
// The mPixelScale will be a "1" for the screen and could be
|
||||
// any value when going to a printer, for example mPixleScale is
|
||||
// 6.25 when going to a 600dpi printer.
|
||||
// round, but take into account whether it is negative
|
||||
float pixelHeight = -ptrLogFont->lfHeight;
|
||||
if (pixelHeight < 0) {
|
||||
HFONT hFont = ::CreateFontIndirectW(ptrLogFont);
|
||||
if (!hFont)
|
||||
return false;
|
||||
HGDIOBJ hObject = ::SelectObject(aHDC, hFont);
|
||||
TEXTMETRIC tm;
|
||||
::GetTextMetrics(aHDC, &tm);
|
||||
::SelectObject(aHDC, hObject);
|
||||
::DeleteObject(hFont);
|
||||
pixelHeight = tm.tmAscent;
|
||||
}
|
||||
pixelHeight *= mPixelScale;
|
||||
|
||||
// we have problem on Simplified Chinese system because the system
|
||||
// report the default font size is 8 points. but if we use 8, the text
|
||||
// display very ugly. force it to be at 9 points (12 pixels) on that
|
||||
// system (cp936), but leave other sizes alone.
|
||||
if (pixelHeight < 12 && ::GetACP() == 936)
|
||||
pixelHeight = 12;
|
||||
|
||||
aFontStyle.size = pixelHeight;
|
||||
|
||||
// FIXME: What about oblique?
|
||||
aFontStyle.style =
|
||||
(ptrLogFont->lfItalic) ? FONT_STYLE_ITALIC : FONT_STYLE_NORMAL;
|
||||
|
||||
// FIXME: Other weights?
|
||||
aFontStyle.weight =
|
||||
(ptrLogFont->lfWeight == FW_BOLD ? FONT_WEIGHT_BOLD : FONT_WEIGHT_NORMAL);
|
||||
|
||||
// FIXME: Set aFontStyle->stretch correctly!
|
||||
aFontStyle.stretch = NS_FONT_STRETCH_NORMAL;
|
||||
|
||||
aFontStyle.systemFont = true;
|
||||
|
||||
name[0] = 0;
|
||||
memcpy(name, ptrLogFont->lfFaceName, LF_FACESIZE*sizeof(PRUnichar));
|
||||
aFontName = name;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
nsLookAndFeel::GetFontImpl(FontID anID, nsString &aFontName,
|
||||
gfxFontStyle &aFontStyle)
|
||||
{
|
||||
HDC tdc = GetDC(NULL);
|
||||
bool status = GetSysFontInfo(tdc, anID, aFontName, aFontStyle);
|
||||
ReleaseDC(NULL, tdc);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* virtual */
|
||||
PRUnichar
|
||||
nsLookAndFeel::GetPasswordCharacterImpl()
|
||||
|
@ -61,6 +61,8 @@ public:
|
||||
virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult);
|
||||
virtual nsresult GetIntImpl(IntID aID, PRInt32 &aResult);
|
||||
virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
|
||||
virtual bool GetFontImpl(FontID aID, nsString& aFontName,
|
||||
gfxFontStyle& aFontStyle);
|
||||
virtual PRUnichar GetPasswordCharacterImpl();
|
||||
};
|
||||
|
||||
|
@ -739,6 +739,13 @@ LookAndFeel::GetFloat(FloatID aID, float* aResult)
|
||||
return nsLookAndFeel::GetInstance()->GetFloatImpl(aID, *aResult);
|
||||
}
|
||||
|
||||
// static
|
||||
bool
|
||||
LookAndFeel::GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle)
|
||||
{
|
||||
return nsLookAndFeel::GetInstance()->GetFontImpl(aID, aName, aStyle);
|
||||
}
|
||||
|
||||
// static
|
||||
PRUnichar
|
||||
LookAndFeel::GetPasswordCharacter()
|
||||
|
@ -88,6 +88,11 @@ public:
|
||||
virtual nsresult GetIntImpl(IntID aID, PRInt32 &aResult);
|
||||
virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
|
||||
|
||||
// This one is different: there are no override prefs (fixme?), so
|
||||
// there is no XP implementation, only per-system impls.
|
||||
virtual bool GetFontImpl(FontID aID, nsString& aName,
|
||||
gfxFontStyle& aStyle) = 0;
|
||||
|
||||
virtual void RefreshImpl();
|
||||
|
||||
virtual PRUnichar GetPasswordCharacterImpl()
|
||||
|
Loading…
Reference in New Issue
Block a user