This commit is contained in:
John Whitington 2023-05-03 13:43:57 +01:00
parent a622c76bbd
commit 829edb6460
2 changed files with 23 additions and 3 deletions

View File

@ -2947,7 +2947,6 @@ and specs =
("-draw-jpeg", Arg.String addjpeg, " Load a JPEG from file and name it");
("-draw-png", Arg.String addpng, " Load a PNG from file and name it");
("-image", Arg.String addimage, " Draw an image which has already been loaded");
("-newpage", Arg.Unit addnewpage, " Move to a fresh page");
("-opacity", Arg.Float addopacity, " Set opacity");
("-sopacity", Arg.Float addsopacity, " Set stroke opacity");
("-bt", Arg.Unit addbt, " Begin text");
@ -2963,6 +2962,7 @@ and specs =
("-rendermode", Arg.Int addrendermode, " Set text rendering mode");
("-rise", Arg.Float addrise, " Set text rise");
("-nl", Arg.Unit addnewline, " New line");
("-newpage", Arg.Unit addnewpage, " Move to a fresh page");
(* These items are undocumented *)
("-debug", Arg.Unit setdebug, "");
("-debug-crypt", Arg.Unit setdebugcrypt, "");

View File

@ -81,6 +81,10 @@ let fresh_font_name pdf f =
Hashtbl.add fonts n (Pdf.Indirect (Pdftext.write_font pdf f));
n
(* This will remove fonts, images etc, for moving on to the next page *)
let reset_state () =
()
let time = ref Cpdfstrftime.dummy
let process_specials pdf endpage filename bates batespad num page s =
@ -173,8 +177,7 @@ and ops_of_drawops pdf endpage filename bates batespad num page drawops =
flatten (map (ops_of_drawop pdf endpage filename bates batespad num page) drawops)
(* Draw all the accumulated operators. *)
let draw ~filename ~bates ~batespad fast range pdf drawops =
time := Cpdfstrftime.current_time ();
let draw_single ~filename ~bates ~batespad fast range pdf drawops =
let endpage = Pdfpage.endpage pdf in
let pages = Pdfpage.pages_of_pagetree pdf in
let ss =
@ -230,3 +233,20 @@ let draw ~filename ~bates ~batespad fast range pdf drawops =
pages
in
Pdfpage.change_pages true pdf pages
let draw ~filename ~bates ~batespad fast range pdf drawops =
time := Cpdfstrftime.current_time ();
let pdf = ref pdf in
let range = ref range in
let chunks = ref (split_around (eq NewPage) drawops) in
while !chunks <> [] do
reset_state ();
pdf := draw_single ~filename ~bates ~batespad fast !range !pdf (hd !chunks);
chunks := tl !chunks;
if !chunks <> [] then begin
let endpage = Pdfpage.endpage !pdf in
pdf := Cpdfpad.padafter [endpage] !pdf;
range := [endpage + 1]
end
done;
!pdf