mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2024-12-27 05:48:20 +01:00
Fix a TrueType CMAP decoding bug and add a NotoSans-Regular test page.
This commit is contained in:
parent
a5dfac7495
commit
d36df63b57
@ -6,6 +6,7 @@ v1.1.4 (Month DD, YYYY)
|
|||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
- Fixed detection of encrypted strings that are too short (Issue #52)
|
- Fixed detection of encrypted strings that are too short (Issue #52)
|
||||||
|
- Fixed a TrueType CMAP decoding bug.
|
||||||
|
|
||||||
|
|
||||||
v1.1.3 (November 15, 2023)
|
v1.1.3 (November 15, 2023)
|
||||||
|
42
testpdfio.c
42
testpdfio.c
@ -44,7 +44,7 @@ static int verify_image(pdfio_file_t *pdf, size_t number);
|
|||||||
static int write_alpha_test(pdfio_file_t *pdf, int number, pdfio_obj_t *font);
|
static int write_alpha_test(pdfio_file_t *pdf, int number, pdfio_obj_t *font);
|
||||||
static int write_color_patch(pdfio_stream_t *st, bool device);
|
static int write_color_patch(pdfio_stream_t *st, bool device);
|
||||||
static int write_color_test(pdfio_file_t *pdf, int number, pdfio_obj_t *font);
|
static int write_color_test(pdfio_file_t *pdf, int number, pdfio_obj_t *font);
|
||||||
static int write_font_test(pdfio_file_t *pdf, int number, pdfio_obj_t *font, bool unicode);
|
static int write_font_test(pdfio_file_t *pdf, int number, pdfio_obj_t *font, const char *textfontfile, bool unicode);
|
||||||
static int write_header_footer(pdfio_stream_t *st, const char *title, int number);
|
static int write_header_footer(pdfio_stream_t *st, const char *title, int number);
|
||||||
static pdfio_obj_t *write_image_object(pdfio_file_t *pdf, _pdfio_predictor_t predictor);
|
static pdfio_obj_t *write_image_object(pdfio_file_t *pdf, _pdfio_predictor_t predictor);
|
||||||
static int write_images_test(pdfio_file_t *pdf, int number, pdfio_obj_t *font);
|
static int write_images_test(pdfio_file_t *pdf, int number, pdfio_obj_t *font);
|
||||||
@ -2229,14 +2229,19 @@ write_color_test(pdfio_file_t *pdf, // I - PDF file
|
|||||||
//
|
//
|
||||||
|
|
||||||
static int // O - 1 on failure, 0 on success
|
static int // O - 1 on failure, 0 on success
|
||||||
write_font_test(pdfio_file_t *pdf, // I - PDF file
|
write_font_test(
|
||||||
|
pdfio_file_t *pdf, // I - PDF file
|
||||||
int number, // I - Page number
|
int number, // I - Page number
|
||||||
pdfio_obj_t *font, // I - Page number font
|
pdfio_obj_t *font, // I - Page number font
|
||||||
|
const char *textfontfile, // I - Text font file
|
||||||
bool unicode) // I - Use Unicode font?
|
bool unicode) // I - Use Unicode font?
|
||||||
{
|
{
|
||||||
pdfio_dict_t *dict; // Page dictionary
|
pdfio_dict_t *dict; // Page dictionary
|
||||||
pdfio_stream_t *st; // Page contents stream
|
pdfio_stream_t *st; // Page contents stream
|
||||||
pdfio_obj_t *opensans; // OpenSans-Regular font
|
pdfio_obj_t *textfont; // Text font
|
||||||
|
char title[256], // Page title
|
||||||
|
textname[256], // Name of text font
|
||||||
|
*ptr; // Pointer into name
|
||||||
int i; // Looping var
|
int i; // Looping var
|
||||||
static const char * const welcomes[] =// "Welcome" in many languages
|
static const char * const welcomes[] =// "Welcome" in many languages
|
||||||
{
|
{
|
||||||
@ -2391,8 +2396,8 @@ write_font_test(pdfio_file_t *pdf, // I - PDF file
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
fputs("pdfioFileCreateFontObjFromFile(OpenSans-Regular.ttf): ", stdout);
|
printf("pdfioFileCreateFontObjFromFile(%s): ", textfontfile);
|
||||||
if ((opensans = pdfioFileCreateFontObjFromFile(pdf, "testfiles/OpenSans-Regular.ttf", unicode)) != NULL)
|
if ((textfont = pdfioFileCreateFontObjFromFile(pdf, textfontfile, unicode)) != NULL)
|
||||||
puts("PASS");
|
puts("PASS");
|
||||||
else
|
else
|
||||||
return (1);
|
return (1);
|
||||||
@ -2410,7 +2415,7 @@ write_font_test(pdfio_file_t *pdf, // I - PDF file
|
|||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
fputs("pdfioPageDictAddFont(F2): ", stdout);
|
fputs("pdfioPageDictAddFont(F2): ", stdout);
|
||||||
if (pdfioPageDictAddFont(dict, "F2", opensans))
|
if (pdfioPageDictAddFont(dict, "F2", textfont))
|
||||||
puts("PASS");
|
puts("PASS");
|
||||||
else
|
else
|
||||||
return (1);
|
return (1);
|
||||||
@ -2422,7 +2427,21 @@ write_font_test(pdfio_file_t *pdf, // I - PDF file
|
|||||||
else
|
else
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
if (write_header_footer(st, unicode ? "Unicode TrueType Font Test" : "CP1252 TrueType Font Test", number))
|
if ((ptr = strrchr(textfontfile, '/')) != NULL)
|
||||||
|
strncpy(textname, ptr + 1, sizeof(textname) - 1);
|
||||||
|
else
|
||||||
|
strncpy(textname, textfontfile, sizeof(textname) - 1);
|
||||||
|
|
||||||
|
textname[sizeof(textname) - 1] = '\0';
|
||||||
|
if ((ptr = strrchr(textname, '.')) != NULL)
|
||||||
|
*ptr = '\0';
|
||||||
|
|
||||||
|
if (unicode)
|
||||||
|
snprintf(title, sizeof(title), "Unicode %s Font Test", textname);
|
||||||
|
else
|
||||||
|
snprintf(title, sizeof(title), "CP1252 %s Font Test", textname);
|
||||||
|
|
||||||
|
if (write_header_footer(st, title, number))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
fputs("pdfioContentTextBegin(): ", stdout);
|
fputs("pdfioContentTextBegin(): ", stdout);
|
||||||
@ -3377,14 +3396,17 @@ write_unit_file(
|
|||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
// Test TrueType fonts...
|
// Test TrueType fonts...
|
||||||
if (write_font_test(outpdf, 9, helvetica, false))
|
if (write_font_test(outpdf, 9, helvetica, "testfiles/OpenSans-Regular.ttf", false))
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
if (write_font_test(outpdf, 10, helvetica, true))
|
if (write_font_test(outpdf, 10, helvetica, "testfiles/OpenSans-Regular.ttf", true))
|
||||||
|
return (1);
|
||||||
|
|
||||||
|
if (write_font_test(outpdf, 11, helvetica, "testfiles/NotoSansJP-Regular.otf", true))
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
// Print this text file...
|
// Print this text file...
|
||||||
if (write_text_test(outpdf, 11, helvetica, "README.md"))
|
if (write_text_test(outpdf, 12, helvetica, "README.md"))
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
fputs("pdfioFileGetNumPages: ", stdout);
|
fputs("pdfioFileGetNumPages: ", stdout);
|
||||||
|
5
ttf.c
5
ttf.c
@ -479,7 +479,7 @@ ttfCreate(const char *filename, // I - Filename
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (i >= ' ' && i < 127)
|
if (i >= ' ' && i < 127 && font->widths[0])
|
||||||
TTF_DEBUG("ttfCreate: width['%c']=%d(%d)\n", (char)i, font->widths[0][i].width, font->widths[0][i].left_bearing);
|
TTF_DEBUG("ttfCreate: width['%c']=%d(%d)\n", (char)i, font->widths[0][i].width, font->widths[0][i].left_bearing);
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
}
|
}
|
||||||
@ -1307,8 +1307,9 @@ read_cmap(ttf_t *font) // I - Font
|
|||||||
{
|
{
|
||||||
// Use an "obscure indexing trick" (words from the spec, not
|
// Use an "obscure indexing trick" (words from the spec, not
|
||||||
// mine) to look up the glyph index...
|
// mine) to look up the glyph index...
|
||||||
temp = segment->idRangeOffset / 2 + ch - segment->startCode + seg - segCount;
|
temp = segment->idRangeOffset / 2 - segCount + (ch - segment->startCode) + (seg - segCount);
|
||||||
|
|
||||||
|
TTF_DEBUG("read_cmap: ch=%d, temp=%d\n", ch, temp);
|
||||||
if (temp < 0 || temp >= numGlyphIdArray)
|
if (temp < 0 || temp >= numGlyphIdArray)
|
||||||
glyph = -1;
|
glyph = -1;
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user