This commit is contained in:
John Whitington 2023-05-04 13:53:49 +01:00
parent 5660e4817c
commit 7351e73a3f
3 changed files with 18 additions and 11 deletions

View File

@ -503,7 +503,8 @@ type args =
mutable toc_title : string; mutable toc_title : string;
mutable toc_bookmark : bool; mutable toc_bookmark : bool;
mutable idir_only_pdfs : bool; mutable idir_only_pdfs : bool;
mutable no_warn_rotate : bool} mutable no_warn_rotate : bool;
mutable xobj_bbox : float * float * float * float}
let args = let args =
{op = None; {op = None;
@ -624,7 +625,8 @@ let args =
toc_title = "Table of Contents"; toc_title = "Table of Contents";
toc_bookmark = true; toc_bookmark = true;
idir_only_pdfs = false; idir_only_pdfs = false;
no_warn_rotate = false} no_warn_rotate = false;
xobj_bbox = (0., 0., 1000., 1000.)}
let reset_arguments () = let reset_arguments () =
args.op <- None; args.op <- None;
@ -728,7 +730,8 @@ let reset_arguments () =
args.dict_entry_search <- None; args.dict_entry_search <- None;
args.toc_title <- "Table of Contents"; args.toc_title <- "Table of Contents";
args.toc_bookmark <- true; args.toc_bookmark <- true;
args.idir_only_pdfs <- false args.idir_only_pdfs <- false;
args.xobj_bbox <- (0., 0., 1000., 1000.)
(* Do not reset original_filename or cpdflin or was_encrypted or (* Do not reset original_filename or cpdflin or was_encrypted or
was_decrypted_with_owner or recrypt or producer or creator or path_to_* or was_decrypted_with_owner or recrypt or producer or creator or path_to_* or
gs_malformed or gs_quiet or no-warn-rotate, since we want these to work gs_malformed or gs_quiet or no-warn-rotate, since we want these to work
@ -1786,6 +1789,9 @@ let startxobj n =
we_are_saving := Some n; we_are_saving := Some n;
Hashtbl.add saved_ops n [] Hashtbl.add saved_ops n []
let xobjbbox s =
args.xobj_bbox <- Cpdfcoord.parse_rectangle (Pdf.empty ()) s
let addop o = let addop o =
match !we_are_saving with match !we_are_saving with
| Some n -> | Some n ->
@ -1797,7 +1803,8 @@ let endxobj () =
match !we_are_saving with match !we_are_saving with
| Some n -> | Some n ->
we_are_saving := None; we_are_saving := None;
addop (Cpdfdraw.FormXObject (n, rev (Hashtbl.find saved_ops n))) let a, b, c, d = args.xobj_bbox in
addop (Cpdfdraw.FormXObject (a, b, c, d, n, rev (Hashtbl.find saved_ops n)))
| None -> | None ->
error "misplaced -endxobj" error "misplaced -endxobj"
@ -2945,7 +2952,8 @@ 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");
("-xobj", Arg.String startxobj, " Beign saving a sequence of graphics operators"); ("-xobj-bbox", Arg.String xobjbbox, " Specify the bounding box for xobjects");
("-xobj", Arg.String startxobj, " Begin saving a sequence of graphics operators");
("-endxobj", Arg.Unit endxobj, " End saving a sequence of graphics operators"); ("-endxobj", Arg.Unit endxobj, " End saving a sequence 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");

View File

@ -32,7 +32,7 @@ type drawops =
| FillStrokeEvenOdd | FillStrokeEvenOdd
| Clip | Clip
| ClipEvenOdd | ClipEvenOdd
| FormXObject of string * drawops list | FormXObject of float * float * float * float * string * drawops list
| Use of string | Use of string
| ImageXObject of string * Pdf.pdfobject | ImageXObject of string * Pdf.pdfobject
| Image of string | Image of string
@ -61,7 +61,6 @@ let current_url = ref None
let fonts = null_hash () let fonts = null_hash ()
let form_xobjects = null_hash () let form_xobjects = null_hash ()
let current_font = let current_font =
ref (Pdftext.StandardFont (Pdftext.TimesRoman, Pdftext.WinAnsiEncoding)) ref (Pdftext.StandardFont (Pdftext.TimesRoman, Pdftext.WinAnsiEncoding))
@ -129,7 +128,7 @@ 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)]
| FormXObject (n, ops) -> create_form_xobject pdf endpage filename bates batespad num page n ops; [] | FormXObject (a, b, c, d, n, ops) -> create_form_xobject a b c d pdf endpage filename bates batespad num page n ops; []
| Use n -> [Pdfops.Op_Do n] | Use n -> [Pdfops.Op_Do n]
| 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) ->
@ -177,7 +176,7 @@ let rec ops_of_drawop pdf endpage filename bates batespad num page = function
and ops_of_drawops pdf endpage filename bates batespad num page drawops = 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) flatten (map (ops_of_drawop pdf endpage filename bates batespad num page) drawops)
and create_form_xobject pdf endpage filename bates batespad num page n ops = and create_form_xobject a b c d pdf endpage filename bates batespad num page n ops =
let data = let data =
Pdfio.bytes_of_string (Pdfops.string_of_ops (ops_of_drawops pdf endpage filename bates batespad num page ops)) Pdfio.bytes_of_string (Pdfops.string_of_ops (ops_of_drawops pdf endpage filename bates batespad num page ops))
in in
@ -187,7 +186,7 @@ and create_form_xobject pdf endpage filename bates batespad num page n ops =
(Pdf.Dictionary (Pdf.Dictionary
[("/Length", Pdf.Integer (Pdfio.bytes_size data)); [("/Length", Pdf.Integer (Pdfio.bytes_size data));
("/Subtype", Pdf.Name "/Form"); ("/Subtype", Pdf.Name "/Form");
("/BBox", Pdf.Array [Pdf.Integer 0; Pdf.Integer 0; Pdf.Integer 1000; Pdf.Integer 1000]) (* FIXME*) ("/BBox", Pdf.Array [Pdf.Real a; Pdf.Real b; Pdf.Real c; Pdf.Real d])
], ],
Pdf.Got data)} Pdf.Got data)}
in in

View File

@ -30,7 +30,7 @@ type drawops =
| FillStrokeEvenOdd | FillStrokeEvenOdd
| Clip | Clip
| ClipEvenOdd | ClipEvenOdd
| FormXObject of string * drawops list | FormXObject of float * float * float * float * string * drawops list
| Use of string | Use of string
| ImageXObject of string * Pdf.pdfobject | ImageXObject of string * Pdf.pdfobject
| Image of string | Image of string