Skip to content

Commit

Permalink
Fix Unicode font handling (Issue #16)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Nov 14, 2023
1 parent 688810f commit 600fa4c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 39 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
-------------------------

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ DSONAME =
LDFLAGS =
LIBS = -lm -lz
RANLIB = ranlib
VERSION = 1.1.2
VERSION = 1.1.3
prefix = /usr/local


Expand Down
4 changes: 3 additions & 1 deletion pdfio-content.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1551,6 +1551,8 @@ pdfioFileCreateFontObjFromFile(

if (i == 65536)
pdfioArrayAppendNumber(temp_array, w0);
else
i --;

pdfioArrayAppendArray(w_array, temp_array);
}
Expand Down
2 changes: 1 addition & 1 deletion pdfio.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern "C" {
// Version number...
//

# define PDFIO_VERSION "1.1.2"
# define PDFIO_VERSION "1.1.3"


//
Expand Down
4 changes: 2 additions & 2 deletions pdfio_native.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion pdfio_native.redist.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
21 changes: 4 additions & 17 deletions testpdfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 20 additions & 16 deletions ttf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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...
Expand Down Expand Up @@ -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.
//
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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.
//
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 600fa4c

Please sign in to comment.