1 #include <stdlib.h>
2 #include "blocks/blocktypes.h"
3 #include "parser.h"
4 #include "swfoutput.h"
5
6 void
outputHeader(struct Movie * m)7 outputHeader (struct Movie *m)
8 {
9 printf("File version: %i\n", m->version);
10 }
11
12 void
outputTrailer(struct Movie * m)13 outputTrailer (struct Movie *m)
14 {
15 }
16
17 void
outputBlock(int type,SWF_Parserstruct * blockp,FILE * f)18 outputBlock (int type, SWF_Parserstruct * blockp, FILE* f)
19 {
20 FILE *out;
21 char name[256];
22 int skipBytes, ret;
23 int offset = blockp->offset;
24 int length = blockp->length;
25 char *buf;
26
27 switch ( type ) {
28 case SWF_DEFINEFONT:
29 case SWF_DEFINEFONT2:
30 case SWF_DEFINEFONT3:
31 break;
32 default:
33 return;
34 }
35
36 sprintf(name, "font%i.fdb", blockp->block.SWF_DEFINEFONT2.FontID);
37
38
39 out=fopen(name,"wb");
40 if ( out == NULL )
41 {
42 perror("Failed");
43 return;
44 }
45
46 fputc('f', out);
47 fputc('d', out);
48 fputc('b', out);
49 fputc('0', out);
50
51 skipBytes = 4; // skip blockType (2 bytes) + fontId (2 bytes)
52 if(length >= 63) // long Block
53 skipBytes += 4;
54
55 fseek(f, offset + skipBytes, SEEK_SET); /* skip FontId (UI16) */
56 length -= 2; /* sub FontId (UI16) only */
57
58 printf("Writing font '%s' to file '%s' (%i bytes)... ",
59 blockp->block.SWF_DEFINEFONT2.FontName, name, length+4); /* +4 for 'fdb0' header */
60 fflush(stdout);
61
62 buf = malloc(length);
63 if (!buf)
64 {
65 fclose(out);
66 SWF_error("memory allocation error");
67 return;
68 }
69 ret = fread(buf, length, 1, f);
70 if (ret != 1)
71 {
72 fclose(out);
73 free(buf);
74 return;
75 }
76
77 ret = fwrite(buf, length, 1, out);
78 free(buf);
79 if(ret != 1)
80 {
81 fclose(out);
82 return;
83 }
84 fclose(out);
85 printf("Done.\n");
86 }
87