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