From 0dd958c95ba1a5c9aa9825c1b5c856e28af6b8ba Mon Sep 17 00:00:00 2001 From: John Whitington Date: Tue, 14 Jan 2014 13:35:20 +0000 Subject: [PATCH] Re-instated octal escape sequences when -raw is used for -set-title etc. --- cpdf.ml | 1 + cpdfcommand.ml | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cpdf.ml b/cpdf.ml index fab39fc..9faa47c 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -881,6 +881,7 @@ let set_viewer_preference (key, value, version) pdf = (* \section{Set an entry in the /Info dictionary} *) let set_pdf_info (key, value, version) pdf = + Printf.printf "set_pdf_info: %s %s\n" key (Pdfwrite.string_of_pdf value); let infodict = match Pdf.lookup_direct pdf "/Info" pdf.Pdf.trailerdict with | Some d -> d diff --git a/cpdfcommand.ml b/cpdfcommand.ml index f80cdd0..97e97e5 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -2684,7 +2684,18 @@ let addrectangle (w, h) color position relative_to_cropbox underneath range pdf in Cpdf.process_pages addrectangle_page pdf range -(* Main function *) +let rec unescape_octals prev = function + | [] -> rev prev + | '\\'::('0'..'9' as a)::('0'..'9' as b)::('0'..'9' as c)::t -> + let chr = char_of_int (int_of_string ("0o" ^ implode [a;b;c])) in + unescape_octals (chr::prev) t + | '\\'::'\\'::t -> unescape_octals ('\\'::prev) t + | h::t -> unescape_octals (h::prev) t + +let unescape_octals s = + implode (unescape_octals [] (explode s)) + + (* Main function *) let go () = match args.op with | Some Version -> @@ -2965,8 +2976,9 @@ let go () = | Some ((SetAuthor _ | SetTitle _ | SetSubject _ | SetKeywords _ | SetCreate _ | SetModify _ | SetCreator _ | SetProducer _ | SetTrapped | SetUntrapped) as op) -> + flprint "a set operation\n"; let key, value, version = - let f s = if args.encoding <> Cpdf.Raw then Pdftext.pdfdocstring_of_utf8 s else s in + let f s = if args.encoding <> Cpdf.Raw then Pdftext.pdfdocstring_of_utf8 s else unescape_octals s in match op with | SetAuthor s -> "/Author", Pdf.String (f s), 0 | SetTitle s -> "/Title", Pdf.String (f s), 1