OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
All rights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
All rights reserved. |
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 }; | 113 }; |
114 // HTML 1 2 3 4 5 6 7 | 114 // HTML 1 2 3 4 5 6 7 |
115 // CSS xxs xs s m l xl xxl | 115 // CSS xxs xs s m l xl xxl |
116 // | | 116 // | |
117 // user pref | 117 // user pref |
118 | 118 |
119 // For values outside the range of the table, we use Todd Fahrner's suggested sc
ale | 119 // For values outside the range of the table, we use Todd Fahrner's suggested sc
ale |
120 // factors for each keyword value. | 120 // factors for each keyword value. |
121 static const float fontSizeFactors[totalKeywords] = { 0.60f, 0.75f, 0.89f, 1.0f,
1.2f, 1.5f, 2.0f, 3.0f }; | 121 static const float fontSizeFactors[totalKeywords] = { 0.60f, 0.75f, 0.89f, 1.0f,
1.2f, 1.5f, 2.0f, 3.0f }; |
122 | 122 |
123 float FontSize::fontSizeForKeyword(const Document* document, int keyword, bool s
houldUseFixedDefaultSize) | 123 static int inline rowFromMediumFontSizeInRange(const Settings* settings, bool qu
irksMode, FixedPitchFontType fixedPitchFontType, int& mediumSize) |
124 { | 124 { |
| 125 mediumSize = fixedPitchFontType == FixedPitchFont ? settings->defaultFixedFo
ntSize() : settings->defaultFontSize(); |
| 126 if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) |
| 127 return mediumSize - fontSizeTableMin; |
| 128 return -1; |
| 129 } |
| 130 |
| 131 float FontSize::fontSizeForKeyword(const Document* document, CSSValueID keyword,
FixedPitchFontType fixedPitchFontType) |
| 132 { |
| 133 ASSERT(keyword >= CSSValueXxSmall && keyword <= CSSValueWebkitXxxLarge); |
125 const Settings* settings = document->settings(); | 134 const Settings* settings = document->settings(); |
126 if (!settings) | 135 if (!settings) |
127 return 1.0f; | 136 return 1.0f; |
128 | 137 |
129 bool quirksMode = document->inQuirksMode(); | 138 bool quirksMode = document->inQuirksMode(); |
130 int mediumSize = shouldUseFixedDefaultSize ? settings->defaultFixedFontSize(
) : settings->defaultFontSize(); | 139 int mediumSize = 0; |
131 if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) { | 140 int row = rowFromMediumFontSizeInRange(settings, quirksMode, fixedPitchFontT
ype, mediumSize); |
132 // Look up the entry in the table. | 141 if (row >= 0) { |
133 int row = mediumSize - fontSizeTableMin; | |
134 int col = (keyword - CSSValueXxSmall); | 142 int col = (keyword - CSSValueXxSmall); |
135 return quirksMode ? quirksFontSizeTable[row][col] : strictFontSizeTable[
row][col]; | 143 return quirksMode ? quirksFontSizeTable[row][col] : strictFontSizeTable[
row][col]; |
136 } | 144 } |
137 | 145 |
138 // Value is outside the range of the table. Apply the scale factor instead. | 146 // Value is outside the range of the table. Apply the scale factor instead. |
139 float minLogicalSize = std::max(settings->minimumLogicalFontSize(), 1); | 147 float minLogicalSize = std::max(settings->minimumLogicalFontSize(), 1); |
140 return std::max(fontSizeFactors[keyword - CSSValueXxSmall] * mediumSize, min
LogicalSize); | 148 return std::max(fontSizeFactors[keyword - CSSValueXxSmall] * mediumSize, min
LogicalSize); |
141 } | 149 } |
142 | 150 |
143 | 151 |
144 | 152 |
145 template<typename T> | 153 template<typename T> |
146 static int findNearestLegacyFontSize(int pixelFontSize, const T* table, int mult
iplier) | 154 static int findNearestLegacyFontSize(int pixelFontSize, const T* table, int mult
iplier) |
147 { | 155 { |
148 // Ignore table[0] because xx-small does not correspond to any legacy font s
ize. | 156 // Ignore table[0] because xx-small does not correspond to any legacy font s
ize. |
149 for (int i = 1; i < totalKeywords - 1; i++) { | 157 for (int i = 1; i < totalKeywords - 1; i++) { |
150 if (pixelFontSize * 2 < (table[i] + table[i + 1]) * multiplier) | 158 if (pixelFontSize * 2 < (table[i] + table[i + 1]) * multiplier) |
151 return i; | 159 return i; |
152 } | 160 } |
153 return totalKeywords - 1; | 161 return totalKeywords - 1; |
154 } | 162 } |
155 | 163 |
156 int FontSize::legacyFontSize(const Document* document, int pixelFontSize, bool s
houldUseFixedDefaultSize) | 164 int FontSize::legacyFontSize(const Document* document, int pixelFontSize, FixedP
itchFontType fixedPitchFontType) |
157 { | 165 { |
158 const Settings* settings = document->settings(); | 166 const Settings* settings = document->settings(); |
159 if (!settings) | 167 if (!settings) |
160 return 1; | 168 return 1; |
161 | 169 |
162 bool quirksMode = document->inQuirksMode(); | 170 bool quirksMode = document->inQuirksMode(); |
163 int mediumSize = shouldUseFixedDefaultSize ? settings->defaultFixedFontSize(
) : settings->defaultFontSize(); | 171 int mediumSize = 0; |
164 if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) { | 172 int row = rowFromMediumFontSizeInRange(settings, quirksMode, fixedPitchFontT
ype, mediumSize); |
165 int row = mediumSize - fontSizeTableMin; | 173 if (row >= 0) |
166 return findNearestLegacyFontSize<int>(pixelFontSize, quirksMode ? quirks
FontSizeTable[row] : strictFontSizeTable[row], 1); | 174 return findNearestLegacyFontSize<int>(pixelFontSize, quirksMode ? quirks
FontSizeTable[row] : strictFontSizeTable[row], 1); |
167 } | |
168 | 175 |
169 return findNearestLegacyFontSize<float>(pixelFontSize, fontSizeFactors, medi
umSize); | 176 return findNearestLegacyFontSize<float>(pixelFontSize, fontSizeFactors, medi
umSize); |
170 } | 177 } |
171 | 178 |
172 } // namespace WebCore | 179 } // namespace WebCore |
OLD | NEW |