Clean up -image-title
This commit is contained in:
parent
9e1cf6f78e
commit
36581a6ee7
|
@ -551,7 +551,6 @@ type args =
|
||||||
mutable extract_stream_decompress : bool;
|
mutable extract_stream_decompress : bool;
|
||||||
mutable verify_single : string option;
|
mutable verify_single : string option;
|
||||||
mutable draw_struct_tree : bool;
|
mutable draw_struct_tree : bool;
|
||||||
mutable image_title : string option;
|
|
||||||
mutable subformat : Cpdfua.subformat option;
|
mutable subformat : Cpdfua.subformat option;
|
||||||
mutable indent : float option}
|
mutable indent : float option}
|
||||||
|
|
||||||
|
@ -690,7 +689,6 @@ let args =
|
||||||
extract_stream_decompress = false;
|
extract_stream_decompress = false;
|
||||||
verify_single = None;
|
verify_single = None;
|
||||||
draw_struct_tree = false;
|
draw_struct_tree = false;
|
||||||
image_title = None;
|
|
||||||
subformat = None;
|
subformat = None;
|
||||||
indent = None}
|
indent = None}
|
||||||
|
|
||||||
|
@ -817,7 +815,6 @@ let reset_arguments () =
|
||||||
clear Cpdfdrawcontrol.fontpack_initialised;
|
clear Cpdfdrawcontrol.fontpack_initialised;
|
||||||
args.verify_single <- None;
|
args.verify_single <- None;
|
||||||
args.draw_struct_tree <- false;
|
args.draw_struct_tree <- false;
|
||||||
args.image_title <- None;
|
|
||||||
args.subformat <- None;
|
args.subformat <- None;
|
||||||
args.indent <- None
|
args.indent <- None
|
||||||
|
|
||||||
|
@ -2881,8 +2878,7 @@ let specs =
|
||||||
("-use", Arg.String Cpdfdrawcontrol.usexobj, " Use a saved sequence of graphics operators");
|
("-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-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");
|
("-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", Arg.String (fun s -> Cpdfdrawcontrol.addimage s), " 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");
|
|
||||||
("-fill-opacity", Arg.Float Cpdfdrawcontrol.addopacity, " Set opacity");
|
("-fill-opacity", Arg.Float Cpdfdrawcontrol.addopacity, " Set opacity");
|
||||||
("-stroke-opacity", Arg.Float Cpdfdrawcontrol.addsopacity, " Set stroke opacity");
|
("-stroke-opacity", Arg.Float Cpdfdrawcontrol.addsopacity, " Set stroke opacity");
|
||||||
("-bt", Arg.Unit Cpdfdrawcontrol.addbt, " Begin text");
|
("-bt", Arg.Unit Cpdfdrawcontrol.addbt, " Begin text");
|
||||||
|
|
30
cpdfdraw.ml
30
cpdfdraw.ml
|
@ -43,7 +43,7 @@ type drawops =
|
||||||
| FormXObject of float * float * float * float * 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 * string option
|
| Image of string
|
||||||
| NewPage
|
| NewPage
|
||||||
| Opacity of float
|
| Opacity of float
|
||||||
| SOpacity of float
|
| SOpacity of float
|
||||||
|
@ -274,9 +274,11 @@ let add_namespace pdf s =
|
||||||
type structdata =
|
type structdata =
|
||||||
| StDataBeginTree of string
|
| StDataBeginTree of string
|
||||||
| StDataEndTree
|
| StDataEndTree
|
||||||
| StDataMCID of string * int * string option
|
| StDataMCID of string * int
|
||||||
| StDataPage of int
|
| StDataPage of int
|
||||||
| StDataNamespace of string
|
| StDataNamespace of string
|
||||||
|
| StEltInfo of string * string
|
||||||
|
| StEndEltInfo of string
|
||||||
|
|
||||||
let structdata = ref []
|
let structdata = ref []
|
||||||
|
|
||||||
|
@ -326,6 +328,8 @@ let format_paragraph indent j w s =
|
||||||
allops =| rev (Pdfops.Op_T'::justify !ops);
|
allops =| rev (Pdfops.Op_T'::justify !ops);
|
||||||
flatten (rev !allops)
|
flatten (rev !allops)
|
||||||
|
|
||||||
|
let current_eltinfo = null_hash ()
|
||||||
|
|
||||||
let rec ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num page = function
|
let rec ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num page = function
|
||||||
| Qq ops ->
|
| Qq ops ->
|
||||||
[Pdfops.Op_q] @ ops_of_drawops struct_tree dryrun pdf endpage filename bates batespad num page ops @ [Pdfops.Op_Q]
|
[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
|
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;
|
(res ()).page_names <- pdfname::(res ()).page_names;
|
||||||
[Pdfops.Op_Do pdfname]
|
[Pdfops.Op_Do pdfname]
|
||||||
| Image (s, t) ->
|
| Image s ->
|
||||||
let m = mcid () in
|
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
|
let pdfname = try fst (Hashtbl.find (res ()).images s) with _ -> error ("Image not found: " ^ s) in
|
||||||
(res ()).page_names <- pdfname::(res ()).page_names;
|
(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 [])
|
(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 ->
|
| TextSection ops ->
|
||||||
let m = mcid () in
|
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 [])
|
(if struct_tree && !do_auto_tag then [Pdfops.Op_BDC ("/P", Pdf.Dictionary ["/MCID", Pdf.Integer m])] else [])
|
||||||
@ [Pdfops.Op_BT]
|
@ [Pdfops.Op_BT]
|
||||||
@ ops_of_drawops struct_tree dryrun pdf endpage filename bates batespad num page ops
|
@ 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']
|
| Newline -> [Pdfops.Op_T']
|
||||||
| Tag s ->
|
| Tag s ->
|
||||||
let m = mcid () in
|
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])]
|
[Pdfops.Op_BDC ("/" ^ s, Pdf.Dictionary ["/MCID", Pdf.Integer m])]
|
||||||
| EndTag -> [Pdfops.Op_EMC]
|
| EndTag -> [Pdfops.Op_EMC]
|
||||||
| STag s -> if not dryrun then structdata =| StDataBeginTree ("/" ^ s); []
|
| 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
|
structdata =| StDataNamespace s
|
||||||
end;
|
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 =
|
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)
|
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
|
let rec make_structure_tree pageobjnums pdf pagenum namespace = function
|
||||||
| [] -> []
|
| [] -> []
|
||||||
| StDataMCID (n, mcid, alt)::t ->
|
| StDataMCID (n, mcid)::t ->
|
||||||
StItem {kind = n; namespace = !namespace; alt; pageobjnum = lookup !pagenum pageobjnums; children = [StMCID mcid]}::make_structure_tree pageobjnums pdf pagenum namespace 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 ->
|
| StDataPage n::t ->
|
||||||
pagenum := n;
|
pagenum := n;
|
||||||
make_structure_tree pageobjnums pdf pagenum namespace t
|
make_structure_tree pageobjnums pdf pagenum namespace t
|
||||||
| StDataNamespace s::t ->
|
| StDataNamespace s::t ->
|
||||||
namespace := s;
|
namespace := s;
|
||||||
make_structure_tree pageobjnums pdf pagenum namespace t
|
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 ->
|
| StDataBeginTree s::t ->
|
||||||
let tree_contents, rest = find_tree_contents [] 1 t in
|
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}
|
StItem {kind = s; namespace = !namespace; alt = None; pageobjnum = None; children = make_structure_tree pageobjnums pdf pagenum namespace tree_contents}
|
||||||
|
|
|
@ -36,7 +36,7 @@ type drawops =
|
||||||
| FormXObject of float * float * float * float * 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 * string option
|
| Image of string
|
||||||
| NewPage
|
| NewPage
|
||||||
| Opacity of float
|
| Opacity of float
|
||||||
| SOpacity of float
|
| SOpacity of float
|
||||||
|
|
|
@ -312,8 +312,8 @@ let addpng ?data n =
|
||||||
let data = Pdfio.bytes_of_string (contents_of_file filename) in
|
let data = Pdfio.bytes_of_string (contents_of_file filename) in
|
||||||
addop (Cpdfdraw.ImageXObject (name, fst (Cpdfimage.obj_of_png_data data)))
|
addop (Cpdfdraw.ImageXObject (name, fst (Cpdfimage.obj_of_png_data data)))
|
||||||
|
|
||||||
let addimage ?title s =
|
let addimage s =
|
||||||
addop (Cpdfdraw.Image (s, title))
|
addop (Cpdfdraw.Image s)
|
||||||
|
|
||||||
let addnewpage s =
|
let addnewpage s =
|
||||||
addop Cpdfdraw.NewPage
|
addop Cpdfdraw.NewPage
|
||||||
|
|
|
@ -63,7 +63,7 @@ val endxobj : unit -> unit
|
||||||
val usexobj : string -> unit
|
val usexobj : string -> unit
|
||||||
val addjpeg : ?data:Pdfio.rawbytes -> string -> unit
|
val addjpeg : ?data:Pdfio.rawbytes -> string -> unit
|
||||||
val addpng : ?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 addopacity : float -> unit
|
||||||
val addsopacity : float -> unit
|
val addsopacity : float -> unit
|
||||||
val addbt : unit -> unit
|
val addbt : unit -> unit
|
||||||
|
|
Loading…
Reference in New Issue