summaryrefslogtreecommitdiff
path: root/mkcfm.c
blob: 3f8737910673ae2e9d7c5da8975d202aab92afd7 (plain)
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
;/* From: Header: xc/programs/mkcfm/RCS/mkcfm.c,v 1.3 1996/05/08 21:38:21 ib Exp $ */
/* Copyright (c) 1994-1999 Silicon Graphics, Inc. All Rights Reserved.
 *
 * The contents of this file are subject to the CID Font Code Public Licence
 * Version 1.0 (the "License"). You may not use this file except in compliance
 * with the Licence. You may obtain a copy of the License at Silicon Graphics,
 * Inc., attn: Legal Services, 2011 N. Shoreline Blvd., Mountain View, CA
 * 94043 or at http://www.sgi.com/software/opensource/cid/license.html.
 *
 * Software distributed under the License is distributed on an "AS IS" basis.
 * ALL WARRANTIES ARE DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED
 * WARRANTIES OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR PURPOSE OR OF
 * NON-INFRINGEMENT. See the License for the specific language governing
 * rights and limitations under the License.
 *
 * The Original Software is CID font code that was developed by Silicon
 * Graphics, Inc.
 */
/* $XFree86: xc/programs/mkcfm/mkcfm.c,v 1.12tsi Exp $ */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/types.h>
#include <dirent.h>

#include <X11/fonts/fntfilst.h>
#include <X11/fonts/FSproto.h>
#include <X11/fonts/FS.h>
#include <X11/fonts/font.h>
#include <X11/fonts/fontenc.h>
#include <X11/fonts/fontstruct.h>
#include <X11/fonts/fsmasks.h>
#include <X11/fonts/fontutil.h>

static void CIDFillVals(FontScalablePtr);
static Bool DoDirectory(char *dirName);
 
#ifndef DEFAULTCID
#define DEFAULTCID "/usr/X11R6/lib/X11/fonts/CID"
#endif
#define DECIPOINTSPERINCH 722.7
#define DEFAULTRES 75
#define DEFAULTPOINTSIZE 120

/* From range.h */
#define CID_NAME_MAX 255

/* From t1intf.h */
extern int CIDOpenScalable ( FontPathElementPtr fpe, FontPtr *ppFont,
                             int flags, FontEntryPtr entry, char *fileName,
                             FontScalablePtr vals, fsBitmapFormat format,
                             fsBitmapFormatMask fmask,
                             FontPtr non_cachable_font );

/* char *unicodetoPSname(unsigned short code); */
extern char *unicodetoPSname(unsigned short code);

FontScalableRec vals;
FontEntryRec entry;

void FatalError(const char *f, ...);
void ErrorF(const char *f, ...);

int 
main(int argc, char **argv)
{
       CIDFillVals(&vals);
       CIDRegisterFontFileFunctions();

       if (argc == 1) {
           if (!DoDirectory(DEFAULTCID)) {
               fprintf(stderr, "Default CID directory %s not found.\n",
                   DEFAULTCID);
               fprintf(stderr, "CFM files not created.\n");
               fprintf(stderr, 
                   "Specify CID directory: mkcfm directory-name.\n");
               exit(1);
           }
       } else if(argc == 2) {
           if (strstr(argv[1], "CID") == NULL || !DoDirectory(argv[1])) {
               fprintf(stderr, 
               "Specified CID directory not found. CFM files not created.\n");
               exit(1);
           }
       }
       exit(0);
}

static Bool 
DoDirectory(char *dirName) {
    DIR *dir, *dir1, *dir2, *dir3;
    struct dirent *dp, *dp1, *dp2;
    char fname[CID_NAME_MAX];
    char dirName1[CID_NAME_MAX], dirName2[CID_NAME_MAX];
    char dirName3[CID_NAME_MAX];
    FontPtr fontptr = NULL;

    entry.name.name = 
        "-foundry-familyname-bold-r-normal--0-0-0-0-p-0-jisx0201.1976-0";

    if ((dir = opendir(dirName))) {
        while((dp = readdir(dir))) {
            if (dp->d_name[0] == '.' || !strncmp(dp->d_name,"fonts.dir",9) ||
                !strncmp(dp->d_name, "fonts.scale", 11))
                continue;
            strcpy(dirName1, dirName);
            strcat(dirName1, "/");
            strcat(dirName1, dp->d_name);
            if ((dir1 = opendir(dirName1))) {
                strcpy(dirName2, dirName1);
                strcat(dirName2, "/CIDFont"); 
                if ((dir2 = opendir(dirName2))) {
                    while((dp1 = readdir(dir2))) {
                        if (dp1->d_name[0] == '.')
                            continue;
                        strcpy(dirName3, dirName1);
                        strcat(dirName3, "/CMap");
                        if ((dir3 = opendir(dirName3))) {
                            while((dp2 = readdir(dir3))) {
                                if (dp2->d_name[0] == '.')
                                    continue;
                                strcpy(fname, dirName1);
                                strcat(fname, "/");
                                strcat(fname, dp1->d_name);
                                strcat(fname, "--");
                                strcat(fname, dp2->d_name);
                                strcat(fname, ".cid");
                                (void)CIDOpenScalable(NULL, &fontptr, 0, &entry, fname, &vals, 0, 0, NULL);
                            }
                            closedir(dir3);
                        }
                    }
                    closedir(dir2);
                }
                closedir(dir1);
            }
        }
        closedir(dir);
        return TRUE;
    } return FALSE;
}

static void 
CIDFillVals(FontScalablePtr vals)
{
    FontResolutionPtr res;
    int         x_res = DEFAULTRES;
    int         y_res = DEFAULTRES;
    int         pointsize = DEFAULTPOINTSIZE;  /* decipoints */
    int         num_res;
 
    /* Must have x, y, and pixel */
    if (!vals->x || !vals->y || !vals->pixel) {
        res = (FontResolutionPtr) GetClientResolutions(&num_res);
        if (num_res) {
            if (res->x_resolution)
                x_res = res->x_resolution;
            if (res->y_resolution)
                y_res = res->y_resolution;
            if (res->point_size)
                pointsize = res->point_size;
        }
        if (!vals->x)
            vals->x = x_res;
        if (!vals->y)
            vals->y = y_res;
        if (!vals->point) {
            if (!vals->pixel) vals->point = pointsize;
            else vals->point = (vals->pixel * DECIPOINTSPERINCH) / vals->y;
            vals->point_matrix[0] = vals->point_matrix[3] = vals->point;
            vals->point_matrix[1] = vals->point_matrix[2] = 0;
        }
        if (!vals->pixel) {
            vals->pixel = (vals->point * vals->y) / DECIPOINTSPERINCH;
            vals->pixel_matrix[0] = vals->pixel_matrix[3] = vals->pixel;
            vals->pixel_matrix[1] = vals->pixel_matrix[2] = 0;
        } 
        /* Make sure above arithmetic is normally in range and will
           round properly. +++ */
    }
}
 
int 
CheckFSFormat(fsBitmapFormat format, fsBitmapFormatMask fmask, int *bit, 
	      int *byte, int *scan, int *glyph, int *image)
{
       *bit = *byte = 1;
       *glyph = *scan = *image = 1;
       return Successful;
 
}

 
Atom 
MakeAtom(char *p, unsigned len, int makeit)
{
       return *p;
}

FontResolutionPtr 
GetClientResolutions(int *resP)
{
       *resP = 0;
       return NULL;
}
 
pointer 
Xalloc(unsigned long size)
{
       return(malloc(size));
}
 
void 
Xfree(pointer p)
{
       free((char *)p);
}
 
void 
FontDefaultFormat(int *bit, int *byte, int *glyph, int *scan) { ; }
 
Bool 
FontFilePriorityRegisterRenderer(FontRendererPtr renderer, int priority) 
{ return TRUE; }
 
Bool 
FontFileRegisterRenderer(FontRendererPtr renderer) { return TRUE; }
 
Bool 
FontParseXLFDName(char *fname, FontScalablePtr vals, int subst)
{ return TRUE; }

void 
FontComputeInfoAccelerators(FontInfoPtr f) { ; }

void 
FatalError(const char *f, ...) { exit (1); }

void 
ErrorF(const char *f, ...) { ; }

char *
FontEncFromXLFD(const char *name, int n ) { return NULL; }

FontMapPtr
FontEncMapFind(const char *c1, int n1, int n2, int n3, const char *c2) 
{ return NULL; }

char *
unicodetoPSname(unsigned short code) { return NULL; }

unsigned 
FontEncRecode(unsigned i, FontMapPtr m) { return 0; }

char *
FontEncName(unsigned i, FontMapPtr m) { return NULL; }

FontPtr 
CreateFontRec (void)
{
    FontPtr pFont;

    pFont = (FontPtr)xalloc(sizeof(FontRec));
    if(pFont)
        bzero((char*)pFont, sizeof(FontRec));

    return pFont;
}

void DestroyFontRec (FontPtr pFont)
{
   xfree(pFont);
}