Skeleton for -paras

This commit is contained in:
John Whitington 2024-09-19 14:41:51 +01:00
parent d70621ed57
commit 76eaa3da21
5 changed files with 35 additions and 18 deletions

View File

@ -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");

View File

@ -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]

View File

@ -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

View File

@ -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))

View File

@ -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. *)