diff --git a/cpdfdraw.ml b/cpdfdraw.ml index 369fa8d..7650a4f 100644 --- a/cpdfdraw.ml +++ b/cpdfdraw.ml @@ -428,9 +428,13 @@ let rec ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num if dryrun then iter (fun c -> Hashtbl.replace (res ()).current_fontpack_codepoints c ()) (Pdftext.codepoints_of_utf8 s); fst (runs_of_utf8 s) | Para (j, w, s) -> - let s = hd s in (* FIXME *) - if dryrun then iter (fun c -> Hashtbl.replace (res ()).current_fontpack_codepoints c ()) (Pdftext.codepoints_of_utf8 s); - format_paragraph j w s + if dryrun then iter (iter (fun c -> Hashtbl.replace (res ()).current_fontpack_codepoints c ())) (map Pdftext.codepoints_of_utf8 s); + let first = ref true in + flatten + (map + (function para -> + if not !first then ([Pdfops.Op_T']) else (clear first; []) @ format_paragraph j w para) + s) | Leading f -> [Pdfops.Op_TL f] | CharSpace f -> [Pdfops.Op_Tc f] | WordSpace f -> [Pdfops.Op_Tw f] diff --git a/cpdfdrawcontrol.ml b/cpdfdrawcontrol.ml index f935999..c272dcc 100644 --- a/cpdfdrawcontrol.ml +++ b/cpdfdrawcontrol.ml @@ -372,12 +372,18 @@ let addpara s = let j, w, s = jws s in addop (Cpdfdraw.Para (j, w, [s])) -let split_on_newline s = [s] +let rec split_on_newlines a = function + | 0x005c::0x004e::t -> rev a::split_on_newlines [] t + | h::t -> split_on_newlines (h::a) t + | [] -> if a = [] then [] else [rev a] + +let split_on_newlines s = + map Pdftext.utf8_of_codepoints (split_on_newlines [] (Pdftext.codepoints_of_utf8 s)) let addparas s = begin match !drawops with _::_::_ -> () | _ -> error "-paras must be in a -bt / -et section" end; add_default_fontpack (!getfontname ()); addop (Cpdfdraw.Font (!getfontname (), !getfontsize ())); let j, w, s = jws s in - let splits = split_on_newline s in + let splits = split_on_newlines s in addop (Cpdfdraw.Para (j, w, splits))