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