\pdfescapestring/convertStringToPDFString
Hello,
what is the purpose of \pdfescapestring?
It calls convertStringToPDFString of utils.c with a useless
semantics:
char *convertStringToPDFString (char *in)
{
static char pstrbuf[MAX_PSTRING_LEN];
char *out = pstrbuf;
int lin = strlen (in);
int i, j;
char buf[4];
j = 0;
for (i = 0; i < lin; i++) {
check_buf(j + sizeof(buf), MAX_PSTRING_LEN);
if ((unsigned char)in[i] < ' ') {
/* convert control characters into hex */
sprintf (buf, "#%02x", (unsigned int)(unsigned char)in[i]);
out[j++] = buf[0];
out[j++] = buf[1];
out[j++] = buf[2];
}
else if ((in[i] == '(') || (in[i] == ')')) {
/* escape paranthesis */
out[j++] = '\\';
out[j++] = in[i];
}
else if (in[i] == '\\') {
/* escape backslash */
out[j++] = '\\';
out[j++] = '\\';
}
else {
/* copy char :-) */
out[j++] = in[i];
}
}
out[j] = '\0';
return pstrbuf;
}
It mixes escaping for PDF *strings* with escaping for PDF *names*.
'(', ')', '\\' are escaped for PDF strings,
control characters are escaped for PDF names.
Thus I suggest to change the control character escaping from
hexadecimal #xx to octal \ooo:
sprintf (buf, "\\%03o", (unsigned int)(unsigned char)in[i]);
out[j++] = buf[0];
out[j++] = buf[1];
out[j++] = buf[2];
out[j++] = buf[3];
Then \pdfescapestring could be used for conversions to pdf strings.
Also a \pdfescapename / convertStringToPDFName is useful. Here
especially the delimiter characters must be escaped in the
#xx manner.
Yours sincerely
Heiko
On 2005-06-15 19:51:26 +0200, Heiko Oberdiek wrote:
It mixes escaping for PDF *strings* with escaping for PDF *names*. '(', ')', '\\' are escaped for PDF strings, control characters are escaped for PDF names.
Thus I suggest to change the control character escaping from hexadecimal #xx to octal \ooo:
sprintf (buf, "\\%03o", (unsigned int)(unsigned char)in[i]); out[j++] = buf[0]; out[j++] = buf[1]; out[j++] = buf[2]; out[j++] = buf[3];
Then \pdfescapestring could be used for conversions to pdf strings.
Also a \pdfescapename / convertStringToPDFName is useful. Here especially the delimiter characters must be escaped in the #xx manner.
Thanks, will do. Best regards Martin -- http://www.tm.oneiros.de
On 2005-06-16 01:41:48 +0200, Martin Schröder wrote:
On 2005-06-15 19:51:26 +0200, Heiko Oberdiek wrote:
Then \pdfescapestring could be used for conversions to pdf strings.
Also a \pdfescapename / convertStringToPDFName is useful. Here especially the delimiter characters must be escaped in the #xx manner.
Thanks, will do.
Fixed in the new beta; it also has \pdfescapename/\pdflastescapedname. Best Martin -- http://www.tm.oneiros.de
Hi, Heiko:
Then \pdfescapestring could be used for conversions to pdf strings. Also a \pdfescapename / convertStringToPDFName is useful. Here especially the delimiter characters must be escaped in the #xx manner.
Martin:
Fixed in the new beta; it also has \pdfescapename/\pdflastescapedname.
I've given a try to describe them in manual (Literals and specials chapter). Please look if the description is relevant. What is \pdflastescapedname for? BR, -- Pawe/l Jackowski P.Jackowski@gust.org.pl
On 2005-06-17 14:55:54 +0200, Pawel Jackowski wrote:
I've given a try to describe them in manual (Literals and specials chapter). Please look if the description is relevant. What is \pdflastescapedname for?
It's like \pdflastescapedstring. Don't know if anybody needs it. :-) -------------------------------- \pdfcompresslevel=0 \tt \pdfescapestring {a ( aä)ßb} \pdflastescapedstring \pdfescapename {a ( aä)ßb} \pdflastescapedname \bye -------------------------------- Best Martin -- http://www.tm.oneiros.de
On Fri, 17 Jun 2005, Martin Schröder wrote:
It's like \pdflastescapedstring. Don't know if anybody needs it. :-) -------------------------------- \pdfcompresslevel=0 \tt \pdfescapestring {a ( aä)ßb} \pdflastescapedstring
here i get (a\134040\134\050\134040a\134344\134\051\134337b) is this right? aren't there a few backslashes missing?
\pdfescapename {a ( aä)ßb} \pdflastescapedname \bye
Regards, Hartmut
On Fri, 17 Jun 2005, Hartmut Henkel wrote:
On Fri, 17 Jun 2005, Martin Schröder wrote:
It's like \pdflastescapedstring. Don't know if anybody needs it. :-) -------------------------------- \pdfcompresslevel=0 \tt \pdfescapestring {a ( aä)ßb} \pdflastescapedstring
here i get
(a\134040\134\050\134040a\134344\134\051\134337b)
in utils.c, convertStringToPDFString (), maybe line check_buf(j + sizeof(buf), MAX_PSTRING_LEN); should be check_buf(j + sizeof(out), MAX_PSTRING_LEN); Regards, Hartmut
Hi,
I've given a try to describe them in manual (Literals and specials chapter). Please look if the description is relevant. What is \pdflastescapedname for?
It's like \pdflastescapedstring. Don't know if anybody needs it. :-)
Aghh, it seems I've missundestood the usage of the command. Sorry, at the moment I can't try it out. So, \pdfescape... commands do NOT expand things on fly (that would be to nice :), just stores the expansion in \pdflastescaped... right? If so, I'd insist on using `lastescape' instead of `lastescaped', to keep naming convention consistent. How do you think? BR, -- Pawe/l Jackowski P.Jackowski@gust.org.pl
On Fri, Jun 17, 2005 at 03:42:17PM +0200, Martin Schröder wrote:
On 2005-06-17 14:55:54 +0200, Pawel Jackowski wrote:
I've given a try to describe them in manual (Literals and specials chapter). Please look if the description is relevant. What is \pdflastescapedname for?
It's like \pdflastescapedstring. Don't know if anybody needs it. :-)
I do.
Example mimetype of embedded file streams:
/Type /EmbeddedFile
/Subtype /... % mimetype encoded as name object.
"..." is arbitrary user data, especially slashes and spaces
can occur inside. Unencoded such characters break the
validity of the dictionary object.
Also names have an implementation limit of 127 bytes,
thus \pdfescapename can be used here, of course after
fixing the bug of unescaped delimiter characters, I
am working on it.
Yours sincerely
Heiko
Hi, Martin:
It's like \pdflastescapedstring. Don't know if anybody needs it. :-)
Heiko:
I do. Example mimetype of embedded file streams[...]
I like the idea of \pdfescape very much either. I use such commands in many other cases, such as special color spaces (i.e. /PANTONE#20231#20CV) or optional content (i.e << /Type /OCG /Name (Layer\(1\)) >>). A `hand-made' implementation of those command is not a horror, but primitives provides it in more general way and obviously much faster. BR, -- Pawe/l Jackowski P.Jackowski@gust.org.pl
participants (4)
-
Hartmut Henkel
-
Heiko Oberdiek
-
Martin Schröder
-
Pawel Jackowski