b=569770 part 7: allow the font to provide its own GetGlyph function r=jfkthame

--HG--
extra : rebase_source : 7468110c4def7c0f0ab04503052ae5de75ecb237
This commit is contained in:
Karl Tomlinson 2010-12-09 20:28:51 +13:00
Родитель 6b1cf3b243
Коммит 4b2f371aea
3 изменённых файлов: 37 добавлений и 16 удалений

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

@ -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

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

@ -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;
}

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

@ -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 */