summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorscuri <scuri>2009-10-20 18:12:26 +0000
committerscuri <scuri>2009-10-20 18:12:26 +0000
commita972dbb9bd731a439d009bd51e36981c41a06232 (patch)
treee4e5d0aaf23706083dfb1fe4180e18f0907a90c9 /src
parent27a4f9c4ac45ff65f941964f7351b64b1e6a9f35 (diff)
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r--src/pdflib/flate/adler32.c4
-rw-r--r--src/pdflib/flate/compress.c4
-rw-r--r--src/pdflib/flate/crc32.c4
-rw-r--r--src/pdflib/flate/deflate.c11
-rw-r--r--src/pdflib/flate/deflate.h4
-rw-r--r--src/pdflib/flate/inffast.c2
-rw-r--r--src/pdflib/flate/inflate.c2
-rw-r--r--src/pdflib/flate/inftrees.c2
-rw-r--r--src/pdflib/flate/trees.c4
-rw-r--r--src/pdflib/flate/trees.h2
-rw-r--r--src/pdflib/flate/uncompr.c4
-rw-r--r--src/pdflib/flate/zconf.h4
-rw-r--r--src/pdflib/flate/zlib.h2
-rw-r--r--src/pdflib/flate/zprefix.h2
-rw-r--r--src/pdflib/flate/zutil.c4
-rw-r--r--src/pdflib/flate/zutil.h23
-rw-r--r--src/pdflib/font/ft_cid.c26
-rw-r--r--src/pdflib/font/ft_cid.h2
-rw-r--r--src/pdflib/font/ft_corefont.c2
-rw-r--r--src/pdflib/font/ft_corefont.h5
-rw-r--r--src/pdflib/font/ft_font.c52
-rw-r--r--src/pdflib/font/ft_font.h8
-rw-r--r--src/pdflib/font/ft_generr.h8
-rw-r--r--src/pdflib/font/ft_hostfont.c2
-rw-r--r--src/pdflib/font/ft_pdffont.c2
-rw-r--r--src/pdflib/font/ft_pdffont.h2
-rw-r--r--src/pdflib/font/ft_truetype.c287
-rw-r--r--src/pdflib/font/ft_truetype.h16
-rw-r--r--src/pdflib/font/ft_type1.c2
-rw-r--r--src/pdflib/pdcore/pc_chartabs.c85
-rw-r--r--src/pdflib/pdcore/pc_chartabs.h2
-rw-r--r--src/pdflib/pdcore/pc_classic.h2
-rw-r--r--src/pdflib/pdcore/pc_config.h133
-rw-r--r--src/pdflib/pdcore/pc_contain.c499
-rw-r--r--src/pdflib/pdcore/pc_contain.h81
-rw-r--r--src/pdflib/pdcore/pc_core.c95
-rw-r--r--src/pdflib/pdcore/pc_core.h50
-rw-r--r--src/pdflib/pdcore/pc_crypt.c2
-rw-r--r--src/pdflib/pdcore/pc_crypt.h2
-rw-r--r--src/pdflib/pdcore/pc_ctype.c159
-rw-r--r--src/pdflib/pdcore/pc_ctype.h149
-rw-r--r--src/pdflib/pdcore/pc_digsig.c2
-rw-r--r--src/pdflib/pdcore/pc_digsig.h2
-rw-r--r--src/pdflib/pdcore/pc_ebcdic.c122
-rw-r--r--src/pdflib/pdcore/pc_ebcdic.h17
-rw-r--r--src/pdflib/pdcore/pc_encoding.c76
-rw-r--r--src/pdflib/pdcore/pc_encoding.h4
-rw-r--r--src/pdflib/pdcore/pc_exports.h2
-rw-r--r--src/pdflib/pdcore/pc_file.c322
-rw-r--r--src/pdflib/pdcore/pc_file.h40
-rw-r--r--src/pdflib/pdcore/pc_generr.h45
-rw-r--r--src/pdflib/pdcore/pc_geom.c2
-rw-r--r--src/pdflib/pdcore/pc_geom.h2
-rw-r--r--src/pdflib/pdcore/pc_md5.c2
-rw-r--r--src/pdflib/pdcore/pc_md5.h2
-rw-r--r--src/pdflib/pdcore/pc_optparse.c165
-rw-r--r--src/pdflib/pdcore/pc_optparse.h70
-rw-r--r--src/pdflib/pdcore/pc_output.c176
-rw-r--r--src/pdflib/pdcore/pc_output.h94
-rw-r--r--src/pdflib/pdcore/pc_prefix.h3
-rw-r--r--src/pdflib/pdcore/pc_pstok.h2
-rw-r--r--src/pdflib/pdcore/pc_resource.c266
-rw-r--r--src/pdflib/pdcore/pc_resource.h40
-rw-r--r--src/pdflib/pdcore/pc_scan.c2
-rw-r--r--src/pdflib/pdcore/pc_scan.h2
-rw-r--r--src/pdflib/pdcore/pc_scantok.h2
-rw-r--r--src/pdflib/pdcore/pc_scope.c2
-rw-r--r--src/pdflib/pdcore/pc_scope.h2
-rw-r--r--src/pdflib/pdcore/pc_string.c6
-rw-r--r--src/pdflib/pdcore/pc_string.h2
-rw-r--r--src/pdflib/pdcore/pc_unicode.c194
-rw-r--r--src/pdflib/pdcore/pc_unicode.h34
-rw-r--r--src/pdflib/pdcore/pc_util.c924
-rw-r--r--src/pdflib/pdcore/pc_util.h39
-rw-r--r--src/pdflib/pdcore/pc_xmp.c23
-rw-r--r--src/pdflib/pdcore/pc_xmp.h8
76 files changed, 3226 insertions, 1221 deletions
diff --git a/src/pdflib/flate/adler32.c b/src/pdflib/flate/adler32.c
index 3f309ba..6db9124 100644
--- a/src/pdflib/flate/adler32.c
+++ b/src/pdflib/flate/adler32.c
@@ -3,8 +3,8 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* $Id: adler32.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
-/* @(#) $Id: adler32.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* $Id: adler32.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
+/* @(#) $Id: adler32.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
#define ZLIB_INTERNAL
#include "zlib.h"
diff --git a/src/pdflib/flate/compress.c b/src/pdflib/flate/compress.c
index 64dd6f3..a2ce19d 100644
--- a/src/pdflib/flate/compress.c
+++ b/src/pdflib/flate/compress.c
@@ -3,8 +3,8 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* $Id: compress.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
-/* @(#) $Id: compress.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* $Id: compress.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
+/* @(#) $Id: compress.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
#define ZLIB_INTERNAL
#include "zlib.h"
diff --git a/src/pdflib/flate/crc32.c b/src/pdflib/flate/crc32.c
index df92f90..682fa12 100644
--- a/src/pdflib/flate/crc32.c
+++ b/src/pdflib/flate/crc32.c
@@ -9,8 +9,8 @@
* factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
*/
-/* $Id: crc32.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
-/* @(#) $Id: crc32.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* $Id: crc32.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
+/* @(#) $Id: crc32.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
/*
Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
diff --git a/src/pdflib/flate/deflate.c b/src/pdflib/flate/deflate.c
index 5454e60..8a360ff 100644
--- a/src/pdflib/flate/deflate.c
+++ b/src/pdflib/flate/deflate.c
@@ -47,8 +47,8 @@
*
*/
-/* $Id: deflate.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
-/* @(#) $Id: deflate.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* $Id: deflate.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
+/* @(#) $Id: deflate.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
#include "deflate.h"
@@ -284,10 +284,13 @@ int ZEXPORT deflateInit2_(
s->hash_mask = s->hash_size - 1;
s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
- s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
+ /* PDFlib GmbH Bug #1707: increase the buffer size by 2x2 bytes to
+ * avoid problems with memory access beyond the end in the assembler code
+ */
+ s->window = (Bytef *) ZALLOC(strm, 2+s->w_size, 2*sizeof(Byte));
/* we don't use calloc -> to satisfy purify
* at least here memset is needed */
- memset((void *)s->window, 0, (size_t) s->w_size * 2*sizeof(Byte));
+ memset((void *)s->window, 0, (size_t) (2+s->w_size) * 2*sizeof(Byte));
s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
diff --git a/src/pdflib/flate/deflate.h b/src/pdflib/flate/deflate.h
index 36e0961..98babdb 100644
--- a/src/pdflib/flate/deflate.h
+++ b/src/pdflib/flate/deflate.h
@@ -9,9 +9,9 @@
*/
-/* $Id: deflate.h,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* $Id: deflate.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
-/* @(#) $Id: deflate.h,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* @(#) $Id: deflate.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
#ifndef DEFLATE_H
#define DEFLATE_H
diff --git a/src/pdflib/flate/inffast.c b/src/pdflib/flate/inffast.c
index c3d8a1d..c82a597 100644
--- a/src/pdflib/flate/inffast.c
+++ b/src/pdflib/flate/inffast.c
@@ -2,7 +2,7 @@
* Copyright (C) 1995-2004 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* $Id: inffast.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* $Id: inffast.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
#include "zutil.h"
#include "inftrees.h"
diff --git a/src/pdflib/flate/inflate.c b/src/pdflib/flate/inflate.c
index 87cd287..bbbc11b 100644
--- a/src/pdflib/flate/inflate.c
+++ b/src/pdflib/flate/inflate.c
@@ -79,7 +79,7 @@
*
* The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
*/
-/* $Id: inflate.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* $Id: inflate.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
#include "zutil.h"
#include "inftrees.h"
diff --git a/src/pdflib/flate/inftrees.c b/src/pdflib/flate/inftrees.c
index 0f67881..c780578 100644
--- a/src/pdflib/flate/inftrees.c
+++ b/src/pdflib/flate/inftrees.c
@@ -2,7 +2,7 @@
* Copyright (C) 1995-2005 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* $Id: inftrees.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* $Id: inftrees.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
#include "zutil.h"
#include "inftrees.h"
diff --git a/src/pdflib/flate/trees.c b/src/pdflib/flate/trees.c
index a885cd4..222a88e 100644
--- a/src/pdflib/flate/trees.c
+++ b/src/pdflib/flate/trees.c
@@ -29,8 +29,8 @@
* Addison-Wesley, 1983. ISBN 0-201-06672-6.
*/
-/* $Id: trees.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
-/* @(#) $Id: trees.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* $Id: trees.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
+/* @(#) $Id: trees.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
/* #define GEN_TREES_H */
diff --git a/src/pdflib/flate/trees.h b/src/pdflib/flate/trees.h
index 3669ef9..3235571 100644
--- a/src/pdflib/flate/trees.h
+++ b/src/pdflib/flate/trees.h
@@ -1,7 +1,7 @@
/* header created automatically with -DGEN_TREES_H */
-/* $Id: trees.h,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* $Id: trees.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
local const ct_data static_ltree[L_CODES+2] = {
{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
diff --git a/src/pdflib/flate/uncompr.c b/src/pdflib/flate/uncompr.c
index e01ad4b..1a3edfd 100644
--- a/src/pdflib/flate/uncompr.c
+++ b/src/pdflib/flate/uncompr.c
@@ -3,8 +3,8 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* $Id: uncompr.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
-/* @(#) $Id: uncompr.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* $Id: uncompr.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
+/* @(#) $Id: uncompr.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
#define ZLIB_INTERNAL
#include "zlib.h"
diff --git a/src/pdflib/flate/zconf.h b/src/pdflib/flate/zconf.h
index 1e664a8..98ec1da 100644
--- a/src/pdflib/flate/zconf.h
+++ b/src/pdflib/flate/zconf.h
@@ -4,8 +4,8 @@
*/
-/* $Id: zconf.h,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
-/* @(#) $Id: zconf.h,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* $Id: zconf.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
+/* @(#) $Id: zconf.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
#ifndef ZCONF_H
#define ZCONF_H
diff --git a/src/pdflib/flate/zlib.h b/src/pdflib/flate/zlib.h
index 977a8bd..d10a9f4 100644
--- a/src/pdflib/flate/zlib.h
+++ b/src/pdflib/flate/zlib.h
@@ -29,7 +29,7 @@
*/
-/* $Id: zlib.h,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* $Id: zlib.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
#ifndef ZLIB_H
#define ZLIB_H
diff --git a/src/pdflib/flate/zprefix.h b/src/pdflib/flate/zprefix.h
index ddac287..791b1da 100644
--- a/src/pdflib/flate/zprefix.h
+++ b/src/pdflib/flate/zprefix.h
@@ -1,4 +1,4 @@
-/* $Id: zprefix.h,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* $Id: zprefix.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
/*
* If you *really* need a unique prefix for all types and library functions,
diff --git a/src/pdflib/flate/zutil.c b/src/pdflib/flate/zutil.c
index 2fa45b3..b20aaa4 100644
--- a/src/pdflib/flate/zutil.c
+++ b/src/pdflib/flate/zutil.c
@@ -3,8 +3,8 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* $Id: zutil.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
-/* @(#) $Id: zutil.c,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* $Id: zutil.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
+/* @(#) $Id: zutil.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
#include "zutil.h"
diff --git a/src/pdflib/flate/zutil.h b/src/pdflib/flate/zutil.h
index 0db04c2..ea0fd6c 100644
--- a/src/pdflib/flate/zutil.h
+++ b/src/pdflib/flate/zutil.h
@@ -9,8 +9,8 @@
*/
-/* $Id: zutil.h,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
-/* @(#) $Id: zutil.h,v 1.1 2008/10/17 06:10:42 scuri Exp $ */
+/* $Id: zutil.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
+/* @(#) $Id: zutil.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
#ifndef ZUTIL_H
#define ZUTIL_H
@@ -175,6 +175,16 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# define F_OPEN(name, mode) fopen((name), (mode))
#endif
+/* PDFlib GmbH: we need this before redefining vsnprintf (Visuals Studio 2008)*/
+/* Diagnostic functions */
+#ifdef DEBUG
+# include <stdio.h>
+ extern int z_verbose;
+ extern void z_error OF((char *m));
+# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
+#else
+# define Assert(cond,msg)
+#endif
/* functions */
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
@@ -239,15 +249,6 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
extern void zmemzero OF((Bytef* dest, uInt len));
#endif
-/* Diagnostic functions */
-#ifdef DEBUG
-# include <stdio.h>
- extern int z_verbose;
- extern void z_error OF((char *m));
-# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
-#else
-# define Assert(cond,msg)
-#endif
/* PDFlib GmbH: we don't like trace messages from here. */
#if 0
diff --git a/src/pdflib/font/ft_cid.c b/src/pdflib/font/ft_cid.c
index aff9784..d1815fd 100644
--- a/src/pdflib/font/ft_cid.c
+++ b/src/pdflib/font/ft_cid.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: ft_cid.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: ft_cid.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* FONT CID functions
*
@@ -57,17 +57,17 @@ static const fnt_cmap_info fnt_predefined_cmaps[] =
{ "GBK-EUC-V", cc_simplified_chinese, 0, PDC_1_3, 2, 2, 2, 2, 1},
{ "GBKp-EUC-H", cc_simplified_chinese, 0, PDC_1_4, 0, 2, 2, 2, 0},
{ "GBKp-EUC-V", cc_simplified_chinese, 0, PDC_1_4, 0, 2, 2, 2, 1},
- { "GBK2K-H", cc_simplified_chinese, 0, PDC_1_4, 0, 4, 4, 4, 0},
- { "GBK2K-V", cc_simplified_chinese, 0, PDC_1_4, 0, 4, 4, 4, 1},
+ { "GBK2K-H", cc_simplified_chinese, 0, PDC_1_4, 0, 4, 4, 5, 0},
+ { "GBK2K-V", cc_simplified_chinese, 0, PDC_1_4, 0, 4, 4, 5, 1},
{ "UniGB-UCS2-H", cc_simplified_chinese, 2, PDC_1_3, 2, 4, 4, 4, 0},
{ "UniGB-UCS2-V", cc_simplified_chinese, 2, PDC_1_3, 2, 4, 4, 4, 1},
- { "UniGB-UTF16-H", cc_simplified_chinese, 2, PDC_1_5, 0, 0, 4, 4, 0},
- { "UniGB-UTF16-V", cc_simplified_chinese, 2, PDC_1_5, 0, 0, 4, 4, 1},
+ { "UniGB-UTF16-H", cc_simplified_chinese, 2, PDC_1_5, 0, 0, 4, 5, 0},
+ { "UniGB-UTF16-V", cc_simplified_chinese, 2, PDC_1_5, 0, 0, 4, 5, 1},
{ "B5pc-H", cc_traditional_chinese, 0, PDC_1_3, 0, 0, 0, 0, 0},
{ "B5pc-V", cc_traditional_chinese, 0, PDC_1_3, 0, 0, 0, 0, 1},
- { "HKscs-B5-H", cc_traditional_chinese, 0, PDC_1_4, 0, 3, 3, 3, 0},
- { "HKscs-B5-V", cc_traditional_chinese, 0, PDC_1_4, 0, 3, 3, 3, 1},
+ { "HKscs-B5-H", cc_traditional_chinese, 0, PDC_1_4, 0, 3, 3, 5, 0},
+ { "HKscs-B5-V", cc_traditional_chinese, 0, PDC_1_4, 0, 3, 3, 5, 1},
{ "ETen-B5-H", cc_traditional_chinese, 0, PDC_1_3, 0, 0, 0, 0, 0},
{ "ETen-B5-V", cc_traditional_chinese, 0, PDC_1_3, 0, 0, 0, 0, 1},
{ "ETenms-B5-H", cc_traditional_chinese, 0, PDC_1_3, 0, 0, 0, 0, 0},
@@ -94,7 +94,7 @@ static const fnt_cmap_info fnt_predefined_cmaps[] =
{ "Identity-H", cc_identity, 0, PDC_1_3, 0, 0, 0, 0, 0},
{ "Identity-V", cc_identity, 0, PDC_1_3, 0, 0, 0, 0, 1},
- { NULL, 0, 0, 0, 0, 0, 0, 0, 0},
+ { NULL, cc_none, 0, 0, 0, 0, 0, 0, 0},
};
static int
@@ -246,8 +246,11 @@ fnt_get_maxcid(int charcoll, int supplement)
return 22352;
case 4:
- default:
return 29063;
+
+ case 5:
+ default:
+ return 30283;
}
case cc_traditional_chinese:
@@ -266,8 +269,11 @@ fnt_get_maxcid(int charcoll, int supplement)
return 18845;
case 4:
- default:
return 18964;
+
+ case 5:
+ default:
+ return 19087;
}
case cc_korean:
diff --git a/src/pdflib/font/ft_cid.h b/src/pdflib/font/ft_cid.h
index 12187cb..db3d5d9 100644
--- a/src/pdflib/font/ft_cid.h
+++ b/src/pdflib/font/ft_cid.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: ft_cid.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: ft_cid.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* CID data structures
*
diff --git a/src/pdflib/font/ft_corefont.c b/src/pdflib/font/ft_corefont.c
index b368f67..cf9dd15 100644
--- a/src/pdflib/font/ft_corefont.c
+++ b/src/pdflib/font/ft_corefont.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: ft_corefont.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: ft_corefont.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* FONT in-core and basic font metric functions
*
diff --git a/src/pdflib/font/ft_corefont.h b/src/pdflib/font/ft_corefont.h
index 526212e..cfc658b 100644
--- a/src/pdflib/font/ft_corefont.h
+++ b/src/pdflib/font/ft_corefont.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: ft_corefont.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: ft_corefont.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* This file contains the metric for the base and
* pre-installed CID fonts of PDF
@@ -2617,7 +2617,8 @@ static const char *fnt_cid_width_arrays[] =
"814 939 500\n"
"7712[517 684 723]\n"
"7716[500]\n"
- "22353[462 462 500 500 500]\n",
+ "22353[462 462 500 500 500]\n"
+ "29064 30283 550\n",
/*------------------------------------------------------------------------*/
diff --git a/src/pdflib/font/ft_font.c b/src/pdflib/font/ft_font.c
index 53a39a9..58f1cf6 100644
--- a/src/pdflib/font/ft_font.c
+++ b/src/pdflib/font/ft_font.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: ft_font.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: ft_font.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* FONT basic font functions
*
@@ -393,10 +393,11 @@ pdc_encodingvector *
fnt_create_font_ev(pdc_core *pdc, fnt_font *font)
{
pdc_encodingvector *ev = NULL;
- char encname[128];
+ char encname[PDC_GEN_BUFSIZE];
pdc->uniqueno++;
- sprintf(encname, "encoding_%s_%d", font->name, pdc->uniqueno);
+ pdc_sprintf(pdc, pdc_false, encname, "encoding_%s_%d",
+ font->name, pdc->uniqueno);
ev = pdc_new_encoding(pdc, encname);
pdc_insert_encoding_vector(pdc, ev);
font->enc = pdc_find_encoding(pdc, encname);
@@ -424,24 +425,35 @@ fnt_check_weight(int weight)
static const pdc_keyconn fnt_fontweight_keylist[] =
{
- {"none", FNT_FW_DONTCARE},
- {"thin", FNT_FW_THIN},
- {"extralight", FNT_FW_EXTRALIGHT},
- {"ultralight", FNT_FW_ULTRALIGHT},
- {"light", FNT_FW_LIGHT},
- {"normal", FNT_FW_NORMAL},
- {"regular", FNT_FW_REGULAR},
+ {"None", FNT_FW_DONTCARE},
+ {"Thin", FNT_FW_THIN},
+ {"Extralight", FNT_FW_EXTRALIGHT},
+ {"Ultralight", FNT_FW_ULTRALIGHT},
+ {"Light", FNT_FW_LIGHT},
+ {"Normal", FNT_FW_NORMAL},
+ {"Regular", FNT_FW_REGULAR},
{"", FNT_FW_REGULAR},
- {"medium", FNT_FW_MEDIUM},
- {"semibold", FNT_FW_SEMIBOLD},
- {"semi", FNT_FW_SEMIBOLD},
- {"demibold", FNT_FW_DEMIBOLD},
- {"bold", FNT_FW_BOLD},
- {"extrabold", FNT_FW_EXTRABOLD},
- {"extra", FNT_FW_EXTRABOLD},
- {"ultrabold", FNT_FW_ULTRABOLD},
- {"heavy", FNT_FW_HEAVY},
- {"black", FNT_FW_BLACK},
+ {"Medium", FNT_FW_MEDIUM},
+ {"Semibold", FNT_FW_SEMIBOLD},
+ {"Semi", FNT_FW_SEMIBOLD},
+ {"Demibold", FNT_FW_DEMIBOLD},
+ {"Bold", FNT_FW_BOLD},
+ {"Extrabold", FNT_FW_EXTRABOLD},
+ {"Extra", FNT_FW_EXTRABOLD},
+ {"Ultrabold", FNT_FW_ULTRABOLD},
+ {"Heavy", FNT_FW_HEAVY},
+ {"Black", FNT_FW_BLACK},
+ {"0", FNT_FW_DONTCARE},
+ {"100", FNT_FW_THIN},
+ {"200", FNT_FW_EXTRALIGHT},
+ {"300", FNT_FW_LIGHT},
+ {"400", FNT_FW_NORMAL},
+ {"500", FNT_FW_MEDIUM},
+ {"600", FNT_FW_SEMIBOLD},
+ {"700", FNT_FW_BOLD},
+ {"800", FNT_FW_EXTRABOLD},
+ {"900", FNT_FW_BLACK},
+
{NULL, 0}
};
diff --git a/src/pdflib/font/ft_font.h b/src/pdflib/font/ft_font.h
index 34f2a0b..73da0e6 100644
--- a/src/pdflib/font/ft_font.h
+++ b/src/pdflib/font/ft_font.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: ft_font.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: ft_font.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Header file for font handling
*
@@ -77,12 +77,18 @@
#define FNT_SMALLCAPS (long) (1L<<17)
#define FNT_FORCEBOLD (long) (1L<<18)
+#define FNT_FI_ITALIC 255
+#define FNT_FI_ITALICNAME "Italic"
#define FNT_DEF_ITALICANGLE -12 /* default italic angle */
+
#define FNT_MISSING_FONTVAL PDC_SHRT_MIN /* missing font value */
/* start sequence of PFA files */
#define FNT_PFA_STARTSEQU "%!PS"
+/* missing file name for font outline data */
+#define FNT_MISSING_FILENAME "__missing__filename__"
+
/* Font types */
typedef enum
{
diff --git a/src/pdflib/font/ft_generr.h b/src/pdflib/font/ft_generr.h
index 909596b..be9a4fc 100644
--- a/src/pdflib/font/ft_generr.h
+++ b/src/pdflib/font/ft_generr.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: ft_generr.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: ft_generr.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* FONT error messages
*
@@ -38,9 +38,13 @@ gen(1, 7001, FONT_PREFIX, "Font '$1': ")
gen(0, 7002, FONT_HOSTNOTFOUND, "Host font not found")
+gen(0, 7003, FONT_HOSTNOTFOUND2,
+ "Host font not found (maybe unsupported QuickDraw font name specified)")
+
gen(1, 7004, FONT_UNSUPP_FORMAT, "Font format '$1' not supported")
-gen(0, 7006, FONT_TTHOSTNOTFOUND, "TrueType host font not found")
+gen(2, 7006, FONT_HOSTNOTLOADED,
+ "Couldn't load $1 host font (system error code $2)")
gen(1, 7007, FONT_NAMETOOLONG,
"Font name too long (max. $1 characters)")
diff --git a/src/pdflib/font/ft_hostfont.c b/src/pdflib/font/ft_hostfont.c
index ec9411d..7f8970a 100644
--- a/src/pdflib/font/ft_hostfont.c
+++ b/src/pdflib/font/ft_hostfont.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: ft_hostfont.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: ft_hostfont.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* FONT host font handling routines for Windows and Mac
*
diff --git a/src/pdflib/font/ft_pdffont.c b/src/pdflib/font/ft_pdffont.c
index 0767d74..278e1ba 100644
--- a/src/pdflib/font/ft_pdffont.c
+++ b/src/pdflib/font/ft_pdffont.c
@@ -6,7 +6,7 @@
| Proprietary source code -- do not redistribute! |
*---------------------------------------------------------------------------*/
-/* $Id: ft_pdffont.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: ft_pdffont.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Routine for parsing font dictionaries in PDF files by pCOS
*
diff --git a/src/pdflib/font/ft_pdffont.h b/src/pdflib/font/ft_pdffont.h
index bb40cbc..c0c5b7a 100644
--- a/src/pdflib/font/ft_pdffont.h
+++ b/src/pdflib/font/ft_pdffont.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: ft_pdffont.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: ft_pdffont.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Header file for parsing font dictionaries in PDF files
*
diff --git a/src/pdflib/font/ft_truetype.c b/src/pdflib/font/ft_truetype.c
index b4e33a6..8aa437c 100644
--- a/src/pdflib/font/ft_truetype.c
+++ b/src/pdflib/font/ft_truetype.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: ft_truetype.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: ft_truetype.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* FONT TrueType handling routines
*
@@ -198,14 +198,13 @@ tt_get_offset(tt_file *ttf, tt_byte offsize)
static void
tt_get_dirent(tt_dirent *dirent, tt_file *ttf)
{
- tt_read(ttf, dirent->tag, 4);
- dirent->tag[4] = 0;
+ tt_read(ttf, dirent->tag, TT_TABTAG_SIZE);
+ dirent->tag[TT_TABTAG_SIZE] = 0;
dirent->checksum = tt_get_ulong(ttf);
dirent->offset = tt_get_ulong(ttf);
dirent->length = tt_get_ulong(ttf);
} /* tt_get_dirent */
-
int
tt_tag2idx(tt_file *ttf, char *tag)
{
@@ -233,6 +232,10 @@ tt_get_tab(tt_file *ttf, char *tag, size_t nbytes, pdc_bool tterror,
return NULL;
}
+ pdc_logg_cond(pdc, 3, trc_font,
+ "\t\treading table \"%s\" (offset=0x%05X, length=%d)\n",
+ tag, ttf->dir[idx].offset, ttf->dir[idx].length);
+
tt_seek(ttf, (long) ttf->dir[idx].offset);
if (offset)
@@ -298,6 +301,28 @@ tt_get_cmap6(tt_file *ttf, tt_cmap0_6 *cm0_6)
} /* tt_get_cmap6 */
static void
+tt_cleanup_cmap4(tt_file *ttf, tt_cmap4 *cm4)
+{
+ pdc_core *pdc = ttf->pdc;
+
+ if (cm4 != (tt_cmap4 *) 0)
+ {
+ if (cm4->endCount != (tt_ushort *) 0)
+ pdc_free(pdc, cm4->endCount);
+ if (cm4->startCount != (tt_ushort *) 0)
+ pdc_free(pdc, cm4->startCount);
+ if (cm4->idDelta != (tt_short *) 0)
+ pdc_free(pdc, cm4->idDelta);
+ if (cm4->idRangeOffs != (tt_ushort *) 0)
+ pdc_free(pdc, cm4->idRangeOffs);
+ if (cm4->glyphIdArray != (tt_ushort *) 0)
+ pdc_free(pdc, cm4->glyphIdArray);
+
+ pdc_free(pdc, cm4);
+ }
+}
+
+static tt_cmap4 *
tt_get_cmap4(tt_file *ttf, tt_cmap4 *cm4)
{
static const char *fn = "tt_get_cmap4";
@@ -321,63 +346,57 @@ tt_get_cmap4(tt_file *ttf, tt_cmap4 *cm4)
segs = cm4->segCountX2 / 2;
- cm4->numGlyphIds = (tt_ushort)(
- ((cm4->length - ( 16L + 8L * segs )) & 0xFFFFU) / 2);
+ if (segs >= 1)
+ {
+ cm4->numGlyphIds = (tt_ushort)(
+ ((cm4->length - ( 16L + 8L * segs )) & 0xFFFFU) / 2);
- TT_IOCHECK(ttf, 0 <= cm4->numGlyphIds);
+ TT_IOCHECK(ttf, 0 <= cm4->numGlyphIds);
- cm4->endCount =
- (tt_ushort *)
- pdc_malloc(pdc, (size_t) (sizeof (tt_ushort) * segs), fn);
- cm4->startCount =
- (tt_ushort *)
- pdc_malloc(pdc, (size_t) (sizeof (tt_ushort) * segs), fn);
- cm4->idDelta =
- (tt_short *)
- pdc_malloc(pdc, (size_t) (sizeof (tt_ushort) * segs), fn);
- cm4->idRangeOffs =
- (tt_ushort *)
- pdc_malloc(pdc, (size_t) (sizeof (tt_ushort) * segs), fn);
+ cm4->endCount =
+ (tt_ushort *)
+ pdc_malloc(pdc, (size_t) (sizeof (tt_ushort) * segs), fn);
+ cm4->startCount =
+ (tt_ushort *)
+ pdc_malloc(pdc, (size_t) (sizeof (tt_ushort) * segs), fn);
+ cm4->idDelta =
+ (tt_short *)
+ pdc_malloc(pdc, (size_t) (sizeof (tt_ushort) * segs), fn);
+ cm4->idRangeOffs =
+ (tt_ushort *)
+ pdc_malloc(pdc, (size_t) (sizeof (tt_ushort) * segs), fn);
- if (cm4->numGlyphIds)
- {
- cm4->glyphIdArray = (tt_ushort *)
- pdc_malloc(pdc,
- (size_t) (sizeof (tt_ushort) * cm4->numGlyphIds), fn);
- }
+ if (cm4->numGlyphIds)
+ {
+ cm4->glyphIdArray = (tt_ushort *)
+ pdc_malloc(pdc,
+ (size_t) (sizeof (tt_ushort) * cm4->numGlyphIds), fn);
+ }
- for (i = 0; i < segs; ++i)
- cm4->endCount[i] = tt_get_ushort(ttf);
+ for (i = 0; i < segs; ++i)
+ cm4->endCount[i] = tt_get_ushort(ttf);
- TT_IOCHECK(ttf, cm4->endCount[segs - 1] == 0xFFFF);
+ TT_IOCHECK(ttf, cm4->endCount[segs - 1] == 0xFFFF);
- (void) tt_get_ushort(ttf); /* padding */
- for (i = 0; i < segs; ++i) cm4->startCount[i] = tt_get_ushort(ttf);
- for (i = 0; i < segs; ++i) cm4->idDelta[i] = tt_get_short(ttf);
- for (i = 0; i < segs; ++i) cm4->idRangeOffs[i] = tt_get_ushort(ttf);
+ (void) tt_get_ushort(ttf); /* padding */
+ for (i = 0; i < segs; ++i) cm4->startCount[i] = tt_get_ushort(ttf);
+ for (i = 0; i < segs; ++i) cm4->idDelta[i] = tt_get_short(ttf);
+ for (i = 0; i < segs; ++i) cm4->idRangeOffs[i] = tt_get_ushort(ttf);
- for (i = 0; i < cm4->numGlyphIds; ++i)
- cm4->glyphIdArray[i] = tt_get_ushort(ttf);
+ for (i = 0; i < cm4->numGlyphIds; ++i)
+ cm4->glyphIdArray[i] = tt_get_ushort(ttf);
+ }
/* empty cmap */
- if (segs == 1 && cm4->endCount[0] == cm4->startCount[0])
- {
- cm4->segCountX2 = 0;
- pdc_free(pdc, cm4->endCount);
- cm4->endCount = (tt_ushort *) 0;
- pdc_free(pdc, cm4->startCount);
- cm4->startCount = (tt_ushort *) 0;
- pdc_free(pdc, cm4->idDelta);
- cm4->idDelta = (tt_short *) 0;
- pdc_free(pdc, cm4->idRangeOffs);
- cm4->idRangeOffs = (tt_ushort *) 0;
- if (cm4->numGlyphIds)
- {
- pdc_free(pdc, cm4->glyphIdArray);
- cm4->glyphIdArray = (tt_ushort *) 0;
- }
+ if (segs == 0 || (segs == 1 && cm4->endCount[0] == cm4->startCount[0]))
+ {
+ tt_cleanup_cmap4(ttf, cm4);
+
+ cm4 = (tt_cmap4 *) 0;
}
+ return cm4;
+
} /* tt_get_cmap4 */
@@ -452,6 +471,8 @@ tt_get_tab_cmap(tt_file *ttf)
pdc_malloc(pdc, sizeof (tt_cmap0_6), fn);
tp->mac->format = 0;
tt_get_cmap0(ttf, tp->mac);
+
+ offset_mac = offsetEncTab;
}
else if (tableFormat == 6 && tp->mac == (tt_cmap0_6 *) 0)
{
@@ -459,53 +480,67 @@ tt_get_tab_cmap(tt_file *ttf)
pdc_malloc(pdc, sizeof (tt_cmap0_6), fn);
tp->mac->format = 6;
tt_get_cmap6(ttf, tp->mac);
+
+ offset_mac = offsetEncTab;
}
- offset_mac = offsetEncTab;
+ else if (numEncTabs == 1 && tableFormat == 4)
+ {
+ /* simulating Windows */
+ tp->win = (tt_cmap4 *) pdc_malloc(pdc, sizeof (tt_cmap4), fn);
+ tp->win->format = tableFormat;
+ tp->win->encodingID = encodingID;
+ tp->win = tt_get_cmap4(ttf, tp->win);
+
+ /* cmap picking not necessary */
+ }
}
/*
- * platformID: 0 encodingID: 3 tableFormat: 4 (old mac)
- * platformID: 3 encodingID: 0/1 tableFormat: 4
+ * platformID: 0 encodingID: 3 tableFormat: 4 (old mac)
+ * platformID: 3 encodingID: 0/1/4 tableFormat: 4 preferred!
*/
- else if ((tp->win == (tt_cmap4 *) 0 && tableFormat == 4) &&
+ else if (tableFormat == 4 &&
((platformID == tt_pfid_win &&
(encodingID == tt_wenc_symbol ||
- encodingID == tt_wenc_text)) ||
+ encodingID == tt_wenc_text ||
+ encodingID == tt_wenc_big5)) ||
(platformID == tt_pfid_uni &&
encodingID == tt_wenc_mtext)))
{
- tp->win = (tt_cmap4 *) pdc_malloc(pdc, sizeof (tt_cmap4), fn);
- tp->win->format = tableFormat;
-
- /* we suppose a windows platform (see old mac hostfont Times) */
- if (encodingID == tt_wenc_mtext)
+ if (tp->win == (tt_cmap4 *) 0 ||
+ (tp->win != (tt_cmap4 *) 0 &&
+ ((tp->win->encodingID == tt_wenc_mtext ||
+ tp->win->encodingID == tt_wenc_big5) &&
+ encodingID < tt_wenc_mtext)))
{
- encodingID = tt_wenc_text;
- }
-
- tt_get_cmap4(ttf, tp->win);
+ if (tp->win != (tt_cmap4 *) 0)
+ tt_cleanup_cmap4(ttf, tp->win);
+ tp->win = (tt_cmap4 *) pdc_malloc(pdc, sizeof (tt_cmap4), fn);
- if (tp->win->segCountX2)
- {
+ tp->win->format = tableFormat;
tp->win->encodingID = encodingID;
+ tp->win = tt_get_cmap4(ttf, tp->win);
+
+ if (tp->win != (tt_cmap4 *) 0)
+ offset_win = offsetEncTab;
}
- else
- {
- pdc_free(pdc, tp->win);
- tp->win = (tt_cmap4 *) 0;
- }
- offset_win = offsetEncTab;
}
tt_seek(ttf, pos);
} /* for */
+ /* we suppose a windows platform (see old mac hostfont Times) */
+ if (tp->win && tp->win->encodingID == tt_wenc_mtext)
+ {
+ encodingID = tt_wenc_text;
+ }
+
/* is symbol font */
ttf->issymbol = (tp->win && tp->win->encodingID == tt_wenc_symbol) ?
pdc_true : pdc_false;
- /* has Unicode cmap */
+ /* has Unicode/CMap cmap */
ttf->haswinuni = (!ttf->issymbol && (tp->win || tp->ucs4)) ?
pdc_true : pdc_false;
@@ -540,6 +575,7 @@ tt_get_tab_cmap(tt_file *ttf)
}
else
{
+ ttf->hasbig5cmap = tp->win->encodingID == tt_wenc_big5;
tp->encoding = tt_wenc_text;
tp->format = tp->win->format;
tp->offset = offset_win;
@@ -553,12 +589,16 @@ tt_get_tab_cmap(tt_file *ttf)
tp->platform, tp->encoding, tp->format,
ttf->issymbol ? "symbol" : "text");
+ if (ttf->hasbig5cmap)
+ pdc_logg_cond(ttf->pdc, 1, trc_font, "\t\tCID font with Big5 cmap\n");
+
/* for subsetting and symbolic font:
* tp->platform = tt_pfid_mac according PDF specification
* otherwise GS will emit an error message
*/
if (ttf->issymbol && offset_mac > 0)
{
+ ttf->forcesubset = !ttf->hasonlymac;
tp->platform = tt_pfid_mac;
tp->encoding = tt_wenc_symbol;
tp->format = tp->mac->format;
@@ -600,7 +640,7 @@ tt_get_tab_head(tt_file *ttf)
tp->glyphDataFormat = tt_get_short(ttf);
} /* tt_get_tab_head */
-static void
+void
tt_get_tab_hhea(tt_file *ttf)
{
tt_tab_hhea *tp = NULL;
@@ -764,7 +804,6 @@ tt_get_tab_name(tt_file *ttf)
tp->englishname4 = NULL;
tp->englishname6 = NULL;
tp->producer = NULL;
-
tp->format = tt_get_ushort(ttf);
/* Format 0 is the only document one, but some Apple fonts use 65535.
@@ -782,6 +821,13 @@ tt_get_tab_name(tt_file *ttf)
"\tRecords in name table of format %d: %d:\n",
tp->format, tp->numNameRecords);
+ if (ttf->utf16fontname != NULL)
+ {
+ pdc_logg_cond(pdc, 1, trc_font,
+ "\tSearching for a host font with Unicode name \"%T\"\n",
+ ttf->utf16fontname, ttf->fnamelen);
+ }
+
/* this was observed. we ignore it in TET */
if (ttf->fortet && tp->numNameRecords == 0)
return pdc_true;
@@ -865,7 +911,7 @@ tt_get_tab_name(tt_file *ttf)
if (namerec->length && namerec->namid == namid)
{
/* TTC font search */
- if (ttf->utf16fontname)
+ if (ttf->utf16fontname != NULL)
{
/* read font name */
if (localname == NULL)
@@ -925,7 +971,7 @@ tt_get_tab_name(tt_file *ttf)
}
/* TTC font not found */
- if (ttf->utf16fontname)
+ if (ttf->utf16fontname != NULL)
return pdc_false;
/* English font names */
@@ -1018,6 +1064,7 @@ void
tt_get_tab_OS_2(tt_file *ttf)
{
pdc_bool logg3 = pdc_logg_is_enabled(ttf->pdc, 3, trc_font);
+ pdc_bool logg5 = pdc_logg_is_enabled(ttf->pdc, 5, trc_font);
int i, j;
tt_tab_OS_2 *tp = NULL;
@@ -1077,7 +1124,8 @@ tt_get_tab_OS_2(tt_file *ttf)
for (i = 0; i < PDC_NUMCHARCOLL; i++)
{
j = i + 17;
- if (tp->ulCodePageRange1 & (1<<j))
+ if (tp->ulCodePageRange1 & (1<<j) || (ttf->hasbig5cmap &&
+ tt_cpflag2charcoll[i] == cc_traditional_chinese))
tp->charcolls[i] = tt_cpflag2charcoll[i];
else
tp->charcolls[i] = cc_none;
@@ -1100,6 +1148,15 @@ tt_get_tab_OS_2(tt_file *ttf)
tp->usMaxContext = 0;
}
+ if (logg5)
+ {
+ pdc_logg(ttf->pdc, "\t\t\tusFirstCharIndex=0x%04X\n",
+ ttf->tab_OS_2->usFirstCharIndex);
+ if (ttf->tab_cmap && ttf->tab_cmap->win)
+ pdc_logg(ttf->pdc, "\t\t\tstartCount[0]=0x%04X\n",
+ ttf->tab_cmap->win->startCount[0]);
+ }
+
/* there are fonts with inconsistent usFirstCharIndex */
if (ttf->tab_cmap && ttf->tab_cmap->win &&
tp->usFirstCharIndex != ttf->tab_cmap->win->startCount[0])
@@ -1191,7 +1248,12 @@ tt_get_tab_post(tt_file *ttf)
tp->maxMemType42 = tt_get_ulong(ttf);
tp->minMemType1 = tt_get_ulong(ttf);
tp->maxMemType1 = tt_get_ulong(ttf);
+ tp->numberOfGlyphs = ttf->numGlyphs;
+ /* there are subset fonts with different number of glyphs
+ * see bug #1418
+ */
+ ttf->numGlyphs = MAX(tp->numberOfGlyphs, ttf->numGlyphs);
} /* tt_get_tab_post */
@@ -1279,6 +1341,7 @@ fnt_test_tt_font(pdc_core *pdc, tt_byte *img, tt_ulong *n_fonts,
return pdc_true;
}
+
pdc_bool
fnt_is_opentype_font(tt_file *ttf)
{
@@ -1387,22 +1450,43 @@ tt_unicode2gidx(tt_file *ttf, int usv, pdc_bool logg)
pdc_core *pdc = ttf->pdc;
tt_cmap4 *cm4 = ttf->tab_cmap->win;
pdc_ushort uv;
- int segs;
- int gidx = 0;
- int i;
+ int lo, hi, segs;
+ int gidx = 0, i = 0;
uv = (pdc_ushort) usv;
- if (logg) pdc_logg(pdc, "\t\t\tU+%04X: ", uv);
+ if (logg) pdc_logg(pdc, "\t\t\tUCS2: %04X: ", uv);
segs = cm4->segCountX2 / 2;
- for (i = 0; i < segs; ++i)
+ lo = 0;
+ hi = segs;
+ while (lo < hi)
+ {
+ i = (lo + hi) / 2;
+
if (uv <= cm4->endCount[i])
- break;
+ {
+ if (uv >= cm4->startCount[i])
+ {
+ break;
+ }
+ else if (!i || uv > cm4->endCount[i - 1])
+ {
+ i = -1;
+ break;
+ }
+ }
+
+ if (uv < cm4->startCount[i])
+ hi = i;
+ else
+ lo = i + 1;
+ }
- if (logg) pdc_logg(pdc, "i=%d start=U+%04X ", i, cm4->startCount[i]);
+
+ if (logg) pdc_logg(pdc, "i=%d start=UCS2: %04X ", i, cm4->startCount[i]);
TT_IOCHECK(ttf, i != segs);
- if (uv < cm4->startCount[i] || uv == 0xFFFF)
+ if (i == -1 || uv == 0xFFFF)
{
if (logg) pdc_logg(pdc, "==> gidx=0\n");
return 0;
@@ -1478,12 +1562,16 @@ tt_gidx2width(tt_file *ttf, int gidx)
void
fnt_set_tt_fontvalues(tt_file *ttf)
{
+ pdc_bool logg3 = pdc_logg_is_enabled(ttf->pdc, 3, trc_font);
fnt_font *font = ttf->font;
fnt_font_metric *ftm = &font->m;
if (ttf->onlyCFF)
return;
+ if (logg3)
+ pdc_logg(ttf->pdc, "\tUnits per EM: %d\n", ttf->tab_head->unitsPerEm);
+
if (ttf->tab_head)
{
ftm->llx = FNT_TT2PDF(ttf->tab_head->xMin);
@@ -1601,6 +1689,9 @@ fnt_set_tt_fontarrays(tt_file *ttf, int flags)
** like that; perhaps we have to apply similar tricks then...
*/
uvoffset = (ttf->tab_OS_2->usFirstCharIndex & 0xFF00);
+
+ if (logg5)
+ pdc_logg(pdc, "\t\tuvoffset=0x%04X\n", uvoffset);
}
else
{
@@ -2140,6 +2231,8 @@ fnt_check_tt_font(pdc_core *pdc, const char *filename, const char *fontname,
* ttf->verbose = pdc_false;
* ttf->kerning = pdc_true;
* ttf->vertical = pdc_true;
+ * ttf->ignorename = pdc_true;
+ * ttf->cmst = ~NULL;
* ttf->fortet = pdc_true;
*
* ttf->check = pdc_true;
@@ -2201,6 +2294,9 @@ fnt_new_tt(pdc_core *pdc, fnt_font *font)
ttf->issymbol = pdc_false;
ttf->haswinuni = pdc_false;
ttf->hasonlymac = pdc_false;
+ ttf->hasbig5cmap = pdc_false;
+ ttf->forcesubset = pdc_false;
+ ttf->gidunequcid = pdc_false;
ttf->utf16fontname = (char *) 0;
@@ -2214,9 +2310,6 @@ void
fnt_delete_tt(tt_file *ttf)
{
pdc_core *pdc = ttf->pdc;
- int i;
-
- (void) i;
if (ttf->check == pdc_false && ttf->fp != (pdc_file *) 0)
pdc_fclose(ttf->fp);
@@ -2243,24 +2336,14 @@ fnt_delete_tt(tt_file *ttf)
if (ttf->tab_cmap != (tt_tab_cmap *) 0)
{
- if (ttf->tab_cmap->mac != (tt_cmap0_6 *) 0) {
+ if (ttf->tab_cmap->mac != (tt_cmap0_6 *) 0)
+ {
if (ttf->tab_cmap->mac->glyphIdArray)
pdc_free(pdc, ttf->tab_cmap->mac->glyphIdArray);
pdc_free(pdc, ttf->tab_cmap->mac);
}
- if (ttf->tab_cmap->win != (tt_cmap4 *) 0)
- {
- tt_cmap4 *cm4 = (tt_cmap4 *) ttf->tab_cmap->win;
-
- if (cm4->endCount != 0) pdc_free(pdc, cm4->endCount);
- if (cm4->startCount != 0) pdc_free(pdc, cm4->startCount);
- if (cm4->idDelta != 0) pdc_free(pdc, cm4->idDelta);
- if (cm4->idRangeOffs != 0) pdc_free(pdc, cm4->idRangeOffs);
- if (cm4->glyphIdArray != 0) pdc_free(pdc, cm4->glyphIdArray);
-
- pdc_free(pdc, cm4);
- }
+ tt_cleanup_cmap4(ttf, ttf->tab_cmap->win);
if (ttf->tab_cmap->ucs4 != (tt_cmap12 *) 0)
{
diff --git a/src/pdflib/font/ft_truetype.h b/src/pdflib/font/ft_truetype.h
index 89cd3fb..eda7513 100644
--- a/src/pdflib/font/ft_truetype.h
+++ b/src/pdflib/font/ft_truetype.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: ft_truetype.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: ft_truetype.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* FONT TrueType typedefs, structures, and enums
*
@@ -44,6 +44,7 @@ typedef unsigned short tt_ufword;
#define TT_NUMEXPSTRINGS 379
#define TT_NUMEXPERTGIDS 166
+#define TT_TABTAG_SIZE 4
#define TT_OFFSETTAB_SIZE 12
/* flags for fnt_set_tt_fontarrays */
@@ -55,6 +56,7 @@ typedef unsigned short tt_ufword;
#define TT_FONT_m_widths (1<<5)
#define TT_FONT_names (1<<6)
#define TT_FONT_name2unitab (1<<7)
+#define TT_FONT_gid2cid (1<<8)
typedef enum
{
@@ -124,7 +126,7 @@ tt_cff_oper;
typedef struct
{
- char tag[5];
+ char tag[TT_TABTAG_SIZE + 1];
tt_ulong checksum;
tt_ulong offset;
tt_ulong length;
@@ -143,7 +145,9 @@ typedef enum
{
tt_wenc_symbol = 0,
tt_wenc_text = 1,
+ tt_wenc_sjis = 2,
tt_wenc_mtext = 3,
+ tt_wenc_big5 = 4,
tt_wenc_utext = 10
} tt_win_encoding_id;
@@ -457,10 +461,13 @@ typedef struct
pdc_bool issymbol; /* symbol font */
pdc_bool haswinuni; /* has a "Microsoft standard character
* to glyph index mapping table"
- * cmap (3, 1) format 4 or
+ * cmap (3, 1, 4) format 4 or
* cmap (3,10) format 12 or
* cmap (0, 3) format 4 (mac old case) */
pdc_bool hasonlymac; /* has only macroman cmap (0,1) */
+ pdc_bool hasbig5cmap; /* has Big5 cmap cmap (3,4) */
+ pdc_bool forcesubset; /* subset will be forced to set unique cmap */
+ pdc_bool gidunequcid; /* GID != SID */
char *utf16fontname; /* UTF-16-BE font name for TTC fonts */
int fnamelen; /* font name length */
@@ -508,6 +515,7 @@ typedef struct
/* Functions */
#define FNT_TT2PDF(v) (int) PDC_ROUND(v * 1000.0 / ttf->tab_head->unitsPerEm)
+#define FNT_PDF2TT(v) (int) (v * ttf->tab_head->unitsPerEm / 1000.0)
#define TT_ASSERT(ttf, cond) \
((cond) ? (void) 0 : tt_assert(ttf))
@@ -520,6 +528,7 @@ void *tt_get_tab(tt_file *ttf, char *tag, size_t nbytes, pdc_bool tterror,
tt_ulong *offset);
void tt_get_tab_maxp(tt_file *ttf);
void tt_get_tab_head(tt_file *ttf);
+void tt_get_tab_hhea(tt_file *ttf);
void tt_get_tab_cmap(tt_file *ttf);
pdc_bool tt_get_tab_CFF_(tt_file *ttf);
void tt_get_tab_OS_2(tt_file *ttf);
@@ -555,4 +564,5 @@ pdc_bool fnt_check_tt_font(pdc_core *pdc, const char *filename,
const char *fontname, fnt_font *font, pdc_bool requested);
+
#endif /* FT_TRUETYPE_H */
diff --git a/src/pdflib/font/ft_type1.c b/src/pdflib/font/ft_type1.c
index 2644284..6c16102 100644
--- a/src/pdflib/font/ft_type1.c
+++ b/src/pdflib/font/ft_type1.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: ft_type1.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: ft_type1.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* FONT Type1 font handling routines
*
diff --git a/src/pdflib/pdcore/pc_chartabs.c b/src/pdflib/pdcore/pc_chartabs.c
index 3799d45..9e33bcb 100644
--- a/src/pdflib/pdcore/pc_chartabs.c
+++ b/src/pdflib/pdcore/pc_chartabs.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_chartabs.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_chartabs.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* PDFlib routines for converting glyph or character names to Unicode
* and vice versa
@@ -33,26 +33,53 @@ int
pdc_glyphname2codelist(const char *glyphname, const pdc_glyph_tab *glyphtab,
int tabsize, pdc_ushort *codelist)
{
+ const char *s1, *s2;
int lo = 0;
int hi = glyphname ? tabsize : lo;
- int nv = 0;
+ int i, j, cmp, nv = 0;
while (lo < hi)
{
- int i = (lo + hi) / 2;
- int cmp = strcmp(glyphname, glyphtab[i].name);
+ i = (lo + hi) / 2;
+
+ s1 = glyphname;
+ s2 = glyphtab[i].name;
+ for (; *s1; ++s1, ++s2)
+ {
+ if (*s1 != *s2)
+ break;
+ }
+ cmp = (*s1 - *s2);
if (cmp == 0)
{
+ j = i;
for (; i >= 1; i--)
{
- if (strcmp(glyphname, glyphtab[i-1].name))
+ s1 = glyphname;
+ s2 = glyphtab[i-1].name;
+ for (; *s1; ++s1, ++s2)
+ {
+ if (*s1 != *s2)
+ break;
+ }
+ if (*s1 != *s2)
break;
}
for (; i < tabsize; i++)
{
- if (strcmp(glyphname, glyphtab[i].name))
- break;
+ if (i > j)
+ {
+ s1 = glyphname;
+ s2 = glyphtab[i].name;
+ for (; *s1; ++s1, ++s2)
+ {
+ if (*s1 != *s2)
+ break;
+ }
+ if (*s1 != *s2)
+ break;
+ }
codelist[nv] = glyphtab[i].code;
nv++;
}
@@ -75,13 +102,23 @@ int
pdc_glyphname2code(const char *glyphname, const pdc_glyph_tab *glyphtab,
int tabsize)
{
+ const char *s1, *s2;
int lo = 0;
int hi = glyphname ? tabsize : lo;
+ int i, cmp;
while (lo < hi)
{
- int i = (lo + hi) / 2;
- int cmp = strcmp(glyphname, glyphtab[i].name);
+ i = (lo + hi) / 2;
+
+ s1 = glyphname;
+ s2 = glyphtab[i].name;
+ for (; *s1; ++s1, ++s2)
+ {
+ if (*s1 != *s2)
+ break;
+ }
+ cmp = (*s1 - *s2);
if (cmp == 0)
return (int) glyphtab[i].code;
@@ -175,13 +212,23 @@ const char *
pdc_glyphname2glyphname(const char *glyphname,
const pdc_glyph_tab *glyphtab, int tabsize)
{
+ const char *s1, *s2;
int lo = 0;
int hi = tabsize;
+ int cmp, i;
while (lo < hi)
{
- int i = (lo + hi) / 2;
- int cmp = strcmp(glyphname, glyphtab[i].name);
+ i = (lo + hi) / 2;
+
+ s1 = glyphname;
+ s2 = glyphtab[i].name;
+ for (; *s1; ++s1, ++s2)
+ {
+ if (*s1 != *s2)
+ break;
+ }
+ cmp = (*s1 - *s2);
if (cmp == 0)
return glyphtab[i].name;
@@ -332,15 +379,25 @@ pdc_glyphname2altunicode(const char *glyphname)
pdc_bool
pdc_is_std_charname(const char *glyphname)
{
+ const char *s1, *s2;
int lo = 0;
int hi = ((sizeof pc_standard_latin_charset) / (sizeof (char *)));
+ int cmp, i;
if (glyphname)
{
while (lo < hi)
{
- int i = (lo + hi) / 2;
- int cmp = strcmp(glyphname, pc_standard_latin_charset[i]);
+ i = (lo + hi) / 2;
+
+ s1 = glyphname;
+ s2 = pc_standard_latin_charset[i];
+ for (; *s1; ++s1, ++s2)
+ {
+ if (*s1 != *s2)
+ break;
+ }
+ cmp = (*s1 - *s2);
if (cmp == 0)
return pdc_true;
@@ -578,7 +635,7 @@ pdc_string2unicode(pdc_core *pdc, const char *text, int i_flags,
if (seterr)
{
- pdc_set_errmsg(pdc, PDC_E_CONV_ILLUTF32, &text[i], 0, 0, 0);
+ pdc_set_errmsg(pdc, PDC_E_CONV_ILLUTF32CHAR, &text[i], 0, 0, 0);
if (verbose)
pdc_error(pdc, -1, 0, 0, 0, 0);
}
diff --git a/src/pdflib/pdcore/pc_chartabs.h b/src/pdflib/pdcore/pc_chartabs.h
index cd6970b..02f320b 100644
--- a/src/pdflib/pdcore/pc_chartabs.h
+++ b/src/pdflib/pdcore/pc_chartabs.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_chartabs.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_chartabs.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* This file contains Adobe Glyph Names, HTML character reference names and
* some special glyph names.
diff --git a/src/pdflib/pdcore/pc_classic.h b/src/pdflib/pdcore/pc_classic.h
index cd6c22c..9d260a4 100644
--- a/src/pdflib/pdcore/pc_classic.h
+++ b/src/pdflib/pdcore/pc_classic.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_classic.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_classic.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Header for CodeWarrior to activate Classic builds (without CarbonLib).
*
diff --git a/src/pdflib/pdcore/pc_config.h b/src/pdflib/pdcore/pc_config.h
index 945c9d1..9a1f738 100644
--- a/src/pdflib/pdcore/pc_config.h
+++ b/src/pdflib/pdcore/pc_config.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_config.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_config.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* PDFlib portability and configuration definitions
*
@@ -37,22 +37,6 @@
#endif
/*
- * Byte order
- * WORDS_BIGENDIAN will be set by the configure script on most platforms.
- * Only on platforms where there is no configure script we must set the
- * endianness explicitly (most importantly CodeWarrior on the Mac)
- */
-#undef PDC_ISBIGENDIAN
-#if defined(WORDS_BIGENDIAN) || defined(__POWERPC__) || defined(__MC68K__)
-#define PDC_ISBIGENDIAN 1
-#if !defined(WORDS_BIGENDIAN)
-#define WORDS_BIGENDIAN
-#endif
-#else
-#define PDC_ISBIGENDIAN 0
-#endif
-
-/*
* Define for compiler supporting file open function _wfopen
* for Unicode filenames.
*/
@@ -85,6 +69,9 @@
#undef PDC_PATHSEP
#define PDC_PATHSEP "\\"
+#undef PDC_PATHSEP_ALT
+#define PDC_PATHSEP_ALT "/"
+
#if defined(_WIN32_WCE) && (_WIN32_WCE >= 300)
#define PDF_PLATFORM "Windows CE"
#define WINCE
@@ -155,14 +142,34 @@
/* try to identify the Mac OS X command line compiler */
-#if (defined(__ppc__) && defined(__APPLE__)) \
- || (defined(__i386__) && defined(__APPLE__))
+#if defined(__APPLE__) && (defined(__ppc__) || \
+ defined(__i386__) || defined(__ppc64__) || defined(__x86_64__))
/* #define MACOSX CDPDF */
/* Mac OS X 10.2 (Jaguar) defines this, but we use it for Mac OS 9 below */
#undef MAC
+#if !defined(PDF_PLATFORM) && defined(PDF_MAC_PLATFORM)
+
+#if defined(__ppc__)
+#define PDF_PLATFORM PDF_MAC_PLATFORM" ppc"
+#endif /* __ppc__ */
+
+#if defined(__ppc64__)
+#define PDF_PLATFORM PDF_MAC_PLATFORM" ppc64"
+#endif /* __ppc64__ */
+
+#if defined(__x86_64__)
+#define PDF_PLATFORM PDF_MAC_PLATFORM" 64"
+#endif /* __x86_64__ */
+
+#if !defined(PDF_PLATFORM)
+#define PDF_PLATFORM PDF_MAC_PLATFORM
+#endif
+
+#endif /* PDF_PLATFORM */
+
#ifndef PDF_PLATFORM
#define PDF_PLATFORM "Mac OS X"
#endif
@@ -180,7 +187,34 @@
#undef MAC /* CDPDF */
#undef MACOSX /* CDPDF */
-#ifdef MAC
+/*
+ * Byte order
+ * WORDS_BIGENDIAN will be set by the configure script on most platforms.
+ * Only on platforms where there is no configure script we must set the
+ * endianness explicitly (most importantly CodeWarrior on the Mac)
+ *
+ * And we have to explicitly set it on Platforms where crosscompiling
+ * is used (like Mac to create Universal Binaries)
+ */
+#undef PDC_ISBIGENDIAN
+#if defined(__APPLE__)
+# if defined(__POWERPC__) || defined(__MC68K__) \
+ || defined(__ppc64__) || defined(__ppc__)
+# define PDC_ISBIGENDIAN 1
+# else
+# define PDC_ISBIGENDIAN 0
+# endif
+#else /* MAC */
+# if defined(WORDS_BIGENDIAN)
+# define PDC_ISBIGENDIAN 1
+# else
+# define PDC_ISBIGENDIAN 0
+# endif
+#endif /* MAC */
+
+
+
+#if defined(MAC) && !defined(__ppc64__)
#define WRITEMODE "wb"
#define APPENDMODE "ab"
#define PDC_PATHSEP ":"
@@ -190,9 +224,10 @@
#define PDF_PLATFORM "Mac OS 9"
#endif /* MAC */
+#if defined(MAC) || defined(MACOSX)
+
/* ------------------ Carbon Handling for both Mac OS 9 and X --------------- */
-#if defined(MAC) || defined(MACOSX)
/*
* By default we always build a carbonized version of the library,
* but allow non-Carbon builds to be triggered by setting the
@@ -201,6 +236,7 @@
#ifdef PDF_TARGET_API_MAC_CLASSIC
#undef PDF_TYPE1_HOSTFONT_SUPPORTED
+#define PDF_ALLOW_MAC_DEPR_FUNCS
#else
#define PDF_TARGET_API_MAC_CARBON
#endif
@@ -209,7 +245,45 @@
#define TARGET_API_MAC_CARBON 1
#endif
-#endif /* MAC */
+/* ---------------- Enabling special MAC functionality --------------------- */
+
+#ifdef PDF_TARGET_API_MAC_CARBON
+
+/* It must be distinguished between 32-bit and 64-bit Mac OS X versions,
+ * because PDFlib uses MAC API functions, especially the old QuickDraw
+ * functions, which are not available on 64-bit Mac OS X platforms.
+ * These functions are already deprecated from Mac OS X v10.4 and
+ * shall be disabled also for 32-bit versions in future releases.
+ * Therefore we set the define PDF_MACATS_SUPPORTED for all CPU versions.
+ *
+ * PDF_MACATS_SUPPORTED:
+ * - ATS font handling (each type of host font name support possible)
+ *
+ * PDF_ALLOW_MAC_DEPR_FUNCS:
+ * - Only QuickDraw font names possible
+ * - FileSpec instead of FileRef functions (also in ATS)
+ * - File type creation (PDF_FILETYPE_SUPPORTED) for PDF files, otherwise none
+ * - Global variable __MacOSErrNo for special error codes supported
+ *
+ * PDF_MAC_LEGACY:
+ * Differentiates between the two versions above (compiler define).
+ *
+ * PDF_MAC_NOCORESERVICES:
+ * Disables PDF_FEATURE_HOSTFONT (see pc_core.h) and PDF_FILETYPE_SUPPORTED
+ * (see pc_output.c) (compiler define). This is relevant for the PHP wrapper
+ * on MAC (see bug #1588).
+ *
+ */
+
+#if defined(PDF_MAC_LEGACY)
+#define PDF_ALLOW_MAC_DEPR_FUNCS
+#else
+#define PDF_MACATS_SUPPORTED
+#endif /* PDF_MAC_LEGACY */
+
+#endif /* PDF_TARGET_API_MAC_CARBON */
+
+#endif /* MAC || MACOSX */
/* ----------------------------------- BeOS --------------------------------- */
@@ -234,6 +308,9 @@
# ifndef _LARGE_FILE_API
#error You need to compile this module with DEFINE(_LARGE_FILE_API)
# endif
+
+#define _LARGEFILE_SOURCE
+
# ifndef __TERASPACE__
#error You need to compile this module with TERASPACE(*YES *TSIFC)
STGMDL(*TERASPACE)
@@ -350,8 +427,12 @@ STGMDL(*TERASPACE)
#endif /* !READBMODE_PLUS */
#ifndef WRITEMODE
-#define WRITEMODE "wb"
-#endif /* !WRITEMODE */
+#define WRITEMODE "wb"
+#endif /* !WRITEMODE */
+
+#ifndef WRITEMODE_V
+#define WRITEMODE_V "wb"
+#endif /* !WRITEMODE_V */
#ifndef APPENDMODE
#define APPENDMODE "ab"
@@ -361,6 +442,10 @@ STGMDL(*TERASPACE)
#define PDC_PATHSEP "/"
#endif /* !PDC_PATHSEP */
+#ifndef PDC_PATHSEP_ALT
+#define PDC_PATHSEP_ALT "\\"
+#endif /* !PDC_PATHSEP_ALT */
+
#ifndef PDC_TMPDIR_ENV
#define PDC_TMPDIR_ENV "TMPDIR"
#endif /* !PDC_TMPDIR_ENV */
diff --git a/src/pdflib/pdcore/pc_contain.c b/src/pdflib/pdcore/pc_contain.c
index 6a3cdfc..ca752f0 100644
--- a/src/pdflib/pdcore/pc_contain.c
+++ b/src/pdflib/pdcore/pc_contain.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_contain.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_contain.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* PDFlib generic container classes
*
@@ -221,7 +221,186 @@ avl_insert(avl_node *root, const char *name, pdc_bool *change_parent_balance)
#endif /* COMMENT */
-/***************************** vector class *****************************/
+
+/*************************** bit vector class ***************************/
+
+struct pdc_bvtr_s
+{
+ pdc_core * pdc;
+
+ char ** ctab; /* chunk table */
+ int ctab_size; /* current # of slots */
+ int ctab_incr;
+ int chunk_size; /* # of bytes per chunk */
+ int size; /* current # of bytes total */
+ char init_char; /* 0x00 or 0xFF */
+};
+
+
+static const pdc_bvtr_parms bvtr_dflt_parms =
+{
+ 0, /* initial number of bits */
+ pdc_false, /* initial bit value */
+ 1000, /* number of bytes per chunk */
+ 10 /* chunk table increment */
+};
+
+
+void pdc_bvtr_dflt_parms(pdc_bvtr_parms *vp)
+{
+ *vp = bvtr_dflt_parms;
+}
+
+
+pdc_bvtr *pdc_bvtr_new(pdc_core *pdc, const pdc_bvtr_parms *parms)
+{
+ static const char fn[] = "pdc_bvtr_new";
+
+ pdc_bvtr *v = (pdc_bvtr *) pdc_malloc(pdc, sizeof (pdc_bvtr), fn);
+
+ if (!parms)
+ parms = &bvtr_dflt_parms;
+
+ v->pdc = pdc;
+
+ v->ctab = (char **) 0;
+ v->ctab_size = 0;
+ v->ctab_incr = parms->ctab_incr;
+ v->chunk_size = parms->chunk_size;
+ v->size = 0;
+ v->init_char = parms->init_value ? 0xFF : 0x00;
+
+ if (parms->init_n_bits != 0)
+ {
+ PDC_TRY (pdc)
+ {
+ pdc_bvtr_resize(v, parms->init_n_bits);
+ }
+ PDC_CATCH (pdc)
+ {
+ pdc_bvtr_delete(v);
+ PDC_RETHROW(pdc);
+ }
+ }
+
+ return v;
+} /* pdc_bvtr_new */
+
+
+void pdc_bvtr_delete(pdc_bvtr *v)
+{
+ int i;
+
+ for (i = 0; i < v->ctab_size && v->ctab[i]; ++i)
+ {
+ pdc_free(v->pdc, v->ctab[i]);
+ }
+
+ if (v->ctab)
+ pdc_free(v->pdc, v->ctab);
+
+ pdc_free(v->pdc, v);
+} /* pdc_bvtr_delete */
+
+
+void
+pdc_bvtr_resize(pdc_bvtr *v, int n_bits)
+{
+ static const char fn[] = "pdc_bvtr_resize";
+
+ int cs = v->chunk_size;
+ int new_size = (n_bits + 7) / 8;
+ int new_ctsize = (new_size + cs - 1) / cs; /* TODO: ctab_incr? */
+ int i;
+
+ PDC_ASSERT(v->pdc, 0 <= n_bits);
+
+ if (new_size < v->size)
+ {
+ if (new_ctsize < v->ctab_size)
+ {
+ for (i = new_ctsize; i < v->ctab_size; ++i)
+ {
+ pdc_free(v->pdc, v->ctab[i]);
+ }
+ }
+
+ v->ctab_size = new_ctsize;
+ v->size = new_ctsize * cs;
+ }
+ else if (new_size > v->size)
+ {
+ v->ctab = (char **) pdc_realloc(v->pdc, v->ctab,
+ (size_t) (new_ctsize * sizeof (char *)), fn);
+
+ for (i = v->size / cs; i < new_ctsize; ++i)
+ {
+ int k;
+
+ v->ctab[i] = (char *) pdc_malloc(v->pdc, (size_t) cs, fn);
+
+ for (k = 0; k < cs; ++k)
+ {
+ v->ctab[i][k] = v->init_char;
+ }
+ }
+
+ v->ctab_size = new_ctsize;
+ v->size = new_ctsize * cs;
+ }
+} /* pdc_vtr_resize */
+
+
+pdc_bool
+pdc_bvtr_getbit(const pdc_bvtr *v, int n)
+{
+ static const char fn[] = "pdc_bvtr_getbit";
+
+ int cs = v->chunk_size;
+ int idx = n / 8;
+ int bit = 1 << (n % 8);
+
+ if (idx < 0 || v->size <= idx)
+ pdc_error(v->pdc, PDC_E_INT_ARRIDX,
+ pdc_errprintf(v->pdc, "%d", n), fn, 0, 0);
+
+ return (v->ctab[idx / cs][idx % cs] & bit) != 0;
+} /* pdc_bvtr_getbit */
+
+
+void pdc_bvtr_setbit(const pdc_bvtr *v, int n)
+{
+ static const char fn[] = "pdc_bvtr_setbit";
+
+ int cs = v->chunk_size;
+ int idx = n / 8;
+ int bit = 1 << (n % 8);
+
+ if (idx < 0 || v->size <= idx)
+ pdc_error(v->pdc, PDC_E_INT_ARRIDX,
+ pdc_errprintf(v->pdc, "%d", n), fn, 0, 0);
+
+ v->ctab[idx / cs][idx % cs] |= bit;
+} /* pdc_bvtr_setbit */
+
+
+void pdc_bvtr_clrbit(const pdc_bvtr *v, int n)
+{
+ static const char fn[] = "pdc_bvtr_clrbit";
+
+ int cs = v->chunk_size;
+ int idx = n / 8;
+ int bit = 1 << (n % 8);
+
+ if (idx < 0 || v->size <= idx)
+ pdc_error(v->pdc, PDC_E_INT_ARRIDX,
+ pdc_errprintf(v->pdc, "%d", n), fn, 0, 0);
+
+ v->ctab[idx / cs][idx % cs] &= ~bit;
+} /* pdc_bvtr_clrbit */
+
+
+/*********************** stack type vector class ************************/
struct pdc_vtr_s
{
@@ -242,7 +421,7 @@ static const pdc_vtr_parms vtr_dflt_parms =
{
0, /* init_size */
100, /* chunk_size */
- 10 /* ctab_incr */
+ 10, /* ctab_incr */
};
void
@@ -413,7 +592,6 @@ pdc__vtr_at(const pdc_vtr *v, int idx)
if (idx < 0 || v->size <= idx)
pdc_error(v->pdc, PDC_E_INT_ARRIDX,
pdc_errprintf(v->pdc, "%d", idx), fn, 0, 0);
- /* TODO: "%u" */
return (void *) (&v->ctab[idx / cs][(idx % cs) * v->ced.size]);
} /* pdc__vtr_at */
@@ -430,7 +608,6 @@ pdc__vtr_at_c(const pdc_vtr *v, int idx)
if (idx < 0 || v->size <= idx)
pdc_error(v->pdc, PDC_E_INT_ARRIDX,
pdc_errprintf(v->pdc, "%d", idx), fn, 0, 0);
- /* TODO: "%u" */
return (const void *) (&v->ctab[idx / cs][(idx % cs) * v->ced.size]);
} /* pdc__vtr_at_c */
@@ -516,3 +693,315 @@ pdc_vtr_pop(pdc_vtr *v)
&v->ctab[v->size / cs][(v->size % cs) * v->ced.size]);
}
} /* pdc_vtr_pop */
+
+
+/************************ heap type vector class ************************/
+
+typedef struct pdc_link_s pdc_link;
+typedef struct pdc_chunk_s pdc_chunk;
+
+struct pdc_link_s /* for doubly linked free items list */
+{
+ int idx;
+ pdc_link * prev; /* previous item in free list */
+ pdc_link * next; /* next item in free list */
+};
+
+
+struct pdc_chunk_s
+{
+ char * data; /* the items in this chunk */
+ int n_items; /* number of used items in this chunk */
+
+ pdc_chunk * next; /* next chunk in free list */
+};
+
+
+struct pdc_hvtr_s
+{
+ pdc_core * pdc;
+
+ pdc_ced ced; /* container entry descriptor */
+ void * context; /* client context */
+
+ pdc_chunk * ctab; /* chunk table */
+ int ctab_size; /* current # of slots */
+ int ctab_incr;
+ int chunk_size; /* # of items per chunk */
+ int size; /* current # of items total */
+
+ pdc_link * free_items; /* first item in free items list */
+ pdc_link end_items; /* sentinel */
+ pdc_chunk * free_chunks; /* first chunk in free chunks list */
+ pdc_chunk end_chunks; /* sentinel */
+
+ pdc_bvtr * free_mask; /* bit mask of free items */
+};
+
+
+static const pdc_hvtr_parms hvtr_dflt_parms =
+{
+ 100, /* chunk_size */
+ 10, /* ctab_incr */
+};
+
+void
+pdc_hvtr_dflt_parms(pdc_hvtr_parms *vp)
+{
+ *vp = hvtr_dflt_parms;
+}
+
+
+pdc_hvtr *
+pdc_hvtr_new(
+ pdc_core *pdc,
+ const pdc_ced *ced,
+ void *context,
+ const pdc_hvtr_parms *parms)
+{
+ static const char fn[] = "pdc_hvtr_new";
+
+ pdc_hvtr *v = (pdc_hvtr *) pdc_malloc(pdc, sizeof (pdc_hvtr), fn);
+
+ if (!parms)
+ parms = &hvtr_dflt_parms;
+
+ v->pdc = pdc;
+ v->ced = *ced;
+ v->context = context ? context : pdc;
+
+ if (v->ced.size < sizeof (pdc_link))
+ {
+ v->ced.size = sizeof (pdc_link);
+ }
+
+ v->ctab = (pdc_chunk *) 0;
+ v->ctab_size = 0;
+ v->ctab_incr = parms->ctab_incr;
+ v->chunk_size = parms->chunk_size;
+ v->size = 0;
+
+ v->free_items = &v->end_items;
+ v->end_items.next = v->end_items.prev = &v->end_items;
+ v->free_chunks = &v->end_chunks;
+ v->free_mask = 0;
+
+ PDC_TRY (pdc)
+ {
+ pdc_bvtr_parms bvp;
+
+ pdc_bvtr_dflt_parms(&bvp);
+ bvp.init_value = pdc_true;
+ v->free_mask = pdc_bvtr_new(pdc, &bvp);
+ }
+ PDC_CATCH (pdc)
+ {
+ pdc_hvtr_delete(v);
+ PDC_RETHROW(pdc);
+ }
+
+ return v;
+} /* pdc_hvtr_new */
+
+
+void
+pdc_hvtr_delete(pdc_hvtr *v)
+{
+ int cs = v->chunk_size;
+ int i;
+
+ if (v->size != 0 && v->ced.release)
+ {
+ for (i = 0; i < v->size; ++i)
+ {
+ if (!pdc_bvtr_getbit(v->free_mask, i))
+ {
+ v->ced.release(v->context, (void *)
+ &v->ctab[i / cs].data[(i % cs) * v->ced.size]);
+ }
+ }
+ }
+
+ if (v->ctab)
+ {
+ for (i = 0; i < v->ctab_size && v->ctab[i].data != (char *) 0; ++i)
+ {
+ pdc_free(v->pdc, v->ctab[i].data);
+ }
+
+ pdc_free(v->pdc, v->ctab);
+ }
+
+ if (v->free_mask)
+ {
+ pdc_bvtr_delete(v->free_mask);
+ }
+
+ pdc_free(v->pdc, v);
+} /* pdc_hvtr_delete */
+
+
+void
+pdc_hvtr_release_item(pdc_hvtr *v, int idx)
+{
+ static const char fn[] = "pdc_hvtr_release_item";
+
+ const int cs = v->chunk_size;
+ pdc_chunk * chunk = &v->ctab[idx / cs];
+ void * item;
+ pdc_link * link;
+
+ if (idx < 0 || v->size <= idx || pdc_bvtr_getbit(v->free_mask, idx))
+ {
+ pdc_error(v->pdc, PDC_E_INT_ARRIDX,
+ pdc_errprintf(v->pdc, "%d", idx), fn, 0, 0);
+ }
+
+ item = &chunk->data[(idx % cs) * v->ced.size];
+
+ if (v->ced.release)
+ {
+ v->ced.release(v->context, item);
+ }
+
+ pdc_bvtr_setbit(v->free_mask, idx);
+
+ link = (pdc_link *) item;
+ link->idx = idx;
+ link->next = v->free_items;
+ link->prev = &v->end_items;
+ link->next->prev = link->prev->next = link;
+ v->free_items = link;
+
+ if (--chunk->n_items == 0)
+ {
+ for (idx = 0; idx < cs; ++idx)
+ {
+ link = (pdc_link *) &chunk->data[idx * v->ced.size];
+
+ link->prev->next = link->next;
+ link->next->prev = link->prev;
+ }
+
+ pdc_free(v->pdc, chunk->data);
+ chunk->data = 0;
+ chunk->next = v->free_chunks;
+ v->free_chunks = chunk;
+ }
+} /* pdc_hvtr_release_item */
+
+
+int
+pdc_hvtr_reclaim_item(pdc_hvtr *v)
+{
+ static const char fn[] = "pdc_hvtr_reclaim_item";
+
+ pdc_link * new_item;
+ int idx;
+
+ if (v->free_items != &v->end_items)
+ {
+ new_item = v->free_items;
+ new_item->prev->next = new_item->next;
+ new_item->next->prev = new_item->prev;
+ v->free_items = new_item->next;
+ }
+ else
+ {
+ /* install new chunk.
+ */
+ const int cs = v->chunk_size;
+ const int es = v->ced.size;
+ pdc_chunk * new_chunk;
+ pdc_link * link;
+ int base;
+
+ if (v->free_chunks != &v->end_chunks)
+ {
+ new_chunk = v->free_chunks;
+ v->free_chunks = new_chunk->next;
+ }
+ else
+ {
+ int new_size = v->ctab_size + v->ctab_incr;
+
+ v->ctab = (pdc_chunk *) pdc_realloc(v->pdc, v->ctab,
+ (size_t) (new_size * sizeof (pdc_chunk)), fn);
+
+ for (idx = v->ctab_size; idx < new_size; ++idx)
+ {
+ v->ctab[idx].data = (char *) 0;
+ v->ctab[idx].n_items = 0;
+ v->ctab[idx].next = &v->ctab[idx + 1];
+ }
+
+ v->ctab[new_size - 1].next = &v->end_chunks;
+ v->free_chunks = &v->ctab[v->ctab_size + 1];
+ new_chunk = &v->ctab[v->ctab_size];
+ v->ctab_size = new_size;
+ v->size += cs * v->ctab_incr;
+ pdc_bvtr_resize(v->free_mask, v->size);
+ }
+
+ new_chunk->data = pdc_malloc(v->pdc, cs * es, fn);
+ base = cs * (new_chunk - &v->ctab[0]);
+
+ for (idx = 1; idx < cs; ++idx)
+ {
+ link = (pdc_link *) &new_chunk->data[idx * es];
+
+ link->idx = base + idx;
+ link->prev = (pdc_link *) &new_chunk->data[(idx - 1) * es];
+ link->next = (pdc_link *) &new_chunk->data[(idx + 1) * es];
+ }
+
+ /* end of new chain:
+ */
+ link = (pdc_link *) &new_chunk->data[(cs - 1) * es];
+ link->next = v->free_items;
+ link->next->prev = link;
+
+ /* start of new chain:
+ */
+ link = (pdc_link *) &new_chunk->data[1 * es];
+ link->prev = &v->end_items;
+ v->free_items = v->end_items.next = link;
+
+ new_item = (pdc_link *) &new_chunk->data[0];
+ new_item->idx = base;
+ }
+
+ idx = new_item->idx;
+ pdc_bvtr_clrbit(v->free_mask, idx);
+
+ if (v->ced.reclaim)
+ {
+ v->ced.reclaim((void *) new_item);
+ }
+
+ return idx;
+} /* pdc_hvtr_reclaim_item */
+
+
+pdc_bool
+pdc_hvtr_check_idx(const pdc_hvtr *v, int idx)
+{
+ return 0 <= idx && idx < v->size && !pdc_bvtr_getbit(v->free_mask, idx);
+} /* pdc__hvtr_at */
+
+
+void *
+pdc__hvtr_at(const pdc_hvtr *v, int idx)
+{
+ static const char fn[] = "pdc__hvtr_at";
+
+ int cs = v->chunk_size;
+
+ if (idx < 0 || v->size <= idx || pdc_bvtr_getbit(v->free_mask, idx))
+ {
+ pdc_error(v->pdc, PDC_E_INT_ARRIDX,
+ pdc_errprintf(v->pdc, "%d", idx), fn, 0, 0);
+ }
+
+ return (void *) &v->ctab[idx / cs].data[(idx % cs) * v->ced.size];
+} /* pdc__hvtr_at */
diff --git a/src/pdflib/pdcore/pc_contain.h b/src/pdflib/pdcore/pc_contain.h
index 007bfd0..8b40e18 100644
--- a/src/pdflib/pdcore/pc_contain.h
+++ b/src/pdflib/pdcore/pc_contain.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_contain.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_contain.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* PDFlib generic container classes
*
@@ -47,7 +47,31 @@ void * pdc_avl_insert(pdc_avl *t, const void *item);
void pdc_avl_for_each(const pdc_avl *t, pdc_for_each_cb cb);
-/***************************** vector class *****************************/
+/*************************** bit vector class ****************************/
+
+typedef struct pdc_bvtr_s pdc_bvtr;
+
+typedef struct
+{
+ int init_n_bits; /* initial number of bits */
+ pdc_bool init_value; /* initial bit value */
+ int chunk_size; /* number of bits per chunk */
+ int ctab_incr; /* chunk table increment */
+} pdc_bvtr_parms;
+
+void pdc_bvtr_dflt_parms(pdc_bvtr_parms *vp);
+
+pdc_bvtr * pdc_bvtr_new(pdc_core *pdc, const pdc_bvtr_parms *parms);
+void pdc_bvtr_delete(pdc_bvtr *v);
+
+void pdc_bvtr_resize(pdc_bvtr *v, int n_bits);
+
+pdc_bool pdc_bvtr_getbit(const pdc_bvtr *v, int n);
+void pdc_bvtr_setbit(const pdc_bvtr *v, int n);
+void pdc_bvtr_clrbit(const pdc_bvtr *v, int n);
+
+
+/************************ stack type vector class ************************/
typedef struct pdc_vtr_s pdc_vtr;
@@ -64,17 +88,11 @@ pdc_vtr * pdc_vtr_new(pdc_core *pdc, const pdc_ced *ced, void *context,
const pdc_vtr_parms *parms);
void pdc_vtr_delete(pdc_vtr *v);
+
int pdc_vtr_size(const pdc_vtr *v);
void pdc_vtr_resize(pdc_vtr *v, int size);
void pdc_vtr_pop(pdc_vtr *v);
-/* don't use the pdc__vtr_xxx() functions directly.
-** use the respective pdc_vtr_xxx() macros below.
-*/
-void * pdc__vtr_at(const pdc_vtr *v, int idx);
-void * pdc__vtr_top(const pdc_vtr *v);
-void * pdc__vtr_push(pdc_vtr *v);
-
/* <type> pdc_vtr_at(const pdc_vtr *v, int idx, <type>);
**
@@ -107,4 +125,49 @@ void * pdc__vtr_push(pdc_vtr *v);
#define pdc_vtr_incr(v, type) \
((type *) pdc__vtr_push(v))
+
+/* don't use the pdc__vtr_xxx() functions directly.
+** use the respective pdc_vtr_xxx() macros above.
+*/
+void * pdc__vtr_at(const pdc_vtr *v, int idx);
+void * pdc__vtr_top(const pdc_vtr *v);
+void * pdc__vtr_push(pdc_vtr *v);
+
+
+
+/************************ heap type vector class ************************/
+
+typedef struct pdc_hvtr_s pdc_hvtr;
+
+typedef struct
+{
+ int chunk_size;
+ int ctab_incr;
+} pdc_hvtr_parms;
+
+void pdc_hvtr_dflt_parms(pdc_hvtr_parms *vp);
+
+pdc_hvtr * pdc_hvtr_new(pdc_core *pdc, const pdc_ced *ced, void *context,
+ const pdc_hvtr_parms *parms);
+
+void pdc_hvtr_delete(pdc_hvtr *v);
+
+void pdc_hvtr_release_item(pdc_hvtr *v, int idx);
+int pdc_hvtr_reclaim_item(pdc_hvtr *v);
+pdc_bool pdc_hvtr_check_idx(const pdc_hvtr *v, int idx);
+
+
+/* <type> pdc_hvtr_at(const pdc_hvtr *v, int idx, <type>);
+**
+** (<type>) v[idx]
+*/
+#define pdc_hvtr_at(v, idx, type) \
+ (*((type *) pdc__hvtr_at(v, idx)))
+
+
+/* don't use the pdc__hvtr_xxx() functions directly.
+** use the respective pdc_hvtr_xxx() macros above.
+*/
+void * pdc__hvtr_at(const pdc_hvtr *v, int idx);
+
#endif /* PC_CONTAIN_H */
diff --git a/src/pdflib/pdcore/pc_core.c b/src/pdflib/pdcore/pc_core.c
index 4617aec..2b26c91 100644
--- a/src/pdflib/pdcore/pc_core.c
+++ b/src/pdflib/pdcore/pc_core.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_core.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_core.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* PDFlib core services
*
@@ -84,7 +84,8 @@ struct pdc_core_priv_s
/* the time of pdc_enter_api() */
/* ------------ error handling ------------ */
- pdc_bool in_error;
+ pdc_bool in_error; /* while initializing pdcore or */
+ /* while creating error resp. */
char * premsg;
char errbuf[PDC_ERRBUF_SIZE];
char errparms[4][PDC_ERRPARM_SIZE];
@@ -203,7 +204,17 @@ pdc_panic(pdc_core *pdc, const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
- pdc_vsnprintf(pdc->pr->errbuf, PDC_ERRPARM_SIZE, fmt, ap);
+
+#if defined (PDC_NO_VSNPRINTF)
+ vsprintf(pdc->pr->errbuf, fmt, ap);
+#else
+#if defined(WIN32)
+ _vsnprintf(pdc->pr->errbuf, PDC_ERRPARM_SIZE, fmt, ap);
+#else
+ vsnprintf(pdc->pr->errbuf, PDC_ERRPARM_SIZE, fmt, ap);
+#endif
+#endif
+
va_end(ap);
(*pdc->pr->errorhandler)(pdc->pr->opaque, PDF_UnknownError,
@@ -364,7 +375,8 @@ pdc_new_core(
pdc->uniqueno = 0;
-#ifdef PDC_DEBUG
+
+#ifdef PDC_DEBUG
pdc->pr->hexdump = pdc_true;
#endif
@@ -378,11 +390,12 @@ pdc_new_core(
/* initialize error & exception handling.
*/
- pdc->pr->in_error = pdc_false;
+ pdc->pr->in_error = pdc_true; /* disable error messages */
pdc->pr->x_thrown = pdc_false;
pdc->pr->epcount = 0;
pdc->pr->errnum = 0;
pdc->pr->premsg = NULL;
+ pdc->pr->errbuf[0] = 0;
pdc->pr->apiname[0] = 0;
pdc->pr->x_sp = -1;
pdc->pr->x_ssize = PDC_XSTACK_INISIZE;
@@ -415,7 +428,19 @@ pdc_new_core(
pdc->pr->err_tables[i].ei = (pdc_error_info *) 0;
pdc_register_errtab(pdc, PDC_ET_CORE, core_errors, N_CORE_ERRORS);
+
+ /* initialize mempool for strings
+ */
pdc_init_strings(pdc);
+ if (pdc->bstr_pool == NULL || pdc->ustr_pool == NULL)
+ {
+ (*freeproc)(opaque, pdc);
+ return (pdc_core *) 0;
+ }
+
+ /* enable error messages
+ */
+ pdc->pr->in_error = pdc_false;
return pdc;
}
@@ -476,7 +501,8 @@ pdc_malloc(pdc_core *pdc, size_t size, const char *caller)
/* the behavior of malloc(0) is undefined in ANSI C, and may
* result in a NULL pointer return value which makes PDFlib bail out.
*/
- if (size == (size_t) 0 || (long) size < 0L) {
+ if (size == (size_t) 0 || (long) size < 0L)
+ {
size = (size_t) 1;
pdc_error(pdc, PDC_E_INT_ALLOC0, caller, 0, 0, 0);
}
@@ -506,7 +532,8 @@ pdc_calloc(pdc_core *pdc, size_t size, const char *caller)
if (logg1)
pdc_logg(pdc, "\ttry to calloc %ld bytes\n", size);
- if (size == (size_t) 0 || (long) size < 0L) {
+ if (size == (size_t) 0 || (long) size < 0L)
+ {
size = (size_t) 1;
pdc_error(pdc, PDC_E_INT_ALLOC0, caller, 0, 0, 0);
}
@@ -534,7 +561,8 @@ pdc_realloc(pdc_core *pdc, void *mem, size_t size, const char *caller)
if (logg1)
pdc_logg(pdc, "\ttry to realloc %p to %ld bytes\n", mem, size);
- if (size == (size_t) 0 || (long) size < 0L) {
+ if (size == (size_t) 0 || (long) size < 0L)
+ {
size = (size_t) 1;
pdc_error(pdc, PDC_E_INT_ALLOC0, caller, 0, 0, 0);
}
@@ -722,7 +750,7 @@ const char *pdc_errprintf(pdc_core *pdc, const char *fmt, ...)
pdc->pr->epcount = 0;
va_start(ap, fmt);
- pdc_vsnprintf(pdc->pr->errparms[pdc->pr->epcount], PDC_ERRPARM_SIZE,
+ pdc_vsnprintf(pdc, pdc->pr->errparms[pdc->pr->epcount], PDC_ERRPARM_SIZE,
fmt, ap);
va_end(ap);
@@ -835,6 +863,7 @@ pdc_push_errmsg(
const pdc_error_info *ei = get_error_info(pdc, errnum);
pdc_pop_errmsg(pdc);
+ pdc->pr->errnum = 0;
make_errmsg(pdc, ei, parm1, parm2, parm3, parm4, pdc_false);
@@ -851,13 +880,17 @@ pdc_set_errmsg(
const char *parm3,
const char *parm4)
{
- const pdc_error_info *ei = get_error_info(pdc, errnum);
+ if (errnum != 0)
+ {
+ const pdc_error_info *ei = get_error_info(pdc, errnum);
- make_errmsg(pdc, ei, parm1, parm2, parm3, parm4, pdc_false);
+ make_errmsg(pdc, ei, parm1, parm2, parm3, parm4, pdc_false);
+ }
pdc->pr->errnum = errnum;
- pdc_logg_cond(pdc, 2, trc_warning,
+ if (errnum)
+ pdc_logg_cond(pdc, 2, trc_warning,
"[Reason for error message %d: \"%s\"]\n",
pdc->pr->errnum, pdc->pr->errbuf);
@@ -901,7 +934,7 @@ pdc_error(
const char *parm3,
const char *parm4)
{
- const char *logmsg;
+ const char *logmsg = NULL;
/* avoid recursive errors, but allow rethrow.
*/
@@ -921,18 +954,22 @@ pdc_error(
if (pdc->pr->x_sp > pdc->pr->x_sp0)
{
- logmsg = "\n[/// Exception %d in %s ]";
+ if (pdc_logg_is_enabled(pdc, 2, trc_warning))
+ logmsg = "[Nested exception %d in %s]";
}
else
{
- logmsg = "\n[+++ Exception %d in %s ]";
+ logmsg = "\n[Last exception %d in %s]";
}
- pdc_logg(pdc, logmsg, pdc->pr->errnum,
- (pdc->pr->errnum == 0 || !pdc->pr->apiname) ? "" : pdc->pr->apiname,
- pdc->pr->x_sp0 + 1, pdc->pr->x_sp - pdc->pr->x_sp0);
+ if (logmsg != NULL)
+ {
+ pdc_logg(pdc, logmsg, pdc->pr->errnum,
+ (pdc->pr->errnum == 0 || !pdc->pr->apiname) ? "" : pdc->pr->apiname,
+ pdc->pr->x_sp0 + 1, pdc->pr->x_sp - pdc->pr->x_sp0);
- pdc_logg(pdc, "[\"%s\"]\n\n", pdc->pr->errbuf);
+ pdc_logg(pdc, "[\"%s\"]\n\n", pdc->pr->errbuf);
+ }
if (pdc->pr->x_sp == -1)
{
@@ -967,6 +1004,9 @@ pdc_jbuf(pdc_core *pdc)
{
static const char fn[] = "pdc_jbuf";
+ pdc_logg_cond(pdc, 3, trc_api,
+ "[TRY to level %d]\n", pdc->pr->x_sp + 1);
+
if (++pdc->pr->x_sp == pdc->pr->x_ssize)
{
pdc_xframe *aux;
@@ -1026,6 +1066,9 @@ pdc_jbuf(pdc_core *pdc)
void
pdc_exit_try(pdc_core *pdc)
{
+ pdc_logg_cond(pdc, 3, trc_api,
+ "[EXIT_TRY at level %d]\n", pdc->pr->x_sp);
+
if (pdc->pr->x_sp == -1)
{
strcpy(pdc->pr->errbuf, "exception stack underflow");
@@ -1042,6 +1085,9 @@ pdc_catch_intern(pdc_core *pdc)
{
pdc_bool result;
+ pdc_logg_cond(pdc, 3, trc_api,
+ "[CATCH intern at level %d]\n", pdc->pr->x_sp);
+
if (pdc->pr->x_sp == -1)
{
strcpy(pdc->pr->errbuf, "exception stack underflow");
@@ -1064,6 +1110,9 @@ pdc_catch_extern(pdc_core *pdc)
{
pdc_bool result;
+ pdc_logg_cond(pdc, 3, trc_api,
+ "[CATCH at level %d]\n", pdc->pr->x_sp);
+
if (pdc->pr->x_sp == -1)
{
strcpy(pdc->pr->errbuf, "exception stack underflow");
@@ -1122,14 +1171,6 @@ pdc_get_errpref(pdc_core *pdc)
return pdc->pr->premsg;
}
-/* ----------- service function to get PDF version string -------------- */
-
-const char *
-pdc_get_pdfversion(pdc_core *pdc, int compatibility)
-{
- return pdc_errprintf(pdc, "%d.%d", compatibility / 10, compatibility % 10);
-}
-
#ifdef PDC_DEBUG
diff --git a/src/pdflib/pdcore/pc_core.h b/src/pdflib/pdcore/pc_core.h
index c758789..2b2c90f 100644
--- a/src/pdflib/pdcore/pc_core.h
+++ b/src/pdflib/pdcore/pc_core.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_core.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_core.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* PDFlib core services:
* - memory management
@@ -37,7 +37,7 @@
#define PDF_FEATURE_NOT_PUBLIC
-/* ------------------------- general ------------------------- */
+/* ------------------------- C types ------------------------- */
typedef struct pdc_core_priv_s pdc_core_priv;
typedef struct pdc_core_s pdc_core;
@@ -65,13 +65,16 @@ typedef unsigned int pdc_uint32;
*/
#if defined(_LARGEFILE_SOURCE)
#if defined(WIN32)
- typedef __int64 pdc_off_t;
+ typedef __int64 pdc_off_t;
+ typedef unsigned __int64 pdc_uoff_t;
#else
#include <sys/types.h>
- typedef off_t pdc_off_t;
+ typedef off_t pdc_off_t;
+ typedef unsigned long long pdc_uoff_t;
#endif
#else
- typedef long pdc_off_t;
+ typedef long pdc_off_t;
+ typedef unsigned long pdc_uoff_t;
#endif
/* use this one for casts from "off_t" to "long" - so we can "grep"
@@ -79,25 +82,12 @@ typedef unsigned int pdc_uint32;
*/
typedef long pdc_off_t1;
-
+/* boolean values */
#define pdc_undef -1
#define pdc_false 0
#define pdc_true 1
-#define PDC_1_1 11 /* PDF 1.1 = Acrobat 2 */
-#define PDC_1_2 12 /* PDF 1.2 = Acrobat 3 */
-#define PDC_1_3 13 /* PDF 1.3 = Acrobat 4 */
-#define PDC_1_4 14 /* PDF 1.4 = Acrobat 5 */
-#define PDC_1_5 15 /* PDF 1.5 = Acrobat 6 */
-#define PDC_1_6 16 /* PDF 1.6 = Acrobat 7 */
-#define PDC_1_7 17 /* PDF 1.7 = Acrobat 8 */
-#define PDC_X_X_LAST 17
-
-/* Acrobat limit for page dimensions */
-#define PDF_ACRO_MINPAGE (3.0) /* 1/24 inch = 0.106 cm */
-#define PDF_ACRO_MAXPAGE (14400.0) /* 200 inch = 508 cm */
-
-
+/* --------------------------- new pdcore --------------------------- */
typedef void (*pdc_error_fp)(void *opaque, int type, const char *msg);
typedef void* (*pdc_alloc_fp)(void *opaque, size_t size, const char *caller);
@@ -111,16 +101,6 @@ pdc_core *pdc_new_core(pdc_error_fp errorhandler, pdc_alloc_fp allocproc,
void pdc_delete_core(pdc_core *pdc);
-typedef enum
-{
- pdc_pbox_none,
- pdc_pbox_art,
- pdc_pbox_bleed,
- pdc_pbox_crop,
- pdc_pbox_media,
- pdc_pbox_trim
-} pdc_pagebox;
-
/* ------------------------- memory management ------------------------- */
void *pdc_malloc(pdc_core *pdc, size_t size, const char *caller);
@@ -239,11 +219,6 @@ void pdc_rethrow(pdc_core *pdc);
#define PDC_RETHROW(pdc) pdc_rethrow(pdc)
-/* ----------- service function to get PDF version string -------------- */
-
-const char *pdc_get_pdfversion(pdc_core *pdc, int compatibility);
-
-
/* --------------------------- debug hexdump --------------------------- */
#ifdef PDC_DEBUG
@@ -266,5 +241,10 @@ void pdc_hexdump(pdc_core *pdc, const char *msg, const char *text, int tlen);
*/
#define PDC_LICFILE_ENV "PDFLIBLICENSEFILE"
+/* default base name for license file
+*/
+#define PDC_LICFILE_NAME "licensekeys.txt"
#endif /* PC_CORE_H */
+
+
diff --git a/src/pdflib/pdcore/pc_crypt.c b/src/pdflib/pdcore/pc_crypt.c
index bcc404b..19c624a 100644
--- a/src/pdflib/pdcore/pc_crypt.c
+++ b/src/pdflib/pdcore/pc_crypt.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_crypt.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_crypt.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Routines for PDF encryption and decryption
*
diff --git a/src/pdflib/pdcore/pc_crypt.h b/src/pdflib/pdcore/pc_crypt.h
index 585f22c..4cbf043 100644
--- a/src/pdflib/pdcore/pc_crypt.h
+++ b/src/pdflib/pdcore/pc_crypt.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_crypt.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_crypt.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Crypto routines
*
diff --git a/src/pdflib/pdcore/pc_ctype.c b/src/pdflib/pdcore/pc_ctype.c
index 658f82f..efcaecd 100644
--- a/src/pdflib/pdcore/pc_ctype.c
+++ b/src/pdflib/pdcore/pc_ctype.c
@@ -6,7 +6,7 @@
| Proprietary source code -- do not redistribute! |
*---------------------------------------------------------------------------*/
-/* $Id: pc_ctype.c,v 1.1 2008/10/17 06:10:43 scuri Exp $ */
+/* $Id: pc_ctype.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
#include "pc_ctype.h"
@@ -23,20 +23,21 @@
#undef NUM0
#undef PDFSP
-#define LOWER 0x0001
-#define UPPER 0x0002
-#define DIGIT 0x0004
-#define PUNCT 0x0008
-#define SPACE 0x0010
+#define LOWER PDC_ISLOWER
+#define UPPER PDC_ISUPPER
+#define DIGIT PDC_ISDIGIT
+#define PUNCT PDC_ISPUNCT
+#define SPACE PDC_ISSPACE
+#define SPACE2 PDC_ISSPACE2
-#define OCT 0x0100
-#define HEX 0x0200
-#define DELIM 0x0400
-#define NUM0 0x0800 /* '+' '-' '.' '0'..'9' */
-#define PDFSP 0x1000 /* ' ' NUL HT NL CR FF */
+#define OCT PDC_ISOCT
+#define HEX PDC_ISXDIGIT
+#define DELIM PDC_ISDELIM
+#define NUM0 PDC_ISNUM0
+#define PDFSP PDC_ISPDFSP
-static const unsigned short pdc_ctype[256] =
+const unsigned short pdc_ctype[256] =
{
PDFSP, /* 0x00 = NUL */
@@ -53,7 +54,7 @@ static const unsigned short pdc_ctype[256] =
0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 .. 0x17 */
0, 0, 0, 0, 0, 0, 0, 0, /* 0x18 .. 0x1F */
- SPACE | PDFSP, /* 0x20 = ' ' */
+ SPACE | SPACE2 | PDFSP, /* 0x20 = ' ' */
PUNCT, /* 0x21 = '!' */
PUNCT, /* 0x22 = '"' */
PUNCT, /* 0x23 = '#' */
@@ -175,135 +176,3 @@ static const unsigned short pdc_ctype[256] =
0, 0, 0, 0, 0, 0, 0, 0, /* 0xF0 .. 0xF7 */
0, 0, 0, 0, 0, 0, 0, 0, /* 0xF8 .. 0xFF */
}; /* pdc_ctype */
-
-
-pdc_bool pdc__isalnum(pdc_byte c)
-{
-
- return (pdc_ctype[c] & (LOWER | UPPER | DIGIT)) != 0;
-}
-
-pdc_bool pdc__isalpha(pdc_byte c)
-{
-
- return (pdc_ctype[c] & (LOWER | UPPER)) != 0;
-}
-
-pdc_bool pdc__isdigit(pdc_byte c)
-{
-
- return (pdc_ctype[c] & DIGIT) != 0;
-}
-
-pdc_bool pdc__islower(pdc_byte c)
-{
-
- return (pdc_ctype[c] & LOWER) != 0;
-}
-
-pdc_bool pdc__isprint(pdc_byte c)
-{
-
- if (c == 0x20)
- return pdc_true;
-
- return (pdc_ctype[c] & (LOWER | UPPER | DIGIT | PUNCT)) != 0;
-}
-
-pdc_bool pdc__ispunct(pdc_byte c)
-{
-
- return (pdc_ctype[c] & PUNCT) != 0;
-}
-
-pdc_bool pdc__isspace(pdc_byte c)
-{
-
- return (pdc_ctype[c] & SPACE) != 0;
-}
-
-pdc_bool pdc__isupper(pdc_byte c)
-{
-
- return (pdc_ctype[c] & UPPER) != 0;
-}
-
-pdc_bool pdc__isxdigit(pdc_byte c)
-{
-
- return (pdc_ctype[c] & HEX) != 0;
-}
-
-pdc_byte pdc__tolower(pdc_byte c)
-{
- if (!pdc_isupper(c))
- {
- return c;
- }
- else
- {
- return (pdc_byte) (c + 0x20);
- }
-}
-
-pdc_byte pdc__toupper(pdc_byte c)
-{
- if (!pdc_islower(c))
- {
- return c;
- }
- else
- {
- return (pdc_byte) (c - 0x20);
- }
-}
-
-pdc_bool pdc__isalpha_a(pdc_byte c)
-{
- return (pdc_ctype[c] & (LOWER | UPPER)) != 0;
-}
-
-pdc_bool pdc__isdecdt_a(pdc_byte c)
-{
- return (pdc_ctype[c] & DIGIT) != 0;
-}
-
-pdc_bool pdc__isdelim_a(pdc_byte c)
-{
- return (pdc_ctype[c] & DELIM) != 0;
-}
-
-pdc_bool pdc__ishexdt_a(pdc_byte c)
-{
- return (pdc_ctype[c] & HEX) != 0;
-}
-
-pdc_bool pdc__islower_a(pdc_byte c)
-{
- return (pdc_ctype[c] & LOWER) != 0;
-}
-
-pdc_bool pdc__isnum0_a(pdc_byte c)
-{
- return (pdc_ctype[c] & NUM0) != 0;
-}
-
-pdc_bool pdc__isoctdt_a(pdc_byte c)
-{
- return (pdc_ctype[c] & OCT) != 0;
-}
-
-pdc_bool pdc__isspace_a(pdc_byte c)
-{
- return (pdc_ctype[c] & PDFSP) != 0;
-}
-
-pdc_bool pdc__isspecial_a(pdc_byte c)
-{
- return (pdc_ctype[c] & (PDFSP | DELIM)) != 0;
-}
-
-pdc_bool pdc__isupper_a(pdc_byte c)
-{
- return (pdc_ctype[c] & UPPER) != 0;
-}
diff --git a/src/pdflib/pdcore/pc_ctype.h b/src/pdflib/pdcore/pc_ctype.h
index 5aebcb4..59da980 100644
--- a/src/pdflib/pdcore/pc_ctype.h
+++ b/src/pdflib/pdcore/pc_ctype.h
@@ -6,72 +6,119 @@
| Proprietary source code -- do not redistribute! |
*---------------------------------------------------------------------------*/
-/* $Id: pc_ctype.h,v 1.1 2008/10/17 06:10:43 scuri Exp $ */
+/* $Id: pc_ctype.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
#ifndef PC_CTYPE_H_INCLUDED
#define PC_CTYPE_H_INCLUDED
#include "pc_util.h"
+extern const unsigned short pdc_ctype[];
+
+#define PDC_ISLOWER 0x0001
+#define PDC_ISUPPER 0x0002
+#define PDC_ISDIGIT 0x0004
+#define PDC_ISPUNCT 0x0008
+#define PDC_ISSPACE 0x0010
+#define PDC_ISSPACE2 0x0020
+
+#define PDC_ISOCT 0x0100
+#define PDC_ISXDIGIT 0x0200
+#define PDC_ISDELIM 0x0400
+#define PDC_ISNUM0 0x0800 /* '+' '-' '.' '0'..'9' */
+#define PDC_ISPDFSP 0x1000 /* ' ' NUL HT NL CR FF */
+
+
+#define PDC_CONVCHAR(c) ((pdc_byte) c)
+
+
/* these are the locale-free replacements for the standard library
-** isXXX() functions. use the macros below, DO NOT use the pdc__isXXX()
-** functions directly.
+** isXXX() functions.
*/
-#define pdc_isalnum(c) pdc__isalnum((pdc_byte) (c))
-#define pdc_isalpha(c) pdc__isalpha((pdc_byte) (c))
-#define pdc_isdigit(c) pdc__isdigit((pdc_byte) (c))
-#define pdc_islower(c) pdc__islower((pdc_byte) (c))
-#define pdc_isprint(c) pdc__isprint((pdc_byte) (c))
-#define pdc_ispunct(c) pdc__ispunct((pdc_byte) (c))
-#define pdc_isspace(c) pdc__isspace((pdc_byte) (c))
-#define pdc_isupper(c) pdc__isupper((pdc_byte) (c))
-#define pdc_isxdigit(c) pdc__isxdigit((pdc_byte) (c))
-
-#define pdc_tolower(c) pdc__tolower((pdc_byte) (c))
-#define pdc_toupper(c) pdc__toupper((pdc_byte) (c))
-
-pdc_bool pdc__isalnum(pdc_byte c);
-pdc_bool pdc__isalpha(pdc_byte c);
-pdc_bool pdc__isdigit(pdc_byte c);
-pdc_bool pdc__islower(pdc_byte c);
-pdc_bool pdc__isprint(pdc_byte c);
-pdc_bool pdc__ispunct(pdc_byte c);
-pdc_bool pdc__isspace(pdc_byte c);
-pdc_bool pdc__isupper(pdc_byte c);
-pdc_bool pdc__isxdigit(pdc_byte c);
-
-pdc_byte pdc__tolower(pdc_byte c);
-pdc_byte pdc__toupper(pdc_byte c);
+#define pdc_isalnum(c) \
+ ((pdc_ctype[PDC_CONVCHAR(c)] & \
+ (PDC_ISLOWER | PDC_ISUPPER | PDC_ISDIGIT)) != 0)
+
+#define pdc_isalpha(c) \
+ ((pdc_ctype[PDC_CONVCHAR(c)] & (PDC_ISLOWER | PDC_ISUPPER)) != 0)
+
+#define pdc_isdigit(c) \
+ ((pdc_ctype[PDC_CONVCHAR(c)] & PDC_ISDIGIT) != 0)
+
+#define pdc_islower(c) \
+ ((pdc_ctype[PDC_CONVCHAR(c)] & PDC_ISLOWER) != 0)
+
+#define pdc_isprint(c) \
+ ((pdc_ctype[PDC_CONVCHAR(c)] & \
+ (PDC_ISLOWER | PDC_ISUPPER | \
+ PDC_ISDIGIT | PDC_ISPUNCT | PDC_ISSPACE2)) != 0)
+
+#define pdc_ispunct(c) \
+ ((pdc_ctype[PDC_CONVCHAR(c)] & PDC_ISPUNCT) != 0)
+
+#define pdc_isspace(c) \
+ ((pdc_ctype[PDC_CONVCHAR(c)] & PDC_ISSPACE) != 0)
+
+#define pdc_isupper(c) \
+ ((pdc_ctype[PDC_CONVCHAR(c)] & PDC_ISUPPER) != 0)
+
+#define pdc_isxdigit(c) \
+ ((pdc_ctype[PDC_CONVCHAR(c)] & PDC_ISXDIGIT) != 0)
+
+
+#define pdc_tolower(c) \
+ (pdc_isupper(c) ? ((pdc_byte) ((c) + 0x20)) : (pdc_byte) (c))
+
+
+#define pdc_toupper(c) \
+ (pdc_islower(c) ? ((pdc_byte) ((c) - 0x20)) : (pdc_byte) (c))
/* these macros are for the various flavors of the token scanner. they
** expect ASCII input even on EBCDIC platforms (thus the "_a" suffix),
** and they implement special rules for PDF character classification.
*/
-#define pdc_isalpha_a(c) pdc__isalpha_a((pdc_byte) (c))
-#define pdc_isdecdt_a(c) pdc__isdecdt_a((pdc_byte) (c))
-#define pdc_isdelim_a(c) pdc__isdelim_a((pdc_byte) (c))
-#define pdc_ishexdt_a(c) pdc__ishexdt_a((pdc_byte) (c))
-#define pdc_islower_a(c) pdc__islower_a((pdc_byte) (c))
-#define pdc_isnum0_a(c) pdc__isnum0_a((pdc_byte) (c))
-#define pdc_isoctdt_a(c) pdc__isoctdt_a((pdc_byte) (c))
+#define pdc_isalnum_a(c) \
+ ((pdc_ctype[(pdc_byte) (c)] & \
+ (PDC_ISLOWER | PDC_ISUPPER | PDC_ISDIGIT)) != 0)
+
+#define pdc_isalpha_a(c) \
+ ((pdc_ctype[(pdc_byte) (c)] & (PDC_ISLOWER | PDC_ISUPPER)) != 0)
+
+#define pdc_isdecdt_a(c) \
+ ((pdc_ctype[(pdc_byte) (c)] & PDC_ISDIGIT) != 0)
+
+#define pdc_isdelim_a(c) \
+ ((pdc_ctype[(pdc_byte) (c)] & PDC_ISDELIM) != 0)
+
+#define pdc_ishexdt_a(c) \
+ ((pdc_ctype[(pdc_byte) (c)] & PDC_ISXDIGIT) != 0)
+
+#define pdc_islower_a(c) \
+ ((pdc_ctype[(pdc_byte) (c)] & PDC_ISLOWER) != 0)
+
+#define pdc_isnum0_a(c) \
+ ((pdc_ctype[(pdc_byte) (c)] & PDC_ISNUM0) != 0)
+
+#define pdc_isoctdt_a(c) \
+ ((pdc_ctype[(pdc_byte) (c)] & PDC_ISOCT) != 0)
+
+#define pdc_isspace_a(c) \
+ ((pdc_ctype[(pdc_byte) (c)] & PDC_ISPDFSP) != 0)
+
+#define pdc_isspecial_a(c) \
+ ((pdc_ctype[(pdc_byte) (c)] & (PDC_ISPDFSP | PDC_ISDELIM)) != 0)
+
+#define pdc_isupper_a(c) \
+ ((pdc_ctype[(pdc_byte) (c)] & PDC_ISUPPER) != 0)
#define pdc_isregular_a(c) \
- ((c) != -1 && !pdc__isspecial_a((pdc_byte) (c)))
-
-#define pdc_isspace_a(c) pdc__isspace_a((pdc_byte) (c))
-#define pdc_isspecial_a(c) pdc__isspecial_a((pdc_byte) (c))
-#define pdc_isupper_a(c) pdc__isupper_a((pdc_byte) (c))
-
-pdc_bool pdc__isalpha_a(pdc_byte c);
-pdc_bool pdc__isdecdt_a(pdc_byte c);
-pdc_bool pdc__isdelim_a(pdc_byte c);
-pdc_bool pdc__ishexdt_a(pdc_byte c);
-pdc_bool pdc__islower_a(pdc_byte c);
-pdc_bool pdc__isnum0_a(pdc_byte c);
-pdc_bool pdc__isoctdt_a(pdc_byte c);
-pdc_bool pdc__isspace_a(pdc_byte c);
-pdc_bool pdc__isspecial_a(pdc_byte c);
-pdc_bool pdc__isupper_a(pdc_byte c);
+ ((c) != -1 && !pdc_isspecial_a((pdc_byte) (c)))
+
+#define pdc_tolower_a(c) \
+ (pdc_isupper_a(c) ? ((pdc_byte) ((c) + 0x20)) : (pdc_byte) (c))
+
+#define pdc_toupper_a(c) \
+ (pdc_islower_a(c) ? ((pdc_byte) ((c) - 0x20)) : (pdc_byte) (c))
#endif /* PC_CTYPE_H_INCLUDED */
diff --git a/src/pdflib/pdcore/pc_digsig.c b/src/pdflib/pdcore/pc_digsig.c
index de2916e..f9466da 100644
--- a/src/pdflib/pdcore/pc_digsig.c
+++ b/src/pdflib/pdcore/pc_digsig.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_digsig.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_digsig.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*/
diff --git a/src/pdflib/pdcore/pc_digsig.h b/src/pdflib/pdcore/pc_digsig.h
index caaa3c7..d78dacf 100644
--- a/src/pdflib/pdcore/pc_digsig.h
+++ b/src/pdflib/pdcore/pc_digsig.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_digsig.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_digsig.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Digital Signature hashing/signing routines
*
diff --git a/src/pdflib/pdcore/pc_ebcdic.c b/src/pdflib/pdcore/pc_ebcdic.c
index cf87c5d..866a033 100644
--- a/src/pdflib/pdcore/pc_ebcdic.c
+++ b/src/pdflib/pdcore/pc_ebcdic.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_ebcdic.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_ebcdic.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* EBCDIC conversion routines
*
@@ -18,10 +18,120 @@
#include "pc_util.h"
+/*
+ * Expected codepages:
+ *
+ * AS/400: US/Canada - CECP (00037)
+ * OS/390: Latin 1 (01047)
+ * MVS: Latin 1 (01047)
+ *
+ */
+
+/*
+ * Table EBCDIC code page 1047 -> ISO/ANSI code page 819
+ *
+ * There are different mappings of LF/NEL on EBCDIC platforms:
+ * (cf. The Unicode Standard 4.0, chapter 5.8, pc_encoding.c)
+ *
+ * | LF | NEL |
+ * -------------|--------|--------|-
+ * ASCII | x0A | x85 |
+ * EBCDIC 37 | x25 | x15 |
+ * EBCDIC 1047 | x15 | x25 |
+ *
+ * '\n' is LF.
+ *
+ * Because x85 is forbidden as control character for new line in PDF
+ * we have to pay attention to this code (see e.g. pdc_ebcdic2pdfascii[_len]).
+ *
+ */
+
+#if PDF_CODEPAGE == 37
+
+/* Table EBCDIC code page 37 -> ISO/ANSI code page 819 */
+
+const pdc_byte ebcdic2ascii_table[257] =
+"\x00\x01\x02\x03\x9C\x09\x86\x7F\x97\x8D\x8E\x0B\x0C\x0D\x0E\x0F"
+"\x10\x11\x12\x13\x9D\x85\x08\x87\x18\x19\x92\x8F\x1C\x1D\x1E\x1F"
+"\x80\x81\x82\x83\x84\x0A\x17\x1B\x88\x89\x8A\x8B\x8C\x05\x06\x07"
+"\x90\x91\x16\x93\x94\x95\x96\x04\x98\x99\x9A\x9B\x14\x15\x9E\x1A"
+"\x20\xA0\xE2\xE4\xE0\xE1\xE3\xE5\xE7\xF1\xA2\x2E\x3C\x28\x2B\x7C"
+"\x26\xE9\xEA\xEB\xE8\xED\xEE\xEF\xEC\xDF\x21\x24\x2A\x29\x3B\xAC"
+"\x2D\x2F\xC2\xC4\xC0\xC1\xC3\xC5\xC7\xD1\xA6\x2C\x25\x5F\x3E\x3F"
+"\xF8\xC9\xCA\xCB\xC8\xCD\xCE\xCF\xCC\x60\x3A\x23\x40\x27\x3D\x22"
+"\xD8\x61\x62\x63\x64\x65\x66\x67\x68\x69\xAB\xBB\xF0\xFD\xFE\xB1"
+"\xB0\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\xAA\xBA\xE6\xB8\xC6\xA4"
+"\xB5\x7E\x73\x74\x75\x76\x77\x78\x79\x7A\xA1\xBF\xD0\xDD\xDE\xAE"
+"\x5E\xA3\xA5\xB7\xA9\xA7\xB6\xBC\xBD\xBE\x5B\x5D\xAF\xA8\xB4\xD7"
+"\x7B\x41\x42\x43\x44\x45\x46\x47\x48\x49\xAD\xF4\xF6\xF2\xF3\xF5"
+"\x7D\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\xB9\xFB\xFC\xF9\xFA\xFF"
+"\x5C\xF7\x53\x54\x55\x56\x57\x58\x59\x5A\xB2\xD4\xD6\xD2\xD3\xD5"
+"\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\xB3\xDB\xDC\xD9\xDA\x9F"
+"";
+
+/* Table ISO/ANSI code page 819 -> EBCDIC code page 37 */
+
+const pdc_byte ascii2ebcdic_table[257] =
+"\x00\x01\x02\x03\x37\x2D\x2E\x2F\x16\x05\x25\x0B\x0C\x0D\x0E\x0F"
+"\x10\x11\x12\x13\x3C\x3D\x32\x26\x18\x19\x3F\x27\x1C\x1D\x1E\x1F"
+"\x40\x5A\x7F\x7B\x5B\x6C\x50\x7D\x4D\x5D\x5C\x4E\x6B\x60\x4B\x61"
+"\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\x7A\x5E\x4C\x7E\x6E\x6F"
+"\x7C\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xD1\xD2\xD3\xD4\xD5\xD6"
+"\xD7\xD8\xD9\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xBA\xE0\xBB\xB0\x6D"
+"\x79\x81\x82\x83\x84\x85\x86\x87\x88\x89\x91\x92\x93\x94\x95\x96"
+"\x97\x98\x99\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xC0\x4F\xD0\xA1\x07"
+"\x20\x21\x22\x23\x24\x15\x06\x17\x28\x29\x2A\x2B\x2C\x09\x0A\x1B"
+"\x30\x31\x1A\x33\x34\x35\x36\x08\x38\x39\x3A\x3B\x04\x14\x3E\xFF"
+"\x41\xAA\x4A\xB1\x9F\xB2\x6A\xB5\xBD\xB4\x9A\x8A\x5F\xCA\xAF\xBC"
+"\x90\x8F\xEA\xFA\xBE\xA0\xB6\xB3\x9D\xDA\x9B\x8B\xB7\xB8\xB9\xAB"
+"\x64\x65\x62\x66\x63\x67\x9E\x68\x74\x71\x72\x73\x78\x75\x76\x77"
+"\xAC\x69\xED\xEE\xEB\xEF\xEC\xBF\x80\xFD\xFE\xFB\xFC\xAD\xAE\x59"
+"\x44\x45\x42\x46\x43\x47\x9C\x48\x54\x51\x52\x53\x58\x55\x56\x57"
+"\x8C\x49\xCD\xCE\xCB\xCF\xCC\xE1\x70\xDD\xDE\xDB\xDC\x8D\x8E\xDF"
+"";
+
+#endif /* PDF_CODEPAGE == 037 */
+
+#if PDF_CODEPAGE == 1047
+
+const pdc_byte ebcdic2ascii_table[257] =
+"\x00\x01\x02\x03\x9C\x09\x86\x7F\x97\x8D\x8E\x0B\x0C\x0D\x0E\x0F"
+"\x10\x11\x12\x13\x9D\x0A\x08\x87\x18\x19\x92\x8F\x1C\x1D\x1E\x1F"
+"\x80\x81\x82\x83\x84\x85\x17\x1B\x88\x89\x8A\x8B\x8C\x05\x06\x07"
+"\x90\x91\x16\x93\x94\x95\x96\x04\x98\x99\x9A\x9B\x14\x15\x9E\x1A"
+"\x20\xA0\xE2\xE4\xE0\xE1\xE3\xE5\xE7\xF1\xA2\x2E\x3C\x28\x2B\x7C"
+"\x26\xE9\xEA\xEB\xE8\xED\xEE\xEF\xEC\xDF\x21\x24\x2A\x29\x3B\x5E"
+"\x2D\x2F\xC2\xC4\xC0\xC1\xC3\xC5\xC7\xD1\xA6\x2C\x25\x5F\x3E\x3F"
+"\xF8\xC9\xCA\xCB\xC8\xCD\xCE\xCF\xCC\x60\x3A\x23\x40\x27\x3D\x22"
+"\xD8\x61\x62\x63\x64\x65\x66\x67\x68\x69\xAB\xBB\xF0\xFD\xFE\xB1"
+"\xB0\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\xAA\xBA\xE6\xB8\xC6\xA4"
+"\xB5\x7E\x73\x74\x75\x76\x77\x78\x79\x7A\xA1\xBF\xD0\x5B\xDE\xAE"
+"\xAC\xA3\xA5\xB7\xA9\xA7\xB6\xBC\xBD\xBE\xDD\xA8\xAF\x5D\xB4\xD7"
+"\x7B\x41\x42\x43\x44\x45\x46\x47\x48\x49\xAD\xF4\xF6\xF2\xF3\xF5"
+"\x7D\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\xB9\xFB\xFC\xF9\xFA\xFF"
+"\x5C\xF7\x53\x54\x55\x56\x57\x58\x59\x5A\xB2\xD4\xD6\xD2\xD3\xD5"
+"\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\xB3\xDB\xDC\xD9\xDA\x9F"
+"";
+
+/* ISO/ANSI code page 819 -> Table EBCDIC code page 1047 */
-void
-pdc_ebcdic2ascii(char *s)
-{
- (void) s;
-}
+const pdc_byte ascii2ebcdic_table[257] =
+"\x00\x01\x02\x03\x37\x2D\x2E\x2F\x16\x05\x15\x0B\x0C\x0D\x0E\x0F"
+"\x10\x11\x12\x13\x3C\x3D\x32\x26\x18\x19\x3F\x27\x1C\x1D\x1E\x1F"
+"\x40\x5A\x7F\x7B\x5B\x6C\x50\x7D\x4D\x5D\x5C\x4E\x6B\x60\x4B\x61"
+"\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\x7A\x5E\x4C\x7E\x6E\x6F"
+"\x7C\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xD1\xD2\xD3\xD4\xD5\xD6"
+"\xD7\xD8\xD9\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xAD\xE0\xBD\x5F\x6D"
+"\x79\x81\x82\x83\x84\x85\x86\x87\x88\x89\x91\x92\x93\x94\x95\x96"
+"\x97\x98\x99\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xC0\x4F\xD0\xA1\x07"
+"\x20\x21\x22\x23\x24\x25\x06\x17\x28\x29\x2A\x2B\x2C\x09\x0A\x1B"
+"\x30\x31\x1A\x33\x34\x35\x36\x08\x38\x39\x3A\x3B\x04\x14\x3E\xFF"
+"\x41\xAA\x4A\xB1\x9F\xB2\x6A\xB5\xBB\xB4\x9A\x8A\xB0\xCA\xAF\xBC"
+"\x90\x8F\xEA\xFA\xBE\xA0\xB6\xB3\x9D\xDA\x9B\x8B\xB7\xB8\xB9\xAB"
+"\x64\x65\x62\x66\x63\x67\x9E\x68\x74\x71\x72\x73\x78\x75\x76\x77"
+"\xAC\x69\xED\xEE\xEB\xEF\xEC\xBF\x80\xFD\xFE\xFB\xFC\xBA\xAE\x59"
+"\x44\x45\x42\x46\x43\x47\x9C\x48\x54\x51\x52\x53\x58\x55\x56\x57"
+"\x8C\x49\xCD\xCE\xCB\xCF\xCC\xE1\x70\xDD\xDE\xDB\xDC\x8D\x8E\xDF"
+"";
+#endif /* PDF_CODEPAGE == 1047 */
diff --git a/src/pdflib/pdcore/pc_ebcdic.h b/src/pdflib/pdcore/pc_ebcdic.h
index 5f8993f..1468bff 100644
--- a/src/pdflib/pdcore/pc_ebcdic.h
+++ b/src/pdflib/pdcore/pc_ebcdic.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_ebcdic.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_ebcdic.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* EBCDIC conversion routines
*
@@ -20,16 +20,11 @@
#define PC_EBCDIC_H
-void pdc_ebcdic2ascii(char *s);
-void pdc_ebcdic2ascii_len(char *s, size_t len);
-void pdc_ascii2ebcdic_len(char *s, size_t len);
-void pdc_ascii2ebcdic(char *s);
-void pdc_ascii2ebcdic_char(char *c);
-void pdc_ascii2ebcdic_int(int *i);
-void pdc_ebcdic2ascii_int(int *i);
-void pdc_ebcdic2ascii_byte(pdc_byte *c);
-void pdc_ebcdic2pdfascii(char *s);
-void pdc_ebcdic2pdfascii_len(char *s, size_t len);
+/* must be defined everywhere (see encoding "winansi_ebcdic") */
+#if !defined(PDF_CODEPAGE)
+#define PDF_CODEPAGE 37
+#endif
+
#endif /* PC_EBCDIC_H */
diff --git a/src/pdflib/pdcore/pc_encoding.c b/src/pdflib/pdcore/pc_encoding.c
index 3dfa390..c532ce2 100644
--- a/src/pdflib/pdcore/pc_encoding.c
+++ b/src/pdflib/pdcore/pc_encoding.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_encoding.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_encoding.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* PDFlib in-core encodings and basic encoding functions
*
@@ -242,6 +242,42 @@ static const pdc_core_encvector pdc_core_enc_ebcdic_winansi =
{
"ebcdic_winansi", 1,
{
+#if PDF_CODEPAGE == 37
+ 0x0000, 0x0001, 0x0002, 0x0003, 0x0153, 0x0009, 0x2020, 0x007F,
+ 0x2014, 0x0000, 0x017D, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
+ 0x0010, 0x0011, 0x0012, 0x0013, 0x0000, 0x2026, 0x0008, 0x2021,
+ 0x0018, 0x0019, 0x2019, 0x0000, 0x001C, 0x001D, 0x001E, 0x001F,
+ 0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x000A, 0x0017, 0x001B,
+ 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0005, 0x0006, 0x0007,
+ 0x0000, 0x2018, 0x0016, 0x201C, 0x201D, 0x2022, 0x2013, 0x0004,
+ 0x02DC, 0x2122, 0x0161, 0x203A, 0x0014, 0x0015, 0x017E, 0x001A,
+ 0x0020, 0x00A0, 0x00E2, 0x00E4, 0x00E0, 0x00E1, 0x00E3, 0x00E5,
+ 0x00E7, 0x00F1, 0x00A2, 0x002E, 0x003C, 0x0028, 0x002B, 0x007C,
+ 0x0026, 0x00E9, 0x00EA, 0x00EB, 0x00E8, 0x00ED, 0x00EE, 0x00EF,
+ 0x00EC, 0x00DF, 0x0021, 0x0024, 0x002A, 0x0029, 0x003B, 0x00AC,
+ 0x002D, 0x002F, 0x00C2, 0x00C4, 0x00C0, 0x00C1, 0x00C3, 0x00C5,
+ 0x00C7, 0x00D1, 0x00A6, 0x002C, 0x0025, 0x005F, 0x003E, 0x003F,
+ 0x00F8, 0x00C9, 0x00CA, 0x00CB, 0x00C8, 0x00CD, 0x00CE, 0x00CF,
+ 0x00CC, 0x0060, 0x003A, 0x0023, 0x0040, 0x0027, 0x003D, 0x0022,
+ 0x00D8, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
+ 0x0068, 0x0069, 0x00AB, 0x00BB, 0x00F0, 0x00FD, 0x00FE, 0x00B1,
+ 0x00B0, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070,
+ 0x0071, 0x0072, 0x00AA, 0x00BA, 0x00E6, 0x00B8, 0x00C6, 0x00A4,
+ 0x00B5, 0x007E, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078,
+ 0x0079, 0x007A, 0x00A1, 0x00BF, 0x00D0, 0x00DD, 0x00DE, 0x00AE,
+ 0x005E, 0x00A3, 0x00A5, 0x00B7, 0x00A9, 0x00A7, 0x00B6, 0x00BC,
+ 0x00BD, 0x00BE, 0x005B, 0x005D, 0x00AF, 0x00A8, 0x00B4, 0x00D7,
+ 0x007B, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
+ 0x0048, 0x0049, 0x00AD, 0x00F4, 0x00F6, 0x00F2, 0x00F3, 0x00F5,
+ 0x007D, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050,
+ 0x0051, 0x0052, 0x00B9, 0x00FB, 0x00FC, 0x00F9, 0x00FA, 0x00FF,
+ 0x005C, 0x00F7, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058,
+ 0x0059, 0x005A, 0x00B2, 0x00D4, 0x00D6, 0x00D2, 0x00D3, 0x00D5,
+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
+ 0x0038, 0x0039, 0x00B3, 0x00DB, 0x00DC, 0x00D9, 0x00DA, 0x0178,
+#endif /* PDF_CODEPAGE == 037 */
+
+#if PDF_CODEPAGE == 1047
0x0000, 0x0001, 0x0002, 0x0003, 0x0153, 0x0009, 0x2020, 0x007F,
0x2014, 0x0000, 0x017D, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
0x0010, 0x0011, 0x0012, 0x0013, 0x0000, 0x000A, 0x0008, 0x2021,
@@ -274,6 +310,7 @@ static const pdc_core_encvector pdc_core_enc_ebcdic_winansi =
0x0059, 0x005A, 0x00B2, 0x00D4, 0x00D6, 0x00D2, 0x00D3, 0x00D5,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x00B3, 0x00DB, 0x00DC, 0x00D9, 0x00DA, 0x0178,
+#endif /* PDF_CODEPAGE == 1047 */
}
};
@@ -1341,25 +1378,46 @@ pdc_new_encoding(pdc_core *pdc, const char *name)
return(ev);
}
-
void
-pdc_cleanup_encoding(pdc_core *pdc, pdc_encodingvector *ev)
+pdc_refresh_encoding(pdc_core *pdc, pdc_encodingvector *ev, const char *name)
{
int slot;
- if (ev->apiname)
+ if (ev->apiname != NULL)
+ {
pdc_free(pdc, ev->apiname);
+ ev->apiname = NULL;
+ }
- if (ev->flags & PDC_ENC_ALLOCCHARS)
+ if (name != NULL)
{
- for (slot = 0; slot < 256; slot++)
- if (ev->chars[slot])
- pdc_free(pdc, ev->chars[slot]);
+ ev->apiname = pdc_strdup(pdc, name);
+ }
+
+ for (slot = 0; slot < 256; slot++)
+ {
+ if (ev->flags & PDC_ENC_ALLOCCHARS && ev->chars[slot] != NULL)
+ pdc_free(pdc, ev->chars[slot]);
+
+ ev->codes[slot] = 0;
+ ev->chars[slot] = NULL;
+ ev->given[slot] = 0;
}
- if (ev->sortedslots)
+ if (ev->sortedslots != NULL)
+ {
pdc_free(pdc, ev->sortedslots);
+ ev->sortedslots = NULL;
+ }
+ ev->nslots = 0;
+ ev->flags = 0;
+}
+
+void
+pdc_cleanup_encoding(pdc_core *pdc, pdc_encodingvector *ev)
+{
+ pdc_refresh_encoding(pdc, ev, NULL);
pdc_free(pdc, ev);
}
diff --git a/src/pdflib/pdcore/pc_encoding.h b/src/pdflib/pdcore/pc_encoding.h
index 633e1a7..7cacbfb 100644
--- a/src/pdflib/pdcore/pc_encoding.h
+++ b/src/pdflib/pdcore/pc_encoding.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_encoding.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_encoding.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Encoding data structures and routines
*
@@ -231,6 +231,8 @@ pdc_priv_glyphtab *pdc_get_pglyphtab_ptr(pdc_core *pdc);
void pdc_init_encoding(pdc_core *pdc, pdc_encodingvector *ev,
const char *name);
pdc_encodingvector *pdc_new_encoding(pdc_core *pdc, const char *name);
+void pdc_refresh_encoding(pdc_core *pdc, pdc_encodingvector *ev,
+ const char *name);
void pdc_cleanup_encoding(pdc_core *pdc, pdc_encodingvector *ev);
pdc_encodingvector *pdc_copy_encoding(pdc_core *pdc, pdc_encodingvector *evfrom,
const char *name);
diff --git a/src/pdflib/pdcore/pc_exports.h b/src/pdflib/pdcore/pc_exports.h
index c062d70..e23210e 100644
--- a/src/pdflib/pdcore/pc_exports.h
+++ b/src/pdflib/pdcore/pc_exports.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_exports.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_exports.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Header for CodeWarrior to create a PDFlib DLL
*
diff --git a/src/pdflib/pdcore/pc_file.c b/src/pdflib/pdcore/pc_file.c
index 35c67ed..18b9a9d 100644
--- a/src/pdflib/pdcore/pc_file.c
+++ b/src/pdflib/pdcore/pc_file.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_file.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_file.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Various file routines
*
@@ -30,7 +30,9 @@
#include <windows.h>
#include <process.h>
#include <io.h>
+#define PDC_FILENO _fileno
#else
+#define PDC_FILENO fileno
#if defined(MAC)
#include <MacErrors.h>
#else
@@ -51,6 +53,37 @@
#include <ssdef.h>
#endif
+#if defined(WIN32) && !defined(__BORLANDC__)
+
+#define PDC_MAXFILEHANDLES 2048
+
+/* set a new maximum for the number of simultaneously open files.
+ * if return = -1 error occured
+ */
+int
+pdc_set_maxfilehandles(pdc_core *pdc, int maxfps)
+{
+ const char *stemp = pdc_errprintf(pdc, "%d", maxfps);
+
+ if (maxfps < _IOB_ENTRIES)
+ pdc_error(pdc, PDC_E_IO_TOOFEW_REQFILEHDLS, stemp,
+ pdc_errprintf(pdc, "%d", _IOB_ENTRIES), 0, 0);
+
+ if (maxfps > PDC_MAXFILEHANDLES)
+ pdc_error(pdc, PDC_E_IO_TOOMANY_REQFILEHDLS, stemp,
+ pdc_errprintf(pdc, "%d", PDC_MAXFILEHANDLES), 0, 0);
+
+ return _setmaxstdio(maxfps);
+}
+
+int
+pdc_get_maxfilehandles(void)
+{
+ return _getmaxstdio();
+}
+
+#endif
+
/* platform independent wrapper functions for 64-bit file handling.
*/
int
@@ -76,10 +109,10 @@ pdc__fseek(FILE *fp, pdc_off_t offset, int whence)
{
pdc_off_t pos, len;
- pos = _telli64(fileno(fp));
- _lseeki64(fileno(fp), 0, SEEK_END);
- len = _telli64(fileno(fp));
- _lseeki64(fileno(fp), pos, SEEK_SET);
+ pos = _telli64(PDC_FILENO(fp));
+ _lseeki64(PDC_FILENO(fp), 0, SEEK_END);
+ len = _telli64(PDC_FILENO(fp));
+ _lseeki64(PDC_FILENO(fp), pos, SEEK_SET);
len += offset;
return fsetpos(fp, &len);
@@ -113,30 +146,56 @@ pdc__ftell(FILE *fp)
#endif
}
+
+/* we had troubles writing a block of 80 MB via network on a windows platform.
+** this could be fixed by breaking down the entire block into 1 MB pieces.
+*/
+#undef PDC_BLOCKSIZE
+#define PDC_BLOCKSIZE 1048576
+
size_t
pdc__fread(void *ptr, size_t size, size_t nmemb, FILE *fp)
{
- return fread(ptr, size, nmemb, fp);
+ char * cp = (char *) ptr;
+ size_t total = size * nmemb;
+ size_t left = total;
+ size_t n, r;
+
+ do
+ {
+ n = (left < PDC_BLOCKSIZE) ? left : PDC_BLOCKSIZE;
+ r = fread(cp, 1, n, fp);
+
+ left -= r;
+ cp += r;
+ } while (r == n && left != 0);
+
+ return total - left;
}
size_t
pdc__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *fp)
{
- return fwrite(ptr, size, nmemb, fp);
-}
+ const char *cp = (const char *) ptr;
+ size_t total = size * nmemb;
+ size_t left = total;
+ size_t n, r;
-int
-pdc__fgetc(FILE *fp)
-{
- return fgetc(fp);
-}
+ do
+ {
+ n = (left < PDC_BLOCKSIZE) ? left : PDC_BLOCKSIZE;
+ r = fwrite(cp, 1, n, fp);
-int
-pdc__feof(FILE *fp)
-{
- return feof(fp);
+ left -= r;
+ cp += r;
+ } while (r == n && left != 0);
+
+ return total - left;
}
+#undef PDC_BLOCKSIZE
+
+
struct pdc_file_s
{
pdc_core *pdc; /* pdcore struct */
@@ -289,7 +348,7 @@ pdc_get_fopen_errnum(pdc_core *pdc, int errnum)
#endif
#ifdef EMACOSERR
case EMACOSERR:
-#if defined(MAC)
+#if defined(MAC) && defined(PDF_ALLOW_MAC_DEPR_FUNCS)
switch (__MacOSErrNo)
{
@@ -341,6 +400,9 @@ pdc_get_fopen_errnum(pdc_core *pdc, int errnum)
{
return outnum;
}
+#else
+ outnum = errnum;
+ break;
#endif
break;
#endif
@@ -386,7 +448,7 @@ pdc_get_fopen_errnum(pdc_core *pdc, int errnum)
#endif
default:
- /* observed on Solaris */
+ /* observed on Solaris because of thread unsafe errno */
if (errno == 0)
pdc_error(pdc, PDC_E_INT_BADERRNO, 0, 0, 0, 0);
@@ -408,9 +470,11 @@ pdc_set_fopen_errmsg(pdc_core *pdc, int errnum, const char *qualifier,
const char *stemp2 = NULL;
int errno1 = errno;
-#if defined(EMACOSERR) && defined(MAC)
+#if defined(EMACOSERR)
+#if defined(MAC) && defined(PDF_ALLOW_MAC_DEPR_FUNCS)
errno1 = (int) __MacOSErrNo;
#endif
+#endif
errnum = pdc_get_fopen_errnum(pdc, errnum);
if (errnum == PDC_E_IO_RDOPEN)
@@ -436,6 +500,31 @@ pdc_set_fopen_errmsg(pdc_core *pdc, int errnum, const char *qualifier,
pdc_set_errmsg(pdc, errnum, qualifier, filename, stemp1, stemp2);
}
+void
+pdc_set_fwrite_errmsg(pdc_core *pdc, const char *filename)
+{
+ const char *stemp1 = NULL;
+ const char *stemp2 = NULL;
+ int errno1 = errno;
+ int errnum = PDC_E_IO_WRITE;
+
+#if defined(EMACOSERR)
+#if defined(MAC) && defined(PDF_ALLOW_MAC_DEPR_FUNCS)
+ errno1 = (int) __MacOSErrNo;
+#endif
+#endif
+
+ stemp1 = pdc_errprintf(pdc, "%d", errno1);
+
+#ifdef PDC_HAS_STRERROR
+ stemp2 = strerror(errno1);
+ if (stemp2 != NULL)
+ errnum = PDC_E_IO_WRITE_CODETEXT;
+#endif
+
+ pdc_set_errmsg(pdc, errnum, filename, stemp1, stemp2, 0);
+}
+
pdc_bool
pdc_check_fopen_errmsg(pdc_core *pdc, pdc_bool requested)
{
@@ -452,7 +541,7 @@ pdc_logg_openclose(pdc_core *pdc, FILE *fp, pdc_bool opened)
{
#if defined(WIN32)
errno2 = (int) GetLastError();
-#elif defined(MAC)
+#elif defined(MAC) && defined(PDF_ALLOW_MAC_DEPR_FUNCS)
errno2 = __MacOSErrNo;
#endif
pdc_logg(pdc, "\t%p", fp);
@@ -462,7 +551,7 @@ pdc_logg_openclose(pdc_core *pdc, FILE *fp, pdc_bool opened)
pdc_logg(pdc, " closed");
#if PDC_FILENO_EXISTS
if (fp != NULL && opened)
- pdc_logg(pdc, ", fileno=%d", fileno(fp));
+ pdc_logg(pdc, ", fileno=%d", PDC_FILENO(fp));
#endif
pdc_logg(pdc, ", errno=%d", errno1);
if (errno2 != 0)
@@ -519,6 +608,7 @@ filelen = len;
* will be deleted and a new char pointer to the Latin-1 string will
* be returned. Otherwise an execption will be thrown.
*
+ * Returned string is temporary allocated.
*/
char *
pdc_check_filename(pdc_core *pdc, char *filename)
@@ -526,7 +616,7 @@ pdc_check_filename(pdc_core *pdc, char *filename)
#if !defined(PDC_UNICODE_FILENAME)
char *ffname = pdc_utf8_to_hostbytes(pdc, pdc->honorlang, filename);
- pdc_free(pdc, filename);
+ pdc_free_tmp(pdc, filename);
if (ffname == NULL)
pdc_error(pdc, PDC_E_IO_UNSUPP_UNINAME, 0, 0, 0, 0);
filename = (char *) ffname;
@@ -535,6 +625,9 @@ pdc_check_filename(pdc_core *pdc, char *filename)
return filename;
}
+/*
+ * Returned string is temporary allocated.
+ */
char *
pdc_get_filename(pdc_core *pdc, char *filename)
{
@@ -543,7 +636,7 @@ pdc_get_filename(pdc_core *pdc, char *filename)
#if defined(PDC_UNICODE_FILENAME)
static const char fn[] = "pdc_get_filename";
- ffname = pdc_strdup_ext(pdc, filename, 0, fn);
+ ffname = pdc_strdup_ext(pdc, filename, PDC_CONV_TMPALLOC, fn);
#else
ffname = pdc_hostbytes_to_utf8(pdc, pdc->honorlang, filename);
#endif
@@ -553,11 +646,13 @@ pdc_get_filename(pdc_core *pdc, char *filename)
/*
* pdc_convert_filename_ext converts a file name as string of name type
- * (see function pdc_convert_name) to a [EBCDIC-]UTF-8 string with or
+ * (see function pdc_convert_name_ext) to a [EBCDIC-]UTF-8 string with or
* without a BOM. If the compiler doesn't allow Unicode filenames
* (see define PDC_UNICODE_FILENAME) the filename is Latin-1 encoded
* if possible or an exception will be thrown.
*
+ * Returned string is temporary allocated.
+ *
*/
const char *
pdc_convert_filename_ext(pdc_core *pdc, const char *filename, int len,
@@ -571,6 +666,9 @@ pdc_convert_filename_ext(pdc_core *pdc, const char *filename, int len,
if (filename == NULL)
pdc_error(pdc, PDC_E_ILLARG_EMPTY, paramname, 0, 0, 0);
+ /* temporary allocation will be enforced */
+ flags |= PDC_CONV_TMPALLOC;
+
fname = pdc_convert_name_ext(pdc, filename, len, enc, codepage, flags);
if (fname == NULL || *fname == '\0')
@@ -585,12 +683,13 @@ pdc_convert_filename_ext(pdc_core *pdc, const char *filename, int len,
#endif
}
- outfilename = pdc_errprintf(pdc, "%s", &fname[i]);
- pdc_free(pdc, fname);
-
+ outfilename = &fname[i];
return outfilename;
}
+/*
+ * Returned string is temporary allocated.
+ */
const char *
pdc_convert_filename(pdc_core *pdc, const char *filename, int len,
const char *paramname, pdc_bool withbom)
@@ -613,16 +712,21 @@ FILE *
pdc_fopen_logg(pdc_core *pdc, const char *filename, const char *mode)
{
FILE *fp = NULL;
+ int i = 0;
+
#if defined(PDC_UNICODE_FILENAME)
pdc_byte *outfilename = NULL;
pdc_text_format nameformat = PDC_UTF8;
pdc_text_format targetnameformat = pdc_utf16;
- int len = (int) strlen(filename);
+ int len = (int) pdc_strlen(filename);
int outlen = 0;
- /* convert filename from UTF-8 to UTF-16 or Latin-1 */
+ if (pdc_is_utf16be_unicode(filename))
+ nameformat = pdc_utf16be;
+
+ /* convert filename from UTF-8 / UTF-16BE to UTF-16 or Latin-1 */
pdc_convert_string(pdc, nameformat, 0, NULL, (pdc_byte *) filename, len,
&targetnameformat, NULL, &outfilename, &outlen,
PDC_CONV_TRYBYTES | PDC_CONV_NOBOM, pdc_true);
@@ -634,7 +738,6 @@ pdc_fopen_logg(pdc_core *pdc, const char *filename, const char *mode)
else
{
wchar_t wmode[8];
- int i;
len = (int) strlen(mode);
for (i = 0; i < len; i++)
@@ -649,11 +752,17 @@ pdc_fopen_logg(pdc_core *pdc, const char *filename, const char *mode)
#else
(void) pdc;
- fp = fopen(filename, mode);
+ /* due to honorlang, codeset of LANG: UTF-8 */
+ if (pdc_is_utf8_bytecode(filename))
+ i = 3;
+
+ fp = fopen(&filename[i], mode);
#endif
pdc_logg_openclose(pdc, fp, pdc_true);
+
+
return fp;
}
@@ -664,6 +773,9 @@ pdc_fopen(pdc_core *pdc, const char *filename, const char *qualifier,
static const char fn[] = "pdc_fopen";
pdc_file *sfp;
+ /* reset error number */
+ pdc_set_errmsg(pdc, 0, 0, 0, 0, 0);
+
sfp = (pdc_file *) pdc_calloc(pdc, sizeof(pdc_file), fn);
/* initialize */
@@ -804,43 +916,53 @@ pdc_freadall(pdc_file *sfp, size_t *filelen, pdc_bool *ismem)
return result;
}
-static int
-pdc_fgetc_e(pdc_file *sfp)
-{
- int c = pdc_fgetc(sfp);
- return c;
-}
-
char *
pdc_fgetline(char *s, int size, pdc_file *sfp)
{
int i, c;
- c = pdc_fgetc_e(sfp);
+
+ c = pdc_fgetc(sfp);
if (c == EOF)
return NULL;
+
size--;
for (i = 0; i < size; i++)
{
- if (c == '\n' || c == '\r' || c == EOF) break;
+ if (c == '\n' || c == '\r')
+ break;
s[i] = (char) c;
- c = pdc_fgetc_e(sfp);
+
+ c = pdc_fgetc(sfp);
+ if (c == EOF)
+ {
+ i++;
+ break;
+ }
+
}
s[i] = 0;
/* Skip windows line end \r\n */
if (c == '\r')
{
- c = pdc_fgetc_e(sfp);
+ c = pdc_fgetc(sfp);
+ if (c != EOF)
+ {
+ if (c != '\n')
+ {
+ if (sfp->fp)
+ {
- if (c != '\n' && c != EOF)
- {
- if (sfp->fp)
- ungetc(c, sfp->fp);
- else
- pdc_fseek(sfp, -1, SEEK_CUR);
- }
+ ungetc(c, sfp->fp);
+ }
+ else
+ {
+ pdc_fseek(sfp, -1, SEEK_CUR);
+ }
+ }
+ }
}
return s;
}
@@ -947,7 +1069,17 @@ pdc_fwrite(const void *ptr, size_t size, size_t nmemb, pdc_file *sfp)
size_t poslen, nbytes = 0;
if (sfp->fp)
- return pdc__fwrite(ptr, size, nmemb, sfp->fp);
+ {
+ size_t total = pdc__fwrite(ptr, size, nmemb, sfp->fp);
+
+ if (total < size * nmemb)
+ {
+ pdc_set_fwrite_errmsg(sfp->pdc, sfp->filename);
+ PDC_RETHROW(sfp->pdc);
+ }
+
+ return total;
+ }
nbytes = size * nmemb;
if (sfp->pos + nbytes > sfp->limit)
@@ -1059,13 +1191,17 @@ pdc_fclose(pdc_file *sfp)
/*
* Concatenating a directory name with a file base name to a full valid
- * file name. On MVS platforms an extension at the end of basename
- * will be discarded.
+ * file name of maximal length PDC_FILENAMELEN - 1.
+ *
+ * On MVS platforms an extension at the end of basename will be discarded.
*/
void
-pdc_file_fullname(const char *dirname, const char *basename, char *fullname)
+pdc_file_fullname(pdc_core *pdc, const char *dirname, const char *basename,
+ char *fullname)
{
const char *pathsep = PDC_PATHSEP;
+ const char *stemp = NULL;
+ size_t len = 0;
#ifdef MVS
pdc_bool lastterm = pdc_false;
@@ -1073,6 +1209,10 @@ pdc_file_fullname(const char *dirname, const char *basename, char *fullname)
if (!dirname || !dirname[0])
{
+ len += strlen(basename);
+ if (len >= PDC_FILENAMELEN)
+ goto PDC_FILE_ERROR;
+
strcpy(fullname, basename);
}
else
@@ -1084,6 +1224,10 @@ pdc_file_fullname(const char *dirname, const char *basename, char *fullname)
strcat(fullname, PDC_FILEQUOT);
#endif
+ len += strlen(dirname);
+ if (len >= PDC_FILENAMELEN)
+ goto PDC_FILE_ERROR;
+
strcat(fullname, dirname);
#ifdef VMS
@@ -1094,6 +1238,10 @@ pdc_file_fullname(const char *dirname, const char *basename, char *fullname)
pathsep = "";
#endif
+ len += strlen(pathsep) + strlen(basename);
+ if (len >= PDC_FILENAMELEN)
+ goto PDC_FILE_ERROR;
+
strcat(fullname, pathsep);
strcat(fullname, basename);
@@ -1120,11 +1268,25 @@ pdc_file_fullname(const char *dirname, const char *basename, char *fullname)
}
if (lastterm)
{
+ len += strlen(PDC_PATHTERM) + strlen(PDC_FILEQUOT);
+ if (len >= PDC_FILENAMELEN)
+ goto PDC_FILE_ERROR;
+
strcat(fullname, PDC_PATHTERM);
strcat(fullname, PDC_FILEQUOT);
}
}
#endif
+
+ return;
+
+ PDC_FILE_ERROR:
+
+ if (!dirname || !dirname[0])
+ stemp = pdc_errprintf(pdc, "%s", basename);
+ else
+ stemp = pdc_errprintf(pdc, "%s%s%s", dirname, pathsep, basename);
+ pdc_error(pdc, PDC_E_IO_TOOLONG_FULLNAME, stemp, 0, 0, 0);
}
#define EXTRA_SPACE 32 /* extra space for separators, FILEQUOT etc. */
@@ -1142,7 +1304,7 @@ pdc_file_fullname_mem(pdc_core *pdc, const char *dirname, const char *basename)
len += EXTRA_SPACE;
fullname = (char *) pdc_malloc(pdc, len, fn);
- pdc_file_fullname(dirname, basename, fullname);
+ pdc_file_fullname(pdc, dirname, basename, fullname);
return fullname;
}
@@ -1178,11 +1340,10 @@ const char *
pdc_file_strip_dirs(const char *pathname)
{
const char *scan = pathname + strlen(pathname);
- char charsep = PDC_PATHSEP[0];
while (pathname <= --scan)
{
- if (*scan == charsep)
+ if (*scan == PDC_PATHSEP[0] || *scan == PDC_PATHSEP_ALT[0])
return scan + 1;
}
@@ -1197,11 +1358,10 @@ char *
pdc_file_strip_name(char *pathname)
{
char *scan = pathname + strlen(pathname);
- char charsep = PDC_PATHSEP[0];
while (pathname <= --scan)
{
- if (*scan == charsep)
+ if (*scan == PDC_PATHSEP[0] || *scan == PDC_PATHSEP_ALT[0])
{
*scan = 0;
break;
@@ -1463,7 +1623,7 @@ pdc_temppath(
if (!outbuf)
outbuf = pdc_file_fullname_mem(pdc, dirname, name);
else
- pdc_file_fullname(dirname, name, outbuf);
+ pdc_file_fullname(pdc, dirname, name, outbuf);
return outbuf;
}
@@ -1474,7 +1634,7 @@ pdc_fwrite_ascii(pdc_core *pdc, const char *str, size_t len, FILE *fp)
{
(void) pdc;
- len = fwrite(str, 1, len, fp);
+ len = pdc__fwrite(str, 1, len, fp);
return len;
@@ -1499,11 +1659,12 @@ pdc_write_file(
if (sfp != NULL)
{
wlen = pdc_fwrite_ascii(pdc, content, len, sfp->fp);
- pdc_fclose(sfp);
- if (wlen != len)
+ if (wlen < len)
{
- pdc_set_errmsg(pdc, PDC_E_IO_WRITE, filename, 0, 0, 0);
+ pdc_set_fwrite_errmsg(pdc, filename);
+ PDC_RETHROW(pdc);
}
+ pdc_fclose(sfp);
}
@@ -1512,37 +1673,4 @@ pdc_write_file(
-#if defined(MAC) || defined(MACOSX)
-
-#ifdef PDF_TARGET_API_MAC_CARBON
-
-/* Construct an FSSpec from a Posix path name. Only required for
- * Carbon (host font support and file type/creator).
- */
-
-OSStatus
-FSPathMakeFSSpec(const UInt8 *path, FSSpec *spec)
-{
- OSStatus result;
- FSRef ref;
-
- /* convert the POSIX path to an FSRef */
- result = FSPathMakeRef(path, &ref, NULL);
-
- if (result != noErr)
- return result;
-
- /* and then convert the FSRef to an FSSpec */
- result = FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL, spec, NULL);
-
- return result;
-}
-
-
-#else
-
-
-#endif /* !PDF_TARGET_API_MAC_CARBON */
-
-#endif /* (defined(MAC) || defined(MACOSX)) */
diff --git a/src/pdflib/pdcore/pc_file.h b/src/pdflib/pdcore/pc_file.h
index d1a6163..3e1159f 100644
--- a/src/pdflib/pdcore/pc_file.h
+++ b/src/pdflib/pdcore/pc_file.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_file.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_file.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Definitions for file routines
*
@@ -19,29 +19,6 @@
#ifndef PC_FILE_H
#define PC_FILE_H
-#if (defined(MAC) || defined(MACOSX))
-
-#include <Files.h>
-
-#ifdef PDF_TARGET_API_MAC_CARBON
-
-OSStatus FSMakePath(SInt16 volRefNum, SInt32 dirID, ConstStr255Param name,
- UInt8 *path, UInt32 maxPathSize);
-
-OSStatus FSPathMakeFSSpec(const UInt8 *path, FSSpec *spec);
-
-#else
-
-#include <Aliases.h>
-
-OSErr FSpGetFullPath(const FSSpec *spec, short *fullPathLength,
- Handle *fullPath);
-
-OSErr FSpLocationFromFullPath(short fullPathLength,
- const void *fullPath, FSSpec *spec);
-
-#endif /* !PDF_TARGET_API_MAC_CARBON */
-#endif /* (defined(MAC) || defined(MACOSX)) */
#define PDC_FILENAMELEN 1024 /* maximum file name length */
@@ -74,19 +51,26 @@ typedef struct pdc_file_s pdc_file;
/* pc_file.c */
+#if defined(WIN32)
+int pdc_set_maxfilehandles(pdc_core *pdc, int maxfps);
+int pdc_get_maxfilehandles(void);
+#endif
+
int pdc__fseek(FILE *fp, pdc_off_t offset, int whence);
pdc_off_t pdc__ftell(FILE *fp);
size_t pdc__fread(void *ptr, size_t size, size_t nmemb, FILE *fp);
size_t pdc__fwrite(const void *ptr, size_t size, size_t nmemb,
FILE *fp);
-int pdc__fgetc(FILE *fp);
-int pdc__feof(FILE *fp);
+
+#define pdc__fgetc(fp) fgetc(fp)
+#define pdc__feof(fp) feof(fp)
FILE *pdc_get_fileptr(pdc_file *sfp);
pdc_core *pdc_get_pdcptr(pdc_file *sfp);
int pdc_get_fopen_errnum(pdc_core *pdc, int errnum);
void pdc_set_fopen_errmsg(pdc_core *pdc, int errnum, const char *qualifier,
const char *filename);
+void pdc_set_fwrite_errmsg(pdc_core *pdc, const char *filename);
pdc_bool pdc_check_fopen_errmsg(pdc_core *pdc, pdc_bool requested);
void *pdc_read_file(pdc_core *pdc, FILE *fp, pdc_off_t *o_filelen,
@@ -127,8 +111,8 @@ int pdc_fgetc(pdc_file *sfp);
int pdc_feof(pdc_file *sfp);
void pdc_fclose(pdc_file *sfp);
void pdc_fclose_logg(pdc_core *pdc, FILE *fp);
-void pdc_file_fullname(const char *dirname, const char *basename,
- char *fullname);
+void pdc_file_fullname(pdc_core *pdc, const char *dirname,
+ const char *basename, char *fullname);
char *pdc_file_fullname_mem(pdc_core *pdc, const char *dirname,
const char *basename);
char *pdc_file_concat(pdc_core *pdc, const char *dirname, const char *basename,
diff --git a/src/pdflib/pdcore/pc_generr.h b/src/pdflib/pdcore/pc_generr.h
index b1651ff..e1b535a 100644
--- a/src/pdflib/pdcore/pc_generr.h
+++ b/src/pdflib/pdcore/pc_generr.h
@@ -1,7 +1,7 @@
/*---------------------------------------------------------------------------*
| PDFlib - A library for generating PDF on the fly |
+---------------------------------------------------------------------------+
- | Copyright (c) 1997-2006 Thomas Merz and PDFlib GmbH. All rights reserved. |
+ | Copyright (c) 1997-2009 Thomas Merz and PDFlib GmbH. All rights reserved. |
+---------------------------------------------------------------------------+
| |
| This software is subject to the PDFlib license. It is NOT in the |
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_generr.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_generr.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* PDCORE error messages
*
@@ -111,15 +111,22 @@ gen(2, 1046, IO_WROPEN_SV,
gen(0, 1048, IO_UNSUPP_UNINAME,
"Unicode file names are not supported on this platform")
+gen(0, 1049, IO_UNSUPP_PDFUNINAME,
+ "Unicode file names require PDF 1.7")
+
gen(1, 1050, IO_COMPRESS, "Compression error ($1)")
gen(0, 1052, IO_NOBUFFER, "Don't fetch buffer contents when writing to file")
gen(2, 1054, IO_BADFORMAT, "'$1' does not appear to be a $2 file")
+gen(2, 1055, IO_WRITE,
+ "Error writing data to file '$1' (system error code $2)")
+
gen(1, 1056, IO_READ, "Error reading data from file '$1'")
-gen(1, 1057, IO_WRITE, "Error writing data to file '$1'")
+gen(3, 1057, IO_WRITE_CODETEXT,
+ "Error writing data to file '$1' (system error code $2: $3)")
gen(3, 1058, IO_ILLSYNTAX, "$1file '$2': Syntax error in line $3")
@@ -134,7 +141,15 @@ gen(2, 1064, IO_RDOPEN_QU,
gen(2, 1066, IO_WROPEN_QU,
"Couldn't open $1file '$2' for writing (quota exceeded)")
+gen(1, 1068, IO_TOOLONG_FULLNAME,
+ "Fully specified file name too long (>= 1024 bytes): '$1'")
+
+gen(2, 1080, IO_TOOFEW_REQFILEHDLS,
+ "Too few requested file handles $1 (< $2)")
+
+gen(2, 1081, IO_TOOMANY_REQFILEHDLS,
+ "Too many requested file handles $1 (> $2)")
/* -------------------------------------------------------------------- */
@@ -171,11 +186,14 @@ gen(1, 1111, ILLARG_FLOAT_NAN,
gen(1, 1112, ILLARG_UTF, "Illegal UTF-$1 sequence in string")
*/
-gen(2, 1114, ILLARG_MATRIX, "Matrix [$1] is degenerate")
+gen(2, 1114, ILLARG_MATRIX, "Matrix [$1] is degenerated")
gen(2, 1116, ILLARG_TOOLONG,
"String parameter '$1' is limited to $2 characters")
+gen(2, 1117, ILLARG_STRINGLEN,
+ "String length has bad value $1 (minimum 0, maximum $2)")
+
gen(2, 1118, ILLARG_HANDLE,
"Handle parameter or option of type '$1' has bad value $2")
@@ -185,6 +203,8 @@ gen(1, 1120, ILLARG_NONNEG, "Parameter '$1' must not be negative")
gen(1, 1122, ILLARG_LANG_CODE, "Unsupported language code '$1'")
+gen(2, 1124, ILLARG_TOOMANY, "Too many '$1' parameters (maximum $2)")
+
/* -------------------------------------------------------------------- */
/* Parameters and values (12xx) */
@@ -204,7 +224,7 @@ gen(2, 1210, PAR_SCOPE_GET, "Can't get parameter '$1' in scope '$2'")
gen(2, 1212, PAR_SCOPE_SET, "Can't set parameter '$1' in scope '$2'")
-gen(2, 1214, PAR_VERSION, "Parameter '$1' requires PDF $2 or above")
+gen(2, 1214, PAR_VERSION, "Parameter '$1' requires PDF $2")
gen(1, 1216, PAR_ILLKEY, "Illegal attempt to set parameter '$1'")
@@ -219,6 +239,8 @@ gen(1, 1220, PAR_UNSUPPKEY, "Unknown or unsupported key '$1'")
gen(1, 1250, PAR_ILLSECT, "Illegal section '$1'")
+gen(1, 1260, PAR_NODATA, "No data supplied ($1)")
+
@@ -317,13 +339,19 @@ gen(2, 1501, CONV_ILLUTF16SUR, "Invalid UTF-16 surrogate pair <U+$1,U+$2>")
gen(0, 1502, CONV_MEMOVERFLOW, "Out of memory in UTF string conversion")
+gen(0, 1503, CONV_ILLUTF32,
+ "Invalid UTF-32 string (byte count not a multiple of four)")
+
gen(1, 1504, CONV_ILLUTF, "Invalid UTF-$1 string")
-gen(1, 1505, CONV_ILLUTF32, "Invalid UTF-32 character U+$1")
+gen(1, 1505, CONV_ILLUTF32CHAR, "Invalid UTF-32 character U+$1")
gen(1, 1506, CONV_ILL_MBTEXTSTRING,
"Invalid text string according to the current codepage '$1'")
+gen(2, 1507, CONV_ILLUTF8SEQU,
+ "Invalid UTF-8 sequence $1 at byte index $2")
+
gen(1, 1508, CONV_UNSUPP_MBTEXTFORM,
"Multi byte text format (codepage $1) not supported on this platform")
@@ -393,6 +421,8 @@ gen(0, 1907, INT_ILLFLOAT, "Bad floating point number for PDF")
gen(2, 1908, INT_BADFORMAT, "Unknown vsprintf() format '$1' ($2)")
+gen(0, 1909, INT_FORMOVERFLOW, "Buffer overflow in formatting function")
+
gen(1, 1910, INT_ALLOC0,
"Tried to allocate 0 or negative number of bytes in function $1")
@@ -429,6 +459,8 @@ gen(1, 1940, INT_BADERRNO,
gen(1, 1950, INT_LONGNAME_MISSING, "Long name is missing at index $1")
+gen(1, 1970, INT_ILLDOCTYPE, "Illegal document type '$1'")
+
@@ -441,4 +473,3 @@ gen(1, 1950, INT_LONGNAME_MISSING, "Long name is missing at index $1")
-
diff --git a/src/pdflib/pdcore/pc_geom.c b/src/pdflib/pdcore/pc_geom.c
index c52cdf4..2f350a4 100644
--- a/src/pdflib/pdcore/pc_geom.c
+++ b/src/pdflib/pdcore/pc_geom.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_geom.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_geom.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Various geometry routines
*
diff --git a/src/pdflib/pdcore/pc_geom.h b/src/pdflib/pdcore/pc_geom.h
index 629157d..111fe8e 100644
--- a/src/pdflib/pdcore/pc_geom.h
+++ b/src/pdflib/pdcore/pc_geom.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_geom.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_geom.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* PDFlib core geometry utilities
*
diff --git a/src/pdflib/pdcore/pc_md5.c b/src/pdflib/pdcore/pc_md5.c
index a9d209a..6190752 100644
--- a/src/pdflib/pdcore/pc_md5.c
+++ b/src/pdflib/pdcore/pc_md5.c
@@ -1,4 +1,4 @@
-/* $Id: pc_md5.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_md5.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* PDFlib MD5 message digest routines
*
diff --git a/src/pdflib/pdcore/pc_md5.h b/src/pdflib/pdcore/pc_md5.h
index 619b47d..c20597f 100644
--- a/src/pdflib/pdcore/pc_md5.h
+++ b/src/pdflib/pdcore/pc_md5.h
@@ -1,4 +1,4 @@
-/* $Id: pc_md5.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_md5.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Header file for the PDFlib MD5 message digest routines
*
diff --git a/src/pdflib/pdcore/pc_optparse.c b/src/pdflib/pdcore/pc_optparse.c
index dee18ad..cf41c8b 100644
--- a/src/pdflib/pdcore/pc_optparse.c
+++ b/src/pdflib/pdcore/pc_optparse.c
@@ -10,16 +10,20 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_optparse.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_optparse.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Parser options routines
*
*/
#include "pc_util.h"
+#include "pc_file.h"
#include "pc_geom.h"
#include "pc_ctype.h"
+#define PDC_PCBITS_SIZE 32
+#define PDC_MAX_PERCENTS (8 * PDC_PCBITS_SIZE)
+
/* result of an option */
struct pdc_resopt_s
{
@@ -29,7 +33,7 @@ struct pdc_resopt_s
void *val; /* list of parsed values */
char *origval; /* original value as string */
int flags; /* flags */
- int pcmask; /* percentage mask */
+ char pcbits[PDC_PCBITS_SIZE]; /* percentage bits */
int currind; /* index of current option */
int lastind; /* index of last option */
pdc_bool isutf8; /* optionlist UTF-8 encoded */
@@ -94,11 +98,22 @@ int
pdc_get_keycode(const char *keyword, const pdc_keyconn *keyconn)
{
int i;
- for (i = 0; keyconn[i].word != 0; i++)
+
+ for (i = 0; keyconn[i].word != NULL; i++)
{
- if (!strcmp(keyword, keyconn[i].word))
+ const char *s1 = keyword;
+ const char *s2 = keyconn[i].word;
+
+ for (; *s1; ++s1, ++s2)
+ {
+ if (*s1 != *s2)
+ break;
+ }
+
+ if (*s1 == *s2)
return keyconn[i].code;
}
+
return PDC_KEY_NOTFOUND;
}
@@ -106,11 +121,22 @@ int
pdc_get_keycode_ci(const char *keyword, const pdc_keyconn *keyconn)
{
int i;
- for (i = 0; keyconn[i].word != 0; i++)
+
+ for (i = 0; keyconn[i].word != NULL; i++)
{
- if (!pdc_stricmp(keyword, keyconn[i].word))
+ const char *s1 = keyword;
+ const char *s2 = keyconn[i].word;
+
+ for (; *s1; ++s1, ++s2)
+ {
+ if (pdc_tolower(*s1) != pdc_tolower(*s2))
+ break;
+ }
+
+ if (pdc_tolower(*s1) == pdc_tolower(*s2))
return keyconn[i].code;
}
+
return PDC_KEY_NOTFOUND;
}
@@ -118,9 +144,10 @@ int
pdc_get_keycode_unique(const char *keyword, const pdc_keyconn *keyconn)
{
int i, j;
+
size_t len = strlen(keyword);
- for (i = 0; keyconn[i].word != 0; i++)
+ for (i = 0; keyconn[i].word != NULL; i++)
{
if (!strncmp(keyword, keyconn[i].word, len))
{
@@ -130,6 +157,7 @@ pdc_get_keycode_unique(const char *keyword, const pdc_keyconn *keyconn)
return keyconn[i].code;
}
}
+
return PDC_KEY_NOTFOUND;
}
@@ -214,11 +242,13 @@ const char *
pdc_get_keyword(int keycode, const pdc_keyconn *keyconn)
{
int i;
- for (i = 0; keyconn[i].word != 0; i++)
+
+ for (i = 0; keyconn[i].word != NULL; i++)
{
if (keycode == keyconn[i].code)
return keyconn[i].word;
}
+
return NULL;
}
@@ -226,11 +256,22 @@ const char *
pdc_get_int_keyword(const char *keyword, const pdc_keyconn *keyconn)
{
int i;
- for (i = 0; keyconn[i].word != 0; i++)
+
+ for (i = 0; keyconn[i].word != NULL; i++)
{
- if (!pdc_stricmp(keyword, keyconn[i].word))
+ const char *s1 = keyword;
+ const char *s2 = keyconn[i].word;
+
+ for (; *s1; ++s1, ++s2)
+ {
+ if (pdc_tolower(*s1) != pdc_tolower(*s2))
+ break;
+ }
+
+ if (pdc_tolower(*s1) == pdc_tolower(*s2))
return keyconn[i].word;
}
+
return NULL;
}
@@ -309,10 +350,10 @@ pdc_parse_optionlist(pdc_core *pdc, const char *optlist,
{
static const char *fn = "pdc_parse_optionlist";
pdc_bool logg5 = pdc_logg_is_enabled(pdc, 5, trc_optlist);
- const char *stemp1 = NULL, *stemp2 = NULL, *stemp3 = NULL;
+ const char *stemp1 = NULL, *stemp2 = NULL, *stemp3 = NULL, *s1, *s2;
char **items = NULL, *keyword = NULL;
char **values = NULL, *value = NULL, **strings = NULL;
- int i, j, k, nd, is, iss, it, iv;
+ int i, j, k, nd, is, iss, it, iv, icoord;
int numdef, nitems = 0, nvalues, ncoords = 0, errcode = 0;
void *resval;
double dz, maxval;
@@ -375,15 +416,31 @@ pdc_parse_optionlist(pdc_core *pdc, const char *optlist,
/* loop over all option list elements */
for (is = 0; is < nitems; is++)
{
+ pdc_bool isequal = pdc_false;
+
/* search keyword */
boolval = pdc_undef;
keyword = items[is];
for (it = 0; it < numdef; it++)
{
+ s1 = keyword;
+ s2 = defopt[it].name;
+
+ /* if (!pdc_stricmp(keyword, defopt[it].name))
+ * isequal = pdc_true;
+ */
+ for (; *s1; ++s1, ++s2)
+ {
+ if (pdc_tolower(*s1) != pdc_tolower(*s2))
+ break;
+ }
+ if (pdc_tolower(*s1) == pdc_tolower(*s2))
+ isequal = pdc_true;
+
/* special handling for booleans */
if (defopt[it].type == pdc_booleanlist)
{
- if (!pdc_stricmp(keyword, defopt[it].name) ||
+ if (isequal ||
(keyword[1] != 0 &&
!pdc_stricmp(&keyword[2], defopt[it].name)))
{
@@ -398,7 +455,7 @@ pdc_parse_optionlist(pdc_core *pdc, const char *optlist,
boolval = pdc_false;
break;
}
- else
+ else if (isequal)
{
boolval = pdc_true;
break;
@@ -407,7 +464,8 @@ pdc_parse_optionlist(pdc_core *pdc, const char *optlist,
}
}
- if (!pdc_stricmp(keyword, defopt[it].name)) break;
+ if (isequal)
+ break;
}
if (logg5)
@@ -516,6 +574,14 @@ pdc_parse_optionlist(pdc_core *pdc, const char *optlist,
goto PDC_OPT_SYNTAXERROR;
}
+ /* deprecated option since PDFlib 7 */
+ if (dopt->flags & PDC_OPT_PDFLIB_7)
+ {
+ pdc_logg_cond(pdc, 2, trc_api,
+ "[Option \"%s\" is deprecated since PDFlib 7]\n",
+ keyword);
+ }
+
/* option already exists */
if (resopt[it].num)
{
@@ -615,6 +681,9 @@ pdc_parse_optionlist(pdc_core *pdc, const char *optlist,
resopt[it].num = nvalues;
resopt[it].currind = it;
+ if (dopt->flags & PDC_OPT_PERCENT)
+ memset(resopt[it].pcbits, 0, PDC_PCBITS_SIZE);
+
if (logg5)
pdc_logg(pdc, "{");
@@ -767,6 +836,7 @@ pdc_parse_optionlist(pdc_core *pdc, const char *optlist,
iz = PDC_KEY_NOTFOUND;
j = 0;
+ icoord = ncoords;
for (i = 0; i < np; i++)
{
char *sk = strings[i];
@@ -788,19 +858,16 @@ pdc_parse_optionlist(pdc_core *pdc, const char *optlist,
if (sk[k] == '%')
{
sk[k] = 0;
- if (ncoords < 32)
+ if (ncoords < PDC_MAX_PERCENTS)
{
- resopt[it].pcmask |= (1L <<ncoords);
+ pdc_setbit(resopt[it].pcbits,
+ ncoords);
}
else
{
errcode = PDC_E_OPT_TOOMANYPERCVALS;
}
}
- else
- {
- resopt[it].pcmask &= ~(1L << ncoords);
- }
}
retval = pdc_str2double(sk, &dz);
@@ -808,7 +875,7 @@ pdc_parse_optionlist(pdc_core *pdc, const char *optlist,
{
errcode = PDC_E_OPT_ILLNUMBER;
}
- else if (resopt[it].pcmask & (1L << ncoords))
+ else if (pdc_getbit(resopt[it].pcbits, ncoords))
{
if (dopt->flags & PDC_OPT_PERCRANGE)
{
@@ -838,7 +905,15 @@ pdc_parse_optionlist(pdc_core *pdc, const char *optlist,
}
if (dopt->flags & PDC_OPT_CLOSEPOLY)
+ {
pl->p[pl->np - 1] = pl->p[0];
+ if (pdc_getbit(resopt[it].pcbits, icoord))
+ pdc_setbit(resopt[it].pcbits, ncoords);
+ ncoords++;
+ if (pdc_getbit(resopt[it].pcbits, icoord + 1))
+ pdc_setbit(resopt[it].pcbits, ncoords);
+ ncoords++;
+ }
}
pdc_cleanup_stringlist(pdc, strings);
}
@@ -915,19 +990,15 @@ pdc_parse_optionlist(pdc_core *pdc, const char *optlist,
if (value[i] == '%')
{
value[i] = 0;
- if (iv < 32)
+ if (iv < PDC_MAX_PERCENTS)
{
- resopt[it].pcmask |= (1L << iv);
+ pdc_setbit(resopt[it].pcbits, iv);
}
else
{
errcode = PDC_E_OPT_TOOMANYPERCVALS;
}
}
- else
- {
- resopt[it].pcmask &= ~(1L << iv);
- }
}
case pdc_stringhandle:
@@ -966,7 +1037,7 @@ pdc_parse_optionlist(pdc_core *pdc, const char *optlist,
}
else
{
- if (resopt[it].pcmask & (1L << iv))
+ if (pdc_getbit(resopt[it].pcbits, iv))
{
if (dopt->flags & PDC_OPT_PERCRANGE)
{
@@ -1221,6 +1292,7 @@ pdc_get_optvalues(const char *keyword, pdc_resopt *resopt,
if (resopt)
{
+ const char *s1, *s2;
int i, cmp;
int lo = 0;
int hi = resopt[0].numdef;
@@ -1228,7 +1300,16 @@ pdc_get_optvalues(const char *keyword, pdc_resopt *resopt,
while (lo < hi)
{
i = (lo + hi) / 2;
- cmp = strcmp(keyword, resopt[i].defopt->name);
+
+ s1 = keyword;
+ s2 = resopt[i].defopt->name;
+
+ for (; *s1; ++s1, ++s2)
+ {
+ if (*s1 != *s2)
+ break;
+ }
+ cmp = (*s1 - *s2);
/* keyword found */
if (cmp == 0)
@@ -1319,8 +1400,8 @@ pdc_is_lastopt_percent(pdc_resopt *resopt, int ind)
{
int i = resopt[0].lastind;
- if (i > -1 && resopt[i].num < 32)
- return (resopt[i].pcmask & (1L << ind)) ? pdc_true : pdc_false;
+ if (i > -1 && resopt[i].num < PDC_MAX_PERCENTS)
+ return pdc_getbit(resopt[i].pcbits, ind) ? pdc_true : pdc_false;
else
return pdc_false;
}
@@ -1368,6 +1449,26 @@ pdc_get_opt_utf8strings(pdc_core *pdc, const char *keyword, pdc_resopt *resopt,
return ns;
}
+const char *
+pdc_get_opt_filename(pdc_core *pdc, const char *keyword, pdc_resopt *resopts)
+{
+ const char *filename = NULL;
+ char **strlist;
+
+ if (pdc_get_optvalues(keyword, resopts, NULL, &strlist))
+ {
+ pdc_bool isutf8 = pdc_is_lastopt_utf8(resopts);
+ int flags = PDC_CONV_WITHBOM;
+
+ if (isutf8)
+ flags |= PDC_CONV_ISUTF8;
+
+ filename = pdc_convert_filename(pdc, strlist[0], 0, keyword, flags);
+ }
+
+ return filename;
+}
+
void
pdc_cleanup_optionlist(pdc_core *pdc, pdc_resopt *resopt)
{
diff --git a/src/pdflib/pdcore/pc_optparse.h b/src/pdflib/pdcore/pc_optparse.h
index ac9e6f2..7c2f680 100644
--- a/src/pdflib/pdcore/pc_optparse.h
+++ b/src/pdflib/pdcore/pc_optparse.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_optparse.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_optparse.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Definitions for option parser routines
*
@@ -196,7 +196,7 @@ struct pdc_defopt_s
{
const char *name; /* name of option keyword */
pdc_opttype type; /* type of option */
- int flags; /* flags (see below) */
+ unsigned int flags; /* flags (see below) */
int minnum; /* permitted minimal number of values */
int maxnum; /* permitted maximal number of values */
double minval; /* minimal permitted value / length of string */
@@ -208,49 +208,51 @@ struct pdc_defopt_s
{NULL, pdc_booleanlist, 0L, 0, 0, 0.0, 0.0, NULL}
#define PDC_OPT_NONE (0) /* no flag specified */
-#define PDC_OPT_NOZERO (1L<<0) /* zero value not allowed */
-#define PDC_OPT_NOSPACES (1L<<1) /* white spaces in strings not allowed */
-#define PDC_OPT_REQUIRED (1L<<2) /* option is required */
-#define PDC_OPT_BUILDOR (1L<<3) /* build an OR bit pattern by keycodes */
-#define PDC_OPT_INTLIST (1L<<4) /* keylist is list of allowed integers */
-#define PDC_OPT_IGNOREIF1 (1L<<5) /* option is ignored if previous option is
+#define PDC_OPT_NOZERO (1U<<0) /* zero value not allowed */
+#define PDC_OPT_NOSPACES (1U<<1) /* white spaces in strings not allowed */
+#define PDC_OPT_REQUIRED (1U<<2) /* option is required */
+#define PDC_OPT_BUILDOR (1U<<3) /* build an OR bit pattern by keycodes */
+#define PDC_OPT_INTLIST (1U<<4) /* keylist is list of allowed integers */
+#define PDC_OPT_IGNOREIF1 (1U<<5) /* option is ignored if previous option is
* specified */
-#define PDC_OPT_IGNOREIF2 (1L<<6) /* option is ignored if either of
+#define PDC_OPT_IGNOREIF2 (1U<<6) /* option is ignored if either of
* previous two options is specified */
-#define PDC_OPT_UNSUPP (1L<<8) /* option is not supported in this
+#define PDC_OPT_UNSUPP (1U<<8) /* option is not supported in this
* configuration */
-#define PDC_OPT_REQUIRIF1 (1L<<9) /* option is required if previous option is
+#define PDC_OPT_REQUIRIF1 (1U<<9) /* option is required if previous option is
* specified */
-#define PDC_OPT_REQUIRIF2 (1L<<10) /* option is required if either of
+#define PDC_OPT_REQUIRIF2 (1U<<10) /* option is required if either of
* previous two options is specified */
-#define PDC_OPT_EVENNUM (1L<<11) /* array has even number of elements */
-#define PDC_OPT_ODDNUM (1L<<12) /* array has odd number of elements */
+#define PDC_OPT_EVENNUM (1U<<11) /* array has even number of elements */
+#define PDC_OPT_ODDNUM (1U<<12) /* array has odd number of elements */
-/* member "compatibility" of pdc_clientdata_s must be specified (1L<<13) ... */
-#define PDC_OPT_PDC_1_3 (1L<<PDC_1_3) /* compatibility PDC_1_3 */
-#define PDC_OPT_PDC_1_4 (1L<<PDC_1_4) /* compatibility PDC_1_4 */
-#define PDC_OPT_PDC_1_5 (1L<<PDC_1_5) /* compatibility PDC_1_5 */
-#define PDC_OPT_PDC_1_6 (1L<<PDC_1_6) /* compatibility PDC_1_6 */
-#define PDC_OPT_PDC_1_7 (1L<<PDC_1_7) /* compatibility PDC_1_7 */
+/* member "compatibility" of pdc_clientdata_s must be specified (1U<<13) ... */
+#define PDC_OPT_PDC_1_3 (1U<<PDC_1_3) /* compatibility PDC_1_3 */
+#define PDC_OPT_PDC_1_4 (1U<<PDC_1_4) /* compatibility PDC_1_4 */
+#define PDC_OPT_PDC_1_5 (1U<<PDC_1_5) /* compatibility PDC_1_5 */
+#define PDC_OPT_PDC_1_6 (1U<<PDC_1_6) /* compatibility PDC_1_6 */
+#define PDC_OPT_PDC_1_7 (1U<<PDC_1_7) /* compatibility PDC_1_7 */
-#define PDC_OPT_CASESENS (1L<<20) /* case-sensitive keywords */
-#define PDC_OPT_PERCENT (1L<<21) /* number maybe with percent sign (123%) */
-#define PDC_OPT_DUPORIGVAL (1L<<22) /* duplicate original value */
-#define PDC_OPT_SUBOPTLIST (1L<<23) /* string list is a suboptlist */
-#define PDC_OPT_CONVUTF8 (1L<<24) /* string has to be converted to UTF-8 */
-#define PDC_OPT_ISBOX (1L<<25) /* polyline is a box (four coordinates) */
-#define PDC_OPT_PERCRANGE (1L<<26) /* number only in the range 0% - 100% */
+#define PDC_OPT_CASESENS (1U<<20) /* case-sensitive keywords */
+#define PDC_OPT_PERCENT (1U<<21) /* number maybe with percent sign (123%) */
+#define PDC_OPT_DUPORIGVAL (1U<<22) /* duplicate original value */
+#define PDC_OPT_SUBOPTLIST (1U<<23) /* string list is a suboptlist */
+#define PDC_OPT_CONVUTF8 (1U<<24) /* string has to be converted to UTF-8 */
+#define PDC_OPT_ISBOX (1U<<25) /* polyline is a box (four coordinates) */
+#define PDC_OPT_PERCRANGE (1U<<26) /* number only in the range 0% - 100% */
-#define PDC_OPT_KEYLIST1 (1L<<27) /* use key list only for first element */
-#define PDC_OPT_CLOSEPOLY (1L<<28) /* close polyline, minimal vertices = 3 */
+#define PDC_OPT_KEYLIST1 (1U<<27) /* use key list only for first element */
+#define PDC_OPT_CLOSEPOLY (1U<<28) /* close polyline, minimal vertices = 3 */
+
+#define PDC_OPT_PDFLIB_7 (1U<<31) /* deprecated since PDFlib 7 */
/* flags for single result */
-#define PDC_OPT_SAVEALL (1L<<0) /* save all pointers */
-#define PDC_OPT_SAVE1ELEM (1L<<1) /* save only first string list element */
-#define PDC_OPT_SAVEORIG (1L<<2) /* save original value string */
+#define PDC_OPT_SAVEALL (1U<<0) /* save all pointers */
+#define PDC_OPT_SAVE1ELEM (1U<<1) /* save only first string list element */
+#define PDC_OPT_SAVEORIG (1U<<2) /* save original value string */
/* flag for UTF-8 value */
-#define PDC_OPT_ISUTF8 (1L<<9) /* string[list] is UTF-8 */
+#define PDC_OPT_ISUTF8 (1U<<9) /* string[list] is UTF-8 */
/* key word not found */
#define PDC_KEY_NOTFOUND -1234567890
@@ -284,6 +286,8 @@ pdc_bool pdc_is_lastopt_percent(pdc_resopt *resopt, int ind);
pdc_bool pdc_is_lastopt_utf8(pdc_resopt *resopt);
int pdc_get_opt_utf8strings(pdc_core *pdc, const char *keyword,
pdc_resopt *resopt, int flags, char ***strings);
+const char *pdc_get_opt_filename(pdc_core *pdc, const char *keyword,
+ pdc_resopt *resopts);
void pdc_cleanup_optionlist(pdc_core *pdc, pdc_resopt *resopt);
void pdc_cleanup_optstringlist(pdc_core *pdc, char **stringlist, int ns);
const char *pdc_get_handletype(pdc_opttype type);
diff --git a/src/pdflib/pdcore/pc_output.c b/src/pdflib/pdcore/pc_output.c
index b1607c5..ae0def7 100644
--- a/src/pdflib/pdcore/pc_output.c
+++ b/src/pdflib/pdcore/pc_output.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_output.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_output.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* PDFlib output routines
*
@@ -33,7 +33,7 @@
#include <winbase.h>
#endif
-#if defined(MAC) || defined (MACOSX)
+#if !defined(PDF_MAC_NOCORESERVICES) && (defined(MAC) || defined (MACOSX))
/*
* Setting the file type requires either Carbon or InterfaceLib/Classic.
@@ -41,15 +41,13 @@
* the code for setting the file type and creator.
*/
-#if !defined(MACOSX) || defined(PDF_TARGET_API_MAC_CARBON)
+#if !defined(MACOSX) || (defined(PDF_TARGET_API_MAC_CARBON) && \
+ defined(PDF_ALLOW_MAC_DEPR_FUNCS))
#define PDF_FILETYPE_SUPPORTED
-#endif
-
-#ifdef PDF_FILETYPE_SUPPORTED
#include <Files.h>
#endif
-#endif /* defined(MAC) || defined (MACOSX) */
+#endif /* !PDF_MAC_NOCORESERVICES && (MAC || MACOSX) */
#ifdef HAVE_LIBZ
#include "zlib.h"
@@ -82,7 +80,8 @@ struct pdc_output_s {
FILE *fp; /* output file stream */
#if defined(MVS) || defined(MVS_TEST)
- int blocksize; /* file record size */
+ const char *fopenparams; /* additional fopen() parameters */
+ int recordsize; /* file record size */
#endif
/* client-supplied data sink procedure */
@@ -104,6 +103,14 @@ struct pdc_output_s {
void *opaque; /* this will be used to store PDF *p */
};
+/* ----------- service function to get PDF version string -------------- */
+
+const char *
+pdc_get_pdfversion(pdc_core *pdc, int compatibility)
+{
+ return pdc_errprintf(pdc, "%d.%d", compatibility / 10, compatibility % 10);
+}
+
/* --------------------- PDFlib stream handling ----------------------- */
void *
@@ -164,14 +171,14 @@ pdc_init_stream(
{
static const char fn[] = "pdc_init_stream";
-#if defined(MAC) || defined(MACOSX)
+#if (defined(MAC) || defined(MACOSX)) && defined(PDF_FILETYPE_SUPPORTED)
#if !defined(TARGET_API_MAC_CARBON) || defined(__MWERKS__)
FCBPBRec fcbInfo;
Str32 name;
#endif /* TARGET_API_MAC_CARBON */
FInfo fInfo;
FSSpec fSpec;
-#endif /* defined(MAC) || defined(MACOSX) */
+#endif /* (MAC || MACOSX) && PDF_FILETYPE_SUPPORTED */
/*
* This may be left over from the previous run. We deliberately
@@ -229,29 +236,42 @@ pdc_init_stream(
{
out->fp = stdout;
#if !defined(__MWERKS__) && (defined(WIN32) || defined(OS2))
-#if defined WINCE
- _setmode(fileno(stdout), _O_BINARY);
+#if !defined(__BORLANDC__) && !defined(OS2)
+ _setmode(_fileno(stdout), _O_BINARY);
#else
setmode(fileno(stdout), O_BINARY);
-#endif /* !WINCE */
+#endif /* !__BORLANDC__ && !OS2 */
#endif
}
else
{
#endif /* !MAC */
+ char fopenparams[200]; /* sufficient */
#if defined(MVS) || defined(MVS_TEST)
- out->fp = pdc_fopen_logg(out->pdc, filename,
- (out->blocksize <= 1) ? WRITEMODE_V : WRITEMODE);
+ if (out->fopenparams != (char *) 0)
+ {
+ strcpy(fopenparams, WRITEMODE);
+ strcat(fopenparams, ",");
+ strcat(fopenparams, out->fopenparams);
+ }
+ else if (out->recordsize <= 1)
+ {
+ strcpy(fopenparams, WRITEMODE_V);
+ }
+ else
+ {
+ strcpy(fopenparams, WRITEMODE);
+ }
#else
- out->fp = pdc_fopen_logg(out->pdc, filename, WRITEMODE);
+ strcpy(fopenparams, WRITEMODE);
#endif
+ out->fp = pdc_fopen_logg(out->pdc, filename, fopenparams);
if (out->fp == NULL)
return pdc_false;
-#ifdef PDF_FILETYPE_SUPPORTED
-#if defined(MAC) || defined(MACOSX)
+#if (defined(MAC) || defined(MACOSX)) && defined(PDF_FILETYPE_SUPPORTED)
if (!pdc->ptfrun)
{
/* set the proper type and creator for the output file */
@@ -260,7 +280,6 @@ pdc_init_stream(
if (FSPathMakeFSSpec((const UInt8 *) filename, &fSpec) == noErr)
{
FSpGetFInfo(&fSpec, &fInfo);
-
fInfo.fdType = 'PDF ';
fInfo.fdCreator = 'CARO';
FSpSetFInfo(&fSpec, &fInfo);
@@ -283,8 +302,7 @@ pdc_init_stream(
}
#endif /* !defined(TARGET_API_MAC_CARBON) || defined(__MWERKS__) */
}
-#endif /* defined(MAC) || defined(MACOSX) */
-#endif /* PDF_FILETYPE_SUPPORTED */
+#endif /* (MAC || MACOSX) && PDF_FILETYPE_SUPPORTED */
#if !((defined(MAC) || defined (MACOSX)) && defined(__MWERKS__))
}
@@ -550,7 +568,8 @@ pdc_init_outctl(pdc_outctl *oc)
oc->writeproc = 0;
oc->flush = pdc_flush_page;
#if defined(MVS) || defined(MVS_TEST)
- oc->blocksize = 0;
+ oc->fopenparams = 0;
+ oc->recordsize = 0;
#endif
} /* pdc_init_outctl */
@@ -577,7 +596,8 @@ pdc_init_output(
out->opaque = opaque;
out->lastobj = 0;
#if defined(MVS) || defined(MVS_TEST)
- out->blocksize = oc->blocksize;
+ out->fopenparams = oc->fopenparams;
+ out->recordsize = oc->recordsize;
#endif
if (out->file_offset == NULL) {
@@ -776,67 +796,83 @@ void
pdc_put_pdffilename(pdc_output *out, const char *text, int len)
{
static const char *fn = "pdc_put_pdffilename";
+ pdc_byte *btext = (pdc_byte *) text;
+ pdc_bool isuni = pdc_is_utf16be_unicode(btext);
char *ttext;
+ pdc_byte c, cp, cpp;
+ int i, ia = 0, j = 0;
-#if defined(WIN32) || defined(MAC)
- int i, j = 0, k = 0;
-#endif
+ ttext = (char *) pdc_calloc(out->pdc, (size_t) (len + 4), fn);
- if (!len)
- len = (int) strlen(text);
-
- ttext = (char *) pdc_malloc(out->pdc, (size_t) (len + 4), fn);
- strcpy(ttext, text);
-
-#if defined(WIN32)
-
- /* absolute path name */
- if (strchr(ttext, PDF_COLON) != NULL || text[0] == PDF_BACKSLASH)
+ if (isuni)
{
- ttext[j] = PDF_SLASH;
- j++;
+ ttext[0] = PDF_BOM0;
+ ttext[1] = PDF_BOM1;
+ ia = 2;
+ j = 2;
}
- for (i = k; i < len; i++)
+
+ /* absolute path name:
+ * r:\pdfdocs\spec.pdf -> /r/pdfdocs/spec.pdf
+ * pclib/eng:\pdfdocs\spec.pdf -> /pclib/eng/pdfdocs/spec.pdf
+ */
+ cp = 0x7F;
+ for (i = ia; i < len; i++)
{
- if (text[i] == PDF_BACKSLASH)
+ c = btext[i];
+ if (c == PDF_COLON && (!isuni || cp == 0))
+ {
+ if (isuni)
+ {
+ ttext[j] = 0;
+ j++;
+ }
ttext[j] = PDF_SLASH;
- else if (text[i] == PDF_COLON)
- continue;
- else
- ttext[j] = text[i];
- j++;
- }
- len = j;
+ j++;
-#elif defined(MAC)
-
- /* absolute path name */
- if (text[0] != PDF_COLON)
- {
- ttext[j] = PDF_SLASH;
- j++;
- }
- else
- {
- k = 1;
+ break;
+ }
+ cp = c;
}
- for (i = k; i < len; i++)
+
+ cp = 0x7F;
+ cpp = 0x7F;
+ for (i = ia; i < len; i++)
{
- if (text[i] == PDF_COLON)
- ttext[j] = PDF_SLASH;
- else
- ttext[j] = text[i];
+ c = btext[i];
+
+ if ((c == PDF_BACKSLASH || c == PDF_SLASH || c == PDF_COLON) &&
+ (!isuni || cp == 0))
+ {
+ /* convert to slash, but avoid multiple slashes */
+ if (cpp != PDF_SLASH)
+ {
+ c = PDF_SLASH;
+ }
+ else
+ {
+ if (isuni)
+ j--;
+ continue;
+ }
+ }
+
+ ttext[j] = c;
j++;
+
+ cp = c;
+ if (c)
+ cpp = c;
}
- len = j;
-#endif
+ len = j;
pdc_put_pdfstring(out, ttext, len);
pdc_free(out->pdc, ttext);
}
+
/* --------------------------- Streams --------------------------- */
void
@@ -1016,11 +1052,11 @@ pdc_write_eof(pdc_output *out)
#if defined(MVS) || defined(MVS_TEST)
int i, k;
- if (out->blocksize > 1)
+ if (out->recordsize > 1)
{
- if ((i = (pdc_tell_out(out) + 6) % out->blocksize) != 0)
+ if ((i = (pdc_tell_out(out) + 6) % out->recordsize) != 0)
{
- for (k = 0; k < out->blocksize - i - 1; ++k)
+ for (k = 0; k < out->recordsize - i - 1; ++k)
pdc_putc(out, PDF_SPACE);
pdc_putc(out, PDF_NEWLINE);
@@ -1075,8 +1111,6 @@ pdc_write_trailer(
/* ---------------------- High-level output functions ---------------------- */
-#define PDC_LINEBUFLEN 4048 /* len of line output buffer */
-
/*
* Write a native encoded string to the output.
*/
@@ -1113,7 +1147,7 @@ pdc_putc(pdc_output *out, const char c)
void
pdc_printf(pdc_output *out, const char *fmt, ...)
{
- char buf[PDC_LINEBUFLEN];
+ char buf[PDC_GEN_BUFSIZE];
va_list ap;
va_start(ap, fmt);
diff --git a/src/pdflib/pdcore/pc_output.h b/src/pdflib/pdcore/pc_output.h
index 61a5697..d0e669c 100644
--- a/src/pdflib/pdcore/pc_output.h
+++ b/src/pdflib/pdcore/pc_output.h
@@ -10,16 +10,40 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_output.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_output.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
- * PDFlib output routines
+ * PDFlib output defines and routines
*
*/
#ifndef PC_OUTPUT_H
#define PC_OUTPUT_H
-/* --------------------------- General --------------------------- */
+/* Define to test special MVS output features */
+#undef MVS_TEST
+
+/* -------------------- some ASCII characters and strings ------------- */
+
+#define PDF_NEWLINE ((char) 0x0A) /* ASCII '\n' */
+#define PDF_RETURN ((char) 0x0D) /* ASCII '\r' */
+#define PDF_SPACE ((char) 0x20) /* ASCII ' ' */
+#define PDF_HASH ((char) 0x23) /* ASCII '#' */
+#define PDF_PARENLEFT ((char) 0x28) /* ASCII '(' */
+#define PDF_PARENRIGHT ((char) 0x29) /* ASCII ')' */
+#define PDF_PLUS ((char) 0x2B) /* ASCII '+' */
+#define PDF_SLASH ((char) 0x2F) /* ASCII '/' */
+#define PDF_COLON ((char) 0x3A) /* ASCII ':' */
+#define PDF_BACKSLASH ((char) 0x5C) /* ASCII '\\' */
+
+#define PDF_A ((char) 0x41) /* ASCII 'A' */
+#define PDF_n ((char) 0x6E) /* ASCII 'n' */
+#define PDF_r ((char) 0x72) /* ASCII 'r' */
+
+#define PDF_STRING_0123456789ABCDEF \
+ "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x41\x42\x43\x44\x45\x46"
+
+
+/* ------------------------ some PDF constant -------------------------- */
/* Acrobat viewers change absolute values < 1/65536 to zero */
#define PDF_SMALLREAL (0.000015)
@@ -34,31 +58,54 @@
/* maximum capacity of an array, in elements */
#define PDF_MAXARRAYSIZE (8191)
+/* maximum capacity of a text string in content stream for Tj, in bytes
+ * PDF Reference, TABLE C.1: 32767
+ * But an error will occur: "Token type not recognized"
+ */
+#define PDF_MAXTEXTSIZE (32763)
+
/* maximum capacity of a string, in bytes */
#define PDF_MAXSTRINGSIZE (65535)
/* maximum capacity of indirect objects */
#define PDF_MAXINDOBJS (8388607)
-/* some ASCII characters and strings, deliberately defined as hex/oct codes */
+/* Acrobat limit for page dimensions */
+#define PDF_ACRO_MINPAGE (3.0) /* 1/24 inch = 0.106 cm */
+#define PDF_ACRO_MAXPAGE (14400.0) /* 200 inch = 508 cm */
-#define PDF_NEWLINE ((char) 0x0A) /* ASCII '\n' */
-#define PDF_RETURN ((char) 0x0D) /* ASCII '\r' */
-#define PDF_SPACE ((char) 0x20) /* ASCII ' ' */
-#define PDF_HASH ((char) 0x23) /* ASCII '#' */
-#define PDF_PARENLEFT ((char) 0x28) /* ASCII '(' */
-#define PDF_PARENRIGHT ((char) 0x29) /* ASCII ')' */
-#define PDF_PLUS ((char) 0x2B) /* ASCII '+' */
-#define PDF_SLASH ((char) 0x2F) /* ASCII '/' */
-#define PDF_COLON ((char) 0x3A) /* ASCII ':' */
-#define PDF_BACKSLASH ((char) 0x5C) /* ASCII '\\' */
+/* PDF versions */
+#define PDC_1_1 11 /* PDF 1.1 = Acrobat 2 */
+#define PDC_1_2 12 /* PDF 1.2 = Acrobat 3 */
+#define PDC_1_3 13 /* PDF 1.3 = Acrobat 4 */
+#define PDC_1_4 14 /* PDF 1.4 = Acrobat 5 */
+#define PDC_1_5 15 /* PDF 1.5 = Acrobat 6 */
+#define PDC_1_6 16 /* PDF 1.6 = Acrobat 7 */
+#define PDC_1_7 17 /* PDF 1.7 = Acrobat 8 */
+#define PDC_X_X_LAST 17
-#define PDF_A ((char) 0x41) /* ASCII 'A' */
-#define PDF_n ((char) 0x6E) /* ASCII 'n' */
-#define PDF_r ((char) 0x72) /* ASCII 'r' */
-#define PDF_STRING_0123456789ABCDEF \
- "\060\061\062\063\064\065\066\067\070\071\101\102\103\104\105\106"
+/* ------------------- some defines for special PDFs ----------------------- */
+
+
+
+
+/* ------------------- some special enumerations -------------------------- */
+
+
+typedef enum
+{
+ pdc_pbox_none,
+ pdc_pbox_art,
+ pdc_pbox_bleed,
+ pdc_pbox_crop,
+ pdc_pbox_media,
+ pdc_pbox_trim
+}
+pdc_pagebox;
+
+
+/* ----------------------- PDF output ---------------------------- */
typedef struct pdc_output_s pdc_output;
@@ -93,10 +140,17 @@ typedef struct
pdc_flush_state flush;
#if defined(MVS) || defined(MVS_TEST)
- int blocksize; /* file record size */
+ const char *fopenparams; /* additional fopen() parameters */
+ int recordsize; /* file record size */
#endif
} pdc_outctl;
+
+/* ----------- service function to get PDF version string -------------- */
+
+const char *pdc_get_pdfversion(pdc_core *pdc, int compatibility);
+
+
/* --------------------------- Setup --------------------------- */
pdc_output * pdc_boot_output(pdc_core *pdc);
diff --git a/src/pdflib/pdcore/pc_prefix.h b/src/pdflib/pdcore/pc_prefix.h
index bcb9135..3a3bc53 100644
--- a/src/pdflib/pdcore/pc_prefix.h
+++ b/src/pdflib/pdcore/pc_prefix.h
@@ -6,7 +6,7 @@
| Proprietary source code -- do not redistribute! |
*---------------------------------------------------------------------------*/
-/* $Id: pc_prefix.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_prefix.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* PDCORE: unique renaming of function names shared by different applications
*/
@@ -15,3 +15,4 @@
#define PC_PREFIX_H
#endif /* PC_PREFIX_H */
+
diff --git a/src/pdflib/pdcore/pc_pstok.h b/src/pdflib/pdcore/pc_pstok.h
index a3a6ca2..cd6f88a 100644
--- a/src/pdflib/pdcore/pc_pstok.h
+++ b/src/pdflib/pdcore/pc_pstok.h
@@ -6,7 +6,7 @@
| Proprietary source code -- do not redistribute! |
*---------------------------------------------------------------------------*/
-/* $Id: pc_pstok.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_pstok.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* PDCORE PostScript token scanner.
*
diff --git a/src/pdflib/pdcore/pc_resource.c b/src/pdflib/pdcore/pc_resource.c
index 727df4e..3e9678b 100644
--- a/src/pdflib/pdcore/pc_resource.c
+++ b/src/pdflib/pdcore/pc_resource.c
@@ -1,7 +1,7 @@
/*---------------------------------------------------------------------------*
| PDFlib - A library for generating PDF on the fly |
+---------------------------------------------------------------------------+
- | Copyright (c) 1997-2006 Thomas Merz and PDFlib GmbH. All rights reserved. |
+ | Copyright (c) 1997-2008 Thomas Merz and PDFlib GmbH. All rights reserved. |
+---------------------------------------------------------------------------+
| |
| This software is subject to the PDFlib license. It is NOT in the |
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_resource.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_resource.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Resource routines
*
@@ -28,6 +28,8 @@
#if defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
+#else
+#include <unistd.h>
#endif
@@ -219,6 +221,7 @@ pdc_get_resourcefile(pdc_core *pdc)
static void
pdc_read_resourcefile(pdc_core *pdc, const char *filename)
{
+ pdc_bool logg1 = pdc_logg_is_enabled(pdc, 1, trc_resource);
pdc_reslist *resl = pdc_get_reslist(pdc);
pdc_file *fp = NULL;
char **linelist;
@@ -226,7 +229,9 @@ pdc_read_resourcefile(pdc_core *pdc, const char *filename)
char *category = NULL;
char *uprfilename = NULL;
char tmpname[PDC_FILENAMELEN];
-#if defined(AS400) || defined(WIN32)
+ char prodname[32];
+ char prodversion[32];
+ char *c;
#define BUFSIZE 2048
char buffer[BUFSIZE];
#ifdef WIN32
@@ -234,11 +239,35 @@ pdc_read_resourcefile(pdc_core *pdc, const char *filename)
HKEY hKey = NULL;
DWORD size, lType;
#endif
-#endif
- int il, nlines = 0, nextcat, begin;
+ int il, ip, nlines = 0, nextcat, begin;
+
+ if (logg1)
+ pdc_logg(pdc, "\n\tSearching for resource file...\n");
- pdc_logg_cond(pdc, 1, trc_resource,
- "\n\tSearching for resource file...\n");
+ /* product name */
+ strcpy(prodname, pdc->prodname);
+
+ /* product version: <major>.<minor> */
+ strcpy(prodversion, pdc->version);
+ if (strlen(pdc->version))
+ {
+ c = strchr(prodversion, '.');
+ if (c != NULL)
+ {
+ c++;
+ if (*c)
+ {
+ c++;
+ if (pdc_isdigit(*c))
+ c++;
+ *c = 0;
+ }
+ }
+ }
+
+ if (logg1)
+ pdc_logg(pdc, "\tProduct name=%s, version=%s\n",
+ prodname, prodversion);
#ifdef WIN32
@@ -251,24 +280,28 @@ pdc_read_resourcefile(pdc_core *pdc, const char *filename)
#endif /* WIN32 */
#ifdef AS400
- pdc_logg_cond(pdc, 1, trc_resource,
- "\tSet AS400 default resources\n");
- strcpy (buffer, "/pdflib/");
- strcat (buffer, pdc->version);
- il = (int) strlen(buffer);
- strcat (buffer, "/fonts");
+ if (logg1)
+ pdc_logg(pdc, "\tSet AS400 default SearchPath entries\n");
+
+ sprintf(buffer, "/%s/%s/fonts", prodname, pdc->version);
pdc_add_resource(pdc, "SearchPath", buffer, "");
- strcpy(&buffer[il], "/bind/data");
+
+ sprintf(buffer, "/%s/%s/bind/data", prodname, pdc->version);
pdc_add_resource(pdc, "SearchPath", buffer, "");
#endif /* AS400 */
+#ifdef MVS
+ (void) buffer;
+ (void) ip;
+#endif
+
#ifdef WIN32
/* process registry entries */
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, regkey, 0L,
(REGSAM) KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
{
- pdc_logg_cond(pdc, 1, trc_resource,
- "\tRead registry key \"%s\":\n", REGISTRYKEY);
+ if (logg1)
+ pdc_logg(pdc, "\tRead registry key \"%s\":\n", regkey);
size = BUFSIZE - 2;
if (RegQueryValueExA(hKey, "searchpath", (LPDWORD) NULL,
@@ -276,11 +309,17 @@ pdc_read_resourcefile(pdc_core *pdc, const char *filename)
== ERROR_SUCCESS && *buffer)
{
char **pathlist;
- int ip, np;
+ int np;
+
+ if (logg1)
+ pdc_logg(pdc, "\tsearchpath entry: \"%s\"\n", buffer);
np = pdc_split_stringlist(pdc, buffer, ";", 0, &pathlist);
for (ip = 0; ip < np; ip++)
+ {
+ /* TODO: we should only accessible directories */
pdc_add_resource(pdc, "SearchPath", pathlist[ip], "");
+ }
pdc_cleanup_stringlist(pdc, pathlist);
}
@@ -288,6 +327,32 @@ pdc_read_resourcefile(pdc_core *pdc, const char *filename)
}
#endif /* WIN32 */
+#if !defined(WIN32) && !defined(AS400) && !defined(MVS)
+ if (logg1)
+ pdc_logg(pdc, "\tSet UNIX default SearchPath entries\n");
+
+ for (il = 0; rootdirectories[il] != NULL; il++)
+ {
+ const char *home = pdc_getenv("HOME");
+
+ if (home != NULL)
+ sprintf(tmpname, rootdirectories[il], home);
+ else
+ strcpy(tmpname, rootdirectories[il]);
+
+ /* we allow only accessible root directories */
+ if (access(tmpname, X_OK) != -1)
+ {
+ for (ip = 0; defsearchpathlist[ip] != NULL; ip++)
+ {
+ sprintf(buffer, defsearchpathlist[ip],
+ tmpname, prodname, prodversion);
+ pdc_add_resource(pdc, "SearchPath", buffer, "");
+ }
+ }
+ }
+#endif /* !WIN32 && !AS400 && !MVS */
+
/* searching for name of upr file */
uprfilename = (char *)filename;
if (uprfilename == NULL || *uprfilename == '\0')
@@ -309,6 +374,9 @@ pdc_read_resourcefile(pdc_core *pdc, const char *filename)
&lType, (LPBYTE) buffer, &size)
== ERROR_SUCCESS && *buffer)
{
+ if (logg1)
+ pdc_logg(pdc, "\tresourcefile entry: \"%s\"\n", buffer);
+
uprfilename = buffer;
}
@@ -324,7 +392,7 @@ pdc_read_resourcefile(pdc_core *pdc, const char *filename)
uprfilename = pdc_strtolower(tmpname);
/* user-supplied upr file */
- fp = pdc_fsearch_fopen(pdc, uprfilename, NULL, NULL, 0);
+ fp = pdc_fsearch_fopen(pdc, uprfilename, NULL, "UPR ", 0);
if (fp == NULL)
{
uprfilename = NULL;
@@ -336,8 +404,8 @@ pdc_read_resourcefile(pdc_core *pdc, const char *filename)
{
char *resfilename = resl->filename;
- pdc_logg_cond(pdc, 1, trc_resource,
- "\tRead resource file \"%s\":\n", uprfilename);
+ if (logg1)
+ pdc_logg(pdc, "\tRead resource file \"%s\":\n", uprfilename);
resl->filename = pdc_strdup(pdc, uprfilename);
if (resfilename)
@@ -411,23 +479,26 @@ pdc_add_resource_ext(pdc_core *pdc, const char *category, const char *resname,
const char *resvalue, pdc_encoding enc, int codepage)
{
static const char fn[] = "pdc_add_resource";
+ pdc_bool logg1 = pdc_logg_is_enabled(pdc, 1, trc_resource);
pdc_reslist *resl = pdc_get_reslist(pdc);
pdc_rescategory rescat;
pdc_category *cat = NULL, *lastcat = NULL;
pdc_res *res = NULL, *lastres = NULL;
char *resnamutf8 = NULL;
char *resvalutf8 = NULL;
- int resnamflags = PDC_CONV_EBCDIC;
- int resvalflags = PDC_CONV_EBCDIC;
+ int resnamflags = PDC_CONV_EBCDIC | PDC_CONV_TMPALLOC;
+ int resvalflags = PDC_CONV_EBCDIC | PDC_CONV_TMPALLOC;
int k;
- if (!resvalue || !strlen(resvalue))
- pdc_logg_cond(pdc, 1, trc_resource,
- "\tAdd \"%s\" to resource category \"%s\"\n", resname, category);
- else
- pdc_logg_cond(pdc, 1, trc_resource,
- "\tAdd \"%s=%s\" to resource category \"%s\"\n",
- resname, resvalue, category);
+ if (logg1)
+ {
+ if (!resvalue || !strlen(resvalue))
+ pdc_logg(pdc, "\tAdd \"%s\" to resource category \"%s\"\n",
+ resname, category);
+ else
+ pdc_logg(pdc, "\tAdd \"%s=%s\" to resource category \"%s\"\n",
+ resname, resvalue, category);
+ }
/* We no longer raise an error but silently ignore unknown categories */
k = pdc_get_keycode_ci(category, pdc_rescategories);
@@ -502,7 +573,7 @@ pdc_add_resource_ext(pdc_core *pdc, const char *category, const char *resname,
}
else
{
- resvalutf8 = pdc_strdup(pdc, "");
+ resvalutf8 = pdc_strdup_ext(pdc, "", PDC_CONV_TMPALLOC, fn);
}
pdc_cleanup_stringlist(pdc, strlist);
}
@@ -531,8 +602,6 @@ pdc_add_resource_ext(pdc_core *pdc, const char *category, const char *resname,
{
if (!strlen(resnamutf8) || !strlen(resvalutf8))
{
- pdc_free(pdc, resnamutf8);
- pdc_free(pdc, resvalutf8);
if (resvalue == NULL)
pdc_error(pdc, PDC_E_RES_BADRES, resname, category, 0, 0);
else
@@ -549,15 +618,12 @@ pdc_add_resource_ext(pdc_core *pdc, const char *category, const char *resname,
{
if (strlen(resvalutf8))
{
- if (resnamutf8 != NULL)
- pdc_free(pdc, resnamutf8);
- pdc_free(pdc, resvalutf8);
pdc_error(pdc, PDC_E_RES_BADRES, resname, category, 0, 0);
}
if (resvalutf8 != NULL)
{
- pdc_free(pdc, resvalutf8);
+ pdc_free_tmp(pdc, resvalutf8);
resvalutf8 = NULL;
}
@@ -570,11 +636,12 @@ pdc_add_resource_ext(pdc_core *pdc, const char *category, const char *resname,
{
/* delete all entries */
if (resnamutf8 != NULL)
- pdc_free(pdc, resnamutf8);
+ pdc_free_tmp(pdc, resnamutf8);
pdc_delete_rescategory(pdc, lastcat, cat, pdc_true);
- pdc_logg_cond(pdc, 1, trc_resource,
- "\tResource category \"%s\" removed\n", category);
+ if (logg1)
+ pdc_logg(pdc, "\tResource category \"%s\" removed\n",
+ category);
return;
}
@@ -603,26 +670,27 @@ pdc_add_resource_ext(pdc_core *pdc, const char *category, const char *resname,
else
cat->kids = res;
res->prev = lastres;
- res->name = resnamutf8;
+ res->name = pdc_strdup(pdc, resnamutf8);
}
else
{
- pdc_free(pdc, resnamutf8);
+ pdc_free_tmp(pdc, resnamutf8);
}
/* New value */
if (res->value)
pdc_free(pdc, res->value);
- res->value = resvalutf8;
+ res->value = pdc_strdup(pdc, resvalutf8);
- if (res->value && strlen(res->value))
- pdc_logg_cond(pdc, 1, trc_resource,
- "\tNew category.resource: \"%s.%s = %s\"\n",
- category, res->name, res->value);
- else
- pdc_logg_cond(pdc, 1, trc_resource,
- "\tNew category.resource: \"%s.%s\"\n",
- category, res->name);
+ if (logg1)
+ {
+ if (res->value && strlen(res->value))
+ pdc_logg(pdc, "\tNew category.resource: \"%s.%s = %s\"\n",
+ category, res->name, res->value);
+ else
+ pdc_logg(pdc, "\tNew category.resource: \"%s.%s\"\n",
+ category, res->name);
+ }
}
void
@@ -737,7 +805,7 @@ pdc_find_resource_nr(pdc_core *pdc, const char *category, int nr)
pdc_errprintf(pdc, "%s%s%s", resname, separ, resval);
if (tobefree)
- pdc_free(pdc, resval);
+ pdc_free_tmp(pdc, resval);
return retval;
}
@@ -798,13 +866,17 @@ pdc__create_pvf(pdc_core *pdc, const char *filename,
static const char fn[] = "pdc__create_pvf";
pdc_bool iscopy = pdc_false;
pdc_virtfile *vfile, *lastvfile = NULL;
+ const char *stemp = NULL;
pdc_resopt *results;
- if (!data)
- pdc_error(pdc, PDC_E_ILLARG_EMPTY, "data", 0, 0, 0);
+ if (data == NULL)
+ stemp = "data = NULL";
if (!size)
- pdc_error(pdc, PDC_E_ILLARG_EMPTY, "size", 0, 0, 0);
+ stemp = "size = 0";
+
+ if (stemp != NULL)
+ pdc_error(pdc, PDC_E_PAR_NODATA, stemp, 0, 0, 0);
/* Parse optlist */
results = pdc_parse_optionlist(pdc, optlist, pdc_create_pvf_options,
@@ -1009,7 +1081,7 @@ pdc_fsearch_fopen(pdc_core *pdc, const char *filename, char *fullname,
while (1)
{
/* Test opening */
- pdc_file_fullname(pathname, filename, fullname);
+ pdc_file_fullname(pdc, pathname, filename, fullname);
if (pathname != NULL)
pdc_logg_cond(pdc, 1, trc_filesearch,
@@ -1255,16 +1327,20 @@ static const pdc_defopt pdc_logg_options[] =
PDC_OPT_TERMINATE
};
+#define PDC_SEPARSTR_LEN 80
+
static const char *separstr =
- "[ --------------------------------------------------------- ]\n";
+ "[---------------------------------------"
+ "---------------------------------------]\n";
void
pdc_set_logg_options(pdc_core *pdc, const char *optlist)
{
pdc_loggdef *logg = pdc_get_logg(pdc);
pdc_resopt *resopts = NULL;
- char **strlist, *keyword;
+ char **strlist;
char filename[PDC_FILENAMELEN+1];
+ const char *keyword;
pdc_bool sare = pdc_false;
pdc_bool enable = pdc_true;
pdc_bool remfile = pdc_false;
@@ -1305,7 +1381,13 @@ pdc_set_logg_options(pdc_core *pdc, const char *optlist)
pdc_get_optvalues("remove", resopts, &remfile, NULL);
if (!logg->fromenviron)
- pdc_get_optvalues("filename", resopts, filename, NULL);
+ {
+ const char *fname = pdc_get_opt_filename(pdc, "filename", resopts);
+
+ if (fname != NULL)
+ strcpy(filename, fname);
+
+ }
if (pdc_get_optvalues("stringformat", resopts, &inum, NULL))
logg->strform = (pdc_strform_kind) inum;
@@ -1412,12 +1494,15 @@ pdc_set_logg_options(pdc_core *pdc, const char *optlist)
/* open file */
if (!logg->flush)
{
+ /* due to honorlang, codeset of LANG: UTF-8 */
+ i = pdc_is_utf8_bytecode(logg->filename) ? 3 : 0;
+
if (!strcmp(logg->filename, "stdout"))
logg->fp = stdout;
else if (!strcmp(logg->filename, "stderr"))
logg->fp = stderr;
else
- logg->fp = fopen(logg->filename, APPENDMODE);
+ logg->fp = fopen(&logg->filename[i], APPENDMODE);
if (logg->fp == NULL)
{
pdc_error(pdc, PDC_E_IO_WROPEN, "log ", logg->filename,
@@ -1434,7 +1519,9 @@ pdc_set_logg_options(pdc_core *pdc, const char *optlist)
logg->enabled = enable;
if (logg->enabled && logg->header && pdc->prodname != NULL)
{
- char binding[64];
+ char binding[64], buf[256], *bp;
+
+ pdc_logg(pdc, separstr);
pdc_localtime(&ltime);
binding[0] = 0;
@@ -1443,17 +1530,38 @@ pdc_set_logg_options(pdc_core *pdc, const char *optlist)
strcat(binding, pdc->binding);
strcat(binding, " binding ");
}
- pdc_logg(pdc, separstr);
- pdc_logg(pdc, "[ %s %s %son %s (%s) ",
- pdc->prodname, pdc->version, binding,
- PDF_PLATFORM, PDC_ISBIGENDIAN ? "be" : "le");
- pdc_logg(pdc, "%04d-%02d-%02d %02d:%02d:%02d ]\n",
- ltime.year + 1900, ltime.month + 1, ltime.mday,
- ltime.hour, ltime.minute, ltime.second);
+
+ sprintf(buf, "[ %s %s %son %s (%s) %04d-%02d-%02d %02d:%02d:%02d",
+ pdc->prodname, pdc->version, binding,
+ PDF_PLATFORM, PDC_ISBIGENDIAN ? "be" : "le",
+ ltime.year + 1900, ltime.month + 1, ltime.mday,
+ ltime.hour, ltime.minute, ltime.second);
+
+ i = MAX(PDC_SEPARSTR_LEN - (int) strlen(buf) - 1, 1);
+ pdc_logg(pdc, "%s%*s]\n", buf, i, " ");
+
+ bp = buf;
+ bp += sprintf(buf, "[ Classes:");
+ for (pclass = 0; pclass < trc_numclasses; pclass++)
+ {
+ level = logg->classlist[logg->sri][pclass];
+ if (level)
+ {
+ keyword = pdc_get_keyword(pclass, pdf_protoclass_keylist);
+ bp += sprintf(bp, " %s=%d", keyword, level);
+ }
+ }
+ i = MAX(PDC_SEPARSTR_LEN - (int) strlen(buf) - 1, 1);
+ pdc_logg(pdc, "%s%*s]\n", buf, i, " ");
if (logg->classapi)
- pdc_logg(pdc, "[ Use %%s/\\[[^]]*\\]//g and %%s/)$/);"
- "/ in vi to compile it ]\n");
+ {
+ strcpy(buf, "[ Use %%s/\\[[^]]*\\]//g and %%s/)$/);"
+ "/ in vi to compile it");
+ i = MAX(PDC_SEPARSTR_LEN - (int) strlen(buf) - 1, 1);
+ pdc_logg(pdc, "%s%*s]\n", buf, i, " ");
+ }
+
pdc_logg(pdc, separstr);
}
}
@@ -1466,17 +1574,20 @@ pdc_set_logg_options(pdc_core *pdc, const char *optlist)
const char *
pdc_print_loggstring(pdc_core *pdc, const char *str, int len)
{
+ pdc_strform_kind strform = strform_readable0;
+ int maxchar = 0;
+
if (pdc->logg != NULL && pdc->logg->enabled)
{
- str = pdc_strprint(pdc, str, len, pdc->logg->maxchar,
- pdc->logg->strform);
+ maxchar = pdc->logg->maxchar;
+ strform = pdc->logg->strform;
+ }
+
+ str = pdc_strprint(pdc, str, len, maxchar, strform);
- return str;
- }
- else
- return "";
+ return str;
}
/* logging function without any class level check and decorations
@@ -1490,12 +1601,15 @@ pdc_logg_output(pdc_core *pdc, const char *fmt, va_list ap)
{
FILE *fp = NULL;
+ /* due to honorlang, codeset of LANG: UTF-8 */
+ int i = pdc_is_utf8_bytecode(logg->filename) ? 3 : 0;
+
if (!strcmp(logg->filename, "stdout"))
fp = stdout;
else if (!strcmp(logg->filename, "stderr"))
fp = stderr;
else
- fp = fopen(logg->filename, APPENDMODE);
+ fp = fopen(&logg->filename[i], APPENDMODE);
if (fp == NULL)
{
diff --git a/src/pdflib/pdcore/pc_resource.h b/src/pdflib/pdcore/pc_resource.h
index f83498c..d83a27f 100644
--- a/src/pdflib/pdcore/pc_resource.h
+++ b/src/pdflib/pdcore/pc_resource.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_resource.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_resource.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Resource routines
*
@@ -19,6 +19,40 @@
#ifndef PC_RESOURCE_H
#define PC_RESOURCE_H
+#ifdef PC_RESOURCE_C
+#if !defined(WIN32) && !defined(AS400) && !defined(MVS)
+
+/* default SearchPath list for UNIX like systems
+*/
+
+/* %s: $HOME
+*/
+static const char *rootdirectories[] =
+{
+ "/usr/local",
+ "%s",
+ NULL
+};
+
+/*
+ * first %s: root directory
+ * second %s: pdc->prodname
+ * third %s: pdc->version without revision: <major>.<minor>
+ */
+static const char *defsearchpathlist[] =
+{
+ "%s/PDFlib",
+ "%s/PDFlib/%s",
+ "%s/PDFlib/%s/%s",
+ "%s/PDFlib/%s/%s/resource/cmap",
+ "%s/PDFlib/%s/%s/resource/fonts",
+ "%s/PDFlib/%s/%s/resource/icc",
+ NULL
+};
+
+#endif /* !WIN32 && !AS400 && !MVS */
+#endif /* PC_RESOURCE_C */
+
/* pdcore logg classes (maximal PDC_CLASSLIST_SIZE) */
typedef enum
{
@@ -42,7 +76,9 @@ typedef enum
trc_warning, /* logging of disabled warnings */
trc_wordfinder, /* word finder logging */
trc_xmp, /* xmp logging */
- trc_zones /* zones logging */
+ trc_zones, /* zones logging */
+
+ trc_numclasses /* number of classes */
}
pdc_logg_class;
diff --git a/src/pdflib/pdcore/pc_scan.c b/src/pdflib/pdcore/pc_scan.c
index 94e713a..a96af58 100644
--- a/src/pdflib/pdcore/pc_scan.c
+++ b/src/pdflib/pdcore/pc_scan.c
@@ -6,7 +6,7 @@
| Proprietary source code -- do not redistribute! |
*---------------------------------------------------------------------------*/
-/* $Id: pc_scan.c,v 1.1 2008/10/17 06:10:43 scuri Exp $ */
+/* $Id: pc_scan.c,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
#include "pc_util.h"
diff --git a/src/pdflib/pdcore/pc_scan.h b/src/pdflib/pdcore/pc_scan.h
index 1b31e54..b32c9bb 100644
--- a/src/pdflib/pdcore/pc_scan.h
+++ b/src/pdflib/pdcore/pc_scan.h
@@ -6,7 +6,7 @@
| Proprietary source code -- do not redistribute! |
*---------------------------------------------------------------------------*/
-/* $Id: pc_scan.h,v 1.1 2008/10/17 06:10:43 scuri Exp $ */
+/* $Id: pc_scan.h,v 1.2 2009/10/20 18:12:26 scuri Exp $ */
#ifndef PC_SCAN_H_INCLUDED
#define PC_SCAN_H_INCLUDED
diff --git a/src/pdflib/pdcore/pc_scantok.h b/src/pdflib/pdcore/pc_scantok.h
index 84420c9..759bb09 100644
--- a/src/pdflib/pdcore/pc_scantok.h
+++ b/src/pdflib/pdcore/pc_scantok.h
@@ -6,7 +6,7 @@
| Proprietary source code -- do not redistribute! |
*---------------------------------------------------------------------------*/
-/* $Id: pc_scantok.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_scantok.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* PDCORE generic token scanner standard tokens.
*
diff --git a/src/pdflib/pdcore/pc_scope.c b/src/pdflib/pdcore/pc_scope.c
index 73daac2..7f3cc2b 100644
--- a/src/pdflib/pdcore/pc_scope.c
+++ b/src/pdflib/pdcore/pc_scope.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_scope.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_scope.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Scoping routines and macros
*
diff --git a/src/pdflib/pdcore/pc_scope.h b/src/pdflib/pdcore/pc_scope.h
index 8c8a8f6..7347db4 100644
--- a/src/pdflib/pdcore/pc_scope.h
+++ b/src/pdflib/pdcore/pc_scope.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_scope.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_scope.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Scoping routines and macros
*
diff --git a/src/pdflib/pdcore/pc_string.c b/src/pdflib/pdcore/pc_string.c
index f792ac1..f0e5824 100644
--- a/src/pdflib/pdcore/pc_string.c
+++ b/src/pdflib/pdcore/pc_string.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_string.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_string.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* The core string classes.
*
@@ -43,7 +43,7 @@ void pdc_cleanup_strings(pdc_core *pdc)
{
pdc_mp_delete(pdc->bstr_pool);
pdc_mp_delete(pdc->ustr_pool);
-} /* pdc_init_strings */
+} /* pdc_cleanup_strings */
/************************************************************************/
@@ -416,7 +416,7 @@ pdc_bs_puts(pdc_bstr *dst, const pdc_byte *src)
if (!src)
return;
- pdc_bs_write(dst, src, strlen(src));
+ pdc_bs_write(dst, src, strlen((char *) src));
} /* pdc_bs_puts */
diff --git a/src/pdflib/pdcore/pc_string.h b/src/pdflib/pdcore/pc_string.h
index 631635f..d784155 100644
--- a/src/pdflib/pdcore/pc_string.h
+++ b/src/pdflib/pdcore/pc_string.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_string.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_string.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* The core string classes.
*
diff --git a/src/pdflib/pdcore/pc_unicode.c b/src/pdflib/pdcore/pc_unicode.c
index 7b32022..cf8561f 100644
--- a/src/pdflib/pdcore/pc_unicode.c
+++ b/src/pdflib/pdcore/pc_unicode.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_unicode.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_unicode.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* PDFlib Unicode converting routines
*
@@ -596,6 +596,12 @@ pdc_convertUTF8toUTF32 (
--------------------------------------------------------------------- */
+const char *
+pdc_get_textformat(int textformat)
+{
+ return pdc_get_keyword(textformat, pdc_textformat_keylist);
+}
+
static const pdc_keyconn pdc_utfformat_keylist[] =
{
{"8", pdc_utf8},
@@ -773,8 +779,9 @@ pdc_convert_string(pdc_core *pdc,
pdc_byte **outstring, int *outlen, int flags,
pdc_bool verbose)
{
+ /* text_nocheck: see bug #1664 */
return pdc_convert_textstring(pdc, inutf, codepage, inev,
- NULL, 0, -1, instring, inlen, oututf_p, outev,
+ NULL, 0, text_nocheck, instring, inlen, oututf_p, outev,
outstring, outlen, flags, verbose);
}
@@ -791,6 +798,7 @@ pdc_convert_textstring(pdc_core *pdc,
static const char *fn = "pdc_convert_textstring";
pdc_bool logg = flags & PDC_CONV_LOGGING;
const char *stemp1 = NULL, *stemp2 = NULL;
+ char sbuf[64];
pdc_text_format oututf = *oututf_p;
pdc_text_format oututf_s;
pdc_ushort *usinstr = (pdc_ushort *) instring;
@@ -806,10 +814,27 @@ pdc_convert_textstring(pdc_core *pdc,
(void) tabsize;
(void) replchar;
+ if (logg || pdc_logg_is_enabled(pdc, 5, trc_encoding))
+ {
+ pdc_logg(pdc, "\n");
+ if (!logg)
+ pdc_logg(pdc, "\t\ttext string of length %d will be converted...\n",
+ inlen);
+ logg = pdc_true;
+ }
+
if (logg)
+ {
pdc_logg(pdc, "\t\tinput textformat for string conversion: %s\n",
pdc_get_keyword(inutf, pdc_textformat_keylist));
+ if (inev != NULL)
+ pdc_logg(pdc, "\t\tinput encoding: %s\n", inev->apiname);
+
+ if (outev != NULL)
+ pdc_logg(pdc, "\t\toutput encoding: %s\n", outev->apiname);
+ }
+
/* prophylactic */
if (!inlen)
{
@@ -900,7 +925,7 @@ pdc_convert_textstring(pdc_core *pdc,
if (codepage > 0)
{
#if defined(WIN32)
- if (!(flags & PDC_CONV_ANALYZE))
+ if (!(flags & PDC_CONV_ANALYZE) && inlen > 0)
{
if (logg)
pdc_logg(pdc,
@@ -1006,13 +1031,13 @@ pdc_convert_textstring(pdc_core *pdc,
(inutf == pdc_utf16le && PDC_ISBIGENDIAN)))
{
if (inalloc)
- pdc_swap_bytes((char *) instring, inlen, NULL);
+ pdc_swap_bytes2((char *) instring, inlen, NULL);
else
{
instr = (pdc_byte *) ((flags & PDC_CONV_TMPALLOC) ?
pdc_calloc_tmp(pdc, (size_t) (inlen + 2), fn, NULL, NULL) :
pdc_calloc(pdc, (size_t) (inlen + 2), fn));
- pdc_swap_bytes((char *) instring, inlen, (char *) instr);
+ pdc_swap_bytes2((char *) instring, inlen, (char *) instr);
inalloc = pdc_true;
instring = instr;
@@ -1022,10 +1047,36 @@ pdc_convert_textstring(pdc_core *pdc,
inutf = pdc_utf16;
}
- /* illegal UTF-16 */
+ /* conversion to UTF-32 by swapping */
+ if (inlen && inutf == pdc_utf32)
+ {
+
+ if ((pdc_is_utf32be_unicode(instring) && !PDC_ISBIGENDIAN) ||
+ (pdc_is_utf32le_unicode(instring) && PDC_ISBIGENDIAN))
+ {
+ if (inalloc)
+ pdc_swap_bytes4((char *) instring, inlen, NULL);
+ else
+ {
+ instr = (pdc_byte *) ((flags & PDC_CONV_TMPALLOC) ?
+ pdc_calloc_tmp(pdc, (size_t) (inlen + 4), fn, NULL, NULL) :
+ pdc_calloc(pdc, (size_t) (inlen + 4), fn));
+ pdc_swap_bytes4((char *) instring, inlen, (char *) instr);
+
+ inalloc = pdc_true;
+ instring = instr;
+ instr = NULL;
+ }
+ }
+ }
+
+ /* illegal UTF-16 / UTF-32 */
if (inutf >= pdc_utf16 && inlen % 2)
{
- errcode = PDC_E_CONV_ILLUTF16;
+ if (inutf == pdc_utf32 && inlen % 4)
+ errcode = PDC_E_CONV_ILLUTF32;
+ else
+ errcode = PDC_E_CONV_ILLUTF16;
goto PDC_CONV_ERROR;
}
@@ -1102,7 +1153,7 @@ pdc_convert_textstring(pdc_core *pdc,
{
pdc_convers_result result = conversionOK;
pdc_byte *instringa, *instra, *instringe, *instre;
- UTF8 *isa8, *ise8;
+ UTF8 *isa8 = NULL, *ise8 = NULL;
UTF16 *isa16, *ise16;
UTF32 *isa32, *ise32;
@@ -1197,16 +1248,44 @@ pdc_convert_textstring(pdc_core *pdc,
case sourceExhausted:
case sourceIllegal:
- if (inutf == pdc_utf8 && (flags & PDC_CONV_INFLATE))
+ if (inutf == pdc_utf8)
{
- pdc_inflate_ascii((char *) instring, inlen, (char *) instr,
- pdc_utf16);
- instra = instr + 2 * inlen;
+ UTF8 *bp, *bpe;
+ char *sb = sbuf;
+
+ bpe = MIN(ise8 - 1, isa8 + 3);
+ for (bp = isa8; bp <= bpe; bp++)
+ sb += sprintf(sb, "\\x%02X", *bp);
+ if (*bp)
+ sb += sprintf(sb, "...");
+ sb += sprintf(sb, " (");
+ for (bp = isa8; bp <= bpe; bp++)
+ sb += sprintf(sb, "%c", *bp);
+ if (*bp)
+ sb += sprintf(sb, "...");
+ sb += sprintf(sb, ")");
+ stemp1 = sbuf;
+
+ stemp2 = pdc_errprintf(pdc, "%d", isa8 - (UTF8 *)instringa);
+
+ if (flags & PDC_CONV_INFLATE)
+ {
+ pdc_warning(pdc, PDC_E_CONV_ILLUTF8SEQU, stemp1, stemp2,
+ 0, 0);
+
+ pdc_inflate_ascii((char *) instring, inlen,
+ (char *) instr, pdc_utf16);
+ instra = instr + 2 * inlen;
+ }
+ else
+ {
+ errcode = PDC_E_CONV_ILLUTF8SEQU;
+ }
}
else
{
- errcode = PDC_E_CONV_ILLUTF;
stemp1 = pdc_get_keyword((int)inutf, pdc_utfformat_keylist);
+ errcode = PDC_E_CONV_ILLUTF;
}
break;
@@ -1383,6 +1462,7 @@ pdc_convert_textstring(pdc_core *pdc,
pdc_free(pdc, instring);
}
+ inalloc = pdc_true;
instring = instr;
instr = NULL;
inlen = len;
@@ -1456,7 +1536,7 @@ pdc_convert_textstring(pdc_core *pdc,
toswap = PDC_ISBIGENDIAN;
}
if (toswap)
- pdc_swap_bytes((char *) &instring[i], inlen - i, NULL);
+ pdc_swap_bytes2((char *) &instring[i], inlen - i, NULL);
}
if (hasbom)
@@ -1530,7 +1610,8 @@ pdc_convert_textstring(pdc_core *pdc,
* flags & PDC_CONV_ISUTF8 is set the string will be duplicated.
* Otherwise the string has encoding enc and codepage
* codepage.
- * If enc < pdc_winansi the string is "host" encoded.
+ * If enc == pdc_unicode the string is "UTF-16" encoded.
+ * Otherwise: If enc < pdc_winansi the string is "host" encoded.
*
* len > 0: The string is a UTF-16 string of len bytes.
*
@@ -1539,6 +1620,7 @@ char *
pdc_convert_name_ext(pdc_core *pdc, const char *name, int len,
pdc_encoding enc, int codepage, int flags)
{
+ static const char fn[] = "pdc_convert_name_ext";
pdc_encodingvector *ev = NULL;
pdc_text_format nameformat = pdc_utf16;
pdc_text_format outnameformat = pdc_utf8;
@@ -1551,32 +1633,39 @@ pdc_convert_name_ext(pdc_core *pdc, const char *name, int len,
if (len == 0)
{
- pdc_bool hasbom = pdc_is_utf8_bytecode(name);
- pdc_bool withbom = (flags & PDC_CONV_WITHBOM) ? pdc_true : pdc_false;
-
/* already [EBCDIC-]UTF-8 encoded */
- if ((flags & PDC_CONV_ISUTF8) || hasbom)
+ if ((flags & PDC_CONV_ISUTF8) || pdc_is_utf8_bytecode(name))
{
- if ((hasbom && withbom) || (!hasbom && !withbom))
- outname = pdc_strdup(pdc, name);
- else if (hasbom && !withbom)
- outname = pdc_strdup(pdc, &name[3]);
- else if (!hasbom && withbom)
- outname = pdc_strdup_withbom(pdc, name);
+ if (!(flags & PDC_CONV_WITHBOM))
+ flags |= PDC_CONV_NOBOM;
+
+ if (!(flags & PDC_CONV_EBCDIC))
+ flags |= PDC_CONV_ASCII;
+
+ /* On EBCDIC platforms EBCDIC-UTF-8 name strings are expected */
+ outname = pdc_strdup_ext(pdc, name, (flags & ~PDC_CONV_EBCDIC), fn);
+
if (outname != NULL)
- {
return outname;
- }
}
- /* 8-bit encoded string */
- nameformat = pdc_bytes;
- if (enc < pdc_winansi)
- ev = pdc_get_encoding_vector(pdc, pdc_find_encoding(pdc, "host"));
+ /* see bug #1486 */
+ if (enc == pdc_unicode)
+ {
+ /* UTF-16 encoded string */
+ len = (int) pdc_wstrlen(name);
+ }
else
- ev = pdc_get_encoding_vector(pdc, enc);
+ {
+ /* 8-bit encoded string */
+ nameformat = pdc_bytes;
+ if (enc < pdc_winansi)
+ ev = pdc_get_encoding_vector(pdc,pdc_find_encoding(pdc,"host"));
+ else
+ ev = pdc_get_encoding_vector(pdc, enc);
- len = (int) strlen(name);
+ len = (int) strlen(name);
+ }
}
if (flags & PDC_CONV_EBCDIC)
@@ -1602,6 +1691,8 @@ pdc_convert_name(pdc_core *pdc, const char *name, int len, int flags)
return pdc_convert_name_ext(pdc, name, len, pdc_invalidenc, 0, flags);
}
+/* returned string is temporary allocated
+*/
char *
pdc_utf8_to_hostbytes(pdc_core *pdc, pdc_bool honorlang, char *name)
{
@@ -1623,16 +1714,19 @@ pdc_utf8_to_hostbytes(pdc_core *pdc, pdc_bool honorlang, char *name)
pdc_convert_string(pdc, informat, 0, NULL, (pdc_byte *) name, len,
&outformat, outev, &outname, &len,
- PDC_CONV_TRYBYTES | PDC_CONV_NOBOM, pdc_true);
+ PDC_CONV_TRYBYTES | PDC_CONV_NOBOM | PDC_CONV_TMPALLOC,
+ pdc_true);
if (outformat == pdc_utf16)
{
- pdc_free(pdc, outname);
+ pdc_free_tmp(pdc, outname);
outname = NULL;
}
return (char *) outname;
}
+/* returned string is temporary allocated
+*/
char *
pdc_hostbytes_to_utf8(pdc_core *pdc, pdc_bool honorlang, char *name)
{
@@ -1654,7 +1748,7 @@ pdc_hostbytes_to_utf8(pdc_core *pdc, pdc_bool honorlang, char *name)
pdc_convert_string(pdc, informat, 0, inev, (pdc_byte *) name, len,
&outformat, NULL, &outname, &len,
- PDC_CONV_NOBOM, pdc_true);
+ PDC_CONV_NOBOM | PDC_CONV_TMPALLOC, pdc_true);
return (char *) outname;
}
@@ -1702,11 +1796,37 @@ pdc_utf8_to_utf16(pdc_core *pdc, const char *utf8string, const char *format,
if (format && *format)
{
int k = pdc_get_keycode_ci(format, pdc_textformat_keylist);
+
+ /* see bug #2175 */
+ if (k == PDC_KEY_NOTFOUND)
+ {
+ char **sfl;
+ const char *sf;
+ int ns, i;
+
+ sf = NULL;
+ ns = pdc_split_stringlist(pdc, format, NULL, 0, &sfl);
+ for (i = 0; i < ns; i++)
+ {
+ if (!strcmp(sfl[i], "inflate"))
+ flags |= PDC_CONV_INFLATE;
+ else
+ sf = sfl[i];
+ }
+ if (sf != NULL)
+ k = pdc_get_keycode_ci(sf, pdc_textformat_keylist);
+ else
+ k = pdc_utf16;
+
+ pdc_cleanup_stringlist(pdc, sfl);
+ }
+
if (k == PDC_KEY_NOTFOUND ||
((pdc_text_format) k != pdc_utf16 &&
(pdc_text_format) k != pdc_utf16be &&
(pdc_text_format) k != pdc_utf16le))
pdc_error(pdc, PDC_E_ILLARG_STRING, "format", format, 0, 0);
+
outtextformat = (pdc_text_format) k;
}
@@ -1875,7 +1995,7 @@ pdc_char32_to_char16(pdc_core *pdc, int usv, pdc_ushort *uvlist,
return 2;
}
- pdc_set_errmsg(pdc, PDC_E_CONV_ILLUTF32,
+ pdc_set_errmsg(pdc, PDC_E_CONV_ILLUTF32CHAR,
pdc_errprintf(pdc, "%05X", usv), 0, 0, 0);
if (verbose)
diff --git a/src/pdflib/pdcore/pc_unicode.h b/src/pdflib/pdcore/pc_unicode.h
index c5c1354..92285b2 100644
--- a/src/pdflib/pdcore/pc_unicode.h
+++ b/src/pdflib/pdcore/pc_unicode.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_unicode.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_unicode.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Unicode glyph name conversion routines
*
@@ -134,8 +134,8 @@
#define PDF_BOM4 0xBF
/*
- * check whether the string is plain C or UTF16 unicode
- * by looking for the BOM in big-endian or little-endian format resp.
+ * check whether the string is UTF-16 unicode by looking for the BOM
+ * in big-endian or little-endian format resp.
* s must not be NULL.
*/
#define pdc_is_utf16be_unicode(s) \
@@ -147,8 +147,24 @@
((pdc_byte *)(s))[1] == PDF_BOM0)
/*
- * check whether the string is plain C or UTF8 unicode
- * by looking for the BOM
+ * check whether the string is UTF-32 unicode by looking for the BOM
+ * in big-endian or little-endian format resp.
+ * s must not be NULL.
+ */
+#define pdc_is_utf32be_unicode(s) \
+ (((pdc_byte *)(s))[0] == 0x00 && \
+ ((pdc_byte *)(s))[1] == 0x00 && \
+ ((pdc_byte *)(s))[2] == PDF_BOM0 && \
+ ((pdc_byte *)(s))[3] == PDF_BOM1)
+
+#define pdc_is_utf32le_unicode(s) \
+ (((pdc_byte *)(s))[0] == PDF_BOM1 && \
+ ((pdc_byte *)(s))[1] == PDF_BOM0 && \
+ ((pdc_byte *)(s))[2] == 0x00 && \
+ ((pdc_byte *)(s))[3] == 0x00)
+
+/*
+ * check whether the string is UTF-8 unicode by looking for the BOM
* s must not be NULL.
*/
#define pdc_is_utf8_unicode(s) \
@@ -211,6 +227,10 @@ pdc_convers_flags;
#define PDC_CONV_KEEPLBCHAR (1<<15)
#define PDC_CONV_LOGGING (1<<16)
#define PDC_CONV_ISUTF8 (1<<17)
+#define PDC_CONV_ASCII (1<<18)
+#define PDC_CONV_MAXSTRLEN (1<<19)
+#define PDC_CONV_FILENAME (1<<20)
+
/* DON'T change the order */
typedef enum
@@ -242,7 +262,9 @@ static const pdc_keyconn pdc_textformat_keylist[] =
{"utf16le", pdc_utf16le},
{NULL, 0}
};
-#endif /* PC_UNICODE_C */
+#endif /* PC_UNICODE_C */
+
+const char *pdc_get_textformat(int textformat);
int pdc_convert_string(pdc_core *pdc,
pdc_text_format inutf, int codepage, pdc_encodingvector *inev,
diff --git a/src/pdflib/pdcore/pc_util.c b/src/pdflib/pdcore/pc_util.c
index 320ee52..337fcb5 100644
--- a/src/pdflib/pdcore/pc_util.c
+++ b/src/pdflib/pdcore/pc_util.c
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_util.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_util.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* PDFlib various utility routines
*
@@ -50,7 +50,7 @@
#endif
-/* ------------------- Floating-point number check ----------------------- */
+/* ---------------------- finite() workarounds -------------------------- */
@@ -99,6 +99,29 @@ pdc_check_number_zero(pdc_core *pdc, const char *paramname, double dz)
}
}
+int
+pdc_check_text_length(pdc_core *pdc, const char **text, int len, int maxlen)
+{
+ if (*text == NULL)
+ {
+ len = 0;
+ *text = "";
+ }
+ else if (len == 0)
+ {
+ len = (int) strlen(*text);
+ }
+
+ if (len < 0 || len > maxlen)
+ {
+ pdc_error(pdc, PDC_E_ILLARG_STRINGLEN,
+ pdc_errprintf(pdc, "%d", len),
+ pdc_errprintf(pdc, "%d", maxlen), 0, 0);
+ }
+
+ return len;
+}
+
/* ---------------- "unsupported feature" error message ------------------ */
@@ -117,6 +140,36 @@ pdc_set_unsupp_error(pdc_core *pdc, int err_config, int err_lite,
}
+/* ---------------- error message with ASCII strings -------------------- */
+
+void
+pdc_ascii_error(pdc_core *pdc, int errnum, int flags, const char *parm1,
+ const char *parm2, const char *parm3, const char *parm4)
+{
+ if (flags & (1<<0))
+ {
+ parm1 = pdc_errprintf(pdc, "%a", parm1);
+ }
+
+ if (flags & (1<<1))
+ {
+ parm2 = pdc_errprintf(pdc, "%a", parm2);
+ }
+
+ if (flags & (1<<2))
+ {
+ parm3 = pdc_errprintf(pdc, "%a", parm3);
+ }
+
+ if (flags & (1<<3))
+ {
+ parm4 = pdc_errprintf(pdc, "%a", parm4);
+ }
+
+ pdc_error(pdc, errnum, parm1, parm2, parm3, parm4);
+}
+
+
/* -------------------------- Time functions ------------------------------ */
#ifndef WINCE
@@ -340,12 +393,20 @@ pdc_check_lang_code(pdc_core *pdc, const char* lang_code)
/* -------------------------- Bit arryas ------------------------------ */
+/* set bit right to left within a byte */
void
pdc_setbit(char *bitarr, int bit)
{
bitarr[bit/8] |= (char) (1<<(bit%8));
}
+/* set bit left to right within a byte */
+void
+pdc_setbit_l2r(char *bitarr, int bit)
+{
+ bitarr[bit/8] |= (char) (0x80>>(bit%8));
+}
+
pdc_bool
pdc_getbit(const char *bitarr, int bit)
{
@@ -439,16 +500,16 @@ pdc_get_be_ulong(const pdc_byte *data)
/* ----------------- String handling for Unicode too ------------------- */
-/* strlen() for unicode strings, which are terminated by two zero bytes.
- * wstrlen() returns the number of bytes in the Unicode string,
- * not including the two terminating null bytes.
+/* strlen() for wide character strings, which are double null terminated.
+ * pdc_wstrlen() returns the number of bytes in the Unicode string,
+ * NOT including the two terminating null bytes.
*/
-static size_t
-wstrlen(const char *s)
+size_t
+pdc_wstrlen(const char *str)
{
size_t len = 0;
- while(s[len] != 0 || s[len+1] != 0)
+ while(str[len] != 0 || str[len+1] != 0)
{
len += 2;
}
@@ -458,16 +519,14 @@ wstrlen(const char *s)
/*
* This function returns the length in bytes for C and Unicode strings.
- * Note that unlike strlen() it returns the length _including_ the
- * terminator, which may be one or two null bytes.
*/
size_t
-pdc_strlen(const char *text)
+pdc_strlen(const char *str)
{
- if (pdc_is_utf16be_unicode(text) || pdc_is_utf16le_unicode(text))
- return wstrlen(text);
+ if (pdc_is_utf16be_unicode(str) || pdc_is_utf16le_unicode(str))
+ return pdc_wstrlen(str);
else
- return strlen(text);
+ return strlen(str);
}
@@ -478,11 +537,12 @@ pdc_strlen(const char *text)
* must be terminated by a single null byte.
* The caller is responsible for freeing the buffer.
*
- * The special functions pdc_strdup and pdc_strdup_tmp
+ * The special functions pdc_strdup, pdc_strdup_tmp and pdc_strdup_withbom
* should be replaced by the more sophisticated function pdc_strdup_ext.
* There: flags (see pc_unicode.h):
*
- * PDC_CONV_TMPALLOC, PDC_CONV_EBCDIC
+ * PDC_CONV_TMPALLOC, PDC_CONV_EBCDIC, PDC_CONV_ASCII,
+ * PDC_CONV_WITHBOM, PDC_CONV_NOBOM, PDC_CONV_MAXSTRLEN
*
*/
char *
@@ -493,19 +553,55 @@ pdc_strdup_ext(pdc_core *pdc, const char *text, int flags, const char *fn)
if (text != NULL)
{
size_t len = pdc_strlen(text) + 1;
+ size_t is = 0, it = 0;
+
+ if ((flags & PDC_CONV_MAXSTRLEN) && len > PDC_ERR_MAXSTRLEN)
+ len = PDC_ERR_MAXSTRLEN;
+ if ((flags & PDC_CONV_NOBOM) && pdc_is_utf8_bytecode(text))
+ is = 3;
+
+ if ((flags & PDC_CONV_WITHBOM) && !pdc_is_utf8_bytecode(text))
+ it = 3;
+
+ len += it - is;
if (flags & PDC_CONV_TMPALLOC)
buf = (char *) pdc_malloc_tmp(pdc, len + 1, fn, NULL, NULL);
else
buf = (char *) pdc_malloc(pdc, len + 1, fn);
- memcpy(buf, text, len);
+
+ memcpy(&buf[it], &text[is], len - it);
buf[len] = 0;
+
+ if (it == 3)
+ pdc_copy_utf8_bom(buf);
+
}
return buf;
}
+/* Convenience functions
+*/
+char *
+pdc_strdup_tmp(pdc_core *pdc, const char *text)
+{
+ static const char fn[] = "pdc_strdup_tmp";
+
+ return pdc_strdup_ext(pdc, text, PDC_CONV_TMPALLOC, fn);
+}
+
+char *
+pdc_strdup_withbom(pdc_core *pdc, const char *text)
+{
+ static const char fn[] = "pdc_strdup_withbom";
+
+ return pdc_strdup_ext(pdc, text, PDC_CONV_WITHBOM, fn);
+}
+
+/* Rapid function
+*/
char *
pdc_strdup(pdc_core *pdc, const char *text)
{
@@ -540,53 +636,18 @@ pdc_strdup2(pdc_core *pdc, const char *text, size_t len)
return buf;
}
-char *
-pdc_strdup_tmp(pdc_core *pdc, const char *text)
-{
- char *buf = NULL;
- static const char fn[] = "pdc_strdup_tmp";
-
- if (text != NULL)
- {
- size_t len = pdc_strlen(text) + 1;
-
- buf = (char *) pdc_malloc_tmp(pdc, len + 1, fn, NULL, NULL);
- memcpy(buf, text, len);
- buf[len] = 0;
- }
-
- return buf;
-}
-
-/* Allocate a local buffer and copy a locale UTF-8 string
- * provided with an UTF-8 BOM.
- * The caller is responsible for freeing the buffer.
+/* Convert Pascal string to a null terminated C string.
+ * Size of C string: at least 256 bytes
*/
-char *
-pdc_strdup_withbom(pdc_core *pdc, const char *text)
+int
+pdc_convert_pascal_str(const char *pstr, char *cstr)
{
- char *buf = NULL;
- static const char fn[] = "pdc_strdup_withbom";
-
- if (text != NULL)
- {
- size_t len;
-
- if (pdc_is_utf8_bytecode(text))
- {
- buf = pdc_strdup(pdc, text);
- }
- else
- {
- len = strlen(text);
- buf = (char *) pdc_malloc(pdc, len + 4, fn);
+ int len = (int) *((pdc_byte *) pstr);
- pdc_copy_utf8_bom(buf);
- strcpy(&buf[3], text);
- }
- }
+ memcpy(cstr, pstr + 1, (size_t) len);
+ cstr[len] = 0;
- return buf;
+ return len;
}
char *
@@ -649,13 +710,14 @@ pdc_strprint(pdc_core *pdc, const char *str, int leni, int maxchar,
if (len)
{
- pdc_strform_kind sf;
+ pdc_strform_kind sf = strform;
char *ts, *tmpstr;
pdc_byte c = ' ', cp = '.';
pdc_ushort *ush = (pdc_ushort *) str;
int i, im;
- tmpstr = (char *) pdc_calloc_tmp(pdc, (size_t) (4 * (len + 4)), fn,
+ /* because of strform_java: \uxxxx: factor 6 */
+ tmpstr = (char *) pdc_calloc_tmp(pdc, (size_t) (6 * (len + 4)), fn,
NULL, NULL);
ts = tmpstr;
@@ -683,7 +745,7 @@ pdc_strprint(pdc_core *pdc, const char *str, int leni, int maxchar,
else
{
c = (pdc_byte) ush[i];
- sf = strform_readable;
+ sf = strform;
}
}
else
@@ -707,25 +769,34 @@ pdc_strprint(pdc_core *pdc, const char *str, int leni, int maxchar,
break;
default:
- if (c == 0x0 && sf == strform_readable0)
+ if (c == 0x00 && sf == strform_readable0)
+ {
c = 0x20;
- if (!pdc_logg_isprint((int) c))
- {
- if (isunicode)
- ts += sprintf(ts, "\\u%04X", c);
- else
- ts += sprintf(ts, "\\%03o", c);
+ *ts = (char) c;
+ ts++;
}
else
{
- if (c == '"')
+ if (!pdc_logg_isprint((int) c))
{
- *ts = '\\';
+ if (isunicode)
+ ts += sprintf(ts, "\\u%04X", c);
+ else
+ ts += sprintf(ts, "\\%03o", c);
+ }
+ else
+ {
+ if (c == '"')
+ {
+ *ts = '\\';
+ ts++;
+ }
+
+ *ts = (char) c;
ts++;
}
- *ts = (char) c;
- ts++;
+
}
}
}
@@ -759,11 +830,16 @@ pdc_strprint(pdc_core *pdc, const char *str, int leni, int maxchar,
return (char *) pdc_calloc_tmp(pdc, 1, fn, NULL, NULL);
}
+/*
+ * Returned string is temporary allocated.
+ */
const char *
pdc_utf8strprint(pdc_core *pdc, const char *str)
{
- int i = pdc_is_utf8_bytecode(str) ? 3 : 0;
- return pdc_errprintf(pdc, "%.*s", PDC_ERR_MAXSTRLEN, &str[i]);
+ static const char fn[] = "pdc_utf8strprint";
+
+ return pdc_strdup_ext(pdc, str,
+ PDC_CONV_TMPALLOC | PDC_CONV_NOBOM | PDC_CONV_MAXSTRLEN, fn);
}
/*
@@ -791,8 +867,7 @@ pdc_split_stringlist(pdc_core *pdc, const char *text, const char *i_separstr,
static const char fn[] = "pdc_split_stringlist";
const char *separstr = " \f\n\r\t\v";
const char *oldtext;
- char **strlist = NULL, *newtext;
- pdc_bool isoptlist = (flags & PDC_SPLIT_ISOPTLIST);
+ char **strlist = NULL, *newtext = NULL;
int it, len, jt = 0, jtb = 0, maxk = 0, count = 0, inside = 0;
int ns, nbs = 0, nbss;
@@ -808,7 +883,8 @@ pdc_split_stringlist(pdc_core *pdc, const char *text, const char *i_separstr,
ns = (int) strspn(text, separstr);
oldtext = &text[ns];
len = (int) strlen(oldtext);
- if (!len) return 0;
+ if (!len)
+ return 0;
/* check for UTF-8-BOM */
if (pdc_is_utf8_bytecode(oldtext))
@@ -818,11 +894,13 @@ pdc_split_stringlist(pdc_core *pdc, const char *text, const char *i_separstr,
ns = (int) strspn(oldtext, separstr);
oldtext = &oldtext[ns];
len -= ns;
- if (!len) return 0;
+ if (!len)
+ return 0;
}
/* new string */
- newtext = (char *) pdc_malloc(pdc, (size_t) (len + 1), fn);
+ if (stringlist != NULL)
+ newtext = (char *) pdc_malloc(pdc, (size_t) (len + 1), fn);
for (it = 0; it <= len; it++)
{
/* check for separators */
@@ -836,16 +914,17 @@ pdc_split_stringlist(pdc_core *pdc, const char *text, const char *i_separstr,
/* close text part */
if (ns)
{
- newtext[jt] = 0;
- if (count == maxk)
+ if (stringlist != NULL)
{
- maxk += 16;
- strlist = (strlist == NULL) ?
- (char **) pdc_malloc(pdc, maxk * sizeof(char *), fn):
- (char **) pdc_realloc(pdc, strlist, maxk *
- sizeof(char *), fn);
+ newtext[jt] = 0;
+ if (count == maxk)
+ {
+ maxk += 16;
+ strlist = (char **) pdc_realloc(pdc, strlist,
+ maxk * sizeof(char *), fn);
+ }
+ strlist[count] = &newtext[jtb];
}
- strlist[count] = &newtext[jtb];
count++;
/* Exit */
@@ -858,7 +937,7 @@ pdc_split_stringlist(pdc_core *pdc, const char *text, const char *i_separstr,
}
/* option list */
- if (isoptlist)
+ if (flags & PDC_SPLIT_ISOPTLIST)
{
/* save backslash counter */
nbss = nbs;
@@ -904,12 +983,48 @@ pdc_split_stringlist(pdc_core *pdc, const char *text, const char *i_separstr,
}
}
+ /* argument list */
+ else if (flags & PDC_SPLIT_ISARGLIST)
+ {
+ /* save backslash counter */
+ nbss = nbs;
+
+ /* backslash */
+ if (oldtext[it] == '\\')
+ {
+ nbs++;
+ if (!(nbs % 2))
+ continue;
+ }
+ else
+ {
+ nbs = 0;
+ }
+
+ /* open and close quotation mark */
+ if (oldtext[it] == '"')
+ {
+ if (!(nbss % 2))
+ {
+ inside = 1 - inside;
+ continue;
+ }
+ else
+ {
+ jt--;
+ }
+ }
+ }
+
/* save character */
- newtext[jt] = oldtext[it];
- jt++;
+ if (stringlist != NULL)
+ {
+ newtext[jt] = oldtext[it];
+ jt++;
+ }
}
- if (stringlist)
+ if (stringlist != NULL)
*stringlist = strlist;
return inside ? -count : count;
@@ -1078,6 +1193,47 @@ pdc_stricmp(const char *s1, const char *s2)
return (pdc_tolower(*s1) - pdc_tolower(*s2));
}
+int
+pdc_stricmp_a(const char *s1, const char *s2)
+{
+ if (s1 == s2) return (0);
+ if (s1 == NULL) return (-1);
+ if (s2 == NULL) return (1);
+
+ for (; *s1; ++s1, ++s2)
+ {
+ if (pdc_tolower_a(*s1) != pdc_tolower_a(*s2))
+ break;
+ }
+
+ return (pdc_tolower_a(*s1) - pdc_tolower_a(*s2));
+}
+
+/*
+ * Same like pdc_strcmp, except that the strings can be
+ * wide character strings with nulls and double null terminated.
+ */
+int
+pdc_wstrcmp(const char *s1, const char *s2)
+{
+ size_t len1, len2, len;
+ int res;
+
+ if (s1 == s2) return (0);
+ if (s1 == NULL) return (-1);
+ if (s2 == NULL) return (1);
+
+ len1 = pdc_strlen(s1);
+ len2 = pdc_strlen(s2);
+ len = MIN(len1, len2);
+
+ res = memcmp(s1, s2, len);
+
+ if (!res && len1 != len2)
+ res = (len1 < len2) ? -1 : 1;
+
+ return res;
+}
/*
* Compares its arguments and returns an integer less than,
@@ -1172,55 +1328,55 @@ pdc_strtolower(char *str)
return str;
}
-int
-pdc_tolower_ascii(int c)
+void
+pdc_swap_bytes2(const char *instring, int inlen, char *outstring)
{
- c = (int) pdc_tolower(c);
+ pdc_ushort *inp, *outp;
+ int i;
- return c;
-}
+ if (instring == NULL)
+ return;
-int
-pdc_toupper_ascii(int c)
-{
- c = (int) pdc_toupper((int) c);
+ if (outstring == NULL)
+ outstring = (char *) instring;
- return c;
+ inp = (pdc_ushort *) instring;
+ outp = (pdc_ushort *) outstring;
+
+ inlen /= sizeof(pdc_ushort);
+ for (i = 0; i < inlen; i++)
+ {
+ outp[i] = (pdc_ushort) (((inp[i] & (pdc_ushort)0x00FFu) << 8) |
+ ((inp[i] & (pdc_ushort)0xFF00u) >> 8));
+ }
}
void
-pdc_swap_bytes(char *instring, int inlen, char *outstring)
+pdc_swap_bytes4(const char *instring, int inlen, char *outstring)
{
- char c;
- int i,j;
+ pdc_uint32 *inp, *outp;
+ int i;
if (instring == NULL)
return;
if (outstring == NULL)
- outstring = instring;
+ outstring = (char *) instring;
+
+ inp = (pdc_uint32 *) instring;
+ outp = (pdc_uint32 *) outstring;
- inlen = 2 * inlen / 2;
+ inlen /= sizeof(pdc_uint32);
for (i = 0; i < inlen; i++)
{
- j = i;
- i++;
- c = instring[j];
- outstring[j] = instring[i];
- outstring[i] = c;
+ outp[i] = (pdc_uint32) (((inp[i] & (pdc_uint32)0x000000FFu) << 24) |
+ ((inp[i] & (pdc_uint32)0x0000FF00u) << 8) |
+ ((inp[i] & (pdc_uint32)0x00FF0000u) >> 8) |
+ ((inp[i] & (pdc_uint32)0xFF000000u) >> 24));
}
}
void
-pdc_swap_unicodes(char *instring)
-{
- if (instring &&
- ((pdc_is_utf16be_unicode(instring) && !PDC_ISBIGENDIAN) ||
- (pdc_is_utf16le_unicode(instring) && PDC_ISBIGENDIAN)))
- pdc_swap_bytes(&instring[2], (int) (wstrlen(instring) - 2), NULL);
-}
-
-void
pdc_inflate_ascii(const char *instring, int inlen, char *outstring,
pdc_text_format textformat)
{
@@ -1323,6 +1479,8 @@ pdc_get_string_value(pdc_byte *str, int i, int charlen)
return retval;
}
+/* return value: length of new string. -1: error
+*/
int
pdc_subst_backslash(pdc_core *pdc, pdc_byte *str, int len,
pdc_encodingvector *ev, pdc_text_format textformat,
@@ -1456,7 +1614,7 @@ pdc_subst_backslash(pdc_core *pdc, pdc_byte *str, int len,
if (verbose)
pdc_error(pdc, -1, 0, 0, 0, 0);
- return 0;
+ return -1;
}
}
@@ -1483,7 +1641,7 @@ pdc_subst_backslash(pdc_core *pdc, pdc_byte *str, int len,
if (verbose)
pdc_error(pdc, -1, 0, 0, 0, 0);
- return 0;
+ return -1;
}
@@ -1754,6 +1912,23 @@ pdc_str2integer(const char *string, int flags, void *o_iz)
return pdc_true;
}
+
+pdc_bool
+pdc_str2integer_ext(pdc_core *pdc, const char *string, int len,
+ int dupflags, int flags, void *o_iz)
+{
+ static const char fn[] = "pdc_str2integer_ext";
+ char *dupstr;
+ pdc_bool retval;
+
+ dupstr = pdc_strdup_ext(pdc, string, dupflags, fn);
+ dupstr[len] = 0;
+ retval = pdc_str2integer(dupstr, flags, o_iz);
+ pdc_free(pdc, dupstr);
+ return retval;
+}
+
+
static const char digits[] = "0123456789ABCDEF";
static char *
@@ -1808,42 +1983,109 @@ pdc_ltoa(char *buf, long n, int width, char pad, int base)
static char *
-pdc_off_t2a(char *buf, pdc_off_t n, int width, char pad, int base)
+pdc_uoff_t2a(
+ char * buf,
+ pdc_uoff_t n,
+ int width,
+ char pad,
+ int base,
+ pdc_bool left_justify)
+{
+ char aux[100];
+ int k, i = sizeof aux;
+ char * dest = buf;
+
+ while (0 < n)
+ {
+ aux[--i] = digits[n % base];
+ n = n / base;
+ }
+
+ width -= (int) (sizeof aux) - i;
+
+ if (!left_justify)
+ {
+ for (k = 0; k < width; ++k)
+ *(dest++) = pad;
+ }
+
+ memcpy(dest, &aux[i], sizeof aux - i);
+ dest += sizeof aux - i;
+
+ if (left_justify)
+ {
+ for (k = 0; k < width; ++k)
+ *(dest++) = pad;
+ }
+
+ return dest;
+} /* pdc_uoff_t2a */
+
+
+static char *
+pdc_off_t2a(
+ char * buf,
+ pdc_off_t n,
+ int width,
+ char pad,
+ pdc_bool left_justify,
+ pdc_bool pos_sign)
{
char aux[100];
int k, i = sizeof aux;
char * dest = buf;
pdc_bool sign;
- if (n < 0 && base == 10)
+ if (n < 0)
{
--width;
sign = pdc_true;
- aux[--i] = digits[- (n % base)];
- n = n / -base;
+ aux[--i] = digits[- (n % 10)];
+ n = n / -10;
}
else
{
+ if (pos_sign)
+ --width;
+
sign = pdc_false;
- aux[--i] = digits[n % base];
- n = n / base;
+ aux[--i] = digits[n % 10];
+ n = n / 10;
}
while (0 < n)
{
- aux[--i] = digits[n % base];
- n = n / base;
+ aux[--i] = digits[n % 10];
+ n = n / 10;
}
width -= (int) (sizeof aux) - i;
- for (k = 0; k < width; ++k)
- *(dest++) = pad;
+
+ if (!left_justify)
+ {
+ for (k = 0; k < width; ++k)
+ *(dest++) = pad;
+ }
if (sign)
+ {
*(dest++) = '-';
+ }
+ else if (pos_sign)
+ {
+ *(dest++) = '+';
+ }
memcpy(dest, &aux[i], sizeof aux - i);
- return dest + sizeof aux - i;
+ dest += sizeof aux - i;
+
+ if (left_justify)
+ {
+ for (k = 0; k < width; ++k)
+ *(dest++) = pad;
+ }
+
+ return dest;
} /* pdc_off_t2a */
@@ -1936,6 +2178,17 @@ pdc_ftoa_pdfconf(pdc_core *pdc, char *buf, double x)
ifd = pdc->floatdigits;
powd = pow10[ifd];
+ /* number <= 1/powd will be mappepd to 1/powd */
+ if (x <= 1 / powd)
+ {
+ *(dest++) = '0';
+ *(dest++) = '.';
+ while (--ifd)
+ *(dest++) = '0';
+ *(dest++) = '1';
+ return dest;
+ }
+
fract = modf(x, &integ);
f = (long) (fract * powd + 0.5);
@@ -1979,76 +2232,171 @@ pdc_ftoa_pdfconf(pdc_core *pdc, char *buf, double x)
return dest;
} /* pdc_ftoa_pdfconf */
+
+/* flags for formatting function pdc_vxprintf()
+*/
+typedef enum
+{
+ pdc_form_nolimit, /* no buffer limit supplied, no overflow check */
+ pdc_form_fixlimit, /* fix buffer limit, buffer overflow causes exception */
+ pdc_form_varlimit /* buffer overflow causes string truncation */
+}
+pdc_limitkind;
+
+/* write to string or file
+*/
+static char *
+write_sf(
+ pdc_core *pdc,
+ FILE *fp,
+ pdc_limitkind ltd,
+ char *dst,
+ char *limit,
+ const char *src,
+ int n)
+{
+ if (fp != (FILE *) 0)
+ {
+ pdc_fwrite_ascii(pdc, src, (size_t) n, fp);
+ }
+ else
+ {
+ if (ltd != pdc_form_nolimit)
+ {
+ int avail = (int) (limit - dst);
+
+ if (avail < n)
+ {
+ if (ltd == pdc_form_fixlimit)
+ {
+ pdc_error(pdc, PDC_E_INT_FORMOVERFLOW, 0, 0, 0, 0);
+ }
+ else
+ {
+ n = MAX(avail, 0);
+ }
+ }
+ }
+
+ if (n > 0)
+ {
+ memcpy(dst, src, (size_t) n);
+ dst += n;
+ }
+ }
+
+ return dst;
+} /* write2buf */
+
static int
pdc_vxprintf(
pdc_core *pdc,
pdc_bool pdfconf,
+ pdc_limitkind ltd,
char *cp,
+ size_t size,
FILE *fp,
const char *format,
va_list args)
{
static const char fn[] = "pdc_vxprintf";
- const char *format_p;
- char aux[1024];
- char *buf = cp ? cp : aux;
+
+ char buf[1024];
char *dest = buf;
+ int result = 0;
+ char *limit = (char *) 0;
+
+ if (cp != (char *) 0 && ltd != pdc_form_nolimit)
+ limit = cp + (int) (size - 1);
for (/* */ ; /* */ ; /* */)
{
- int width = 0;
- int prec = 0;
+ int width = 0; /* = no width specified */
+ int prec = -1; /* = no precision specified */
char pad = ' ';
pdc_bool left_justify = pdc_false;
+ pdc_bool pos_sign = pdc_false;
+
+ char fbuf[100]; /* format buffer for %f and %g */
+ char * fscan = fbuf;
/* as long as there is no '%', just print.
*/
while (*format != 0 && *format != '%')
*(dest++) = *(format++);
+ if (dest > buf)
+ {
+ int inbuf = (int) (dest - buf);
+
+ cp = write_sf(pdc, fp, ltd, cp, limit, buf, inbuf);
+ result += inbuf;
+ dest = buf;
+ }
+
if (*format == 0)
{
- if (fp != (FILE *) 0)
- {
- if (dest > buf)
- pdc_fwrite_ascii(pdc, buf, (size_t) (dest - buf), fp);
- }
- else
- *dest = 0;
+ if (cp != (char *) 0)
+ *cp = 0;
- return (int) (dest - buf);
+ return result;
}
- format_p = format;
+
+ *(fscan++) = *(format++); /* '%' */
/* get the "flags", if any.
*/
- if (*(++format) == '-')
- {
- left_justify = pdc_true;
- ++format;
- }
+ while (*format && strchr("+- #0", *format))
+ {
+ switch (*format)
+ {
+ case '-': left_justify = pdc_true;
+ break;
- if (*format == '0')
- {
- if (!left_justify)
- pad = '0';
+ case '+': pos_sign = pdc_true;
+ break;
- ++format;
- }
+ case '0': pad = '0';
+ break;
+
+ default: break;
+ }
+
+ *(fscan++) = *(format++);
+ }
/* get the "width", if present.
*/
if (*format == '*')
{
- width = va_arg(args, int); /* TODO: sign? */
+ width = va_arg(args, int);
++format;
+
+ if (width < 0)
+ {
+ width = -width;
+
+ if (!left_justify)
+ {
+ *(fscan++) = '-';
+ left_justify = pdc_true;
+ }
+ }
+
+ fscan += sprintf(fscan, "%d", width);
}
else
{
while (pdc_isdigit(*format))
- width = 10 * width + *(format++) - '0';
+ {
+ width = 10 * width + *format - '0';
+ *(fscan++) = *(format++);
+ }
}
+ if (left_justify)
+ pad = ' ';
+
/* get the "precision", if present.
*/
if (*format == '.')
@@ -2057,23 +2405,37 @@ pdc_vxprintf(
if (*format == '*')
{
- prec = va_arg(args, int); /* TODO: sign? */
+ prec = va_arg(args, int);
++format;
+
+ if (prec >= 0) /* ignore negative precision */
+ {
+ fscan += sprintf(fscan, ".%d", prec);
+ }
}
- else
+ else if (pdc_isdigit(*format))
{
- while (pdc_isdigit(*format))
- prec = 10 * prec + *(format++) - '0';
+ prec = 0;
+ *(fscan++) = '.';
+
+ do
+ {
+ prec = 10 * prec + *format - '0';
+ *(fscan++) = *(format++);
+ } while (pdc_isdigit(*format));
}
}
+ *(fscan++) = *format;
+ *fscan = 0;
+
switch (*format)
{
case 'x':
case 'X':
- dest = pdc_off_t2a(
- dest, (pdc_off_t) va_arg(args, unsigned int),
- width, pad, 16);
+ dest = pdc_uoff_t2a(
+ dest, (pdc_uoff_t) va_arg(args, pdc_uint),
+ width, pad, 16, left_justify);
break;
case 'c':
@@ -2082,7 +2444,13 @@ pdc_vxprintf(
case 'd':
dest = pdc_off_t2a(dest, (pdc_off_t) va_arg(args, int),
- width, pad, 10);
+ width, pad, left_justify, pos_sign);
+ break;
+
+ case 'u':
+ dest = pdc_uoff_t2a(
+ dest, (pdc_uoff_t) va_arg(args, pdc_uint),
+ width, pad, 10, left_justify);
break;
case 'g':
@@ -2093,46 +2461,65 @@ pdc_vxprintf(
}
else
{
- char ff[32];
- size_t n = (size_t) (format - format_p + 1);
-
- strncpy(ff, format_p, n);
- ff[n] = 0;
- dest = pdc_ftoa(pdc, ff, dest, va_arg(args, double));
+ dest = pdc_ftoa(pdc, fbuf, dest, va_arg(args, double));
}
break;
case 'l':
{
- pdc_off_t n;
+ pdc_off_t n = 0;
+ pdc_uoff_t u = 0;
+ pdc_bool ll = pdc_false;
- if (format[1] == 'l')
+ if (*(++format) == 'l')
{
- n = va_arg(args, pdc_off_t);
+ ll = pdc_true;
++format;
}
- else
- {
- n = va_arg(args, long);
- }
- switch (*(++format))
+ if (strchr("xXu", *format))
+ {
+ if (ll)
+ u = va_arg(args, pdc_uoff_t);
+ else
+ u = va_arg(args, pdc_ulong);
+ }
+ else if (*format == 'd')
+ {
+ if (ll)
+ n = va_arg(args, pdc_off_t);
+ else
+ n = va_arg(args, long);
+ }
+ else
+ {
+ pdc_error(pdc, PDC_E_INT_BADFORMAT,
+ pdc_errprintf(pdc, "l%c",
+ pdc_isprint((int) *format) ? *format : '?'),
+ pdc_errprintf(pdc, "0x%02X", *format),
+ 0, 0);
+ }
+
+ switch (*format)
{
case 'x':
case 'X':
- dest = pdc_off_t2a(dest, n, width, pad, 16);
+ dest = pdc_uoff_t2a(
+ dest, u, width, pad, 16, left_justify);
break;
case 'd':
- dest = pdc_off_t2a(dest, n, width, pad, 10);
+ dest = pdc_off_t2a(dest, n, width, pad,
+ left_justify, pos_sign);
+ break;
+
+ case 'u':
+ dest = pdc_uoff_t2a(
+ dest, u, width, pad, 10, left_justify);
break;
default:
- pdc_error(pdc, PDC_E_INT_BADFORMAT,
- pdc_errprintf(pdc, "l%c",
- pdc_isprint((int) *format) ? *format : '?'),
- pdc_errprintf(pdc, "0x%02X", *format),
- 0, 0);
+ break;
}
break;
@@ -2140,8 +2527,15 @@ pdc_vxprintf(
case 'p':
{
+ char tmp[64];
void *ptr = va_arg(args, void *);
- dest += sprintf(dest, "%p", ptr);
+
+ sprintf(tmp, "%p", ptr);
+#if defined(AIX)
+ if (strncmp(tmp, "0x", 2))
+ dest += sprintf(dest, "0x");
+#endif
+ dest += sprintf(dest, "%s", tmp);
break;
}
@@ -2153,51 +2547,65 @@ pdc_vxprintf(
const char *cstr = str;
pdc_bool tobefree = pdc_false;
size_t len;
+ int llen;
- if (str == 0)
- cstr = "(NULL)";
- len = strlen(cstr);
-
- if (*format == 'T')
+ if (str != 0)
{
- int l = va_arg(args, int);
-
- if (str != 0)
+ if (*format == 'T')
{
- cstr = pdc_print_loggstring(pdc, str, l);
- len = strlen(cstr);
+ llen = va_arg(args, int);
+ cstr = pdc_print_loggstring(pdc, str, llen);
+ }
+ else if (*format == 'a')
+ {
+ cstr = pdc_strdup_ext(pdc, str, PDC_CONV_EBCDIC, fn);
+ tobefree = pdc_true;
}
}
-
- if (*format == 'a' && str != 0)
+ else
{
- cstr = pdc_strdup_ext(pdc, str, PDC_CONV_EBCDIC, fn);
- tobefree = pdc_true;
+ cstr = "(NULL)";
+ if (*format == 'T')
+ llen = va_arg(args, int);
}
+ len = strlen(cstr);
+
+ if (prec != -1 && prec < len)
+ {
+ len = prec;
+ }
+
if (!left_justify && len < (size_t) width)
{
- memset(dest, pad, width - len);
- dest += width - len;
+ int inbuf = (int) (width - len);
+
+ memset(buf, pad, (size_t) inbuf);
+ cp = write_sf(pdc, fp, ltd, cp, limit, buf, inbuf);
+ result += inbuf;
}
if (len != 0)
{
+ result += (int) len;
+
if (fp != (FILE *) 0)
{
- if (dest > buf)
- {
- pdc_fwrite_ascii(pdc, buf,
- (size_t) (dest - buf), fp);
- dest = buf;
- }
-
pdc_fwrite_ascii(pdc, cstr, len, fp);
}
- else
+ else if (ltd == pdc_form_nolimit || result < (int) size)
{
- memcpy(dest, cstr, len);
- dest += len;
+ memcpy(cp, cstr, len);
+ cp += (int) len;
+ }
+ else if (ltd == pdc_form_fixlimit)
+ {
+ pdc_error(pdc, PDC_E_INT_FORMOVERFLOW, 0, 0, 0, 0);
+ }
+ else if (cp < limit)
+ {
+ memcpy(cp, cstr, (size_t) (limit - cp));
+ cp = limit;
}
if (tobefree)
@@ -2206,8 +2614,11 @@ pdc_vxprintf(
if (left_justify && len < (size_t) width)
{
- memset(dest, pad, width - len);
- dest += width - len;
+ int inbuf = (int) (width - len);
+
+ memset(buf, pad, (size_t) inbuf);
+ cp = write_sf(pdc, fp, ltd, cp, limit, buf, inbuf);
+ result += inbuf;
}
break;
@@ -2239,7 +2650,8 @@ int
pdc_vfprintf(pdc_core *pdc, pdc_bool pdfconf, FILE *fp,
const char *format, va_list args)
{
- return pdc_vxprintf(pdc, pdfconf, NULL, fp, format, args);
+ return pdc_vxprintf(pdc, pdfconf, pdc_form_nolimit,
+ NULL, 0, fp, format, args);
} /* pdc_vfprintf */
int
@@ -2250,7 +2662,8 @@ pdc_fprintf(pdc_core *pdc, pdc_bool pdfconf, FILE *fp,
va_list ap;
va_start(ap, format);
- result = pdc_vxprintf(pdc, pdfconf, NULL, fp, format, ap);
+ result = pdc_vxprintf(pdc, pdfconf, pdc_form_nolimit,
+ NULL, 0, fp, format, ap);
va_end(ap);
return result;
@@ -2264,7 +2677,8 @@ int
pdc_vsprintf(pdc_core *pdc, pdc_bool pdfconf, char *buf,
const char *format, va_list args)
{
- return pdc_vxprintf(pdc, pdfconf, buf, NULL, format, args);
+ return pdc_vxprintf(pdc, pdfconf, pdc_form_fixlimit,
+ buf, PDC_GEN_BUFSIZE, NULL, format, args);
} /* pdc_vsprintf */
int
@@ -2275,33 +2689,19 @@ pdc_sprintf(pdc_core *pdc, pdc_bool pdfconf, char *buf,
va_list ap;
va_start(ap, format);
- result = pdc_vxprintf(pdc, pdfconf, buf, NULL, format, ap);
+ result = pdc_vxprintf(pdc, pdfconf, pdc_form_nolimit,
+ buf, 0, NULL, format, ap);
va_end(ap);
return result;
} /* pdc_sprintf */
-/*
- * we cannot use own converter because of missing format
- * specifications like %lu
- */
int
-pdc_vsnprintf(char *buf, size_t size, const char *format, va_list args)
+pdc_vsnprintf(pdc_core *pdc, char *buf, size_t size,
+ const char *format, va_list args)
{
- int result;
-
-#if defined (PDC_NO_VSNPRINTF)
- (void) size;
- result = vsprintf(buf, format, args);
-#else
-#if defined(WIN32)
- result = _vsnprintf(buf, size, format, args);
-#else
- result = vsnprintf(buf, size, format, args);
-#endif
-#endif
-
- return result;
+ return pdc_vxprintf(pdc, pdc_false, pdc_form_varlimit,
+ buf, size, NULL, format, args);
} /* pdc_vsnprintf */
@@ -2360,7 +2760,9 @@ pdc_create_treebranch(pdc_core *pdc, pdc_branch *root, const char *pathname,
name = namelist[i];
if (name_p)
- *name_p = pdc_errprintf(pdc, "%.*s", PDC_ERR_MAXSTRLEN, name);
+ {
+ *name_p = pdc_utf8strprint(pdc, name);
+ }
nkids = parent->nkids;
for (j = 0; j < nkids; j++)
@@ -2394,8 +2796,8 @@ pdc_create_treebranch(pdc_core *pdc, pdc_branch *root, const char *pathname,
if (!strcmp(kid->name, name))
{
if (errcode) *errcode = tree_nameexists;
- if (name_p) *name_p =
- pdc_errprintf(pdc, "%.*s", PDC_ERR_MAXSTRLEN, name);
+ if (name_p) *name_p = pdc_utf8strprint(pdc, name);
+
pdc_free(pdc, name);
return NULL;
}
@@ -2562,23 +2964,26 @@ pdc_mp_new(pdc_core *pdc, size_t item_size)
pdc_mempool *mp = (pdc_mempool *)
pdc_malloc(pdc, sizeof (pdc_mempool), fn);
- /* round up 'item_size' to a multiple of 'sizeof (mp_item)'
- ** to ensure proper alignment.
- */
- if ((m = (int) (item_size % sizeof (mp_item))) != 0)
- item_size += sizeof (mp_item) - m;
+ if (mp != (pdc_mempool *) 0)
+ {
+ /* round up 'item_size' to a multiple of 'sizeof (mp_item)'
+ ** to ensure proper alignment.
+ */
+ if ((m = (int) (item_size % sizeof (mp_item))) != 0)
+ item_size += sizeof (mp_item) - m;
- mp->pdc = pdc;
+ mp->pdc = pdc;
- mp->pool_tab = (char **) 0;
- mp->free_list = (mp_item *) 0;
- mp->pool_incr = 1000;
+ mp->pool_tab = (char **) 0;
+ mp->free_list = (mp_item *) 0;
+ mp->pool_incr = 1000;
- mp->ptab_cap = 0;
- mp->ptab_size = 0;
- mp->ptab_incr = 100;
+ mp->ptab_cap = 0;
+ mp->ptab_size = 0;
+ mp->ptab_incr = 100;
- mp->item_size = item_size;
+ mp->item_size = item_size;
+ }
return mp;
} /* pdc_mp_new */
@@ -2724,3 +3129,4 @@ pdc_srand(pdc_core *pdc, pdc_uint seed)
{
pdc->last_rand = seed;
} /* pdc_srand */
+
diff --git a/src/pdflib/pdcore/pc_util.h b/src/pdflib/pdcore/pc_util.h
index af84606..62ce8bb 100644
--- a/src/pdflib/pdcore/pc_util.h
+++ b/src/pdflib/pdcore/pc_util.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_util.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_util.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* Declaration of various utility routines
*
@@ -105,9 +105,22 @@ struct pdc_core_s
#define PDC_FLOAT_ISNULL(x) \
(((((x) < 0) ? -1 * (x) : (x)) < PDC_FLOAT_PREC) ? pdc_true : pdc_false)
+#define PDC_SIGN(x) \
+ (((x) < 0) ? -1 : 1)
+
+/*
+ * general buffer size and
+ * obligatory size of buffers for formatting function pdc_vsprintf().
+ */
+#define PDC_GEN_BUFSIZE 4096
+
+#define PDC_TIME_SBUF_SIZE 50
+
/* flags for pdc_split_stringlist */
#define PDC_SPLIT_ISOPTLIST (1L<<0)
+#define PDC_SPLIT_ISARGLIST (1L<<1)
+/* flags for convert functions */
#define PDC_INT_UNSIGNED (1L<<0)
#define PDC_INT_CHAR (1L<<1)
#define PDC_INT_SHORT (1L<<2)
@@ -147,14 +160,16 @@ pdc_branch_error;
typedef struct pdc_branch_s pdc_branch;
-#define PDC_TIME_SBUF_SIZE 50
-
void pdc_set_unsupp_error(pdc_core *pdc, int err_config, int err_lite,
pdc_bool warning);
+void pdc_ascii_error(pdc_core *pdc, int errnum, int flags, const char *parm1,
+ const char *parm2, const char *parm3, const char *parm4);
void pdc_check_number(pdc_core *pdc, const char *paramname, double dz);
void pdc_check_number_limits(pdc_core *pdc, const char *paramname, double dz,
double dmin, double dmax);
void pdc_check_number_zero(pdc_core *pdc, const char *paramname, double dz);
+int pdc_check_text_length(pdc_core *pdc, const char **text, int len,
+ int maxlen);
typedef struct
{
@@ -173,6 +188,7 @@ void pdc_get_timestr(char *str, pdc_bool ktoascii);
pdc_bool pdc_check_lang_code(pdc_core *pdc, const char* lang_code);
void pdc_setbit(char *bitarr, int bit);
+void pdc_setbit_l2r(char *bitarr, int bit);
pdc_bool pdc_getbit(const char *bitarr, int bit);
void pdc_setbit_text(char *bitarr, const unsigned char *text,
int len, int nbits, int size);
@@ -188,13 +204,15 @@ pdc_sint32 pdc_get_be_long(const pdc_byte *data);
pdc_uint32 pdc_get_be_ulong3(const pdc_byte *data);
pdc_uint32 pdc_get_be_ulong(const pdc_byte *data);
-size_t pdc_strlen(const char *text);
+size_t pdc_wstrlen(const char *str);
+size_t pdc_strlen(const char *str);
char *pdc_getenv(const char *name);
char *pdc_strdup_ext(pdc_core *pdc, const char *text, int flags,
const char *fn);
char *pdc_strdup(pdc_core *pdc, const char *text);
char *pdc_strdup2(pdc_core *pdc, const char *text, size_t len);
char *pdc_strdup_tmp(pdc_core *pdc, const char *text);
+int pdc_convert_pascal_str(const char *pstr, char *cstr);
pdc_bool pdc_logg_isprint(int c);
char *pdc_strprint(pdc_core *pdc, const char *str, int leni,
int maxchar, pdc_strform_kind strform);
@@ -210,15 +228,15 @@ char * pdc_substitute_variables(pdc_core *pdc, const char *string, char vchar,
void pdc_cleanup_stringlist(pdc_core *pdc, char **stringlist);
int pdc_strcmp(const char *s1, const char *s2);
int pdc_stricmp(const char *s1, const char *s2);
+int pdc_stricmp_a(const char *s1, const char *s2);
int pdc_strincmp(const char *s1, const char *s2, int n);
+int pdc_wstrcmp(const char *s1, const char *s2);
char *pdc_strtrim(char *m_str);
char *pdc_str2trim(char *m_str);
char *pdc_strtoupper(char *str);
char *pdc_strtolower(char *str);
-int pdc_tolower_ascii(int c);
-int pdc_toupper_ascii(int c);
-void pdc_swap_bytes(char *instring, int inlen, char *outstring);
-void pdc_swap_unicodes(char *instring);
+void pdc_swap_bytes2(const char *instring, int inlen, char *outstring);
+void pdc_swap_bytes4(const char *instring, int inlen, char *outstring);
char *pdc_strdup_withbom(pdc_core *pdc, const char *text);
void pdc_inflate_ascii(const char *instring, int inlen, char *outstring,
pdc_text_format textformat);
@@ -230,6 +248,8 @@ int pdc_subst_backslash(pdc_core *pdc, pdc_byte *str, int len,
pdc_bool pdc_str2double(const char *string, double *o_dz);
pdc_bool pdc_str2integer(const char *string, int flags, void *o_iz);
+pdc_bool pdc_str2integer_ext(pdc_core *pdc, const char *string, int len,
+ int dupflags, int flags, void *o_iz);
int pdc_vfprintf(pdc_core *pdc, pdc_bool pdfconf, FILE *fp,
const char *format, va_list args);
@@ -239,7 +259,7 @@ int pdc_vsprintf(pdc_core *pdc, pdc_bool pdfconf, char *buf,
const char *format, va_list args);
int pdc_sprintf(pdc_core *pdc, pdc_bool pdfconf, char *buf,
const char *format, ...);
-int pdc_vsnprintf(char *buf, size_t size,
+int pdc_vsnprintf(pdc_core *pdc, char *buf, size_t size,
const char *format, va_list args);
pdc_branch *pdc_init_tree(pdc_core *pdc);
@@ -266,3 +286,4 @@ int pdc_rand(pdc_core *pdc);
void pdc_srand(pdc_core *pdc, pdc_uint seed);
#endif /* PC_UTIL_H */
+
diff --git a/src/pdflib/pdcore/pc_xmp.c b/src/pdflib/pdcore/pc_xmp.c
index f939c0b..ea9f751 100644
--- a/src/pdflib/pdcore/pc_xmp.c
+++ b/src/pdflib/pdcore/pc_xmp.c
@@ -10,12 +10,13 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_xmp.c,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_xmp.c,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* The core XMP support.
*
*/
+#include "pc_ctype.h"
#include "pc_util.h"
#include "pc_strconst.h"
#include "pc_md5.h"
@@ -29,3 +30,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/pdflib/pdcore/pc_xmp.h b/src/pdflib/pdcore/pc_xmp.h
index 4ad0f12..615c380 100644
--- a/src/pdflib/pdcore/pc_xmp.h
+++ b/src/pdflib/pdcore/pc_xmp.h
@@ -10,7 +10,7 @@
| |
*---------------------------------------------------------------------------*/
-/* $Id: pc_xmp.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
+/* $Id: pc_xmp.h,v 1.2 2009/10/20 18:12:26 scuri Exp $
*
* The public core XMP support.
*
@@ -25,3 +25,9 @@
+
+
+
+
+
+