Bug 1213280 - fix OSX font selection under 10.11. r=jfkthame

This commit is contained in:
John Daggett 2015-11-20 22:01:12 +09:00
parent 7ea8960cd1
commit 4c5448c1f7
30 changed files with 84 additions and 44 deletions

View File

@ -3973,10 +3973,13 @@ gfxFontGroup *CanvasRenderingContext2D::GetCurrentFontStyle()
if (presShell && !presShell->IsDestroying()) {
tp = presShell->GetPresContext()->GetTextPerfMetrics();
}
int32_t perDevPixel, perCSSPixel;
GetAppUnitsValues(&perDevPixel, &perCSSPixel);
gfxFloat devToCssSize = gfxFloat(perDevPixel) / gfxFloat(perCSSPixel);
CurrentState().fontGroup =
gfxPlatform::GetPlatform()->CreateFontGroup(FontFamilyList(eFamily_sans_serif),
&style, tp,
nullptr);
nullptr, devToCssSize);
if (CurrentState().fontGroup) {
CurrentState().font = kDefaultFontStyle;
} else {

View File

@ -150,8 +150,11 @@ nsFontMetrics::Init(const nsFont& aFont,
aFont.AddFontFeaturesToStyle(&style);
gfxFloat devToCssSize = gfxFloat(mP2A) /
gfxFloat(mDeviceContext->AppUnitsPerCSSPixel());
mFontGroup = gfxPlatform::GetPlatform()->
CreateFontGroup(aFont.fontlist, &style, aTextPerf, aUserFontSet);
CreateFontGroup(aFont.fontlist, &style, aTextPerf,
aUserFontSet, devToCssSize);
return NS_OK;
}

View File

@ -249,7 +249,7 @@ static bool
RunTest (TestEntry *test, gfxContext *ctx) {
RefPtr<gfxFontGroup> fontGroup;
fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->utf8FamilyString), &test->fontStyle, nullptr, nullptr);
fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->utf8FamilyString), &test->fontStyle, nullptr, nullptr, 1.0);
nsAutoPtr<gfxTextRun> textRun;
gfxTextRunFactory::Parameters params = {

View File

@ -63,7 +63,7 @@ RunTest (TestEntry *test, gfxContext *ctx) {
false, false,
NS_LITERAL_STRING(""));
fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16, nullptr, nullptr);
fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16, nullptr, nullptr, 1.0);
}
nsAutoPtr<gfxTextRun> textRun;

View File

@ -111,7 +111,7 @@ TEST(Gfx, WordCache) {
RefPtr<gfxFontGroup> fontGroup =
gfxPlatform::GetPlatform()->CreateFontGroup(
NS_LITERAL_STRING("Geneva, MS Sans Serif, Helvetica,serif"), &style,
nullptr, nullptr);
nullptr, nullptr, 1.0);
gfxTextRunFactory::Parameters params = {
ctx, nullptr, nullptr, nullptr, 0, 60

View File

@ -313,9 +313,11 @@ gfxFontGroup *
gfxAndroidPlatform::CreateFontGroup(const FontFamilyList& aFontFamilyList,
const gfxFontStyle* aStyle,
gfxTextPerfMetrics* aTextPerf,
gfxUserFontSet* aUserFontSet)
gfxUserFontSet* aUserFontSet,
gfxFloat aDevToCssSize)
{
return new gfxFontGroup(aFontFamilyList, aStyle, aTextPerf, aUserFontSet);
return new gfxFontGroup(aFontFamilyList, aStyle, aTextPerf,
aUserFontSet, aDevToCssSize);
}
FT_Library

View File

@ -73,7 +73,8 @@ public:
CreateFontGroup(const mozilla::FontFamilyList& aFontFamilyList,
const gfxFontStyle *aStyle,
gfxTextPerfMetrics* aTextPerf,
gfxUserFontSet *aUserFontSet) override;
gfxUserFontSet *aUserFontSet,
gfxFloat aDevToCssSize) override;
virtual bool FontHintingEnabled() override;
virtual bool RequiresLinearZoom() override;

View File

@ -1257,7 +1257,8 @@ gfxDWriteFontList::GetStandardFamilyName(const nsAString& aFontName,
}
gfxFontFamily*
gfxDWriteFontList::FindFamily(const nsAString& aFamily, gfxFontStyle* aStyle)
gfxDWriteFontList::FindFamily(const nsAString& aFamily, gfxFontStyle* aStyle,
gfxFloat aDevToCssSize)
{
nsAutoString keyName(aFamily);
BuildKeyNameFromFontName(keyName);

View File

@ -368,7 +368,8 @@ public:
bool UseGDIFontTableAccess() { return mGDIFontTableAccess; }
gfxFontFamily* FindFamily(const nsAString& aFamily,
gfxFontStyle* aStyle = nullptr) override;
gfxFontStyle* aStyle = nullptr,
gfxFloat aDevToCssSize = 1.0) override;
gfxFloat GetForceGDIClassicMaxFontSize() { return mForceGDIClassicMaxFontSize; }

View File

@ -1310,7 +1310,8 @@ gfxFcPlatformFontList::MakePlatformFont(const nsAString& aFontName,
}
gfxFontFamily*
gfxFcPlatformFontList::FindFamily(const nsAString& aFamily, gfxFontStyle* aStyle)
gfxFcPlatformFontList::FindFamily(const nsAString& aFamily, gfxFontStyle* aStyle,
gfxFloat aDevToCssSize)
{
nsAutoString familyName(aFamily);
ToLowerCase(familyName);

View File

@ -225,7 +225,8 @@ public:
uint32_t aLength) override;
gfxFontFamily* FindFamily(const nsAString& aFamily,
gfxFontStyle* aStyle = nullptr) override;
gfxFontStyle* aStyle = nullptr,
gfxFloat aDevToCssSize = 1.0) override;
bool GetStandardFamilyName(const nsAString& aFontName,
nsAString& aFamilyName) override;

View File

@ -1258,8 +1258,9 @@ PrepareSortPattern(FcPattern *aPattern, double aFallbackSize,
gfxPangoFontGroup::gfxPangoFontGroup(const FontFamilyList& aFontFamilyList,
const gfxFontStyle *aStyle,
gfxUserFontSet *aUserFontSet)
: gfxFontGroup(aFontFamilyList, aStyle, nullptr, aUserFontSet),
gfxUserFontSet *aUserFontSet,
gfxFloat aDevToCssSize)
: gfxFontGroup(aFontFamilyList, aStyle, nullptr, aUserFontSet, aDevToCssSize),
mPangoLanguage(GuessPangoLanguage(aStyle->language))
{
// This language is passed to the font for shaping.
@ -1280,7 +1281,7 @@ gfxPangoFontGroup::~gfxPangoFontGroup()
gfxFontGroup *
gfxPangoFontGroup::Copy(const gfxFontStyle *aStyle)
{
return new gfxPangoFontGroup(mFamilyList, aStyle, mUserFontSet);
return new gfxPangoFontGroup(mFamilyList, aStyle, mUserFontSet, mDevToCssSize);
}
void
@ -1813,7 +1814,7 @@ gfxPangoFontGroup::GetFTLibrary()
gfxFontStyle style;
RefPtr<gfxPangoFontGroup> fontGroup =
new gfxPangoFontGroup(FontFamilyList(eFamily_sans_serif),
&style, nullptr);
&style, nullptr, 1.0);
gfxFcFont *font = fontGroup->GetBaseFont();
if (!font)

View File

@ -25,7 +25,8 @@ class gfxPangoFontGroup : public gfxFontGroup {
public:
gfxPangoFontGroup(const mozilla::FontFamilyList& aFontFamilyList,
const gfxFontStyle *aStyle,
gfxUserFontSet *aUserFontSet);
gfxUserFontSet *aUserFontSet,
gfxFloat aDevToCssSize);
virtual ~gfxPangoFontGroup();
virtual gfxFontGroup *Copy(const gfxFontStyle *aStyle);

View File

@ -831,7 +831,8 @@ gfxGDIFontList::MakePlatformFont(const nsAString& aFontName,
}
gfxFontFamily*
gfxGDIFontList::FindFamily(const nsAString& aFamily, gfxFontStyle* aStyle)
gfxGDIFontList::FindFamily(const nsAString& aFamily, gfxFontStyle* aStyle,
gfxFloat aDevToCssSize)
{
nsAutoString keyName(aFamily);
BuildKeyNameFromFontName(keyName);

View File

@ -306,7 +306,8 @@ public:
virtual gfxFontFamily* GetDefaultFont(const gfxFontStyle* aStyle);
gfxFontFamily* FindFamily(const nsAString& aFamily,
gfxFontStyle* aStyle = nullptr) override;
gfxFontStyle* aStyle = nullptr,
gfxFloat aDevToCssSize = 1.0) override;
virtual gfxFontEntry* LookupLocalFont(const nsAString& aFontName,
uint16_t aWeight,

View File

@ -96,7 +96,8 @@ public:
uint32_t aLength) override;
gfxFontFamily* FindFamily(const nsAString& aFamily,
gfxFontStyle* aStyle = nullptr) override;
gfxFontStyle* aStyle = nullptr,
gfxFloat aDevToCssSize = 1.0) override;
// lookup the system font for a particular system font type and set
// the name and style characteristics

View File

@ -1092,18 +1092,19 @@ gfxMacPlatformFontList::MakePlatformFont(const nsAString& aFontName,
static const char kSystemFont_system[] = "-apple-system";
gfxFontFamily*
gfxMacPlatformFontList::FindFamily(const nsAString& aFamily, gfxFontStyle* aStyle)
gfxMacPlatformFontList::FindFamily(const nsAString& aFamily, gfxFontStyle* aStyle,
gfxFloat aDevToCssSize)
{
// search for special system font name, -apple-system
if (aFamily.EqualsLiteral(kSystemFont_system)) {
if (mUseSizeSensitiveSystemFont &&
aStyle && aStyle->size >= kTextDisplayCrossover) {
aStyle && (aStyle->size * aDevToCssSize) >= kTextDisplayCrossover) {
return mSystemDisplayFontFamily;
}
return mSystemTextFontFamily;
}
return gfxPlatformFontList::FindFamily(aFamily, aStyle);
return gfxPlatformFontList::FindFamily(aFamily, aStyle, aDevToCssSize);
}
void

View File

@ -337,7 +337,8 @@ public:
CreateFontGroup(const mozilla::FontFamilyList& aFontFamilyList,
const gfxFontStyle *aStyle,
gfxTextPerfMetrics* aTextPerf,
gfxUserFontSet *aUserFontSet) = 0;
gfxUserFontSet *aUserFontSet,
gfxFloat aDevToCssSize) = 0;
/**
* Look up a local platform font using the full font face name.

View File

@ -639,7 +639,8 @@ gfxPlatformFontList::CheckFamily(gfxFontFamily *aFamily)
}
gfxFontFamily*
gfxPlatformFontList::FindFamily(const nsAString& aFamily, gfxFontStyle* aStyle)
gfxPlatformFontList::FindFamily(const nsAString& aFamily, gfxFontStyle* aStyle,
gfxFloat aDevToCssSize)
{
nsAutoString key;
gfxFontFamily *familyEntry;

View File

@ -129,8 +129,9 @@ public:
int32_t aRunScript,
const gfxFontStyle* aStyle);
virtual gfxFontFamily* FindFamily(const nsAString& aFamily,
gfxFontStyle* aStyle = nullptr);
virtual gfxFontFamily*
FindFamily(const nsAString& aFamily, gfxFontStyle* aStyle = nullptr,
gfxFloat aDevToCssSize = 1.0);
gfxFontEntry* FindFontForFamily(const nsAString& aFamily, const gfxFontStyle* aStyle, bool& aNeedsBold);

View File

@ -247,13 +247,16 @@ gfxFontGroup *
gfxPlatformGtk::CreateFontGroup(const FontFamilyList& aFontFamilyList,
const gfxFontStyle* aStyle,
gfxTextPerfMetrics* aTextPerf,
gfxUserFontSet* aUserFontSet)
gfxUserFontSet* aUserFontSet,
gfxFloat aDevToCssSize)
{
if (sUseFcFontList) {
return new gfxFontGroup(aFontFamilyList, aStyle, aTextPerf, aUserFontSet);
return new gfxFontGroup(aFontFamilyList, aStyle, aTextPerf,
aUserFontSet, aDevToCssSize);
}
return new gfxPangoFontGroup(aFontFamilyList, aStyle, aUserFontSet);
return new gfxPangoFontGroup(aFontFamilyList, aStyle,
aUserFontSet, aDevToCssSize);
}
gfxFontEntry*

View File

@ -54,7 +54,8 @@ public:
CreateFontGroup(const mozilla::FontFamilyList& aFontFamilyList,
const gfxFontStyle *aStyle,
gfxTextPerfMetrics* aTextPerf,
gfxUserFontSet *aUserFontSet) override;
gfxUserFontSet *aUserFontSet,
gfxFloat aDevToCssSize) override;
/**
* Look up a local platform font using the full font face name (needed to

View File

@ -142,9 +142,11 @@ gfxFontGroup *
gfxPlatformMac::CreateFontGroup(const FontFamilyList& aFontFamilyList,
const gfxFontStyle *aStyle,
gfxTextPerfMetrics* aTextPerf,
gfxUserFontSet *aUserFontSet)
gfxUserFontSet *aUserFontSet,
gfxFloat aDevToCssSize)
{
return new gfxFontGroup(aFontFamilyList, aStyle, aTextPerf, aUserFontSet);
return new gfxFontGroup(aFontFamilyList, aStyle, aTextPerf,
aUserFontSet, aDevToCssSize);
}
// these will move to gfxPlatform once all platforms support the fontlist

View File

@ -39,7 +39,8 @@ public:
CreateFontGroup(const mozilla::FontFamilyList& aFontFamilyList,
const gfxFontStyle *aStyle,
gfxTextPerfMetrics* aTextPerf,
gfxUserFontSet *aUserFontSet) override;
gfxUserFontSet *aUserFontSet,
gfxFloat aDevToCssSize) override;
virtual gfxFontEntry* LookupLocalFont(const nsAString& aFontName,
uint16_t aWeight,

View File

@ -123,9 +123,11 @@ gfxFontGroup *
gfxQtPlatform::CreateFontGroup(const FontFamilyList& aFontFamilyList,
const gfxFontStyle *aStyle,
gfxTextPerfMetrics* aTextPerf,
gfxUserFontSet* aUserFontSet)
gfxUserFontSet* aUserFontSet,
gfxFloat aDevToCssSize)
{
return new gfxPangoFontGroup(aFontFamilyList, aStyle, aUserFontSet);
return new gfxPangoFontGroup(aFontFamilyList, aStyle,
aUserFontSet, aDevToCssSize);
}
gfxFontEntry*

View File

@ -45,7 +45,8 @@ public:
CreateFontGroup(const mozilla::FontFamilyList& aFontFamilyList,
const gfxFontStyle *aStyle,
gfxTextPerfMetrics* aTextPerf,
gfxUserFontSet *aUserFontSet) override;
gfxUserFontSet *aUserFontSet,
gfxFloat aDevToCssSize) override;
/**
* Look up a local platform font using the full font face name (needed to

View File

@ -1532,11 +1532,13 @@ gfxTextRun::Dump(FILE* aOutput) {
gfxFontGroup::gfxFontGroup(const FontFamilyList& aFontFamilyList,
const gfxFontStyle *aStyle,
gfxTextPerfMetrics* aTextPerf,
gfxUserFontSet *aUserFontSet)
gfxUserFontSet *aUserFontSet,
gfxFloat aDevToCssSize)
: mFamilyList(aFontFamilyList)
, mStyle(*aStyle)
, mUnderlineOffset(UNDERLINE_OFFSET_NOT_SET)
, mHyphenWidth(-1)
, mDevToCssSize(aDevToCssSize)
, mUserFontSet(aUserFontSet)
, mTextPerf(aTextPerf)
, mPageLang(gfxPlatformFontList::GetFontPrefLangFor(aStyle->language))
@ -1619,7 +1621,7 @@ gfxFontGroup::AddPlatformFont(const nsAString& aName,
// Not known in the user font set ==> check system fonts
if (!family) {
gfxPlatformFontList* fontList = gfxPlatformFontList::PlatformFontList();
family = fontList->FindFamily(aName, &mStyle);
family = fontList->FindFamily(aName, &mStyle, mDevToCssSize);
}
if (family) {
@ -1896,7 +1898,8 @@ gfxFontGroup *
gfxFontGroup::Copy(const gfxFontStyle *aStyle)
{
gfxFontGroup *fg =
new gfxFontGroup(mFamilyList, aStyle, mTextPerf, mUserFontSet);
new gfxFontGroup(mFamilyList, aStyle, mTextPerf,
mUserFontSet, mDevToCssSize);
return fg;
}

View File

@ -727,7 +727,8 @@ public:
gfxFontGroup(const mozilla::FontFamilyList& aFontFamilyList,
const gfxFontStyle* aStyle,
gfxTextPerfMetrics* aTextPerf,
gfxUserFontSet* aUserFontSet = nullptr);
gfxUserFontSet* aUserFontSet,
gfxFloat aDevToCssSize);
virtual ~gfxFontGroup();
@ -1027,6 +1028,7 @@ protected:
gfxFloat mUnderlineOffset;
gfxFloat mHyphenWidth;
gfxFloat mDevToCssSize;
RefPtr<gfxUserFontSet> mUserFontSet;
uint64_t mCurrGeneration; // track the current user font set generation, rebuild font list if needed

View File

@ -1048,9 +1048,11 @@ gfxFontGroup *
gfxWindowsPlatform::CreateFontGroup(const FontFamilyList& aFontFamilyList,
const gfxFontStyle *aStyle,
gfxTextPerfMetrics* aTextPerf,
gfxUserFontSet *aUserFontSet)
gfxUserFontSet *aUserFontSet,
gfxFloat aDevToCssSize)
{
return new gfxFontGroup(aFontFamilyList, aStyle, aTextPerf, aUserFontSet);
return new gfxFontGroup(aFontFamilyList, aStyle, aTextPerf,
aUserFontSet, aDevToCssSize);
}
gfxFontEntry*

View File

@ -185,7 +185,8 @@ public:
CreateFontGroup(const mozilla::FontFamilyList& aFontFamilyList,
const gfxFontStyle *aStyle,
gfxTextPerfMetrics* aTextPerf,
gfxUserFontSet *aUserFontSet) override;
gfxUserFontSet *aUserFontSet,
gfxFloat aDevToCssSize) override;
/**
* Look up a local platform font using the full font face name (needed to support @font-face src local() )