tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

gfxMacFont.h (3298B)


      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/. */
      5 
      6 #ifndef GFX_MACFONT_H
      7 #define GFX_MACFONT_H
      8 
      9 #include "mozilla/MemoryReporting.h"
     10 #include "gfxFont.h"
     11 #include <CoreText/CoreText.h>
     12 
     13 #include "mozilla/gfx/UnscaledFontMac.h"
     14 
     15 class CTFontEntry;
     16 
     17 class gfxMacFont final : public gfxFont {
     18 public:
     19  gfxMacFont(const RefPtr<mozilla::gfx::UnscaledFontMac>& aUnscaledFont,
     20             CTFontEntry* aFontEntry, const gfxFontStyle* aFontStyle);
     21 
     22  CGFontRef GetCGFontRef() const { return mCGFont; }
     23 
     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;
     30 
     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'));
     37  }
     38 
     39  int32_t GetGlyphWidth(uint16_t aGID) override;
     40 
     41  bool GetGlyphBounds(uint16_t aGID, gfxRect* aBounds, bool aTight) override;
     42 
     43  already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(
     44      const TextRunDrawParams& aRunParams) override;
     45 
     46  bool ShouldRoundXOffset(cairo_t* aCairo) const override;
     47 
     48  void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
     49                              FontCacheSizes* aSizes) const override;
     50  void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
     51                              FontCacheSizes* aSizes) const override;
     52 
     53  FontType GetType() const override { return FONT_TYPE_MAC; }
     54 
     55  bool UseNativeColrFontSupport() const override;
     56 
     57 protected:
     58  ~gfxMacFont() override;
     59 
     60  const Metrics& GetHorizontalMetrics() const override { return mMetrics; }
     61 
     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;
     67 
     68  void InitMetrics();
     69  void InitMetricsFromPlatform();
     70 
     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);
     75 
     76  // a strong reference to the CoreGraphics font
     77  CGFontRef mCGFont;
     78 
     79  // a Core Text font reference, created only if we're using CT to measure
     80  // glyph widths; otherwise null.
     81  CTFontRef mCTFont;
     82 
     83  mozilla::UniquePtr<gfxFontShaper> mCoreTextShaper;
     84 
     85  Metrics mMetrics;
     86 
     87  bool mVariationFont;  // true if font has OpenType variations
     88 };
     89 
     90 #endif /* GFX_MACFONT_H */