forked from mandovinnie/Lute-Tab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdvi.cc
281 lines (246 loc) · 6.53 KB
/
dvi.cc
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*
This program is copyright 1991 by Wayne Cripps,
P.O. Box 677 Hanover N.H. 03755.
All rights reserved. It is supplied "as is"
without express or implied warranty.
Permission is granted to use, copy, modify and distribute
this software without fee, provided that this notice appears
in all copies, and that a copy of this notice is provided to
anyone who recieves a binary copy without sources.
This software may not be used for commercial purposes
without explicit, prior written permission.
Please mail bug reports, suggestions, and improvements
*/
/*
* dvi output stuff
*
* note that we use dvi units, and we use the tfm file for font
* widths
*/
#include "win.h"
#include "dvi.h"
#include "tab.h"
#include <errno.h>
#include "print.h"
#include "dviprint.h"
#include "system.h"
double tfm_dvi_to_inch(int dvi);
/* LOCAL */
int pt_to_dvi(double pt);
int mm_to_dvi(double mm);
struct font_list *init_font_list(int num, const char *name, double scale);
struct font_list *delete_font_list(struct font_list *f);
int max_font_num = 0;
#ifdef MAC
double atof(char *s);
double atof(char *s)
{
#define SZ 15
int i, j=0, point=-1;
double r=0.0;
double mul=1.0;
double sign=1.0;
char *p;
char tmp[SZ];
p=s;
if (*p == '-') { sign = -1.0; *p++; }
for (i=0; i < SZ; i++) {
if (*p == '.') {
point = i ;
}
else if (*p == '\0' || *p == '\n' || *p == ' ') {
if (point<0) point = i;
break;
}
else tmp[i] = *p;
p++;
}
tmp[i] = '\0';
while (point--) {
r *= 10.0;
r +=(double)tmp[j]-'0';
j++, i--;
}
if (i) {
i--;
if (!i) goto exit_it;
while (i--) {
mul /=10.0;
r += (double)(tmp[++j]-'0') * mul;
}
}
exit_it:
return (r* sign);
}
#endif /* MAC */
struct font_list *init_font_list(int num, const char *name, double scale)
{
font_list *f;
f = new font_list;
f->next = NULL;
f->name = (char *) malloc (BL );
strcpy (f->name, name);
f->num = num;
if (num > max_font_num) max_font_num = num;
f->fnt = new tfm_font(name, scale);
f->real_name = NULL;
f->size = 10.0 * scale;
return f;
}
struct font_list *delete_font_list(struct font_list *f)
{
free(f->name);
delete(f->fnt);
delete(f);
return(NULL);
}
int str_to_dvi(const char *string)
{
char *s, str[32];
mystrncpy(str, string, (int)sizeof(str)-1);
s = strstr(str, "in");
if (s) { /* inches */
*s = 0;
return (inch_to_dvi(atof(str)));
}
else if ((s = strstr(str, "pt"))) { /* points */
*s = 0;
return (pt_to_dvi(atof(str)));
}
else if ((s = strstr(str, "mm"))) { /* points */
*s = 0;
return (mm_to_dvi(atof(str)));
}
dbg1(Error,
"tab: str_to_dvi: unsupported dimension %s\n", (void *)str);
return (0);
}
void
mystrncpy(char *s1, const char *s2, int n) /* not as robust as the real thing */
/* but quite a bit faster! */
{
while (n) {
*s1 = *s2;
s1++;
s2++;
if (!*s2) break;
n--;
}
*s1=0;
}
int inch_to_dvi(const double inch)
{
return ((int)(red * (inch * 254000.0) * ( (double)DENOM / (double)NUM)));
}
int mm_to_dvi(double mm)
{
return ((int)(
(red * (mm * 254000) * ( (double)DENOM / (double)NUM)) / 25.4));
}
int pt_to_dvi(double pt)
{
return((int) (
(red *
(pt * 254000) *
((double)DENOM / (double)NUM) ) / 72.27));
}
double dvi_to_inch(int dvi)
{
return ((double) dvi * ((double)NUM / (double)DENOM) / (254000.0 * red) );
}
double tfm_dvi_to_inch(int dvi)
{
return ((double) dvi * ((double)NUM / (double)DENOM) / (254000.0) );
}
double dvi_to_pt(int dvi)
{
return ((72.27 / red ) * ( (double)NUM / (double)DENOM)
* (double) dvi / 254000 );
}
double dvi_to_mm(int dvi)
{
return (dvi_to_inch(dvi) * 25.4);
}
double str_to_inch(const char *string)
{
char *s, str[85];
double val;
mystrncpy(str, string, sizeof(str));
s = strstr(str, "in");
if (s) { /* inches */
*s = 0;
val = atof(str);
return (val);
}
else if ((s = strstr(str, "pt"))) { /* points */
*s = 0;
val = (atof(str) / 72.27 );
return (val);
}
else if ((s = strstr(str, "mm"))) { /* points */
*s = 0;
return (atof(str) / 25.4);
}
dbg2(Warning, "tab: str_to_inch: unsupported dimen %s [ %s ]\n",
(void *)string, (void *)str);
return(0);
}
struct font_list *add_font(char *name, double scale)
{
font_list *f;
f = new font_list;
f->next = NULL;
f->name = (char *) malloc (BL );
/* look for name in list */
strcpy (f->name, name);
f->num = ++max_font_num;
f->fnt = new tfm_font(name, scale);
return f;
}
#include "tree.h"
char *
get_real_name(const char *short_name, int dump)
{
static char *c = NULL;
struct tuple pfonts[] = {
{(char*)"pbkd", (void *)"/Bookman-Demi"},
{(char*)"pbkdi", (void *)"/Bookman-DemiItalic"},
{(char*)"pbkl", (void *)"/Bookman-Light"},
{(char*)"pbkli", (void *)"/Bookman-LightItalic"},
{(char*)"pcrb", (void *)"/Courier-Bold"},
{(char*)"pcrbo", (void *)"/Courier-BoldOblique"},
{(char*)"pcrro", (void *)"/Courier-Oblique"},
{(char*)"pcrr", (void *)"/Courier"},
{(char*)"phvb", (void *)"/Helvetica-Bold"},
{(char*)"phvbo", (void *)"/Helvetica-BoldOblique"},
{(char*)"phvro", (void *)"/Helvetica-Oblique"},
{(char*)"phvr", (void *)"/Helvetica"},
{(char*)"phvbrn", (void *)"/Helvetica-Narrow-Bold"},
{(char*)"phvbon", (void *)"/Helvetica-Narrow-BoldOblique"},
{(char*)"phvron", (void *)"/Helvetica-Narrow-Oblique"},
{(char*)"phvrrn", (void *)"/Helvetica-Narrow"},
{(char*)"pncb", (void *)"/NewCenturySchlbk-Bold"},
{(char*)"pncbi", (void *)"/NewCenturySchlbk-BoldItalic"},
{(char*)"pncri", (void *)"/NewCenturySchlbk-Italic"},
{(char*)"pncr", (void *)"/NewCenturySchlbk-Roman"},
{(char*)"pplb", (void *)"/Palatino-Bold"},
{(char*)"pplbi", (void *)"/Palatino-BoldItalic"},
// {"pplbu", (void *)"/Palatino-BoldUnslanted"},
// {"pplrrn", (void *)"/Palatino-Narrow"},
// {"pplrre", (void *)"/Palatino-Expanded"},
{(char*)"pplri", (void *)"/Palatino-Italic"},
{(char*)"pplr", (void *)"/Palatino-Roman"},
{(char*)"ptmb", (void *)"/Times-Bold"},
{(char*)"ptmbi", (void *)"/Times-BoldItalic"},
{(char*)"ptmri", (void *)"/Times-Italic"},
{(char*)"ptmr", (void *)"/Times-Roman"},
{(char*)"pzcmi", (void *)"/ZapfChancery-MediumItalic"},
{(char*)" ", (void *)" "},
{0,0}
};
static tree ft(pfonts);
if (dump) ft.dumpval();
c = (char *)ft.get(short_name);
return (c);
}