1 | /* |
2 | * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
3 | * (C) 2000 Antti Koivisto (koivisto@kde.org) |
4 | * (C) 2000 Dirk Mueller (mueller@kde.org) |
5 | * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights reserved. |
6 | * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> |
7 | * |
8 | * This library is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; either |
11 | * version 2 of the License, or (at your option) any later version. |
12 | * |
13 | * This library is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * Library General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU Library General Public License |
19 | * along with this library; see the file COPYING.LIother.m_ If not, write to |
20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | * Boston, MA 02110-1301, USm_ |
22 | * |
23 | */ |
24 | |
25 | #pragma once |
26 | |
27 | #include "FontSelectionAlgorithm.h" |
28 | #include "FontTaggedSettings.h" |
29 | #include "TextFlags.h" |
30 | #include "WebKitFontFamilyNames.h" |
31 | #include <unicode/uscript.h> |
32 | #include <wtf/MathExtras.h> |
33 | |
34 | #define USE_PLATFORM_SYSTEM_FALLBACK_LIST ((PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)) |
35 | |
36 | namespace WebCore { |
37 | |
38 | using namespace WebKitFontFamilyNames; |
39 | |
40 | class FontDescription { |
41 | public: |
42 | WEBCORE_EXPORT FontDescription(); |
43 | |
44 | bool operator==(const FontDescription&) const; |
45 | bool operator!=(const FontDescription& other) const { return !(*this == other); } |
46 | |
47 | float computedSize() const { return m_computedSize; } |
48 | unsigned computedPixelSize() const { return unsigned(m_computedSize + 0.5f); } |
49 | Optional<FontSelectionValue> italic() const { return m_fontSelectionRequest.slope; } |
50 | FontSelectionValue stretch() const { return m_fontSelectionRequest.width; } |
51 | FontSelectionValue weight() const { return m_fontSelectionRequest.weight; } |
52 | FontSelectionRequest fontSelectionRequest() const { return m_fontSelectionRequest; } |
53 | FontRenderingMode renderingMode() const { return static_cast<FontRenderingMode>(m_renderingMode); } |
54 | TextRenderingMode textRenderingMode() const { return static_cast<TextRenderingMode>(m_textRendering); } |
55 | UScriptCode script() const { return static_cast<UScriptCode>(m_script); } |
56 | const AtomicString& locale() const { return m_locale; } |
57 | |
58 | FontOrientation orientation() const { return static_cast<FontOrientation>(m_orientation); } |
59 | NonCJKGlyphOrientation nonCJKGlyphOrientation() const { return static_cast<NonCJKGlyphOrientation>(m_nonCJKGlyphOrientation); } |
60 | FontWidthVariant widthVariant() const { return static_cast<FontWidthVariant>(m_widthVariant); } |
61 | const FontFeatureSettings& featureSettings() const { return m_featureSettings; } |
62 | const FontVariationSettings& variationSettings() const { return m_variationSettings; } |
63 | FontSynthesis fontSynthesis() const { return static_cast<FontSynthesis>(m_fontSynthesis); } |
64 | FontVariantLigatures variantCommonLigatures() const { return static_cast<FontVariantLigatures>(m_variantCommonLigatures); } |
65 | FontVariantLigatures variantDiscretionaryLigatures() const { return static_cast<FontVariantLigatures>(m_variantDiscretionaryLigatures); } |
66 | FontVariantLigatures variantHistoricalLigatures() const { return static_cast<FontVariantLigatures>(m_variantHistoricalLigatures); } |
67 | FontVariantLigatures variantContextualAlternates() const { return static_cast<FontVariantLigatures>(m_variantContextualAlternates); } |
68 | FontVariantPosition variantPosition() const { return static_cast<FontVariantPosition>(m_variantPosition); } |
69 | FontVariantCaps variantCaps() const { return static_cast<FontVariantCaps>(m_variantCaps); } |
70 | FontVariantNumericFigure variantNumericFigure() const { return static_cast<FontVariantNumericFigure>(m_variantNumericFigure); } |
71 | FontVariantNumericSpacing variantNumericSpacing() const { return static_cast<FontVariantNumericSpacing>(m_variantNumericSpacing); } |
72 | FontVariantNumericFraction variantNumericFraction() const { return static_cast<FontVariantNumericFraction>(m_variantNumericFraction); } |
73 | FontVariantNumericOrdinal variantNumericOrdinal() const { return static_cast<FontVariantNumericOrdinal>(m_variantNumericOrdinal); } |
74 | FontVariantNumericSlashedZero variantNumericSlashedZero() const { return static_cast<FontVariantNumericSlashedZero>(m_variantNumericSlashedZero); } |
75 | FontVariantAlternates variantAlternates() const { return static_cast<FontVariantAlternates>(m_variantAlternates); } |
76 | FontVariantEastAsianVariant variantEastAsianVariant() const { return static_cast<FontVariantEastAsianVariant>(m_variantEastAsianVariant); } |
77 | FontVariantEastAsianWidth variantEastAsianWidth() const { return static_cast<FontVariantEastAsianWidth>(m_variantEastAsianWidth); } |
78 | FontVariantEastAsianRuby variantEastAsianRuby() const { return static_cast<FontVariantEastAsianRuby>(m_variantEastAsianRuby); } |
79 | FontVariantSettings variantSettings() const |
80 | { |
81 | return { variantCommonLigatures(), |
82 | variantDiscretionaryLigatures(), |
83 | variantHistoricalLigatures(), |
84 | variantContextualAlternates(), |
85 | variantPosition(), |
86 | variantCaps(), |
87 | variantNumericFigure(), |
88 | variantNumericSpacing(), |
89 | variantNumericFraction(), |
90 | variantNumericOrdinal(), |
91 | variantNumericSlashedZero(), |
92 | variantAlternates(), |
93 | variantEastAsianVariant(), |
94 | variantEastAsianWidth(), |
95 | variantEastAsianRuby() }; |
96 | } |
97 | FontOpticalSizing opticalSizing() const { return static_cast<FontOpticalSizing>(m_opticalSizing); } |
98 | FontStyleAxis fontStyleAxis() const { return m_fontStyleAxis ? FontStyleAxis::ital : FontStyleAxis::slnt; } |
99 | AllowUserInstalledFonts shouldAllowUserInstalledFonts() const { return static_cast<AllowUserInstalledFonts>(m_shouldAllowUserInstalledFonts); } |
100 | |
101 | void setComputedSize(float s) { m_computedSize = clampToFloat(s); } |
102 | void setItalic(Optional<FontSelectionValue> italic) { m_fontSelectionRequest.slope = italic; } |
103 | void setStretch(FontSelectionValue stretch) { m_fontSelectionRequest.width = stretch; } |
104 | void setIsItalic(bool isItalic) { setItalic(isItalic ? Optional<FontSelectionValue> { italicValue() } : Optional<FontSelectionValue> { }); } |
105 | void setWeight(FontSelectionValue weight) { m_fontSelectionRequest.weight = weight; } |
106 | void setRenderingMode(FontRenderingMode mode) { m_renderingMode = static_cast<unsigned>(mode); } |
107 | void setTextRenderingMode(TextRenderingMode rendering) { m_textRendering = static_cast<unsigned>(rendering); } |
108 | void setOrientation(FontOrientation orientation) { m_orientation = static_cast<unsigned>(orientation); } |
109 | void setNonCJKGlyphOrientation(NonCJKGlyphOrientation orientation) { m_nonCJKGlyphOrientation = static_cast<unsigned>(orientation); } |
110 | void setWidthVariant(FontWidthVariant widthVariant) { m_widthVariant = static_cast<unsigned>(widthVariant); } // Make sure new callers of this sync with FontPlatformData::isForTextCombine()! |
111 | void setLocale(const AtomicString&); |
112 | void setFeatureSettings(FontFeatureSettings&& settings) { m_featureSettings = WTFMove(settings); } |
113 | #if ENABLE(VARIATION_FONTS) |
114 | void setVariationSettings(FontVariationSettings&& settings) { m_variationSettings = WTFMove(settings); } |
115 | #endif |
116 | void setFontSynthesis(FontSynthesis fontSynthesis) { m_fontSynthesis = fontSynthesis; } |
117 | void setVariantCommonLigatures(FontVariantLigatures variant) { m_variantCommonLigatures = static_cast<unsigned>(variant); } |
118 | void setVariantDiscretionaryLigatures(FontVariantLigatures variant) { m_variantDiscretionaryLigatures = static_cast<unsigned>(variant); } |
119 | void setVariantHistoricalLigatures(FontVariantLigatures variant) { m_variantHistoricalLigatures = static_cast<unsigned>(variant); } |
120 | void setVariantContextualAlternates(FontVariantLigatures variant) { m_variantContextualAlternates = static_cast<unsigned>(variant); } |
121 | void setVariantPosition(FontVariantPosition variant) { m_variantPosition = static_cast<unsigned>(variant); } |
122 | void setVariantCaps(FontVariantCaps variant) { m_variantCaps = static_cast<unsigned>(variant); } |
123 | void setVariantNumericFigure(FontVariantNumericFigure variant) { m_variantNumericFigure = static_cast<unsigned>(variant); } |
124 | void setVariantNumericSpacing(FontVariantNumericSpacing variant) { m_variantNumericSpacing = static_cast<unsigned>(variant); } |
125 | void setVariantNumericFraction(FontVariantNumericFraction variant) { m_variantNumericFraction = static_cast<unsigned>(variant); } |
126 | void setVariantNumericOrdinal(FontVariantNumericOrdinal variant) { m_variantNumericOrdinal = static_cast<unsigned>(variant); } |
127 | void setVariantNumericSlashedZero(FontVariantNumericSlashedZero variant) { m_variantNumericSlashedZero = static_cast<unsigned>(variant); } |
128 | void setVariantAlternates(FontVariantAlternates variant) { m_variantAlternates = static_cast<unsigned>(variant); } |
129 | void setVariantEastAsianVariant(FontVariantEastAsianVariant variant) { m_variantEastAsianVariant = static_cast<unsigned>(variant); } |
130 | void setVariantEastAsianWidth(FontVariantEastAsianWidth variant) { m_variantEastAsianWidth = static_cast<unsigned>(variant); } |
131 | void setVariantEastAsianRuby(FontVariantEastAsianRuby variant) { m_variantEastAsianRuby = static_cast<unsigned>(variant); } |
132 | void setOpticalSizing(FontOpticalSizing sizing) { m_opticalSizing = static_cast<unsigned>(sizing); } |
133 | void setFontStyleAxis(FontStyleAxis axis) { m_fontStyleAxis = axis == FontStyleAxis::ital; } |
134 | void setShouldAllowUserInstalledFonts(AllowUserInstalledFonts shouldAllowUserInstalledFonts) { m_shouldAllowUserInstalledFonts = static_cast<unsigned>(shouldAllowUserInstalledFonts); } |
135 | |
136 | static AtomicString platformResolveGenericFamily(UScriptCode, const AtomicString& locale, const AtomicString& familyName); |
137 | |
138 | private: |
139 | // FIXME: Investigate moving these into their own object on the heap (to save memory). |
140 | FontFeatureSettings m_featureSettings; |
141 | FontVariationSettings m_variationSettings; |
142 | AtomicString m_locale; |
143 | |
144 | FontSelectionRequest m_fontSelectionRequest; |
145 | float m_computedSize { 0 }; // Computed size adjusted for the minimum font size and the zoom factor. |
146 | unsigned m_orientation : 1; // FontOrientation - Whether the font is rendering on a horizontal line or a vertical line. |
147 | unsigned m_nonCJKGlyphOrientation : 1; // NonCJKGlyphOrientation - Only used by vertical text. Determines the default orientation for non-ideograph glyphs. |
148 | unsigned m_widthVariant : 2; // FontWidthVariant |
149 | unsigned m_renderingMode : 1; // Used to switch between CG and GDI text on Windows. |
150 | unsigned m_textRendering : 2; // TextRenderingMode |
151 | unsigned m_script : 7; // Used to help choose an appropriate font for generic font families. |
152 | unsigned m_fontSynthesis : 3; // FontSynthesis type |
153 | unsigned m_variantCommonLigatures : 2; // FontVariantLigatures |
154 | unsigned m_variantDiscretionaryLigatures : 2; // FontVariantLigatures |
155 | unsigned m_variantHistoricalLigatures : 2; // FontVariantLigatures |
156 | unsigned m_variantContextualAlternates : 2; // FontVariantLigatures |
157 | unsigned m_variantPosition : 2; // FontVariantPosition |
158 | unsigned m_variantCaps : 3; // FontVariantCaps |
159 | unsigned m_variantNumericFigure : 2; // FontVariantNumericFigure |
160 | unsigned m_variantNumericSpacing : 2; // FontVariantNumericSpacing |
161 | unsigned m_variantNumericFraction : 2; // FontVariantNumericFraction |
162 | unsigned m_variantNumericOrdinal : 1; // FontVariantNumericOrdinal |
163 | unsigned m_variantNumericSlashedZero : 1; // FontVariantNumericSlashedZero |
164 | unsigned m_variantAlternates : 1; // FontVariantAlternates |
165 | unsigned m_variantEastAsianVariant : 3; // FontVariantEastAsianVariant |
166 | unsigned m_variantEastAsianWidth : 2; // FontVariantEastAsianWidth |
167 | unsigned m_variantEastAsianRuby : 1; // FontVariantEastAsianRuby |
168 | unsigned m_opticalSizing : 1; // FontOpticalSizing |
169 | unsigned m_fontStyleAxis : 1; // Whether "font-style: italic" or "font-style: oblique 20deg" was specified |
170 | unsigned m_shouldAllowUserInstalledFonts : 1; // AllowUserInstalledFonts: If this description is allowed to match a user-installed font |
171 | }; |
172 | |
173 | inline bool FontDescription::operator==(const FontDescription& other) const |
174 | { |
175 | return m_computedSize == other.m_computedSize |
176 | && m_fontSelectionRequest == other.m_fontSelectionRequest |
177 | && m_renderingMode == other.m_renderingMode |
178 | && m_textRendering == other.m_textRendering |
179 | && m_orientation == other.m_orientation |
180 | && m_nonCJKGlyphOrientation == other.m_nonCJKGlyphOrientation |
181 | && m_widthVariant == other.m_widthVariant |
182 | && m_locale == other.m_locale |
183 | && m_featureSettings == other.m_featureSettings |
184 | #if ENABLE(VARIATION_FONTS) |
185 | && m_variationSettings == other.m_variationSettings |
186 | #endif |
187 | && m_fontSynthesis == other.m_fontSynthesis |
188 | && m_variantCommonLigatures == other.m_variantCommonLigatures |
189 | && m_variantDiscretionaryLigatures == other.m_variantDiscretionaryLigatures |
190 | && m_variantHistoricalLigatures == other.m_variantHistoricalLigatures |
191 | && m_variantContextualAlternates == other.m_variantContextualAlternates |
192 | && m_variantPosition == other.m_variantPosition |
193 | && m_variantCaps == other.m_variantCaps |
194 | && m_variantNumericFigure == other.m_variantNumericFigure |
195 | && m_variantNumericSpacing == other.m_variantNumericSpacing |
196 | && m_variantNumericFraction == other.m_variantNumericFraction |
197 | && m_variantNumericOrdinal == other.m_variantNumericOrdinal |
198 | && m_variantNumericSlashedZero == other.m_variantNumericSlashedZero |
199 | && m_variantAlternates == other.m_variantAlternates |
200 | && m_variantEastAsianVariant == other.m_variantEastAsianVariant |
201 | && m_variantEastAsianWidth == other.m_variantEastAsianWidth |
202 | && m_variantEastAsianRuby == other.m_variantEastAsianRuby |
203 | && m_opticalSizing == other.m_opticalSizing |
204 | && m_fontStyleAxis == other.m_fontStyleAxis |
205 | && m_shouldAllowUserInstalledFonts == other.m_shouldAllowUserInstalledFonts; |
206 | } |
207 | |
208 | } |
209 | |