gfx/thebes/gfxHarfBuzzShaper.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef GFX_HARFBUZZSHAPER_H
michael@0 7 #define GFX_HARFBUZZSHAPER_H
michael@0 8
michael@0 9 #include "gfxFont.h"
michael@0 10
michael@0 11 #include "harfbuzz/hb.h"
michael@0 12
michael@0 13 class gfxHarfBuzzShaper : public gfxFontShaper {
michael@0 14 public:
michael@0 15 gfxHarfBuzzShaper(gfxFont *aFont);
michael@0 16 virtual ~gfxHarfBuzzShaper();
michael@0 17
michael@0 18 /*
michael@0 19 * For HarfBuzz font callback functions, font_data is a ptr to a
michael@0 20 * FontCallbackData struct
michael@0 21 */
michael@0 22 struct FontCallbackData {
michael@0 23 gfxHarfBuzzShaper *mShaper;
michael@0 24 gfxContext *mContext;
michael@0 25 };
michael@0 26
michael@0 27 bool Initialize();
michael@0 28 virtual bool ShapeText(gfxContext *aContext,
michael@0 29 const char16_t *aText,
michael@0 30 uint32_t aOffset,
michael@0 31 uint32_t aLength,
michael@0 32 int32_t aScript,
michael@0 33 gfxShapedText *aShapedText);
michael@0 34
michael@0 35 // get a given font table in harfbuzz blob form
michael@0 36 hb_blob_t * GetFontTable(hb_tag_t aTag) const;
michael@0 37
michael@0 38 // map unicode character to glyph ID
michael@0 39 hb_codepoint_t GetGlyph(hb_codepoint_t unicode,
michael@0 40 hb_codepoint_t variation_selector) const;
michael@0 41
michael@0 42 // get harfbuzz glyph advance, in font design units
michael@0 43 hb_position_t GetGlyphHAdvance(gfxContext *aContext,
michael@0 44 hb_codepoint_t glyph) const;
michael@0 45
michael@0 46 // get harfbuzz horizontal advance in 16.16 fixed point format.
michael@0 47 static hb_position_t
michael@0 48 HBGetGlyphHAdvance(hb_font_t *font, void *font_data,
michael@0 49 hb_codepoint_t glyph, void *user_data);
michael@0 50
michael@0 51 hb_position_t GetHKerning(uint16_t aFirstGlyph,
michael@0 52 uint16_t aSecondGlyph) const;
michael@0 53
michael@0 54 protected:
michael@0 55 nsresult SetGlyphsFromRun(gfxContext *aContext,
michael@0 56 gfxShapedText *aShapedText,
michael@0 57 uint32_t aOffset,
michael@0 58 uint32_t aLength,
michael@0 59 const char16_t *aText,
michael@0 60 hb_buffer_t *aBuffer);
michael@0 61
michael@0 62 // retrieve glyph positions, applying advance adjustments and attachments
michael@0 63 // returns results in appUnits
michael@0 64 nscoord GetGlyphPositions(gfxContext *aContext,
michael@0 65 hb_buffer_t *aBuffer,
michael@0 66 nsTArray<nsPoint>& aPositions,
michael@0 67 uint32_t aAppUnitsPerDevUnit);
michael@0 68
michael@0 69 // harfbuzz face object: we acquire a reference from the font entry
michael@0 70 // on shaper creation, and release it in our destructor
michael@0 71 hb_face_t *mHBFace;
michael@0 72
michael@0 73 // size-specific font object, owned by the gfxHarfBuzzShaper
michael@0 74 hb_font_t *mHBFont;
michael@0 75
michael@0 76 FontCallbackData mCallbackData;
michael@0 77
michael@0 78 // Following table references etc are declared "mutable" because the
michael@0 79 // harfbuzz callback functions take a const ptr to the shaper, but
michael@0 80 // wish to cache tables here to avoid repeatedly looking them up
michael@0 81 // in the font.
michael@0 82
michael@0 83 // Old-style TrueType kern table, if we're not doing GPOS kerning
michael@0 84 mutable hb_blob_t *mKernTable;
michael@0 85
michael@0 86 // Cached copy of the hmtx table and numLongMetrics field from hhea,
michael@0 87 // for use when looking up glyph metrics; initialized to 0 by the
michael@0 88 // constructor so we can tell it hasn't been set yet.
michael@0 89 // This is a signed value so that we can use -1 to indicate
michael@0 90 // an error (if the hhea table was not available).
michael@0 91 mutable hb_blob_t *mHmtxTable;
michael@0 92 mutable int32_t mNumLongMetrics;
michael@0 93
michael@0 94 // Cached pointer to cmap subtable to be used for char-to-glyph mapping.
michael@0 95 // This comes from GetFontTablePtr; if it is non-null, our destructor
michael@0 96 // must call ReleaseFontTablePtr to avoid permanently caching the table.
michael@0 97 mutable hb_blob_t *mCmapTable;
michael@0 98 mutable int32_t mCmapFormat;
michael@0 99 mutable uint32_t mSubtableOffset;
michael@0 100 mutable uint32_t mUVSTableOffset;
michael@0 101
michael@0 102 // Whether the font implements GetGlyph, or we should read tables
michael@0 103 // directly
michael@0 104 bool mUseFontGetGlyph;
michael@0 105 // Whether the font implements GetGlyphWidth, or we should read tables
michael@0 106 // directly to get ideal widths
michael@0 107 bool mUseFontGlyphWidths;
michael@0 108
michael@0 109 bool mInitialized;
michael@0 110 };
michael@0 111
michael@0 112 #endif /* GFX_HARFBUZZSHAPER_H */

mercurial