mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2025-07-15 13:29:56 +02:00
Compare commits
8 Commits
v1.3.1
...
6cb661f0f4
Author | SHA1 | Date | |
---|---|---|---|
6cb661f0f4 | |||
7e01451b18 | |||
138f3955d1 | |||
82844ad2ce | |||
d7cce4dfbc | |||
1cec42f399 | |||
f3f70e7877 | |||
90923c3818 |
58
CHANGES.md
58
CHANGES.md
@ -2,16 +2,22 @@ Changes in PDFio
|
|||||||
================
|
================
|
||||||
|
|
||||||
|
|
||||||
v1.3.1 (August 5, 2024)
|
v1.3.2 - YYYY-MM-DD
|
||||||
-----------------------
|
-------------------
|
||||||
|
|
||||||
|
- Added some more sanity checks to the TrueType font reader.
|
||||||
|
|
||||||
|
|
||||||
|
v1.3.1 - 2024-08-05
|
||||||
|
-------------------
|
||||||
|
|
||||||
- CVE 2024-42358: Updated TrueType font reader to avoid large memory
|
- CVE 2024-42358: Updated TrueType font reader to avoid large memory
|
||||||
allocations.
|
allocations.
|
||||||
- Fixed some documentation errors and added examples (Issue #68, Issue #69)
|
- Fixed some documentation errors and added examples (Issue #68, Issue #69)
|
||||||
|
|
||||||
|
|
||||||
v1.3.0 (June 28, 2024)
|
v1.3.0 - 2024-06-28
|
||||||
----------------------
|
-------------------
|
||||||
|
|
||||||
- Added `pdfioFileGetCatalog` API for accessing the root/catalog object of a
|
- Added `pdfioFileGetCatalog` API for accessing the root/catalog object of a
|
||||||
PDF file (Issue #67)
|
PDF file (Issue #67)
|
||||||
@ -21,8 +27,8 @@ v1.3.0 (June 28, 2024)
|
|||||||
- Optimized string pool code.
|
- Optimized string pool code.
|
||||||
|
|
||||||
|
|
||||||
v1.2.0 (January 24, 2024)
|
v1.2.0 - 2024-01-24
|
||||||
-------------------------
|
-------------------
|
||||||
|
|
||||||
- Now use autoconf to configure the PDFio sources (Issue #54)
|
- Now use autoconf to configure the PDFio sources (Issue #54)
|
||||||
- Added `pdfioFileCreateNumberObj` and `pdfioFileCreateStringObj` functions
|
- Added `pdfioFileCreateNumberObj` and `pdfioFileCreateStringObj` functions
|
||||||
@ -45,8 +51,8 @@ v1.2.0 (January 24, 2024)
|
|||||||
65536 in the xref table (Issue #59)
|
65536 in the xref table (Issue #59)
|
||||||
|
|
||||||
|
|
||||||
v1.1.4 (December 3, 2023)
|
v1.1.4 - 2023-12-03
|
||||||
-------------------------
|
-------------------
|
||||||
|
|
||||||
- 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.
|
- Fixed a TrueType CMAP decoding bug.
|
||||||
@ -54,15 +60,15 @@ v1.1.4 (December 3, 2023)
|
|||||||
- Added a ToUnicode map for Unicode text to support text copying.
|
- Added a ToUnicode map for Unicode text to support text copying.
|
||||||
|
|
||||||
|
|
||||||
v1.1.3 (November 15, 2023)
|
v1.1.3 - 2023-11-15
|
||||||
--------------------------
|
-------------------
|
||||||
|
|
||||||
- Fixed Unicode font support (Issue #16)
|
- Fixed Unicode font support (Issue #16)
|
||||||
- Fixed missing initializer for 40-bit RC4 encryption (Issue #51)
|
- Fixed missing initializer for 40-bit RC4 encryption (Issue #51)
|
||||||
|
|
||||||
|
|
||||||
v1.1.2 (October 10, 2023)
|
v1.1.2 - 2023-10-10
|
||||||
-------------------------
|
-------------------
|
||||||
|
|
||||||
- Updated `pdfioContentSetDashPattern` to support setting a solid (0 length)
|
- Updated `pdfioContentSetDashPattern` to support setting a solid (0 length)
|
||||||
dash pattern (Issue #41)
|
dash pattern (Issue #41)
|
||||||
@ -77,15 +83,15 @@ v1.1.2 (October 10, 2023)
|
|||||||
(Issue #48)
|
(Issue #48)
|
||||||
|
|
||||||
|
|
||||||
v1.1.1 (March 20, 2023)
|
v1.1.1 - 2023-03-20
|
||||||
-----------------------
|
-------------------
|
||||||
|
|
||||||
- CVE-2023-28428: Fixed a potential denial-of-service with corrupt PDF files.
|
- CVE-2023-28428: Fixed a potential denial-of-service with corrupt PDF files.
|
||||||
- Fixed a few build issues.
|
- Fixed a few build issues.
|
||||||
|
|
||||||
|
|
||||||
v1.1.0 (February 6, 2023)
|
v1.1.0 - 2023-02-06
|
||||||
-------------------------
|
-------------------
|
||||||
|
|
||||||
- CVE-2023-24808: Fixed a potential denial-of-service with corrupt PDF files.
|
- CVE-2023-24808: Fixed a potential denial-of-service with corrupt PDF files.
|
||||||
- Added `pdfioFileCreateTemporary` function (Issue #29)
|
- Added `pdfioFileCreateTemporary` function (Issue #29)
|
||||||
@ -99,28 +105,28 @@ v1.1.0 (February 6, 2023)
|
|||||||
- Fixed `pdfioContentMatrixRotate` function.
|
- Fixed `pdfioContentMatrixRotate` function.
|
||||||
|
|
||||||
|
|
||||||
v1.0.1 (March 2, 2022)
|
v1.0.1 - 2022-03-02
|
||||||
----------------------
|
-------------------
|
||||||
|
|
||||||
- Added missing `pdfioPageGetNumStreams` and `pdfioPageOpenStream` functions.
|
- Added missing `pdfioPageGetNumStreams` and `pdfioPageOpenStream` functions.
|
||||||
- Added demo pdfiototext utility.
|
- Added demo pdfiototext utility.
|
||||||
- Fixed bug in `pdfioStreamGetToken`.
|
- Fixed bug in `pdfioStreamGetToken`.
|
||||||
|
|
||||||
|
|
||||||
v1.0.0 (December 14, 2021)
|
v1.0.0 - 2021-12-14
|
||||||
--------------------------
|
-------------------
|
||||||
|
|
||||||
- First stable release.
|
- First stable release.
|
||||||
|
|
||||||
|
|
||||||
v1.0rc1 (November 30, 2021)
|
v1.0rc1 - 2021-11-30
|
||||||
---------------------------
|
--------------------
|
||||||
|
|
||||||
- Fixed a few stack/buffer overflow bugs discovered via fuzzing.
|
- Fixed a few stack/buffer overflow bugs discovered via fuzzing.
|
||||||
|
|
||||||
|
|
||||||
v1.0b2 (November 7, 2021)
|
v1.0b2 - 2021-11-07
|
||||||
-------------------------
|
-------------------
|
||||||
|
|
||||||
- Added `pdfioFileCreateOutput` API to support streaming output of PDF
|
- Added `pdfioFileCreateOutput` API to support streaming output of PDF
|
||||||
(Issue #21)
|
(Issue #21)
|
||||||
@ -131,7 +137,7 @@ v1.0b2 (November 7, 2021)
|
|||||||
- Fixed some issues identified by a Coverity scan.
|
- Fixed some issues identified by a Coverity scan.
|
||||||
|
|
||||||
|
|
||||||
v1.0b1 (August 30, 2021)
|
v1.0b1 - 2021-08-30
|
||||||
------------------------
|
-------------------
|
||||||
|
|
||||||
- Initial release
|
- Initial release
|
||||||
|
24
configure
vendored
24
configure
vendored
@ -1,6 +1,6 @@
|
|||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# Guess values for system-dependent variables and create Makefiles.
|
# Guess values for system-dependent variables and create Makefiles.
|
||||||
# Generated by GNU Autoconf 2.71 for pdfio 1.3.1.
|
# Generated by GNU Autoconf 2.71 for pdfio 1.3.2.
|
||||||
#
|
#
|
||||||
# Report bugs to <https://github.com/michaelrsweet/pdfio/issues>.
|
# Report bugs to <https://github.com/michaelrsweet/pdfio/issues>.
|
||||||
#
|
#
|
||||||
@ -610,8 +610,8 @@ MAKEFLAGS=
|
|||||||
# Identity of this package.
|
# Identity of this package.
|
||||||
PACKAGE_NAME='pdfio'
|
PACKAGE_NAME='pdfio'
|
||||||
PACKAGE_TARNAME='pdfio'
|
PACKAGE_TARNAME='pdfio'
|
||||||
PACKAGE_VERSION='1.3.1'
|
PACKAGE_VERSION='1.3.2'
|
||||||
PACKAGE_STRING='pdfio 1.3.1'
|
PACKAGE_STRING='pdfio 1.3.2'
|
||||||
PACKAGE_BUGREPORT='https://github.com/michaelrsweet/pdfio/issues'
|
PACKAGE_BUGREPORT='https://github.com/michaelrsweet/pdfio/issues'
|
||||||
PACKAGE_URL='https://www.msweet.org/pdfio'
|
PACKAGE_URL='https://www.msweet.org/pdfio'
|
||||||
|
|
||||||
@ -1293,7 +1293,7 @@ if test "$ac_init_help" = "long"; then
|
|||||||
# Omit some internal or obsolete options to make the list less imposing.
|
# Omit some internal or obsolete options to make the list less imposing.
|
||||||
# This message is too long to be a string in the A/UX 3.1 sh.
|
# This message is too long to be a string in the A/UX 3.1 sh.
|
||||||
cat <<_ACEOF
|
cat <<_ACEOF
|
||||||
\`configure' configures pdfio 1.3.1 to adapt to many kinds of systems.
|
\`configure' configures pdfio 1.3.2 to adapt to many kinds of systems.
|
||||||
|
|
||||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||||
|
|
||||||
@ -1359,7 +1359,7 @@ fi
|
|||||||
|
|
||||||
if test -n "$ac_init_help"; then
|
if test -n "$ac_init_help"; then
|
||||||
case $ac_init_help in
|
case $ac_init_help in
|
||||||
short | recursive ) echo "Configuration of pdfio 1.3.1:";;
|
short | recursive ) echo "Configuration of pdfio 1.3.2:";;
|
||||||
esac
|
esac
|
||||||
cat <<\_ACEOF
|
cat <<\_ACEOF
|
||||||
|
|
||||||
@ -1456,7 +1456,7 @@ fi
|
|||||||
test -n "$ac_init_help" && exit $ac_status
|
test -n "$ac_init_help" && exit $ac_status
|
||||||
if $ac_init_version; then
|
if $ac_init_version; then
|
||||||
cat <<\_ACEOF
|
cat <<\_ACEOF
|
||||||
pdfio configure 1.3.1
|
pdfio configure 1.3.2
|
||||||
generated by GNU Autoconf 2.71
|
generated by GNU Autoconf 2.71
|
||||||
|
|
||||||
Copyright (C) 2021 Free Software Foundation, Inc.
|
Copyright (C) 2021 Free Software Foundation, Inc.
|
||||||
@ -1612,7 +1612,7 @@ cat >config.log <<_ACEOF
|
|||||||
This file contains any messages produced by compilers while
|
This file contains any messages produced by compilers while
|
||||||
running configure, to aid debugging if configure makes a mistake.
|
running configure, to aid debugging if configure makes a mistake.
|
||||||
|
|
||||||
It was created by pdfio $as_me 1.3.1, which was
|
It was created by pdfio $as_me 1.3.2, which was
|
||||||
generated by GNU Autoconf 2.71. Invocation command line was
|
generated by GNU Autoconf 2.71. Invocation command line was
|
||||||
|
|
||||||
$ $0$ac_configure_args_raw
|
$ $0$ac_configure_args_raw
|
||||||
@ -2368,9 +2368,9 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
PDFIO_VERSION="1.3.1"
|
PDFIO_VERSION="1.3.2"
|
||||||
PDFIO_VERSION_MAJOR="`echo 1.3.1 | awk -F. '{print $1}'`"
|
PDFIO_VERSION_MAJOR="`echo 1.3.2 | awk -F. '{print $1}'`"
|
||||||
PDFIO_VERSION_MINOR="`echo 1.3.1 | awk -F. '{printf("%d\n",$2);}'`"
|
PDFIO_VERSION_MINOR="`echo 1.3.2 | awk -F. '{printf("%d\n",$2);}'`"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -4935,7 +4935,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
|
|||||||
# report actual input values of CONFIG_FILES etc. instead of their
|
# report actual input values of CONFIG_FILES etc. instead of their
|
||||||
# values after options handling.
|
# values after options handling.
|
||||||
ac_log="
|
ac_log="
|
||||||
This file was extended by pdfio $as_me 1.3.1, which was
|
This file was extended by pdfio $as_me 1.3.2, which was
|
||||||
generated by GNU Autoconf 2.71. Invocation command line was
|
generated by GNU Autoconf 2.71. Invocation command line was
|
||||||
|
|
||||||
CONFIG_FILES = $CONFIG_FILES
|
CONFIG_FILES = $CONFIG_FILES
|
||||||
@ -4991,7 +4991,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
|
|||||||
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
||||||
ac_cs_config='$ac_cs_config_escaped'
|
ac_cs_config='$ac_cs_config_escaped'
|
||||||
ac_cs_version="\\
|
ac_cs_version="\\
|
||||||
pdfio config.status 1.3.1
|
pdfio config.status 1.3.2
|
||||||
configured by $0, generated by GNU Autoconf 2.71,
|
configured by $0, generated by GNU Autoconf 2.71,
|
||||||
with options \\"\$ac_cs_config\\"
|
with options \\"\$ac_cs_config\\"
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ AC_PREREQ([2.70])
|
|||||||
|
|
||||||
|
|
||||||
dnl Package name and version...
|
dnl Package name and version...
|
||||||
AC_INIT([pdfio], [1.3.1], [https://github.com/michaelrsweet/pdfio/issues], [pdfio], [https://www.msweet.org/pdfio])
|
AC_INIT([pdfio], [1.3.2], [https://github.com/michaelrsweet/pdfio/issues], [pdfio], [https://www.msweet.org/pdfio])
|
||||||
|
|
||||||
PDFIO_VERSION="AC_PACKAGE_VERSION"
|
PDFIO_VERSION="AC_PACKAGE_VERSION"
|
||||||
PDFIO_VERSION_MAJOR="`echo AC_PACKAGE_VERSION | awk -F. '{print $1}'`"
|
PDFIO_VERSION_MAJOR="`echo AC_PACKAGE_VERSION | awk -F. '{print $1}'`"
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
LIBRARY pdfio1
|
LIBRARY pdfio1
|
||||||
VERSION 1.2
|
VERSION 1.3
|
||||||
EXPORTS
|
EXPORTS
|
||||||
_pdfioArrayDebug
|
_pdfioArrayDebug
|
||||||
|
_pdfioArrayDecrypt
|
||||||
_pdfioArrayDelete
|
_pdfioArrayDelete
|
||||||
_pdfioArrayGetValue
|
_pdfioArrayGetValue
|
||||||
_pdfioArrayRead
|
_pdfioArrayRead
|
||||||
@ -24,6 +25,7 @@ _pdfioCryptoSHA256Init
|
|||||||
_pdfioCryptoUnlock
|
_pdfioCryptoUnlock
|
||||||
_pdfioDictClear
|
_pdfioDictClear
|
||||||
_pdfioDictDebug
|
_pdfioDictDebug
|
||||||
|
_pdfioDictDecrypt
|
||||||
_pdfioDictDelete
|
_pdfioDictDelete
|
||||||
_pdfioDictGetValue
|
_pdfioDictGetValue
|
||||||
_pdfioDictRead
|
_pdfioDictRead
|
||||||
@ -61,9 +63,12 @@ _pdfioTokenPush
|
|||||||
_pdfioTokenRead
|
_pdfioTokenRead
|
||||||
_pdfioValueCopy
|
_pdfioValueCopy
|
||||||
_pdfioValueDebug
|
_pdfioValueDebug
|
||||||
|
_pdfioValueDecrypt
|
||||||
_pdfioValueDelete
|
_pdfioValueDelete
|
||||||
_pdfioValueRead
|
_pdfioValueRead
|
||||||
_pdfioValueWrite
|
_pdfioValueWrite
|
||||||
|
_pdfio_strtod
|
||||||
|
_pdfio_vsnprintf
|
||||||
pdfioArrayAppendArray
|
pdfioArrayAppendArray
|
||||||
pdfioArrayAppendBinary
|
pdfioArrayAppendBinary
|
||||||
pdfioArrayAppendBoolean
|
pdfioArrayAppendBoolean
|
||||||
@ -190,6 +195,7 @@ pdfioFileCreateStringObj
|
|||||||
pdfioFileCreateTemporary
|
pdfioFileCreateTemporary
|
||||||
pdfioFileFindObj
|
pdfioFileFindObj
|
||||||
pdfioFileGetAuthor
|
pdfioFileGetAuthor
|
||||||
|
pdfioFileGetCatalog
|
||||||
pdfioFileGetCreationDate
|
pdfioFileGetCreationDate
|
||||||
pdfioFileGetCreator
|
pdfioFileGetCreator
|
||||||
pdfioFileGetID
|
pdfioFileGetID
|
||||||
|
@ -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.3.1</version>
|
<version>1.3.2</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-2024 by Michael R Sweet</copyright>
|
<copyright>Copyright © 2019-2024 by Michael R Sweet</copyright>
|
||||||
<tags>pdf file native</tags>
|
<tags>pdf file native</tags>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency id="pdfio_native.redist" version="1.3.1" />
|
<dependency id="pdfio_native.redist" version="1.3.2" />
|
||||||
<dependency id="zlib_native.redist" version="1.2.11" />
|
<dependency id="zlib_native.redist" version="1.2.11" />
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
@ -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.3.1</version>
|
<version>1.3.2</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>
|
||||||
|
57
testpdfio.c
57
testpdfio.c
@ -27,7 +27,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
static int do_crypto_tests(void);
|
static int do_crypto_tests(void);
|
||||||
static int do_test_file(const char *filename, int objnum, bool verbose);
|
static int do_test_file(const char *filename, int objnum, const char *password, bool verbose);
|
||||||
static int do_unit_tests(void);
|
static int do_unit_tests(void);
|
||||||
static int draw_image(pdfio_stream_t *st, const char *name, double x, double y, double w, double h, const char *label);
|
static int draw_image(pdfio_stream_t *st, const char *name, double x, double y, double w, double h, const char *label);
|
||||||
static bool error_cb(pdfio_file_t *pdf, const char *message, bool *error);
|
static bool error_cb(pdfio_file_t *pdf, const char *message, bool *error);
|
||||||
@ -37,6 +37,7 @@ static const char *password_cb(void *data, const char *filename);
|
|||||||
static int read_unit_file(const char *filename, size_t num_pages, size_t first_image, bool is_output);
|
static int read_unit_file(const char *filename, size_t num_pages, size_t first_image, bool is_output);
|
||||||
static ssize_t token_consume_cb(const char **s, size_t bytes);
|
static ssize_t token_consume_cb(const char **s, size_t bytes);
|
||||||
static ssize_t token_peek_cb(const char **s, char *buffer, size_t bytes);
|
static ssize_t token_peek_cb(const char **s, char *buffer, size_t bytes);
|
||||||
|
static int usage(FILE *fp);
|
||||||
static int verify_image(pdfio_file_t *pdf, size_t number);
|
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);
|
||||||
@ -59,22 +60,33 @@ int // O - Exit status
|
|||||||
main(int argc, // I - Number of command-line arguments
|
main(int argc, // I - Number of command-line arguments
|
||||||
char *argv[]) // I - Command-line arguments
|
char *argv[]) // I - Command-line arguments
|
||||||
{
|
{
|
||||||
int ret = 0; // Return value
|
int ret = 0; // Return value
|
||||||
|
|
||||||
|
|
||||||
fprintf(stderr, "testpdfio: Test locale is \"%s\".\n", setlocale(LC_ALL, getenv("LANG")));
|
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
{
|
{
|
||||||
int i; // Looping var
|
int i; // Looping var
|
||||||
|
const char *password = NULL; // Password
|
||||||
bool verbose = false; // Be verbose?
|
bool verbose = false; // Be verbose?
|
||||||
|
|
||||||
for (i = 1; i < argc; i ++)
|
for (i = 1; i < argc; i ++)
|
||||||
{
|
{
|
||||||
if (!strcmp(argv[i], "--help"))
|
if (!strcmp(argv[i], "--help"))
|
||||||
{
|
{
|
||||||
puts("Usage: ./testpdfio [--help] [--verbose] [filename [objnum] ...]");
|
return (usage(stdout));
|
||||||
return (0);
|
}
|
||||||
|
else if (!strcmp(argv[i], "--password"))
|
||||||
|
{
|
||||||
|
i ++;
|
||||||
|
if (i < argc)
|
||||||
|
{
|
||||||
|
password = argv[i];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fputs("testpdfio: Missing password after '--password'.\n", stderr);
|
||||||
|
return (usage(stderr));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (!strcmp(argv[i], "--verbose"))
|
else if (!strcmp(argv[i], "--verbose"))
|
||||||
{
|
{
|
||||||
@ -82,24 +94,27 @@ main(int argc, // I - Number of command-line arguments
|
|||||||
}
|
}
|
||||||
else if (argv[i][0] == '-')
|
else if (argv[i][0] == '-')
|
||||||
{
|
{
|
||||||
printf("Unknown option '%s'.\n\n", argv[i]);
|
fprintf(stderr, "testpdfio: Unknown option '%s'.\n", argv[i]);
|
||||||
puts("Usage: ./testpdfio [--help] [--verbose] [filename [objnum] ...]");
|
return (usage(stderr));
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
else if ((i + 1) < argc && isdigit(argv[i + 1][0] & 255))
|
else if ((i + 1) < argc && isdigit(argv[i + 1][0] & 255))
|
||||||
{
|
{
|
||||||
// filename.pdf object-number
|
// filename.pdf object-number
|
||||||
if (do_test_file(argv[i], atoi(argv[i + 1]), verbose))
|
if (do_test_file(argv[i], atoi(argv[i + 1]), password, verbose))
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
i ++;
|
i ++;
|
||||||
}
|
}
|
||||||
else if (do_test_file(argv[i], 0, verbose))
|
else if (do_test_file(argv[i], 0, password, verbose))
|
||||||
|
{
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
fprintf(stderr, "testpdfio: Test locale is \"%s\".\n", setlocale(LC_ALL, getenv("LANG")));
|
||||||
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
// Windows puts executables in Platform/Configuration subdirs...
|
// Windows puts executables in Platform/Configuration subdirs...
|
||||||
if (!_access("../../testfiles", 0))
|
if (!_access("../../testfiles", 0))
|
||||||
@ -363,6 +378,7 @@ do_crypto_tests(void)
|
|||||||
static int // O - Exit status
|
static int // O - Exit status
|
||||||
do_test_file(const char *filename, // I - PDF filename
|
do_test_file(const char *filename, // I - PDF filename
|
||||||
int objnum, // I - Object number to dump, if any
|
int objnum, // I - Object number to dump, if any
|
||||||
|
const char *password, // I - Password for file
|
||||||
bool verbose) // I - Be verbose?
|
bool verbose) // I - Be verbose?
|
||||||
{
|
{
|
||||||
bool error = false; // Have we shown an error yet?
|
bool error = false; // Have we shown an error yet?
|
||||||
@ -381,7 +397,7 @@ do_test_file(const char *filename, // I - PDF filename
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pdf = pdfioFileOpen(filename, /*password_cb*/NULL, /*password_data*/NULL, (pdfio_error_cb_t)error_cb, &error)) != NULL)
|
if ((pdf = pdfioFileOpen(filename, password_cb, (void *)password, (pdfio_error_cb_t)error_cb, &error)) != NULL)
|
||||||
{
|
{
|
||||||
if (objnum)
|
if (objnum)
|
||||||
{
|
{
|
||||||
@ -1559,6 +1575,23 @@ token_peek_cb(const char **s, // IO - Test string
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// 'usage()' - Show program usage.
|
||||||
|
//
|
||||||
|
|
||||||
|
static int // O - Exit status
|
||||||
|
usage(FILE *fp) // I - Output file
|
||||||
|
{
|
||||||
|
fputs("Usage: ./testpdfio [OPTIONS] [FILENAME [OBJNUM]] ...\n", fp);
|
||||||
|
fputs("Options:\n", fp);
|
||||||
|
fputs(" --help Show program help.\n", fp);
|
||||||
|
fputs(" --password PASSWORD Set PDF password.\n", fp);
|
||||||
|
fputs(" --verbose Be verbose.\n", fp);
|
||||||
|
|
||||||
|
return (fp != stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'verify_image()' - Verify an image object.
|
// 'verify_image()' - Verify an image object.
|
||||||
//
|
//
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
//
|
//
|
||||||
// https://github.com/michaelrsweet/ttf
|
// https://github.com/michaelrsweet/ttf
|
||||||
//
|
//
|
||||||
// Copyright © 2018-2023 by Michael R Sweet.
|
// Copyright © 2018-2024 by Michael R Sweet.
|
||||||
//
|
//
|
||||||
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
||||||
// information.
|
// information.
|
||||||
@ -120,6 +120,7 @@ test_font(const char *filename) // I - Font filename
|
|||||||
|
|
||||||
|
|
||||||
printf("ttfCreate(\"%s\"): ", filename);
|
printf("ttfCreate(\"%s\"): ", filename);
|
||||||
|
fflush(stdout);
|
||||||
if ((font = ttfCreate(filename, 0, error_cb, NULL)) != NULL)
|
if ((font = ttfCreate(filename, 0, error_cb, NULL)) != NULL)
|
||||||
puts("PASS");
|
puts("PASS");
|
||||||
else
|
else
|
||||||
|
92
ttf.c
92
ttf.c
@ -62,7 +62,7 @@
|
|||||||
# define O_CREAT _O_CREAT
|
# define O_CREAT _O_CREAT
|
||||||
# define O_TRUNC _O_TRUNC
|
# define O_TRUNC _O_TRUNC
|
||||||
|
|
||||||
typedef __int64 ssize_t; // POSIX type not present on Windows...
|
typedef __int64 ssize_t; // POSIX type not present on Windows... @private@
|
||||||
|
|
||||||
#else
|
#else
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
@ -100,6 +100,8 @@ typedef __int64 ssize_t; // POSIX type not present on Windows...
|
|||||||
|
|
||||||
#define TTF_FONT_MAX_CHAR 262144 // Maximum number of character values
|
#define TTF_FONT_MAX_CHAR 262144 // Maximum number of character values
|
||||||
#define TTF_FONT_MAX_GROUPS 65536 // Maximum number of sub-groups
|
#define TTF_FONT_MAX_GROUPS 65536 // Maximum number of sub-groups
|
||||||
|
#define TTF_FONT_MAX_NAMES 16777216// Maximum size of names table we support
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// TTF/OFF tag constants...
|
// TTF/OFF tag constants...
|
||||||
@ -254,7 +256,7 @@ typedef struct _ttf_off_hhea_s // Horizontal header
|
|||||||
{
|
{
|
||||||
short ascender, // Ascender
|
short ascender, // Ascender
|
||||||
descender; // Descender
|
descender; // Descender
|
||||||
int numberOfHMetrics; // Number of horizontal metrics
|
unsigned short numberOfHMetrics; // Number of horizontal metrics
|
||||||
} _ttf_off_hhea_t;
|
} _ttf_off_hhea_t;
|
||||||
|
|
||||||
typedef struct _ttf_off_os_2_s // OS/2 information
|
typedef struct _ttf_off_os_2_s // OS/2 information
|
||||||
@ -297,7 +299,28 @@ static unsigned seek_table(ttf_t *font, unsigned tag, unsigned offset, bool requ
|
|||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'ttfCreate()' - Create a new font object for the named font family.
|
// 'ttfCreate()' - Create a new font object for the named font file.
|
||||||
|
//
|
||||||
|
// This function creates a new font object for the named TrueType or OpenType
|
||||||
|
// font file or collection. The "filename" argument specifies the name of the
|
||||||
|
// file to read.
|
||||||
|
//
|
||||||
|
// The "idx" argument specifies the font to load from a collection - the first
|
||||||
|
// font is number `0`. Once created, you can call the @link ttfGetNumFonts@
|
||||||
|
// function to determine whether the loaded font file is a collection with more
|
||||||
|
// than one font.
|
||||||
|
//
|
||||||
|
// The "err_cb" and "err_data" arguments specify a callback function and data
|
||||||
|
// pointer for receiving error messages. If `NULL`, errors are sent to the
|
||||||
|
// `stderr` file. The callback function receives the data pointer and a text
|
||||||
|
// message string, for example:
|
||||||
|
//
|
||||||
|
// ```
|
||||||
|
// void my_err_cb(void *err_data, const char *message)
|
||||||
|
// {
|
||||||
|
// fprintf(stderr, "ERROR: %s\n", message);
|
||||||
|
// }
|
||||||
|
// ```
|
||||||
//
|
//
|
||||||
|
|
||||||
ttf_t * // O - New font object
|
ttf_t * // O - New font object
|
||||||
@ -550,6 +573,10 @@ ttfGetAscent(ttf_t *font) // I - Font
|
|||||||
//
|
//
|
||||||
// 'ttfGetBounds()' - Get the bounds of all characters in a font.
|
// 'ttfGetBounds()' - Get the bounds of all characters in a font.
|
||||||
//
|
//
|
||||||
|
// This function gets the bounds of all characters in a font. The "bounds"
|
||||||
|
// argument is a pointer to a `ttf_rect_t` structure that will be filled with
|
||||||
|
// the limits for characters in the font scaled to a 1000x1000 unit square.
|
||||||
|
//
|
||||||
|
|
||||||
ttf_rect_t * // O - Bounds or `NULL` on error
|
ttf_rect_t * // O - Bounds or `NULL` on error
|
||||||
ttfGetBounds(ttf_t *font, // I - Font
|
ttfGetBounds(ttf_t *font, // I - Font
|
||||||
@ -631,8 +658,11 @@ ttfGetDescent(ttf_t *font) // I - Font
|
|||||||
//
|
//
|
||||||
// 'ttfGetExtents()' - Get the extents of a UTF-8 string.
|
// 'ttfGetExtents()' - Get the extents of a UTF-8 string.
|
||||||
//
|
//
|
||||||
// This function computes the extents of a UTF-8 string when rendered using the
|
// This function computes the extents of the UTF-8 string "s" when rendered
|
||||||
// specified font and size.
|
// using the specified font "font" and size "size". The "extents" argument is
|
||||||
|
// a pointer to a `ttf_rect_t` structure that is filled with the extents of a
|
||||||
|
// simple rendering of the string with no kerning or rewriting applied. The
|
||||||
|
// values are scaled using the specified font size.
|
||||||
//
|
//
|
||||||
|
|
||||||
ttf_rect_t * // O - Pointer to extents or `NULL` on error
|
ttf_rect_t * // O - Pointer to extents or `NULL` on error
|
||||||
@ -1272,21 +1302,28 @@ read_cmap(ttf_t *font) // I - Font
|
|||||||
for (i = 0; i < numGlyphIdArray; i ++)
|
for (i = 0; i < numGlyphIdArray; i ++)
|
||||||
glyphIdArray[i] = read_ushort(font);
|
glyphIdArray[i] = read_ushort(font);
|
||||||
|
|
||||||
#ifdef DEBUG
|
for (i = 0, segment = segments; i < segCount; i ++, segment ++)
|
||||||
for (i = 0; i < segCount; i ++)
|
{
|
||||||
TTF_DEBUG("read_cmap: segment[%d].startCode=%d, endCode=%d, idDelta=%d, idRangeOffset=%d\n", i, segments[i].startCode, segments[i].endCode, segments[i].idDelta, segments[i].idRangeOffset);
|
TTF_DEBUG("read_cmap: segment[%d].startCode=%d, endCode=%d, idDelta=%d, idRangeOffset=%d\n", i, segment->startCode, segment->endCode, segment->idDelta, segment->idRangeOffset);
|
||||||
|
|
||||||
|
if (segment->startCode > segment->endCode)
|
||||||
|
{
|
||||||
|
errorf(font, "Bad cmap table segment %u to %u.", segments->startCode, segment->endCode);
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Based on the end code of the segment table, allocate space for the
|
||||||
|
// uncompressed cmap table...
|
||||||
|
if (segment->endCode >= font->num_cmap)
|
||||||
|
font->num_cmap = segment->endCode + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
for (i = 0; i < numGlyphIdArray; i ++)
|
for (i = 0; i < numGlyphIdArray; i ++)
|
||||||
TTF_DEBUG("read_cmap: glyphIdArray[%d]=%d\n", i, glyphIdArray[i]);
|
TTF_DEBUG("read_cmap: glyphIdArray[%d]=%d\n", i, glyphIdArray[i]);
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
|
|
||||||
// Based on the end code of the segent table, allocate space for the
|
if (font->num_cmap == 0 || font->num_cmap > TTF_FONT_MAX_CHAR)
|
||||||
// uncompressed cmap table...
|
|
||||||
// segCount --; // Last segment is not used (sigh)
|
|
||||||
|
|
||||||
font->num_cmap = segments[segCount - 1].endCode + 1;
|
|
||||||
|
|
||||||
if (font->num_cmap > TTF_FONT_MAX_CHAR)
|
|
||||||
{
|
{
|
||||||
errorf(font, "Invalid cmap table with %u characters.", (unsigned)font->num_cmap);
|
errorf(font, "Invalid cmap table with %u characters.", (unsigned)font->num_cmap);
|
||||||
return (false);
|
return (false);
|
||||||
@ -1382,6 +1419,12 @@ read_cmap(ttf_t *font) // I - Font
|
|||||||
group->startGlyphID = read_ulong(font);
|
group->startGlyphID = read_ulong(font);
|
||||||
TTF_DEBUG("read_cmap: [%u] startCharCode=%u, endCharCode=%u, startGlyphID=%u\n", gidx, group->startCharCode, group->endCharCode, group->startGlyphID);
|
TTF_DEBUG("read_cmap: [%u] startCharCode=%u, endCharCode=%u, startGlyphID=%u\n", gidx, group->startCharCode, group->endCharCode, group->startGlyphID);
|
||||||
|
|
||||||
|
if (group->startCharCode > group->endCharCode)
|
||||||
|
{
|
||||||
|
errorf(font, "Bad cmap table segment %u to %u.", group->startCharCode, group->endCharCode);
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
|
||||||
if (group->endCharCode >= font->num_cmap)
|
if (group->endCharCode >= font->num_cmap)
|
||||||
font->num_cmap = group->endCharCode + 1;
|
font->num_cmap = group->endCharCode + 1;
|
||||||
}
|
}
|
||||||
@ -1390,7 +1433,7 @@ read_cmap(ttf_t *font) // I - Font
|
|||||||
// uncompressed cmap table...
|
// uncompressed cmap table...
|
||||||
TTF_DEBUG("read_cmap: num_cmap=%u\n", (unsigned)font->num_cmap);
|
TTF_DEBUG("read_cmap: num_cmap=%u\n", (unsigned)font->num_cmap);
|
||||||
|
|
||||||
if (font->num_cmap > TTF_FONT_MAX_CHAR)
|
if (font->num_cmap == 0 || font->num_cmap > TTF_FONT_MAX_CHAR)
|
||||||
{
|
{
|
||||||
errorf(font, "Invalid cmap table with %u characters.", (unsigned)font->num_cmap);
|
errorf(font, "Invalid cmap table with %u characters.", (unsigned)font->num_cmap);
|
||||||
return (false);
|
return (false);
|
||||||
@ -1465,6 +1508,12 @@ read_cmap(ttf_t *font) // I - Font
|
|||||||
group->glyphID = read_ulong(font);
|
group->glyphID = read_ulong(font);
|
||||||
TTF_DEBUG("read_cmap: [%u] startCharCode=%u, endCharCode=%u, glyphID=%u\n", gidx, group->startCharCode, group->endCharCode, group->glyphID);
|
TTF_DEBUG("read_cmap: [%u] startCharCode=%u, endCharCode=%u, glyphID=%u\n", gidx, group->startCharCode, group->endCharCode, group->glyphID);
|
||||||
|
|
||||||
|
if (group->startCharCode > group->endCharCode)
|
||||||
|
{
|
||||||
|
errorf(font, "Bad cmap table segment %u to %u.", group->startCharCode, group->endCharCode);
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
|
||||||
if (group->endCharCode >= font->num_cmap)
|
if (group->endCharCode >= font->num_cmap)
|
||||||
font->num_cmap = group->endCharCode + 1;
|
font->num_cmap = group->endCharCode + 1;
|
||||||
}
|
}
|
||||||
@ -1473,7 +1522,7 @@ read_cmap(ttf_t *font) // I - Font
|
|||||||
// uncompressed cmap table...
|
// uncompressed cmap table...
|
||||||
TTF_DEBUG("read_cmap: num_cmap=%u\n", (unsigned)font->num_cmap);
|
TTF_DEBUG("read_cmap: num_cmap=%u\n", (unsigned)font->num_cmap);
|
||||||
|
|
||||||
if (font->num_cmap > TTF_FONT_MAX_CHAR)
|
if (font->num_cmap == 0 || font->num_cmap > TTF_FONT_MAX_CHAR)
|
||||||
{
|
{
|
||||||
errorf(font, "Invalid cmap table with %u characters.", (unsigned)font->num_cmap);
|
errorf(font, "Invalid cmap table with %u characters.", (unsigned)font->num_cmap);
|
||||||
return (false);
|
return (false);
|
||||||
@ -1598,7 +1647,7 @@ read_hmtx(ttf_t *font, // I - Font
|
|||||||
_ttf_off_hhea_t *hhea) // O - hhea table data
|
_ttf_off_hhea_t *hhea) // O - hhea table data
|
||||||
{
|
{
|
||||||
unsigned length; // Length of hmtx table
|
unsigned length; // Length of hmtx table
|
||||||
int i; // Looping var
|
unsigned i; // Looping var
|
||||||
_ttf_metric_t *widths; // Glyph metrics array
|
_ttf_metric_t *widths; // Glyph metrics array
|
||||||
|
|
||||||
|
|
||||||
@ -1677,8 +1726,15 @@ read_names(ttf_t *font) // I - Font
|
|||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
font->names.storage_size = length - (unsigned)offset;
|
font->names.storage_size = length - (unsigned)offset;
|
||||||
|
if (font->names.storage_size > TTF_FONT_MAX_NAMES)
|
||||||
|
{
|
||||||
|
errorf(font, "Name table too large - %u bytes.", (unsigned)font->names.storage_size);
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
|
||||||
if ((font->names.storage = malloc(font->names.storage_size)) == NULL)
|
if ((font->names.storage = malloc(font->names.storage_size)) == NULL)
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
memset(font->names.storage, 'A', font->names.storage_size);
|
memset(font->names.storage, 'A', font->names.storage_size);
|
||||||
|
|
||||||
for (i = font->names.num_names, name = font->names.names; i > 0; i --, name ++)
|
for (i = font->names.num_names, name = font->names.names; i > 0; i --, name ++)
|
||||||
|
16
ttf.h
16
ttf.h
@ -3,7 +3,7 @@
|
|||||||
//
|
//
|
||||||
// https://github.com/michaelrsweet/ttf
|
// https://github.com/michaelrsweet/ttf
|
||||||
//
|
//
|
||||||
// Copyright © 2018-2023 by Michael R Sweet.
|
// Copyright © 2018-2024 by Michael R Sweet.
|
||||||
//
|
//
|
||||||
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
||||||
// information.
|
// information.
|
||||||
@ -22,12 +22,12 @@ extern "C" {
|
|||||||
// Types...
|
// Types...
|
||||||
//
|
//
|
||||||
|
|
||||||
typedef struct _ttf_s ttf_t; //// Font object
|
typedef struct _ttf_s ttf_t; // Font object
|
||||||
|
|
||||||
typedef void (*ttf_err_cb_t)(void *data, const char *message);
|
typedef void (*ttf_err_cb_t)(void *data, const char *message);
|
||||||
//// Font error callback
|
// Font error callback
|
||||||
|
|
||||||
typedef enum ttf_stretch_e //// Font stretch
|
typedef enum ttf_stretch_e // Font stretch
|
||||||
{
|
{
|
||||||
TTF_STRETCH_NORMAL, // normal
|
TTF_STRETCH_NORMAL, // normal
|
||||||
TTF_STRETCH_ULTRA_CONDENSED, // ultra-condensed
|
TTF_STRETCH_ULTRA_CONDENSED, // ultra-condensed
|
||||||
@ -40,20 +40,20 @@ typedef enum ttf_stretch_e //// Font stretch
|
|||||||
TTF_STRETCH_ULTRA_EXPANDED // ultra-expanded
|
TTF_STRETCH_ULTRA_EXPANDED // ultra-expanded
|
||||||
} ttf_stretch_t;
|
} ttf_stretch_t;
|
||||||
|
|
||||||
typedef enum ttf_style_e //// Font style
|
typedef enum ttf_style_e // Font style
|
||||||
{
|
{
|
||||||
TTF_STYLE_NORMAL, // Normal font
|
TTF_STYLE_NORMAL, // Normal font
|
||||||
TTF_STYLE_ITALIC, // Italic font
|
TTF_STYLE_ITALIC, // Italic font
|
||||||
TTF_STYLE_OBLIQUE // Oblique (angled) font
|
TTF_STYLE_OBLIQUE // Oblique (angled) font
|
||||||
} ttf_style_t;
|
} ttf_style_t;
|
||||||
|
|
||||||
typedef enum ttf_variant_e //// Font variant
|
typedef enum ttf_variant_e // Font variant
|
||||||
{
|
{
|
||||||
TTF_VARIANT_NORMAL, // Normal font
|
TTF_VARIANT_NORMAL, // Normal font
|
||||||
TTF_VARIANT_SMALL_CAPS // Font whose lowercase letters are small capitals
|
TTF_VARIANT_SMALL_CAPS // Font whose lowercase letters are small capitals
|
||||||
} ttf_variant_t;
|
} ttf_variant_t;
|
||||||
|
|
||||||
typedef enum ttf_weight_e //// Font weight
|
typedef enum ttf_weight_e // Font weight
|
||||||
{
|
{
|
||||||
TTF_WEIGHT_100 = 100, // Weight 100 (Thin)
|
TTF_WEIGHT_100 = 100, // Weight 100 (Thin)
|
||||||
TTF_WEIGHT_200 = 200, // Weight 200 (Extra/Ultra-Light)
|
TTF_WEIGHT_200 = 200, // Weight 200 (Extra/Ultra-Light)
|
||||||
@ -66,7 +66,7 @@ typedef enum ttf_weight_e //// Font weight
|
|||||||
TTF_WEIGHT_900 = 900 // Weight 900 (Black/Heavy)
|
TTF_WEIGHT_900 = 900 // Weight 900 (Black/Heavy)
|
||||||
} ttf_weight_t;
|
} ttf_weight_t;
|
||||||
|
|
||||||
typedef struct ttf_rect_s //// Bounding rectangle
|
typedef struct ttf_rect_s // Bounding rectangle
|
||||||
{
|
{
|
||||||
float left; // Left offset
|
float left; // Left offset
|
||||||
float top; // Top offset
|
float top; // Top offset
|
||||||
|
Reference in New Issue
Block a user