1 /* 2 * This file is part of the internal font implementation. 3 * 4 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public License 17 * along with this library; see the file COPYING.LIB. If not, write to 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #import "config.h" 24 #import "FontPlatformData.h" 25 26 #import "PlatformString.h" 27 #import "WebCoreSystemInterface.h" 28 #import <AppKit/NSFont.h> 29 30 namespace WebCore { 31 32 FontPlatformData::FontPlatformData(NSFont *nsFont, bool syntheticBold, bool syntheticOblique) 33 : m_syntheticBold(syntheticBold) 34 , m_syntheticOblique(syntheticOblique) 35 , m_font(nsFont) 36 { 37 if (nsFont) 38 CFRetain(nsFont); 39 m_size = nsFont ? [nsFont pointSize] : 0.0f; 40 #ifndef BUILDING_ON_TIGER 41 m_cgFont.adoptCF(CTFontCopyGraphicsFont(toCTFontRef(nsFont), 0)); 42 m_atsuFontID = CTFontGetPlatformFont(toCTFontRef(nsFont), 0); 43 #else 44 m_cgFont = wkGetCGFontFromNSFont(nsFont); 45 m_atsuFontID = wkGetNSFontATSUFontId(nsFont); 46 #endif 47 } 48 49 FontPlatformData::FontPlatformData(const FontPlatformData& f) 50 { 51 m_font = f.m_font && f.m_font != reinterpret_cast<NSFont *>(-1) ? static_cast<const NSFont *>(CFRetain(f.m_font)) : f.m_font; 52 m_syntheticBold = f.m_syntheticBold; 53 m_syntheticOblique = f.m_syntheticOblique; 54 m_size = f.m_size; 55 m_cgFont = f.m_cgFont; 56 m_atsuFontID = f.m_atsuFontID; 57 } 58 59 FontPlatformData:: ~FontPlatformData() 60 { 61 if (m_font && m_font != reinterpret_cast<NSFont *>(-1)) 62 CFRelease(m_font); 63 } 64 65 const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& f) 66 { 67 m_syntheticBold = f.m_syntheticBold; 68 m_syntheticOblique = f.m_syntheticOblique; 69 m_size = f.m_size; 70 m_cgFont = f.m_cgFont; 71 m_atsuFontID = f.m_atsuFontID; 72 if (m_font == f.m_font) 73 return *this; 74 if (f.m_font && f.m_font != reinterpret_cast<NSFont *>(-1)) 75 CFRetain(f.m_font); 76 if (m_font && m_font != reinterpret_cast<NSFont *>(-1)) 77 CFRelease(m_font); 78 m_font = f.m_font; 79 return *this; 80 } 81 82 void FontPlatformData::setFont(NSFont *font) 83 { 84 if (m_font == font) 85 return; 86 if (font) 87 CFRetain(font); 88 if (m_font && m_font != reinterpret_cast<NSFont *>(-1)) 89 CFRelease(m_font); 90 m_font = font; 91 m_size = font ? [font pointSize] : 0.0f; 92 #ifndef BUILDING_ON_TIGER 93 m_cgFont.adoptCF(CTFontCopyGraphicsFont(toCTFontRef(font), 0)); 94 m_atsuFontID = CTFontGetPlatformFont(toCTFontRef(font), 0); 95 #else 96 m_cgFont = wkGetCGFontFromNSFont(font); 97 m_atsuFontID = wkGetNSFontATSUFontId(font); 98 #endif 99 } 100 101 bool FontPlatformData::roundsGlyphAdvances() const 102 { 103 return [m_font renderingMode] == NSFontAntialiasedIntegerAdvancementsRenderingMode; 104 } 105 106 bool FontPlatformData::allowsLigatures() const 107 { 108 return ![[m_font coveredCharacterSet] characterIsMember:'a']; 109 } 110 111 #ifndef NDEBUG 112 String FontPlatformData::description() const 113 { 114 RetainPtr<CFStringRef> cgFontDescription(AdoptCF, CFCopyDescription(cgFont())); 115 return String(cgFontDescription.get()) + " " + String::number(m_size) + (m_syntheticBold ? " synthetic bold" : "") + (m_syntheticOblique ? " syntheitic oblique" : ""); 116 } 117 #endif 118 119 } // namespace WebCore 120