/* A large implementation using NSTextStorage and NSLayoutManager. This is probably the most correct way to do it, since fonts get replaced, etc., but there is NO way to render a character at a time, so irregular fonts or international miscellany cause problems. In an ideal world, ns_dumpglyphs() would just create a single attributed string for its whole job and use this approach though. */ /* First comes an ifdef'd version that will work on OS X < 10.3 and use the current method in nsterm.m for 10.3+. */ // TextStorage and friends static NSMutableDictionary *attribs; static BOOL firstTime = YES; static NSNumber *noUL, *yesUL; static CGFontRef fontref = 0; static NSString *lastFontName = nil; static float lastFontSize = 0; #ifdef MAC_OS_X_VERSION_10_3 static EmacsGlyphStorage *glyphStorage; static NSGlyphGenerator *glyphGenerator; #else static NSTextStorage *store; static NSLayoutManager *layout; static NSRange range; static NSRange glyphRange; static NSGlyph glyphs[1024]; static CGGlyph cglyphs[1024]; #endif float px = x; float py = y + [font boundingRectForFont].size.height + [font descender]; if (!font) error ("NO FONT"); if (firstTime == YES) { id objects[4], keys[4]; int n = 0; noUL = [[NSNumber alloc] initWithInt: NSUnderlineStyleNone]; yesUL = [[NSNumber alloc] initWithInt: NSUnderlineStyleSingle]; keys[n] = (id) NSFontAttributeName; objects[n++] = font; keys[n] = (id) NSForegroundColorAttributeName; objects[n++] = [NSColor blackColor]; keys[n] = (id) NSUnderlineStyleAttributeName; objects[n++] = noUL; attribs = [NSMutableDictionary dictionaryWithObjects: objects forKeys: keys count: n]; firstTime = NO; #ifdef MAC_OS_X_VERSION_10_3 glyphStorage = [[EmacsGlyphStorage alloc] init]; glyphGenerator = [NSGlyphGenerator sharedGlyphGenerator]; #else range = NSMakeRange(0,0); store = [[NSTextStorage alloc] init]; layout = [[NSLayoutManager alloc] init]; [store addLayoutManager: layout]; [layout release]; #endif } #ifdef MAC_OS_X_VERSION_10_3 [glyphStorage setString: [NSString stringWithUTF8String: buf] font: font]; #else range.length = [store length]; [store beginEditing]; [store deleteCharactersInRange: range]; [[store mutableString] appendString: [NSString stringWithUTF8String: buf]]; range.length = [store length]; if (font) [attribs setObject: font forKey: NSFontAttributeName]; if (col) [attribs setObject: col forKey: NSForegroundColorAttributeName]; else [attribs setObject: [NSColor blackColor] forKey: NSForegroundColorAttributeName]; if (ul) [attribs setObject: yesUL forKey: NSUnderlineStyleAttributeName]; else [attribs setObject: noUL forKey: NSUnderlineStyleAttributeName]; [store addAttributes: attribs range: range]; [store endEditing]; #endif #ifdef MAC_OS_X_VERSION_10_3 unsigned int gInd = 0; unsigned int cInd = 0; [glyphGenerator generateGlyphsForGlyphStorage: glyphStorage desiredNumberOfCharacters: glyphStorage->maxChar glyphIndex: &gInd characterIndex: &cInd]; #else glyphRange = [layout glyphRangeForCharacterRange: range actualCharacterRange: nil]; //1 // [layout drawGlyphsForGlyphRange: glyphRange // atPoint: NSMakePoint(px, py)]; //2 // int len = glyphRange.length; // glyphRange.length = 1; // fprintf(stderr,"%.1f\n",w); // NSPoint pos = NSMakePoint(px,py); // for (glyphRange.location=0; glyphRange.locationcglyphs; int len = glyphStorage->maxGlyph; for (i=0; i