Bug 1811847 [wpt PR 38108] - Update wpt metadata, a=testonly
[gecko.git] / gfx / thebes / gfxMacFont.h
blob850da79f9eff69cebf202c6dfe11b583d614d13e
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GFX_MACFONT_H
7 #define GFX_MACFONT_H
9 #include "mozilla/MemoryReporting.h"
10 #include "gfxFont.h"
11 #include <ApplicationServices/ApplicationServices.h>
13 #include "mozilla/gfx/UnscaledFontMac.h"
15 class MacOSFontEntry;
17 class gfxMacFont final : public gfxFont {
18 public:
19 gfxMacFont(const RefPtr<mozilla::gfx::UnscaledFontMac>& aUnscaledFont, MacOSFontEntry* aFontEntry,
20 const gfxFontStyle* aFontStyle);
22 CGFontRef GetCGFontRef() const { return mCGFont; }
24 /* override Measure to add padding for antialiasing */
25 RunMetrics Measure(const gfxTextRun* aTextRun, uint32_t aStart, uint32_t aEnd,
26 BoundingBoxType aBoundingBoxType, DrawTarget* aDrawTargetForTightBoundingBox,
27 Spacing* aSpacing, mozilla::gfx::ShapedTextFlags aOrientation) override;
29 // We need to provide hinted (non-linear) glyph widths if using a font
30 // with embedded color bitmaps (Apple Color Emoji), as Core Text renders
31 // the glyphs with non-linear scaling at small pixel sizes.
32 bool ProvidesGlyphWidths() const override {
33 return mVariationFont || mFontEntry->HasFontTable(TRUETYPE_TAG('s', 'b', 'i', 'x'));
36 int32_t GetGlyphWidth(uint16_t aGID) override;
38 bool GetGlyphBounds(uint16_t aGID, gfxRect* aBounds, bool aTight) override;
40 already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(
41 const TextRunDrawParams& aRunParams) override;
43 bool ShouldRoundXOffset(cairo_t* aCairo) const override;
45 void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
46 FontCacheSizes* aSizes) const override;
47 void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
48 FontCacheSizes* aSizes) const override;
50 FontType GetType() const override { return FONT_TYPE_MAC; }
52 bool UseNativeColrFontSupport() const override;
54 // Helper to create a CTFont from a CGFont, with optional font descriptor
55 // (for features), and copying any variations that were set on the CGFont.
56 // This is public so that gfxCoreTextShaper can also use it.
57 static CTFontRef CreateCTFontFromCGFontWithVariations(CGFontRef aCGFont, CGFloat aSize,
58 bool aInstalledFont,
59 CTFontDescriptorRef aFontDesc = nullptr);
61 protected:
62 ~gfxMacFont() override;
64 const Metrics& GetHorizontalMetrics() const override { return mMetrics; }
66 // override to prefer CoreText shaping with fonts that depend on AAT
67 bool ShapeText(DrawTarget* aDrawTarget, const char16_t* aText, uint32_t aOffset, uint32_t aLength,
68 Script aScript, nsAtom* aLanguage, bool aVertical, RoundingFlags aRounding,
69 gfxShapedText* aShapedText) override;
71 void InitMetrics();
72 void InitMetricsFromPlatform();
74 // Get width and glyph ID for a character; uses aConvFactor
75 // to convert font units as returned by CG to actual dimensions
76 gfxFloat GetCharWidth(CFDataRef aCmap, char16_t aUniChar, uint32_t* aGlyphID,
77 gfxFloat aConvFactor);
79 // a strong reference to the CoreGraphics font
80 CGFontRef mCGFont;
82 // a Core Text font reference, created only if we're using CT to measure
83 // glyph widths; otherwise null.
84 CTFontRef mCTFont;
86 mozilla::UniquePtr<gfxFontShaper> mCoreTextShaper;
88 Metrics mMetrics;
89 nscolor mFontSmoothingBackgroundColor;
91 bool mVariationFont; // true if font has OpenType variations
94 #endif /* GFX_MACFONT_H */