diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 762971e..82ff35e 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -551,7 +551,6 @@ type args = mutable extract_stream_decompress : bool; mutable verify_single : string option; mutable draw_struct_tree : bool; - mutable image_title : string option; mutable subformat : Cpdfua.subformat option; mutable indent : float option} @@ -690,7 +689,6 @@ let args = extract_stream_decompress = false; verify_single = None; draw_struct_tree = false; - image_title = None; subformat = None; indent = None} @@ -817,7 +815,6 @@ let reset_arguments () = clear Cpdfdrawcontrol.fontpack_initialised; args.verify_single <- None; args.draw_struct_tree <- false; - args.image_title <- None; args.subformat <- None; args.indent <- None @@ -2881,8 +2878,7 @@ let specs = ("-use", Arg.String Cpdfdrawcontrol.usexobj, " Use a saved sequence of graphics operators"); ("-draw-jpeg", Arg.String Cpdfdrawcontrol.addjpeg, " Load a JPEG from file and name it"); ("-draw-png", Arg.String Cpdfdrawcontrol.addpng, " Load a PNG from file and name it"); - ("-image", Arg.String (fun s -> Cpdfdrawcontrol.addimage ?title:args.image_title s; args.image_title <- None), " Draw an image which has already been loaded"); - ("-image-title", Arg.String (fun s -> args.image_title <- Some s), " Give title for the next -image"); + ("-image", Arg.String (fun s -> Cpdfdrawcontrol.addimage s), " Draw an image which has already been loaded"); ("-fill-opacity", Arg.Float Cpdfdrawcontrol.addopacity, " Set opacity"); ("-stroke-opacity", Arg.Float Cpdfdrawcontrol.addsopacity, " Set stroke opacity"); ("-bt", Arg.Unit Cpdfdrawcontrol.addbt, " Begin text"); diff --git a/cpdfdraw.ml b/cpdfdraw.ml index e8cdc78..76734b4 100644 --- a/cpdfdraw.ml +++ b/cpdfdraw.ml @@ -43,7 +43,7 @@ type drawops = | FormXObject of float * float * float * float * string * drawops list | Use of string | ImageXObject of string * Pdf.pdfobject - | Image of string * string option + | Image of string | NewPage | Opacity of float | SOpacity of float @@ -274,9 +274,11 @@ let add_namespace pdf s = type structdata = | StDataBeginTree of string | StDataEndTree - | StDataMCID of string * int * string option + | StDataMCID of string * int | StDataPage of int | StDataNamespace of string + | StEltInfo of string * string + | StEndEltInfo of string let structdata = ref [] @@ -326,6 +328,8 @@ let format_paragraph indent j w s = allops =| rev (Pdfops.Op_T'::justify !ops); flatten (rev !allops) +let current_eltinfo = null_hash () + let rec ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num page = function | Qq ops -> [Pdfops.Op_q] @ ops_of_drawops struct_tree dryrun pdf endpage filename bates batespad num page ops @ [Pdfops.Op_Q] @@ -370,9 +374,9 @@ let rec ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num let pdfname = try fst (Hashtbl.find (res ()).form_xobjects n) with _ -> error ("Form XObject not found: " ^ n) in (res ()).page_names <- pdfname::(res ()).page_names; [Pdfops.Op_Do pdfname] - | Image (s, t) -> + | Image s -> let m = mcid () in - if not dryrun then structdata := StDataMCID ("/Figure", m, t)::!structdata; + if not dryrun then structdata := StDataMCID ("/Figure", m)::!structdata; let pdfname = try fst (Hashtbl.find (res ()).images s) with _ -> error ("Image not found: " ^ s) in (res ()).page_names <- pdfname::(res ()).page_names; (if struct_tree && !do_auto_tag then [Pdfops.Op_BDC ("/Figure", Pdf.Dictionary ["/MCID", Pdf.Integer m])] else []) @@ -433,7 +437,7 @@ let rec ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num [] | TextSection ops -> let m = mcid () in - if not dryrun then structdata := StDataMCID ("/P", m, None)::!structdata; + if not dryrun then structdata := StDataMCID ("/P", m)::!structdata; (if struct_tree && !do_auto_tag then [Pdfops.Op_BDC ("/P", Pdf.Dictionary ["/MCID", Pdf.Integer m])] else []) @ [Pdfops.Op_BT] @ ops_of_drawops struct_tree dryrun pdf endpage filename bates batespad num page ops @@ -463,7 +467,7 @@ let rec ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num | Newline -> [Pdfops.Op_T'] | Tag s -> let m = mcid () in - if not dryrun then structdata := StDataMCID ("/" ^ s, m, None)::!structdata; + if not dryrun then structdata := StDataMCID ("/" ^ s, m)::!structdata; [Pdfops.Op_BDC ("/" ^ s, Pdf.Dictionary ["/MCID", Pdf.Integer m])] | EndTag -> [Pdfops.Op_EMC] | STag s -> if not dryrun then structdata =| StDataBeginTree ("/" ^ s); [] @@ -477,6 +481,12 @@ let rec ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num structdata =| StDataNamespace s end; [] + | EltInfo (k, v) -> + if not dryrun then structdata =| StEltInfo (k, v); + [] + | EndEltInfo s -> + if not dryrun then structdata =| StEndEltInfo s; + [] and ops_of_drawops struct_tree dryrun pdf endpage filename bates batespad num page drawops = flatten (map (ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num page) drawops) @@ -645,14 +655,18 @@ let rec find_tree_contents a level = function let rec make_structure_tree pageobjnums pdf pagenum namespace = function | [] -> [] - | StDataMCID (n, mcid, alt)::t -> - StItem {kind = n; namespace = !namespace; alt; pageobjnum = lookup !pagenum pageobjnums; children = [StMCID mcid]}::make_structure_tree pageobjnums pdf pagenum namespace t + | StDataMCID (n, mcid)::t -> + StItem {kind = n; namespace = !namespace; alt = None; pageobjnum = lookup !pagenum pageobjnums; children = [StMCID mcid]}::make_structure_tree pageobjnums pdf pagenum namespace t | StDataPage n::t -> pagenum := n; make_structure_tree pageobjnums pdf pagenum namespace t | StDataNamespace s::t -> namespace := s; make_structure_tree pageobjnums pdf pagenum namespace t + | StEltInfo (k, v)::t -> + make_structure_tree pageobjnums pdf pagenum namespace t + | StEndEltInfo s::t -> + make_structure_tree pageobjnums pdf pagenum namespace t | StDataBeginTree s::t -> let tree_contents, rest = find_tree_contents [] 1 t in StItem {kind = s; namespace = !namespace; alt = None; pageobjnum = None; children = make_structure_tree pageobjnums pdf pagenum namespace tree_contents} diff --git a/cpdfdraw.mli b/cpdfdraw.mli index bfcf18e..04564ed 100644 --- a/cpdfdraw.mli +++ b/cpdfdraw.mli @@ -36,7 +36,7 @@ type drawops = | FormXObject of float * float * float * float * string * drawops list | Use of string | ImageXObject of string * Pdf.pdfobject - | Image of string * string option + | Image of string | NewPage | Opacity of float | SOpacity of float diff --git a/cpdfdrawcontrol.ml b/cpdfdrawcontrol.ml index dc7527d..43ba739 100644 --- a/cpdfdrawcontrol.ml +++ b/cpdfdrawcontrol.ml @@ -312,8 +312,8 @@ let addpng ?data n = let data = Pdfio.bytes_of_string (contents_of_file filename) in addop (Cpdfdraw.ImageXObject (name, fst (Cpdfimage.obj_of_png_data data))) -let addimage ?title s = - addop (Cpdfdraw.Image (s, title)) +let addimage s = + addop (Cpdfdraw.Image s) let addnewpage s = addop Cpdfdraw.NewPage diff --git a/cpdfdrawcontrol.mli b/cpdfdrawcontrol.mli index e2338ff..b8195f3 100644 --- a/cpdfdrawcontrol.mli +++ b/cpdfdrawcontrol.mli @@ -63,7 +63,7 @@ val endxobj : unit -> unit val usexobj : string -> unit val addjpeg : ?data:Pdfio.rawbytes -> string -> unit val addpng : ?data:Pdfio.rawbytes -> string -> unit -val addimage : ?title:string -> string -> unit +val addimage : string -> unit val addopacity : float -> unit val addsopacity : float -> unit val addbt : unit -> unit