gfxGraphiteShaper.h (2776B)
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 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/. */ 5 6 #ifndef GFX_GRAPHITESHAPER_H 7 #define GFX_GRAPHITESHAPER_H 8 9 #include "gfxFont.h" 10 11 #include "mozilla/gfx/2D.h" 12 #include "nsTHashSet.h" 13 14 #include "ThebesRLBoxTypes.h" 15 16 struct gr_face; 17 struct gr_font; 18 struct gr_segment; 19 20 class gfxGraphiteShaper : public gfxFontShaper { 21 public: 22 explicit gfxGraphiteShaper(gfxFont* aFont); 23 virtual ~gfxGraphiteShaper(); 24 25 bool ShapeText(DrawTarget* aDrawTarget, const char16_t* aText, 26 uint32_t aOffset, uint32_t aLength, Script aScript, 27 nsAtom* aLanguage, bool aVertical, RoundingFlags aRounding, 28 gfxShapedText* aShapedText) override; 29 30 static void Shutdown(); 31 32 protected: 33 nsresult SetGlyphsFromSegment(gfxShapedText* aShapedText, uint32_t aOffset, 34 uint32_t aLength, const char16_t* aText, 35 tainted_opaque_gr<char16_t*> t_aText, 36 tainted_opaque_gr<gr_segment*> aSegment, 37 RoundingFlags aRounding); 38 39 // Graphite is run in a rlbox sandbox. Callback GrGetAdvance must be 40 // explicitly permitted. Since the sandbox is owned in gfxFontEntry class, 41 // gfxFontEntry needs access to the protected callback. 42 friend class gfxFontEntryCallbacks; 43 static tainted_opaque_gr<float> GrGetAdvance( 44 rlbox_sandbox_gr& sandbox, tainted_opaque_gr<const void*> appFontHandle, 45 tainted_opaque_gr<uint16_t> glyphid); 46 47 tainted_opaque_gr<gr_face*> 48 mGrFace; // owned by the font entry; shaper must call 49 // gfxFontEntry::ReleaseGrFace when finished with it 50 tainted_opaque_gr<gr_font*> mGrFont; // owned by the shaper itself 51 52 // All libGraphite functionality is sandboxed. This is the sandbox instance. 53 rlbox_sandbox_gr* mSandbox; 54 55 // Holds the handle to the permitted callback into Firefox for the sandboxed 56 // libGraphite 57 sandbox_callback_gr<float (*)(const void*, uint16_t)>* mCallback; 58 59 struct CallbackData { 60 // mFont is a pointer to the font that owns this shaper, so it will 61 // remain valid throughout our lifetime 62 gfxFont* MOZ_NON_OWNING_REF mFont; 63 }; 64 65 CallbackData mCallbackData; 66 static thread_local CallbackData* tl_GrGetAdvanceData; 67 68 bool mFallbackToSmallCaps; // special fallback for the petite-caps case 69 70 // Convert HTML 'lang' (BCP47) to Graphite language code 71 static uint32_t GetGraphiteTagForLang(const nsCString& aLang); 72 static nsTHashSet<uint32_t>* sLanguageTags; 73 }; 74 75 #endif /* GFX_GRAPHITESHAPER_H */