FontPlatformDataWx.cpp [plain text]
#include "config.h"
#include "FontPlatformData.h"
#include "FontDescription.h"
#include "PlatformString.h"
#include <wx/defs.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
namespace WebCore {
static wxFontFamily fontFamilyToWxFontFamily(const int family)
{
switch (family) {
case FontDescription::StandardFamily:
return wxFONTFAMILY_DEFAULT;
case FontDescription::SerifFamily:
return wxFONTFAMILY_ROMAN;
case FontDescription::SansSerifFamily:
return wxFONTFAMILY_MODERN;
case FontDescription::MonospaceFamily:
return wxFONTFAMILY_TELETYPE; case FontDescription::CursiveFamily:
return wxFONTFAMILY_SCRIPT;
case FontDescription::FantasyFamily:
return wxFONTFAMILY_DECORATIVE;
default:
return wxFONTFAMILY_DEFAULT;
}
}
static wxFontWeight fontWeightToWxFontWeight(FontWeight weight)
{
if (weight >= FontWeight600)
return wxFONTWEIGHT_BOLD;
if (weight <= FontWeight300)
return wxFONTWEIGHT_LIGHT;
return wxFONTWEIGHT_NORMAL;
}
static int italicToWxFontStyle(bool isItalic)
{
if (isItalic)
return wxFONTSTYLE_ITALIC;
return wxFONTSTYLE_NORMAL;
}
FontPlatformData::FontPlatformData(const FontDescription& desc, const AtomicString& family)
{
#if __WXMSW__
m_font = adoptRef(new FontHolder(new wxFont( wxSize(0, -desc.computedPixelSize()),
fontFamilyToWxFontFamily(desc.genericFamily()),
italicToWxFontStyle(desc.italic()),
fontWeightToWxFontWeight(desc.weight()),
false,
family.string()
)
));
#else
m_font = adoptRef(new FontHolder(new wxFont( desc.computedPixelSize(),
fontFamilyToWxFontFamily(desc.genericFamily()),
italicToWxFontStyle(desc.italic()),
fontWeightToWxFontWeight(desc.weight()),
false,
family.string()
)
));
#endif
#if OS(DARWIN)
#if !wxOSX_USE_CORE_TEXT
#if wxCHECK_VERSION(2,9,0)
m_atsuFontID = m_font->font()->OSXGetATSUFontID();
#else
m_atsuFontID = m_font->font()->MacGetATSUFontID();
#endif
#endif
m_nsFont = 0;
cacheNSFont();
#endif
m_size = desc.computedPixelSize();
m_fontState = VALID;
m_size = desc.computedPixelSize();
}
unsigned FontPlatformData::computeHash() const
{
wxFont* thisFont = m_font->font();
ASSERT(thisFont && thisFont->IsOk());
uintptr_t hashCodes[6] = {
thisFont->GetPointSize(),
thisFont->GetFamily(),
thisFont->GetStyle(),
thisFont->GetWeight(),
thisFont->GetUnderlined(),
StringHasher::computeHash(thisFont->GetFaceName().utf8_str().data())
};
return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
}
FontPlatformData::~FontPlatformData()
{
m_fontState = UNINITIALIZED;
m_font = 0;
}
#ifndef NDEBUG
String FontPlatformData::description() const
{
return String();
}
#endif
#if OS(WINDOWS)
bool FontPlatformData::useGDI() const
{
return true;
}
HFONT FontPlatformData::hfont() const
{
return static_cast<HFONT>(m_font->font()->GetHFONT());
}
#endif
#if OS(DARWIN)
CGFontRef FontPlatformData::cgFont() const
{
CGFontRef cgFont = 0;
#ifdef wxOSX_USE_CORE_TEXT && wxOSX_USE_CORE_TEXT
cgFont = CTFontCopyGraphicsFont((CTFontRef)m_font->font()->OSXGetCTFont(), 0);
#else
ATSFontRef fontRef;
fontRef = FMGetATSFontRefFromFont(m_atsuFontID);
if (fontRef)
cgFont = CGFontCreateWithPlatformFont((void*)&fontRef);
#endif
return cgFont;
}
#endif
}