From 9040630487d484c889435c287e1cc5d18f199ab5 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Wed, 3 May 2023 14:19:55 +0100 Subject: [PATCH] more --- cpdfcommand.ml | 34 +++++++++------------------------- cpdfdraw.ml | 10 +++++----- cpdfdraw.mli | 6 +++--- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 9fb3d5b..e4fa596 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1775,17 +1775,10 @@ let whingemalformed () = exit 1 (* Drawing operations. *) -let drawops = - let t = Hashtbl.create 10 in - Hashtbl.add t "_" []; - t - -(* For now, re-using a save name is undefined, and nesting them is undefined too. To fix in both cases. *) -let currstash = ref "_" +let drawops = ref [] let addop o = - let v = Hashtbl.find drawops !currstash in - Hashtbl.replace drawops !currstash (o::v) + drawops := o::!drawops let tdeep = ref 0 @@ -1949,18 +1942,13 @@ let setmsheary s = | [a; b; c] -> addop (Cpdfdraw.Matrix (Pdftransform.matrix_of_transform [Pdftransform.ShearY ((a, b), c)])) | _ | exception _ -> error "-msheary takes three numbers" -let savexobj s = - Hashtbl.add drawops s []; - currstash := s +let saved_ops = ref [] -let endsave s = - currstash := "_" +let setxobj s = + saved_ops := [] let usexobj s = - try - addop (Cpdfdraw.SoftXObject (rev (Hashtbl.find drawops s))) - with - _ -> error (Printf.sprintf "Could not find stashed graphics %s\n" s) + addop (Cpdfdraw.Use "/X1") let obj_of_jpeg_data data = let w, h = Cpdfjpeg.jpeg_dimensions data in @@ -2941,8 +2929,7 @@ and specs = ("-mscale", Arg.String setmscale, " Scale the graphics matrix"); ("-mshearx", Arg.String setmshearx, " Shear the graphics matrix in X"); ("-msheary", Arg.String setmshearx, " Shear the graphics matrix in Y"); - ("-save", Arg.String savexobj, " Begin to save graphics operators"); - ("-endsave", Arg.String endsave, " End saving of graphics operators"); + ("-xobj", Arg.String setxobj, " Save a sequence of graphics operators"); ("-use", Arg.String usexobj, " Use a saved sequence of graphics operators"); ("-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"); @@ -4470,7 +4457,7 @@ let go () = let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in write_pdf false - (Cpdfdraw.draw ~filename:args.original_filename ~bates:args.bates ~batespad:args.batespad args.fast range pdf (rev (Hashtbl.find drawops "_"))) + (Cpdfdraw.draw ~filename:args.original_filename ~bates:args.bates ~batespad:args.batespad args.fast range pdf (rev !drawops)) | Some (Composition json) -> let pdf = get_single_pdf args.op false in let filesize = @@ -4575,10 +4562,7 @@ let go_withargv argv = let addrange pdf = AlreadyInMemory pdf, args.dashrange, "", "", ref false, None in args.inputs <- rev (map addrange !output_pdfs) @ rev args.inputs; output_pdfs := []; - go (); - Hashtbl.clear drawops; - Hashtbl.add drawops "_" [] - ) + go ()) sets; flush stdout; (*r for Windows *) exit 0 diff --git a/cpdfdraw.ml b/cpdfdraw.ml index 2e99662..92f84aa 100644 --- a/cpdfdraw.ml +++ b/cpdfdraw.ml @@ -32,10 +32,10 @@ type drawops = | FillStrokeEvenOdd | Clip | ClipEvenOdd - | SoftXObject of drawops list - | HardXObject of drawops list - | Image of string + | FormXObject of drawops list + | Use of string | ImageXObject of string * Pdf.pdfobject + | Image of string | NewPage | Opacity of float | SOpacity of float @@ -128,8 +128,8 @@ let rec ops_of_drawop pdf endpage filename bates batespad num page = function | SetLineJoin j -> [Pdfops.Op_j j] | SetMiterLimit m -> [Pdfops.Op_M m] | SetDashPattern (x, y) -> [Pdfops.Op_d (x, y)] - | SoftXObject l | HardXObject l -> - [Pdfops.Op_q] @ ops_of_drawops pdf endpage filename bates batespad num page l @ [Pdfops.Op_Q] + (*| Use l -> + [Pdfops.Op_q] @ ops_of_drawops pdf endpage filename bates batespad num page l @ [Pdfops.Op_Q]*) | Image s -> [Pdfops.Op_Do (try fst (Hashtbl.find images s) with _ -> Cpdferror.error ("Image not found: " ^ s))] | ImageXObject (s, obj) -> Hashtbl.add images s (fresh_xobj_name (), Pdf.addobj pdf obj); diff --git a/cpdfdraw.mli b/cpdfdraw.mli index c9a4cce..af151f8 100644 --- a/cpdfdraw.mli +++ b/cpdfdraw.mli @@ -30,10 +30,10 @@ type drawops = | FillStrokeEvenOdd | Clip | ClipEvenOdd - | SoftXObject of drawops list - | HardXObject of drawops list - | Image of string + | FormXObject of drawops list + | Use of string | ImageXObject of string * Pdf.pdfobject + | Image of string | NewPage | Opacity of float | SOpacity of float