Bumping manifests a=b2g-bump
[gecko.git] / gfx / thebes / gfxHarfBuzzShaper.h
blob908d965a9c9e060d99accbfbfc6cc19b86723786
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 "gfxFont.h"
11 #include "harfbuzz/hb.h"
12 #include "nsUnicodeProperties.h"
14 class gfxHarfBuzzShaper : public gfxFontShaper {
15 public:
16 explicit gfxHarfBuzzShaper(gfxFont *aFont);
17 virtual ~gfxHarfBuzzShaper();
20 * For HarfBuzz font callback functions, font_data is a ptr to a
21 * FontCallbackData struct
23 struct FontCallbackData {
24 gfxHarfBuzzShaper *mShaper;
25 gfxContext *mContext;
28 bool Initialize();
29 virtual bool ShapeText(gfxContext *aContext,
30 const char16_t *aText,
31 uint32_t aOffset,
32 uint32_t aLength,
33 int32_t aScript,
34 gfxShapedText *aShapedText);
36 // get a given font table in harfbuzz blob form
37 hb_blob_t * GetFontTable(hb_tag_t aTag) const;
39 // map unicode character to glyph ID
40 hb_codepoint_t GetGlyph(hb_codepoint_t unicode,
41 hb_codepoint_t variation_selector) const;
43 // get harfbuzz glyph advance, in font design units
44 hb_position_t GetGlyphHAdvance(gfxContext *aContext,
45 hb_codepoint_t glyph) const;
47 // get harfbuzz horizontal advance in 16.16 fixed point format.
48 static hb_position_t
49 HBGetGlyphHAdvance(hb_font_t *font, void *font_data,
50 hb_codepoint_t glyph, void *user_data);
52 hb_position_t GetHKerning(uint16_t aFirstGlyph,
53 uint16_t aSecondGlyph) const;
55 static hb_script_t
56 GetHBScriptUsedForShaping(int32_t aScript) {
57 // Decide what harfbuzz script code will be used for shaping
58 hb_script_t hbScript;
59 if (aScript <= MOZ_SCRIPT_INHERITED) {
60 // For unresolved "common" or "inherited" runs,
61 // default to Latin for now.
62 hbScript = HB_SCRIPT_LATIN;
63 } else {
64 hbScript =
65 hb_script_t(mozilla::unicode::GetScriptTagForCode(aScript));
67 return hbScript;
70 protected:
71 nsresult SetGlyphsFromRun(gfxContext *aContext,
72 gfxShapedText *aShapedText,
73 uint32_t aOffset,
74 uint32_t aLength,
75 const char16_t *aText,
76 hb_buffer_t *aBuffer);
78 // retrieve glyph positions, applying advance adjustments and attachments
79 // returns results in appUnits
80 nscoord GetGlyphPositions(gfxContext *aContext,
81 hb_buffer_t *aBuffer,
82 nsTArray<nsPoint>& aPositions,
83 uint32_t aAppUnitsPerDevUnit);
85 // harfbuzz face object: we acquire a reference from the font entry
86 // on shaper creation, and release it in our destructor
87 hb_face_t *mHBFace;
89 // size-specific font object, owned by the gfxHarfBuzzShaper
90 hb_font_t *mHBFont;
92 FontCallbackData mCallbackData;
94 // Following table references etc are declared "mutable" because the
95 // harfbuzz callback functions take a const ptr to the shaper, but
96 // wish to cache tables here to avoid repeatedly looking them up
97 // in the font.
99 // Old-style TrueType kern table, if we're not doing GPOS kerning
100 mutable hb_blob_t *mKernTable;
102 // Cached copy of the hmtx table and numLongMetrics field from hhea,
103 // for use when looking up glyph metrics; initialized to 0 by the
104 // constructor so we can tell it hasn't been set yet.
105 // This is a signed value so that we can use -1 to indicate
106 // an error (if the hhea table was not available).
107 mutable hb_blob_t *mHmtxTable;
108 mutable int32_t mNumLongMetrics;
110 // Cached pointer to cmap subtable to be used for char-to-glyph mapping.
111 // This comes from GetFontTablePtr; if it is non-null, our destructor
112 // must call ReleaseFontTablePtr to avoid permanently caching the table.
113 mutable hb_blob_t *mCmapTable;
114 mutable int32_t mCmapFormat;
115 mutable uint32_t mSubtableOffset;
116 mutable uint32_t mUVSTableOffset;
118 // Whether the font implements GetGlyph, or we should read tables
119 // directly
120 bool mUseFontGetGlyph;
121 // Whether the font implements GetGlyphWidth, or we should read tables
122 // directly to get ideal widths
123 bool mUseFontGlyphWidths;
125 bool mInitialized;
128 #endif /* GFX_HARFBUZZSHAPER_H */