diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 0ef5c9c..da22a2b 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1789,9 +1789,13 @@ let set_input_image f s = let jbig2_global = ref None -let set_input_png = set_input_image Cpdfimage.obj_of_png_data -let set_input_jpeg = set_input_image Cpdfimage.obj_of_jpeg_data -let set_input_jbig2 = set_input_image (Cpdfimage.obj_of_jbig2_data ?global:!jbig2_global) +let set_input_png = set_input_image (fun () -> Cpdfimage.obj_of_png_data) +let set_input_jpeg = set_input_image (fun () -> Cpdfimage.obj_of_jpeg_data) +let set_input_jbig2 = + set_input_image + (fun () -> + Printf.printf "set_input_jbig2, global = %s\n" (match !jbig2_global with None -> "none" | _ -> "some"); + Cpdfimage.obj_of_jbig2_data ?global:!jbig2_global) let embed_font_inner font = match font with @@ -1899,6 +1903,7 @@ let setlistimagesjson () = args.format_json <- true let set_jbig2_global f = + Printf.printf "inside set_jbig2_global\n"; jbig2_global := Some (Pdfio.bytes_of_string (contents_of_file f)) let clear_jbig2_global () = diff --git a/cpdfimage.ml b/cpdfimage.ml index 7b1b743..17affbb 100644 --- a/cpdfimage.ml +++ b/cpdfimage.ml @@ -418,7 +418,7 @@ let obj_of_jbig2_data ?global data = match global with | Some data -> [("/DecodeParms", Pdf.Dictionary [("/JBIG2Globals", Pdf.Indirect 10000)])], - [(10000, Pdf.Stream {contents = (Pdf.Dictionary [("/Length", Pdf.Integer (bytes_size data))], Pdf.Got data)})] (* FIXME flate *) + [(10000, Pdf.Stream {contents = (Pdf.Dictionary [("/Length", Pdf.Integer (bytes_size data))], Pdf.Got data)})] | None -> [], [] in @@ -437,7 +437,7 @@ let obj_of_jbig2_data ?global data = let image_of_input fobj i = let pdf = Pdf.empty () in let data = Pdfio.bytes_of_input i 0 i.Pdfio.in_channel_length in - let obj, extras = fobj data in + let obj, extras = fobj () data in iter (Pdf.addobj_given_num pdf) extras; let w = match Pdf.lookup_direct pdf "/Width" obj with Some x -> Pdf.getnum pdf x | _ -> assert false in let h = match Pdf.lookup_direct pdf "/Height" obj with Some x -> Pdf.getnum pdf x | _ -> assert false in diff --git a/cpdfimage.mli b/cpdfimage.mli index 4c42d42..cc1ac7e 100644 --- a/cpdfimage.mli +++ b/cpdfimage.mli @@ -12,7 +12,7 @@ val image_resolution : Pdf.t -> int list -> float -> (int * string * int * int * val images : Pdf.t -> int list -> Cpdfyojson.Safe.t (**/**) -val image_of_input : (Pdfio.bytes -> Pdf.pdfobject * (int * Pdf.pdfobject) list) -> Pdfio.input -> Pdf.t +val image_of_input : (unit -> Pdfio.bytes -> Pdf.pdfobject * (int * Pdf.pdfobject) list) -> Pdfio.input -> Pdf.t val obj_of_jpeg_data : Pdfio.bytes -> Pdf.pdfobject * (int * Pdf.pdfobject) list val obj_of_png_data : Pdfio.bytes -> Pdf.pdfobject * (int * Pdf.pdfobject) list val obj_of_jbig2_data : ?global:Pdfio.bytes -> Pdfio.bytes -> Pdf.pdfobject * (int * Pdf.pdfobject) list