Fix Unicode font handling (Issue #16)

This commit is contained in:
Michael R Sweet 2023-11-14 18:19:34 -05:00
parent 688810f143
commit 600fa4ce59
No known key found for this signature in database
GPG Key ID: BE67C75EC81F3244
8 changed files with 38 additions and 39 deletions

View File

@ -2,6 +2,12 @@ Changes in PDFio
================ ================
v1.1.3 (Month DD, YYYY)
-----------------------
- Fixed Unicode font support (Issue #16)
v1.1.2 (October 10, 2023) v1.1.2 (October 10, 2023)
------------------------- -------------------------

View File

@ -29,7 +29,7 @@ DSONAME =
LDFLAGS = LDFLAGS =
LIBS = -lm -lz LIBS = -lm -lz
RANLIB = ranlib RANLIB = ranlib
VERSION = 1.1.2 VERSION = 1.1.3
prefix = /usr/local prefix = /usr/local

View File

@ -1526,7 +1526,7 @@ pdfioFileCreateFontObjFromFile(
{ {
// Encode a repeating sequence... // Encode a repeating sequence...
pdfioArrayAppendNumber(w_array, start); pdfioArrayAppendNumber(w_array, start);
pdfioArrayAppendNumber(w_array, i); pdfioArrayAppendNumber(w_array, i - 1);
pdfioArrayAppendNumber(w_array, w0); pdfioArrayAppendNumber(w_array, w0);
} }
else else
@ -1551,6 +1551,8 @@ pdfioFileCreateFontObjFromFile(
if (i == 65536) if (i == 65536)
pdfioArrayAppendNumber(temp_array, w0); pdfioArrayAppendNumber(temp_array, w0);
else
i --;
pdfioArrayAppendArray(w_array, temp_array); pdfioArrayAppendArray(w_array, temp_array);
} }

View File

@ -23,7 +23,7 @@ extern "C" {
// Version number... // Version number...
// //
# define PDFIO_VERSION "1.1.2" # define PDFIO_VERSION "1.1.3"
// //

View File

@ -3,7 +3,7 @@
<metadata> <metadata>
<id>pdfio_native</id> <id>pdfio_native</id>
<title>PDFio Library for VS2019+</title> <title>PDFio Library for VS2019+</title>
<version>1.1.2</version> <version>1.1.3</version>
<authors>Michael R Sweet</authors> <authors>Michael R Sweet</authors>
<owners>michaelrsweet</owners> <owners>michaelrsweet</owners>
<projectUrl>https://github.com/michaelrsweet/pappl</projectUrl> <projectUrl>https://github.com/michaelrsweet/pappl</projectUrl>
@ -16,7 +16,7 @@
<copyright>Copyright © 2019-2023 by Michael R Sweet</copyright> <copyright>Copyright © 2019-2023 by Michael R Sweet</copyright>
<tags>pdf file native</tags> <tags>pdf file native</tags>
<dependencies> <dependencies>
<dependency id="pdfio_native.redist" version="1.1.2" /> <dependency id="pdfio_native.redist" version="1.1.3" />
<dependency id="zlib_native.redist" version="1.2.11" /> <dependency id="zlib_native.redist" version="1.2.11" />
</dependencies> </dependencies>
</metadata> </metadata>

View File

@ -3,7 +3,7 @@
<metadata> <metadata>
<id>pdfio_native.redist</id> <id>pdfio_native.redist</id>
<title>PDFio Library for VS2019+</title> <title>PDFio Library for VS2019+</title>
<version>1.1.2</version> <version>1.1.3</version>
<authors>Michael R Sweet</authors> <authors>Michael R Sweet</authors>
<owners>michaelrsweet</owners> <owners>michaelrsweet</owners>
<projectUrl>https://github.com/michaelrsweet/pappl</projectUrl> <projectUrl>https://github.com/michaelrsweet/pappl</projectUrl>

View File

@ -2391,24 +2391,11 @@ write_font_test(pdfio_file_t *pdf, // I - PDF file
}; };
#if 0 fputs("pdfioFileCreateFontObjFromFile(OpenSans-Regular.ttf): ", stdout);
if (unicode) if ((opensans = pdfioFileCreateFontObjFromFile(pdf, "testfiles/OpenSans-Regular.ttf", unicode)) != NULL)
{ puts("PASS");
fputs("pdfioFileCreateFontObjFromFile(NotoSansJP-Regular.otf): ", stdout);
if ((opensans = pdfioFileCreateFontObjFromFile(pdf, "testfiles/NotoSansJP-Regular.otf", true)) != NULL)
puts("PASS");
else
return (1);
}
else else
#endif // 0 return (1);
{
fputs("pdfioFileCreateFontObjFromFile(OpenSans-Regular.ttf): ", stdout);
if ((opensans = pdfioFileCreateFontObjFromFile(pdf, "testfiles/OpenSans-Regular.ttf", unicode)) != NULL)
puts("PASS");
else
return (1);
}
fputs("pdfioDictCreate: ", stdout); fputs("pdfioDictCreate: ", stdout);
if ((dict = pdfioDictCreate(pdf)) != NULL) if ((dict = pdfioDictCreate(pdf)) != NULL)

36
ttf.c
View File

@ -71,11 +71,10 @@ typedef __int64 ssize_t; // POSIX type not present on Windows...
// //
// DEBUG is typically defined for debug builds. TTF_DEBUG maps to printf when // DEBUG is typically defined for debug builds. TTF_DEBUG maps to fprintf when
// DEBUG is defined and is a no-op otherwise... // DEBUG is defined and is a no-op otherwise...
// //
#define DEBUG
#ifdef DEBUG #ifdef DEBUG
# define TTF_DEBUG(...) fprintf(stderr, __VA_ARGS__) # define TTF_DEBUG(...) fprintf(stderr, __VA_ARGS__)
#else #else
@ -459,8 +458,7 @@ ttfCreate(const char *filename, // I - Filename
if (font->cmap[i] >= 0) if (font->cmap[i] >= 0)
{ {
int bin = (int)i / 256, // Sub-array bin int bin = (int)i / 256, // Sub-array bin
glyph = font->cmap[i] + 1; glyph = font->cmap[i]; // Glyph index
// Glyph index (+1 to get past .notdef)
// Update min/max... // Update min/max...
if (font->min_char < 0) if (font->min_char < 0)
@ -479,6 +477,11 @@ ttfCreate(const char *filename, // I - Filename
else else
font->widths[bin][i & 255] = widths[glyph]; font->widths[bin][i & 255] = widths[glyph];
} }
#ifdef DEBUG
if (i >= ' ' && i < 127)
TTF_DEBUG("ttfCreate: width['%c']=%d(%d)\n", (char)i, font->widths[0][i].width, font->widths[0][i].left_bearingx);
#endif // DEBUG
} }
// Cleanup and return the font... // Cleanup and return the font...
@ -735,17 +738,6 @@ ttfGetFamily(ttf_t *font) // I - Font
} }
//
// 'ttfIsFixedPitch()' - Determine whether a font is fixedpitch.
//
bool // O - `true` if fixed pitch, `false` otherwise
ttfIsFixedPitch(ttf_t *font) // I - Font
{
return (font ? font->is_fixed : false);
}
// //
// 'ttfGetItalicAngle()' - Get the italic angle. // 'ttfGetItalicAngle()' - Get the italic angle.
// //
@ -854,7 +846,6 @@ int // O - Width in 1000ths
ttfGetWidth(ttf_t *font, // I - Font ttfGetWidth(ttf_t *font, // I - Font
int ch) // I - Unicode character int ch) // I - Unicode character
{ {
ch --;
int bin = ch >> 8; // Bin in widths array int bin = ch >> 8; // Bin in widths array
@ -882,6 +873,17 @@ ttfGetXHeight(ttf_t *font) // I - Font
} }
//
// 'ttfIsFixedPitch()' - Determine whether a font is fixedpitch.
//
bool // O - `true` if fixed pitch, `false` otherwise
ttfIsFixedPitch(ttf_t *font) // I - Font
{
return (font ? font->is_fixed : false);
}
// //
// 'copy_name()' - Copy a name string from a font. // 'copy_name()' - Copy a name string from a font.
// //
@ -1582,6 +1584,8 @@ read_hmtx(ttf_t *font, // I - Font
{ {
widths[i].width = (short)read_ushort(font); widths[i].width = (short)read_ushort(font);
widths[i].left_bearing = (short)read_short(font); widths[i].left_bearing = (short)read_short(font);
TTF_DEBUG("read_hmtx: widths[%d].width=%d, .left_bearing=%d\n", i, widths[i].width, widths[i].left_bearing);
} }
return (widths); return (widths);