Bug 1860959 [wpt PR 42048] - [webaudio] Convert test to testharness, a=testonly
[gecko.git] / gfx / 2d / UnscaledFontMac.h
blobd958e59fde75bd22281f1c7805bd36ee96150b3a
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_UNSCALEDFONTMAC_H_
8 #define MOZILLA_GFX_UNSCALEDFONTMAC_H_
10 #ifdef MOZ_WIDGET_COCOA
11 # include <ApplicationServices/ApplicationServices.h>
12 #else
13 # include <CoreGraphics/CoreGraphics.h>
14 # include <CoreText/CoreText.h>
15 #endif
17 #include "2D.h"
19 namespace mozilla {
20 namespace gfx {
22 class UnscaledFontMac final : public UnscaledFont {
23 public:
24 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(UnscaledFontMac, override)
25 explicit UnscaledFontMac(CGFontRef aFont, bool aIsDataFont = false)
26 : mFont(aFont), mIsDataFont(aIsDataFont) {
27 CFRetain(mFont);
29 explicit UnscaledFontMac(CTFontDescriptorRef aFontDesc, CGFontRef aFont,
30 bool aIsDataFont = false)
31 : mFontDesc(aFontDesc), mFont(aFont), mIsDataFont(aIsDataFont) {
32 CFRetain(mFontDesc);
33 CFRetain(mFont);
36 virtual ~UnscaledFontMac() {
37 if (mCTAxesCache) {
38 CFRelease(mCTAxesCache);
40 if (mCGAxesCache) {
41 CFRelease(mCGAxesCache);
43 if (mFontDesc) {
44 CFRelease(mFontDesc);
46 if (mFont) {
47 CFRelease(mFont);
51 FontType GetType() const override { return FontType::MAC; }
53 CGFontRef GetFont() const { return mFont; }
55 bool GetFontFileData(FontFileDataOutput aDataCallback, void* aBaton) override;
57 bool IsDataFont() const { return mIsDataFont; }
59 already_AddRefed<ScaledFont> CreateScaledFont(
60 Float aGlyphSize, const uint8_t* aInstanceData,
61 uint32_t aInstanceDataLength, const FontVariation* aVariations,
62 uint32_t aNumVariations) override;
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;
69 static CGFontRef CreateCGFontWithVariations(CGFontRef aFont,
70 CFArrayRef& aCGAxesCache,
71 CFArrayRef& aCTAxesCache,
72 uint32_t aVariationCount,
73 const FontVariation* aVariations);
75 bool GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton) override;
77 CFArrayRef& CGAxesCache() { return mCGAxesCache; }
78 CFArrayRef& CTAxesCache() { return mCTAxesCache; }
80 static already_AddRefed<UnscaledFont> CreateFromFontDescriptor(
81 const uint8_t* aData, uint32_t aDataLength, uint32_t aIndex);
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;
91 } // namespace gfx
92 } // namespace mozilla
94 #endif /* MOZILLA_GFX_UNSCALEDFONTMAC_H_ */