diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 90072d8..ade6ba9 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -2867,6 +2867,7 @@ let specs = ("-text", Arg.String Cpdfdrawcontrol.addtext, " Draw text"); ("-stext", Arg.String Cpdfdrawcontrol.addspecialtext, " Draw text with %specials"); ("-para", Arg.String Cpdfdrawcontrol.addpara, " Add a paragraph of text"); + ("-paras", Arg.String Cpdfdrawcontrol.addparas, " Add paragraphs of text, splitting on newlines"); ("-leading", Arg.Float (fun f -> Cpdfdrawcontrol.addop (Cpdfdraw.Leading f)), " Set leading"); ("-charspace", Arg.Float (fun f -> Cpdfdrawcontrol.addop (Cpdfdraw.CharSpace f)), " Set character spacing"); ("-wordspace", Arg.Float (fun f -> Cpdfdrawcontrol.addop (Cpdfdraw.WordSpace f)), " Set word space"); diff --git a/cpdfdraw.ml b/cpdfdraw.ml index 6d7ecd0..369fa8d 100644 --- a/cpdfdraw.ml +++ b/cpdfdraw.ml @@ -50,7 +50,7 @@ type drawops = | TextSection of drawops list | Text of string | SpecialText of string - | Para of justification * float * string + | Para of justification * float * string list | Newline | Leading of float | CharSpace of float @@ -428,6 +428,7 @@ 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 | Leading f -> [Pdfops.Op_TL f] diff --git a/cpdfdraw.mli b/cpdfdraw.mli index 4e8b156..981ce93 100644 --- a/cpdfdraw.mli +++ b/cpdfdraw.mli @@ -45,7 +45,7 @@ type drawops = | TextSection of drawops list | Text of string | SpecialText of string - | Para of justification * float * string + | Para of justification * float * string list | Newline | Leading of float | CharSpace of float diff --git a/cpdfdrawcontrol.ml b/cpdfdrawcontrol.ml index b22ac5d..f935999 100644 --- a/cpdfdrawcontrol.ml +++ b/cpdfdrawcontrol.ml @@ -350,20 +350,34 @@ let addspecialtext s = addop (Cpdfdraw.SpecialText s) (* "L200pt=....." *) +let jws s = + let j, rest = + match explode s with + | 'L'::t -> (Cpdfdraw.Left, t) + | 'R'::t -> (Cpdfdraw.Right, t) + | 'C'::t -> (Cpdfdraw.Centre, t) + | _ -> error "Unknown justification specification" + in + let w, s = + match String.split_on_char '=' (implode rest) with + | [w; s] -> (Cpdfcoord.parse_single_number (Pdf.empty ()) w, s) + | _ -> error "addjpeg: bad file specification" + in + j, w, s + let addpara s = - begin match !drawops with _::_::_ -> () | _ -> error "-stext must be in a -bt / -et section" end; - add_default_fontpack (!getfontname ()); - addop (Cpdfdraw.Font (!getfontname (), !getfontsize ())); - let j, rest = - match explode s with - | 'L'::t -> (Cpdfdraw.Left, t) - | 'R'::t -> (Cpdfdraw.Right, t) - | 'C'::t -> (Cpdfdraw.Centre, t) - | _ -> error "Unknown justification specification" - in - let w, s = - match String.split_on_char '=' (implode rest) with - | [w; s] -> (Cpdfcoord.parse_single_number (Pdf.empty ()) w, s) - | _ -> error "addjpeg: bad file specification" - in - addop (Cpdfdraw.Para (j, w, s)) + begin match !drawops with _::_::_ -> () | _ -> error "-para must be in a -bt / -et section" end; + add_default_fontpack (!getfontname ()); + addop (Cpdfdraw.Font (!getfontname (), !getfontsize ())); + let j, w, s = jws s in + addop (Cpdfdraw.Para (j, w, [s])) + +let split_on_newline s = [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 + addop (Cpdfdraw.Para (j, w, splits)) diff --git a/cpdfdrawcontrol.mli b/cpdfdrawcontrol.mli index e0036e0..f546f55 100644 --- a/cpdfdrawcontrol.mli +++ b/cpdfdrawcontrol.mli @@ -76,6 +76,7 @@ val add_default_fontpack : string -> unit val addtext : string -> unit val addspecialtext : string -> unit val addpara : string -> unit +val addparas : string -> unit (** This the beginnings of separation between cpdfcommand and cpdfdraw when drawing, for use in cpdflib. It is presently undocumented. *)