Back to home page

Wine source

 
 

    


File indexing completed on 2023-05-13 02:24:01

55d2e575a Ian *0001 /*******************************************************************************
                0002  *
                0003  *  Function to write WINEPS AFM data structures as C
                0004  *
                0005  *  Copyright 2001 Ian Pilcher
                0006  *
0799c1a78 Alex*0007  * This library is free software; you can redistribute it and/or
                0008  * modify it under the terms of the GNU Lesser General Public
                0009  * License as published by the Free Software Foundation; either
                0010  * version 2.1 of the License, or (at your option) any later version.
                0011  *
                0012  * This library is distributed in the hope that it will be useful,
                0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
                0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                0015  * Lesser General Public License for more details.
                0016  *
                0017  * You should have received a copy of the GNU Lesser General Public
                0018  * License along with this library; if not, write to the Free Software
360a3f914 Jona*0019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
0799c1a78 Alex*0020  *
                0021  * NOTES:
55d2e575a Ian *0022  *
                0023  *  PSDRV_AFM2C(AFM *afm) writes the AFM data structure addressed by afm (and
                0024  *  its subsidiary objects) as a C file which can which can then be built in to
                0025  *  the driver.  It creates the file in the current directory with a name of
                0026  *  the form {FontName}.c, where {FontName} is the PostScript font name with
                0027  *  hyphens replaced by underscores.
                0028  *
                0029  *  To use this function, do the following:
                0030  *
                0031  *      *  Edit dlls/wineps/Makefile (or dlls/wineps/Makefile.in) and add
                0032  *         afm2c.c as a source file.
                0033  *
                0034  *      *  Edit dlls/wineps/afm.c and uncomment the call to PSDRV_AFM2C in
257651301 Ian *0035  *         PSDRV_DumpFontList() (or wherever it gets moved).  The resulting
55d2e575a Ian *0036  *         compiler warning can be safely ignored.
                0037  *
                0038  *  IMPORTANT:  For this to work, all glyph names in the AFM data being
                0039  *      written *MUST* already be present in PSDRV_AGLGlyphNames in agl.c.
                0040  *      See mkagl.c in this directory for information on how to generate
                0041  *      updated glyph name information.  Note, however, that if the glyph
                0042  *      name information in agl.c is regenerated, *ALL* AFM data must also
                0043  *      be recreated.
                0044  *
                0045  */
                0046 
                0047 #include <string.h>
                0048 #include <stdio.h>
                0049 #include <math.h>
                0050 
0799c1a78 Alex*0051 #include "wine/debug.h"
55d2e575a Ian *0052 #include "psdrv.h"
                0053 
0799c1a78 Alex*0054 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
55d2e575a Ian *0055 
41c0cc8f9 Andr*0056 static inline void cursorto(FILE *of, int np, int cp)
55d2e575a Ian *0057 {
                0058     int ntp = np & 0xfffffff8;
                0059     int ctp = cp & 0xfffffff8;
9a6249166 Vinc*0060 
55d2e575a Ian *0061     while (ctp < ntp)
                0062     {
                0063         fputc('\t', of);
                0064     ctp += 8;
                0065     cp = ctp;
                0066     }
9a6249166 Vinc*0067 
55d2e575a Ian *0068     while (cp < np)
                0069     {
                0070         fputc(' ', of);
                0071     ++cp;
                0072     }
                0073 }
                0074 
257651301 Ian *0075 static void writeHeader(FILE *of, const AFM *afm, const char *buffer)
55d2e575a Ian *0076 {
                0077     int i;
9a6249166 Vinc*0078 
55d2e575a Ian *0079     fputc('/', of);
                0080     for (i = 1; i < 80; ++i)
                0081         fputc('*', of);
                0082     fprintf(of, "\n"
                0083                 " *\n"
11ab927ae Piot*0084         " *\tFont metric data for %S\n"
55d2e575a Ian *0085         " *\n"
                0086         " *\tCopyright 2001 Ian Pilcher\n"
                0087         " *\n"
                0088         " *\n"
257651301 Ian *0089         " *\tSee dlls/wineps/data/COPYRIGHTS for font copyright "
                0090                 "information.\n"
55d2e575a Ian *0091         " *\n"
                0092         " */\n"
                0093         "\n"
257651301 Ian *0094         "#include \"psdrv.h\"\n"
                0095         "#include \"data/agl.h\"\n", afm->FullName);
55d2e575a Ian *0096 }
                0097 
257651301 Ian *0098 static void writeMetrics(FILE *of, const AFM *afm, const char *buffer)
55d2e575a Ian *0099 {
                0100     int i;
9a6249166 Vinc*0101 
55d2e575a Ian *0102     fputs("\n\n/*\n *  Glyph metrics\n */\n\n", of);
9a6249166 Vinc*0103 
                0104     fprintf(of, "static const AFMMETRICS metrics[%i] =\n{\n",
55d2e575a Ian *0105             afm->NumofMetrics);
9a6249166 Vinc*0106 
55d2e575a Ian *0107     for (i = 0; i < afm->NumofMetrics - 1; ++i)
                0108     {
257651301 Ian *0109         fprintf(of, "    { %3i, 0x%.4lx, %4g, GN_%s },\n", afm->Metrics[i].C,
                0110             afm->Metrics[i].UV, afm->Metrics[i].WX, afm->Metrics[i].N->sz);
55d2e575a Ian *0111     }
9a6249166 Vinc*0112 
257651301 Ian *0113     fprintf(of, "    { %3i, 0x%.4lx, %4g, GN_%s }\n};\n", afm->Metrics[i].C,
                0114             afm->Metrics[i].UV, afm->Metrics[i].WX, afm->Metrics[i].N->sz);
55d2e575a Ian *0115 }
                0116 
257651301 Ian *0117 static void writeAFM(FILE *of, const AFM *afm, const char *buffer)
55d2e575a Ian *0118 {
                0119     fputs("\n\n/*\n *  Font metrics\n */\n\n", of);
                0120 
257651301 Ian *0121     fprintf(of, "const AFM PSDRV_%s =\n{\n", buffer);
                0122     cursorto(of, 44, fprintf(of, "    \"%s\",", afm->FontName));
55d2e575a Ian *0123     fputs("/* FontName */\n", of);
11ab927ae Piot*0124     cursorto(of, 44, fprintf(of, "    L\"%S\",", afm->FullName));
55d2e575a Ian *0125     fputs("/* FullName */\n", of);
11ab927ae Piot*0126     cursorto(of, 44, fprintf(of, "    L\"%S\",", afm->FamilyName));
55d2e575a Ian *0127     fputs("/* FamilyName */\n", of);
11ab927ae Piot*0128     cursorto(of, 44, fprintf(of, "    L\"%S\",", afm->EncodingScheme));
55d2e575a Ian *0129     fputs("/* EncodingScheme */\n", of);
257651301 Ian *0130     cursorto(of, 44, fprintf(of, "    %s,",
                0131             (afm->Weight > 550) ? "FW_BOLD" : "FW_NORMAL"));
55d2e575a Ian *0132     fputs("/* Weight */\n", of);
257651301 Ian *0133     cursorto(of, 44, fprintf(of, "    %g,", afm->ItalicAngle));
55d2e575a Ian *0134     fputs("/* ItalicAngle */\n", of);
257651301 Ian *0135     cursorto(of, 44, fprintf(of, "    %s,",
55d2e575a Ian *0136             afm->IsFixedPitch ? "TRUE" : "FALSE"));
                0137     fputs("/* IsFixedPitch */\n", of);
257651301 Ian *0138     cursorto(of, 44, fprintf(of, "    %g,", afm->UnderlinePosition));
55d2e575a Ian *0139     fputs("/* UnderlinePosition */\n", of);
257651301 Ian *0140     cursorto(of, 44, fprintf(of, "    %g,", afm->UnderlineThickness));
55d2e575a Ian *0141     fputs("/* UnderlineThickness */\n", of);
257651301 Ian *0142     cursorto(of, 44, fprintf(of, "    { %g, %g, %g, %g },", afm->FontBBox.llx,
55d2e575a Ian *0143             afm->FontBBox.lly, afm->FontBBox.urx, afm->FontBBox.ury));
                0144     fputs("/* FontBBox */\n", of);
257651301 Ian *0145     cursorto(of, 44, fprintf(of, "    %g,", afm->Ascender));
55d2e575a Ian *0146     fputs("/* Ascender */\n", of);
257651301 Ian *0147     cursorto(of, 44, fprintf(of, "    %g,", afm->Descender));
55d2e575a Ian *0148     fputs("/* Descender */\n", of);
                0149     fputs("    {\n", of);
257651301 Ian *0150     cursorto(of, 44, 7 + fprintf(of, "\t%u,",
55d2e575a Ian *0151             (unsigned int)(afm->WinMetrics.usUnitsPerEm)));
                0152     fputs("/* WinMetrics.usUnitsPerEm */\n", of);
257651301 Ian *0153     cursorto(of, 44, 7 + fprintf(of, "\t%i,",
55d2e575a Ian *0154             (int)(afm->WinMetrics.sAscender)));
                0155     fputs("/* WinMetrics.sAscender */\n", of);
257651301 Ian *0156     cursorto(of, 44, 7 + fprintf(of, "\t%i,",
55d2e575a Ian *0157             (int)(afm->WinMetrics.sDescender)));
                0158     fputs("/* WinMetrics.sDescender */\n", of);
257651301 Ian *0159     cursorto(of, 44, 7 + fprintf(of, "\t%i,",
55d2e575a Ian *0160             (int)(afm->WinMetrics.sLineGap)));
                0161     fputs("/* WinMetrics.sLineGap */\n", of);
257651301 Ian *0162     cursorto(of, 44, 7 + fprintf(of, "\t%i,",
55d2e575a Ian *0163             (int)(afm->WinMetrics.sAvgCharWidth)));
                0164     fputs("/* WinMetrics.sAvgCharWidth */\n", of);
257651301 Ian *0165     cursorto(of, 44, 7 + fprintf(of, "\t%i,",
55d2e575a Ian *0166             (int)(afm->WinMetrics.sTypoAscender)));
                0167     fputs("/* WinMetrics.sTypoAscender */\n", of);
257651301 Ian *0168     cursorto(of, 44, 7 + fprintf(of, "\t%i,",
55d2e575a Ian *0169             (int)(afm->WinMetrics.sTypoDescender)));
                0170     fputs("/* WinMetrics.sTypoDescender */\n", of);
257651301 Ian *0171     cursorto(of, 44, 7 + fprintf(of, "\t%i,",
55d2e575a Ian *0172             (int)(afm->WinMetrics.sTypoLineGap)));
                0173     fputs("/* WinMetrics.sTypoLineGap */\n", of);
257651301 Ian *0174     cursorto(of, 44, 7 + fprintf(of, "\t%u,",
55d2e575a Ian *0175             (unsigned int)(afm->WinMetrics.usWinAscent)));
                0176     fputs("/* WinMetrics.usWinAscent */\n", of);
257651301 Ian *0177     cursorto(of, 44, 7 + fprintf(of, "\t%u",
55d2e575a Ian *0178             (unsigned int)(afm->WinMetrics.usWinDescent)));
                0179     fputs("/* WinMetrics.usWinDescent */\n",of);
257651301 Ian *0180     fputs("    },\n", of);
                0181     cursorto(of, 44, fprintf(of, "    %i,", afm->NumofMetrics));
55d2e575a Ian *0182     fputs("/* NumofMetrics */\n", of);
257651301 Ian *0183     fputs("    metrics\t\t\t\t    /* Metrics */\n};\n", of);
55d2e575a Ian *0184 }
                0185 
257651301 Ian *0186 void PSDRV_AFM2C(const AFM *afm)
55d2e575a Ian *0187 {
                0188     char    buffer[256];
                0189     FILE    *of;
97295b3a3 Andr*0190     unsigned int i;
9a6249166 Vinc*0191 
e732fc023 Pete*0192     lstrcpynA(buffer, afm->FontName, sizeof(buffer) - 2);
9a6249166 Vinc*0193 
55d2e575a Ian *0194     for (i = 0; i < strlen(buffer); ++i)
                0195         if (buffer[i] == '-')
                0196         buffer[i] = '_';
9a6249166 Vinc*0197 
55d2e575a Ian *0198     buffer[i] = '.';  buffer[i + 1] = 'c';  buffer[i + 2] = '\0';
                0199 
                0200     MESSAGE("writing '%s'\n", buffer);
9a6249166 Vinc*0201 
55d2e575a Ian *0202     of = fopen(buffer, "w");
                0203     if (of == NULL)
                0204     {
                0205         ERR("error opening '%s' for writing\n", buffer);
                0206     return;
                0207     }
9a6249166 Vinc*0208 
55d2e575a Ian *0209     buffer[i] = '\0';
9a6249166 Vinc*0210 
55d2e575a Ian *0211     writeHeader(of, afm, buffer);
                0212     writeMetrics(of, afm, buffer);
                0213     writeAFM(of, afm, buffer);
9a6249166 Vinc*0214 
55d2e575a Ian *0215     fclose(of);
                0216 }