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/. */
7 #ifndef MOZILLA_GFX_SCALEDFONTMAC_H_
8 #define MOZILLA_GFX_SCALEDFONTMAC_H_
10 #ifdef MOZ_WIDGET_COCOA
11 # include <ApplicationServices/ApplicationServices.h>
13 # include <CoreGraphics/CoreGraphics.h>
14 # include <CoreText/CoreText.h>
19 #include "ScaledFontBase.h"
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);
32 class UnscaledFontMac
;
34 class ScaledFontMac
: public ScaledFontBase
{
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);
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
;
52 bool GetFontInstanceData(FontInstanceDataOutput aCb
, void* aBaton
) override
;
54 bool GetWRFontInstanceOptions(
55 Maybe
<wr::FontInstanceOptions
>* aOutOptions
,
56 Maybe
<wr::FontInstancePlatformOptions
>* aOutPlatformOptions
,
57 std::vector
<FontVariation
>* aOutVariations
) override
;
59 bool CanSerialize() override
{ return true; }
61 bool MayUseBitmaps() override
{ return mHasColorGlyphs
; }
63 bool UseSubpixelPosition() const override
{ return true; }
65 cairo_font_face_t
* CreateCairoFontFace(
66 cairo_font_options_t
* aFontOptions
) override
;
69 friend class DrawTargetSkia
;
70 friend class UnscaledFontMac
;
74 mCTFont
; // only created if CTFontDrawGlyphs is available, otherwise null
76 bool mUseFontSmoothing
;
77 bool mApplySyntheticBold
;
81 explicit InstanceData(ScaledFontMac
* aScaledFont
)
82 : mUseFontSmoothing(aScaledFont
->mUseFontSmoothing
),
83 mApplySyntheticBold(aScaledFont
->mApplySyntheticBold
),
84 mHasColorGlyphs(aScaledFont
->mHasColorGlyphs
) {}
86 InstanceData(const wr::FontInstanceOptions
* aOptions
,
87 const wr::FontInstancePlatformOptions
* aPlatformOptions
);
89 bool mUseFontSmoothing
;
90 bool mApplySyntheticBold
;
96 } // namespace mozilla
98 #endif /* MOZILLA_GFX_SCALEDFONTMAC_H_ */