Add impl for -no-auto-tag
This commit is contained in:
parent
cccb1eee93
commit
935d43d5eb
31
cpdfdraw.ml
31
cpdfdraw.ml
|
@ -3,6 +3,8 @@ open Cpdferror
|
||||||
|
|
||||||
let do_add_artifacts = ref false
|
let do_add_artifacts = ref false
|
||||||
|
|
||||||
|
let do_auto_tag = ref true
|
||||||
|
|
||||||
type colspec =
|
type colspec =
|
||||||
NoCol
|
NoCol
|
||||||
| RGB of float * float * float
|
| RGB of float * float * float
|
||||||
|
@ -56,6 +58,8 @@ type drawops =
|
||||||
| TextScale of float
|
| TextScale of float
|
||||||
| RenderMode of int
|
| RenderMode of int
|
||||||
| Rise of float
|
| Rise of float
|
||||||
|
| Tag of string
|
||||||
|
| EndTag
|
||||||
| STag of string
|
| STag of string
|
||||||
| EndSTag
|
| EndSTag
|
||||||
| BeginArtifact
|
| BeginArtifact
|
||||||
|
@ -335,9 +339,9 @@ let rec ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num
|
||||||
if not dryrun then structdata := StDataMCID ("/Figure", m, t)::!structdata;
|
if not dryrun then structdata := StDataMCID ("/Figure", m, t)::!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 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 [])
|
||||||
@ [Pdfops.Op_Do pdfname]
|
@ [Pdfops.Op_Do pdfname]
|
||||||
@ (if struct_tree then [Pdfops.Op_EMC] else [])
|
@ (if struct_tree && !do_auto_tag then [Pdfops.Op_EMC] else [])
|
||||||
| ImageXObject (s, obj) ->
|
| ImageXObject (s, obj) ->
|
||||||
Hashtbl.replace (res ()).images s (fresh_name "/I", Pdf.addobj pdf obj);
|
Hashtbl.replace (res ()).images s (fresh_name "/I", Pdf.addobj pdf obj);
|
||||||
[]
|
[]
|
||||||
|
@ -394,11 +398,11 @@ 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, None)::!structdata;
|
||||||
(if struct_tree 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
|
||||||
@ [Pdfops.Op_ET]
|
@ [Pdfops.Op_ET]
|
||||||
@ (if struct_tree then [Pdfops.Op_EMC] else [])
|
@ (if struct_tree && !do_auto_tag then [Pdfops.Op_EMC] else [])
|
||||||
| Text s ->
|
| Text s ->
|
||||||
if dryrun then iter (fun c -> Hashtbl.replace (res ()).current_fontpack_codepoints c ()) (Pdftext.codepoints_of_utf8 s);
|
if dryrun then iter (fun c -> Hashtbl.replace (res ()).current_fontpack_codepoints c ()) (Pdftext.codepoints_of_utf8 s);
|
||||||
fst (runs_of_utf8 s)
|
fst (runs_of_utf8 s)
|
||||||
|
@ -416,16 +420,15 @@ let rec ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num
|
||||||
| RenderMode i -> [Pdfops.Op_Tr i]
|
| RenderMode i -> [Pdfops.Op_Tr i]
|
||||||
| Rise f -> [Pdfops.Op_Ts f]
|
| Rise f -> [Pdfops.Op_Ts f]
|
||||||
| Newline -> [Pdfops.Op_T']
|
| Newline -> [Pdfops.Op_T']
|
||||||
| STag s ->
|
| Tag s ->
|
||||||
structdata =| StDataBeginTree s;
|
let m = mcid () in
|
||||||
[]
|
if not dryrun then structdata := StDataMCID (s, m, None)::!structdata;
|
||||||
| EndSTag ->
|
[Pdfops.Op_BDC (s, Pdf.Dictionary ["/MCID", Pdf.Integer m])]
|
||||||
structdata =| StDataEndTree;
|
| EndTag -> [Pdfops.Op_EMC]
|
||||||
[]
|
| STag s -> structdata =| StDataBeginTree s; []
|
||||||
| BeginArtifact ->
|
| EndSTag -> structdata =| StDataEndTree; []
|
||||||
[Pdfops.Op_BMC "/Artifact"]
|
| BeginArtifact -> [Pdfops.Op_BMC "/Artifact"]
|
||||||
| EndArtifact ->
|
| EndArtifact -> [Pdfops.Op_EMC]
|
||||||
[Pdfops.Op_EMC]
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
@ -53,6 +53,8 @@ type drawops =
|
||||||
| TextScale of float
|
| TextScale of float
|
||||||
| RenderMode of int
|
| RenderMode of int
|
||||||
| Rise of float
|
| Rise of float
|
||||||
|
| Tag of string
|
||||||
|
| EndTag
|
||||||
| STag of string
|
| STag of string
|
||||||
| EndSTag
|
| EndSTag
|
||||||
| BeginArtifact
|
| BeginArtifact
|
||||||
|
@ -60,6 +62,8 @@ type drawops =
|
||||||
|
|
||||||
val do_add_artifacts : bool ref
|
val do_add_artifacts : bool ref
|
||||||
|
|
||||||
|
val do_auto_tag : bool ref
|
||||||
|
|
||||||
(** Calling [draw fast underneath filename bates batespad range pdf drawops] draws on
|
(** Calling [draw fast underneath filename bates batespad range pdf drawops] draws on
|
||||||
top of all the pages in the range. *)
|
top of all the pages in the range. *)
|
||||||
val draw : struct_tree:bool ->
|
val draw : struct_tree:bool ->
|
||||||
|
|
|
@ -95,17 +95,29 @@ let setstroke s =
|
||||||
let setfill s =
|
let setfill s =
|
||||||
addop (Cpdfdraw.SetFill (col_of_string s))
|
addop (Cpdfdraw.SetFill (col_of_string s))
|
||||||
|
|
||||||
let addtag t = ()
|
let addtag t =
|
||||||
|
addop (Cpdfdraw.Tag t)
|
||||||
|
|
||||||
let addstag t =
|
let addstag t =
|
||||||
addop (Cpdfdraw.STag t)
|
addop (Cpdfdraw.STag t)
|
||||||
let endtag () = ()
|
|
||||||
|
let endtag () =
|
||||||
|
addop Cpdfdraw.EndTag
|
||||||
|
|
||||||
let endstag () =
|
let endstag () =
|
||||||
addop Cpdfdraw.EndSTag
|
addop Cpdfdraw.EndSTag
|
||||||
let autotags b = ()
|
|
||||||
|
let autotags b =
|
||||||
|
Cpdfdraw.do_auto_tag := b
|
||||||
|
|
||||||
let autoartifacts b =
|
let autoartifacts b =
|
||||||
Cpdfdraw.do_add_artifacts := b
|
Cpdfdraw.do_add_artifacts := b
|
||||||
let artifact () = ()
|
|
||||||
let endartifact () = ()
|
let artifact () =
|
||||||
|
addop Cpdfdraw.BeginArtifact
|
||||||
|
|
||||||
|
let endartifact () =
|
||||||
|
addop Cpdfdraw.EndArtifact
|
||||||
|
|
||||||
let addrect s =
|
let addrect s =
|
||||||
let x, y, w, h = Cpdfcoord.parse_rectangle (Pdf.empty ()) s in
|
let x, y, w, h = Cpdfcoord.parse_rectangle (Pdf.empty ()) s in
|
||||||
|
|
Loading…
Reference in New Issue