Clean up chains

This commit is contained in:
John Whitington 2024-10-23 13:44:31 +01:00
parent 7deffc2607
commit 1be567759f
6 changed files with 15 additions and 10 deletions

View File

@ -3593,6 +3593,11 @@ let print_version () =
flprint
("cpdf " ^ (if agpl then "AGPL " else "") ^ "Version " ^ string_of_int major_version ^ "." ^ string_of_int minor_version ^ "." ^ string_of_int minor_minor_version ^ " " ^ version_date ^ "\n")
let replace_obj pdf objspec obj =
let split_chain str = map (fun x -> "/" ^ x) (tl (String.split_on_char '/' str)) in
let chain = split_chain objspec in
Pdf.replace_chain pdf chain obj
(* Main function *)
let go () =
check_bookmarks_mistake ();
@ -4637,7 +4642,7 @@ let go () =
| Some (ReplaceObj (a, b)) ->
let pdf = get_single_pdf args.op false in
let pdfobj = Cpdfjson.object_of_json (Cpdfyojson.Safe.from_string b) in
Pdf.replace_obj pdf a pdfobj;
replace_obj pdf a pdfobj;
write_pdf false pdf
| Some (Verify standard) ->
begin match standard with

View File

@ -770,7 +770,7 @@ let write_structure_tree pdf st =
("/K", Pdf.Array items)])
in
Pdf.addobj_given_num pdf (struct_tree_root, st);
Pdf.replace_chain pdf ["/Root"] ("/StructTreeRoot", Pdf.Indirect struct_tree_root)
Pdf.replace_chain pdf ["/Root"; "/StructTreeRoot"] (Pdf.Indirect struct_tree_root)
let draw ~struct_tree ~fast ~underneath ~filename ~bates ~batespad range pdf drawops =
(*Printf.printf "%s\n" (string_of_drawops drawops);*)

View File

@ -533,7 +533,7 @@ let image_of_input ?subformat ?title ~process_struct_tree fobj i =
Pdf.addobj_given_num pdf (figure, Pdf.Dictionary [("/K", Pdf.Array [Pdf.Integer 0]); ("/P", Pdf.Indirect document); ("/S", Pdf.Name "/Figure"); ("/Alt", Pdf.String title)]);
Pdf.addobj_given_num pdf (str, Pdf.Dictionary [("/Namespaces", Pdf.Array [Pdf.Indirect namespace]); ("/Type", Pdf.Name "/StructTreeRoot");
("/K", Pdf.Array [Pdf.Indirect document]); ("/ParentTree", Pdf.Indirect parent_tree)]);
Pdf.replace_chain pdf ["/Root"] ("/StructTreeRoot", (Pdf.Indirect str))
Pdf.replace_chain pdf ["/Root"; "/StructTreeRoot"] (Pdf.Indirect str)
end
else if process_struct_tree || subformat = Some Cpdfua.PDFUA1 then
begin
@ -543,7 +543,7 @@ let image_of_input ?subformat ?title ~process_struct_tree fobj i =
Pdf.addobj_given_num pdf (parent_tree, Pdf.Dictionary [("/Nums", Pdf.Array [Pdf.Integer 1; Pdf.Array [Pdf.Indirect figure]])]);
Pdf.addobj_given_num pdf (figure, Pdf.Dictionary [("/K", Pdf.Array [Pdf.Integer 0]); ("/P", Pdf.Indirect str); ("/S", Pdf.Name "/Figure"); ("/Alt", Pdf.String title)]);
Pdf.addobj_given_num pdf (str, Pdf.Dictionary [("/Type", Pdf.Name "/StructTreeRoot"); ("/K", Pdf.Array [Pdf.Indirect figure]); ("/ParentTree", Pdf.Indirect parent_tree)]);
Pdf.replace_chain pdf ["/Root"] ("/StructTreeRoot", (Pdf.Indirect str))
Pdf.replace_chain pdf ["/Root"; "/StructTreeRoot"] (Pdf.Indirect str)
end;
let ops =
(if structinfo then [Pdfops.Op_BDC ("/Figure", Pdf.Dictionary [("/MCID", Pdf.Integer 0)])] else [])

View File

@ -471,7 +471,7 @@ let language pdf =
| _ -> None
let set_language pdf s =
Pdf.replace_chain pdf ["/Root"] ("/Lang", (Pdf.String s))
Pdf.replace_chain pdf ["/Root"; "/Lang"] (Pdf.String s)
let output_xmp_info ?(json=ref [("none", `Null)]) encoding pdf =
let notjson = !json = [("none", `Null)] in

View File

@ -171,6 +171,6 @@ let typeset ~process_struct_tree ?subformat ?title ~papersize ~font ~fontsize te
if subformat = Some Cpdfua.PDFUA2 then Pdf.Indirect document else Pdf.Array topks
in
Pdf.addobj_given_num pdf (str, Pdf.Dictionary (stns @ [("/Type", Pdf.Name "/StructTreeRoot"); ("/K", k); ("/ParentTree", Pdf.Indirect parent_tree)]));
Pdf.replace_chain pdf ["/Root"] ("/StructTreeRoot", (Pdf.Indirect str))
Pdf.replace_chain pdf ["/Root"; "/StructTreeRoot"] (Pdf.Indirect str)
end;
pdf

View File

@ -1610,8 +1610,8 @@ let create_pdfua1 title pagesize pages =
let pdf = Cpdfmetadata.create_metadata pdf in
Cpdfmetadata.set_language pdf "en-US";
let pdf = Cpdfmetadata.set_viewer_preference ("/DisplayDocTitle", Pdf.Boolean true, 0) pdf in
Pdf.replace_obj pdf "/Root/MarkInfo/Marked" (Pdf.Boolean true);
Pdf.replace_obj pdf "/Root/StructTreeRoot/Type" (Pdf.Name "/StructTreeRoot");
Pdf.replace_chain pdf ["/Root"; "/MarkInfo"; "/Marked"] (Pdf.Boolean true);
Pdf.replace_chain pdf ["/Root"; "/StructTreeRoot"; "/Type"] (Pdf.Name "/StructTreeRoot");
let pdf = {pdf with Pdf.major = 1; Pdf.minor = 7} in
mark pdf;
pdf
@ -1622,8 +1622,8 @@ let create_pdfua2 title pagesize pages =
let pdf = Cpdfmetadata.create_metadata pdf in
Cpdfmetadata.set_language pdf "en-US";
let pdf = Cpdfmetadata.set_viewer_preference ("/DisplayDocTitle", Pdf.Boolean true, 0) pdf in
Pdf.replace_obj pdf "/Root/MarkInfo/Marked" (Pdf.Boolean true);
Pdf.replace_obj pdf "/Root/StructTreeRoot/Type" (Pdf.Name "/StructTreeRoot");
Pdf.replace_chain pdf ["/Root"; "/MarkInfo"; "/Marked"] (Pdf.Boolean true);
Pdf.replace_chain pdf ["/Root"; "/StructTreeRoot"; "/Type"] (Pdf.Name "/StructTreeRoot");
let pdf = {pdf with Pdf.major = 2; Pdf.minor = 0} in
mark2 2024 pdf;
pdf