This source file includes following definitions.
- getComputedSizeFromSpecifiedSize
- fontSizeForKeyword
- findNearestLegacyFontSize
- legacyFontSize
#include "config.h"
#include "core/css/FontSize.h"
#include "CSSValueKeywords.h"
#include "core/dom/Document.h"
#include "core/frame/Settings.h"
namespace WebCore {
float FontSize::getComputedSizeFromSpecifiedSize(const Document* document, float zoomFactor, bool isAbsoluteSize, float specifiedSize, ESmartMinimumForFontSize useSmartMinimumForFontSize)
{
if (fabsf(specifiedSize) < std::numeric_limits<float>::epsilon())
return 0.0f;
Settings* settings = document->settings();
if (!settings)
return 1.0f;
int minSize = settings->minimumFontSize();
int minLogicalSize = settings->minimumLogicalFontSize();
float zoomedSize = specifiedSize * zoomFactor;
if (zoomedSize < minSize)
zoomedSize = minSize;
if (useSmartMinimumForFontSize && zoomedSize < minLogicalSize && (specifiedSize >= minLogicalSize || !isAbsoluteSize))
zoomedSize = minLogicalSize;
return std::min(maximumAllowedFontSize, zoomedSize);
}
const int fontSizeTableMax = 16;
const int fontSizeTableMin = 9;
const int totalKeywords = 8;
static const int quirksFontSizeTable[fontSizeTableMax - fontSizeTableMin + 1][totalKeywords] =
{
{ 9, 9, 9, 9, 11, 14, 18, 28 },
{ 9, 9, 9, 10, 12, 15, 20, 31 },
{ 9, 9, 9, 11, 13, 17, 22, 34 },
{ 9, 9, 10, 12, 14, 18, 24, 37 },
{ 9, 9, 10, 13, 16, 20, 26, 40 },
{ 9, 9, 11, 14, 17, 21, 28, 42 },
{ 9, 10, 12, 15, 17, 23, 30, 45 },
{ 9, 10, 13, 16, 18, 24, 32, 48 }
};
static const int strictFontSizeTable[fontSizeTableMax - fontSizeTableMin + 1][totalKeywords] =
{
{ 9, 9, 9, 9, 11, 14, 18, 27 },
{ 9, 9, 9, 10, 12, 15, 20, 30 },
{ 9, 9, 10, 11, 13, 17, 22, 33 },
{ 9, 9, 10, 12, 14, 18, 24, 36 },
{ 9, 10, 12, 13, 16, 20, 26, 39 },
{ 9, 10, 12, 14, 17, 21, 28, 42 },
{ 9, 10, 13, 15, 18, 23, 30, 45 },
{ 9, 10, 13, 16, 18, 24, 32, 48 }
};
static const float fontSizeFactors[totalKeywords] = { 0.60f, 0.75f, 0.89f, 1.0f, 1.2f, 1.5f, 2.0f, 3.0f };
float FontSize::fontSizeForKeyword(const Document* document, int keyword, bool shouldUseFixedDefaultSize)
{
const Settings* settings = document->settings();
if (!settings)
return 1.0f;
bool quirksMode = document->inQuirksMode();
int mediumSize = shouldUseFixedDefaultSize ? settings->defaultFixedFontSize() : settings->defaultFontSize();
if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) {
int row = mediumSize - fontSizeTableMin;
int col = (keyword - CSSValueXxSmall);
return quirksMode ? quirksFontSizeTable[row][col] : strictFontSizeTable[row][col];
}
float minLogicalSize = std::max(settings->minimumLogicalFontSize(), 1);
return std::max(fontSizeFactors[keyword - CSSValueXxSmall] * mediumSize, minLogicalSize);
}
template<typename T>
static int findNearestLegacyFontSize(int pixelFontSize, const T* table, int multiplier)
{
for (int i = 1; i < totalKeywords - 1; i++) {
if (pixelFontSize * 2 < (table[i] + table[i + 1]) * multiplier)
return i;
}
return totalKeywords - 1;
}
int FontSize::legacyFontSize(const Document* document, int pixelFontSize, bool shouldUseFixedDefaultSize)
{
const Settings* settings = document->settings();
if (!settings)
return 1;
bool quirksMode = document->inQuirksMode();
int mediumSize = shouldUseFixedDefaultSize ? settings->defaultFixedFontSize() : settings->defaultFontSize();
if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) {
int row = mediumSize - fontSizeTableMin;
return findNearestLegacyFontSize<int>(pixelFontSize, quirksMode ? quirksFontSizeTable[row] : strictFontSizeTable[row], 1);
}
return findNearestLegacyFontSize<float>(pixelFontSize, fontSizeFactors, mediumSize);
}
}