added gfx2gfx to Makefile, small fix in as3compile
[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 static char * fontname = 0;
34
35 static struct options_t options[] = {
36 {"h", "help"},
37 {"v", "verbose"},
38 {"o", "output"},
39 {"V", "version"},
40 {0,0}
41 };
42
43 int args_callback_option(char*name,char*val)
44 {
45     if(!strcmp(name, "V")) {
46         printf("font2swf - part of %s %s\n", PACKAGE, VERSION);
47         exit(0);
48     }
49     else if(!strcmp(name, "o")) {
50         destfilename = val;
51         return 1;
52     }
53     else if(!strcmp(name, "v")) {
54         verbose ++;
55         return 0;
56     }
57     else if(!strcmp(name, "n")) {
58         fontname = val;
59         return 1;
60     }
61     else if(!strcmp(name, "a")) {
62         all = 1;
63         return 0;
64     }
65     else {
66         printf("Unknown option: -%s\n", name);
67         exit(1);
68     }
69     return 0;
70 }
71 int args_callback_longoption(char*name,char*val)
72 {
73     return args_long2shortoption(options, name, val);
74 }
75 void args_callback_usage(char *name)
76 {
77     printf("\n");
78     printf("Usage: %s <fontfile>\n", name);
79     printf("\n");
80     printf("-h , --help                    Print short help message and exit\n");
81     printf("-v , --verbose                 Be verbose. Use more than one -v for greater effect.\n");
82     printf("-o , --output <filename>       Write output to file <filename>.\n");
83     printf("-V , --version                 Print version info and exit\n");
84     printf("\n");
85 }
86 int args_callback_command(char*name,char*val)
87 {
88     if(filename) {
89         fprintf(stderr, "Please specify only one font\n");
90         exit(1);
91     }
92     filename = name;
93     return 0;
94 }
95
96 static void convertFont(char*infile, char*outfile)
97 {
98     SWFFONT * font;
99     
100     font = swf_LoadFont(infile);
101
102     if(fontname)
103         font->name = strdup(fontname);
104
105     swf_WriteFont(font, outfile);
106     swf_FontFree(font);
107 }
108
109 int main(int argc, char ** argv)
110 {
111     char cwd[128];
112     getcwd(cwd, 128);
113     processargs(argc, argv);
114     if(!all && !filename) {
115         fprintf(stderr, "You must supply a filename.\n");
116         exit(1);
117     }
118    
119     if(!all) {
120         convertFont(filename, destfilename);
121         return 0;
122     }
123
124     /* TODO */
125     printf("--all not implemented yet.\n");
126
127     return 0;
128 }
129
130