Convert nsSystemFonts* from storing nsFont (with size in twips) to name and gfxFontStyle (with size in pixels) to avoid problems when t2p changes. b=333357 r=stuart

This commit is contained in:
dbaron%dbaron.org 2006-11-04 01:11:20 +00:00
Родитель e7f57bbca3
Коммит 3ca46df87a
9 изменённых файлов: 185 добавлений и 138 удалений

Просмотреть файл

@ -46,18 +46,24 @@
#include "nsUnitConversion.h"
#include "nsSystemFontsBeOS.h"
#define DEFAULT_TWIP_FONT_SIZE 240
#define DEFAULT_PIXEL_FONT_SIZE 16.0f
nsSystemFontsBeOS::nsSystemFontsBeOS(float aPixelsToTwips)
: mDefaultFont("sans-serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL, NS_FONT_DECORATION_NONE,
DEFAULT_TWIP_FONT_SIZE),
mMenuFont("sans-serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL, NS_FONT_DECORATION_NONE,
DEFAULT_TWIP_FONT_SIZE),
mCaptionFont("sans-serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL, NS_FONT_DECORATION_NONE,
DEFAULT_TWIP_FONT_SIZE)
nsSystemFontsBeOS::nsSystemFontsBeOS()
: mDefaultFontName(NS_LITERAL_STRING("sans-serif"))
, mMenuFontName(NS_LITERAL_STRING("sans-serif"))
, mCaptionFontName(NS_LITERAL_STRING("sans-serif"))
, mDefaultFontStyle(FONT_STYLE_NORMAL, FONT_VARIANT_NORMAL,
FONT_WEIGHT_NORMAL, FONT_DECORATION_NONE,
DEFAULT_PIXEL_FONT_SIZE, NS_LITERAL_CSTRING(""),
0.0f, PR_TRUE, PR_FALSE)
, mMenuFontStyle(FONT_STYLE_NORMAL, FONT_VARIANT_NORMAL,
FONT_WEIGHT_NORMAL, FONT_DECORATION_NONE,
DEFAULT_PIXEL_FONT_SIZE, NS_LITERAL_CSTRING(""),
0.0f, PR_TRUE, PR_FALSE)
, mCaptionFontStyle(FONT_STYLE_NORMAL, FONT_VARIANT_NORMAL,
FONT_WEIGHT_NORMAL, FONT_DECORATION_NONE,
DEFAULT_PIXEL_FONT_SIZE, NS_LITERAL_CSTRING(""),
0.0f, PR_TRUE, PR_FALSE)
{
menu_info info;
get_menu_info(&info);
@ -65,21 +71,24 @@ nsSystemFontsBeOS::nsSystemFontsBeOS(float aPixelsToTwips)
menuFont.SetFamilyAndStyle(info.f_family, info.f_style);
menuFont.SetSize(info.font_size);
GetSystemFontInfo(be_plain_font, &mDefaultFont, aPixelsToTwips);
GetSystemFontInfo(be_bold_font, &mCaptionFont, aPixelsToTwips);
GetSystemFontInfo(&menuFont, &mMenuFont, aPixelsToTwips);
GetSystemFontInfo(be_plain_font, &mDefaultFontName, &mDefaultFontStyle);
GetSystemFontInfo(be_bold_font, &mCaptionFontName, &mCaptionFontStyle);
GetSystemFontInfo(&menuFont, &mMenuFontName, &mMenuFontStyle);
}
nsresult nsSystemFontsBeOS::GetSystemFont(nsSystemFontID aID,
nsFont* aFont) const
nsString *aFontName,
gfxFontStyle *aFontStyle) const
{
switch (aID) {
case eSystemFont_PullDownMenu:
case eSystemFont_Menu:
*aFont = mMenuFont;
*aFontName = mMenuFontName;
*aFontStyle = mMenuFontStyle;
return NS_OK;
case eSystemFont_Caption: // css2 bold
*aFont = mCaptionFont;
*aFontName = mCaptionFontName;
*aFontStyle = mCaptionFontStyle;
return NS_OK;
case eSystemFont_List:
case eSystemFont_Field:
@ -97,41 +106,42 @@ nsresult nsSystemFontsBeOS::GetSystemFont(nsSystemFontID aID,
case eSystemFont_Tooltips: // moz
case eSystemFont_Widget:
default:
*aFont = mDefaultFont;
*aFontName = mDefaultFontName;
*aFontStyle = mDefaultFontStyle;
return NS_OK;
}
NS_NOTREACHED("huh?");
}
nsresult
nsSystemFontsBeOS::GetSystemFontInfo(const BFont *theFont, nsFont* aFont,
float aPixelsToTwips) const
nsSystemFontsBeOS::GetSystemFontInfo(const BFont *theFont, nsString *aFontName,
gfxFontStyle *aFontStyle) const
{
aFont->style = NS_FONT_STYLE_NORMAL;
aFont->weight = NS_FONT_WEIGHT_NORMAL;
aFont->decorations = NS_FONT_DECORATION_NONE;
aFontStyle->style = FONT_STYLE_NORMAL;
aFontStyle->weight = FONT_WEIGHT_NORMAL;
aFontStyle->decorations = FONT_DECORATION_NONE;
font_family family;
theFont->GetFamilyAndStyle(&family, NULL);
uint16 face = theFont->Face();
CopyUTF8toUTF16(family, aFont->name);
aFont->size = NSIntPixelsToTwips(uint32(theFont->Size()), aPixelsToTwips);
CopyUTF8toUTF16(family, *aFontName);
aFontStyle->size = theFont->Size();
if (face & B_ITALIC_FACE)
aFont->style = NS_FONT_STYLE_ITALIC;
aFontStyle->style = FONT_STYLE_ITALIC;
if (face & B_BOLD_FACE)
aFont->weight = NS_FONT_WEIGHT_BOLD;
aFontStyle->weight = FONT_WEIGHT_BOLD;
if (face & B_UNDERSCORE_FACE)
aFont->decorations |= NS_FONT_DECORATION_UNDERLINE;
aFontStyle->decorations |= FONT_DECORATION_UNDERLINE;
if (face & B_STRIKEOUT_FACE)
aFont->decorations |= NS_FONT_DECORATION_LINE_THROUGH;
aFontStyle->decorations |= FONT_DECORATION_STRIKEOUT;
aFont->systemFont = PR_TRUE;
aFontStyle->systemFont = PR_TRUE;
return NS_OK;
}

Просмотреть файл

@ -37,20 +37,21 @@
#ifndef _NS_SYSTEMFONTSBEOS_H_
#define _NS_SYSTEMFONTSBEOS_H_
#include <nsFont.h>
#include <gfxFont.h>
class BFont;
class nsSystemFontsBeOS
{
public:
nsSystemFontsBeOS(float aPixelsToTwips);
nsSystemFontsBeOS();
nsresult GetSystemFont(nsSystemFontID aID, nsFont* aFont) const;
nsresult GetSystemFont(nsSystemFontID anID, nsString *aFontName,
gfxFontStyle *aFontStyle) const;
private:
nsresult GetSystemFontInfo(const BFont *theFont, nsFont* aFont,
float aPixelsToTwips) const;
nsresult GetSystemFontInfo(const BFont *theFont, nsString *aFontName,
gfxFontStyle *aFontStyle) const;
/*
* The following system font constants exist:
@ -68,9 +69,8 @@ private:
* // moz
* eSystemFont_Tooltips, eSystemFont_Widget
*/
nsFont mDefaultFont;
nsFont mMenuFont;
nsFont mCaptionFont;
nsString mDefaultFontName, mMenuFontName, mCaptionFontName;
gfxFontStyle mDefaultFontStyle, mMenuFontStyle, mCaptionFontStyle;
};
#endif /* _NS_SYSTEMFONTSBEOS_H_ */

Просмотреть файл

@ -90,21 +90,29 @@ MOZ_pango_font_description_get_size_is_absolute(PangoFontDescription *desc)
return PR_FALSE;
}
#define DEFAULT_TWIP_FONT_SIZE 240
#define DEFAULT_PIXEL_FONT_SIZE 16.0f
nsSystemFontsGTK2::nsSystemFontsGTK2(float aPixelsToTwips)
: mDefaultFont("sans-serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL, NS_FONT_DECORATION_NONE,
DEFAULT_TWIP_FONT_SIZE),
mButtonFont("sans-serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL, NS_FONT_DECORATION_NONE,
DEFAULT_TWIP_FONT_SIZE),
mFieldFont("sans-serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL, NS_FONT_DECORATION_NONE,
DEFAULT_TWIP_FONT_SIZE),
mMenuFont("sans-serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL, NS_FONT_DECORATION_NONE,
DEFAULT_TWIP_FONT_SIZE)
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"))
, mDefaultFontStyle(FONT_STYLE_NORMAL, FONT_VARIANT_NORMAL,
FONT_WEIGHT_NORMAL, FONT_DECORATION_NONE,
DEFAULT_PIXEL_FONT_SIZE, NS_LITERAL_CSTRING(""),
0.0f, PR_TRUE, PR_FALSE)
, mButtonFontStyle(FONT_STYLE_NORMAL, FONT_VARIANT_NORMAL,
FONT_WEIGHT_NORMAL, FONT_DECORATION_NONE,
DEFAULT_PIXEL_FONT_SIZE, NS_LITERAL_CSTRING(""),
0.0f, PR_TRUE, PR_FALSE)
, mFieldFontStyle(FONT_STYLE_NORMAL, FONT_VARIANT_NORMAL,
FONT_WEIGHT_NORMAL, FONT_DECORATION_NONE,
DEFAULT_PIXEL_FONT_SIZE, NS_LITERAL_CSTRING(""),
0.0f, PR_TRUE, PR_FALSE)
, mMenuFontStyle(FONT_STYLE_NORMAL, FONT_VARIANT_NORMAL,
FONT_WEIGHT_NORMAL, FONT_DECORATION_NONE,
DEFAULT_PIXEL_FONT_SIZE, NS_LITERAL_CSTRING(""),
0.0f, PR_TRUE, PR_FALSE)
{
InitPangoLib();
@ -123,7 +131,7 @@ nsSystemFontsGTK2::nsSystemFontsGTK2(float aPixelsToTwips)
gtk_widget_ensure_style(label);
GetSystemFontInfo(label, &mDefaultFont, aPixelsToTwips);
GetSystemFontInfo(label, &mDefaultFontName, &mDefaultFontStyle);
gtk_widget_destroy(window); // no unref, windows are different
@ -136,7 +144,7 @@ nsSystemFontsGTK2::nsSystemFontsGTK2(float aPixelsToTwips)
gtk_container_add(GTK_CONTAINER(window), parent);
gtk_widget_ensure_style(entry);
GetSystemFontInfo(entry, &mFieldFont, aPixelsToTwips);
GetSystemFontInfo(entry, &mFieldFontName, &mFieldFontStyle);
gtk_widget_destroy(window); // no unref, windows are different
@ -152,7 +160,7 @@ nsSystemFontsGTK2::nsSystemFontsGTK2(float aPixelsToTwips)
gtk_widget_ensure_style(accel_label);
GetSystemFontInfo(accel_label, &mMenuFont, aPixelsToTwips);
GetSystemFontInfo(accel_label, &mMenuFontName, &mMenuFontStyle);
gtk_widget_unref(menu);
@ -168,19 +176,19 @@ nsSystemFontsGTK2::nsSystemFontsGTK2(float aPixelsToTwips)
gtk_widget_ensure_style(label);
GetSystemFontInfo(label, &mButtonFont, aPixelsToTwips);
GetSystemFontInfo(label, &mButtonFontName, &mButtonFontStyle);
gtk_widget_destroy(window); // no unref, windows are different
}
nsresult
nsSystemFontsGTK2::GetSystemFontInfo(GtkWidget *aWidget, nsFont* aFont,
float aPixelsToTwips) const
nsSystemFontsGTK2::GetSystemFontInfo(GtkWidget *aWidget, nsString *aFontName,
gfxFontStyle *aFontStyle) const
{
GtkSettings *settings = gtk_widget_get_settings(aWidget);
aFont->style = NS_FONT_STYLE_NORMAL;
aFont->decorations = NS_FONT_DECORATION_NONE;
aFontStyle->style = FONT_STYLE_NORMAL;
aFontStyle->decorations = FONT_DECORATION_NONE;
gchar *fontname;
g_object_get(settings, "gtk-font-name", &fontname, NULL);
@ -188,15 +196,15 @@ nsSystemFontsGTK2::GetSystemFontInfo(GtkWidget *aWidget, nsFont* aFont,
PangoFontDescription *desc;
desc = pango_font_description_from_string(fontname);
aFont->systemFont = PR_TRUE;
aFontStyle->systemFont = PR_TRUE;
g_free(fontname);
NS_NAMED_LITERAL_STRING(quote, "\"");
NS_ConvertUTF8toUTF16 family(pango_font_description_get_family(desc));
aFont->name = quote + family + quote;
*aFontName = quote + family + quote;
aFont->weight = pango_font_description_get_weight(desc);
aFontStyle->weight = pango_font_description_get_weight(desc);
float size = float(pango_font_description_get_size(desc) / PANGO_SCALE);
@ -209,7 +217,7 @@ nsSystemFontsGTK2::GetSystemFontInfo(GtkWidget *aWidget, nsFont* aFont,
// |size| is now pixels
aFont->size = NSToCoordRound(size * aPixelsToTwips);
aFontStyle->size = size;
pango_font_description_free(desc);
@ -217,21 +225,25 @@ nsSystemFontsGTK2::GetSystemFontInfo(GtkWidget *aWidget, nsFont* aFont,
}
nsresult
nsSystemFontsGTK2::GetSystemFont(nsSystemFontID anID, nsFont *aFont) const
nsSystemFontsGTK2::GetSystemFont(nsSystemFontID anID, nsString *aFontName,
gfxFontStyle *aFontStyle) const
{
switch (anID) {
case eSystemFont_Menu: // css2
case eSystemFont_PullDownMenu: // css3
*aFont = mMenuFont;
*aFontName = mMenuFontName;
*aFontStyle = mMenuFontStyle;
break;
case eSystemFont_Field: // css3
case eSystemFont_List: // css3
*aFont = mFieldFont;
*aFontName = mFieldFontName;
*aFontStyle = mFieldFontStyle;
break;
case eSystemFont_Button: // css3
*aFont = mButtonFont;
*aFontName = mButtonFontName;
*aFontStyle = mButtonFontStyle;
break;
case eSystemFont_Caption: // css2
@ -247,7 +259,8 @@ nsSystemFontsGTK2::GetSystemFont(nsSystemFontID anID, nsFont *aFont) const
case eSystemFont_Dialog: // css3
case eSystemFont_Tooltips: // moz
case eSystemFont_Widget: // moz
*aFont = mDefaultFont;
*aFontName = mDefaultFontName;
*aFontStyle = mDefaultFontStyle;
break;
}

Просмотреть файл

@ -39,23 +39,20 @@
#ifndef _NS_SYSTEMFONTSGTK2_H_
#define _NS_SYSTEMFONTSGTK2_H_
#include <nsFont.h>
#include <gfxFont.h>
class nsSystemFontsGTK2
{
public:
nsSystemFontsGTK2(float aPixelsToTwips);
nsSystemFontsGTK2();
nsresult GetSystemFont(nsSystemFontID anID, nsFont *aFont) const;
const nsFont& GetDefaultFont() { return mDefaultFont; }
const nsFont& GetMenuFont() { return mMenuFont; }
const nsFont& GetFieldFont() { return mFieldFont; }
const nsFont& GetButtonFont() { return mButtonFont; }
nsresult GetSystemFont(nsSystemFontID anID, nsString *aFontName,
gfxFontStyle *aFontStyle) const;
private:
nsresult GetSystemFontInfo(GtkWidget *aWidget, nsFont* aFont,
float aPixelsToTwips) const;
nsresult GetSystemFontInfo(GtkWidget *aWidget, nsString *aFontName,
gfxFontStyle *aFontStyle) const;
/*
* The following system font constants exist:
@ -73,10 +70,8 @@ private:
* // moz
* eSystemFont_Tooltips, eSystemFont_Widget
*/
nsFont mDefaultFont;
nsFont mButtonFont;
nsFont mFieldFont;
nsFont mMenuFont;
nsString mDefaultFontName, mButtonFontName, mFieldFontName, mMenuFontName;
gfxFontStyle mDefaultFontStyle, mButtonFontStyle, mFieldFontStyle, mMenuFontStyle;
};
#endif /* _NS_SYSTEMFONTSGTK2_H_ */

Просмотреть файл

@ -39,8 +39,7 @@
#include "nsSystemFontsMac.h"
nsSystemFontsMac::nsSystemFontsMac(float aPixelsToTwips)
: mPixelsToTwips(aPixelsToTwips)
nsSystemFontsMac::nsSystemFontsMac()
{
}
@ -106,7 +105,8 @@ GetSystemFontForScript(ThemeFontID aFontID, ScriptCode aScriptCode,
}
nsresult
nsSystemFontsMac::GetSystemFont(nsSystemFontID aID, nsFont *aFont) const
nsSystemFontsMac::GetSystemFont(nsSystemFontID aID, nsString *aFontName,
gfxFontStyle *aFontStyle) const
{
nsresult rv;
@ -114,13 +114,13 @@ nsSystemFontsMac::GetSystemFont(nsSystemFontID aID, nsFont *aFont) const
if (aID == eSystemFont_Window ||
aID == eSystemFont_Document)
{
aFont->style = NS_FONT_STYLE_NORMAL;
aFont->weight = NS_FONT_WEIGHT_NORMAL;
aFont->decorations = NS_FONT_DECORATION_NONE;
aFontStyle->style = FONT_STYLE_NORMAL;
aFontStyle->weight = FONT_WEIGHT_NORMAL;
aFontStyle->decorations = FONT_DECORATION_NONE;
aFont->name.AssignLiteral("sans-serif");
aFont->size = NSToCoordRound(aFont->size * 0.875f);
aFont->systemFont = PR_TRUE;
aFontName->AssignLiteral("sans-serif");
aFontStyle->size = 14;
aFontStyle->systemFont = PR_TRUE;
return NS_OK;
}
@ -176,17 +176,17 @@ nsSystemFontsMac::GetSystemFont(nsSystemFontID aID, nsFont *aFont) const
}
}
aFont->name = fontName;
aFont->size = NSToCoordRound(float(fontSize) * mPixelsToTwips);
*aFontName = fontName;
aFontStyle->size = gfxFloat(fontSize);
if (fontStyle & bold)
aFont->weight = NS_FONT_WEIGHT_BOLD;
aFontStyle->weight = FONT_WEIGHT_BOLD;
if (fontStyle & italic)
aFont->style = NS_FONT_STYLE_ITALIC;
aFontStyle->style = FONT_STYLE_ITALIC;
if (fontStyle & underline)
aFont->decorations = NS_FONT_DECORATION_UNDERLINE;
aFontStyle->decorations = FONT_DECORATION_UNDERLINE;
aFont->systemFont = PR_TRUE;
aFontStyle->systemFont = PR_TRUE;
return NS_OK;
}

Просмотреть файл

@ -38,17 +38,15 @@
#ifndef _NS_SYSTEMFONTSMAC_H_
#define _NS_SYSTEMFONTSMAC_H_
#include <nsFont.h>
#include <gfxFont.h>
#include <nsIDeviceContext.h>
class nsSystemFontsMac
{
public:
nsSystemFontsMac(float aPixelsToTwips);
nsresult GetSystemFont(nsSystemFontID anID, nsFont *aFont) const;
protected:
float mPixelsToTwips;
nsSystemFontsMac();
nsresult GetSystemFont(nsSystemFontID anID, nsString *aFontName,
gfxFontStyle *aFontStyle) const;
};
#endif /* _NS_SYSTEMFONTSMAC_H_ */

Просмотреть файл

@ -44,7 +44,9 @@
nsresult nsSystemFontsWin::CopyLogFontToNSFont(HDC* aHDC, const LOGFONT* ptrLogFont,
nsFont* aFont, PRBool aIsWide) const
nsString *aFontName,
gfxFontStyle *aFontStyle,
PRBool aIsWide) const
{
PRUnichar name[LF_FACESIZE];
name[0] = 0;
@ -54,31 +56,31 @@ nsresult nsSystemFontsWin::CopyLogFontToNSFont(HDC* aHDC, const LOGFONT* ptrLogF
MultiByteToWideChar(CP_ACP, 0, ptrLogFont->lfFaceName,
strlen(ptrLogFont->lfFaceName) + 1, name, sizeof(name)/sizeof(name[0]));
}
aFont->name = name;
*aFontName = name;
// Do Style
aFont->style = NS_FONT_STYLE_NORMAL;
aFontStyle->style = FONT_STYLE_NORMAL;
if (ptrLogFont->lfItalic)
{
aFont->style = NS_FONT_STYLE_ITALIC;
aFontStyle->style = FONT_STYLE_ITALIC;
}
// XXX What about oblique?
aFont->variant = NS_FONT_VARIANT_NORMAL;
aFontStyle->variant = FONT_VARIANT_NORMAL;
// Do Weight
aFont->weight = (ptrLogFont->lfWeight == FW_BOLD ?
NS_FONT_WEIGHT_BOLD : NS_FONT_WEIGHT_NORMAL);
aFontStyle->weight = (ptrLogFont->lfWeight == FW_BOLD ?
FONT_WEIGHT_BOLD : FONT_WEIGHT_NORMAL);
// Do decorations
aFont->decorations = NS_FONT_DECORATION_NONE;
aFontStyle->decorations = FONT_DECORATION_NONE;
if (ptrLogFont->lfUnderline)
{
aFont->decorations |= NS_FONT_DECORATION_UNDERLINE;
aFontStyle->decorations |= FONT_DECORATION_UNDERLINE;
}
if (ptrLogFont->lfStrikeOut)
{
aFont->decorations |= NS_FONT_DECORATION_LINE_THROUGH;
aFontStyle->decorations |= FONT_DECORATION_STRIKEOUT;
}
@ -108,20 +110,23 @@ nsresult nsSystemFontsWin::CopyLogFontToNSFont(HDC* aHDC, const LOGFONT* ptrLogF
pixelHeight = tm.tmAscent;
}
float pointSize = pixelHeight * mPixelScale * 72 / ::GetDeviceCaps(*aHDC, LOGPIXELSY);
pixelHeight *= mPixelScale;
// we have problem on Simplified Chinese system because the system report
// the default font size is 8. but if we use 8, the text display very
// Ugly. force it to be at 9 on that system (cp936), but leave other sizes alone.
if ((pointSize < 9) &&
// 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()))
pointSize = 9;
pixelHeight = 12;
aFont->size = NSFloatPointsToTwips(pointSize);
aFontStyle->size = pixelHeight;
return NS_OK;
}
nsresult nsSystemFontsWin::GetSysFontInfo(HDC aHDC, nsSystemFontID anID, nsFont* aFont) const
nsresult nsSystemFontsWin::GetSysFontInfo(HDC aHDC, nsSystemFontID anID,
nsString *aFontName,
gfxFontStyle *aFontStyle) const
{
HGDIOBJ hGDI;
@ -220,12 +225,14 @@ nsresult nsSystemFontsWin::GetSysFontInfo(HDC aHDC, nsSystemFontID anID, nsFont*
return NS_ERROR_FAILURE;
}
aFont->systemFont = PR_TRUE;
aFontStyle->systemFont = PR_TRUE;
return CopyLogFontToNSFont(&aHDC, ptrLogFont, aFont);
return CopyLogFontToNSFont(&aHDC, ptrLogFont, aFontName, aFontStyle);
}
nsresult nsSystemFontsWin::GetSystemFont(nsSystemFontID anID, nsFont *aFont) const
nsresult nsSystemFontsWin::GetSystemFont(nsSystemFontID anID,
nsString *aFontName,
gfxFontStyle *aFontStyle) const
{
nsresult status = NS_OK;
@ -253,7 +260,7 @@ nsresult nsSystemFontsWin::GetSystemFont(nsSystemFontID anID, nsFont *aFont) con
HWND hwnd = nsnull;
HDC tdc = GetDC(hwnd);
status = GetSysFontInfo(tdc, anID, aFont);
status = GetSysFontInfo(tdc, anID, aFontName, aFontStyle);
ReleaseDC(hwnd, tdc);
@ -264,7 +271,7 @@ nsresult nsSystemFontsWin::GetSystemFont(nsSystemFontID anID, nsFont *aFont) con
return status;
}
nsSystemFontsWin::nsSystemFontsWin(float aPixelsToTwips)
nsSystemFontsWin::nsSystemFontsWin()
{
}

Просмотреть файл

@ -39,18 +39,23 @@
#ifndef _NS_SYSTEMFONTSWIN_H_
#define _NS_SYSTEMFONTSWIN_H_
#include "nsFont.h"
#include "gfxFont.h"
#include "nsIDeviceContext.h"
class nsSystemFontsWin
{
public:
nsSystemFontsWin(float aPixelsToTwips);
nsSystemFontsWin();
nsresult GetSystemFont(nsSystemFontID anID, nsString *aFontName,
gfxFontStyle *aFontStyle) const;
private:
nsresult CopyLogFontToNSFont(HDC* aHDC, const LOGFONT* ptrLogFont,
nsFont* aFont, PRBool aIsWide = PR_FALSE) const;
nsresult GetSysFontInfo(HDC aHDC, nsSystemFontID anID, nsFont* aFont) const;
nsresult GetSystemFont(nsSystemFontID anID, nsFont *aFont) const;
nsString *aFontName, gfxFontStyle *aFontStyle,
PRBool aIsWide = PR_FALSE) const;
nsresult GetSysFontInfo(HDC aHDC, nsSystemFontID anID,
nsString *aFontName,
gfxFontStyle *aFontStyle) const;
};
#endif /* _NS_SYSTEMFONTSWIN_H_ */

Просмотреть файл

@ -135,7 +135,7 @@ nsresult
nsThebesDeviceContext::SetDPI(PRInt32 aPrefDPI)
{
PRInt32 OSVal;
PRBool do_round = PR_TRUE;
PRBool do_round = PR_TRUE; // XXX bogus -- only caller for which it's false is a round number
PRInt32 dpi = 96;
@ -383,19 +383,38 @@ nsThebesDeviceContext::GetSystemFont(nsSystemFontID aID, nsFont *aFont) const
{
if (!gSystemFonts) {
#ifdef MOZ_ENABLE_GTK2
gSystemFonts = new nsSystemFontsGTK2(mPixelsToTwips);
gSystemFonts = new nsSystemFontsGTK2();
#elif XP_WIN
gSystemFonts = new nsSystemFontsWin(mPixelsToTwips);
gSystemFonts = new nsSystemFontsWin();
#elif defined(XP_BEOS)
gSystemFonts = new nsSystemFontsBeOS(mPixelsToTwips);
gSystemFonts = new nsSystemFontsBeOS();
#elif XP_MACOSX
gSystemFonts = new nsSystemFontsMac(mPixelsToTwips);
gSystemFonts = new nsSystemFontsMac();
#else
#error Need to know how to create gSystemFonts, fix me!
#endif
}
return gSystemFonts->GetSystemFont(aID, aFont);
nsString fontName;
gfxFontStyle fontStyle(NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
FONT_WEIGHT_NORMAL, FONT_DECORATION_NONE,
16.0f, NS_LITERAL_CSTRING(""), 0.0f, PR_TRUE,
PR_FALSE);
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 = fontStyle.variant;
aFont->familyNameQuirks = fontStyle.familyNameQuirks;
aFont->weight = fontStyle.weight;
aFont->decorations = fontStyle.decorations;
aFont->size = NSToCoordRound(fontStyle.size * mPixelsToTwips);
//aFont->langGroup = fontStyle.langGroup;
aFont->sizeAdjust = fontStyle.sizeAdjust;
return rv;
}
NS_IMETHODIMP