зеркало из https://github.com/mozilla/gecko-dev.git
Bug 422774 - reduce narrow Windows API calls in gfx, original patch by Brad Lassey <blassey@mozilla.com>, r=pavlov
This commit is contained in:
Родитель
e647dbc547
Коммит
abfb506004
|
@ -43,19 +43,13 @@
|
|||
#include "nsSystemFontsWin.h"
|
||||
|
||||
|
||||
nsresult nsSystemFontsWin::CopyLogFontToNSFont(HDC* aHDC, const LOGFONT* ptrLogFont,
|
||||
nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle,
|
||||
PRBool aIsWide) const
|
||||
nsresult nsSystemFontsWin::CopyLogFontToNSFont(HDC* aHDC, const LOGFONTW* ptrLogFont,
|
||||
nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const
|
||||
{
|
||||
PRUnichar name[LF_FACESIZE];
|
||||
name[0] = 0;
|
||||
if (aIsWide)
|
||||
memcpy(name, ptrLogFont->lfFaceName, LF_FACESIZE*2);
|
||||
else {
|
||||
MultiByteToWideChar(CP_ACP, 0, ptrLogFont->lfFaceName,
|
||||
strlen(ptrLogFont->lfFaceName) + 1, name, sizeof(name)/sizeof(name[0]));
|
||||
}
|
||||
memcpy(name, ptrLogFont->lfFaceName, LF_FACESIZE*sizeof(PRUnichar));
|
||||
*aFontName = name;
|
||||
|
||||
// Do Style
|
||||
|
@ -85,7 +79,7 @@ nsresult nsSystemFontsWin::CopyLogFontToNSFont(HDC* aHDC, const LOGFONT* ptrLogF
|
|||
// round, but take into account whether it is negative
|
||||
float pixelHeight = -ptrLogFont->lfHeight;
|
||||
if (pixelHeight < 0) {
|
||||
HFONT hFont = ::CreateFontIndirect(ptrLogFont);
|
||||
HFONT hFont = ::CreateFontIndirectW(ptrLogFont);
|
||||
if (!hFont)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
HGDIOBJ hObject = ::SelectObject(*aHDC, hFont);
|
||||
|
@ -116,32 +110,32 @@ nsresult nsSystemFontsWin::GetSysFontInfo(HDC aHDC, nsSystemFontID anID,
|
|||
{
|
||||
HGDIOBJ hGDI;
|
||||
|
||||
LOGFONT logFont;
|
||||
LOGFONT* ptrLogFont = NULL;
|
||||
LOGFONTW logFont;
|
||||
LOGFONTW* ptrLogFont = NULL;
|
||||
|
||||
#ifdef WINCE
|
||||
hGDI = ::GetStockObject(SYSTEM_FONT);
|
||||
if (hGDI == NULL)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
if (::GetObject(hGDI, sizeof(logFont), &logFont) > 0)
|
||||
if (::GetObjectW(hGDI, sizeof(logFont), &logFont) > 0)
|
||||
ptrLogFont = &logFont;
|
||||
#else
|
||||
|
||||
NONCLIENTMETRICS ncm;
|
||||
NONCLIENTMETRICSW ncm;
|
||||
|
||||
BOOL status;
|
||||
if (anID == eSystemFont_Icon)
|
||||
{
|
||||
status = ::SystemParametersInfo(SPI_GETICONTITLELOGFONT,
|
||||
sizeof(logFont),
|
||||
(PVOID)&logFont,
|
||||
0);
|
||||
status = ::SystemParametersInfoW(SPI_GETICONTITLELOGFONT,
|
||||
sizeof(logFont),
|
||||
(PVOID)&logFont,
|
||||
0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncm.cbSize = sizeof(NONCLIENTMETRICS);
|
||||
status = ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
|
||||
ncm.cbSize = sizeof(NONCLIENTMETRICSW);
|
||||
status = ::SystemParametersInfoW(SPI_GETNONCLIENTMETRICS,
|
||||
sizeof(ncm),
|
||||
(PVOID)&ncm,
|
||||
0);
|
||||
|
@ -196,7 +190,7 @@ nsresult nsSystemFontsWin::GetSysFontInfo(HDC aHDC, nsSystemFontID anID,
|
|||
hGDI = ::GetStockObject(DEFAULT_GUI_FONT);
|
||||
if (hGDI != NULL)
|
||||
{
|
||||
if (::GetObject(hGDI, sizeof(logFont), &logFont) > 0)
|
||||
if (::GetObjectW(hGDI, sizeof(logFont), &logFont) > 0)
|
||||
{
|
||||
ptrLogFont = &logFont;
|
||||
}
|
||||
|
|
|
@ -50,9 +50,8 @@ public:
|
|||
nsresult GetSystemFont(nsSystemFontID anID, nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const;
|
||||
private:
|
||||
nsresult CopyLogFontToNSFont(HDC* aHDC, const LOGFONT* ptrLogFont,
|
||||
nsString *aFontName, gfxFontStyle *aFontStyle,
|
||||
PRBool aIsWide = PR_FALSE) const;
|
||||
nsresult CopyLogFontToNSFont(HDC* aHDC, const LOGFONTW* ptrLogFont,
|
||||
nsString *aFontName, gfxFontStyle *aFontStyle) const;
|
||||
nsresult GetSysFontInfo(HDC aHDC, nsSystemFontID anID,
|
||||
nsString *aFontName,
|
||||
gfxFontStyle *aFontStyle) const;
|
||||
|
|
|
@ -642,7 +642,7 @@ gfxWindowsFont::ComputeMetrics()
|
|||
|
||||
// Cache the width of a single space.
|
||||
SIZE size;
|
||||
GetTextExtentPoint32(dc, " ", 1, &size);
|
||||
GetTextExtentPoint32W(dc, L" ", 1, &size);
|
||||
mMetrics->spaceWidth = ROUND(size.cx);
|
||||
|
||||
// Cache the width of digit zero.
|
||||
|
@ -657,7 +657,7 @@ gfxWindowsFont::ComputeMetrics()
|
|||
mSpaceGlyph = 0;
|
||||
if (metrics.tmPitchAndFamily & TMPF_TRUETYPE) {
|
||||
WORD glyph;
|
||||
DWORD ret = GetGlyphIndicesA(dc, " ", 1, &glyph,
|
||||
DWORD ret = GetGlyphIndicesW(dc, L" ", 1, &glyph,
|
||||
GGI_MARK_NONEXISTING_GLYPHS);
|
||||
if (ret != GDI_ERROR && glyph != 0xFFFF) {
|
||||
mSpaceGlyph = glyph;
|
||||
|
|
|
@ -168,54 +168,26 @@ gfxWindowsSurface::OptimizeToDDB(HDC dc, const gfxIntSize& size, gfxImageFormat
|
|||
return raw;
|
||||
}
|
||||
|
||||
static char*
|
||||
GetACPString(const nsAString& aStr)
|
||||
{
|
||||
int acplen = aStr.Length() * 2 + 1;
|
||||
char * acp = new char[acplen];
|
||||
if(acp) {
|
||||
int outlen = ::WideCharToMultiByte(CP_ACP, 0,
|
||||
PromiseFlatString(aStr).get(),
|
||||
aStr.Length(),
|
||||
acp, acplen, NULL, NULL);
|
||||
if (outlen > 0)
|
||||
acp[outlen] = '\0'; // null terminate
|
||||
}
|
||||
return acp;
|
||||
}
|
||||
|
||||
nsresult gfxWindowsSurface::BeginPrinting(const nsAString& aTitle,
|
||||
const nsAString& aPrintToFileName)
|
||||
{
|
||||
#define DOC_TITLE_LENGTH 30
|
||||
DOCINFO docinfo;
|
||||
DOCINFOW docinfo;
|
||||
|
||||
nsString titleStr;
|
||||
titleStr = aTitle;
|
||||
nsString titleStr(aTitle);
|
||||
if (titleStr.Length() > DOC_TITLE_LENGTH) {
|
||||
titleStr.SetLength(DOC_TITLE_LENGTH-3);
|
||||
titleStr.AppendLiteral("...");
|
||||
}
|
||||
char *title = GetACPString(titleStr);
|
||||
|
||||
char *docName = nsnull;
|
||||
if (!aPrintToFileName.IsEmpty()) {
|
||||
docName = ToNewCString(aPrintToFileName);
|
||||
}
|
||||
|
||||
nsString docName(aPrintToFileName);
|
||||
docinfo.cbSize = sizeof(docinfo);
|
||||
docinfo.lpszDocName = title ? title : "Mozilla Document";
|
||||
docinfo.lpszOutput = docName;
|
||||
docinfo.lpszDocName = titleStr.Length() > 0 ? titleStr.get() : L"Mozilla Document";
|
||||
docinfo.lpszOutput = docName.Length() > 0 ? docName.get() : nsnull;
|
||||
docinfo.lpszDatatype = NULL;
|
||||
docinfo.fwType = 0;
|
||||
|
||||
int result = ::StartDoc(mDC, &docinfo);
|
||||
|
||||
delete [] title;
|
||||
if (docName != nsnull) nsMemory::Free(docName);
|
||||
|
||||
if (result <= 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
::StartDocW(mDC, &docinfo);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче