From fc28d8c4695bd31b3700998caaf8980a92caa49d Mon Sep 17 00:00:00 2001 From: John Whitington Date: Wed, 18 Sep 2024 15:31:24 +0100 Subject: [PATCH] Skeleton for -namespace --- cpdfcommand.ml | 9 +++++++++ cpdfdraw.ml | 7 +++++++ cpdfdraw.mli | 1 + cpdfdrawcontrol.ml | 3 +++ cpdfdrawcontrol.mli | 1 + 5 files changed, 21 insertions(+) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 34db148..90072d8 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -404,6 +404,9 @@ let spray_outputs = ref [] (* A list of PDFs to be output, if no output method was specified. *) let output_pdfs : Pdf.t list ref = ref [] +let standard_namespace = "http://iso.org/pdf/ssn" +let pdf2_namespace = "http://iso.org/pdf2/ssn" + type font = | StandardFont of Pdftext.standard_font | EmbeddedFont of string @@ -1885,6 +1888,11 @@ let setreplaceobj s = | [a; b] -> args.op <- Some (ReplaceObj (a, b)) | _ -> error "replace_obj: bad specification" +let expand_namespace = function + | "PDF" -> standard_namespace + | "PDF2" -> pdf2_namespace + | x -> x + let specs = [("-version", Arg.Unit (setop Version), @@ -2813,6 +2821,7 @@ let specs = ("-artifact", Arg.Unit (fun _ -> Cpdfdrawcontrol.artifact ()), " Begin an artifact"); ("-end-artifact", Arg.Unit (fun _ -> Cpdfdrawcontrol.endartifact ()), "End an artifact"); ("-no-auto-artifacts", Arg.Unit (fun _ -> Cpdfdrawcontrol.autoartifacts false), " Don't mark untagged content as artifacts"); + ("-namespace", Arg.String (fun s -> Cpdfdrawcontrol.addnamespace (expand_namespace s)), " Set the structure tree namespace"); ("-rect", Arg.String Cpdfdrawcontrol.addrect, " Draw rectangle"); ("-to", Arg.String Cpdfdrawcontrol.addto, " Move to"); ("-line", Arg.String Cpdfdrawcontrol.addline, " Add line to"); diff --git a/cpdfdraw.ml b/cpdfdraw.ml index d4f68dc..6466196 100644 --- a/cpdfdraw.ml +++ b/cpdfdraw.ml @@ -64,6 +64,7 @@ type drawops = | EndSTag | BeginArtifact | EndArtifact + | Namespace of string (*let rec string_of_drawop = function | Qq o -> "Qq (" ^ string_of_drawops o ^ ")" @@ -238,6 +239,11 @@ let mcidr = ref ~-1 let mcid () = (incr mcidr; !mcidr) let mcpage = ref ~-1 +let standard_namespace = "http://iso.org/pdf/ssn" +let pdf2_namespace = "http://iso.org/pdf2/ssn" + +let namespace = ref standard_namespace + (* The structure data, as it is created, in flat form. Later on, this will be reconstructed into a structure tree. *) type structdata = @@ -429,6 +435,7 @@ let rec ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num | EndSTag -> if not dryrun then structdata =| StDataEndTree; [] | BeginArtifact -> [Pdfops.Op_BMC "/BeginArtifact"] | EndArtifact -> [Pdfops.Op_BMC "/EndArtifact"] + | Namespace s -> if not dryrun then namespace := 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) diff --git a/cpdfdraw.mli b/cpdfdraw.mli index 8844f48..4e8b156 100644 --- a/cpdfdraw.mli +++ b/cpdfdraw.mli @@ -59,6 +59,7 @@ type drawops = | EndSTag | BeginArtifact | EndArtifact + | Namespace of string val do_add_artifacts : bool ref diff --git a/cpdfdrawcontrol.ml b/cpdfdrawcontrol.ml index 883f8d7..b22ac5d 100644 --- a/cpdfdrawcontrol.ml +++ b/cpdfdrawcontrol.ml @@ -119,6 +119,9 @@ let artifact () = let endartifact () = addop Cpdfdraw.EndArtifact +let addnamespace s = + addop (Cpdfdraw.Namespace s) + let addrect s = let x, y, w, h = Cpdfcoord.parse_rectangle (Pdf.empty ()) s in addop (Cpdfdraw.Rect (x, y, w, h)) diff --git a/cpdfdrawcontrol.mli b/cpdfdrawcontrol.mli index dac3f48..e0036e0 100644 --- a/cpdfdrawcontrol.mli +++ b/cpdfdrawcontrol.mli @@ -19,6 +19,7 @@ val addstag : string -> unit val endtag : unit -> unit val endstag : unit -> unit val autotags : bool -> unit +val addnamespace : string -> unit val artifact : unit -> unit val endartifact : unit -> unit val autoartifacts : bool -> unit