This commit is contained in:
John Whitington 2023-05-03 14:19:55 +01:00
parent f192a99a35
commit 9040630487
3 changed files with 17 additions and 33 deletions

View File

@ -1775,17 +1775,10 @@ let whingemalformed () =
exit 1 exit 1
(* Drawing operations. *) (* Drawing operations. *)
let drawops = let drawops = ref []
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 addop o = let addop o =
let v = Hashtbl.find drawops !currstash in drawops := o::!drawops
Hashtbl.replace drawops !currstash (o::v)
let tdeep = ref 0 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)])) | [a; b; c] -> addop (Cpdfdraw.Matrix (Pdftransform.matrix_of_transform [Pdftransform.ShearY ((a, b), c)]))
| _ | exception _ -> error "-msheary takes three numbers" | _ | exception _ -> error "-msheary takes three numbers"
let savexobj s = let saved_ops = ref []
Hashtbl.add drawops s [];
currstash := s
let endsave s = let setxobj s =
currstash := "_" saved_ops := []
let usexobj s = let usexobj s =
try addop (Cpdfdraw.Use "/X1")
addop (Cpdfdraw.SoftXObject (rev (Hashtbl.find drawops s)))
with
_ -> error (Printf.sprintf "Could not find stashed graphics %s\n" s)
let obj_of_jpeg_data data = let obj_of_jpeg_data data =
let w, h = Cpdfjpeg.jpeg_dimensions data in let w, h = Cpdfjpeg.jpeg_dimensions data in
@ -2941,8 +2929,7 @@ and specs =
("-mscale", Arg.String setmscale, " Scale the graphics matrix"); ("-mscale", Arg.String setmscale, " Scale the graphics matrix");
("-mshearx", Arg.String setmshearx, " Shear the graphics matrix in X"); ("-mshearx", Arg.String setmshearx, " Shear the graphics matrix in X");
("-msheary", Arg.String setmshearx, " Shear the graphics matrix in Y"); ("-msheary", Arg.String setmshearx, " Shear the graphics matrix in Y");
("-save", Arg.String savexobj, " Begin to save graphics operators"); ("-xobj", Arg.String setxobj, " Save a sequence of graphics operators");
("-endsave", Arg.String endsave, " End saving of graphics operators");
("-use", Arg.String usexobj, " Use a saved 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-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"); ("-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 let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
write_pdf write_pdf
false 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) -> | Some (Composition json) ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
let filesize = let filesize =
@ -4575,10 +4562,7 @@ let go_withargv argv =
let addrange pdf = AlreadyInMemory pdf, args.dashrange, "", "", ref false, None in let addrange pdf = AlreadyInMemory pdf, args.dashrange, "", "", ref false, None in
args.inputs <- rev (map addrange !output_pdfs) @ rev args.inputs; args.inputs <- rev (map addrange !output_pdfs) @ rev args.inputs;
output_pdfs := []; output_pdfs := [];
go (); go ())
Hashtbl.clear drawops;
Hashtbl.add drawops "_" []
)
sets; sets;
flush stdout; (*r for Windows *) flush stdout; (*r for Windows *)
exit 0 exit 0

View File

@ -32,10 +32,10 @@ type drawops =
| FillStrokeEvenOdd | FillStrokeEvenOdd
| Clip | Clip
| ClipEvenOdd | ClipEvenOdd
| SoftXObject of drawops list | FormXObject of drawops list
| HardXObject of drawops list | Use of string
| Image of string
| ImageXObject of string * Pdf.pdfobject | ImageXObject of string * Pdf.pdfobject
| Image of string
| NewPage | NewPage
| Opacity of float | Opacity of float
| SOpacity 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] | SetLineJoin j -> [Pdfops.Op_j j]
| SetMiterLimit m -> [Pdfops.Op_M m] | SetMiterLimit m -> [Pdfops.Op_M m]
| SetDashPattern (x, y) -> [Pdfops.Op_d (x, y)] | SetDashPattern (x, y) -> [Pdfops.Op_d (x, y)]
| SoftXObject l | HardXObject l -> (*| Use l ->
[Pdfops.Op_q] @ ops_of_drawops pdf endpage filename bates batespad num page l @ [Pdfops.Op_Q] [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))] | Image s -> [Pdfops.Op_Do (try fst (Hashtbl.find images s) with _ -> Cpdferror.error ("Image not found: " ^ s))]
| ImageXObject (s, obj) -> | ImageXObject (s, obj) ->
Hashtbl.add images s (fresh_xobj_name (), Pdf.addobj pdf obj); Hashtbl.add images s (fresh_xobj_name (), Pdf.addobj pdf obj);

View File

@ -30,10 +30,10 @@ type drawops =
| FillStrokeEvenOdd | FillStrokeEvenOdd
| Clip | Clip
| ClipEvenOdd | ClipEvenOdd
| SoftXObject of drawops list | FormXObject of drawops list
| HardXObject of drawops list | Use of string
| Image of string
| ImageXObject of string * Pdf.pdfobject | ImageXObject of string * Pdf.pdfobject
| Image of string
| NewPage | NewPage
| Opacity of float | Opacity of float
| SOpacity of float | SOpacity of float