FontPlatformData.h [plain text]
#if (PLATFORM(CHROMIUM) && !OS(DARWIN)) || PLATFORM(BLACKBERRY)
#include "chromium/FontPlatformData.h"
#elif PLATFORM(QT)
#include "qt/FontPlatformData.h"
#elif PLATFORM(WIN) && OS(WINCE)
#include "wince/FontPlatformData.h"
#elif PLATFORM(WX)
#include "wx/FontPlatformData.h"
#elif (PLATFORM(EFL) || PLATFORM(GTK)) && USE(FREETYPE)
#include "freetype/FontPlatformData.h"
#elif (PLATFORM(EFL) || PLATFORM(GTK)) && USE(PANGO)
#include "pango/FontPlatformData.h"
#else
#ifndef FontPlatformData_h
#define FontPlatformData_h
#include "FontOrientation.h"
#include "FontWidthVariant.h"
#include "GlyphBuffer.h"
#include "TextOrientation.h"
#if PLATFORM(WIN)
#include "RefCountedGDIHandle.h"
#endif
#if USE(CAIRO)
#include <wtf/HashFunctions.h>
#include <cairo.h>
#endif
#if OS(DARWIN)
OBJC_CLASS NSFont;
#import <GraphicsServices/GraphicsServices.h>
typedef struct CGFont* CGFontRef;
typedef const struct __CTFont* CTFontRef;
#include <CoreFoundation/CFBase.h>
#include <objc/objc-auto.h>
#endif
#include <wtf/Forward.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RetainPtr.h>
#include <wtf/text/StringImpl.h>
#if PLATFORM(CHROMIUM) && OS(DARWIN)
#include "CrossProcessFontLoading.h"
#endif
#if PLATFORM(WIN)
typedef struct HFONT__* HFONT;
#endif
#if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
typedef struct CGFont* CGFontRef;
#if OS(DARWIN)
typedef const struct __CTFont* CTFontRef;
typedef UInt32 FMFont;
typedef FMFont ATSUFontID;
typedef UInt32 ATSFontRef;
#endif
#endif
namespace WebCore {
class FontDescription;
class SharedBuffer;
class FontPlatformData {
public:
FontPlatformData(WTF::HashTableDeletedValueType)
: m_syntheticBold(false)
, m_syntheticOblique(false)
, m_orientation(Horizontal)
, m_textOrientation(TextOrientationVerticalRight)
, m_isEmoji(false)
, m_size(0)
, m_widthVariant(RegularWidth)
#if PLATFORM(WIN)
, m_font(WTF::HashTableDeletedValue)
#elif OS(DARWIN)
, m_font(hashTableDeletedFontValue())
#endif
#if USE(CG) && PLATFORM(WIN)
, m_cgFont(0)
#elif USE(CAIRO)
, m_scaledFont(hashTableDeletedFontValue())
#endif
, m_isColorBitmapFont(false)
, m_isCompositeFontReference(false)
#if OS(DARWIN)
, m_isPrinterFont(false)
#endif
#if PLATFORM(WIN)
, m_useGDI(false)
#endif
{
}
FontPlatformData()
: m_syntheticBold(false)
, m_syntheticOblique(false)
, m_orientation(Horizontal)
, m_textOrientation(TextOrientationVerticalRight)
, m_isEmoji(false)
, m_size(0)
, m_widthVariant(RegularWidth)
#if OS(DARWIN)
, m_font(0)
#endif
#if USE(CG) && PLATFORM(WIN)
, m_cgFont(0)
#elif USE(CAIRO)
, m_scaledFont(0)
#endif
, m_isColorBitmapFont(false)
, m_isCompositeFontReference(false)
#if OS(DARWIN)
, m_isPrinterFont(false)
#endif
#if PLATFORM(WIN)
, m_useGDI(false)
#endif
{
}
FontPlatformData(const FontPlatformData&);
FontPlatformData(const FontDescription&, const AtomicString& family);
FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation = Horizontal,
TextOrientation textOrientation = TextOrientationVerticalRight, FontWidthVariant widthVariant = RegularWidth)
: m_syntheticBold(syntheticBold)
, m_syntheticOblique(syntheticOblique)
, m_orientation(orientation)
, m_textOrientation(textOrientation)
, m_isEmoji(false)
, m_size(size)
, m_widthVariant(widthVariant)
#if OS(DARWIN)
, m_font(0)
#endif
#if USE(CG) && PLATFORM(WIN)
, m_cgFont(0)
#elif USE(CAIRO)
, m_scaledFont(0)
#endif
, m_isColorBitmapFont(false)
, m_isCompositeFontReference(false)
#if OS(DARWIN)
, m_isPrinterFont(false)
#endif
#if PLATFORM(WIN)
, m_useGDI(false)
#endif
{
}
#if OS(DARWIN)
FontPlatformData(GSFontRef, float size, bool isPrinterFont = false, bool syntheticBold = false, bool syntheticOblique = false,
FontOrientation = Horizontal, TextOrientation = TextOrientationVerticalRight, FontWidthVariant = RegularWidth);
#if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation,
TextOrientation textOrientation, FontWidthVariant widthVariant)
: m_syntheticBold(syntheticBold)
, m_syntheticOblique(syntheticOblique)
, m_orientation(orientation)
, m_textOrientation(textOrientation)
, m_isEmoji(false)
, m_size(size)
, m_widthVariant(widthVariant)
, m_font(0)
, m_cgFont(cgFont)
, m_isColorBitmapFont(false)
, m_isCompositeFontReference(false)
, m_isPrinterFont(false)
{
}
#endif
#endif
#if PLATFORM(WIN)
FontPlatformData(HFONT, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
#if USE(CG)
FontPlatformData(HFONT, CGFontRef, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
#endif
#endif
#if USE(CAIRO)
FontPlatformData(cairo_font_face_t*, float size, bool bold, bool italic);
#endif
FontPlatformData(CTFontRef, float size, bool syntheticBold = false, bool syntheticOblique = false, FontOrientation = Horizontal, TextOrientation = TextOrientationVerticalRight, FontWidthVariant = RegularWidth);
~FontPlatformData();
GSFontRef font() const { return m_font; }
void setFont(GSFontRef font);
#if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
#if OS(DARWIN)
CGFontRef cgFont() const { return m_cgFont.get(); }
CTFontRef ctFont() const;
bool roundsGlyphAdvances() const { return false; }
bool allowsLigatures() const;
#else
CGFontRef cgFont() const { return m_cgFont.get(); }
#endif
#endif
bool isFixedPitch() const;
float size() const { return m_size; }
void setSize(float size) { m_size = size; }
bool syntheticBold() const { return m_syntheticBold; }
bool syntheticOblique() const { return m_syntheticOblique; }
bool isColorBitmapFont() const { return m_isColorBitmapFont; }
bool isCompositeFontReference() const { return m_isCompositeFontReference; }
#if OS(DARWIN)
bool isPrinterFont() const { return m_isPrinterFont; }
#endif
FontOrientation orientation() const { return m_orientation; }
TextOrientation textOrientation() const { return m_textOrientation; }
FontWidthVariant widthVariant() const { return m_widthVariant; }
void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
#if USE(CAIRO)
cairo_scaled_font_t* scaledFont() const { return m_scaledFont; }
#endif
unsigned hash() const
{
#if PLATFORM(WIN) && !USE(CAIRO)
return m_font ? m_font->hash() : 0;
#elif OS(DARWIN)
ASSERT(m_font != 0 || m_cgFont == 0 || m_isEmoji != 0);
uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, m_isEmoji << 5 | m_isPrinterFont << 4 | m_textOrientation << 3 | m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique };
return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
#elif USE(CAIRO)
return PtrHash<cairo_scaled_font_t*>::hash(m_scaledFont);
#endif
}
const FontPlatformData& operator=(const FontPlatformData&);
bool operator==(const FontPlatformData& other) const
{
return platformIsEqual(other)
&& m_size == other.m_size
&& m_syntheticBold == other.m_syntheticBold
&& m_syntheticOblique == other.m_syntheticOblique
&& m_isColorBitmapFont == other.m_isColorBitmapFont
&& m_isCompositeFontReference == other.m_isCompositeFontReference
#if OS(DARWIN)
&& m_isPrinterFont == other.m_isPrinterFont
#endif
&& m_orientation == other.m_orientation
&& m_textOrientation == other.m_textOrientation
&& m_widthVariant == other.m_widthVariant;
}
bool isHashTableDeletedValue() const
{
#if PLATFORM(WIN) && !USE(CAIRO)
return m_font.isHashTableDeletedValue();
#elif OS(DARWIN)
return m_font == hashTableDeletedFontValue();
#elif USE(CAIRO)
return m_scaledFont == hashTableDeletedFontValue();
#endif
}
#if PLATFORM(WIN) && (USE(CG) || USE(CAIRO))
PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const;
#endif
#ifndef NDEBUG
String description() const;
#endif
private:
bool platformIsEqual(const FontPlatformData&) const;
void platformDataInit(const FontPlatformData&);
const FontPlatformData& platformDataAssign(const FontPlatformData&);
static GSFontRef hashTableDeletedFontValue() { return reinterpret_cast<GSFontRef>(-1); }
#if USE(CAIRO)
static cairo_scaled_font_t* hashTableDeletedFontValue() { return reinterpret_cast<cairo_scaled_font_t*>(-1); }
#endif
public:
bool m_syntheticBold;
bool m_syntheticOblique;
FontOrientation m_orientation;
TextOrientation m_textOrientation;
bool m_isEmoji;
float m_size;
FontWidthVariant m_widthVariant;
private:
GSFontRef m_font;
#if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
#if PLATFORM(WIN)
RetainPtr<CGFontRef> m_cgFont;
#else
RetainPtr<CGFontRef> m_cgFont;
mutable RetainPtr<CTFontRef> m_CTFont;
#endif
#endif
#if USE(CAIRO)
cairo_scaled_font_t* m_scaledFont;
#endif
#if PLATFORM(CHROMIUM) && OS(DARWIN)
RefPtr<MemoryActivatedFont> m_inMemoryFont;
#endif
bool m_isColorBitmapFont;
bool m_isCompositeFontReference;
#if OS(DARWIN)
bool m_isPrinterFont;
#endif
#if PLATFORM(WIN)
bool m_useGDI;
#endif
};
}
#endif // FontPlatformData_h
#endif