Allow Int/Float to appear in CPDFJSON and CPDF bookmark JSON

This commit is contained in:
John Whitington
2025-06-04 11:43:30 +01:00
parent b51ce326d8
commit de0c2b0863
2 changed files with 13 additions and 5 deletions

View File

@ -65,18 +65,24 @@ let bookmark_of_data pdf i s i' isopen optionaldest =
let target_of_json_target pdf pagenumber target =
target_of_markfile_obj pdf pagenumber (Cpdfjson.object_of_json target)
let rec json_make_all_float = function
| `Assoc l -> `Assoc (map (fun (k, v) -> (k, json_make_all_float v)) l)
| `List l -> `List (map json_make_all_float l)
| `Int i -> `Float (float_of_int i)
| x -> x
let mark_of_json pdf = function
| `Assoc [("bold", `Bool bold);
("colour", `List [`Float r; `Float g; `Float b]);
("italic", `Bool italic);
("level", `Int level);
("level", `Float level);
("open", `Bool openstatus);
("page", `Int pagenumber);
("page", `Float pagenumber);
("target", target);
("text", `String text)] ->
{Pdfmarks.level = level;
{Pdfmarks.level = int_of_float level;
Pdfmarks.text = Pdftext.pdfdocstring_of_utf8 text;
Pdfmarks.target = target_of_json_target pdf pagenumber target;
Pdfmarks.target = target_of_json_target pdf (int_of_float pagenumber) target;
Pdfmarks.isopen = openstatus;
Pdfmarks.colour = (r, g, b);
Pdfmarks.flags = (if italic then 1 else 0) lor ((if bold then 1 else 0) lsl 1)}
@ -87,7 +93,7 @@ let mark_of_json_sort pdf = function
| _ -> error "malformed mark in mark_of_json_sort"
let marks_of_json pdf = function
| `List ms -> map (mark_of_json_sort pdf) ms
| `List ms -> map (mark_of_json_sort pdf) (map json_make_all_float ms)
| _ -> error "top level of JSON boomark file not a list"
let parse_bookmark_file_json verify pdf i =

View File

@ -222,7 +222,9 @@ and object_of_json = function
_ -> Pdfe.log (Printf.sprintf "Could not read UTF8 string %S\n" u); P.String u
end
| `Assoc ["I", `Int i] -> P.Integer i
| `Assoc ["I", `Float f] -> P.Integer (int_of_float f)
| `Assoc ["F", `Float f] -> P.Real f
| `Assoc ["F", `Int i] -> P.Real (float_of_int i)
| `Assoc ["N", `String n] -> P.Name n
| `Assoc ["S", `List [dict; `String data]] ->
let d' =