2 * This file is part of the internal font implementation.
3 * It should not be included by source files outside it.
5 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #ifndef FontPlatformData_h
25 #define FontPlatformData_h
27 #include "StringImpl.h"
35 typedef struct CGFont* CGFontRef;
36 typedef UInt32 ATSUFontID;
37 #ifndef BUILDING_ON_TIGER
38 typedef const struct __CTFont* CTFontRef;
41 #include <CoreFoundation/CFBase.h>
42 #include <objc/objc-auto.h>
43 #include <wtf/RetainPtr.h>
47 #ifndef BUILDING_ON_TIGER
48 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef>(nsFont); }
51 struct FontPlatformData {
52 FontPlatformData(float size, bool syntheticBold, bool syntheticOblique)
53 : m_syntheticBold(syntheticBold)
54 , m_syntheticOblique(syntheticOblique)
58 #ifdef BUILDING_ON_TIGER
64 FontPlatformData(NSFont * = 0, bool syntheticBold = false, bool syntheticOblique = false);
66 FontPlatformData(CGFontRef f, ATSUFontID fontID, float s, bool b , bool o)
67 : m_syntheticBold(b), m_syntheticOblique(o), m_atsuFontID(fontID), m_size(s), m_font(0), m_cgFont(f)
71 FontPlatformData(const FontPlatformData&);
75 FontPlatformData(WTF::HashTableDeletedValueType) : m_font(hashTableDeletedFontValue()) { }
76 bool isHashTableDeletedValue() const { return m_font == hashTableDeletedFontValue(); }
78 float size() const { return m_size; }
81 bool m_syntheticOblique;
83 ATSUFontID m_atsuFontID;
88 ASSERT(m_font != 0 || m_cgFont == 0);
89 uintptr_t hashCodes[2] = { (uintptr_t)m_font, m_syntheticBold << 1 | m_syntheticOblique };
90 return StringImpl::computeHash(reinterpret_cast<UChar*>(hashCodes), sizeof(hashCodes) / sizeof(UChar));
93 const FontPlatformData& operator=(const FontPlatformData& f);
95 bool operator==(const FontPlatformData& other) const
97 return m_font == other.m_font && m_syntheticBold == other.m_syntheticBold && m_syntheticOblique == other.m_syntheticOblique &&
98 m_cgFont == other.m_cgFont && m_size == other.m_size && m_atsuFontID == other.m_atsuFontID;
101 NSFont *font() const { return m_font; }
102 void setFont(NSFont *font);
104 #ifndef BUILDING_ON_TIGER
105 CGFontRef cgFont() const { return m_cgFont.get(); }
107 CGFontRef cgFont() const { return m_cgFont; }
111 static NSFont *hashTableDeletedFontValue() { return reinterpret_cast<NSFont *>(-1); }
114 #ifndef BUILDING_ON_TIGER
115 RetainPtr<CGFontRef> m_cgFont;
117 CGFontRef m_cgFont; // It is not necessary to refcount this, since either an NSFont owns it or some CachedFont has it referenced.