gfxCoreTextShaper.h (2490B)
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_CORETEXTSHAPER_H 7 #define GFX_CORETEXTSHAPER_H 8 9 #include "gfxFont.h" 10 11 #include <CoreText/CoreText.h> 12 13 class gfxMacFont; 14 15 class gfxCoreTextShaper : public gfxFontShaper { 16 public: 17 explicit gfxCoreTextShaper(gfxMacFont* aFont); 18 19 virtual ~gfxCoreTextShaper(); 20 21 bool ShapeText(DrawTarget* aDrawTarget, const char16_t* aText, 22 uint32_t aOffset, uint32_t aLength, Script aScript, 23 nsAtom* aLanguage, bool aVertical, RoundingFlags aRounding, 24 gfxShapedText* aShapedText) override; 25 26 // clean up static objects that may have been cached 27 static void Shutdown(); 28 29 // Flags used to track what AAT features should be enabled on the Core Text 30 // font instance. (Internal; only public so that we can use the 31 // MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS macro below.) 32 enum FeatureFlags : uint8_t { 33 kDefaultFeatures = 0x00, 34 // bit flags for non-default feature settings we might need 35 // to use, which will require separate font instances 36 kDisableLigatures = 0x01, 37 kAddSmallCaps = 0x02, 38 kIndicFeatures = 0x04, 39 40 // number of font instances, indexed by OR-ing the flags above 41 kMaxFontInstances = 8 42 }; 43 44 protected: 45 CTFontRef mCTFont[kMaxFontInstances]; 46 47 // attributes for shaping text with LTR or RTL directionality 48 CFDictionaryRef mAttributesDictLTR; 49 CFDictionaryRef mAttributesDictRTL; 50 51 nsresult SetGlyphsFromRun(gfxShapedText* aShapedText, uint32_t aOffset, 52 uint32_t aLength, CTRunRef aCTRun); 53 54 CTFontRef CreateCTFontWithFeatures(CGFloat aSize, 55 CTFontDescriptorRef aDescriptor); 56 57 CFDictionaryRef CreateAttrDict(bool aRightToLeft); 58 CFDictionaryRef CreateAttrDictWithoutDirection(); 59 60 static CTFontDescriptorRef CreateFontFeaturesDescriptor( 61 const std::pair<SInt16, SInt16>* aFeatures, size_t aCount); 62 63 static CTFontDescriptorRef GetFeaturesDescriptor(FeatureFlags aFeatureFlags); 64 65 // cached font descriptors, created the first time they're needed 66 static CTFontDescriptorRef sFeaturesDescriptor[kMaxFontInstances]; 67 }; 68 69 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(gfxCoreTextShaper::FeatureFlags) 70 71 #endif /* GFX_CORETEXTSHAPER_H */