File: GnuView.m

package info (click to toggle)
gnuplot 3.5beta6.340-5
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 4,792 kB
  • ctags: 4,205
  • sloc: ansic: 41,878; asm: 539; makefile: 498; objc: 379; csh: 297; sh: 277; pascal: 194; perl: 138; lisp: 88
file content (128 lines) | stat: -rw-r--r-- 2,149 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#import "GnuView.h"


@implementation GnuView

static NXCoord xsize= NEXT_XMAX;
static NXCoord ysize= NEXT_YMAX;

static int printing;
static void setprintsize();

- initFrame: (NXRect *)rects
{
    [super initFrame:rects];
		
	PSstring = NULL;
	[self display];

	return self;
}


	/* This is here to fix NeXT bug # 21973:  failure to free D.O. memory */
	/* Note:  personally I don't think this fixes it. */
- free
{
	if (PSstring) free(PSstring);
	[super free];
	
	return self;

}

- executePS:(char *) PStext
{
	if (PSstring) free(PSstring);
	PSstring = PStext;

	[window makeKeyAndOrderFront:self];

	[self display];

	return self;
}


- drawSelf:(const NXRect *) rects : (int) rectCount
{
    DPSContext d;
	
    d = DPSGetCurrentContext();

	if (!printing) {
							/* Clear Screen */ 
		PSsetgray(NX_WHITE);
		NXRectFill(&bounds);
							/* scale to gnuplot coords */
		[self setDrawSize:xsize:ysize];	
	}
	else {
		setprintsize();
	}

	if (PSstring) DPSWritePostScript(d, PSstring, strlen(PSstring));

    DPSFlushContext(d);

	return self;
}


- printPSCode: sender
{
	printing = 1;
	[super printPSCode:sender];
	printing = 0;
	
	return self;
}

static void setprintsize()
{
	DPSContext d;
	NXRect *paperRect;
	float width, height;
	id prInfo;
	float xscale, yscale;

    d = DPSGetCurrentContext();
	prInfo = [NXApp printInfo];
	paperRect = (NXRect *) [prInfo paperRect];
	
	width = paperRect->size.width;
	height = paperRect->size.height;

							/* Leave margins on paper */
	
	DPSPrintf(d, "grestore\ngrestore\ngrestore\n");
	

	if ([prInfo orientation] == NX_LANDSCAPE) {		
		DPSPrintf(d, "-90 rotate\n");
		DPSPrintf(d, "%g 0 translate\n", -1 * paperRect->size.width);
		DPSPrintf(d, "0 %g translate\n", paperRect->size.height/100);
		
		xscale = width/NEXT_XMAX*0.95;
		yscale = height/NEXT_YMAX*0.9;
		DPSPrintf(d, "%g %g scale\n", xscale, yscale);	
	}
	else {				
		xscale = width/NEXT_XMAX*0.95;
		yscale = height/NEXT_YMAX*0.95;	
		DPSPrintf(d, "%g %g scale\n", xscale, yscale);
		DPSPrintf(d, "0 %g translate\n", paperRect->size.height/100);
	}
		
	DPSPrintf(d, "gsave\ngsave\n");

    DPSFlushContext(d);

	return;
}



@end