ScaledFontMac.h (3466B)
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_SCALEDFONTMAC_H_ 8 #define MOZILLA_GFX_SCALEDFONTMAC_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 #include "ScaledFontBase.h" 20 21 namespace mozilla { 22 namespace gfx { 23 24 // Utility to create a CTFont from a CGFont, copying any variations that were 25 // set on the original CGFont, and applying additional attributes from aDesc 26 // (which may be NULL). 27 // Exposed here because it is also used by gfxMacFont and gfxCoreTextShaper. 28 CTFontRef CreateCTFontFromCGFontWithVariations( 29 CGFontRef aCGFont, CGFloat aSize, bool aInstalledFont, 30 CTFontDescriptorRef aFontDesc = nullptr); 31 32 class UnscaledFontMac; 33 34 class ScaledFontMac : public ScaledFontBase { 35 public: 36 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFontMac, override) 37 ScaledFontMac(CGFontRef aFont, const RefPtr<UnscaledFont>& aUnscaledFont, 38 Float aSize, bool aOwnsFont = false, 39 bool aUseFontSmoothing = true, bool aApplySyntheticBold = false, 40 bool aHasColorGlyphs = false); 41 ScaledFontMac(CTFontRef aFont, const RefPtr<UnscaledFont>& aUnscaledFont, 42 bool aUseFontSmoothing = true, bool aApplySyntheticBold = false, 43 bool aHasColorGlyphs = false); 44 ~ScaledFontMac(); 45 46 FontType GetType() const override { return FontType::MAC; } 47 SkTypeface* CreateSkTypeface() override; 48 void SetupSkFontDrawOptions(SkFont& aFont) override; 49 already_AddRefed<Path> GetPathForGlyphs(const GlyphBuffer& aBuffer, 50 const DrawTarget* aTarget) override; 51 52 bool GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton) override; 53 54 bool GetWRFontInstanceOptions( 55 Maybe<wr::FontInstanceOptions>* aOutOptions, 56 Maybe<wr::FontInstancePlatformOptions>* aOutPlatformOptions, 57 std::vector<FontVariation>* aOutVariations) override; 58 59 bool CanSerialize() override { return true; } 60 61 bool MayUseBitmaps() override { return mHasColorGlyphs; } 62 63 bool UseSubpixelPosition() const override { return true; } 64 65 bool UseFontSmoothing() const { return mUseFontSmoothing; } 66 67 cairo_font_face_t* CreateCairoFontFace( 68 cairo_font_options_t* aFontOptions) override; 69 70 private: 71 friend class DrawTargetSkia; 72 friend class UnscaledFontMac; 73 74 CGFontRef mFont; 75 CTFontRef 76 mCTFont; // only created if CTFontDrawGlyphs is available, otherwise null 77 78 bool mUseFontSmoothing; 79 bool mApplySyntheticBold; 80 bool mHasColorGlyphs; 81 82 struct InstanceData { 83 explicit InstanceData(ScaledFontMac* aScaledFont) 84 : mUseFontSmoothing(aScaledFont->mUseFontSmoothing), 85 mApplySyntheticBold(aScaledFont->mApplySyntheticBold), 86 mHasColorGlyphs(aScaledFont->mHasColorGlyphs) {} 87 88 InstanceData(const wr::FontInstanceOptions* aOptions, 89 const wr::FontInstancePlatformOptions* aPlatformOptions); 90 91 bool mUseFontSmoothing; 92 bool mApplySyntheticBold; 93 bool mHasColorGlyphs; 94 }; 95 }; 96 97 } // namespace gfx 98 } // namespace mozilla 99 100 #endif /* MOZILLA_GFX_SCALEDFONTMAC_H_ */