Bug 1089787 - Get glyph widths via Core Text for fonts with embedded color bitmaps. r=jdaggett

This commit is contained in:
Jonathan Kew 2014-11-17 09:59:49 +00:00
parent 485ffc18ab
commit 8949117378
2 changed files with 35 additions and 0 deletions

View File

@ -25,6 +25,7 @@ gfxMacFont::gfxMacFont(MacOSFontEntry *aFontEntry, const gfxFontStyle *aFontStyl
bool aNeedsBold)
: gfxFont(aFontEntry, aFontStyle),
mCGFont(nullptr),
mCTFont(nullptr),
mFontFace(nullptr)
{
mApplySyntheticBold = aNeedsBold;
@ -110,6 +111,9 @@ gfxMacFont::gfxMacFont(MacOSFontEntry *aFontEntry, const gfxFontStyle *aFontStyl
gfxMacFont::~gfxMacFont()
{
if (mCTFont) {
::CFRelease(mCTFont);
}
if (mScaledFont) {
cairo_scaled_font_destroy(mScaledFont);
}
@ -362,6 +366,24 @@ gfxMacFont::GetCharWidth(CFDataRef aCmap, char16_t aUniChar,
return 0;
}
int32_t
gfxMacFont::GetGlyphWidth(DrawTarget& aDrawTarget, uint16_t aGID)
{
if (!mCTFont) {
mCTFont = ::CTFontCreateWithGraphicsFont(mCGFont, mAdjustedSize,
nullptr, nullptr);
if (!mCTFont) { // shouldn't happen, but let's be safe
NS_WARNING("failed to create CTFontRef to measure glyph width");
return 0;
}
}
CGSize advance;
::CTFontGetAdvancesForGlyphs(mCTFont, kCTFontDefaultOrientation, &aGID,
&advance, 1);
return advance.width * 0x10000;
}
// Try to initialize font metrics via platform APIs (CG/CT),
// and set mIsValid = TRUE on success.
// We ONLY call this for local (platform) fonts that are not sfnt format;

View File

@ -37,6 +37,15 @@ public:
gfxContext *aContextForTightBoundingBox,
Spacing *aSpacing, uint16_t aOrientation);
// We need to provide hinted (non-linear) glyph widths if using a font
// with embedded color bitmaps (Apple Color Emoji), as Core Text renders
// the glyphs with non-linear scaling at small pixel sizes.
virtual bool ProvidesGlyphWidths() const {
return mFontEntry->HasFontTable(TRUETYPE_TAG('s','b','i','x'));
}
virtual int32_t GetGlyphWidth(DrawTarget& aDrawTarget, uint16_t aGID);
virtual mozilla::TemporaryRef<mozilla::gfx::ScaledFont> GetScaledFont(mozilla::gfx::DrawTarget *aTarget);
virtual mozilla::TemporaryRef<mozilla::gfx::GlyphRenderingOptions>
@ -75,6 +84,10 @@ protected:
// MacOSFontEntry, it is not retained or released by gfxMacFont
CGFontRef mCGFont;
// a Core Text font reference, created only if we're using CT to measure
// glyph widths; otherwise null.
CTFontRef mCTFont;
cairo_font_face_t *mFontFace;
nsAutoPtr<gfxFontShaper> mCoreTextShaper;