Tidy
This commit is contained in:
parent
02e220ec1a
commit
745e009393
10
cpdfua.ml
10
cpdfua.ml
|
@ -357,7 +357,7 @@ let extract_struct_tree pdf =
|
||||||
(* Use JSON data to replace objects in a file. Negative objects are new ones,
|
(* Use JSON data to replace objects in a file. Negative objects are new ones,
|
||||||
we make them positive and renumber them not to clash. Everything else must
|
we make them positive and renumber them not to clash. Everything else must
|
||||||
remain unrenumbered. *)
|
remain unrenumbered. *)
|
||||||
let replace_struct_tree pdf (json : Cpdfyojson.Safe.t) =
|
let replace_struct_tree pdf json =
|
||||||
try
|
try
|
||||||
let rec rewrite_indirects negobjnummap = function
|
let rec rewrite_indirects negobjnummap = function
|
||||||
| Pdf.Indirect i ->
|
| Pdf.Indirect i ->
|
||||||
|
@ -370,15 +370,15 @@ let replace_struct_tree pdf (json : Cpdfyojson.Safe.t) =
|
||||||
| x -> x
|
| x -> x
|
||||||
in
|
in
|
||||||
match json with
|
match json with
|
||||||
| `List (_::xs) ->
|
| `List (`List [`Int 0; _]::xs) ->
|
||||||
let neg, pos = List.partition (function (`List [`Int x; _]) -> x > 0 | _ -> error "structure 1") xs in
|
let pos, neg = List.partition (function (`List [`Int x; _]) -> x > 0 | _ -> error "structure 1") xs in
|
||||||
let pos = map (function `List [`Int x; j] -> (x, Cpdfjson.object_of_json j) | _ -> error "structure 2") pos in
|
let pos = map (function `List [`Int x; j] -> (x, Cpdfjson.object_of_json j) | _ -> error "structure 2") pos in
|
||||||
let neg = map (function `List [`Int x; j] -> (x, Cpdfjson.object_of_json j) | _ -> error "structure 3") neg in
|
let neg = map (function `List [`Int x; j] -> (x, Cpdfjson.object_of_json j) | _ -> error "structure 3") neg in
|
||||||
let nextnum = Pdf.objcard pdf + 1 in
|
let nextnum = Pdf.objcard pdf + 1 in
|
||||||
let negobjnummap = map2 (fun n n' -> (n, n')) (map fst neg) (ilist nextnum (nextnum + length neg - 1)) in
|
let negobjnummap = if length neg = 0 then [] else map2 (fun n n' -> (n, n')) (map fst neg) (ilist nextnum (nextnum + length neg - 1)) in
|
||||||
let pos = map (fun (objnum, obj) -> (objnum, rewrite_indirects negobjnummap obj)) pos in
|
let pos = map (fun (objnum, obj) -> (objnum, rewrite_indirects negobjnummap obj)) pos in
|
||||||
let neg = map (fun (objnum, obj) -> (objnum, rewrite_indirects negobjnummap obj)) neg in
|
let neg = map (fun (objnum, obj) -> (objnum, rewrite_indirects negobjnummap obj)) neg in
|
||||||
iter (Pdf.addobj_given_num pdf) (pos @ neg)
|
iter (Pdf.addobj_given_num pdf) (pos @ neg)
|
||||||
| _ -> error "top level JSON wrong"
|
| _ -> error "Top level JSON wrong. Must be list with 0 first."
|
||||||
with
|
with
|
||||||
e -> error (Printf.sprintf "replace_struct_tree: %s" (Printexc.to_string e))
|
e -> error (Printf.sprintf "replace_struct_tree: %s" (Printexc.to_string e))
|
||||||
|
|
Loading…
Reference in New Issue