зеркало из https://github.com/mozilla/gecko-dev.git
Bug 495455. Always get correct bounding boxes for text rendered with user fonts, since they are likely to be using unusually-sized glyphs. Mac/Windows only at the moment. r=jdaggett
--HG-- extra : rebase_source : 3e5a713873c59488c19f5008a075d13397566358
This commit is contained in:
Родитель
a315781458
Коммит
fe7959db5e
|
@ -160,7 +160,7 @@ public:
|
|||
gfxFontEntry(const nsAString& aName) :
|
||||
mName(aName), mItalic(PR_FALSE), mFixedPitch(PR_FALSE),
|
||||
mIsProxy(PR_FALSE), mIsValid(PR_TRUE),
|
||||
mIsBadUnderlineFont(PR_FALSE),
|
||||
mIsBadUnderlineFont(PR_FALSE), mIsUserFont(PR_FALSE),
|
||||
mWeight(500), mStretch(NS_FONT_STRETCH_NORMAL),
|
||||
mCmapInitialized(PR_FALSE), mUserFontData(nsnull)
|
||||
{ }
|
||||
|
@ -169,6 +169,7 @@ public:
|
|||
mName(aEntry.mName), mItalic(aEntry.mItalic),
|
||||
mFixedPitch(aEntry.mFixedPitch), mIsProxy(aEntry.mIsProxy),
|
||||
mIsValid(aEntry.mIsValid), mIsBadUnderlineFont(aEntry.mIsBadUnderlineFont),
|
||||
mIsUserFont(aEntry.mIsUserFont),
|
||||
mWeight(aEntry.mWeight), mCmapInitialized(aEntry.mCmapInitialized),
|
||||
mCharacterMap(aEntry.mCharacterMap), mUserFontData(aEntry.mUserFontData)
|
||||
{ }
|
||||
|
@ -180,6 +181,7 @@ public:
|
|||
|
||||
PRInt32 Weight() { return mWeight; }
|
||||
|
||||
PRBool IsUserFont() { return mIsUserFont; }
|
||||
PRBool IsFixedPitch() { return mFixedPitch; }
|
||||
PRBool IsItalic() { return mItalic; }
|
||||
PRBool IsBold() { return mWeight >= 600; } // bold == weights 600 and above
|
||||
|
@ -198,11 +200,10 @@ public:
|
|||
|
||||
PRPackedBool mItalic : 1;
|
||||
PRPackedBool mFixedPitch : 1;
|
||||
|
||||
PRPackedBool mIsProxy : 1;
|
||||
PRPackedBool mIsValid : 1;
|
||||
|
||||
PRPackedBool mIsBadUnderlineFont : 1;
|
||||
PRPackedBool mIsUserFont : 1;
|
||||
|
||||
PRUint16 mWeight;
|
||||
PRUint16 mStretch;
|
||||
|
|
|
@ -114,7 +114,7 @@ public:
|
|||
PRBool aItalic, PRUint16 aWeight, gfxUserFontData *aUserFontData) :
|
||||
gfxFontEntry(aFaceName), mFontType(aFontType),
|
||||
mForceGDI(PR_FALSE), mUnknownCMAP(PR_FALSE),
|
||||
mUnicodeFont(PR_FALSE), mSymbolFont(PR_FALSE), mUserFont(PR_FALSE),
|
||||
mUnicodeFont(PR_FALSE), mSymbolFont(PR_FALSE),
|
||||
mCharset(0), mUnicodeRanges(0)
|
||||
{
|
||||
mUserFontData = aUserFontData;
|
||||
|
@ -122,6 +122,7 @@ public:
|
|||
mWeight = aWeight;
|
||||
if (IsType1())
|
||||
mForceGDI = PR_TRUE;
|
||||
mIsUserFont = aUserFontData != nsnull;
|
||||
}
|
||||
|
||||
FontEntry(const FontEntry& aFontEntry) :
|
||||
|
@ -133,7 +134,6 @@ public:
|
|||
mUnknownCMAP(aFontEntry.mUnknownCMAP),
|
||||
mUnicodeFont(aFontEntry.mUnicodeFont),
|
||||
mSymbolFont(aFontEntry.mSymbolFont),
|
||||
mUserFont(aFontEntry.mUserFont),
|
||||
mCharset(aFontEntry.mCharset),
|
||||
mUnicodeRanges(aFontEntry.mUnicodeRanges)
|
||||
{
|
||||
|
@ -293,7 +293,6 @@ public:
|
|||
PRPackedBool mUnknownCMAP : 1;
|
||||
PRPackedBool mUnicodeFont : 1;
|
||||
PRPackedBool mSymbolFont : 1;
|
||||
PRPackedBool mUserFont : 1;
|
||||
|
||||
std::bitset<256> mCharset;
|
||||
std::bitset<128> mUnicodeRanges;
|
||||
|
|
|
@ -493,10 +493,28 @@ UnionRange(gfxFloat aX, gfxFloat* aDestMin, gfxFloat* aDestMax)
|
|||
*aDestMax = PR_MAX(*aDestMax, aX);
|
||||
}
|
||||
|
||||
// We get precise glyph extents if the textrun creator requested them, or
|
||||
// if the font is a user font --- in which case the author may be relying
|
||||
// on overflowing glyphs.
|
||||
static PRBool
|
||||
NeedsGlyphExtents(gfxFont *aFont, gfxTextRun *aTextRun)
|
||||
{
|
||||
return (aTextRun->GetFlags() & gfxTextRunFactory::TEXT_NEED_BOUNDING_BOX) ||
|
||||
aFont->GetFontEntry()->IsUserFont();
|
||||
}
|
||||
|
||||
static PRBool
|
||||
NeedsGlyphExtents(gfxTextRun *aTextRun)
|
||||
{
|
||||
return (aTextRun->GetFlags() & gfxTextRunFactory::TEXT_NEED_BOUNDING_BOX) != 0;
|
||||
if (aTextRun->GetFlags() & gfxTextRunFactory::TEXT_NEED_BOUNDING_BOX)
|
||||
return PR_TRUE;
|
||||
PRUint32 numRuns;
|
||||
const gfxTextRun::GlyphRun *glyphRuns = aTextRun->GetGlyphRuns(&numRuns);
|
||||
for (PRUint32 i = 0; i < numRuns; ++i) {
|
||||
if (glyphRuns[i].mFont->GetFontEntry()->IsUserFont())
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
gfxFont::RunMetrics
|
||||
|
@ -522,9 +540,10 @@ gfxFont::Measure(gfxTextRun *aTextRun,
|
|||
const gfxTextRun::CompressedGlyph *charGlyphs = aTextRun->GetCharacterGlyphs();
|
||||
PRBool isRTL = aTextRun->IsRightToLeft();
|
||||
double direction = aTextRun->GetDirection();
|
||||
PRBool needsGlyphExtents = NeedsGlyphExtents(this, aTextRun);
|
||||
gfxGlyphExtents *extents =
|
||||
(aBoundingBoxType == LOOSE_INK_EXTENTS &&
|
||||
!NeedsGlyphExtents(aTextRun) &&
|
||||
!needsGlyphExtents &&
|
||||
!aTextRun->HasDetailedGlyphs()) ? nsnull
|
||||
: GetOrCreateGlyphExtents(aTextRun->GetAppUnitsPerDevUnit());
|
||||
double x = 0;
|
||||
|
@ -538,8 +557,8 @@ gfxFont::Measure(gfxTextRun *aTextRun,
|
|||
double advance = glyphData->GetSimpleAdvance();
|
||||
// Only get the real glyph horizontal extent if we were asked
|
||||
// for the tight bounding box or we're in quality mode
|
||||
if ((aBoundingBoxType != LOOSE_INK_EXTENTS ||
|
||||
NeedsGlyphExtents(aTextRun)) && extents) {
|
||||
if ((aBoundingBoxType != LOOSE_INK_EXTENTS || needsGlyphExtents) &&
|
||||
extents) {
|
||||
PRUint32 glyphIndex = glyphData->GetSimpleGlyph();
|
||||
PRUint16 extentsWidth = extents->GetContainedGlyphWidthAppUnits(glyphIndex);
|
||||
if (extentsWidth != gfxGlyphExtents::INVALID_WIDTH &&
|
||||
|
@ -2493,7 +2512,8 @@ gfxTextRun::SetSpaceGlyph(gfxFont *aFont, gfxContext *aContext, PRUint32 aCharIn
|
|||
void
|
||||
gfxTextRun::FetchGlyphExtents(gfxContext *aRefContext)
|
||||
{
|
||||
if (!NeedsGlyphExtents(this) && !mDetailedGlyphs)
|
||||
PRBool needsGlyphExtents = NeedsGlyphExtents(this);
|
||||
if (!needsGlyphExtents && !mDetailedGlyphs)
|
||||
return;
|
||||
|
||||
PRUint32 i;
|
||||
|
@ -2512,7 +2532,7 @@ gfxTextRun::FetchGlyphExtents(gfxContext *aRefContext)
|
|||
if (glyphData->IsSimpleGlyph()) {
|
||||
// If we're in speed mode, don't set up glyph extents here; we'll
|
||||
// just return "optimistic" glyph bounds later
|
||||
if (NeedsGlyphExtents(this)) {
|
||||
if (needsGlyphExtents) {
|
||||
PRUint32 glyphIndex = glyphData->GetSimpleGlyph();
|
||||
if (!extents->IsGlyphKnown(glyphIndex)) {
|
||||
if (!fontIsSetup) {
|
||||
|
|
|
@ -192,6 +192,7 @@ protected:
|
|||
mItalic = aProxyEntry.mItalic;
|
||||
mWeight = aProxyEntry.mWeight;
|
||||
mStretch = aProxyEntry.mStretch;
|
||||
mIsUserFont = PR_TRUE;
|
||||
}
|
||||
|
||||
// Helper function to change a pattern so that it matches the CSS style
|
||||
|
|
|
@ -162,6 +162,7 @@ MacOSFontEntry::MacOSFontEntry(const nsAString& aPostscriptName, ATSFontRef aFon
|
|||
mStretch = aStretch;
|
||||
mFixedPitch = PR_FALSE; // xxx - do we need this for downloaded fonts?
|
||||
mItalic = (aItalicStyle & (FONT_STYLE_ITALIC | FONT_STYLE_OBLIQUE)) != 0;
|
||||
mIsUserFont = aUserFontData != nsnull;
|
||||
|
||||
mTraits = (mItalic ? NSItalicFontMask : NSUnitalicFontMask) |
|
||||
(mFixedPitch ? NSFixedPitchFontMask : 0) |
|
||||
|
|
|
@ -72,6 +72,7 @@ gfxProxyFontEntry::gfxProxyFontEntry(const nsTArray<gfxFontFaceSrc>& aFontFaceSr
|
|||
mWeight = aWeight;
|
||||
mStretch = aStretch;
|
||||
mItalic = (aItalicStyle & (FONT_STYLE_ITALIC | FONT_STYLE_OBLIQUE)) != 0;
|
||||
mIsUserFont = PR_TRUE;
|
||||
}
|
||||
|
||||
gfxProxyFontEntry::~gfxProxyFontEntry()
|
||||
|
|
|
@ -583,7 +583,6 @@ FontEntry::LoadFont(const gfxProxyFontEntry &aProxyEntry,
|
|||
if (!fe)
|
||||
return fe;
|
||||
|
||||
fe->mUserFont = PR_TRUE;
|
||||
if (isCFF)
|
||||
fe->mForceGDI = PR_TRUE;
|
||||
|
||||
|
@ -735,7 +734,7 @@ FontEntry::LoadLocalFont(const gfxProxyFontEntry &aProxyEntry,
|
|||
if (!fe)
|
||||
return fe;
|
||||
|
||||
fe->mUserFont = PR_TRUE;
|
||||
fe->mIsUserFont = PR_TRUE;
|
||||
return fe;
|
||||
}
|
||||
|
||||
|
@ -1064,7 +1063,7 @@ gfxWindowsFont::FillLogFont(gfxFloat aSize)
|
|||
|
||||
// if user font, disable italics/bold if defined to be italics/bold face
|
||||
// this avoids unwanted synthetic italics/bold
|
||||
if (fe->mUserFont) {
|
||||
if (fe->mIsUserFont) {
|
||||
if (fe->IsItalic())
|
||||
isItalic = PR_FALSE; // avoid synthetic italic
|
||||
if (fe->IsBold())
|
||||
|
|
Загрузка…
Ссылка в новой задаче