mirror of
https://github.com/johnwhitington/cpdf-source.git
synced 2025-06-05 22:09:39 +02:00
Allow Int/Float to appear in CPDFJSON and CPDF bookmark JSON
This commit is contained in:
@ -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 =
|
||||
|
@ -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' =
|
||||
|
Reference in New Issue
Block a user