tor-browser

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

gfxDWriteFonts.h (3985B)


      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_WINDOWSDWRITEFONTS_H
      7 #define GFX_WINDOWSDWRITEFONTS_H
      8 
      9 #include "mozilla/Atomics.h"
     10 #include "mozilla/MemoryReporting.h"
     11 #include "mozilla/UniquePtr.h"
     12 #include <dwrite_1.h>
     13 
     14 #include "gfxDWriteCommon.h"
     15 #include "gfxFont.h"
     16 #include "gfxUserFontSet.h"
     17 #include "nsTHashMap.h"
     18 #include "nsHashKeys.h"
     19 
     20 #include "mozilla/gfx/gfxVars.h"
     21 #include "mozilla/gfx/UnscaledFontDWrite.h"
     22 
     23 /**
     24 * \brief Class representing a font face for a font entry.
     25 */
     26 class gfxDWriteFont final : public gfxFont {
     27 public:
     28  gfxDWriteFont(const RefPtr<mozilla::gfx::UnscaledFontDWrite>& aUnscaledFont,
     29                gfxFontEntry* aFontEntry, const gfxFontStyle* aFontStyle,
     30                RefPtr<IDWriteFontFace> aFontFace = nullptr,
     31                AntialiasOption = kAntialiasDefault);
     32 
     33  static bool InitDWriteSupport();
     34 
     35  // These Update functions update gfxVars with font settings, they must only be
     36  // called in the parent process.
     37  static void UpdateSystemTextVars();
     38  static void UpdateClearTypeVars();
     39 
     40  static void SystemTextQualityChanged();
     41 
     42  gfxFont* CopyWithAntialiasOption(AntialiasOption anAAOption) const override;
     43 
     44  bool AllowSubpixelAA() const override { return mAllowManualShowGlyphs; }
     45 
     46  bool IsValid() const;
     47 
     48  IDWriteFontFace* GetFontFace();
     49 
     50  /* override Measure to add padding for antialiasing */
     51  RunMetrics Measure(const gfxTextRun* aTextRun, uint32_t aStart, uint32_t aEnd,
     52                     BoundingBoxType aBoundingBoxType,
     53                     DrawTarget* aDrawTargetForTightBoundingBox,
     54                     Spacing* aSpacing,
     55                     mozilla::gfx::ShapedTextFlags aOrientation) override;
     56 
     57  bool ProvidesGlyphWidths() const override;
     58 
     59  int32_t GetGlyphWidth(uint16_t aGID) override;
     60 
     61  bool GetGlyphBounds(uint16_t aGID, gfxRect* aBounds, bool aTight) override;
     62 
     63  void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
     64                              FontCacheSizes* aSizes) const override;
     65  void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
     66                              FontCacheSizes* aSizes) const override;
     67 
     68  FontType GetType() const override { return FONT_TYPE_DWRITE; }
     69 
     70  already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(
     71      const TextRunDrawParams& aRunParams) override;
     72 
     73  bool ShouldRoundXOffset(cairo_t* aCairo) const override;
     74 
     75 protected:
     76  ~gfxDWriteFont() override;
     77 
     78  const Metrics& GetHorizontalMetrics() const override { return mMetrics; }
     79 
     80  bool GetFakeMetricsForArialBlack(DWRITE_FONT_METRICS* aFontMetrics);
     81 
     82  void ComputeMetrics(AntialiasOption anAAOption);
     83 
     84  bool HasBitmapStrikeForSize(uint32_t aSize);
     85 
     86  gfxFloat MeasureGlyphWidth(uint16_t aGlyph);
     87 
     88  DWRITE_MEASURING_MODE GetMeasuringMode() const;
     89 
     90  static mozilla::Atomic<bool> sForceGDIClassicEnabled;
     91  bool GetForceGDIClassic() const;
     92 
     93  RefPtr<IDWriteFontFace> mFontFace;
     94  RefPtr<IDWriteFontFace1> mFontFace1;  // may be unavailable on older DWrite
     95 
     96  Metrics mMetrics;
     97 
     98  // cache of glyph widths in 16.16 fixed-point pixels
     99  mozilla::UniquePtr<nsTHashMap<nsUint32HashKey, int32_t>> mGlyphWidths;
    100 
    101  bool mUseSubpixelPositions;
    102  bool mAllowManualShowGlyphs;
    103 
    104  // Used to record the sUseClearType setting at the time mAzureScaledFont
    105  // was set up, so we can tell if it's stale and needs to be re-created.
    106  mozilla::Atomic<bool> mAzureScaledFontUsedClearType;
    107 
    108  // Cache the GDI version of the ScaledFont so that font keys and other
    109  // meta-data can remain stable even if there is thrashing between GDI and
    110  // non-GDI usage.
    111  mozilla::Atomic<mozilla::gfx::ScaledFont*> mAzureScaledFontGDI;
    112 
    113  bool UsingClearType() {
    114    return mozilla::gfx::gfxVars::SystemTextQuality() == CLEARTYPE_QUALITY;
    115  }
    116 };
    117 
    118 #endif