fonttosfnt.c revision ea148d1d
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    int rc;
5143f32c10Smrg    char *output = NULL;
5243f32c10Smrg    FontPtr font;
5343f32c10Smrg
5443f32c10Smrg    i = 1;
5543f32c10Smrg    while(i < argc) {
5643f32c10Smrg        if(argv[i][0] != '-')
5743f32c10Smrg            break;
5843f32c10Smrg
5943f32c10Smrg        if(argv[i][1] == 'o') {
6043f32c10Smrg            if(argv[i][2] == '\0') {
6143f32c10Smrg                output = sprintf_alloc("%s", argv[i + 1]);
6243f32c10Smrg                i += 2;
6343f32c10Smrg            } else {
6443f32c10Smrg                output = sprintf_alloc("%s", argv[i] + 2);
6543f32c10Smrg                i++;
6643f32c10Smrg            }
6743f32c10Smrg        } else if(strcmp(argv[i], "-v") == 0) {
6843f32c10Smrg            verbose_flag = 1;
6943f32c10Smrg            i++;
7043f32c10Smrg        } else if(strcmp(argv[i], "-c") == 0) {
7143f32c10Smrg            crop_flag = 0;
7243f32c10Smrg            i++;
7343f32c10Smrg        } else if(strcmp(argv[i], "-b") == 0) {
7443f32c10Smrg            bit_aligned_flag = 0;
7543f32c10Smrg            i++;
7643f32c10Smrg        } else if(strcmp(argv[i], "-r") == 0) {
7743f32c10Smrg            reencode_flag = 0;
7843f32c10Smrg            i++;
7943f32c10Smrg        } else if(strcmp(argv[i], "-g") == 0) {
8043f32c10Smrg            if(argc <= i + 1) {
8143f32c10Smrg                usage();
8243f32c10Smrg                exit(1);
8343f32c10Smrg            }
8443f32c10Smrg            glyph_flag = atoi(argv[i + 1]);
8543f32c10Smrg            i += 2;
8643f32c10Smrg        } else if(strcmp(argv[i], "-m") == 0) {
8743f32c10Smrg            if(argc <= i + 1) {
8843f32c10Smrg                usage();
8943f32c10Smrg                exit(1);
9043f32c10Smrg            }
9143f32c10Smrg            metrics_flag = atoi(argv[i + 1]);
9243f32c10Smrg            i += 2;
9343f32c10Smrg        } else if(strcmp(argv[i], "--") == 0) {
9443f32c10Smrg            i++;
9543f32c10Smrg            break;
9643f32c10Smrg        } else {
9743f32c10Smrg            usage();
9843f32c10Smrg            exit(1);
9943f32c10Smrg        }
10043f32c10Smrg    }
10143f32c10Smrg
10243f32c10Smrg    if(output == NULL) {
10343f32c10Smrg        usage();
10443f32c10Smrg        exit(1);
10543f32c10Smrg    }
10643f32c10Smrg
10743f32c10Smrg    font = makeFont();
10843f32c10Smrg
109ea148d1dSmrg    if(i == argc) {
110ea148d1dSmrg        rc = readFile(NULL, font);
111ea148d1dSmrg        if(rc != 0)
112ea148d1dSmrg            exit(1);
113ea148d1dSmrg    } else while(i < argc) {
11443f32c10Smrg        rc = readFile(argv[i], font);
11543f32c10Smrg        if(rc != 0)
11643f32c10Smrg            exit(1);
11743f32c10Smrg        i++;
11843f32c10Smrg    }
11943f32c10Smrg
12043f32c10Smrg    writeFile(output, font);
12143f32c10Smrg    return 0;
12243f32c10Smrg}
123