~ubuntu-branches/ubuntu/lucid/lcdf-typetools/lucid

« back to all changes in this revision

Viewing changes to ttftotype42/ttftotype42.cc

  • Committer: Bazaar Package Importer
  • Author(s): C.M. Connelly
  • Date: 2009-04-06 16:49:02 UTC
  • mfrom: (1.2.8 upstream) (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090406164902-9mu14sman9wo3112
Tags: 2.78-1
* New upstream release.
* t1lint: Report warnings when a font charstring command has too many
  arguments.
* Font library changes: correctly implement binary search in a couple
  places -- unexpected sizes could lead to overflow and bad behavior.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* ttftotype42.cc -- driver for translating TrueType fonts to Type 42 fonts
2
2
 *
3
 
 * Copyright (c) 2006 Eddie Kohler
 
3
 * Copyright (c) 2006-2009 Eddie Kohler
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or modify it
6
6
 * under the terms of the GNU General Public License as published by the Free
67
67
    if (!error_message)
68
68
        errh->message("Usage: %s [OPTIONS] [FONTFILE [OUTPUTFILE]]", program_name);
69
69
    else
70
 
        errh->verror(ErrorHandler::ERR_ERROR, String(), error_message, val);
 
70
        errh->vxmessage(ErrorHandler::e_error, error_message, val);
71
71
    errh->message("Type %s --help for more information.", program_name);
72
72
    exit(1);
73
73
}
75
75
void
76
76
usage()
77
77
{
78
 
    printf("\
79
 
'Ttftotype42' translates a TrueType or TrueType-flavored OpenType font into\n\
 
78
    FileErrorHandler uerrh(stdout);
 
79
    uerrh.message("\
 
80
%<Ttftotype42%> translates a TrueType or TrueType-flavored OpenType font into\n\
80
81
PostScript Type 42 format, which is suitable for inclusion in PostScript\n\
81
82
files. The result, is usually written to the standard output.\n\
82
83
\n\
88
89
  -h, --help                   Print this message and exit.\n\
89
90
  -v, --version                Print version number and exit.\n\
90
91
\n\
91
 
Report bugs to <kohler@cs.ucla.edu>.\n", program_name);
 
92
Report bugs to <ekohler@gmail.com>.\n", program_name);
92
93
}
93
94
 
94
95
 
162
163
#endif
163
164
    } else if (!(f = fopen(infn, "rb")))
164
165
        errh->fatal("%s: %s", infn, strerror(errno));
165
 
  
 
166
 
166
167
    int c = getc(f);
167
168
    ungetc(c, f);
168
169
 
198
199
            tables.push_back(s);
199
200
        }
200
201
    OpenType::Font reduced_font = OpenType::Font::make(true, tags, tables);
201
 
    
 
202
 
202
203
    // output file
203
204
    if (!outfn || strcmp(outfn, "-") == 0) {
204
205
        f = stdout;
212
213
#endif
213
214
 
214
215
    // fprintf(f, "%%!\n");
215
 
    
 
216
 
216
217
    // get glyph names
217
218
    TrueTypeBoundsCharstringProgram ttbprog(&otf);
218
219
    Vector<PermString> gn;
271
272
        fprintf(f, "/UnderlineThickness %g def\n", post.underline_thickness() / emunits);
272
273
    }
273
274
    fprintf(f, "end readonly def\n");
274
 
    
 
275
 
275
276
    // encoding
276
277
    fprintf(f, "/Encoding 256 array\n0 1 255{1 index exch/.notdef put}for\n");
277
278
    for (int i = 0; i < 256; i++)
301
302
    fprintf(f, "FontName currentdict end definefont pop\n");
302
303
 
303
304
    // fprintf(f, "/%s 100 selectfont 30 30 moveto (Hello! 9) show showpage\n", name.english_name(OpenType::Name::N_POSTSCRIPT).c_str());
304
 
    
 
305
 
305
306
    if (f != stdout)
306
307
        fclose(f);
307
308
}
312
313
    Clp_Parser *clp =
313
314
        Clp_NewParser(argc, (const char * const *)argv, sizeof(options) / sizeof(options[0]), options);
314
315
    program_name = Clp_ProgramName(clp);
315
 
  
 
316
 
316
317
    ErrorHandler *errh = ErrorHandler::static_initialize(new FileErrorHandler(stderr, String(program_name) + ": "));
317
318
    const char *input_file = 0;
318
319
    const char *output_file = 0;
319
 
  
 
320
 
320
321
    while (1) {
321
322
        int opt = Clp_Next(clp);
322
323
        switch (opt) {
327
328
            else
328
329
                errh = new SilentErrorHandler;
329
330
            break;
330
 
      
 
331
 
331
332
          case VERSION_OPT:
332
333
            printf("ttftotype42 (LCDF typetools) %s\n", VERSION);
333
 
            printf("Copyright (C) 2006 Eddie Kohler\n\
 
334
            printf("Copyright (C) 2006-2009 Eddie Kohler\n\
334
335
This is free software; see the source for copying conditions.\n\
335
336
There is NO warranty, not even for merchantability or fitness for a\n\
336
337
particular purpose.\n");
337
338
            exit(0);
338
339
            break;
339
 
      
 
340
 
340
341
          case HELP_OPT:
341
342
            usage();
342
343
            exit(0);
357
358
            else
358
359
                input_file = clp->vstr;
359
360
            break;
360
 
      
 
361
 
361
362
          case Clp_Done:
362
363
            goto done;
363
 
      
 
364
 
364
365
          case Clp_BadOption:
365
366
            usage_error(errh, 0);
366
367
            break;
367
 
      
 
368
 
368
369
          default:
369
370
            break;
370
 
      
 
371
 
371
372
        }
372
373
    }
373
 
  
 
374
 
374
375
  done:
375
376
    do_file(input_file, output_file, errh);
376
 
    
 
377
 
377
378
    return (errh->nerrors() == 0 ? 0 : 1);
378
379
}