Georg Seifert wrote:

 [NSView dataWithEPSInsideRect:] does not seem to help, unless I
build a dummy view, draw in it and then use this method.

I believe that's the general idea. An NSBezierPath instance by itself doesn't really do anything unless/until you draw it into a suitable graphics context. Read the Cocoa Drawing Guide; in particular, the 'Creating Graphics Contexts' chapter.

but this seems to be quite complicated.


I'm no graphics guru (so try not to laugh), but here's a simple example:


/////// CustomView.h ///////

#import <Cocoa/Cocoa.h>

@interface CustomView : NSView {
}

- (NSEPSImageRep *)epsImageRep;

@end


/////// CustomView.m ///////

#import "CustomView.h"

@implementation CustomView

- (void)drawRect:(NSRect)rect {
// do all your drawing here... e.g. to draw a black rectangle in middle of view:
        [[NSBezierPath bezierPathWithRect: NSMakeRect(10, 10, 20, 20)] fill];
}

- (NSEPSImageRep *)epsImageRep {
        NSData* theData = [self dataWithEPSInsideRect: [self bounds]];
        return [NSEPSImageRep imageRepWithData: theData];
}

@end


/////// main.m ///////

int main(int argc, char *argv[])
{
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        
        // create a custom view of the desired size
CustomView *view = [[CustomView alloc] initWithFrame: NSMakeRect(0, 0, 40, 40)];
        
        // extract an EPS image rep from it
        NSEPSImageRep *epsRep = [view epsImageRep];

        // do some stuff with the EPS image rep here... e.g. to write to file:
[[epsRep EPSRepresentation] writeToFile: @"/Users/foobar/test.eps" atomically: NO];
        
        [view release];
        [pool release];
        return 0;
}


HTH

has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to