bug 627840 - (DirectWrite) only check for bitmaps in CJK fonts. r=masayuki a=joe

This commit is contained in:
Jonathan Kew 2011-01-25 09:17:18 +00:00
parent 5e2b167371
commit dfed233bd0
3 changed files with 49 additions and 2 deletions

View File

@ -50,6 +50,8 @@
#include "nsIWindowsRegKey.h"
using namespace mozilla;
#ifdef PR_LOGGING
#define LOG_FONTLIST(args) PR_LOG(gfxPlatform::GetLog(eGfxLog_fontlist), \
@ -433,6 +435,41 @@ gfxDWriteFontEntry::InitLogFont(IDWriteFont *aFont, LOGFONTW *aLogFont)
return (FAILED(hr) ? PR_FALSE : PR_TRUE);
}
PRBool
gfxDWriteFontEntry::IsCJKFont()
{
if (mIsCJK != UNINITIALIZED_VALUE) {
return mIsCJK;
}
mIsCJK = PR_FALSE;
const PRUint32 kOS2Tag = TRUETYPE_TAG('O','S','/','2');
AutoFallibleTArray<PRUint8,128> buffer;
if (GetFontTable(kOS2Tag, buffer) != NS_OK) {
return mIsCJK;
}
// ulCodePageRange bit definitions for the CJK codepages,
// from http://www.microsoft.com/typography/otspec/os2.htm#cpr
const PRUint32 CJK_CODEPAGE_BITS =
(1 << 17) | // codepage 932 - JIS/Japan
(1 << 18) | // codepage 936 - Chinese (simplified)
(1 << 19) | // codepage 949 - Korean Wansung
(1 << 20) | // codepage 950 - Chinese (traditional)
(1 << 21); // codepage 1361 - Korean Johab
if (buffer.Length() >= offsetof(OS2Table, sxHeight)) {
const OS2Table* os2 =
reinterpret_cast<const OS2Table*>(buffer.Elements());
if ((PRUint32(os2->codePageRange1) & CJK_CODEPAGE_BITS) != 0) {
mIsCJK = PR_TRUE;
}
}
return mIsCJK;
}
////////////////////////////////////////////////////////////////////////////////
// gfxDWriteFontList

View File

@ -103,8 +103,9 @@ public:
weight = NS_MAX<PRUint16>(100, weight);
weight = NS_MIN<PRUint16>(900, weight);
mWeight = weight;
mIsCJK = UNINITIALIZED_VALUE;
}
/**
@ -130,6 +131,7 @@ public:
mItalic = aItalic;
mIsUserFont = PR_TRUE;
mIsLocalUserFont = PR_TRUE;
mIsCJK = UNINITIALIZED_VALUE;
}
/**
@ -152,6 +154,7 @@ public:
mStretch = aStretch;
mItalic = aItalic;
mIsUserFont = PR_TRUE;
mIsCJK = UNINITIALIZED_VALUE;
}
virtual ~gfxDWriteFontEntry();
@ -162,6 +165,9 @@ public:
FallibleTArray<PRUint8>& aBuffer);
nsresult ReadCMAP();
PRBool IsCJKFont();
protected:
friend class gfxDWriteFont;
friend class gfxDWriteFontList;
@ -182,6 +188,8 @@ protected:
nsRefPtr<IDWriteFont> mFont;
nsRefPtr<IDWriteFontFile> mFontFile;
DWRITE_FONT_FACE_TYPE mFaceType;
PRBool mIsCJK;
};

View File

@ -225,7 +225,9 @@ gfxDWriteFont::ComputeMetrics()
mAdjustedSize = mStyle.size;
}
if (HasBitmapStrikeForSize(NS_lround(mAdjustedSize))) {
gfxDWriteFontEntry *fe =
static_cast<gfxDWriteFontEntry*>(mFontEntry.get());
if (fe->IsCJKFont() && HasBitmapStrikeForSize(NS_lround(mAdjustedSize))) {
mAdjustedSize = NS_lround(mAdjustedSize);
mUseSubpixelPositions = PR_FALSE;
// if we have bitmaps, we need to tell Cairo NOT to use subpixel AA,