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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 static int inline rowFromMediumFontSizeInRange(const Settings* settings, bool qu
irksMode, FixedPitchFontType fixedPitchFontType, int& mediumSize) | 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(); | 125 mediumSize = fixedPitchFontType == FixedPitchFont ? settings->defaultFixedFo
ntSize() : settings->defaultFontSize(); |
126 if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) | 126 if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) |
127 return mediumSize - fontSizeTableMin; | 127 return mediumSize - fontSizeTableMin; |
128 return -1; | 128 return -1; |
129 } | 129 } |
130 | 130 |
131 float FontSize::fontSizeForKeyword(const Document* document, CSSValueID keyword,
FixedPitchFontType fixedPitchFontType) | 131 float FontSize::fontSizeForKeyword(const Document* document, unsigned keyword, F
ixedPitchFontType fixedPitchFontType) |
132 { | 132 { |
133 ASSERT(keyword >= CSSValueXxSmall && keyword <= CSSValueWebkitXxxLarge); | 133 ASSERT(keyword >= 1 && keyword <= 8); |
134 const Settings* settings = document->settings(); | 134 const Settings* settings = document->settings(); |
135 if (!settings) | 135 if (!settings) |
136 return 1.0f; | 136 return 1.0f; |
137 | 137 |
138 bool quirksMode = document->inQuirksMode(); | 138 bool quirksMode = document->inQuirksMode(); |
139 int mediumSize = 0; | 139 int mediumSize = 0; |
140 int row = rowFromMediumFontSizeInRange(settings, quirksMode, fixedPitchFontT
ype, mediumSize); | 140 int row = rowFromMediumFontSizeInRange(settings, quirksMode, fixedPitchFontT
ype, mediumSize); |
141 if (row >= 0) { | 141 if (row >= 0) { |
142 int col = (keyword - CSSValueXxSmall); | 142 int col = (keyword - 1); |
143 return quirksMode ? quirksFontSizeTable[row][col] : strictFontSizeTable[
row][col]; | 143 return quirksMode ? quirksFontSizeTable[row][col] : strictFontSizeTable[
row][col]; |
144 } | 144 } |
145 | 145 |
146 // 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. |
147 float minLogicalSize = std::max(settings->minimumLogicalFontSize(), 1); | 147 float minLogicalSize = std::max(settings->minimumLogicalFontSize(), 1); |
148 return std::max(fontSizeFactors[keyword - CSSValueXxSmall] * mediumSize, min
LogicalSize); | 148 return std::max(fontSizeFactors[keyword - 1] * mediumSize, minLogicalSize); |
149 } | 149 } |
150 | 150 |
151 | 151 |
152 | 152 |
153 template<typename T> | 153 template<typename T> |
154 static int findNearestLegacyFontSize(int pixelFontSize, const T* table, int mult
iplier) | 154 static int findNearestLegacyFontSize(int pixelFontSize, const T* table, int mult
iplier) |
155 { | 155 { |
156 // 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. |
157 for (int i = 1; i < totalKeywords - 1; i++) { | 157 for (int i = 1; i < totalKeywords - 1; i++) { |
158 if (pixelFontSize * 2 < (table[i] + table[i + 1]) * multiplier) | 158 if (pixelFontSize * 2 < (table[i] + table[i + 1]) * multiplier) |
(...skipping 11 matching lines...) Expand all Loading... |
170 bool quirksMode = document->inQuirksMode(); | 170 bool quirksMode = document->inQuirksMode(); |
171 int mediumSize = 0; | 171 int mediumSize = 0; |
172 int row = rowFromMediumFontSizeInRange(settings, quirksMode, fixedPitchFontT
ype, mediumSize); | 172 int row = rowFromMediumFontSizeInRange(settings, quirksMode, fixedPitchFontT
ype, mediumSize); |
173 if (row >= 0) | 173 if (row >= 0) |
174 return findNearestLegacyFontSize<int>(pixelFontSize, quirksMode ? quirks
FontSizeTable[row] : strictFontSizeTable[row], 1); | 174 return findNearestLegacyFontSize<int>(pixelFontSize, quirksMode ? quirks
FontSizeTable[row] : strictFontSizeTable[row], 1); |
175 | 175 |
176 return findNearestLegacyFontSize<float>(pixelFontSize, fontSizeFactors, medi
umSize); | 176 return findNearestLegacyFontSize<float>(pixelFontSize, fontSizeFactors, medi
umSize); |
177 } | 177 } |
178 | 178 |
179 } // namespace blink | 179 } // namespace blink |
OLD | NEW |