fix crashes reported by Debian Cylab Mayhem Team
[swftools.git] / src / font2swf.c
blob2ba59bd856292c86153e14f476d808f032858c89
1 /* font2swf.c
3 Utility for converting TrueType and Type 1 fonts to SWF.
5 Part of the swftools package.
7 Copyright (c) 2004 Matthias Kramm <kramm@quiss.org>
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.
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.
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 */
23 #include <stdio.h>
24 #include <unistd.h>
25 #include <math.h>
26 #include "../lib/rfxswf.h"
27 #include "../lib/args.h"
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;
36 static struct options_t options[] = {
37 {"h", "help"},
38 {"v", "verbose"},
39 {"o", "output"},
40 {"V", "version"},
41 {0,0}
44 int args_callback_option(char*name,char*val)
46 if(!strcmp(name, "V")) {
47 printf("font2swf - part of %s %s\n", PACKAGE, VERSION);
48 exit(0);
50 else if(!strcmp(name, "o")) {
51 destfilename = val;
52 return 1;
54 else if(!strcmp(name, "v")) {
55 verbose ++;
56 return 0;
58 else if(!strcmp(name, "T")) {
59 config_flashtype=1;
60 return 0;
62 else if(!strcmp(name, "n")) {
63 fontname = val;
64 return 1;
66 else if(!strcmp(name, "a")) {
67 all = 1;
68 return 0;
70 else {
71 printf("Unknown option: -%s\n", name);
72 exit(1);
74 return 0;
76 int args_callback_longoption(char*name,char*val)
78 return args_long2shortoption(options, name, val);
80 void args_callback_usage(char *name)
82 printf("\n");
83 printf("Usage: %s <fontfile>\n", name);
84 printf("\n");
85 printf("-h , --help Print short help message and exit\n");
86 printf("-v , --verbose Be verbose. Use more than one -v for greater effect.\n");
87 printf("-o , --output <filename> Write output to file <filename>.\n");
88 printf("-V , --version Print version info and exit\n");
89 printf("\n");
91 int args_callback_command(char*name,char*val)
93 if(filename) {
94 fprintf(stderr, "Please specify only one font\n");
95 exit(1);
97 filename = name;
98 return 0;
101 static void convertFont(char*infile, char*outfile)
103 SWFFONT * font;
105 font = swf_LoadFont(infile, config_flashtype);
106 if(!font)
107 exit(1);
108 swf_FontCreateAlignZones(font);
110 if(fontname)
111 font->name = strdup(fontname);
113 swf_WriteFont(font, outfile);
114 swf_FontFree(font);
117 int main(int argc, char ** argv)
119 char cwd[128];
120 getcwd(cwd, 128);
121 processargs(argc, argv);
122 if(!all && !filename) {
123 fprintf(stderr, "You must supply a filename.\n");
124 exit(1);
127 if(!all) {
128 convertFont(filename, destfilename);
129 return 0;
132 /* TODO */
133 printf("--all not implemented yet.\n");
135 return 0;