From c02f47cf4f5037cc924eba3ac044b478dcf61432 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Fri, 18 Oct 2013 11:52:01 +0100 Subject: [PATCH] Changed multiline text support to deal properly with double backslashes, for example '\\\\n' on command line gives '\\n' which should print '\n' not act as a newline --- cpdf.ml | 9 +++++---- cpdfcommand.ml | 8 ++++---- hello.pdf | 29 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 hello.pdf diff --git a/cpdf.ml b/cpdf.ml index da16a20..f5e831d 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -1707,6 +1707,7 @@ let addtext let split_at_newline t = let rec split_at_newline_inner prev = function | [] -> rev (map implode (map rev prev)) + | '\\'::'\\'::'n'::t -> split_at_newline_inner (('n'::'\\'::'\\'::hd prev)::tl prev) t | '\\'::'n'::t -> split_at_newline_inner ([]::prev) t | h::t -> split_at_newline_inner ((h::hd prev)::tl prev) t in @@ -1716,7 +1717,8 @@ let rec unescape_chars 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_chars (chr::prev) t + unescape_chars (chr::prev) t + | '\\'::'\\'::t -> unescape_chars ('\\'::prev) t | '\\'::c::t when c <> 'n' -> unescape_chars (c::prev) t | h::t -> unescape_chars (h::prev) t @@ -1753,9 +1755,8 @@ let flprint "\n";*) ops_metrics := []; let text = winansi_of_utf8 text in - let text = unescape_string text in - let lines = split_at_newline text - and pdf = ref pdf in + let lines = map unescape_string (split_at_newline text) in + let pdf = ref pdf in let voffset = match position with | Bottom _ | BottomLeft _ | BottomRight _ -> diff --git a/cpdfcommand.ml b/cpdfcommand.ml index e84baec..dc17d1f 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1,9 +1,9 @@ (* cpdf command line tools *) let demo = false -and noncomp = true -and major_version = 1 -and minor_version = 8 -and version_date = "(unreleased)" +let noncomp = false +let major_version = 1 +let minor_version = 8 +let version_date = "(unreleased)" open Pdfutil open Pdfio diff --git a/hello.pdf b/hello.pdf new file mode 100644 index 0000000..e4209ab --- /dev/null +++ b/hello.pdf @@ -0,0 +1,29 @@ +%PDF-1.1 +% +1 0 obj +<>>>>>/MediaBox[0 0 595.275590551 841.88976378]/Rotate 0/Contents[4 0 R]>> +endobj +2 0 obj +<> +endobj +3 0 obj +<> +endobj +4 0 obj +<> +stream +1 0 0 1 50 770 cm BT /F0 36 Tf (Hello, World!) Tj ET +endstream +endobj +xref +0 5 +0000000000 65535 f +0000000015 00000 n +0000000200 00000 n +0000000245 00000 n +0000000296 00000 n +trailer +<> +startxref +397 +%%EOF