b=364300, monospace font sometimes isn't with ATSUI, breaking cols attribute of textarea, r+sr=roc

This commit is contained in:
vladimir@pobox.com 2007-07-18 07:41:40 -07:00
Родитель 77c5fe6ed4
Коммит f2536cca83
3 изменённых файлов: 38 добавлений и 11 удалений

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

@ -192,6 +192,13 @@ gfxAtsuiFont::InitMetrics(ATSUFontID aFontID, ATSFontRef aFontRef)
else
mMetrics.aveCharWidth = xWidth;
if (gfxQuartzFontCache::SharedFontCache()->IsFixedPitch(aFontID)) {
// Some Quartz fonts are fixed pitch, but there's some glyph with a bigger
// advance than the average character width... this forces
// those fonts to be recognized like fixed pitch fonts by layout.
mMetrics.maxAdvance = mMetrics.aveCharWidth;
}
mMetrics.underlineOffset = atsMetrics.underlinePosition * size;
// ATSUI sometimes returns 0 for underline thickness, see bug 361576.
mMetrics.underlineSize = PR_MAX(1.0f, atsMetrics.underlineThickness * size);
@ -207,7 +214,7 @@ gfxAtsuiFont::InitMetrics(ATSUFontID aFontID, ATSFontRef aFontRef)
mSpaceGlyph = glyphID;
#if 0
fprintf (stderr, "Font: %p size: %f", this, size);
fprintf (stderr, "Font: %p size: %f (fixed: %d)", this, size, gfxQuartzFontCache::SharedFontCache()->IsFixedPitch(aFontID));
fprintf (stderr, " emHeight: %f emAscent: %f emDescent: %f\n", mMetrics.emHeight, mMetrics.emAscent, mMetrics.emDescent);
fprintf (stderr, " maxAscent: %f maxDescent: %f maxAdvance: %f\n", mMetrics.maxAscent, mMetrics.maxDescent, mMetrics.maxAdvance);
fprintf (stderr, " internalLeading: %f externalLeading: %f\n", mMetrics.externalLeading, mMetrics.internalLeading);

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

@ -72,7 +72,7 @@ public:
THEBES_INLINE_DECL_REFCOUNTING(FontEntry)
FontEntry(nsString &aName) :
mName(aName), mWeight(0), mTraits(0)
mName(aName), mWeight(0)
{
}
@ -82,11 +82,6 @@ public:
RealizeWeightAndTraits();
return mWeight;
}
PRUint32 Traits() {
if (!mWeight)
RealizeWeightAndTraits();
return mTraits;
}
PRBool IsFixedPitch();
PRBool IsItalicStyle();
PRBool IsBold();
@ -99,7 +94,8 @@ protected:
nsString mName;
PRInt32 mWeight;
PRUint32 mTraits;
PRPackedBool mFixedPitch;
PRPackedBool mItalicStyle;
};
class gfxQuartzFontCache {
@ -134,6 +130,8 @@ public:
const nsString& GetPostscriptNameForFontID(ATSUFontID fid);
PRBool IsFixedPitch(ATSUFontID fid);
private:
static gfxQuartzFontCache *sSharedFontCache;

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

@ -102,13 +102,17 @@ FontEntry::GetNSFont(float aSize)
PRBool
FontEntry::IsFixedPitch()
{
return Traits() & NSFixedPitchFontMask ? PR_TRUE : PR_FALSE;
if (!mWeight)
RealizeWeightAndTraits();
return mFixedPitch;
}
PRBool
FontEntry::IsItalicStyle()
{
return Traits() & NSItalicFontMask ? PR_TRUE : PR_FALSE;
if (!mWeight)
RealizeWeightAndTraits();
return mItalicStyle;
}
PRBool
@ -121,9 +125,14 @@ void
FontEntry::RealizeWeightAndTraits()
{
NSFont *font = GetNSFont(10.0);
// traitsOfFont seems to give bogus results in some cases,
// see http://lists.apple.com/archives/cocoa-dev/2001/Dec/msg00836.html
// so we just ask the font directly. annoyingly, we can't ask
// the font for its weight, so we have to use the fm for that.
NSFontManager *fontManager = [NSFontManager sharedFontManager];
mWeight = [fontManager weightOfFont:font];
mTraits = [fontManager traitsOfFont:font];
mItalicStyle = [font italicAngle] != 0.0;
mFixedPitch = [font isFixedPitch];
}
void
@ -772,3 +781,16 @@ gfxQuartzFontCache::GetPostscriptNameForFontID(ATSUFontID fid)
return fe->Name();
}
PRBool
gfxQuartzFontCache::IsFixedPitch(ATSUFontID fid)
{
nsRefPtr<FontEntry> fe;
if (!mFontIDTable.Get(PRUint32(fid), &fe)) {
NS_WARNING("Invalid font");
return PR_FALSE;
}
return fe->IsFixedPitch();
}