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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
// Copyright (C) 1999-2017
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"
#include "grid2dbase.h"
#include "attribute.h"
#include "widget.h"
extern "C" {
#include "ast.h"
#include "grf.h"
}
Grid2dBase* astGrid2dPtr = NULL;
Grid2dBase::Grid2dBase(Widget* p) : GridBase(p)
{}
Grid2dBase::Grid2dBase(Widget* p, const char* o) : GridBase(p,o)
{}
Grid2dBase::~Grid2dBase()
{}
int Grid2dBase::gLine(int n, float* x, float* y)
{
switch (renderMode_) {
case X11:
x11Line(n,x,y);
break;
case PS:
psLine(n,x,y);
break;
case MACOSX:
#ifdef MAC_OSX_TK
macosxLine(n,x,y);
#endif
break;
case GWIN32:
#ifdef __WIN32
win32Line(n,x,y);
#endif
break;
}
return 1;
}
int Grid2dBase::gQch(float* chv, float* chh)
{
Tk_Font font =NULL;
switch (renderMode_) {
case X11:
font = text_->tkfont();
break;
case PS:
font = text_->psfont();
break;
case MACOSX:
#ifdef MAC_OSX_TK
font = text_->tkfont();
#endif
break;
case GWIN32:
#ifdef __WIN32
font = text_->tkfont();
#endif
break;
}
if (font) {
Tk_FontMetrics metrics;
Tk_GetFontMetrics(font, &metrics);
*chv = (float)metrics.linespace;
*chh = (float)metrics.linespace;
return 1;
}
else {
*chv = *chh = 0;
return 0;
}
}
int Grid2dBase::gText(const char* txt, float x, float y, const char* just,
float upx, float upy)
{
if (!(txt && txt[0] && just && just[0] && just[1]))
return 0;
switch (renderMode_) {
case X11:
return x11Text(txt,x,y,just,Vector(upx,upy));
case PS:
return psText(txt,x,y,just,Vector(upx,upy));
case MACOSX:
#ifdef MAC_OSX_TK
return macosxText(txt,x,y,just,Vector(upx,upy));
#endif
break;
case GWIN32:
#ifdef __WIN32
return win32Text(txt,x,y,just,Vector(upx,upy));
#endif
break;
}
return 0;
}
int Grid2dBase::gTxExt(const char* txt, float x, float y, const char* just,
float upx, float upy, float* xb, float* yb)
{
if (!(txt && txt[0] && just)) {
xb[0] = xb[1] = xb[2] = xb[3] = 0;
yb[0] = yb[1] = yb[2] = yb[3] = 0;
return 0;
}
Tk_Font font =NULL;
switch (renderMode_) {
case X11:
font = text_->tkfont();
break;
case PS:
font = text_->psfont();
break;
case MACOSX:
#ifdef MAC_OSX_TK
font = text_->tkfont();
#endif
break;
case GWIN32:
#ifdef __WIN32
font = text_->tkfont();
#endif
break;
}
if (!font)
return 0;
Vector vv = Vector(x,y);
double angle = calcTextAngle(just, Vector(upx, upy));
Vector cc = vv * calcTextPos(vv, angle, txt, just, Vector(upx, upy), font);
Tk_FontMetrics metrics;
Tk_GetFontMetrics(font, &metrics);
int width = Tk_TextWidth(font, txt, strlen(txt));
BBox nn = BBox(Vector(0,-metrics.descent), Vector(width,metrics.ascent));
BBox bb = nn * Rotate(angle) * Translate(cc);
xb[0] = bb.ll[0];
yb[0] = bb.ll[1];
xb[1] = bb.ur[0];
yb[1] = bb.ll[1];
xb[2] = bb.ur[0];
yb[2] = bb.ur[1];
xb[3] = bb.ll[0];
yb[3] = bb.ur[1];
return 1;
}
int Grid2dBase::gScales(float* alpha, float* beta)
{
return 1;
}
|