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. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. |
6 * All rights reserved. | 6 * All rights reserved. |
7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
10 * (http://www.torchmobile.com/) | 10 * (http://www.torchmobile.com/) |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
35 #include "core/frame/Settings.h" | 35 #include "core/frame/Settings.h" |
36 | 36 |
37 namespace blink { | 37 namespace blink { |
38 | 38 |
39 float FontSize::getComputedSizeFromSpecifiedSize( | 39 float FontSize::getComputedSizeFromSpecifiedSize( |
40 const Document* document, | 40 const Document* document, |
41 float zoomFactor, | 41 float zoomFactor, |
42 bool isAbsoluteSize, | 42 bool isAbsoluteSize, |
43 float specifiedSize, | 43 float specifiedSize, |
44 ESmartMinimumForFontSize useSmartMinimumForFontSize) { | 44 ApplyMinimumFontSize applyMinimumFontSize) { |
45 // Text with a 0px font size should not be visible and therefore needs to be | 45 // Text with a 0px font size should not be visible and therefore needs to be |
46 // exempt from minimum font size rules. Acid3 relies on this for pixel-perfect | 46 // exempt from minimum font size rules. Acid3 relies on this for pixel-perfect |
47 // rendering. This is also compatible with other browsers that have minimum | 47 // rendering. This is also compatible with other browsers that have minimum |
48 // font size settings (e.g. Firefox). | 48 // font size settings (e.g. Firefox). |
49 if (fabsf(specifiedSize) < std::numeric_limits<float>::epsilon()) | 49 if (fabsf(specifiedSize) < std::numeric_limits<float>::epsilon()) |
50 return 0.0f; | 50 return 0.0f; |
51 | 51 |
52 // We support two types of minimum font size. The first is a hard override | 52 // We support two types of minimum font size. The first is a hard override |
53 // that applies to all fonts. This is "minSize." The second type of minimum | 53 // that applies to all fonts. This is "minSize." The second type of minimum |
54 // font size is a "smart minimum" that is applied only when the Web page can't | 54 // font size is a "smart minimum" that is applied only when the Web page can't |
55 // know what size it really asked for, e.g., when it uses logical sizes like | 55 // know what size it really asked for, e.g., when it uses logical sizes like |
56 // "small" or expresses the font-size as a percentage of the user's default | 56 // "small" or expresses the font-size as a percentage of the user's default |
57 // font setting. | 57 // font setting. |
58 | 58 |
59 // With the smart minimum, we never want to get smaller than the minimum font | 59 // With the smart minimum, we never want to get smaller than the minimum font |
60 // size to keep fonts readable. However we always allow the page to set an | 60 // size to keep fonts readable. However we always allow the page to set an |
61 // explicit pixel size that is smaller, since sites will mis-render otherwise | 61 // explicit pixel size that is smaller, since sites will mis-render otherwise |
62 // (e.g., http://www.gamespot.com with a 9px minimum). | 62 // (e.g., http://www.gamespot.com with a 9px minimum). |
63 | 63 |
64 Settings* settings = document->settings(); | 64 Settings* settings = document->settings(); |
65 if (!settings) | 65 if (!settings) |
66 return 1.0f; | 66 return 1.0f; |
67 | 67 |
68 int minSize = settings->minimumFontSize(); | |
69 int minLogicalSize = settings->minimumLogicalFontSize(); | |
70 float zoomedSize = specifiedSize * zoomFactor; | 68 float zoomedSize = specifiedSize * zoomFactor; |
| 69 if (applyMinimumFontSize) { |
| 70 int minSize = settings->minimumFontSize(); |
| 71 int minLogicalSize = settings->minimumLogicalFontSize(); |
71 | 72 |
72 // Apply the hard minimum first. We only apply the hard minimum if after | 73 // Apply the hard minimum first. We only apply the hard minimum if after |
73 // zooming we're still too small. | 74 // zooming we're still too small. |
74 if (zoomedSize < minSize) | 75 if (zoomedSize < minSize) |
75 zoomedSize = minSize; | 76 zoomedSize = minSize; |
76 | 77 |
77 // Now apply the "smart minimum." This minimum is also only applied if we're | 78 // Now apply the "smart minimum." This minimum is also only applied if we're |
78 // still too small after zooming. The font size must either be relative to the | 79 // still too small after zooming. The font size must either be relative to |
79 // user default or the original size must have been acceptable. In other | 80 // the user default or the original size must have been acceptable. In other |
80 // words, we only apply the smart minimum whenever we're positive doing so | 81 // words, we only apply the smart minimum whenever we're positive doing so |
81 // won't disrupt the layout. | 82 // won't disrupt the layout. |
82 if (useSmartMinimumForFontSize && zoomedSize < minLogicalSize && | 83 if (zoomedSize < minLogicalSize && |
83 (specifiedSize >= minLogicalSize || !isAbsoluteSize)) | 84 (specifiedSize >= minLogicalSize || !isAbsoluteSize)) |
84 zoomedSize = minLogicalSize; | 85 zoomedSize = minLogicalSize; |
85 | 86 } |
86 // Also clamp to a reasonable maximum to prevent insane font sizes from | 87 // Also clamp to a reasonable maximum to prevent insane font sizes from |
87 // causing crashes on various platforms (I'm looking at you, Windows.) | 88 // causing crashes on various platforms (I'm looking at you, Windows.) |
88 return std::min(maximumAllowedFontSize, zoomedSize); | 89 return std::min(maximumAllowedFontSize, zoomedSize); |
89 } | 90 } |
90 | 91 |
91 const int fontSizeTableMax = 16; | 92 const int fontSizeTableMax = 16; |
92 const int fontSizeTableMin = 9; | 93 const int fontSizeTableMin = 9; |
93 const int totalKeywords = 8; | 94 const int totalKeywords = 8; |
94 | 95 |
95 // WinIE/Nav4 table for font sizes. Designed to match the legacy font mapping | 96 // WinIE/Nav4 table for font sizes. Designed to match the legacy font mapping |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 if (row >= 0) | 188 if (row >= 0) |
188 return findNearestLegacyFontSize<int>( | 189 return findNearestLegacyFontSize<int>( |
189 pixelFontSize, | 190 pixelFontSize, |
190 quirksMode ? quirksFontSizeTable[row] : strictFontSizeTable[row], 1); | 191 quirksMode ? quirksFontSizeTable[row] : strictFontSizeTable[row], 1); |
191 | 192 |
192 return findNearestLegacyFontSize<float>(pixelFontSize, fontSizeFactors, | 193 return findNearestLegacyFontSize<float>(pixelFontSize, fontSizeFactors, |
193 mediumSize); | 194 mediumSize); |
194 } | 195 } |
195 | 196 |
196 } // namespace blink | 197 } // namespace blink |
OLD | NEW |