fonttosfnt.c revision fbfaf8f3
1/*
2Copyright (c) 2002-2003 by Juliusz Chroboczek
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20THE SOFTWARE.
21*/
22/* $XdotOrg: xc/programs/fonttosfnt/fonttosfnt.c,v 1.4 2003/12/19 02:16:36 dawes Exp $ */
23/* $XFree86: xc/programs/fonttosfnt/fonttosfnt.c,v 1.3 2003/07/08 15:39:49 tsi Exp $ */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include "fonttosfnt.h"
29
30int verbose_flag = 0;
31int reencode_flag = 1;
32int glyph_flag = 2;
33int metrics_flag = 1;
34int crop_flag = 1;
35int bit_aligned_flag = 1;
36
37static void
38usage(void)
39{
40    fprintf(stderr, "Usage:\n");
41    fprintf(stderr,
42            "fonttosfnt [ -v ] [ -c ] [ -b ] [ -r ] [ -g n ] [ -m n ] -o font.otb "
43            "[ -- ] [ font ] ...\n");
44}
45
46int
47main(int argc, char **argv)
48{
49    int i;
50    char *output = NULL;
51    FontPtr font;
52
53    i = 1;
54    while(i < argc) {
55        if(argv[i][0] != '-')
56            break;
57
58        if(argv[i][1] == 'o') {
59            if(argv[i][2] == '\0') {
60                output = sprintf_alloc("%s", argv[i + 1]);
61                i += 2;
62            } else {
63                output = sprintf_alloc("%s", argv[i] + 2);
64                i++;
65            }
66        } else if(strcmp(argv[i], "-v") == 0) {
67            verbose_flag = 1;
68            i++;
69        } else if(strcmp(argv[i], "-c") == 0) {
70            crop_flag = 0;
71            i++;
72        } else if(strcmp(argv[i], "-b") == 0) {
73            bit_aligned_flag = 0;
74            i++;
75        } else if(strcmp(argv[i], "-r") == 0) {
76            reencode_flag = 0;
77            i++;
78        } else if(strcmp(argv[i], "-g") == 0) {
79            if(argc <= i + 1) {
80                usage();
81                exit(1);
82            }
83            glyph_flag = atoi(argv[i + 1]);
84            i += 2;
85        } else if(strcmp(argv[i], "-m") == 0) {
86            if(argc <= i + 1) {
87                usage();
88                exit(1);
89            }
90            metrics_flag = atoi(argv[i + 1]);
91            i += 2;
92        } else if(strcmp(argv[i], "--") == 0) {
93            i++;
94            break;
95        } else {
96            usage();
97            exit(1);
98        }
99    }
100
101    if(output == NULL) {
102        usage();
103        exit(1);
104    }
105
106    font = makeFont();
107
108    if(argc - i > 1)
109	fprintf(stderr,
110	    "You are requesting to put more than one font into a single OpenType font.\n"
111	    "This is not recommended. The global font metrics will not match every font face.\n"
112	    "The creation of an OpenType font collection is recommended.\n");
113
114    if(i == argc) {
115        int rc = readFile(NULL, font);
116        if(rc != 0)
117            exit(1);
118    } else while(i < argc) {
119        int rc = readFile(argv[i], font);
120        if(rc != 0)
121            exit(1);
122        i++;
123    }
124
125    writeFile(output, font);
126    return 0;
127}
128