Tidying split_max

This commit is contained in:
John Whitington 2023-10-30 14:21:49 +00:00
parent 3ea4086a0b
commit 99a43a24a5
1 changed files with 2 additions and 6 deletions

View File

@ -3158,8 +3158,7 @@ let split_pdf
(* Given a PDF, write the split as if we had selected pages, and return its filesize. Delete it. *) (* Given a PDF, write the split as if we had selected pages, and return its filesize. Delete it. *)
let split_max_fits pdf s p q = let split_max_fits pdf s p q =
(*Printf.printf "split_max_fits: %i, %i\n%!" p q;*) if q < p then error "split_max_fits" else
assert (q >= p);
let filename = Filename.temp_file "cpdf" "sm" in let filename = Filename.temp_file "cpdf" "sm" in
let range = ilist p q in let range = ilist p q in
let newpdf = Pdfpage.pdf_of_pages ~retain_numbering:args.retain_numbering pdf range in let newpdf = Pdfpage.pdf_of_pages ~retain_numbering:args.retain_numbering pdf range in
@ -3175,7 +3174,6 @@ let split_max_fits pdf s p q =
(* Binary search on q from current value down to p to find max which fits. Returns q. Upon failure, returns -1 *) (* Binary search on q from current value down to p to find max which fits. Returns q. Upon failure, returns -1 *)
let rec split_max_search pdf s b p q = let rec split_max_search pdf s b p q =
(*Printf.printf "split_max_search b p q %i %i %i\n%!" b p q;*)
if p = q then if p = q then
if split_max_fits pdf s b q then q else -1 if split_max_fits pdf s b q then q else -1
else else
@ -3185,15 +3183,13 @@ let rec split_max_search pdf s b p q =
else split_max_search pdf s b p half else split_max_search pdf s b p half
let rec split_max enc original_filename ~squeeze output_spec s pdf = let rec split_max enc original_filename ~squeeze output_spec s pdf =
Printf.printf "***split_max\n";
let outs = ref [] in let outs = ref [] in
let p = ref 1 in let p = ref 1 in
let endpage = Pdfpage.endpage pdf in let endpage = Pdfpage.endpage pdf in
let q = ref endpage in let q = ref endpage in
while !p < !q || !p = endpage do while !p < !q || !p = endpage do
(*Printf.printf "Calling split_max_search %i %i %i\n%!" !p !p !q;*)
let newq = split_max_search pdf s !p !p !q in let newq = split_max_search pdf s !p !p !q in
if newq = -1 then (Printf.eprintf "Failed to make small enough split at page %i\n" !p; exit 2) else if newq = -1 then (Printf.eprintf "Failed to make small enough split at page %i. No files written.\n" !p; exit 2) else
begin begin
Printf.printf "Pages %i-%i will fit...\n%!" !p newq; Printf.printf "Pages %i-%i will fit...\n%!" !p newq;
outs := ilist !p newq::!outs; outs := ilist !p newq::!outs;