Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / gfx / thebes / gfxMacFont.h
blob051c4ea675b817c98bf93be187fbef59c409685a
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 <CoreText/CoreText.h>
13 #include "mozilla/gfx/UnscaledFontMac.h"
15 class CTFontEntry;
17 class gfxMacFont final : public gfxFont {
18 public:
19 gfxMacFont(const RefPtr<mozilla::gfx::UnscaledFontMac>& aUnscaledFont,
20 CTFontEntry* aFontEntry, 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,
27 DrawTarget* aDrawTargetForTightBoundingBox,
28 Spacing* aSpacing,
29 mozilla::gfx::ShapedTextFlags aOrientation) override;
31 // We need to provide hinted (non-linear) glyph widths if using a font
32 // with embedded color bitmaps (Apple Color Emoji), as Core Text renders
33 // the glyphs with non-linear scaling at small pixel sizes.
34 bool ProvidesGlyphWidths() const override {
35 return mVariationFont ||
36 mFontEntry->HasFontTable(TRUETYPE_TAG('s', 'b', 'i', 'x'));
39 int32_t GetGlyphWidth(uint16_t aGID) override;
41 bool GetGlyphBounds(uint16_t aGID, gfxRect* aBounds, bool aTight) override;
43 already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(
44 const TextRunDrawParams& aRunParams) override;
46 bool ShouldRoundXOffset(cairo_t* aCairo) const override;
48 void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
49 FontCacheSizes* aSizes) const override;
50 void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
51 FontCacheSizes* aSizes) const override;
53 FontType GetType() const override { return FONT_TYPE_MAC; }
55 bool UseNativeColrFontSupport() const override;
57 protected:
58 ~gfxMacFont() override;
60 const Metrics& GetHorizontalMetrics() const override { return mMetrics; }
62 // override to prefer CoreText shaping with fonts that depend on AAT
63 bool ShapeText(DrawTarget* aDrawTarget, const char16_t* aText,
64 uint32_t aOffset, uint32_t aLength, Script aScript,
65 nsAtom* aLanguage, bool aVertical, RoundingFlags aRounding,
66 gfxShapedText* aShapedText) override;
68 void InitMetrics();
69 void InitMetricsFromPlatform();
71 // Get width and glyph ID for a character; uses aConvFactor
72 // to convert font units as returned by CG to actual dimensions
73 gfxFloat GetCharWidth(CFDataRef aCmap, char16_t aUniChar, uint32_t* aGlyphID,
74 gfxFloat aConvFactor);
76 // a strong reference to the CoreGraphics font
77 CGFontRef mCGFont;
79 // a Core Text font reference, created only if we're using CT to measure
80 // glyph widths; otherwise null.
81 CTFontRef mCTFont;
83 mozilla::UniquePtr<gfxFontShaper> mCoreTextShaper;
85 Metrics mMetrics;
87 bool mVariationFont; // true if font has OpenType variations
90 #endif /* GFX_MACFONT_H */