2 /* Copyright (C) 1989, 1990 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.uucp)
5 This file is part of groff.
7 groff is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 1, or (at your option) any later
12 groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License along
18 with groff; see the file LICENSE. If not, write to the Free Software
19 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
29 #include "stringclass.h"
34 static void convert_font(const font_params
&, FILE *, FILE *);
36 typedef font_params::*param_t
;
42 "x-height", &font_params::x_height
,
43 "fig-height", &font_params::fig_height
,
44 "asc-height", &font_params::asc_height
,
45 "body-height", &font_params::body_height
,
46 "cap-height", &font_params::cap_height
,
47 "comma-depth", &font_params::comma_depth
,
48 "desc-depth", &font_params::desc_depth
,
49 "body-depth", &font_params::body_depth
,
52 // These are all in thousandths of an em.
53 // These values are correct for PostScript Times Roman.
55 #define DEFAULT_X_HEIGHT 448
56 #define DEFAULT_FIG_HEIGHT 676
57 #define DEFAULT_ASC_HEIGHT 682
58 #define DEFAULT_BODY_HEIGHT 676
59 #define DEFAULT_CAP_HEIGHT 662
60 #define DEFAULT_COMMA_DEPTH 143
61 #define DEFAULT_DESC_DEPTH 217
62 #define DEFAULT_BODY_DEPTH 177
64 int main(int argc
, char **argv
)
66 program_name
= argv
[0];
70 if (sscanf(argv
[argc
-3], "%d", &resolution
) != 1)
73 fatal("resolution must be > 0");
75 if (sscanf(argv
[argc
-2], "%d", &unitwidth
) != 1)
78 fatal("unitwidth must be > 0");
80 const char *font
= argv
[argc
-1];
81 param
.italic
= (font
[0] != '\0' && strchr(font
, '\0')[-1] == 'I');
82 param
.em
= (resolution
*unitwidth
)/72;
83 param
.x_height
= DEFAULT_X_HEIGHT
;
84 param
.fig_height
= DEFAULT_FIG_HEIGHT
;
85 param
.asc_height
= DEFAULT_ASC_HEIGHT
;
86 param
.body_height
= DEFAULT_BODY_HEIGHT
;
87 param
.cap_height
= DEFAULT_CAP_HEIGHT
;
88 param
.comma_depth
= DEFAULT_COMMA_DEPTH
;
89 param
.desc_depth
= DEFAULT_DESC_DEPTH
;
90 param
.body_depth
= DEFAULT_BODY_DEPTH
;
91 for (int i
= 1; i
< argc
&& argv
[i
][0] == '-'; i
++) {
92 if (argv
[i
][1] == '-' && argv
[i
][2] == '\0') {
98 for (int j
= 0;; j
++) {
99 if (j
>= sizeof(param_table
)/sizeof(param_table
[0]))
100 fatal("parameter `%1' not recognized", argv
[i
] + 1);
101 if (strcmp(param_table
[j
].name
, argv
[i
] + 1) == 0)
104 if (sscanf(argv
[i
+1], "%d", &(param
.*(param_table
[j
].par
))) != 1)
105 fatal("invalid argument `%1'", argv
[i
+1]);
110 FILE *infp
= fopen(font
, "r");
112 fatal("can't open `%1': %2", font
, strerror(errno
));
113 convert_font(param
, infp
, stdout
);
119 fprintf(stderr
, "usage: %s [-param value] ... resolution unitwidth font\n",
124 static int get_line(FILE *fp
, string
*p
)
128 while ((c
= getc(fp
)) != EOF
) {
133 return p
->length() > 0;
136 static void convert_font(const font_params
¶m
, FILE *infp
, FILE *outfp
)
139 while (get_line(infp
, &s
)) {
140 put_string(s
, outfp
);
142 && strncmp(&s
[0], "charset", 7))
145 while (get_line(infp
, &s
)) {
148 const char *p
= s
.contents();
151 while (*p
!= '\0' && !csspace(*p
))
155 for (const char *q
= s
.contents(); q
< p
; q
++)
159 metric
.width
= (int)strtol(p
, &next
, 10);
161 printf("%d", metric
.width
);
163 metric
.type
= (int)strtol(p
, &next
, 10);
166 guess(name
.contents(), param
, &metric
);
167 if (metric
.sk
== 0) {
168 if (metric
.left_ic
== 0) {
169 if (metric
.ic
== 0) {
170 if (metric
.depth
== 0) {
171 if (metric
.height
!= 0)
172 printf(",%d", metric
.height
);
175 printf(",%d,%d", metric
.height
, metric
.depth
);
178 printf(",%d,%d,%d", metric
.height
, metric
.depth
, metric
.ic
);
181 printf(",%d,%d,%d,%d", metric
.height
, metric
.depth
, metric
.ic
,
185 printf(",%d,%d,%d,%d,%d", metric
.height
, metric
.depth
, metric
.ic
,
186 metric
.left_ic
, metric
.sk
);