]> www.fi.muni.cz Git - evince.git/blobdiff - backend/dvi/mdvi-lib/pk.c
Fix problem with some pk fonts.
[evince.git] / backend / dvi / mdvi-lib / pk.c
index 39064a13a5d32e3bec9f44561a1f86571af41685..a91161348fe803d175e22820deacafb076884ac2 100644 (file)
@@ -13,7 +13,7 @@
  *
  * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 /*
@@ -307,7 +307,7 @@ static BITMAP *get_packed(FILE *p, int w, int h, int flags)
                paint = !paint;
        }
        if(row != h || inrow != w) {
-               error(_("Bad PK file: More bits than required\n"));
+               mdvi_error(_("Bad PK file: More bits than required\n"));
                bitmap_destroy(bm);
                return NULL;
        }
@@ -328,13 +328,14 @@ static int pk_load_font(DviParams *unused, DviFont *font)
 {
        int     i;
        int     flag_byte;
-       int     loc, hic, maxch;
+       int     hic, maxch;
        Int32   checksum;
        FILE    *p;
 #ifndef NODEBUG
        char    s[256];
 #endif
        long    alpha, beta, z;
+       unsigned int loc;
 
        font->chars = xnalloc(DviFontChar, 256);
        p = font->in;
@@ -360,8 +361,8 @@ static int pk_load_font(DviParams *unused, DviFont *font)
        /* get the checksum */
        checksum = fuget4(p);
        if(checksum && font->checksum && font->checksum != checksum) {
-               warning(_("%s: checksum mismatch (expected %u, got %u)\n"),
-                       font->fontname, font->checksum, checksum);
+               mdvi_warning(_("%s: checksum mismatch (expected %u, got %u)\n"),
+                            font->fontname, font->checksum, checksum);
        } else if(!font->checksum)
                font->checksum = checksum;
        /* skip pixel per point ratios */
@@ -417,7 +418,7 @@ static int pk_load_font(DviParams *unused, DviFont *font)
                        case PK_NOOP:
                                break;
                        case PK_PRE:
-                               error(_("%s: unexpected preamble\n"), font->fontname);
+                               mdvi_error(_("%s: unexpected preamble\n"), font->fontname);
                                goto error;
                        }
                } else {
@@ -469,6 +470,15 @@ static int pk_load_font(DviParams *unused, DviFont *font)
                        }
                        if(feof(p))
                                break;
+
+                       /* Although the PK format support bigger char codes,
+                         * XeTeX and other extended TeX engines support charcodes up to
+                         * 65536, while normal TeX engine supports only charcode up to 255.*/
+                       if (cc < 0 || cc > 65536) {
+                               mdvi_error (_("%s: unexpected charcode (%d)\n"),
+                                           font->fontname,cc);
+                               goto error;
+                       } 
                        if(cc < loc)
                                loc = cc;
                        if(cc > hic)
@@ -500,13 +510,13 @@ static int pk_load_font(DviParams *unused, DviFont *font)
                }
        }
        if(flag_byte != PK_POST) {
-               error(_("%s: unexpected end of file (no postamble)\n"),
-                       font->fontname);
+               mdvi_error(_("%s: unexpected end of file (no postamble)\n"),
+                          font->fontname);
                goto error;
        }
        while((flag_byte = fuget1(p)) != EOF) {
                if(flag_byte != PK_NOOP) {
-                       error(_("invalid PK file! (junk in postamble)\n"));
+                       mdvi_error(_("invalid PK file! (junk in postamble)\n"));
                        goto error;
                }
        }
@@ -523,7 +533,7 @@ static int pk_load_font(DviParams *unused, DviFont *font)
        return 0;
 
 badpk:
-       error(_("%s: File corrupted, or not a PK file\n"), font->fontname);
+       mdvi_error(_("%s: File corrupted, or not a PK file\n"), font->fontname);
 error:
        mdvi_free(font->chars);
        font->chars = NULL;