Annotation of OpenXM_contrib/gnuplot/NeXT/GnuView.m, Revision 1.1
1.1 ! maekawa 1: #import "GnuView.h"
! 2:
! 3:
! 4: @implementation GnuView
! 5:
! 6: static NXCoord xsize= NEXT_XMAX;
! 7: static NXCoord ysize= NEXT_YMAX;
! 8:
! 9: static int printing;
! 10: static void setprintsize();
! 11:
! 12: - initFrame: (NXRect *)rects
! 13: {
! 14: [super initFrame:rects];
! 15:
! 16: PSstring = NULL;
! 17: [self display];
! 18:
! 19: return self;
! 20: }
! 21:
! 22:
! 23: /* This is here to fix NeXT bug # 21973: failure to free D.O. memory */
! 24: /* Note: personally I don't think this fixes it. */
! 25: - free
! 26: {
! 27: if (PSstring) free(PSstring);
! 28: [super free];
! 29:
! 30: return self;
! 31:
! 32: }
! 33:
! 34: - executePS:(char *) PStext
! 35: {
! 36: if (PSstring) free(PSstring);
! 37: PSstring = PStext;
! 38:
! 39: [window makeKeyAndOrderFront:self];
! 40:
! 41: [self display];
! 42:
! 43: return self;
! 44: }
! 45:
! 46:
! 47: - drawSelf:(const NXRect *) rects : (int) rectCount
! 48: {
! 49: DPSContext d;
! 50:
! 51: d = DPSGetCurrentContext();
! 52:
! 53: if (!printing) {
! 54: /* Clear Screen */
! 55: PSsetgray(NX_WHITE);
! 56: NXRectFill(&bounds);
! 57: /* scale to gnuplot coords */
! 58: [self setDrawSize:xsize:ysize];
! 59: }
! 60: else {
! 61: setprintsize();
! 62: }
! 63:
! 64: if (PSstring) DPSWritePostScript(d, PSstring, strlen(PSstring));
! 65:
! 66: DPSFlushContext(d);
! 67:
! 68: return self;
! 69: }
! 70:
! 71:
! 72: - printPSCode: sender
! 73: {
! 74: printing = 1;
! 75: [super printPSCode:sender];
! 76: printing = 0;
! 77:
! 78: return self;
! 79: }
! 80:
! 81: static void setprintsize()
! 82: {
! 83: DPSContext d;
! 84: NXRect *paperRect;
! 85: float width, height;
! 86: id prInfo;
! 87: float xscale, yscale;
! 88:
! 89: d = DPSGetCurrentContext();
! 90: prInfo = [NXApp printInfo];
! 91: paperRect = (NXRect *) [prInfo paperRect];
! 92:
! 93: width = paperRect->size.width;
! 94: height = paperRect->size.height;
! 95:
! 96: /* Leave margins on paper */
! 97:
! 98: DPSPrintf(d, "grestore\ngrestore\ngrestore\n");
! 99:
! 100:
! 101: if ([prInfo orientation] == NX_LANDSCAPE) {
! 102: DPSPrintf(d, "-90 rotate\n");
! 103: DPSPrintf(d, "%g 0 translate\n", -1 * paperRect->size.width);
! 104: DPSPrintf(d, "0 %g translate\n", paperRect->size.height/100);
! 105:
! 106: xscale = width/NEXT_XMAX*0.95;
! 107: yscale = height/NEXT_YMAX*0.9;
! 108: DPSPrintf(d, "%g %g scale\n", xscale, yscale);
! 109: }
! 110: else {
! 111: xscale = width/NEXT_XMAX*0.95;
! 112: yscale = height/NEXT_YMAX*0.95;
! 113: DPSPrintf(d, "%g %g scale\n", xscale, yscale);
! 114: DPSPrintf(d, "0 %g translate\n", paperRect->size.height/100);
! 115: }
! 116:
! 117: DPSPrintf(d, "gsave\ngsave\n");
! 118:
! 119: DPSFlushContext(d);
! 120:
! 121: return;
! 122: }
! 123:
! 124:
! 125:
! 126: @end
! 127:
! 128:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>