From e997256c0986b92663c1c5f6e5d5d8a4e8a6eadf Mon Sep 17 00:00:00 2001 From: ben Date: Sun, 2 Dec 2007 18:38:31 +0000 Subject: [PATCH] Cope with TrueType fonts with slightly broken cmaps, just ignoring code points that can't be resolved (apart from warning about it). git-svn-id: svn://svn.tartarus.org/sgt/halibut@7800 cda61777-01e9-0310-a592-d414129be87e --- error.c | 10 +++++++++- halibut.h | 1 + in_sfnt.c | 20 ++++++++++++++++---- inputs/test.but | 1 + 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/error.c b/error.c index b6c2007..2a2c6cd 100644 --- a/error.c +++ b/error.c @@ -18,7 +18,7 @@ static void do_error(int code, va_list ap) { char c; int i, j; char *sp, *sp2; - wchar_t *wsp, *wsp2; + wchar_t *wsp, *wsp2, wc; filepos fpos, fpos2, *fposp; int flags = 0; @@ -374,6 +374,14 @@ static void do_error(int code, va_list ap) { sprintf(error, "font has an invalid header"); flags = FILEPOS; break; + case err_sfntbadglyph: + fpos = *va_arg(ap, filepos *); + wc = va_arg(ap, wchar_t); + sprintf(error, + "warning: character U+%04X references an non-existent glyph", + wc); + flags = FILEPOS; + break; case err_whatever: sp = va_arg(ap, char *); vsprintf(error, sp, ap); diff --git a/halibut.h b/halibut.h index 183a0cb..4f433e1 100644 --- a/halibut.h +++ b/halibut.h @@ -260,6 +260,7 @@ enum { err_sfntnounicmap, /* sfnt has no UCS-2 cmap */ err_sfnttablevers, /* sfnt table version unknown */ err_sfntbadhdr, /* sfnt has bad header */ + err_sfntbadglyph, /* sfnt cmap references bad glyph */ err_whatever /* random error of another type */ }; diff --git a/in_sfnt.c b/in_sfnt.c index 73479b1..fc37dc0 100644 --- a/in_sfnt.c +++ b/in_sfnt.c @@ -885,19 +885,31 @@ void sfnt_getmap(font_info *fi) { for (k = startCode[j]; k <= endCode[j]; k++) { idx = (k + idDelta[j]) & 0xffff; if (idx != 0) { - if (idx > sf->nglyphs) goto bad; + if (idx > sf->nglyphs) { + error(err_sfntbadglyph, &sf->pos, + (wchar_t)k); + continue; + } fi->bmp[k] = sfnt_indextoglyph(sf, idx); } } } else { unsigned startidx = idRangeOffset[j]/2 - segcount + j; for (k = startCode[j]; k <= endCode[j]; k++) { - if (startidx + k - startCode[j] >= nglyphindex) - goto bad; + if (startidx + k - startCode[j] >= + nglyphindex) { + error(err_sfntbadglyph, &sf->pos, + (wchar_t)k); + continue; + } idx = glyphIndexArray[startidx + k - startCode[j]]; if (idx != 0) { idx = (idx + idDelta[j]) & 0xffff; - if (idx > sf->nglyphs) goto bad; + if (idx > sf->nglyphs) { + error(err_sfntbadglyph, &sf->pos, + (wchar_t)k); + continue; + } fi->bmp[k] = sfnt_indextoglyph(sf, idx); } } diff --git a/inputs/test.but b/inputs/test.but index 69c1c82..95b8346 100644 --- a/inputs/test.but +++ b/inputs/test.but @@ -13,6 +13,7 @@ backend has to treat it specially in order to pass it to pdfmark. \cfg{info-dir-entry}{Florbles}{test.but}{Subsection of Halibut test document}{sub-sub} \cfg{info-section-underline}{2}{~} +\cfg{info-charset}{utf-8} \cfg{man-headnumbers}{true} \cfg{contents}{Contents(edited)} -- 2.11.0