FontPlatformData.h [plain text]
#ifndef FontPlatformData_h
#define FontPlatformData_h
#include "StringImpl.h"
#ifdef __OBJC__
@class NSFont;
#else
class NSFont;
#endif
#include <CoreFoundation/CFBase.h>
#include <objc/objc-auto.h>
namespace WebCore {
struct FontPlatformData {
class Deleted {};
FontPlatformData(Deleted)
: syntheticBold(false), syntheticOblique(false), m_font((NSFont*)-1)
{}
FontPlatformData(NSFont* f = 0, bool b = false, bool o = false)
: syntheticBold(b), syntheticOblique(o), m_font(f)
{
if (f)
CFRetain(f);
}
FontPlatformData(const FontPlatformData& f)
{
m_font = (f.m_font && f.m_font != (NSFont*)-1) ? (NSFont*)CFRetain(f.m_font) : f.m_font;
syntheticBold = f.syntheticBold;
syntheticOblique = f.syntheticOblique;
}
~FontPlatformData()
{
if (m_font && m_font != (NSFont*)-1)
CFRelease(m_font);
}
bool syntheticBold;
bool syntheticOblique;
unsigned hash() const
{
uintptr_t hashCodes[2] = { (uintptr_t)m_font, syntheticBold << 1 | syntheticOblique };
return StringImpl::computeHash(reinterpret_cast<UChar*>(hashCodes), sizeof(hashCodes) / sizeof(UChar));
}
bool operator==(const FontPlatformData& other) const
{
return m_font == other.m_font && syntheticBold == other.syntheticBold && syntheticOblique == other.syntheticOblique;
}
NSFont *font() const { return m_font; }
void setFont(NSFont* font) {
if (m_font == font)
return;
if (font && font != (NSFont*)-1)
CFRetain(font);
if (m_font && m_font != (NSFont*)-1)
CFRelease(m_font);
m_font = font;
}
private:
NSFont *m_font;
};
}
#endif