remapunicode paramter
[swftools.git] / lib / gfxfont.c
index 45a44ca..8b66e80 100644 (file)
@@ -60,7 +60,7 @@ typedef struct _gfxdrawinfo_t {
     double quality;
 } gfxdrawinfo_t;
 
-static int ft_move_to(FT_Vector* _to, void* user) 
+static int ft_move_to(const FT_Vector* _to, void* user) 
 {
     gfxdrawinfo_t* info = (gfxdrawinfo_t*)user;
     gfxdrawer_t* draw = info->draw;
@@ -69,7 +69,7 @@ static int ft_move_to(FT_Vector* _to, void* user)
     draw->moveTo(draw, x,y);
     return 0;
 }
-static int ft_line_to(FT_Vector* _to, void* user) 
+static int ft_line_to(const FT_Vector* _to, void* user) 
 {
     gfxdrawinfo_t* info = (gfxdrawinfo_t*)user;
     gfxdrawer_t* draw = info->draw;
@@ -78,7 +78,7 @@ static int ft_line_to(FT_Vector* _to, void* user)
     draw->lineTo(draw, x,y);
     return 0;
 }
-static int ft_cubic_to(FT_Vector* _c1, FT_Vector* _c2, FT_Vector* _to, void* user)
+static int ft_cubic_to(const FT_Vector* _c1, const FT_Vector* _c2, const FT_Vector* _to, void* user)
 {
     gfxdrawinfo_t* info = (gfxdrawinfo_t*)user;
     gfxdrawer_t* draw = info->draw;
@@ -91,7 +91,7 @@ static int ft_cubic_to(FT_Vector* _c1, FT_Vector* _c2, FT_Vector* _to, void* use
     gfxdraw_cubicTo(draw, c1x, c1y, c2x, c2y, tox, toy, info->quality);
     return 0;
 }
-static int ft_conic_to(FT_Vector* _c, FT_Vector* _to, void* user) 
+static int ft_conic_to(const FT_Vector* _c, const FT_Vector* _to, void* user) 
 {
     gfxdrawinfo_t* info = (gfxdrawinfo_t*)user;
     gfxdrawer_t* draw = info->draw;
@@ -129,7 +129,7 @@ static void glyph_clear(gfxglyph_t*g)
 {
     gfxline_t*line;
     if(g->name) {
-       free(g->name); g->name = 0;
+       free((void*)g->name); g->name = 0;
     }
     gfxline_free(g->line);g->line = 0;
 }
@@ -191,9 +191,34 @@ gfxfont_t* gfxfont_load(char*id, char*filename, double quality)
 
     fontname = FT_Get_Postscript_Name(face);
 
+    /*for(t=0;t<face->num_charmaps;t++) {
+        printf("possible encoding: %c%c%c%c (%d of %d)\n", 
+                (face->charmaps[t]->encoding >> 24)&255,
+                (face->charmaps[t]->encoding >> 16)&255,
+                (face->charmaps[t]->encoding >> 8)&255,
+                (face->charmaps[t]->encoding >> 0)&255,
+                t+1, face->num_charmaps
+                );
+    }*/
+
     while(1) 
     {
        charcode = FT_Get_First_Char(face, &gindex);
+
+        /*if(face->charmap) {
+            printf("ENCODING: %c%c%c%c (%d of %d)\n", 
+                    (face->charmap->encoding >> 24)&255,
+                    (face->charmap->encoding >> 16)&255,
+                    (face->charmap->encoding >> 8)&255,
+                    (face->charmap->encoding >> 0)&255,
+                    charmap, face->num_charmaps
+                    );
+        } else {
+            printf("ENCODING: NONE (%d of %d)\n",
+                    charmap, face->num_charmaps
+                    );
+        }*/
+
        while(gindex != 0)
        {
            if(gindex >= 0 && gindex<face->num_glyphs) {
@@ -213,7 +238,9 @@ gfxfont_t* gfxfont_load(char*id, char*filename, double quality)
           TODO: find a way to convert the encoding to unicode
         */
        if(font->max_unicode == 0 && charmap < face->num_charmaps-1 && 
-               face->charmaps[charmap+1]->encoding != 0x41444243 /* custom */)
+               face->charmaps[charmap+1]->encoding != 0x41444243 /* custom */
+               && face->charmaps[charmap+1]->encoding != 0x61726d6e    /* armn */
+                )
                {
            charmap++;
            FT_Set_Charmap(face, face->charmaps[charmap]);
@@ -221,7 +248,6 @@ gfxfont_t* gfxfont_load(char*id, char*filename, double quality)
        } else
            break;
     }
-
     /* TODO: if isunicode is 1, we now need to permutate the character
              order so that each character is at it's encoding position */
 
@@ -283,12 +309,17 @@ gfxfont_t* gfxfont_load(char*id, char*filename, double quality)
                hasname = 1;
            }
        }
-       if(has_had_errors && (isunicode && !glyph2unicode[t]) && !hasname) {
+
+#if 0 // some cantonese pdfs fail to work if this is activated
+
+       if(has_had_errors && (isunicode && !glyph2unicode[t]) && !hasname && t>=256) {
            /* some freetype versions crash or corrupt memory if we try to load
               characters (without unicode index or name) above 256 for some fonts.
               So skip those characters once the first error occured */
            omit = 1;
        }
+#endif
+
        if(!omit) {
            error = FT_Load_Glyph(face, t, FT_LOAD_NO_BITMAP);
            if(error) {
@@ -339,7 +370,7 @@ gfxfont_t* gfxfont_load(char*id, char*filename, double quality)
                FT_Done_Glyph(glyph);
                omit = 4;
            } else {
-               font->glyphs[font->num_glyphs].advance = (glyph->advance.x*20)/65536;
+               font->glyphs[font->num_glyphs].advance = glyph->advance.x/65536;
                font->glyphs[font->num_glyphs].line = (gfxline_t*)draw.result(&draw);
            }
            l = font->glyphs[font->num_glyphs].line;
@@ -362,7 +393,7 @@ gfxfont_t* gfxfont_load(char*id, char*filename, double quality)
                    */
                font->glyphs[font->num_glyphs].unicode = 0;
                if(font->glyphs[font->num_glyphs].name) {
-                   free(font->glyphs[font->num_glyphs].name);
+                   free((void*)font->glyphs[font->num_glyphs].name);
                    font->glyphs[font->num_glyphs].name = 0;
                }
                FT_Done_Glyph(glyph);