2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-05 03:40:53 +00:00

tweak when we decide to use hex strings vs literal strings

git-svn-id: svn+q:///qpdf/trunk@810 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
Jay Berkenbilt 2009-10-17 17:31:52 +00:00
parent 55e400376a
commit 27e8d4bbff
7 changed files with 26 additions and 24 deletions

View File

@ -9,6 +9,10 @@
#include <string.h>
// See above about ctype.
static bool is_ascii_printable(unsigned char ch)
{
return ((ch >= 32) && (ch <= 126));
}
static bool is_iso_latin1_printable(unsigned char ch)
{
return (((ch >= 32) && (ch <= 126)) || (ch >= 160));
@ -40,12 +44,13 @@ QPDF_String::unparse(bool force_binary)
for (unsigned int i = 0; i < this->val.length(); ++i)
{
char ch = this->val[i];
// Note: do not use locale to determine printability. The PDF
// specification accepts arbitrary binary data. Some locales
// imply multibyte characters. We'll consider something
// printable if it is printable in ISO-Latin-1. We'll code
// this manually rather than being rude and setting locale.
if ((ch == 0) || (! (is_iso_latin1_printable(ch) ||
// Note: do not use locale to determine printability. The
// PDF specification accepts arbitrary binary data. Some
// locales imply multibyte characters. We'll consider
// something printable if it is printable in 7-bit ASCII.
// We'll code this manually rather than being rude and
// setting locale.
if ((ch == 0) || (! (is_ascii_printable(ch) ||
strchr("\n\r\t\b\f", ch))))
{
++nonprintable;
@ -64,10 +69,7 @@ QPDF_String::unparse(bool force_binary)
}
// Use hex notation if more than 20% of the characters are not
// printable in the current locale. Uniformly distributed random
// characters will not pass this test even with ISO-Latin-1 in
// which 76% are either printable or in the set of standard
// escaped characters.
// printable in plain ASCII.
if (5 * nonprintable > val.length())
{
use_hexstring = true;

View File

@ -1,7 +1,7 @@
D:20000914005716
Acrobat Distiller 4.05 for Windows
(hs[¨.<7ľ¸"\205\020ş~?öĽzßů\220\024\203Ţ#W\230\214\nBŞH)
(ó*Řý˘Ź:F\027\21177\nov\007\031 I\235­\205\n\225ńwš\b\233n Ę)
<68735ba82e3c37b5b8228510ba7e3ff6a57adff9901483de2357988c0a42aa48>
<f32ad8fda2ac3a46178937370a6f76071920499dad850a95f177b9089b6e20ca>
1 g
/GS1 gs
1 i

View File

@ -5,5 +5,5 @@
/nesting is direct
/strings is direct
unparse: 7 0 R
unparseResolved: << /hex#20strings [ (Potato) <01020300040560> (AB) ] /indirect 8 0 R /nesting << /a [ 1 2 << /x (y) >> [ (z) ] ] /b << / (legal) /a [ 1 2 ] >> >> /strings [ (one) ($¢) () (\(\)) (\() (\)) (a\f\b\t\r\nb) <410042> (a\nb) (a b) ] >>
unparseResolved: << /hex#20strings [ (Potato) <01020300040560> (AB) ] /indirect 8 0 R /nesting << /a [ 1 2 << /x (y) >> [ (z) ] ] /b << / (legal) /a [ 1 2 ] >> >> /strings [ (one) <24a2> () (\(\)) (\() (\)) (a\f\b\t\r\nb) <410042> (a\nb) (a b) ] >>
test 1 done

View File

@ -40,7 +40,7 @@ endobj
>>
/strings [
(one)
($「)
<24a2>
()
(\(\))
(\()
@ -129,12 +129,12 @@ xref
0000000000 65535 f
0000000052 00000 n
0000000133 00000 n
0000000576 00000 n
0000000685 00000 n
0000000927 00000 n
0000001026 00000 n
0000001072 00000 n
0000001217 00000 n
0000000578 00000 n
0000000687 00000 n
0000000929 00000 n
0000001028 00000 n
0000001074 00000 n
0000001219 00000 n
trailer <<
/QTest 2 0 R
/Root 1 0 R
@ -142,5 +142,5 @@ trailer <<
/ID [<31415926535897932384626433832795><31415926535897932384626433832795>]
>>
startxref
1252
1254
%%EOF

View File

@ -12,7 +12,7 @@ three lines
(\001B%DEF)<01>
<8a8b>
(ab)
<8c>(ン) ) >
<8c><dd> ) >
<610062> (MOO)
-- stream 1 --
This stream does end with a newline.

View File

@ -95,7 +95,7 @@ trailer <<
/QTest (¡Hola!)
/Root 1 0 R
/Size 8
/Z ('\236yÔ\005\037ăjř׸B^Q\n\2139\224\rD|kă˘JZm:˝l\231\002\\)
/Z <279e79d4051fe36af8d7b8425e510a8b39940d447c6be3a24a5a6d3abd6c99025c>
/ID [<31415926535897932384626433832795><31415926535897932384626433832795>]
>>
startxref

View File

@ -1,2 +1,2 @@
Object is stream. Dictionary:
<< /DecodeParms << /Columns 4 /Predictor 12 >> /Encrypt 11 0 R /Filter /FlateDecode /ID [ (ª&\237þÂ\226±?>ø5ª¡:\n\b) (ím\023\021OµUt\bµ\026Ê9'\025\033) ] /Info 3 0 R /Length 52 /Root 1 0 R /Size 13 /Type /XRef /W [ 1 2 1 ] >>
<< /DecodeParms << /Columns 4 /Predictor 12 >> /Encrypt 11 0 R /Filter /FlateDecode /ID [ <aa269ffec296b13f3ef835aaa13a0a08> <ed6d13114fb5557408b516ca3927151b> ] /Info 3 0 R /Length 52 /Root 1 0 R /Size 13 /Type /XRef /W [ 1 2 1 ] >>