diff --git a/cpdfannot.ml b/cpdfannot.ml index dc98c22..5626feb 100644 --- a/cpdfannot.ml +++ b/cpdfannot.ml @@ -200,7 +200,7 @@ let get_annotations_json pdf = let json = `List (flatten (map2 (annotations_json_page pdf) pages pagenums)) in Pdfio.bytes_of_string (J.to_string json) -(** Set annotations from JSON. Existing annotations will be removed. *) +(** Set annotations from JSON. Existing annotations? *) let set_annotations_json pdf json = () (* Equalise the page lengths of two PDFs by chopping or extending the first one. diff --git a/cpdfcommand.ml b/cpdfcommand.ml index f781d47..fa0c8a2 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -3369,37 +3369,28 @@ let prerotate range pdf = Cpdfpage.upright ~fast:args.fast range pdf let embed_font () = - let fontpack_of_standardfont sf = - let te = Pdftext.text_extractor_of_font_real sf in - let table = null_hash () in - for x = 0 to 255 do - let u = hd (Pdftext.codepoints_of_text te (string_of_char (char_of_int x))) in - Hashtbl.add table u (0, x) - done; - ([sf], table) - in - match args.font with - | StandardFont f -> - (* FIXME proper error handling for missing file etc. *) - begin match args.embedstd14 with - | Some dirname -> - begin try - let fontfile, fontname = - let filename = hd (List.assoc f fontnames) in - Pdfio.bytes_of_string (contents_of_file (Filename.concat dirname filename)), - Filename.remove_extension filename - in - Cpdfembed.EmbedInfo {fontfile; fontname; encoding = args.fontencoding} - with - e -> error (Printf.sprintf "Can't load font for embedding: %s\n" (Printexc.to_string e)) - end - | None -> - PreMadeFontPack (fontpack_of_standardfont (Pdftext.StandardFont (f, args.fontencoding))) + match args.font with + | StandardFont f -> + (* FIXME proper error handling for missing file etc. *) + begin match args.embedstd14 with + | Some dirname -> + begin try + let fontfile, fontname = + let filename = hd (List.assoc f fontnames) in + Pdfio.bytes_of_string (contents_of_file (Filename.concat dirname filename)), + Filename.remove_extension filename + in + Cpdfembed.EmbedInfo {fontfile; fontname; encoding = args.fontencoding} + with + e -> error (Printf.sprintf "Can't load font for embedding: %s\n" (Printexc.to_string e)) end - | OtherFont f -> - ExistingNamedFont - | FontToEmbed fontfile -> - EmbedInfo {fontfile; fontname = args.fontname; encoding = args.fontencoding} + | None -> + PreMadeFontPack (Cpdfembed.fontpack_of_standardfont (Pdftext.StandardFont (f, args.fontencoding))) + end + | OtherFont f -> + ExistingNamedFont + | FontToEmbed fontfile -> + EmbedInfo {fontfile; fontname = args.fontname; encoding = args.fontencoding} (* Main function *) let go () = diff --git a/cpdfembed.ml b/cpdfembed.ml index 26c845f..7e519bf 100644 --- a/cpdfembed.ml +++ b/cpdfembed.ml @@ -8,6 +8,15 @@ type cpdffont = | EmbedInfo of {fontfile : Pdfio.bytes; fontname : string; encoding : Pdftext.encoding} | ExistingNamedFont +let fontpack_of_standardfont sf = + let te = Pdftext.text_extractor_of_font_real sf in + let table = null_hash () in + for x = 0 to 255 do + let u = hd (Pdftext.codepoints_of_text te (string_of_char (char_of_int x))) in + Hashtbl.add table u (0, x) + done; + ([sf], table) + let get_char (fonts, table) u = match Hashtbl.find table u with | (n, charcode) -> Some (charcode, n, List.nth fonts n) diff --git a/cpdfembed.mli b/cpdfembed.mli index 1375a6b..6cc89c7 100644 --- a/cpdfembed.mli +++ b/cpdfembed.mli @@ -15,6 +15,8 @@ type cpdffont = | EmbedInfo of {fontfile : Pdfio.bytes; fontname : string; encoding : Pdftext.encoding} | ExistingNamedFont +val fontpack_of_standardfont : Pdftext.font -> t + val get_char : t -> int -> (int * int * Pdftext.font) option val embed_truetype : diff --git a/cpdfsqueeze.ml b/cpdfsqueeze.ml index 28f23d2..f70dfa5 100644 --- a/cpdfsqueeze.ml +++ b/cpdfsqueeze.ml @@ -234,16 +234,9 @@ let squeeze ?logto ?(pagedata=true) ?(recompress=true) pdf = end; if recompress then begin - ignore (decompress_pdf pdf); log (Printf.sprintf "Recompressing document\n"); - let n = !Pdfcodec.flate_level in - Pdfcodec.flate_level := 9; - ignore (recompress_pdf pdf); - Pdfcodec.flate_level := n + ignore (recompress_pdf pdf); end - else - (* Re-compress processed pagedata, even if recompress not set *) - if pagedata then ignore (recompress_pdf pdf) with e -> raise