more horizontal refactoring
[swftools.git] / lib / example / dumpfont.c
index b8f7520..e7edb1d 100644 (file)
@@ -9,16 +9,24 @@
    external files.
 
    Usage: ./dumpfont filename.swf > myfont.c
-
-   Limits: does not parse ST_DEFINEFONT2 
    
    Part of the swftools package.
 
    Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>
  
-   This file is distributed under the GPL, see file COPYING for details 
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-*/
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 #include <stdio.h>
 #include <fcntl.h>
@@ -83,9 +91,20 @@ void DumpFont(SWFFONT * f,char * name)
 
   for (i=0;i<f->numchars;i++)
     if (f->glyph[i].shape)
-    { printf("  addGlyph(f,%3i, 0x%02x,%4i, &Glyphs_%s[0x%04x],%4i); // %c\n",
-             i, f->glyph2ascii[i], f->glyph[i].advance, name, gpos[i],
-             f->glyph[i].shape->bitlen,PRINTABLE(f->glyph2ascii[i]));
+    { 
+       printf("  addGlyph(f,%3i, 0x%03x,%4i, &Glyphs_%s[0x%04x], %4i, ",
+              i, f->glyph2ascii[i], f->glyph[i].advance, name, gpos[i],
+              f->glyph[i].shape->bitlen);
+       if(f->layout && f->layout->bounds) {
+           printf("%d, %d, %d, %d);",
+                   f->layout->bounds[i].xmin,
+                   f->layout->bounds[i].ymin,
+                   f->layout->bounds[i].xmax,
+                   f->layout->bounds[i].ymax);
+        } else {
+           printf("/* bbox not set */ 0, 0, 0, 0);");
+       }
+       printf(" // %c\n", PRINTABLE(f->glyph2ascii[i]));
     }
 
   printf("  return f;\n}\n\n");
@@ -93,7 +112,7 @@ void DumpFont(SWFFONT * f,char * name)
 }
 
 void DumpGlobal(char * funcname)
-{ printf("\nvoid %s(SWFFONT * f,int i,U16 ascii,U16 advance,U8 * data,U32 bitlen)\n",funcname);
+{ printf("\nvoid %s(SWFFONT * f,int i,U16 ascii,U16 advance,U8 * data,U32 bitlen,int xmin,int ymin,int xmax, int ymax)\n",funcname);
   printf("{ SHAPE * s;\n  U32 l = (bitlen+7)/8;\n\n");
   printf("  if (FAILED(swf_ShapeNew(&s))) return;\n");
   printf("  s->data = malloc(l);\n");
@@ -104,11 +123,17 @@ void DumpGlobal(char * funcname)
   printf("  f->glyph[i].shape     = s;\n");
   printf("  s->bitlen             = bitlen;\n");
   printf("  s->bits.fill          = 1;\n");
+  printf("  if(f->layout && f->layout->bounds)\n");
+  printf("  {  f->layout->bounds[i].xmin = xmin;\n");
+  printf("     f->layout->bounds[i].ymin = ymin;\n");
+  printf("     f->layout->bounds[i].xmax = xmax;\n");
+  printf("     f->layout->bounds[i].ymax = ymax;\n");
+  printf("  }\n");
   printf("  memcpy(s->data,data,l);\n}\n\n");
 }
 
 
-void fontcallback(U16 id,U8 * name)
+void fontcallback(U16 id,U8 * name,void*data)
 { SWFFONT * font;
 
   int f;
@@ -149,7 +174,7 @@ int main(int argc,char ** argv)
         sprintf(fn,"fn%04x",getpid()); // avoid name conflicts @ using multiple fonts
         printf("#define addGlyph %s\n",fn);
         DumpGlobal(fn);
-        swf_FontEnumerate(&swf,&fontcallback);
+        swf_FontEnumerate(&swf,&fontcallback,0);
         swf_FreeTags(&swf);
         printf("#undef addGlyph\n");
       }