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