OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2007 Nicholas Shanks <contact@nickshanks.com> | |
3 * Copyright (C) 2008 Apple Inc. All rights reserved. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions | |
7 * are met: | |
8 * | |
9 * 1. Redistributions of source code must retain the above copyright | |
10 * notice, this list of conditions and the following disclaimer. | |
11 * 2. Redistributions in binary form must reproduce the above copyright | |
12 * notice, this list of conditions and the following disclaimer in the | |
13 * documentation and/or other materials provided with the distribution. | |
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
15 * its contributors may be used to endorse or promote products derived | |
16 * from this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 */ | |
29 | |
30 #include "config.h" | |
31 #include "core/platform/graphics/FontDescription.h" | |
32 | |
33 #include "RuntimeEnabledFeatures.h" | |
34 #include "wtf/text/AtomicStringHash.h" | |
35 #include "wtf/text/StringHash.h" | |
36 | |
37 namespace WebCore { | |
38 | |
39 struct SameSizeAsFontDescription { | |
40 FontFamily familyList; | |
41 RefPtr<FontFeatureSettings> m_featureSettings; | |
42 float sizes[2]; | |
43 // FXIME: Make them fit into one word. | |
44 uint32_t bitfields; | |
45 uint32_t bitfields2 : 8; | |
46 }; | |
47 | |
48 COMPILE_ASSERT(sizeof(FontDescription) == sizeof(SameSizeAsFontDescription), Fon
tDescription_should_stay_small); | |
49 | |
50 FontWeight FontDescription::lighterWeight(void) const | |
51 { | |
52 switch (m_weight) { | |
53 case FontWeight100: | |
54 case FontWeight200: | |
55 case FontWeight300: | |
56 case FontWeight400: | |
57 case FontWeight500: | |
58 return FontWeight100; | |
59 | |
60 case FontWeight600: | |
61 case FontWeight700: | |
62 return FontWeight400; | |
63 | |
64 case FontWeight800: | |
65 case FontWeight900: | |
66 return FontWeight700; | |
67 } | |
68 ASSERT_NOT_REACHED(); | |
69 return FontWeightNormal; | |
70 } | |
71 | |
72 FontWeight FontDescription::bolderWeight(void) const | |
73 { | |
74 switch (m_weight) { | |
75 case FontWeight100: | |
76 case FontWeight200: | |
77 case FontWeight300: | |
78 return FontWeight400; | |
79 | |
80 case FontWeight400: | |
81 case FontWeight500: | |
82 return FontWeight700; | |
83 | |
84 case FontWeight600: | |
85 case FontWeight700: | |
86 case FontWeight800: | |
87 case FontWeight900: | |
88 return FontWeight900; | |
89 } | |
90 ASSERT_NOT_REACHED(); | |
91 return FontWeightNormal; | |
92 } | |
93 | |
94 FontTraitsMask FontDescription::traitsMask() const | |
95 { | |
96 return static_cast<FontTraitsMask>((m_italic ? FontStyleItalicMask : FontSty
leNormalMask) | |
97 | (m_smallCaps ? FontVariantSmallCapsMask : FontVariantNormalMask) | |
98 | (FontWeight100Mask << (m_weight - FontWeight100))); | |
99 | |
100 } | |
101 | |
102 FontDescription FontDescription::makeNormalFeatureSettings() const | |
103 { | |
104 FontDescription normalDescription(*this); | |
105 normalDescription.setFeatureSettings(0); | |
106 return normalDescription; | |
107 } | |
108 | |
109 float FontDescription::effectiveFontSize() const | |
110 { | |
111 return (RuntimeEnabledFeatures::subpixelFontScalingEnabled()) | |
112 ? computedSize() | |
113 : computedPixelSize(); | |
114 } | |
115 | |
116 FontCacheKey FontDescription::cacheKey(const AtomicString& familyName, FontTrait
sMask desiredTraits) const | |
117 { | |
118 FontTraitsMask traits = desiredTraits | |
119 ? desiredTraits | |
120 : traitsMask(); | |
121 | |
122 unsigned options = | |
123 // synthetic bold, italics - bits 7-8 | |
124 static_cast<unsigned>(m_fontSmoothing) << 4 | // bits 5-6 | |
125 static_cast<unsigned>(m_textRendering) << 2 | // bits 3-4 | |
126 static_cast<unsigned>(m_orientation) << 1 | // bit 2 | |
127 static_cast<unsigned>(m_usePrinterFont); // bit 1 | |
128 | |
129 return FontCacheKey(familyName, effectiveFontSize(), options | traits << 8); | |
130 } | |
131 | |
132 } // namespace WebCore | |
OLD | NEW |