Justification working now

This commit is contained in:
John Whitington 2024-09-15 15:33:00 +01:00
parent 93a28695d1
commit de68538857
2 changed files with 12 additions and 5 deletions

View File

@ -11,7 +11,7 @@ New features:
* New -replace-obj to edit dictionary entries via chain
* Create PDF/UA files from scratch with -create-pdf-ua-[1|2]
* Create structure information for files with -draw
* Draw can now make paragraphs
* Draw can now make paragraphs with -para, -paras
* Add structure information to -typeset, add -typeset-subformat
* = Supported by a grant from NLnet

View File

@ -244,7 +244,14 @@ let format_paragraph j w s =
let rs_and_widths = ref (map runs_of_utf8 ss) in
let space_runs, space_width = runs_of_utf8 " " in
let remaining = ref w in
let allops = ref [] in
let ops = ref [] in
let justify ops =
match j with
| Left -> ops
| Right -> [Pdfops.Op_Td (~-.(!remaining), 0.)] @ ops @ [Pdfops.Op_Td (!remaining, 0.)]
| Centre -> [Pdfops.Op_Td (~-.(!remaining) /. 2., 0.)] @ ops @ [Pdfops.Op_Td (!remaining /. 2., 0.)]
in
while !rs_and_widths <> [] do
let word, word_width = hd !rs_and_widths in
if !remaining = w then
@ -265,13 +272,13 @@ let format_paragraph j w s =
else
(* If current line not empty, and not enough space, emit newline. *)
begin
ops := Pdfops.Op_T'::!ops;
allops =| rev (Pdfops.Op_T'::justify !ops);
ops := [];
remaining := w
end
done;
rev !ops
(* TODO Justification - requires a way to offset, which means keeping the ops
separate, and retaining the full line width *)
allops =| rev (Pdfops.Op_T'::justify !ops);
flatten (rev !allops)
let rec ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num page = function
| Qq ops ->