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