OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
3 * (C) 2000 Antti Koivisto (koivisto@kde.org) | 3 * (C) 2000 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2000 Dirk Mueller (mueller@kde.org) | 4 * (C) 2000 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed. | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed. |
6 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> | 6 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 15 matching lines...) Expand all Loading... | |
26 #define FontDescription_h | 26 #define FontDescription_h |
27 | 27 |
28 #include "SkFontStyle.h" | 28 #include "SkFontStyle.h" |
29 #include "platform/FontFamilyNames.h" | 29 #include "platform/FontFamilyNames.h" |
30 #include "platform/fonts/FontCacheKey.h" | 30 #include "platform/fonts/FontCacheKey.h" |
31 #include "platform/fonts/FontFamily.h" | 31 #include "platform/fonts/FontFamily.h" |
32 #include "platform/fonts/FontFeatureSettings.h" | 32 #include "platform/fonts/FontFeatureSettings.h" |
33 #include "platform/fonts/FontOrientation.h" | 33 #include "platform/fonts/FontOrientation.h" |
34 #include "platform/fonts/FontSmoothingMode.h" | 34 #include "platform/fonts/FontSmoothingMode.h" |
35 #include "platform/fonts/FontTraits.h" | 35 #include "platform/fonts/FontTraits.h" |
36 #include "platform/fonts/FontVariantNumeric.h" | |
36 #include "platform/fonts/FontWidthVariant.h" | 37 #include "platform/fonts/FontWidthVariant.h" |
37 #include "platform/fonts/TextRenderingMode.h" | 38 #include "platform/fonts/TextRenderingMode.h" |
38 #include "platform/fonts/TypesettingFeatures.h" | 39 #include "platform/fonts/TypesettingFeatures.h" |
39 #include "platform/text/LocaleToScriptMapping.h" | 40 #include "platform/text/LocaleToScriptMapping.h" |
40 #include "wtf/Allocator.h" | 41 #include "wtf/Allocator.h" |
41 #include "wtf/MathExtras.h" | 42 #include "wtf/MathExtras.h" |
42 | 43 |
43 #include "wtf/RefPtr.h" | 44 #include "wtf/RefPtr.h" |
44 | 45 |
45 #include <unicode/uscript.h> | 46 #include <unicode/uscript.h> |
46 | 47 |
47 namespace blink { | 48 namespace blink { |
48 | 49 |
49 const float FontSizeAdjustNone = -1; | 50 const float FontSizeAdjustNone = -1; |
51 typedef struct { | |
52 uint32_t f[2]; | |
eae
2016/05/09 16:31:58
part or segment might be a better name than f. Non
drott
2016/05/10 10:59:06
Renamed to 'parts' to indicate it's an array.
| |
53 } FieldsAsUnsignedType; | |
50 | 54 |
51 class PLATFORM_EXPORT FontDescription { | 55 class PLATFORM_EXPORT FontDescription { |
52 USING_FAST_MALLOC(FontDescription); | 56 USING_FAST_MALLOC(FontDescription); |
53 public: | 57 public: |
54 enum GenericFamilyType { NoFamily, StandardFamily, SerifFamily, SansSerifFam ily, | 58 enum GenericFamilyType { NoFamily, StandardFamily, SerifFamily, SansSerifFam ily, |
55 MonospaceFamily, CursiveFamily, FantasyFamily, Pict ographFamily }; | 59 MonospaceFamily, CursiveFamily, FantasyFamily, Pict ographFamily }; |
56 | 60 |
57 enum Kerning { AutoKerning, NormalKerning, NoneKerning }; | 61 enum Kerning { AutoKerning, NormalKerning, NoneKerning }; |
58 | 62 |
59 enum LigaturesState { NormalLigaturesState, DisabledLigaturesState, EnabledL igaturesState }; | 63 enum LigaturesState { NormalLigaturesState, DisabledLigaturesState, EnabledL igaturesState }; |
60 | 64 |
61 enum FontVariantCaps { CapsNormal, SmallCaps, AllSmallCaps, PetiteCaps, AllP etiteCaps, Unicase, TitlingCaps }; | 65 enum FontVariantCaps { CapsNormal, SmallCaps, AllSmallCaps, PetiteCaps, AllP etiteCaps, Unicase, TitlingCaps }; |
62 | 66 |
63 FontDescription() | 67 FontDescription() |
64 : m_specifiedSize(0) | 68 : m_specifiedSize(0) |
65 , m_computedSize(0) | 69 , m_computedSize(0) |
66 , m_adjustedSize(0) | 70 , m_adjustedSize(0) |
67 , m_sizeAdjust(FontSizeAdjustNone) | 71 , m_sizeAdjust(FontSizeAdjustNone) |
68 , m_letterSpacing(0) | 72 , m_letterSpacing(0) |
69 , m_wordSpacing(0) | 73 , m_wordSpacing(0) |
70 { | 74 { |
71 m_fieldsAsUnsigned[0] = 0; | 75 m_fieldsAsUnsigned.f[0] = 0; |
72 m_fieldsAsUnsigned[1] = 0; | 76 m_fieldsAsUnsigned.f[1] = 0; |
73 m_fields.m_orientation = static_cast<unsigned>(FontOrientation::Horizont al); | 77 m_fields.m_orientation = static_cast<unsigned>(FontOrientation::Horizont al); |
74 m_fields.m_widthVariant = RegularWidth; | 78 m_fields.m_widthVariant = RegularWidth; |
75 m_fields.m_style = FontStyleNormal; | 79 m_fields.m_style = FontStyleNormal; |
76 m_fields.m_variantCaps = CapsNormal; | 80 m_fields.m_variantCaps = CapsNormal; |
77 m_fields.m_isAbsoluteSize = false; | 81 m_fields.m_isAbsoluteSize = false; |
78 m_fields.m_weight = FontWeightNormal; | 82 m_fields.m_weight = FontWeightNormal; |
79 m_fields.m_stretch = FontStretchNormal; | 83 m_fields.m_stretch = FontStretchNormal; |
80 m_fields.m_genericFamily = NoFamily; | 84 m_fields.m_genericFamily = NoFamily; |
81 m_fields.m_kerning = AutoKerning; | 85 m_fields.m_kerning = AutoKerning; |
82 m_fields.m_commonLigaturesState = NormalLigaturesState; | 86 m_fields.m_commonLigaturesState = NormalLigaturesState; |
83 m_fields.m_discretionaryLigaturesState = NormalLigaturesState; | 87 m_fields.m_discretionaryLigaturesState = NormalLigaturesState; |
84 m_fields.m_historicalLigaturesState = NormalLigaturesState; | 88 m_fields.m_historicalLigaturesState = NormalLigaturesState; |
85 m_fields.m_contextualLigaturesState = NormalLigaturesState; | 89 m_fields.m_contextualLigaturesState = NormalLigaturesState; |
86 m_fields.m_keywordSize = 0; | 90 m_fields.m_keywordSize = 0; |
87 m_fields.m_fontSmoothing = AutoSmoothing; | 91 m_fields.m_fontSmoothing = AutoSmoothing; |
88 m_fields.m_textRendering = AutoTextRendering; | 92 m_fields.m_textRendering = AutoTextRendering; |
89 m_fields.m_script = USCRIPT_COMMON; | 93 m_fields.m_script = USCRIPT_COMMON; |
90 m_fields.m_syntheticBold = false; | 94 m_fields.m_syntheticBold = false; |
91 m_fields.m_syntheticItalic = false; | 95 m_fields.m_syntheticItalic = false; |
92 m_fields.m_subpixelTextPosition = s_useSubpixelTextPositioning; | 96 m_fields.m_subpixelTextPosition = s_useSubpixelTextPositioning; |
93 m_fields.m_typesettingFeatures = s_defaultTypesettingFeatures; | 97 m_fields.m_typesettingFeatures = s_defaultTypesettingFeatures; |
98 m_fields.m_variantNumeric = FontVariantNumeric().m_fieldsAsUnsigned; | |
94 } | 99 } |
95 | 100 |
96 bool operator==(const FontDescription&) const; | 101 bool operator==(const FontDescription&) const; |
97 bool operator!=(const FontDescription& other) const { return !(*this == othe r); } | 102 bool operator!=(const FontDescription& other) const { return !(*this == othe r); } |
98 | 103 |
99 struct VariantLigatures { | 104 struct VariantLigatures { |
100 STACK_ALLOCATED(); | 105 STACK_ALLOCATED(); |
101 VariantLigatures(LigaturesState state = NormalLigaturesState) | 106 VariantLigatures(LigaturesState state = NormalLigaturesState) |
102 : common(state) | 107 : common(state) |
103 , discretionary(state) | 108 , discretionary(state) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 static Size smallerSize(const Size&); | 163 static Size smallerSize(const Size&); |
159 GenericFamilyType genericFamily() const { return static_cast<GenericFamilyTy pe>(m_fields.m_genericFamily); } | 164 GenericFamilyType genericFamily() const { return static_cast<GenericFamilyTy pe>(m_fields.m_genericFamily); } |
160 | 165 |
161 // only use fixed default size when there is only one font family, and that family is "monospace" | 166 // only use fixed default size when there is only one font family, and that family is "monospace" |
162 bool isMonospace() const | 167 bool isMonospace() const |
163 { | 168 { |
164 return genericFamily() == MonospaceFamily && !family().next() && family( ).family() == FontFamilyNames::webkit_monospace; | 169 return genericFamily() == MonospaceFamily && !family().next() && family( ).family() == FontFamilyNames::webkit_monospace; |
165 } | 170 } |
166 Kerning getKerning() const { return static_cast<Kerning>(m_fields.m_kerning) ; } | 171 Kerning getKerning() const { return static_cast<Kerning>(m_fields.m_kerning) ; } |
167 VariantLigatures getVariantLigatures() const; | 172 VariantLigatures getVariantLigatures() const; |
173 FontVariantNumeric variantNumeric() const { return FontVariantNumeric::init ializeFromUnsigned(m_fields.m_variantNumeric); }; | |
168 LigaturesState commonLigaturesState() const { return static_cast<LigaturesSt ate>(m_fields.m_commonLigaturesState); } | 174 LigaturesState commonLigaturesState() const { return static_cast<LigaturesSt ate>(m_fields.m_commonLigaturesState); } |
169 LigaturesState discretionaryLigaturesState() const { return static_cast<Liga turesState>(m_fields.m_discretionaryLigaturesState); } | 175 LigaturesState discretionaryLigaturesState() const { return static_cast<Liga turesState>(m_fields.m_discretionaryLigaturesState); } |
170 LigaturesState historicalLigaturesState() const { return static_cast<Ligatur esState>(m_fields.m_historicalLigaturesState); } | 176 LigaturesState historicalLigaturesState() const { return static_cast<Ligatur esState>(m_fields.m_historicalLigaturesState); } |
171 LigaturesState contextualLigaturesState() const { return static_cast<Ligatur esState>(m_fields.m_contextualLigaturesState); } | 177 LigaturesState contextualLigaturesState() const { return static_cast<Ligatur esState>(m_fields.m_contextualLigaturesState); } |
172 unsigned keywordSize() const { return m_fields.m_keywordSize; } | 178 unsigned keywordSize() const { return m_fields.m_keywordSize; } |
173 FontSmoothingMode fontSmoothing() const { return static_cast<FontSmoothingMo de>(m_fields.m_fontSmoothing); } | 179 FontSmoothingMode fontSmoothing() const { return static_cast<FontSmoothingMo de>(m_fields.m_fontSmoothing); } |
174 TextRenderingMode textRendering() const { return static_cast<TextRenderingMo de>(m_fields.m_textRendering); } | 180 TextRenderingMode textRendering() const { return static_cast<TextRenderingMo de>(m_fields.m_textRendering); } |
175 UScriptCode script() const { return static_cast<UScriptCode>(m_fields.m_scri pt); } | 181 UScriptCode script() const { return static_cast<UScriptCode>(m_fields.m_scri pt); } |
176 const AtomicString& locale(bool includeDefault = true) const; | 182 const AtomicString& locale(bool includeDefault = true) const; |
177 bool isSyntheticBold() const { return m_fields.m_syntheticBold; } | 183 bool isSyntheticBold() const { return m_fields.m_syntheticBold; } |
(...skipping 15 matching lines...) Expand all Loading... | |
193 FontCacheKey cacheKey(const FontFaceCreationParams&, FontTraits desiredTrait s = FontTraits(0)) const; | 199 FontCacheKey cacheKey(const FontFaceCreationParams&, FontTraits desiredTrait s = FontTraits(0)) const; |
194 | 200 |
195 void setFamily(const FontFamily& family) { m_familyList = family; } | 201 void setFamily(const FontFamily& family) { m_familyList = family; } |
196 void setComputedSize(float s) { m_computedSize = clampTo<float>(s); } | 202 void setComputedSize(float s) { m_computedSize = clampTo<float>(s); } |
197 void setSpecifiedSize(float s) { m_specifiedSize = clampTo<float>(s); } | 203 void setSpecifiedSize(float s) { m_specifiedSize = clampTo<float>(s); } |
198 void setAdjustedSize(float s) { m_adjustedSize = clampTo<float>(s); } | 204 void setAdjustedSize(float s) { m_adjustedSize = clampTo<float>(s); } |
199 void setSizeAdjust(float aspect) { m_sizeAdjust = clampTo<float>(aspect); } | 205 void setSizeAdjust(float aspect) { m_sizeAdjust = clampTo<float>(aspect); } |
200 void setStyle(FontStyle i) { m_fields.m_style = i; } | 206 void setStyle(FontStyle i) { m_fields.m_style = i; } |
201 void setVariantCaps(FontVariantCaps variantCaps) { m_fields.m_variantCaps = variantCaps; } | 207 void setVariantCaps(FontVariantCaps variantCaps) { m_fields.m_variantCaps = variantCaps; } |
202 void setVariantLigatures(const VariantLigatures&); | 208 void setVariantLigatures(const VariantLigatures&); |
209 void setVariantNumeric(const FontVariantNumeric&); | |
203 void setIsAbsoluteSize(bool s) { m_fields.m_isAbsoluteSize = s; } | 210 void setIsAbsoluteSize(bool s) { m_fields.m_isAbsoluteSize = s; } |
204 void setWeight(FontWeight w) { m_fields.m_weight = w; } | 211 void setWeight(FontWeight w) { m_fields.m_weight = w; } |
205 void setStretch(FontStretch s) { m_fields.m_stretch = s; } | 212 void setStretch(FontStretch s) { m_fields.m_stretch = s; } |
206 void setGenericFamily(GenericFamilyType genericFamily) { m_fields.m_genericF amily = genericFamily; } | 213 void setGenericFamily(GenericFamilyType genericFamily) { m_fields.m_genericF amily = genericFamily; } |
207 void setKerning(Kerning kerning) { m_fields.m_kerning = kerning; updateTypes ettingFeatures(); } | 214 void setKerning(Kerning kerning) { m_fields.m_kerning = kerning; updateTypes ettingFeatures(); } |
208 void setKeywordSize(unsigned s) { m_fields.m_keywordSize = s; } | 215 void setKeywordSize(unsigned s) { m_fields.m_keywordSize = s; } |
209 void setFontSmoothing(FontSmoothingMode smoothing) { m_fields.m_fontSmoothin g = smoothing; } | 216 void setFontSmoothing(FontSmoothingMode smoothing) { m_fields.m_fontSmoothin g = smoothing; } |
210 void setTextRendering(TextRenderingMode rendering) { m_fields.m_textRenderin g = rendering; updateTypesettingFeatures(); } | 217 void setTextRendering(TextRenderingMode rendering) { m_fields.m_textRenderin g = rendering; updateTypesettingFeatures(); } |
211 void setOrientation(FontOrientation orientation) { m_fields.m_orientation = static_cast<unsigned>(orientation); } | 218 void setOrientation(FontOrientation orientation) { m_fields.m_orientation = static_cast<unsigned>(orientation); } |
212 void setWidthVariant(FontWidthVariant widthVariant) { m_fields.m_widthVarian t = widthVariant; } | 219 void setWidthVariant(FontWidthVariant widthVariant) { m_fields.m_widthVarian t = widthVariant; } |
(...skipping 11 matching lines...) Expand all Loading... | |
224 | 231 |
225 TypesettingFeatures getTypesettingFeatures() const { return static_cast<Type settingFeatures>(m_fields.m_typesettingFeatures); } | 232 TypesettingFeatures getTypesettingFeatures() const { return static_cast<Type settingFeatures>(m_fields.m_typesettingFeatures); } |
226 | 233 |
227 static void setSubpixelPositioning(bool b) { s_useSubpixelTextPositioning = b; } | 234 static void setSubpixelPositioning(bool b) { s_useSubpixelTextPositioning = b; } |
228 static bool subpixelPositioning() { return s_useSubpixelTextPositioning; } | 235 static bool subpixelPositioning() { return s_useSubpixelTextPositioning; } |
229 | 236 |
230 static void setDefaultTypesettingFeatures(TypesettingFeatures); | 237 static void setDefaultTypesettingFeatures(TypesettingFeatures); |
231 static TypesettingFeatures defaultTypesettingFeatures(); | 238 static TypesettingFeatures defaultTypesettingFeatures(); |
232 | 239 |
233 unsigned styleHashWithoutFamilyList() const; | 240 unsigned styleHashWithoutFamilyList() const; |
234 unsigned bitmapFields() const { return m_fieldsAsUnsigned[0]; } | 241 // FIXME: We should not expose internal structure here, but rather introduce |
235 unsigned auxiliaryBitmapFields() const { return m_fieldsAsUnsigned[1]; } | 242 // a hash function here. |
243 unsigned bitmapFields() const { return m_fieldsAsUnsigned.f[0]; } | |
244 unsigned auxiliaryBitmapFields() const { return m_fieldsAsUnsigned.f[1]; } | |
236 | 245 |
237 SkFontStyle skiaFontStyle() const; | 246 SkFontStyle skiaFontStyle() const; |
238 | 247 |
239 private: | 248 private: |
240 FontFamily m_familyList; // The list of font families to be used. | 249 FontFamily m_familyList; // The list of font families to be used. |
241 RefPtr<FontFeatureSettings> m_featureSettings; | 250 RefPtr<FontFeatureSettings> m_featureSettings; |
242 AtomicString m_locale; | 251 AtomicString m_locale; |
243 | 252 |
244 void updateTypesettingFeatures(); | 253 void updateTypesettingFeatures(); |
245 | 254 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 // then we can accurately translate across different generic families to adjust for different preference settings | 292 // then we can accurately translate across different generic families to adjust for different preference settings |
284 // (e.g., 13px monospace vs. 16px everything else). Sizes are 1-8 (like the HTML size values for <font>). | 293 // (e.g., 13px monospace vs. 16px everything else). Sizes are 1-8 (like the HTML size values for <font>). |
285 | 294 |
286 unsigned m_fontSmoothing : 2; // FontSmoothingMode | 295 unsigned m_fontSmoothing : 2; // FontSmoothingMode |
287 unsigned m_textRendering : 2; // TextRenderingMode | 296 unsigned m_textRendering : 2; // TextRenderingMode |
288 unsigned m_script : 7; // Used to help choose an appropriate font for ge neric font families. | 297 unsigned m_script : 7; // Used to help choose an appropriate font for ge neric font families. |
289 unsigned m_syntheticBold : 1; | 298 unsigned m_syntheticBold : 1; |
290 unsigned m_syntheticItalic : 1; | 299 unsigned m_syntheticItalic : 1; |
291 unsigned m_subpixelTextPosition : 1; | 300 unsigned m_subpixelTextPosition : 1; |
292 unsigned m_typesettingFeatures : 2; // TypesettingFeatures | 301 unsigned m_typesettingFeatures : 2; // TypesettingFeatures |
302 unsigned m_variantNumeric : 8; | |
293 }; | 303 }; |
304 | |
305 static_assert(sizeof(BitFields) == sizeof(FieldsAsUnsignedType), | |
306 "Mapped bitfield datatypes must have identical size."); | |
294 union { | 307 union { |
295 BitFields m_fields; | 308 BitFields m_fields; |
296 uint32_t m_fieldsAsUnsigned[2]; | 309 FieldsAsUnsignedType m_fieldsAsUnsigned; |
297 }; | 310 }; |
298 | 311 |
299 static TypesettingFeatures s_defaultTypesettingFeatures; | 312 static TypesettingFeatures s_defaultTypesettingFeatures; |
300 | 313 |
301 static bool s_useSubpixelTextPositioning; | 314 static bool s_useSubpixelTextPositioning; |
302 }; | 315 }; |
303 | 316 |
304 inline bool FontDescription::operator==(const FontDescription& other) const | 317 inline bool FontDescription::operator==(const FontDescription& other) const |
305 { | 318 { |
306 return m_familyList == other.m_familyList | 319 return m_familyList == other.m_familyList |
307 && m_locale == other.m_locale | 320 && m_locale == other.m_locale |
308 && m_specifiedSize == other.m_specifiedSize | 321 && m_specifiedSize == other.m_specifiedSize |
309 && m_computedSize == other.m_computedSize | 322 && m_computedSize == other.m_computedSize |
310 && m_adjustedSize == other.m_adjustedSize | 323 && m_adjustedSize == other.m_adjustedSize |
311 && m_sizeAdjust == other.m_sizeAdjust | 324 && m_sizeAdjust == other.m_sizeAdjust |
312 && m_letterSpacing == other.m_letterSpacing | 325 && m_letterSpacing == other.m_letterSpacing |
313 && m_wordSpacing == other.m_wordSpacing | 326 && m_wordSpacing == other.m_wordSpacing |
314 && m_fieldsAsUnsigned[0] == other.m_fieldsAsUnsigned[0] | 327 && m_fieldsAsUnsigned.f[0] == other.m_fieldsAsUnsigned.f[0] |
315 && m_fieldsAsUnsigned[1] == other.m_fieldsAsUnsigned[1] | 328 && m_fieldsAsUnsigned.f[1] == other.m_fieldsAsUnsigned.f[1] |
316 && (m_featureSettings == other.m_featureSettings || (m_featureSettings & & other.m_featureSettings && *m_featureSettings == *other.m_featureSettings)); | 329 && (m_featureSettings == other.m_featureSettings || (m_featureSettings & & other.m_featureSettings && *m_featureSettings == *other.m_featureSettings)); |
317 } | 330 } |
318 | 331 |
319 } // namespace blink | 332 } // namespace blink |
320 | 333 |
321 #endif | 334 #endif |
OLD | NEW |