Bug 835381 - Update libnestegg to 38c83d9d4c0c5c84373aa285bd30094a12d6b6f6. r=kinetik
[gecko.git] / gfx / thebes / gfxHarfBuzzShaper.h
bloba76af1963e5ee6565dcd3814732e617a6aca9572
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GFX_HARFBUZZSHAPER_H
7 #define GFX_HARFBUZZSHAPER_H
9 #include "gfxTypes.h"
10 #include "gfxFont.h"
11 #include "nsDataHashtable.h"
12 #include "nsPoint.h"
14 #include "harfbuzz/hb.h"
16 class gfxHarfBuzzShaper : public gfxFontShaper {
17 public:
18 gfxHarfBuzzShaper(gfxFont *aFont);
19 virtual ~gfxHarfBuzzShaper();
21 virtual bool ShapeText(gfxContext *aContext,
22 const PRUnichar *aText,
23 uint32_t aOffset,
24 uint32_t aLength,
25 int32_t aScript,
26 gfxShapedText *aShapedText);
28 // get a given font table in harfbuzz blob form
29 hb_blob_t * GetFontTable(hb_tag_t aTag) const;
31 // map unicode character to glyph ID
32 hb_codepoint_t GetGlyph(hb_codepoint_t unicode,
33 hb_codepoint_t variation_selector) const;
35 // get harfbuzz glyph advance, in font design units
36 hb_position_t GetGlyphHAdvance(gfxContext *aContext,
37 hb_codepoint_t glyph) const;
39 hb_position_t GetHKerning(uint16_t aFirstGlyph,
40 uint16_t aSecondGlyph) const;
42 protected:
43 nsresult SetGlyphsFromRun(gfxContext *aContext,
44 gfxShapedText *aShapedText,
45 uint32_t aOffset,
46 uint32_t aLength,
47 const PRUnichar *aText,
48 hb_buffer_t *aBuffer);
50 // retrieve glyph positions, applying advance adjustments and attachments
51 // returns results in appUnits
52 nscoord GetGlyphPositions(gfxContext *aContext,
53 hb_buffer_t *aBuffer,
54 nsTArray<nsPoint>& aPositions,
55 uint32_t aAppUnitsPerDevUnit);
57 // harfbuzz face object, created on first use (caches font tables)
58 hb_face_t *mHBFace;
60 // Following table references etc are declared "mutable" because the
61 // harfbuzz callback functions take a const ptr to the shaper, but
62 // wish to cache tables here to avoid repeatedly looking them up
63 // in the font.
65 // Old-style TrueType kern table, if we're not doing GPOS kerning
66 mutable hb_blob_t *mKernTable;
68 // Cached copy of the hmtx table and numLongMetrics field from hhea,
69 // for use when looking up glyph metrics; initialized to 0 by the
70 // constructor so we can tell it hasn't been set yet.
71 // This is a signed value so that we can use -1 to indicate
72 // an error (if the hhea table was not available).
73 mutable hb_blob_t *mHmtxTable;
74 mutable int32_t mNumLongMetrics;
76 // Cached pointer to cmap subtable to be used for char-to-glyph mapping.
77 // This comes from GetFontTablePtr; if it is non-null, our destructor
78 // must call ReleaseFontTablePtr to avoid permanently caching the table.
79 mutable hb_blob_t *mCmapTable;
80 mutable int32_t mCmapFormat;
81 mutable uint32_t mSubtableOffset;
82 mutable uint32_t mUVSTableOffset;
84 // Whether the font implements GetGlyph, or we should read tables
85 // directly
86 bool mUseFontGetGlyph;
87 // Whether the font implements GetGlyphWidth, or we should read tables
88 // directly to get ideal widths
89 bool mUseFontGlyphWidths;
92 #endif /* GFX_HARFBUZZSHAPER_H */