From d148d8fedf1caafdfa6ed1fd5ce796df337cd608 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Tue, 17 Jan 2023 13:37:54 +0800 Subject: [PATCH] more --- cpdfcommand.ml | 10 +++++----- cpdftweak.ml | 8 ++++---- cpdftweak.mli | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 9d8a41f..6711401 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1705,14 +1705,14 @@ let setprintdictentry s = let setreplacedictentryvalue s = try - let pdfobj = Cpdfjson.object_of_json ~utf8:false (Cpdfyojson.Safe.from_string s) in + let pdfobj = Cpdfjson.object_of_json ~utf8:(args.encoding = Cpdfmetadata.UTF8) (Cpdfyojson.Safe.from_string s) in args.replace_dict_entry_value <- pdfobj with e -> error (Printf.sprintf "Failed to parse replacement value: %s\n" (Printexc.to_string e)) let setdictentrysearch s = try - let pdfobj = Cpdfjson.object_of_json ~utf8:false (Cpdfyojson.Safe.from_string s) in + let pdfobj = Cpdfjson.object_of_json ~utf8:(args.encoding = Cpdfmetadata.UTF8) (Cpdfyojson.Safe.from_string s) in args.dict_entry_search <- Some pdfobj with e -> error (Printf.sprintf "Failed to parse search term: %s\n" (Printexc.to_string e)) @@ -3332,7 +3332,7 @@ let write_json output pdf = | Stdout -> Cpdfjson.to_output (Pdfio.output_of_channel stdout) - ~utf8:false + ~utf8:(args.encoding = Cpdfmetadata.UTF8) ~parse_content:args.jsonparsecontentstreams ~no_stream_data:args.jsonnostreamdata ~decompress_streams:args.jsondecompressstreams @@ -3342,7 +3342,7 @@ let write_json output pdf = let f = open_out filename in Cpdfjson.to_output (Pdfio.output_of_channel f) - ~utf8:false + ~utf8:(args.encoding = Cpdfmetadata.UTF8) ~parse_content:args.jsonparsecontentstreams ~no_stream_data:args.jsonnostreamdata ~decompress_streams:args.jsondecompressstreams @@ -4258,7 +4258,7 @@ let go () = write_pdf false pdf | Some (PrintDictEntry key) -> let pdf = get_single_pdf args.op true in - Cpdftweak.print_dict_entry pdf key + Cpdftweak.print_dict_entry ~utf8:(args.encoding = Cpdfmetadata.UTF8) pdf key | Some ListSpotColours -> let pdf = get_single_pdf args.op false in Cpdfspot.list_spot_colours pdf diff --git a/cpdftweak.ml b/cpdftweak.ml index 445e5e6..8582a04 100644 --- a/cpdftweak.ml +++ b/cpdftweak.ml @@ -264,12 +264,12 @@ let replace_dict_entry pdf key value search = pdf.Pdf.trailerdict <- dict_entry_single_object f pdf pdf.Pdf.trailerdict (* FIXME no need to self map here, since nothing changes *) -let print_dict_entry pdf key = +let print_dict_entry ~utf8 pdf key = let f d = match Pdf.lookup_direct pdf key d with | Some v -> (* We use a double newline as a separator. *) - Printf.printf "%s\n\n" (Cpdfyojson.Safe.to_string (Cpdfjson.json_of_object ~utf8:false ~clean_strings:true pdf (fun _ -> ()) ~no_stream_data:false ~parse_content:false v)); + Printf.printf "%s\n\n" (Cpdfyojson.Safe.to_string (Cpdfjson.json_of_object ~utf8 ~clean_strings:true pdf (fun _ -> ()) ~no_stream_data:false ~parse_content:false v)); d | None -> d in @@ -277,11 +277,11 @@ let print_dict_entry pdf key = pdf.Pdf.trailerdict <- dict_entry_single_object f pdf pdf.Pdf.trailerdict (* For cpdflib. *) -let get_dict_entries pdf key = +let get_dict_entries ~utf8 pdf key = let es = ref [] in let f d = match Pdf.lookup_direct pdf key d with - | Some v -> es := Cpdfjson.json_of_object ~utf8:false ~clean_strings:true pdf (fun _ -> ()) ~no_stream_data:false ~parse_content:false v::!es; d + | Some v -> es := Cpdfjson.json_of_object ~utf8 ~clean_strings:true pdf (fun _ -> ()) ~no_stream_data:false ~parse_content:false v::!es; d | None -> d in Pdf.objselfmap (dict_entry_single_object f pdf) pdf; diff --git a/cpdftweak.mli b/cpdftweak.mli index c89b26e..5178645 100644 --- a/cpdftweak.mli +++ b/cpdftweak.mli @@ -22,10 +22,10 @@ val remove_dict_entry : Pdf.t -> string -> Pdf.pdfobject option -> unit val replace_dict_entry : Pdf.t -> string -> Pdf.pdfobject -> Pdf.pdfobject option -> unit (** Print a dictionary entry. *) -val print_dict_entry : Pdf.t -> string -> unit +val print_dict_entry : utf8:bool -> Pdf.t -> string -> unit (** Get dictionary entries in JSON format *) -val get_dict_entries : Pdf.t -> string -> Pdfio.bytes +val get_dict_entries : utf8:bool -> Pdf.t -> string -> Pdfio.bytes (** Remove clipping. *) val remove_clipping : Pdf.t -> int list -> Pdf.t