SimpleFontDataWx.cpp [plain text]
#include "config.h"
#include "SimpleFontData.h"
#include "FontCache.h"
#include "FloatRect.h"
#include "FontDescription.h"
#include <wtf/MathExtras.h>
#include <unicode/uchar.h>
#include <unicode/unorm.h>
#if OS(DARWIN)
#include "WebCoreSystemInterface.h"
#endif
#include <wx/defs.h>
#include <wx/dcscreen.h>
#include <wx/string.h>
#include "fontprops.h"
namespace WebCore
{
void SimpleFontData::platformInit()
{
wxFont *font = m_platformData.font();
if (font && font->IsOk()) {
wxFontProperties props = wxFontProperties(font);
m_ascent = props.GetAscent();
m_descent = props.GetDescent();
m_lineSpacing = props.GetLineSpacing();
m_xHeight = props.GetXHeight();
m_unitsPerEm = 1; m_lineGap = props.GetLineGap();
}
m_syntheticBoldOffset = 0.0f;
#if OS(WINDOWS)
m_scriptCache = 0;
m_scriptFontProperties = 0;
m_isSystemFont = false;
#endif
}
void SimpleFontData::platformCharWidthInit()
{
m_avgCharWidth = 0.f;
m_maxCharWidth = 0.f;
initCharWidths();
}
void SimpleFontData::platformDestroy()
{
delete m_smallCapsFontData;
m_smallCapsFontData = 0;
#if OS(WINDOWS)
if (m_scriptFontProperties) {
delete m_scriptFontProperties;
m_scriptFontProperties = 0;
}
if (m_scriptCache)
ScriptFreeCache(&m_scriptCache);
#endif
}
SimpleFontData* SimpleFontData::smallCapsFontData(const FontDescription& fontDescription) const
{
if (!m_smallCapsFontData){
FontDescription desc = FontDescription(fontDescription);
desc.setSpecifiedSize(0.70f * fontDescription.computedSize());
FontPlatformData platformData(desc, desc.family().family());
m_smallCapsFontData = new SimpleFontData(platformData);
}
return m_smallCapsFontData;
}
bool SimpleFontData::containsCharacters(const UChar* characters, int length) const
{
#if OS(WINDOWS)
return wxFontContainsCharacters(m_platformData.hfont(), characters, length);
#elif OS(DARWIN)
return wxFontContainsCharacters(m_platformData.nsFont(), characters, length);
#endif
return true;
}
void SimpleFontData::determinePitch()
{
if (m_platformData.font() && m_platformData.font()->Ok())
m_treatAsFixedPitch = m_platformData.font()->IsFixedWidth();
else
m_treatAsFixedPitch = false;
}
FloatRect SimpleFontData::platformBoundsForGlyph(Glyph) const
{
return FloatRect();
}
float SimpleFontData::platformWidthForGlyph(Glyph glyph) const
{
#if __WXMSW__
return widthForGDIGlyph(glyph);
#elif OS(DARWIN)
float pointSize = m_platformData.size();
CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize);
CGSize advance;
NSFont* nsfont = (NSFont*)m_platformData.nsFont();
if (!wkGetGlyphTransformedAdvances(m_platformData.cgFont(), nsfont, &m, &glyph, &advance)) {
advance.width = 0;
}
return advance.width + m_syntheticBoldOffset;
#else
int width = 10;
GetTextExtent(*m_platformData.font(), (wxChar)glyph, &width, NULL);
return width;
#endif
}
#if OS(WINDOWS)
SCRIPT_FONTPROPERTIES* SimpleFontData::scriptFontProperties() const
{
return 0;
}
void SimpleFontData::initGDIFont()
{
}
void SimpleFontData::platformCommonDestroy()
{
}
float SimpleFontData::widthForGDIGlyph(Glyph glyph) const
{
HDC hdc = GetDC(0);
HGDIOBJ oldFont = SelectObject(hdc, m_platformData.hfont());
int width;
GetCharWidthI(hdc, glyph, 1, 0, &width);
SelectObject(hdc, oldFont);
ReleaseDC(0, hdc);
return width;
}
#endif
}