#import #import int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *fontName; int fontSize; NSFont *font; NSView *view; NSWindow *win; NSRect r; float w, *offsets; int i, len; if (argc < 2) { fontName = @"BitstreamVeraSansMono-Roman"; // @"Courier"; fontSize = 12; } else { fontName = [NSString stringWithCString: argv[1]]; fontSize = (argc == 3) ? atoi(argv[2]) : 12; } len = 10; offsets = (float *)malloc(len*2*sizeof(float)); [NSApplication sharedApplication]; font = [NSFont fontWithName: fontName size: fontSize]; if (font == nil) { NSLog(@"Unable to load font."); exit (1); } else { NSLog(@"Loaded font '%@'.", font); } font = [font screenFont] ? [font screenFont] : font; w = 5; for (i=0; i<2*len; i++) offsets[i] = w; r = NSMakeRect(0,0,400,300); view = [[NSView alloc] initWithFrame: r]; win = [[NSWindow alloc] initWithContentRect:r styleMask: (NSResizableWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask) backing: NSBackingStoreBuffered defer:YES]; [[win contentView] addSubview: view]; [win makeKeyAndOrderFront: view]; [win display]; // "direct" drawing { [view lockFocus]; NSGraphicsContext *ctxt = GSCurrentContext(); // Test to make sure everything is working.. /*r = NSMakeRect(100,100,50,50); [ctxt DPSmoveto: r.origin.x+10: r.origin.y+(r.size.height/2)]; DPSlineto(ctxt, r.origin.x+r.size.width-10, r.origin.y+(r.size.height));*/ [font set]; [[NSColor blackColor] set]; // DPSshow DPSmoveto(ctxt, 20,280); DPSshow(ctxt, "show"); // DPSxshow DPSmoveto(ctxt, 20,260); DPSxshow(ctxt, "xshow", offsets, len); // DPSashow DPSmoveto(ctxt, 140,240); DPSashow(ctxt, 10,10, "ashow"); // DPSwidthshow DPSmoveto(ctxt, 20,220); DPSwidthshow(ctxt, 10,10, 's', "widthshow"); // DPSawidthshow DPSmoveto(ctxt, 20,200); DPSawidthshow(ctxt, 10,10, 's', 10,10, "awidthshow"); // DPSyshow DPSmoveto(ctxt, 20,180); DPSyshow(ctxt, "yshow", offsets, len); DPSstroke(ctxt); [view unlockFocus]; [win flushWindow]; } // NSString -drawAtPoint:withAttributes /*{ NSDictionary *attribs; id objects[4], keys[4]; int n = 0; keys[n] = (id) NSFontAttributeName; objects[n++] = font; keys[n] = (id) NSLigatureAttributeName; objects[n++] = [NSNumber numberWithInt: 0]; attribs = [NSDictionary dictionaryWithObjects: objects forKeys: keys count: n]; [view lockFocus]; [str drawAtPoint: NSMakePoint(20, 200) withAttributes: attribs]; [view unlockFocus]; [win flushWindow]; }*/ [NSApp run]; [pool release]; return 0; }