2001-05-30 00:06:10 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* Function to write WINEPS AFM data structures as C
|
|
|
|
*
|
|
|
|
* Copyright 2001 Ian Pilcher
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* NOTES:
|
2001-05-30 00:06:10 +02:00
|
|
|
*
|
|
|
|
* 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
|
2001-08-15 19:41:37 +02:00
|
|
|
* PSDRV_DumpFontList() (or wherever it gets moved). The resulting
|
2001-05-30 00:06:10 +02:00
|
|
|
* 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>
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2001-05-30 00:06:10 +02:00
|
|
|
#include "psdrv.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
|
2001-05-30 00:06:10 +02:00
|
|
|
|
|
|
|
inline static void cursorto(FILE *of, int np, int cp)
|
|
|
|
{
|
|
|
|
int ntp = np & 0xfffffff8;
|
|
|
|
int ctp = cp & 0xfffffff8;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-05-30 00:06:10 +02:00
|
|
|
while (ctp < ntp)
|
|
|
|
{
|
|
|
|
fputc('\t', of);
|
|
|
|
ctp += 8;
|
|
|
|
cp = ctp;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-05-30 00:06:10 +02:00
|
|
|
while (cp < np)
|
|
|
|
{
|
|
|
|
fputc(' ', of);
|
|
|
|
++cp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-15 19:41:37 +02:00
|
|
|
static void writeHeader(FILE *of, const AFM *afm, const char *buffer)
|
2001-05-30 00:06:10 +02:00
|
|
|
{
|
|
|
|
int i;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-05-30 00:06:10 +02:00
|
|
|
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"
|
2001-08-15 19:41:37 +02:00
|
|
|
" *\tSee dlls/wineps/data/COPYRIGHTS for font copyright "
|
|
|
|
"information.\n"
|
2001-05-30 00:06:10 +02:00
|
|
|
" *\n"
|
|
|
|
" */\n"
|
|
|
|
"\n"
|
2001-08-15 19:41:37 +02:00
|
|
|
"#include \"psdrv.h\"\n"
|
|
|
|
"#include \"data/agl.h\"\n", afm->FullName);
|
2001-05-30 00:06:10 +02:00
|
|
|
}
|
|
|
|
|
2001-08-15 19:41:37 +02:00
|
|
|
static void writeMetrics(FILE *of, const AFM *afm, const char *buffer)
|
2001-05-30 00:06:10 +02:00
|
|
|
{
|
|
|
|
int i;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-05-30 00:06:10 +02:00
|
|
|
fputs("\n\n/*\n * Glyph metrics\n */\n\n", of);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
fprintf(of, "static const AFMMETRICS metrics[%i] =\n{\n",
|
2001-05-30 00:06:10 +02:00
|
|
|
afm->NumofMetrics);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-05-30 00:06:10 +02:00
|
|
|
for (i = 0; i < afm->NumofMetrics - 1; ++i)
|
|
|
|
{
|
2001-08-15 19:41:37 +02:00
|
|
|
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);
|
2001-05-30 00:06:10 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-15 19:41:37 +02:00
|
|
|
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);
|
2001-05-30 00:06:10 +02:00
|
|
|
}
|
|
|
|
|
2001-08-15 19:41:37 +02:00
|
|
|
static void writeAFM(FILE *of, const AFM *afm, const char *buffer)
|
2001-05-30 00:06:10 +02:00
|
|
|
{
|
|
|
|
fputs("\n\n/*\n * Font metrics\n */\n\n", of);
|
|
|
|
|
2001-08-15 19:41:37 +02:00
|
|
|
fprintf(of, "const AFM PSDRV_%s =\n{\n", buffer);
|
|
|
|
cursorto(of, 44, fprintf(of, " \"%s\",", afm->FontName));
|
2001-05-30 00:06:10 +02:00
|
|
|
fputs("/* FontName */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, fprintf(of, " \"%s\",", afm->FullName));
|
2001-05-30 00:06:10 +02:00
|
|
|
fputs("/* FullName */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, fprintf(of, " \"%s\",", afm->FamilyName));
|
2001-05-30 00:06:10 +02:00
|
|
|
fputs("/* FamilyName */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, fprintf(of, " \"%s\",", afm->EncodingScheme));
|
2001-05-30 00:06:10 +02:00
|
|
|
fputs("/* EncodingScheme */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, fprintf(of, " %s,",
|
|
|
|
(afm->Weight > 550) ? "FW_BOLD" : "FW_NORMAL"));
|
2001-05-30 00:06:10 +02:00
|
|
|
fputs("/* Weight */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, fprintf(of, " %g,", afm->ItalicAngle));
|
2001-05-30 00:06:10 +02:00
|
|
|
fputs("/* ItalicAngle */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, fprintf(of, " %s,",
|
2001-05-30 00:06:10 +02:00
|
|
|
afm->IsFixedPitch ? "TRUE" : "FALSE"));
|
|
|
|
fputs("/* IsFixedPitch */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, fprintf(of, " %g,", afm->UnderlinePosition));
|
2001-05-30 00:06:10 +02:00
|
|
|
fputs("/* UnderlinePosition */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, fprintf(of, " %g,", afm->UnderlineThickness));
|
2001-05-30 00:06:10 +02:00
|
|
|
fputs("/* UnderlineThickness */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, fprintf(of, " { %g, %g, %g, %g },", afm->FontBBox.llx,
|
2001-05-30 00:06:10 +02:00
|
|
|
afm->FontBBox.lly, afm->FontBBox.urx, afm->FontBBox.ury));
|
|
|
|
fputs("/* FontBBox */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, fprintf(of, " %g,", afm->Ascender));
|
2001-05-30 00:06:10 +02:00
|
|
|
fputs("/* Ascender */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, fprintf(of, " %g,", afm->Descender));
|
2001-05-30 00:06:10 +02:00
|
|
|
fputs("/* Descender */\n", of);
|
|
|
|
fputs(" {\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, 7 + fprintf(of, "\t%u,",
|
2001-05-30 00:06:10 +02:00
|
|
|
(unsigned int)(afm->WinMetrics.usUnitsPerEm)));
|
|
|
|
fputs("/* WinMetrics.usUnitsPerEm */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, 7 + fprintf(of, "\t%i,",
|
2001-05-30 00:06:10 +02:00
|
|
|
(int)(afm->WinMetrics.sAscender)));
|
|
|
|
fputs("/* WinMetrics.sAscender */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, 7 + fprintf(of, "\t%i,",
|
2001-05-30 00:06:10 +02:00
|
|
|
(int)(afm->WinMetrics.sDescender)));
|
|
|
|
fputs("/* WinMetrics.sDescender */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, 7 + fprintf(of, "\t%i,",
|
2001-05-30 00:06:10 +02:00
|
|
|
(int)(afm->WinMetrics.sLineGap)));
|
|
|
|
fputs("/* WinMetrics.sLineGap */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, 7 + fprintf(of, "\t%i,",
|
2001-05-30 00:06:10 +02:00
|
|
|
(int)(afm->WinMetrics.sAvgCharWidth)));
|
|
|
|
fputs("/* WinMetrics.sAvgCharWidth */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, 7 + fprintf(of, "\t%i,",
|
2001-05-30 00:06:10 +02:00
|
|
|
(int)(afm->WinMetrics.sTypoAscender)));
|
|
|
|
fputs("/* WinMetrics.sTypoAscender */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, 7 + fprintf(of, "\t%i,",
|
2001-05-30 00:06:10 +02:00
|
|
|
(int)(afm->WinMetrics.sTypoDescender)));
|
|
|
|
fputs("/* WinMetrics.sTypoDescender */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, 7 + fprintf(of, "\t%i,",
|
2001-05-30 00:06:10 +02:00
|
|
|
(int)(afm->WinMetrics.sTypoLineGap)));
|
|
|
|
fputs("/* WinMetrics.sTypoLineGap */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, 7 + fprintf(of, "\t%u,",
|
2001-05-30 00:06:10 +02:00
|
|
|
(unsigned int)(afm->WinMetrics.usWinAscent)));
|
|
|
|
fputs("/* WinMetrics.usWinAscent */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
cursorto(of, 44, 7 + fprintf(of, "\t%u",
|
2001-05-30 00:06:10 +02:00
|
|
|
(unsigned int)(afm->WinMetrics.usWinDescent)));
|
|
|
|
fputs("/* WinMetrics.usWinDescent */\n",of);
|
2001-08-15 19:41:37 +02:00
|
|
|
fputs(" },\n", of);
|
|
|
|
cursorto(of, 44, fprintf(of, " %i,", afm->NumofMetrics));
|
2001-05-30 00:06:10 +02:00
|
|
|
fputs("/* NumofMetrics */\n", of);
|
2001-08-15 19:41:37 +02:00
|
|
|
fputs(" metrics\t\t\t\t /* Metrics */\n};\n", of);
|
2001-05-30 00:06:10 +02:00
|
|
|
}
|
|
|
|
|
2001-08-15 19:41:37 +02:00
|
|
|
void PSDRV_AFM2C(const AFM *afm)
|
2001-05-30 00:06:10 +02:00
|
|
|
{
|
|
|
|
char buffer[256];
|
|
|
|
FILE *of;
|
|
|
|
int i;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-03-28 16:17:51 +02:00
|
|
|
lstrcpynA(buffer, afm->FontName, sizeof(buffer) - 2);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-05-30 00:06:10 +02:00
|
|
|
for (i = 0; i < strlen(buffer); ++i)
|
|
|
|
if (buffer[i] == '-')
|
|
|
|
buffer[i] = '_';
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-05-30 00:06:10 +02:00
|
|
|
buffer[i] = '.'; buffer[i + 1] = 'c'; buffer[i + 2] = '\0';
|
|
|
|
|
|
|
|
MESSAGE("writing '%s'\n", buffer);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-05-30 00:06:10 +02:00
|
|
|
of = fopen(buffer, "w");
|
|
|
|
if (of == NULL)
|
|
|
|
{
|
|
|
|
ERR("error opening '%s' for writing\n", buffer);
|
|
|
|
return;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-05-30 00:06:10 +02:00
|
|
|
buffer[i] = '\0';
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-05-30 00:06:10 +02:00
|
|
|
writeHeader(of, afm, buffer);
|
|
|
|
writeMetrics(of, afm, buffer);
|
|
|
|
writeAFM(of, afm, buffer);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-05-30 00:06:10 +02:00
|
|
|
fclose(of);
|
|
|
|
}
|