143f32c10Smrg/*
243f32c10SmrgCopyright (c) 2002-2003 by Juliusz Chroboczek
343f32c10Smrg
443f32c10SmrgPermission is hereby granted, free of charge, to any person obtaining a copy
543f32c10Smrgof this software and associated documentation files (the "Software"), to deal
643f32c10Smrgin the Software without restriction, including without limitation the rights
743f32c10Smrgto use, copy, modify, merge, publish, distribute, sublicense, and/or sell
843f32c10Smrgcopies of the Software, and to permit persons to whom the Software is
943f32c10Smrgfurnished to do so, subject to the following conditions:
1043f32c10Smrg
1143f32c10SmrgThe above copyright notice and this permission notice shall be included in
1243f32c10Smrgall copies or substantial portions of the Software.
1343f32c10Smrg
1443f32c10SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1543f32c10SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1643f32c10SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
1743f32c10SmrgAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1843f32c10SmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1943f32c10SmrgOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2043f32c10SmrgTHE SOFTWARE.
2143f32c10Smrg*/
2243f32c10Smrg/* $XdotOrg: xc/programs/fonttosfnt/fonttosfnt.c,v 1.4 2003/12/19 02:16:36 dawes Exp $ */
2343f32c10Smrg/* $XFree86: xc/programs/fonttosfnt/fonttosfnt.c,v 1.3 2003/07/08 15:39:49 tsi Exp $ */
2443f32c10Smrg
2543f32c10Smrg#include <stdio.h>
2643f32c10Smrg#include <stdlib.h>
2743f32c10Smrg#include <string.h>
2843f32c10Smrg#include "fonttosfnt.h"
2943f32c10Smrg
3043f32c10Smrgint verbose_flag = 0;
3143f32c10Smrgint reencode_flag = 1;
3243f32c10Smrgint glyph_flag = 2;
3343f32c10Smrgint metrics_flag = 1;
3443f32c10Smrgint crop_flag = 1;
3543f32c10Smrgint bit_aligned_flag = 1;
3643f32c10Smrg
3743f32c10Smrgstatic void
3843f32c10Smrgusage(void)
3943f32c10Smrg{
4043f32c10Smrg    fprintf(stderr, "Usage:\n");
4143f32c10Smrg    fprintf(stderr,
42ea148d1dSmrg            "fonttosfnt [ -v ] [ -c ] [ -b ] [ -r ] [ -g n ] [ -m n ] -o font.otb "
43ea148d1dSmrg            "[ -- ] [ font ] ...\n");
4443f32c10Smrg}
4543f32c10Smrg
4643f32c10Smrgint
4743f32c10Smrgmain(int argc, char **argv)
4843f32c10Smrg{
4943f32c10Smrg    int i;
5043f32c10Smrg    char *output = NULL;
5143f32c10Smrg    FontPtr font;
5243f32c10Smrg
5343f32c10Smrg    i = 1;
5443f32c10Smrg    while(i < argc) {
5543f32c10Smrg        if(argv[i][0] != '-')
5643f32c10Smrg            break;
5743f32c10Smrg
5843f32c10Smrg        if(argv[i][1] == 'o') {
5943f32c10Smrg            if(argv[i][2] == '\0') {
6043f32c10Smrg                output = sprintf_alloc("%s", argv[i + 1]);
6143f32c10Smrg                i += 2;
6243f32c10Smrg            } else {
6343f32c10Smrg                output = sprintf_alloc("%s", argv[i] + 2);
6443f32c10Smrg                i++;
6543f32c10Smrg            }
6643f32c10Smrg        } else if(strcmp(argv[i], "-v") == 0) {
6743f32c10Smrg            verbose_flag = 1;
6843f32c10Smrg            i++;
6943f32c10Smrg        } else if(strcmp(argv[i], "-c") == 0) {
7043f32c10Smrg            crop_flag = 0;
7143f32c10Smrg            i++;
7243f32c10Smrg        } else if(strcmp(argv[i], "-b") == 0) {
7343f32c10Smrg            bit_aligned_flag = 0;
7443f32c10Smrg            i++;
7543f32c10Smrg        } else if(strcmp(argv[i], "-r") == 0) {
7643f32c10Smrg            reencode_flag = 0;
7743f32c10Smrg            i++;
7843f32c10Smrg        } else if(strcmp(argv[i], "-g") == 0) {
7943f32c10Smrg            if(argc <= i + 1) {
8043f32c10Smrg                usage();
8143f32c10Smrg                exit(1);
8243f32c10Smrg            }
8343f32c10Smrg            glyph_flag = atoi(argv[i + 1]);
8443f32c10Smrg            i += 2;
8543f32c10Smrg        } else if(strcmp(argv[i], "-m") == 0) {
8643f32c10Smrg            if(argc <= i + 1) {
8743f32c10Smrg                usage();
8843f32c10Smrg                exit(1);
8943f32c10Smrg            }
9043f32c10Smrg            metrics_flag = atoi(argv[i + 1]);
9143f32c10Smrg            i += 2;
9243f32c10Smrg        } else if(strcmp(argv[i], "--") == 0) {
9343f32c10Smrg            i++;
9443f32c10Smrg            break;
9543f32c10Smrg        } else {
9643f32c10Smrg            usage();
9743f32c10Smrg            exit(1);
9843f32c10Smrg        }
9943f32c10Smrg    }
10043f32c10Smrg
10143f32c10Smrg    if(output == NULL) {
10243f32c10Smrg        usage();
10343f32c10Smrg        exit(1);
10443f32c10Smrg    }
10543f32c10Smrg
10643f32c10Smrg    font = makeFont();
10743f32c10Smrg
108c813b494Smrg    if(argc - i > 1)
109c813b494Smrg	fprintf(stderr,
110c813b494Smrg	    "You are requesting to put more than one font into a single OpenType font.\n"
111c813b494Smrg	    "This is not recommended. The global font metrics will not match every font face.\n"
112c813b494Smrg	    "The creation of an OpenType font collection is recommended.\n");
113c813b494Smrg
114ea148d1dSmrg    if(i == argc) {
115fbfaf8f3Smrg        int rc = readFile(NULL, font);
116ea148d1dSmrg        if(rc != 0)
117ea148d1dSmrg            exit(1);
118ea148d1dSmrg    } else while(i < argc) {
119fbfaf8f3Smrg        int rc = readFile(argv[i], font);
12043f32c10Smrg        if(rc != 0)
12143f32c10Smrg            exit(1);
12243f32c10Smrg        i++;
12343f32c10Smrg    }
12443f32c10Smrg
12543f32c10Smrg    writeFile(output, font);
12643f32c10Smrg    return 0;
12743f32c10Smrg}
128