Copyright ©1995 by NeXT Computer, Inc.  All Rights Reserved.

NXEPSImageRep



Inherits From: NXImageRep : Object
Declared In: appkit/NXEPSImageRep.h



Class Description

An NXEPSImageRep is an object that can render an image from encapsulated PostScript code (EPS).  The size of the object is set from the bounding box specified in the EPS header comments.  Other information about the image should be supplied using inherited NXImageRep methods.

Like most other kinds of NXImageReps, an NXEPSImageRep is generally used indirectly, through an NXImage object.



Instance Variables

None declared in this class.



Method Types

Initializing a new NXEPSImageRep instance
initFromSection:
initFromFile:
initFromStream:
Creating a List of NXEPSImageReps
+ newListFromSection:
+ newListFromSection:zone:
+ newListFromFile:
+ newListFromFile:zone:
+ newListFromStream:
+ newListFromStream:zone:
Copying and freeing an NXEPSImageRep
copyFromZone:
free
Getting the rectangle that bounds the image
getBoundingBox:
Getting image data getEPS:length:
Drawing the image prepareGState
drawIn:
draw
Archiving read:
write:



Instance Methods

newListFromFile:
+ (List *)newListFromFile:(const char *)filename

Creates one new NXEPSImageRep instance for each EPS image specified in the filename file, and returns a List object containing all the objects created.  If no NXEPSImageReps can be created (for example, if filename doesn't exist or it doesn't contain EPS code or data that can be filtered to EPS), nil is returned.  The List should be freed when it's no longer needed.

Each new NXEPSImageRep is initialized by the initFromFile: method, which reads a minimal amount of information about the image from the header comments in the file.  The PostScript code will be read when it's needed to render the image.

The EPS format doesn't support more than one image per file.  If filename contains EPS code, the List returned will be a list of one.

See also:  + newListFromFile:zone:, initFromFile:



newListFromFile:zone:
+ (List *)newListFromFile:(const char *)filename zone:(NXZone *)aZone

Returns a List of new NXEPSImageRep instances, just as newListFromFile: does, except that the NXEPSImageReps and the List object are allocated from memory located in  aZone.

See also:  + newListFromFile:, initFromFile:



newListFromSection:
+ (List *)newListFromSection:(const char *)name

Creates one new NXEPSImageRep instance for each image specified in the name section of the _ _EPS segment in the executable file or in the name file in the application bundle, and returns a List object containing all the objects created.  If not even one NXEPSImageRep can be created (for example, if the name section doesn't exist or it doesn't contain EPS code or data that can be filtered to EPS), nil is returned.  The List should be freed when it's no longer needed.

Each new NXEPSImageRep is initialized by the initFromSection: method, which reads a minimal amount of information about the image from the EPS header comments.  The PostScript code will be read only when it's needed to render the image.

The EPS format doesn't support more than one image per file.  If the name section or file contains EPS code, the List returned will be a list of one.

See also:  + newListFromSection:zone:, initFromSection:



newListFromSection:zone:
+ (List *)newListFromSection:(const char *)name zone:(NXZone *)aZone

Returns a List of new NXEPSImageRep instances, just as newListFromSection: does, except that the List object and the NXEPSImageReps are allocated from memory located in aZone.

See also:  + newListFromSection:, initFromSection:



newListFromStream:
+ (List *)newListFromStream:(NXStream *)stream

Creates one new NXEPSImageRep instance for each image that can be read from stream, and returns a List object containing all the objects created.  If not even one NXEPSImageRep can be created (for example, if the stream doesn't contain EPS code or data that can be converted to EPS), nil is returned.  The List should be freed when it's no longer needed.

The data is read and each new object initialized by the initFromStream: method.

See also:  + newListFromStream:zone:, initFromStream:



newListFromStream:zone:
+ (List *)newListFromStream:(NXStream *)stream zone:(NXZone *)aZone

Returns a List of new NXEPSImageRep instances, just as newListFromStream: does, except that the List object and the NXEPSImageReps are allocated from memory located in aZone.

See also:  + newListFromStream:, initFromStream:



Instance Methods

copyFromZone:
copyFromZone:(NXZone *)zone

Returns a new NXEPSImageRep instance that's an exact copy of the receiver.  The new object will have its own copy of the image data.  It doesn't need to be initialized.  Both object and data are allocated from zone.

See also:  copy (Object)



draw
(BOOL)draw

Draws the image at (0.0, 0.0) in the current coordinate system on the current device.  This method returns YES if successful in rendering the image, and NO if not.

An NXEPSImageRep draws in a separate PostScript context and graphics state.  Before the EPS code is interpreted, all graphics state parameters--with the exception of the CTM and device--are set to the Window Server's defaults and the defaults required by EPS conventions.  If you want to change any of these defaults, you can do so by implementing a prepareGState method in an NXEPSImageRep subclass.  The draw method invokes prepareGState just before sending the EPS code to the Window Server.  For example, if you need to set a transfer function or halftone screen that's specific to the image, prepareGState is the place to do it.

See also:  drawAt: (NXImageRep), drawIn:, prepareGState



drawIn:
(BOOL)drawIn:(const NXRect *)rect

Draws the image so that it fits inside the rectangle referred to by rect.  The current coordinate system is translated and scaled so the image will appear at the right location and fit within the rectangle.  The draw method is then invoked to produce the image. This method returns the value returned by the draw method, which indicates whether the image was successfully drawn.

The coordinate system is not restored after it has been altered.

See also:  draw, drawAt: (NXImageRep)



free
free

Deallocates the NXEPSImageRep.



getBoundingBox:
getBoundingBox:(NXRect *)theRect

Provides the rectangle that bounds the image.  The rectangle is copied from the "%%BoundingBox:" comment in the EPS header to structure referred to by theRect.  Returns self.



getEPS:length:
getEPS:(char **)theEPS length:(int *)numBytes

Sets the pointer referred to by theEPS so that it points to the EPS code.  The length of the code in bytes is provided in the integer referred to by numBytes.  Returns self.



init

Generates an error message.  This method can't be used to initialize an NXEPSImageRep.  Use one of the other init... methods instead.

See also:  initFromSection:, initFromFile:, initFromStream:



initFromFile:
initFromFile:(const char *)filename

Initializes the receiver, a newly allocated NXEPSImageRep object, with the EPS image found in the filename file.  Some information about the image is read from the EPS header comments, but the PostScript code won't be read until it's needed to render the image.

If the new object can't be initialized for any reason (for example, filename doesn't exist or doesn't contain EPS code), this method frees it and returns nil.  Otherwise, it returns self.

This method is the designated initializer for NXEPSImageReps that read EPS code from a file.

See also:  + newListFromFile:, initFromSection:



initFromSection:
initFromSection:(const char *)name

Initializes the receiver, a newly allocated NXEPSImageRep object, with the image found in the  name section in the _ _EPS segment of the application executable or the name file in the application bundle.  Some information about the image is read from the EPS header comments, but the PostScript code won't be read until it's needed to render the image.

If the new object can't be initialized for any reason (for example, the name section doesn't exist or doesn't contain EPS code), this method frees it and returns nil.  Otherwise, it returns self.

This method is the designated initializer for NXEPSImageReps that read image data from the _ _EPS segment.

See also:  + newListFromSection:, initFromFile:



initFromStream:
initFromStream:(NXStream *)stream

Initializes the receiver, a newly allocated NXEPSImageRep object, with the EPS image read from stream.  If the new object can't be initialized for any reason (for example, stream doesn't contain EPS code), this method frees it and returns nil. Otherwise, it returns self.

This method is the designated initializer for NXEPSImageReps that read image data from a stream.

See also:  + newListFromStream:



prepareGState
prepareGState

Implemented by subclasses to initialize the graphics state before the image is drawn.  The draw method sends a prepareGState message just before rendering the EPS code.  This default implementation of the method does no initialization; it simply returns self.

See also:  draw



read:
read:(NXTypedStream *)stream

Reads the NXEPSImageRep from the typed stream stream.

See also:  write:



write:
write:(NXTypedStream *)stream

Writes the NXEPSImageRep to the typed stream stream.

See also:  read: