4 * convert X font metrics into troff font metrics
10 # include "libXdvi/XFontName.h"
11 # include "libXdvi/DviChar.h"
13 # define charWidth(fi,c) ((fi)->per_char[(c) - (fi)->min_char_or_byte2].width)
14 # define charHeight(fi,c) ((fi)->per_char[(c) - (fi)->min_char_or_byte2].ascent)
15 # define charDepth(fi,c) ((fi)->per_char[(c) - (fi)->min_char_or_byte2].descent)
16 # define charLBearing(fi,c) ((fi)->per_char[(c) - (fi)->min_char_or_byte2].lbearing)
17 # define charRBearing(fi,c) ((fi)->per_char[(c) - (fi)->min_char_or_byte2].rbearing)
22 int charExists (fi
, c
)
28 if (c
< fi
->min_char_or_byte2
|| c
> fi
->max_char_or_byte2
)
30 p
= fi
->per_char
+ (c
- fi
->min_char_or_byte2
);
31 return (p
->lbearing
!= 0 || p
->rbearing
!= 0 || p
->width
!= 0
32 || p
->ascent
!= 0 || p
->descent
!= 0 || p
->attributes
!= 0);
35 MapFont (font_name
, troff_name
)
44 unsigned int attributes
;
47 DviCharNameMap
*char_map
;
52 names
= XListFonts (dpy
, font_name
, 100000, &count
);
54 fprintf (stderr
, "bad font name: %s\n", font_name
);
58 fprintf (stderr
, "ambiguous font name: %s\n", font_name
);
61 if (!XParseFontName (names
[0], &parsed
, &attributes
)) {
62 fprintf (stderr
, "not a standard name: %s\n", names
[0]);
65 sprintf (encoding
, "%s-%s", parsed
.CharSetRegistry
,
66 parsed
.CharSetEncoding
);
67 for (s
= encoding
; *s
; s
++)
70 char_map
= DviFindMap (encoding
);
72 fprintf (stderr
, "not a standard encoding: %s\n", encoding
);
76 out
= fopen (troff_name
, "w");
81 fprintf (out
, "name %s\n", troff_name
);
82 if (!strcmp (char_map
->encoding
, "adobe-fontspecific"))
83 fprintf (out
, "special\n");
84 fi
= XLoadQueryFont (dpy
, names
[0]);
85 if (charExists (fi
, ' ')) {
86 int w
= charWidth (fi
, ' ');
88 fprintf (out
, "spacewidth %d\n", w
);
90 fprintf (out
, "charset\n");
91 for (c
= fi
->min_char_or_byte2
; c
<= fi
->max_char_or_byte2
; c
++) {
92 char *name
= DviCharName (char_map
,c
,0);
93 if (charExists (fi
, c
) && (groff_flag
|| name
)) {
95 wid
= charWidth (fi
, c
);
97 fprintf (out
, "%s\t%d",
102 param
[0] = charHeight (fi
, c
);
103 param
[1] = charDepth (fi
, c
);
104 param
[2] = 0 /* charRBearing (fi, c) - wid */;
105 param
[3] = 0 /* charLBearing (fi, c) */;
106 param
[4] = 0; /* XXX */
107 for (j
= 0; j
< 5; j
++)
110 for (j
= 4; j
>= 0; j
--)
113 for (k
= 0; k
<= j
; k
++)
114 fprintf (out
, ",%d", param
[k
]);
116 fprintf (out
, "\t0\t0%o\n", c
);
119 for (k
= 1; DviCharName(char_map
,c
,k
); k
++) {
120 fprintf (out
, "%s\t\"\n",
121 DviCharName (char_map
,c
,k
));
126 XUnloadFont (dpy
, fi
->fid
);
134 fprintf (stderr
, "usage: %s [-g] FontMap\n", prog
);
141 char troff_name
[1024];
142 char font_name
[1024];
150 while ((opt
= getopt(argc
, argv
, "g")) != EOF
) {
159 if (argc
- optind
!= 1)
162 dpy
= XOpenDisplay (0);
164 fprintf (stderr
, "Can't connect to the X server.\n");
165 fprintf (stderr
, "Make sure the DISPLAY environment variable is set correctly.\n");
170 map
= fopen (argv
[optind
], "r");
172 perror (argv
[optind
]);
176 while (fgets (line
, sizeof (line
), map
)) {
177 for (a
=line
,b
=troff_name
; *a
; a
++,b
++) {
179 if (c
== ' ' || c
== '\t')
183 while (*a
&& (*a
== ' ' || *a
== '\t'))
185 for (b
=font_name
; *a
; a
++,b
++)
186 if ((*b
= *a
) == '\n')
189 printf ("%s -> %s\n", font_name
, troff_name
);
190 if (!MapFont (font_name
, troff_name
))
200 c-continued-statement-offset: 8
204 c-tab-always-indent: nil