This source file includes following definitions.
- smallSystemFont
- menuFont
- labelFont
- pointsToPixels
- getNonClientMetrics
- systemFontSize
- systemFont
- setDefaultFontSize
#include "config.h"
#include "core/rendering/RenderThemeChromiumFontProvider.h"
#include <windows.h>
#include "CSSValueKeywords.h"
#include "platform/fonts/FontDescription.h"
#include "platform/win/HWndDC.h"
#include "platform/win/SystemInfo.h"
#include "wtf/text/WTFString.h"
#define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(structName, member) \
offsetof(structName, member) + \
(sizeof static_cast<structName*>(0)->member)
#define NONCLIENTMETRICS_SIZE_PRE_VISTA \
SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont)
namespace WebCore {
static FontDescription& smallSystemFont()
{
DEFINE_STATIC_LOCAL(FontDescription, font, ());
return font;
}
static FontDescription& menuFont()
{
DEFINE_STATIC_LOCAL(FontDescription, font, ());
return font;
}
static FontDescription& labelFont()
{
DEFINE_STATIC_LOCAL(FontDescription, font, ());
return font;
}
static float pointsToPixels(float points)
{
static float pixelsPerInch = 0.0f;
if (!pixelsPerInch) {
HWndDC hdc(0);
if (hdc)
pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
else
pixelsPerInch = 96.0f;
}
static const float pointsPerInch = 72.0f;
return points / pointsPerInch * pixelsPerInch;
}
static void getNonClientMetrics(NONCLIENTMETRICS* metrics)
{
static UINT size = isWindowsVistaOrGreater() ?
sizeof(NONCLIENTMETRICS) : NONCLIENTMETRICS_SIZE_PRE_VISTA;
metrics->cbSize = size;
bool success = !!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, size, metrics, 0);
ASSERT(success);
}
static float systemFontSize(const LOGFONT& font)
{
float size = -font.lfHeight;
if (size < 0) {
HFONT hFont = CreateFontIndirect(&font);
if (hFont) {
HWndDC hdc(0);
if (hdc) {
HGDIOBJ hObject = SelectObject(hdc, hFont);
TEXTMETRIC tm;
GetTextMetrics(hdc, &tm);
SelectObject(hdc, hObject);
size = tm.tmAscent;
}
DeleteObject(hFont);
}
}
return ((size < 12.0f) && (GetACP() == 936)) ? 12.0f : size;
}
void RenderThemeChromiumFontProvider::systemFont(CSSValueID valueID, FontDescription& fontDescription)
{
FontDescription* cachedDesc = 0;
AtomicString faceName;
float fontSize = 0;
switch (valueID) {
case CSSValueSmallCaption:
cachedDesc = &smallSystemFont();
if (!smallSystemFont().isAbsoluteSize()) {
NONCLIENTMETRICS metrics;
getNonClientMetrics(&metrics);
faceName = AtomicString(metrics.lfSmCaptionFont.lfFaceName, wcslen(metrics.lfSmCaptionFont.lfFaceName));
fontSize = systemFontSize(metrics.lfSmCaptionFont);
}
break;
case CSSValueMenu:
cachedDesc = &menuFont();
if (!menuFont().isAbsoluteSize()) {
NONCLIENTMETRICS metrics;
getNonClientMetrics(&metrics);
faceName = AtomicString(metrics.lfMenuFont.lfFaceName, wcslen(metrics.lfMenuFont.lfFaceName));
fontSize = systemFontSize(metrics.lfMenuFont);
}
break;
case CSSValueStatusBar:
cachedDesc = &labelFont();
if (!labelFont().isAbsoluteSize()) {
NONCLIENTMETRICS metrics;
getNonClientMetrics(&metrics);
faceName = metrics.lfStatusFont.lfFaceName;
fontSize = systemFontSize(metrics.lfStatusFont);
}
break;
case CSSValueWebkitMiniControl:
case CSSValueWebkitSmallControl:
case CSSValueWebkitControl:
faceName = defaultGUIFont();
fontSize = s_defaultFontSize - pointsToPixels(2);
break;
default:
faceName = defaultGUIFont();
fontSize = s_defaultFontSize;
break;
}
if (!cachedDesc)
cachedDesc = &fontDescription;
if (fontSize) {
cachedDesc->firstFamily().setFamily(faceName);
cachedDesc->setIsAbsoluteSize(true);
cachedDesc->setGenericFamily(FontDescription::NoFamily);
cachedDesc->setSpecifiedSize(fontSize);
cachedDesc->setWeight(FontWeightNormal);
cachedDesc->setStyle(FontStyleNormal);
}
fontDescription = *cachedDesc;
}
void RenderThemeChromiumFontProvider::setDefaultFontSize(int fontSize)
{
s_defaultFontSize = static_cast<float>(fontSize);
smallSystemFont() = menuFont() = labelFont() = FontDescription();
}
}