Bug 1799258 - Fix constexpr issue on base toolchain builds. r=gfx-reviewers,lsalzman
[gecko.git] / gfx / thebes / gfxDWriteCommon.h
blob8daf02fd14588a8999c13240ded96af4b6be65bf
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_DWRITECOMMON_H
7 #define GFX_DWRITECOMMON_H
9 // Mozilla includes
10 #include "mozilla/MemoryReporting.h"
11 #include "mozilla/FontPropertyTypes.h"
12 #include "nscore.h"
13 #include "nsCOMPtr.h"
14 #include "cairo-features.h"
15 #include "gfxFontConstants.h"
16 #include "nsTArray.h"
17 #include "gfxWindowsPlatform.h"
19 #include <windows.h>
20 #include <dwrite.h>
22 #define GFX_CLEARTYPE_PARAMS "gfx.font_rendering.cleartype_params."
23 #define GFX_CLEARTYPE_PARAMS_GAMMA "gfx.font_rendering.cleartype_params.gamma"
24 #define GFX_CLEARTYPE_PARAMS_CONTRAST \
25 "gfx.font_rendering.cleartype_params.enhanced_contrast"
26 #define GFX_CLEARTYPE_PARAMS_LEVEL \
27 "gfx.font_rendering.cleartype_params.cleartype_level"
28 #define GFX_CLEARTYPE_PARAMS_STRUCTURE \
29 "gfx.font_rendering.cleartype_params.pixel_structure"
30 #define GFX_CLEARTYPE_PARAMS_MODE \
31 "gfx.font_rendering.cleartype_params.rendering_mode"
33 #define DISPLAY1_REGISTRY_KEY \
34 HKEY_CURRENT_USER, L"Software\\Microsoft\\Avalon.Graphics\\DISPLAY1"
36 #define ENHANCED_CONTRAST_VALUE_NAME L"EnhancedContrastLevel"
38 // FIXME: This shouldn't look at constants probably.
39 static inline DWRITE_FONT_STRETCH DWriteFontStretchFromStretch(
40 mozilla::FontStretch aStretch) {
41 if (aStretch == mozilla::FontStretch::ULTRA_CONDENSED) {
42 return DWRITE_FONT_STRETCH_ULTRA_CONDENSED;
44 if (aStretch == mozilla::FontStretch::EXTRA_CONDENSED) {
45 return DWRITE_FONT_STRETCH_EXTRA_CONDENSED;
47 if (aStretch == mozilla::FontStretch::CONDENSED) {
48 return DWRITE_FONT_STRETCH_CONDENSED;
50 if (aStretch == mozilla::FontStretch::SEMI_CONDENSED) {
51 return DWRITE_FONT_STRETCH_SEMI_CONDENSED;
53 if (aStretch == mozilla::FontStretch::NORMAL) {
54 return DWRITE_FONT_STRETCH_NORMAL;
56 if (aStretch == mozilla::FontStretch::SEMI_EXPANDED) {
57 return DWRITE_FONT_STRETCH_SEMI_EXPANDED;
59 if (aStretch == mozilla::FontStretch::EXPANDED) {
60 return DWRITE_FONT_STRETCH_EXPANDED;
62 if (aStretch == mozilla::FontStretch::EXTRA_EXPANDED) {
63 return DWRITE_FONT_STRETCH_EXTRA_EXPANDED;
65 if (aStretch == mozilla::FontStretch::ULTRA_EXPANDED) {
66 return DWRITE_FONT_STRETCH_ULTRA_EXPANDED;
68 return DWRITE_FONT_STRETCH_UNDEFINED;
71 static inline mozilla::FontStretch FontStretchFromDWriteStretch(
72 DWRITE_FONT_STRETCH aStretch) {
73 switch (aStretch) {
74 case DWRITE_FONT_STRETCH_ULTRA_CONDENSED:
75 return mozilla::FontStretch::ULTRA_CONDENSED;
76 case DWRITE_FONT_STRETCH_EXTRA_CONDENSED:
77 return mozilla::FontStretch::EXTRA_CONDENSED;
78 case DWRITE_FONT_STRETCH_CONDENSED:
79 return mozilla::FontStretch::CONDENSED;
80 case DWRITE_FONT_STRETCH_SEMI_CONDENSED:
81 return mozilla::FontStretch::SEMI_CONDENSED;
82 case DWRITE_FONT_STRETCH_NORMAL:
83 return mozilla::FontStretch::NORMAL;
84 case DWRITE_FONT_STRETCH_SEMI_EXPANDED:
85 return mozilla::FontStretch::SEMI_EXPANDED;
86 case DWRITE_FONT_STRETCH_EXPANDED:
87 return mozilla::FontStretch::EXPANDED;
88 case DWRITE_FONT_STRETCH_EXTRA_EXPANDED:
89 return mozilla::FontStretch::EXTRA_EXPANDED;
90 case DWRITE_FONT_STRETCH_ULTRA_EXPANDED:
91 return mozilla::FontStretch::ULTRA_EXPANDED;
92 default:
93 return mozilla::FontStretch::NORMAL;
97 class gfxDWriteFontFileLoader : public IDWriteFontFileLoader {
98 public:
99 gfxDWriteFontFileLoader() {}
101 // IUnknown interface
102 IFACEMETHOD(QueryInterface)(IID const& iid, OUT void** ppObject) {
103 if (iid == __uuidof(IDWriteFontFileLoader)) {
104 *ppObject = static_cast<IDWriteFontFileLoader*>(this);
105 return S_OK;
106 } else if (iid == __uuidof(IUnknown)) {
107 *ppObject = static_cast<IUnknown*>(this);
108 return S_OK;
109 } else {
110 return E_NOINTERFACE;
114 IFACEMETHOD_(ULONG, AddRef)() { return 1; }
116 IFACEMETHOD_(ULONG, Release)() { return 1; }
118 // IDWriteFontFileLoader methods
120 * Important! Note the key here -has- to be a pointer to a uint64_t.
122 virtual HRESULT STDMETHODCALLTYPE CreateStreamFromKey(
123 void const* fontFileReferenceKey, UINT32 fontFileReferenceKeySize,
124 OUT IDWriteFontFileStream** fontFileStream);
127 * Gets the singleton loader instance. Note that when using this font
128 * loader, the key must be a pointer to a unint64_t.
130 static IDWriteFontFileLoader* Instance() {
131 if (!mInstance) {
132 mInstance = new gfxDWriteFontFileLoader();
133 mozilla::gfx::Factory::GetDWriteFactory()->RegisterFontFileLoader(
134 mInstance);
136 return mInstance;
140 * Creates a IDWriteFontFile and IDWriteFontFileStream from aFontData.
141 * The data from aFontData will be copied internally, so the caller
142 * is free to dispose of it once this method returns.
144 * @param aFontData the font data for the custom font file
145 * @param aLength length of the font data
146 * @param aFontFile out param for the created font file
147 * @param aFontFileStream out param for the corresponding stream
148 * @return HRESULT of internal calls
150 static HRESULT CreateCustomFontFile(const uint8_t* aFontData,
151 uint32_t aLength,
152 IDWriteFontFile** aFontFile,
153 IDWriteFontFileStream** aFontFileStream);
155 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
157 private:
158 static IDWriteFontFileLoader* mInstance;
161 #endif /* GFX_DWRITECOMMON_H */