added -L,-N options
[swftools.git] / src / font2swf.c
1 /* font2swf.c
2
3    Utility for converting TrueType and Type 1 fonts to SWF.
4    
5    Part of the swftools package.
6
7    Copyright (c) 2004 Matthias Kramm <kramm@quiss.org>
8  
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
22
23 #include <stdio.h>
24 #include <unistd.h>
25 #include <math.h>
26 #include "../lib/rfxswf.h"
27 #include "../lib/args.h"
28
29 static char * filename = 0;
30 static char * destfilename = "output.swf";
31 static int all=0;
32 static int verbose=0;
33
34 static struct options_t options[] = {
35 {"h", "help"},
36 {"v", "verbose"},
37 {"o", "output"},
38 {"V", "version"},
39 {0,0}
40 };
41
42 int args_callback_option(char*name,char*val)
43 {
44     if(!strcmp(name, "V")) {
45         printf("font2swf - part of %s %s\n", PACKAGE, VERSION);
46         exit(0);
47     }
48     else if(!strcmp(name, "o")) {
49         destfilename = val;
50         return 1;
51     }
52     else if(!strcmp(name, "v")) {
53         verbose ++;
54         return 0;
55     }
56     else if(!strcmp(name, "a")) {
57         all = 1;
58         return 0;
59     }
60     else {
61         printf("Unknown option: -%s\n", name);
62         exit(1);
63     }
64     return 0;
65 }
66 int args_callback_longoption(char*name,char*val)
67 {
68     return args_long2shortoption(options, name, val);
69 }
70 void args_callback_usage(char *name)
71 {
72     printf("\n");
73     printf("Usage: %s <fontfile>\n", name);
74     printf("\n");
75     printf("-h , --help                    Print short help message and exit\n");
76     printf("-v , --verbose                 Be verbose. Use more than one -v for greater effect.\n");
77     printf("-o , --output <filename>       Write output to file <filename>.\n");
78     printf("-V , --version                 Print version info and exit\n");
79     printf("\n");
80 }
81 int args_callback_command(char*name,char*val)
82 {
83     if(filename) {
84         fprintf(stderr, "Please specify only one font\n");
85         exit(1);
86     }
87     filename = name;
88     return 0;
89 }
90
91 static void convertFont(char*infile, char*outfile)
92 {
93     SWFFONT * font;
94     
95     font = swf_LoadFont(infile);
96
97     swf_WriteFont(font, outfile);
98     swf_FontFree(font);
99 }
100
101 int main(int argc, char ** argv)
102 {
103     char cwd[128];
104     getcwd(cwd, 128);
105     processargs(argc, argv);
106     if(!all && !filename) {
107         fprintf(stderr, "You must supply a filename.\n");
108         exit(1);
109     }
110    
111     if(!all) {
112         convertFont(filename, destfilename);
113         return 0;
114     }
115
116     /* TODO */
117     printf("--all not implemented yet.\n");
118
119     return 0;
120 }
121
122