First working globals creation

This commit is contained in:
John Whitington 2023-12-04 17:15:15 +00:00
parent 1bc4c57fec
commit 92aa81f554
3 changed files with 11 additions and 6 deletions

View File

@ -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 () =

View File

@ -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

View File

@ -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