Scaffolding for JBIG2Globals
This commit is contained in:
parent
cd9512a4de
commit
e928818ccb
|
@ -1787,9 +1787,11 @@ let set_input_image f s =
|
|||
with
|
||||
Sys_error _ -> error "Image file not found"
|
||||
|
||||
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:1)
|
||||
let set_input_jbig2 = set_input_image (Cpdfimage.obj_of_jbig2_data ?global:!jbig2_global)
|
||||
|
||||
let embed_font_inner font =
|
||||
match font with
|
||||
|
@ -1896,6 +1898,12 @@ let setlistimagesjson () =
|
|||
setop ListImages ();
|
||||
args.format_json <- true
|
||||
|
||||
let set_jbig2_global f =
|
||||
jbig2_global := Some (Pdfio.bytes_of_string (contents_of_file f))
|
||||
|
||||
let clear_jbig2_global () =
|
||||
jbig2_global := None
|
||||
|
||||
(* Parse a control file, make an argv, and then make Arg parse it. *)
|
||||
let rec make_control_argv_and_parse filename =
|
||||
control_args := !control_args @ parse_control_file filename
|
||||
|
@ -1919,6 +1927,12 @@ and specs =
|
|||
("-jbig2",
|
||||
Arg.String set_input_jbig2,
|
||||
" Load from a JBIG2 fragment, converting to PDF");
|
||||
("-jbig2-global",
|
||||
Arg.String set_jbig2_global,
|
||||
" Load a JBIG2 global stream");
|
||||
("-jbig2-global-clear",
|
||||
Arg.Unit clear_jbig2_global,
|
||||
" Forget any JBIG2 global stream");
|
||||
("-idir",
|
||||
Arg.String set_input_dir,
|
||||
" Add a directory of files");
|
||||
|
|
|
@ -245,7 +245,7 @@ let addjpeg n =
|
|||
in
|
||||
try
|
||||
let data = Pdfio.bytes_of_string (contents_of_file filename) in
|
||||
addop (Cpdfdraw.ImageXObject (name, Cpdfimage.obj_of_jpeg_data data))
|
||||
addop (Cpdfdraw.ImageXObject (name, fst (Cpdfimage.obj_of_jpeg_data data)))
|
||||
with
|
||||
_ -> error "addjpeg: could not load JPEG"
|
||||
|
||||
|
@ -256,7 +256,7 @@ let addpng n =
|
|||
| _ -> error "addpng: bad file specification"
|
||||
in
|
||||
let data = Pdfio.bytes_of_string (contents_of_file filename) in
|
||||
addop (Cpdfdraw.ImageXObject (name, Cpdfimage.obj_of_png_data data))
|
||||
addop (Cpdfdraw.ImageXObject (name, fst (Cpdfimage.obj_of_png_data data)))
|
||||
|
||||
let addimage s =
|
||||
addop (Cpdfdraw.Image s)
|
||||
|
|
|
@ -388,7 +388,7 @@ let obj_of_jpeg_data data =
|
|||
"/Width", Pdf.Integer w;
|
||||
"/Height", Pdf.Integer h]
|
||||
in
|
||||
Pdf.Stream {contents = (Pdf.Dictionary d, Pdf.Got data)}
|
||||
Pdf.Stream {contents = (Pdf.Dictionary d, Pdf.Got data)}, []
|
||||
|
||||
let obj_of_png_data data =
|
||||
let png = Cpdfpng.read_png (Pdfio.input_of_bytes data) in
|
||||
|
@ -406,7 +406,7 @@ let obj_of_png_data data =
|
|||
"/Width", Pdf.Integer png.width;
|
||||
"/Height", Pdf.Integer png.height]
|
||||
in
|
||||
Pdf.Stream {contents = (Pdf.Dictionary d, Pdf.Got png.idat)}
|
||||
Pdf.Stream {contents = (Pdf.Dictionary d, Pdf.Got png.idat)}, []
|
||||
|
||||
let jbig2_dimensions data =
|
||||
(bget data 11 * 256 * 256 * 256 + bget data 12 * 256 * 256 + bget data 13 * 256 + bget data 14,
|
||||
|
@ -424,12 +424,12 @@ let obj_of_jbig2_data ?global:int data =
|
|||
("/Width", Pdf.Integer w);
|
||||
("/Height", Pdf.Integer h)]
|
||||
in
|
||||
Pdf.Stream {contents = (Pdf.Dictionary d, Pdf.Got data)}
|
||||
Pdf.Stream {contents = (Pdf.Dictionary d, Pdf.Got 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 = fobj data in
|
||||
let obj, extras = fobj data in
|
||||
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
|
||||
let page =
|
||||
|
|
|
@ -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) -> Pdfio.input -> Pdf.t
|
||||
val obj_of_jpeg_data : Pdfio.bytes -> Pdf.pdfobject
|
||||
val obj_of_png_data : Pdfio.bytes -> Pdf.pdfobject
|
||||
val obj_of_jbig2_data : ?global:int -> Pdfio.bytes -> Pdf.pdfobject
|
||||
val image_of_input : (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
|
||||
|
|
Loading…
Reference in New Issue