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)
-------------------------

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@
<metadata>
<id>pdfio_native.redist</id>
<title>PDFio Library for VS2019+</title>
<version>1.1.2</version>
<version>1.1.3</version>
<authors>Michael R Sweet</authors>
<owners>michaelrsweet</owners>
<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
if (unicode)
{
fputs("pdfioFileCreateFontObjFromFile(NotoSansJP-Regular.otf): ", stdout);
if ((opensans = pdfioFileCreateFontObjFromFile(pdf, "testfiles/NotoSansJP-Regular.otf", true)) != NULL)
puts("PASS");
else
return (1);
}
fputs("pdfioFileCreateFontObjFromFile(OpenSans-Regular.ttf): ", stdout);
if ((opensans = pdfioFileCreateFontObjFromFile(pdf, "testfiles/OpenSans-Regular.ttf", unicode)) != NULL)
puts("PASS");
else
#endif // 0
{
fputs("pdfioFileCreateFontObjFromFile(OpenSans-Regular.ttf): ", stdout);
if ((opensans = pdfioFileCreateFontObjFromFile(pdf, "testfiles/OpenSans-Regular.ttf", unicode)) != NULL)
puts("PASS");
else
return (1);
}
return (1);
fputs("pdfioDictCreate: ", stdout);
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...
//
#define DEBUG
#ifdef DEBUG
# define TTF_DEBUG(...) fprintf(stderr, __VA_ARGS__)
#else
@ -459,8 +458,7 @@ ttfCreate(const char *filename, // I - Filename
if (font->cmap[i] >= 0)
{
int bin = (int)i / 256, // Sub-array bin
glyph = font->cmap[i] + 1;
// Glyph index (+1 to get past .notdef)
glyph = font->cmap[i]; // Glyph index
// Update min/max...
if (font->min_char < 0)
@ -479,6 +477,11 @@ ttfCreate(const char *filename, // I - Filename
else
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...
@ -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.
//
@ -854,7 +846,6 @@ int // O - Width in 1000ths
ttfGetWidth(ttf_t *font, // I - Font
int ch) // I - Unicode character
{
ch --;
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.
//
@ -1582,6 +1584,8 @@ read_hmtx(ttf_t *font, // I - Font
{
widths[i].width = (short)read_ushort(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);