1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef MOZILLA_GFX_UNSCALEDFONTMAC_H_ 8 #define MOZILLA_GFX_UNSCALEDFONTMAC_H_ 9 10 #ifdef MOZ_WIDGET_COCOA 11 # include <ApplicationServices/ApplicationServices.h> 12 #else 13 # include <CoreGraphics/CoreGraphics.h> 14 # include <CoreText/CoreText.h> 15 #endif 16 17 #include "2D.h" 18 19 namespace mozilla { 20 namespace gfx { 21 22 class UnscaledFontMac final : public UnscaledFont { 23 public: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(UnscaledFontMac,override)24 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(UnscaledFontMac, override) 25 explicit UnscaledFontMac(CGFontRef aFont, bool aIsDataFont = false) 26 : mFont(aFont), mIsDataFont(aIsDataFont) { 27 CFRetain(mFont); 28 } 29 explicit UnscaledFontMac(CTFontDescriptorRef aFontDesc, CGFontRef aFont, 30 bool aIsDataFont = false) mFontDesc(aFontDesc)31 : mFontDesc(aFontDesc), mFont(aFont), mIsDataFont(aIsDataFont) { 32 CFRetain(mFontDesc); 33 CFRetain(mFont); 34 } 35 ~UnscaledFontMac()36 virtual ~UnscaledFontMac() { 37 if (mCTAxesCache) { 38 CFRelease(mCTAxesCache); 39 } 40 if (mCGAxesCache) { 41 CFRelease(mCGAxesCache); 42 } 43 if (mFontDesc) { 44 CFRelease(mFontDesc); 45 } 46 if (mFont) { 47 CFRelease(mFont); 48 } 49 } 50 GetType()51 FontType GetType() const override { return FontType::MAC; } 52 GetFont()53 CGFontRef GetFont() const { return mFont; } 54 55 bool GetFontFileData(FontFileDataOutput aDataCallback, void* aBaton) override; 56 IsDataFont()57 bool IsDataFont() const { return mIsDataFont; } 58 59 already_AddRefed<ScaledFont> CreateScaledFont( 60 Float aGlyphSize, const uint8_t* aInstanceData, 61 uint32_t aInstanceDataLength, const FontVariation* aVariations, 62 uint32_t aNumVariations) override; 63 64 already_AddRefed<ScaledFont> CreateScaledFontFromWRFont( 65 Float aGlyphSize, const wr::FontInstanceOptions* aOptions, 66 const wr::FontInstancePlatformOptions* aPlatformOptions, 67 const FontVariation* aVariations, uint32_t aNumVariations) override; 68 69 static CGFontRef CreateCGFontWithVariations(CGFontRef aFont, 70 CFArrayRef& aCGAxesCache, 71 CFArrayRef& aCTAxesCache, 72 uint32_t aVariationCount, 73 const FontVariation* aVariations); 74 75 bool GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton) override; 76 CGAxesCache()77 CFArrayRef& CGAxesCache() { return mCGAxesCache; } CTAxesCache()78 CFArrayRef& CTAxesCache() { return mCTAxesCache; } 79 80 static already_AddRefed<UnscaledFont> CreateFromFontDescriptor( 81 const uint8_t* aData, uint32_t aDataLength, uint32_t aIndex); 82 83 private: 84 CTFontDescriptorRef mFontDesc = nullptr; 85 CGFontRef mFont = nullptr; 86 CFArrayRef mCGAxesCache = nullptr; // Cached arrays of variation axis details 87 CFArrayRef mCTAxesCache = nullptr; 88 bool mIsDataFont; 89 }; 90 91 } // namespace gfx 92 } // namespace mozilla 93 94 #endif /* MOZILLA_GFX_UNSCALEDFONTMAC_H_ */ 95