no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / gfx / 2d / UnscaledFontMac.h
blob72524feeb4716b24688ce8b19ec45d685989980c
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 // Generate a font descriptor to send to WebRender. The descriptor consists
76 // of a string that concatenates the PostScript name of the font and the path
77 // to the font file, and an "index" that indicates the length of the psname
78 // part of the string (= starting offset of the path).
79 bool GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton) override;
81 CFArrayRef& CGAxesCache() { return mCGAxesCache; }
82 CFArrayRef& CTAxesCache() { return mCTAxesCache; }
84 static already_AddRefed<UnscaledFont> CreateFromFontDescriptor(
85 const uint8_t* aData, uint32_t aDataLength, uint32_t aIndex);
87 private:
88 CTFontDescriptorRef mFontDesc = nullptr;
89 CGFontRef mFont = nullptr;
90 CFArrayRef mCGAxesCache = nullptr; // Cached arrays of variation axis details
91 CFArrayRef mCTAxesCache = nullptr;
92 bool mIsDataFont;
95 } // namespace gfx
96 } // namespace mozilla
98 #endif /* MOZILLA_GFX_UNSCALEDFONTMAC_H_ */