Skip to content

Commit

Permalink
Escape strings used in pdf outlines
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlHegbloom committed May 14, 2016
1 parent 669a28e commit 4120aa7
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/src/Plugins/Pdf/pdf_hummus_renderer.cpp
Expand Up @@ -1983,6 +1983,49 @@ std_string_to_string (std::string str) {
return r;
}

// At least in outlines a single paren will break the PDF and no more
// outlines will show up after it. Does it need this for other PDF
// strings?
//
// Jim King, Document Management — Portable Document Format — Part 1:
// PDF 1.7 (Adobe Sys. Inc., First ed. 2008),
// §7.3.4.2, Literal Strings, Table 3, Escape sequences in literal strings
//
// Fixme? This does not handle octal character sequences \nnn. Does it
// ever need to?
//
string
escape_string (string s) {
int i, n= N(s);
string r;
for (i=0; i<n; i++)
switch (s[i]) {
case '\n':
r << '\\' << 'n';
break;
case '\r':
r << '\\' << 'r';
break;
case '\t':
r << '\\' << 't';
break;
case '\b':
r << '\\' << 'b';
break;
case '\f':
r << '\\' << 'f';
break;
case '(':
case ')':
case '\\':
r << '\\' << s[i];
break;
default:
r << s[i];
}
return r;
}

static PDFTextString
as_hummus_string (string s) {
s= cork_to_utf8 (s);
Expand Down Expand Up @@ -2108,7 +2151,8 @@ pdf_hummus_renderer_rep::toc_entry (string kind, string title, SI x, SI y) {
if (kind == "toc-6") ls= 8;
if (kind == "toc-7") ls= 9;

outlines << outline_data(title, page_num, to_x(x), to_y(y+20*pixel), ls);
// Use escape_string here. Should it be part of prepare_text instead?
outlines << outline_data(escape_string (title), page_num, to_x(x), to_y(y+20*pixel), ls);
}

void pdf_hummus_renderer_rep::recurse (ObjectsContext& objectsContext, list<outline_data>& it, ObjectIDType parentId,
Expand Down

0 comments on commit 4120aa7

Please sign in to comment.