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
/*******************************************************************************
*
* Function to write WINEPS AFM data structures as C
*
* Copyright 2001 Ian Pilcher
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* NOTES:
*
* PSDRV_AFM2C(AFM *afm) writes the AFM data structure addressed by afm (and
* its subsidiary objects) as a C file which can which can then be built in to
* the driver. It creates the file in the current directory with a name of
* the form {FontName}.c, where {FontName} is the PostScript font name with
* hyphens replaced by underscores.
*
* To use this function, do the following:
*
* * Edit dlls/wineps/Makefile (or dlls/wineps/Makefile.in) and add
* afm2c.c as a source file.
*
* * Edit dlls/wineps/afm.c and uncomment the call to PSDRV_AFM2C in
* PSDRV_DumpFontList() (or wherever it gets moved). The resulting
* compiler warning can be safely ignored.
*
* IMPORTANT: For this to work, all glyph names in the AFM data being
* written *MUST* already be present in PSDRV_AGLGlyphNames in agl.c.
* See mkagl.c in this directory for information on how to generate
* updated glyph name information. Note, however, that if the glyph
* name information in agl.c is regenerated, *ALL* AFM data must also
* be recreated.
*
*/
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "wine/debug.h"
#include "psdrv.h"
WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
static inline void cursorto(FILE *of, int np, int cp)
{
int ntp = np & 0xfffffff8;
int ctp = cp & 0xfffffff8;
while (ctp < ntp)
{
fputc('\t', of);
ctp += 8;
cp = ctp;
}
while (cp < np)
{
fputc(' ', of);
++cp;
}
}
static void writeHeader(FILE *of, const AFM *afm, const char *buffer)
{
int i;
fputc('/', of);
for (i = 1; i < 80; ++i)
fputc('*', of);
fprintf(of, "\n"
" *\n"
" *\tFont metric data for %s\n"
" *\n"
" *\tCopyright 2001 Ian Pilcher\n"
" *\n"
" *\n"
" *\tSee dlls/wineps/data/COPYRIGHTS for font copyright "
"information.\n"
" *\n"
" */\n"
"\n"
"#include \"psdrv.h\"\n"
"#include \"data/agl.h\"\n", afm->FullName);
}
static void writeMetrics(FILE *of, const AFM *afm, const char *buffer)
{
int i;
fputs("\n\n/*\n * Glyph metrics\n */\n\n", of);
fprintf(of, "static const AFMMETRICS metrics[%i] =\n{\n",
afm->NumofMetrics);
for (i = 0; i < afm->NumofMetrics - 1; ++i)
{
fprintf(of, " { %3i, 0x%.4lx, %4g, GN_%s },\n", afm->Metrics[i].C,
afm->Metrics[i].UV, afm->Metrics[i].WX, afm->Metrics[i].N->sz);
}
fprintf(of, " { %3i, 0x%.4lx, %4g, GN_%s }\n};\n", afm->Metrics[i].C,
afm->Metrics[i].UV, afm->Metrics[i].WX, afm->Metrics[i].N->sz);
}
static void writeAFM(FILE *of, const AFM *afm, const char *buffer)
{
fputs("\n\n/*\n * Font metrics\n */\n\n", of);
fprintf(of, "const AFM PSDRV_%s =\n{\n", buffer);
cursorto(of, 44, fprintf(of, " \"%s\",", afm->FontName));
fputs("/* FontName */\n", of);
cursorto(of, 44, fprintf(of, " \"%s\",", afm->FullName));
fputs("/* FullName */\n", of);
cursorto(of, 44, fprintf(of, " \"%s\",", afm->FamilyName));
fputs("/* FamilyName */\n", of);
cursorto(of, 44, fprintf(of, " \"%s\",", afm->EncodingScheme));
fputs("/* EncodingScheme */\n", of);
cursorto(of, 44, fprintf(of, " %s,",
(afm->Weight > 550) ? "FW_BOLD" : "FW_NORMAL"));
fputs("/* Weight */\n", of);
cursorto(of, 44, fprintf(of, " %g,", afm->ItalicAngle));
fputs("/* ItalicAngle */\n", of);
cursorto(of, 44, fprintf(of, " %s,",
afm->IsFixedPitch ? "TRUE" : "FALSE"));
fputs("/* IsFixedPitch */\n", of);
cursorto(of, 44, fprintf(of, " %g,", afm->UnderlinePosition));
fputs("/* UnderlinePosition */\n", of);
cursorto(of, 44, fprintf(of, " %g,", afm->UnderlineThickness));
fputs("/* UnderlineThickness */\n", of);
cursorto(of, 44, fprintf(of, " { %g, %g, %g, %g },", afm->FontBBox.llx,
afm->FontBBox.lly, afm->FontBBox.urx, afm->FontBBox.ury));
fputs("/* FontBBox */\n", of);
cursorto(of, 44, fprintf(of, " %g,", afm->Ascender));
fputs("/* Ascender */\n", of);
cursorto(of, 44, fprintf(of, " %g,", afm->Descender));
fputs("/* Descender */\n", of);
fputs(" {\n", of);
cursorto(of, 44, 7 + fprintf(of, "\t%u,",
(unsigned int)(afm->WinMetrics.usUnitsPerEm)));
fputs("/* WinMetrics.usUnitsPerEm */\n", of);
cursorto(of, 44, 7 + fprintf(of, "\t%i,",
(int)(afm->WinMetrics.sAscender)));
fputs("/* WinMetrics.sAscender */\n", of);
cursorto(of, 44, 7 + fprintf(of, "\t%i,",
(int)(afm->WinMetrics.sDescender)));
fputs("/* WinMetrics.sDescender */\n", of);
cursorto(of, 44, 7 + fprintf(of, "\t%i,",
(int)(afm->WinMetrics.sLineGap)));
fputs("/* WinMetrics.sLineGap */\n", of);
cursorto(of, 44, 7 + fprintf(of, "\t%i,",
(int)(afm->WinMetrics.sAvgCharWidth)));
fputs("/* WinMetrics.sAvgCharWidth */\n", of);
cursorto(of, 44, 7 + fprintf(of, "\t%i,",
(int)(afm->WinMetrics.sTypoAscender)));
fputs("/* WinMetrics.sTypoAscender */\n", of);
cursorto(of, 44, 7 + fprintf(of, "\t%i,",
(int)(afm->WinMetrics.sTypoDescender)));
fputs("/* WinMetrics.sTypoDescender */\n", of);
cursorto(of, 44, 7 + fprintf(of, "\t%i,",
(int)(afm->WinMetrics.sTypoLineGap)));
fputs("/* WinMetrics.sTypoLineGap */\n", of);
cursorto(of, 44, 7 + fprintf(of, "\t%u,",
(unsigned int)(afm->WinMetrics.usWinAscent)));
fputs("/* WinMetrics.usWinAscent */\n", of);
cursorto(of, 44, 7 + fprintf(of, "\t%u",
(unsigned int)(afm->WinMetrics.usWinDescent)));
fputs("/* WinMetrics.usWinDescent */\n",of);
fputs(" },\n", of);
cursorto(of, 44, fprintf(of, " %i,", afm->NumofMetrics));
fputs("/* NumofMetrics */\n", of);
fputs(" metrics\t\t\t\t /* Metrics */\n};\n", of);
}
void PSDRV_AFM2C(const AFM *afm)
{
char buffer[256];
FILE *of;
int i;
lstrcpynA(buffer, afm->FontName, sizeof(buffer) - 2);
for (i = 0; i < strlen(buffer); ++i)
if (buffer[i] == '-')
buffer[i] = '_';
buffer[i] = '.'; buffer[i + 1] = 'c'; buffer[i + 2] = '\0';
MESSAGE("writing '%s'\n", buffer);
of = fopen(buffer, "w");
if (of == NULL)
{
ERR("error opening '%s' for writing\n", buffer);
return;
}
buffer[i] = '\0';
writeHeader(of, afm, buffer);
writeMetrics(of, afm, buffer);
writeAFM(of, afm, buffer);
fclose(of);
}