From 8b2fb0cd5d9bdeaa2a1a26f2bf798277b4c1bb86 Mon Sep 17 00:00:00 2001 From: Karl Tomlinson Date: Thu, 9 Dec 2010 20:28:51 +1300 Subject: [PATCH] b=569770 part 7: allow the font to provide its own GetGlyph function r=jfkthame --HG-- extra : rebase_source : 7468110c4def7c0f0ab04503052ae5de75ecb237 --- gfx/thebes/gfxFont.h | 12 +++++++++++ gfx/thebes/gfxHarfBuzzShaper.cpp | 36 +++++++++++++++++++------------- gfx/thebes/gfxHarfBuzzShaper.h | 5 ++++- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/gfx/thebes/gfxFont.h b/gfx/thebes/gfxFont.h index 6554717978b..b8fd8721dbe 100644 --- a/gfx/thebes/gfxFont.h +++ b/gfx/thebes/gfxFont.h @@ -1000,6 +1000,18 @@ public: // the table doesn't exist in the font virtual hb_blob_t *GetFontTable(PRUint32 aTag); + // Subclasses may choose to look up glyph ids for characters. + // If they do not override this, gfxHarfBuzzShaper will fetch the cmap + // table and use that. + virtual PRBool ProvidesGetGlyph() const { + return PR_FALSE; + } + // Map unicode character to glyph ID. + // Only used if ProvidesGetGlyph() returns PR_TRUE. + virtual PRUint32 GetGlyph(PRUint32 unicode, PRUint32 variation_selector) { + return 0; + } + // subclasses may provide hinted glyph widths (in font units); // if they do not override this, harfbuzz will use unhinted widths // derived from the font tables diff --git a/gfx/thebes/gfxHarfBuzzShaper.cpp b/gfx/thebes/gfxHarfBuzzShaper.cpp index d05843bcb37..1f8adf104f3 100644 --- a/gfx/thebes/gfxHarfBuzzShaper.cpp +++ b/gfx/thebes/gfxHarfBuzzShaper.cpp @@ -82,6 +82,7 @@ gfxHarfBuzzShaper::gfxHarfBuzzShaper(gfxFont *aFont) mCmapFormat(-1), mSubtableOffset(0), mUVSTableOffset(0), + mUseFontGetGlyph(aFont->ProvidesGetGlyph()), mUseHintedWidths(aFont->ProvidesHintedWidths()) { } @@ -127,6 +128,10 @@ hb_codepoint_t gfxHarfBuzzShaper::GetGlyph(hb_codepoint_t unicode, hb_codepoint_t variation_selector) const { + if (mUseFontGetGlyph) { + return mFont->GetGlyph(unicode, variation_selector); + } + // we only instantiate a harfbuzz shaper if there's a cmap available NS_ASSERTION(mFont->GetFontEntry()->HasCmapTable(), "we cannot be using this font!"); @@ -731,21 +736,21 @@ gfxHarfBuzzShaper::InitTextRun(gfxContext *aContext, mHBFace = hb_face_create_for_tables(HBGetTable, nsnull, this); - // get the cmap table and find offset to our subtable - mCmapTable = mFont->GetFontTable(TRUETYPE_TAG('c','m','a','p')); - if (!mCmapTable) { - NS_WARNING("failed to load cmap, glyphs will be missing"); - return PR_FALSE; + if (!mUseFontGetGlyph) { + // get the cmap table and find offset to our subtable + mCmapTable = mFont->GetFontTable(TRUETYPE_TAG('c','m','a','p')); + if (!mCmapTable) { + NS_WARNING("failed to load cmap, glyphs will be missing"); + return PR_FALSE; + } + const PRUint8* data = (const PRUint8*)hb_blob_lock(mCmapTable); + PRBool symbol; + mCmapFormat = gfxFontUtils:: + FindPreferredSubtable(data, hb_blob_get_length(mCmapTable), + &mSubtableOffset, &mUVSTableOffset, + &symbol); + hb_blob_unlock(mCmapTable); } - const PRUint8* data = (const PRUint8*)hb_blob_lock(mCmapTable); - PRBool symbol; - mCmapFormat = - gfxFontUtils::FindPreferredSubtable(data, - hb_blob_get_length(mCmapTable), - &mSubtableOffset, - &mUVSTableOffset, - &symbol); - hb_blob_unlock(mCmapTable); if (!mUseHintedWidths) { // if font doesn't implement hinted widths, we will be reading @@ -782,7 +787,8 @@ gfxHarfBuzzShaper::InitTextRun(gfxContext *aContext, } } - if (mCmapFormat <= 0 || (!mUseHintedWidths && !mHmtxTable)) { + if ((!mUseFontGetGlyph && mCmapFormat <= 0) || + (!mUseHintedWidths && !mHmtxTable)) { // unable to shape with this font return PR_FALSE; } diff --git a/gfx/thebes/gfxHarfBuzzShaper.h b/gfx/thebes/gfxHarfBuzzShaper.h index a94ac78d8ee..665bdef0c3b 100644 --- a/gfx/thebes/gfxHarfBuzzShaper.h +++ b/gfx/thebes/gfxHarfBuzzShaper.h @@ -115,9 +115,12 @@ protected: mutable PRUint32 mSubtableOffset; mutable PRUint32 mUVSTableOffset; + // Whether the font implements GetGlyph, or we should read tables + // directly + PRPackedBool mUseFontGetGlyph; // Whether the font implements hinted widths, or we should read tables // directly to get ideal widths - PRBool mUseHintedWidths; + PRPackedBool mUseHintedWidths; }; #endif /* GFX_HARFBUZZSHAPER_H */