tor-browser

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

UnscaledFontMac.h (3417B)


      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/. */
      6 
      7 #ifndef MOZILLA_GFX_UNSCALEDFONTMAC_H_
      8 #define MOZILLA_GFX_UNSCALEDFONTMAC_H_
      9 
     10 #ifdef MOZ_WIDGET_COCOA
     11 #  include <ApplicationServices/ApplicationServices.h>
     12 #else
     13 #  include <CoreGraphics/CoreGraphics.h>
     14 #  include <CoreText/CoreText.h>
     15 #endif
     16 
     17 #include "2D.h"
     18 
     19 namespace mozilla {
     20 namespace gfx {
     21 
     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);
     28  }
     29  explicit UnscaledFontMac(CTFontDescriptorRef aFontDesc, CGFontRef aFont,
     30                           bool aIsDataFont = false)
     31      : mFontDesc(aFontDesc), mFont(aFont), mIsDataFont(aIsDataFont) {
     32    CFRetain(mFontDesc);
     33    CFRetain(mFont);
     34  }
     35 
     36  virtual ~UnscaledFontMac() {
     37    if (mCTAxesCache) {
     38      CFRelease(mCTAxesCache);
     39    }
     40    if (mCGAxesCache) {
     41      CFRelease(mCGAxesCache);
     42    }
     43    if (mFontDesc) {
     44      CFRelease(mFontDesc);
     45    }
     46    if (mFont) {
     47      CFRelease(mFont);
     48    }
     49  }
     50 
     51  FontType GetType() const override { return FontType::MAC; }
     52 
     53  CGFontRef GetFont() const { return mFont; }
     54 
     55  bool GetFontFileData(FontFileDataOutput aDataCallback, void* aBaton) override;
     56 
     57  bool IsDataFont() const { return mIsDataFont; }
     58 
     59  already_AddRefed<ScaledFont> CreateScaledFont(
     60      Float aGlyphSize, const uint8_t* aInstanceData,
     61      uint32_t aInstanceDataLength, const FontVariation* aVariations,
     62      uint32_t aNumVariations) override;
     63 
     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;
     68 
     69  static CGFontRef CreateCGFontWithVariations(CGFontRef aFont,
     70                                              CFArrayRef& aCGAxesCache,
     71                                              CFArrayRef& aCTAxesCache,
     72                                              uint32_t aVariationCount,
     73                                              const FontVariation* aVariations);
     74 
     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;
     80 
     81  CFArrayRef& CGAxesCache() { return mCGAxesCache; }
     82  CFArrayRef& CTAxesCache() { return mCTAxesCache; }
     83 
     84  static already_AddRefed<UnscaledFont> CreateFromFontDescriptor(
     85      const uint8_t* aData, uint32_t aDataLength, uint32_t aIndex);
     86 
     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;
     93 };
     94 
     95 }  // namespace gfx
     96 }  // namespace mozilla
     97 
     98 #endif /* MOZILLA_GFX_UNSCALEDFONTMAC_H_ */