00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */ 00002 00003 /* AbiSource Application Framework 00004 * Copyright (C) 1998 AbiSource, Inc. 00005 * Copyright (C) 2001-2003 Hubert Figuiere 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License 00009 * as published by the Free Software Foundation; either version 2 00010 * of the License, or (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00020 * 02111-1307, USA. 00021 */ 00022 00023 #ifndef XAP_COCOAFONT_H 00024 #define XAP_COCOAFONT_H 00025 00026 #import <Cocoa/Cocoa.h> 00027 00028 #include "ut_vector.h" 00029 #include "gr_Graphics.h" 00030 00031 00032 /* 00033 We derive our handle from GR_Font so we can be passed around the GR 00034 contexts as a native Cocoa font. 00035 GR_Font is a completely virtual class with no data or accessors of 00036 its own. 00037 */ 00038 00039 class XAP_CocoaFont : public GR_Font 00040 { 00041 public: 00042 XAP_CocoaFont(); 00043 XAP_CocoaFont(NSFont * font); 00044 XAP_CocoaFont(const XAP_CocoaFont & copy); 00045 00046 ~XAP_CocoaFont(); 00047 00048 ATSUStyle makeAtsuStyle(NSFont *font) const; 00049 NSFont * getNSFont(void) const 00050 { return m_font; } 00051 00052 UT_uint32 getSize(void); 00053 const char * getName(void); 00054 00055 float getAscent(); 00056 float getDescent(); /* returns -descent because it is <0 on CG */ 00057 float getHeight(); 00058 void getCoverage(UT_NumberVector& coverage); 00059 00060 virtual UT_sint32 measureUnremappedCharForCache(UT_UCSChar cChar) const; 00061 // 00062 // UT_Rect of glyph in Logical units. 00063 // rec.left = bearing Left (distance from origin to start) 00064 // rec.width = width of the glyph 00065 // rec.top = distance from the origin to the top of the glyph 00066 // rec.height = total height of the glyph 00067 00068 virtual bool glyphBox(UT_UCS4Char g, UT_Rect & rec, GR_Graphics *); 00069 00070 enum RemapFont { 00071 rf_None = 0, 00072 rf_Symbols, 00073 rf_Dings 00074 }; 00075 bool needsRemap() 00076 { 00077 return m_rfRemap; 00078 } 00079 static RemapFont remapFont(NSFont * font); 00080 static UT_UCS4Char remapChar(UT_UCS4Char charCode, RemapFont rf); 00081 UT_UCS4Char remapChar(UT_UCS4Char charCode) const 00082 { return m_rfRemap ? remapChar(charCode, m_rfRemap) : charCode; } 00083 00084 private: 00085 RemapFont m_rfRemap; 00086 00087 NSFont * m_font; 00088 mutable ATSUStyle m_styleForCache; 00089 00090 void _resetMetricsCache(); 00091 static void _initMetricsLayouts(void); 00092 00096 UT_sint32 _measureChar(UT_UCSChar cChar, ATSUStyle style) const; 00097 00098 /* metrics cache */ 00099 UT_uint32 _m_size; 00100 volatile float _m_ascent; 00101 volatile float _m_descent; 00102 volatile float _m_height; 00103 UT_NumberVector * _m_coverage; 00104 mutable unichar _m_text[2]; 00107 static ATSUTextLayout s_atsuLayout; 00108 }; 00109 00110 @interface XAP_CocoaFontFamilyHelper : NSObject 00111 { 00112 NSString * m_FontFamilyName; 00113 NSAttributedString * m_AttributedFontFamilyName; 00114 00115 NSMutableArray * m_FontNames; 00116 NSMutableArray * m_FontMembers; 00117 NSMutableArray * m_AttributedFontMembers; 00118 00119 unsigned m_count; 00120 00121 int m_indexRegular; 00122 int m_indexItalic; 00123 int m_indexBold; 00124 int m_indexBoldItalic; 00125 } 00126 + (NSMutableDictionary *)fontFamilyHelperDictionary:(NSMutableDictionary *)referenceDictionary; 00127 00128 - (id)initWithFontFamilyName:(NSString *)fontFamilyName known:(BOOL)known; 00129 - (void)dealloc; 00130 00131 - (NSString *)fontFamilyName; 00132 - (NSAttributedString *)attributedFontFamilyName; 00133 00134 - (unsigned)count; 00135 00136 - (NSArray *)fontNames; 00137 - (NSArray *)fontMembers; 00138 - (NSArray *)attributedFontMembers; 00139 00140 /* These return -1 if there is no matching font member. 00141 */ 00142 - (int)indexRegular; 00143 - (int)indexItalic; 00144 - (int)indexBold; 00145 - (int)indexBoldItalic; 00146 00147 - (void)addFontReferences:(NSMutableDictionary *)referenceDictionary; 00148 @end 00149 00150 @interface XAP_CocoaFontReference : NSObject 00151 { 00152 NSString * m_FontFamily; 00153 00154 XAP_CocoaFontFamilyHelper * m_FontFamilyHelper; 00155 00156 unsigned m_index; 00157 } 00158 - (id)initWithFontFamily:(NSString *)fontFamily helper:(XAP_CocoaFontFamilyHelper *)helper index:(unsigned)index; 00159 - (void)dealloc; 00160 00161 - (NSString *)fontFamily; 00162 00163 - (XAP_CocoaFontFamilyHelper *)fontFamilyHelper; 00164 00165 - (unsigned)index; 00166 @end 00167 00168 #endif /* XAP_COCOAFONT_H */