michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GFX_HARFBUZZSHAPER_H michael@0: #define GFX_HARFBUZZSHAPER_H michael@0: michael@0: #include "gfxFont.h" michael@0: michael@0: #include "harfbuzz/hb.h" michael@0: michael@0: class gfxHarfBuzzShaper : public gfxFontShaper { michael@0: public: michael@0: gfxHarfBuzzShaper(gfxFont *aFont); michael@0: virtual ~gfxHarfBuzzShaper(); michael@0: michael@0: /* michael@0: * For HarfBuzz font callback functions, font_data is a ptr to a michael@0: * FontCallbackData struct michael@0: */ michael@0: struct FontCallbackData { michael@0: gfxHarfBuzzShaper *mShaper; michael@0: gfxContext *mContext; michael@0: }; michael@0: michael@0: bool Initialize(); michael@0: virtual bool ShapeText(gfxContext *aContext, michael@0: const char16_t *aText, michael@0: uint32_t aOffset, michael@0: uint32_t aLength, michael@0: int32_t aScript, michael@0: gfxShapedText *aShapedText); michael@0: michael@0: // get a given font table in harfbuzz blob form michael@0: hb_blob_t * GetFontTable(hb_tag_t aTag) const; michael@0: michael@0: // map unicode character to glyph ID michael@0: hb_codepoint_t GetGlyph(hb_codepoint_t unicode, michael@0: hb_codepoint_t variation_selector) const; michael@0: michael@0: // get harfbuzz glyph advance, in font design units michael@0: hb_position_t GetGlyphHAdvance(gfxContext *aContext, michael@0: hb_codepoint_t glyph) const; michael@0: michael@0: // get harfbuzz horizontal advance in 16.16 fixed point format. michael@0: static hb_position_t michael@0: HBGetGlyphHAdvance(hb_font_t *font, void *font_data, michael@0: hb_codepoint_t glyph, void *user_data); michael@0: michael@0: hb_position_t GetHKerning(uint16_t aFirstGlyph, michael@0: uint16_t aSecondGlyph) const; michael@0: michael@0: protected: michael@0: nsresult SetGlyphsFromRun(gfxContext *aContext, michael@0: gfxShapedText *aShapedText, michael@0: uint32_t aOffset, michael@0: uint32_t aLength, michael@0: const char16_t *aText, michael@0: hb_buffer_t *aBuffer); michael@0: michael@0: // retrieve glyph positions, applying advance adjustments and attachments michael@0: // returns results in appUnits michael@0: nscoord GetGlyphPositions(gfxContext *aContext, michael@0: hb_buffer_t *aBuffer, michael@0: nsTArray& aPositions, michael@0: uint32_t aAppUnitsPerDevUnit); michael@0: michael@0: // harfbuzz face object: we acquire a reference from the font entry michael@0: // on shaper creation, and release it in our destructor michael@0: hb_face_t *mHBFace; michael@0: michael@0: // size-specific font object, owned by the gfxHarfBuzzShaper michael@0: hb_font_t *mHBFont; michael@0: michael@0: FontCallbackData mCallbackData; michael@0: michael@0: // Following table references etc are declared "mutable" because the michael@0: // harfbuzz callback functions take a const ptr to the shaper, but michael@0: // wish to cache tables here to avoid repeatedly looking them up michael@0: // in the font. michael@0: michael@0: // Old-style TrueType kern table, if we're not doing GPOS kerning michael@0: mutable hb_blob_t *mKernTable; michael@0: michael@0: // Cached copy of the hmtx table and numLongMetrics field from hhea, michael@0: // for use when looking up glyph metrics; initialized to 0 by the michael@0: // constructor so we can tell it hasn't been set yet. michael@0: // This is a signed value so that we can use -1 to indicate michael@0: // an error (if the hhea table was not available). michael@0: mutable hb_blob_t *mHmtxTable; michael@0: mutable int32_t mNumLongMetrics; michael@0: michael@0: // Cached pointer to cmap subtable to be used for char-to-glyph mapping. michael@0: // This comes from GetFontTablePtr; if it is non-null, our destructor michael@0: // must call ReleaseFontTablePtr to avoid permanently caching the table. michael@0: mutable hb_blob_t *mCmapTable; michael@0: mutable int32_t mCmapFormat; michael@0: mutable uint32_t mSubtableOffset; michael@0: mutable uint32_t mUVSTableOffset; michael@0: michael@0: // Whether the font implements GetGlyph, or we should read tables michael@0: // directly michael@0: bool mUseFontGetGlyph; michael@0: // Whether the font implements GetGlyphWidth, or we should read tables michael@0: // directly to get ideal widths michael@0: bool mUseFontGlyphWidths; michael@0: michael@0: bool mInitialized; michael@0: }; michael@0: michael@0: #endif /* GFX_HARFBUZZSHAPER_H */