File:  [NeXTSTEP 3.3 examples] / Examples / AppKit / ScrollDoodScroll / PostScriptView.m
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:48:40 2018 UTC (8 years, 1 month ago) by root
Branches: NeXT, MAIN
CVS tags: NeXTSTEP33, HEAD
Sample Programs from NeXSTEP 3.3

// PostScriptView.m
// By Jayson Adams, NeXT Developer Support Team
// You may freely copy, distribute and reuse the code in this example.
// NeXT disclaims any warranty of any kind, expressed or implied, as to its
// fitness for any particular use.

#import <dpsclient/psops.h>
#import <appkit/NXImage.h>

#import "PostScriptView.h"

@implementation PostScriptView


/* instance methods */

- initFrame:(const NXRect *)frameRect
{
    [super initFrame:frameRect];

  /*
   * create an nximage to hold the PostScript image contained in our MachO
   * segment, created by Makefile.preamble; we'll "draw" by compositing the
   * resulting bits into ourself.  By making the image scalable, we can scale
   * the bitmap image by changing our nximage's size
   */

    postscriptImage = [[[NXImage alloc] initFromSection:"SampleImage"]
    							     setScalable:YES];
    
    return self;
}
    
- free
{
    [postscriptImage free];
    
    return [super free];
}

- scale:(float)factor
{
    NXSize	aSize;

  /*
   * if we resize the nximage, it will reexcute the PostScript
   * image with the new scale factor (resulting in a bitmap image that's
   * larger or smaller than before)
   */
    [postscriptImage getSize:&aSize];
    aSize.width *= factor;
    aSize.height *= factor;
    [postscriptImage setSize:&aSize];

    aSize.width = NX_WIDTH(&bounds) * factor;
    aSize.height = NX_HEIGHT(&bounds) * factor;
    [self sizeTo:aSize.width :aSize.height];
   
  /* show the new image */
    [self display];
    
    return self;
}

- drawSelf:(const NXRect *)rects :(int)rectCount
{
  /* erase update rect since the nximage might be smaller than our bounds */
    PSsetgray(NX_WHITE);
    NXRectFill(&(rects[0]));
    
  /*
   * copy the bits from the nximage into ourself;  note that we need not check
   * to see if we're printing since the nximage will do the right thing (i.e.
   * spit out PostScript) if we are
   */
    
    [postscriptImage composite:NX_SOVER
    		     fromRect:&(rects[0])
		     toPoint:&(rects[0].origin)];
    
    return self;
}

@end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.