Support memory JPEGs and PNGs for cpdflib
This commit is contained in:
parent
aacc8cf633
commit
718d93713a
|
@ -237,26 +237,38 @@ let setmsheary s =
|
||||||
let usexobj s =
|
let usexobj s =
|
||||||
addop (Cpdfdraw.Use s)
|
addop (Cpdfdraw.Use s)
|
||||||
|
|
||||||
let addjpeg n =
|
let addjpeg ?data n =
|
||||||
let name, filename =
|
match data with
|
||||||
match String.split_on_char '=' n with
|
| Some d ->
|
||||||
| [name; filename] -> name, filename
|
addop
|
||||||
| _ -> error "addjpeg: bad file specification"
|
(Cpdfdraw.ImageXObject
|
||||||
in
|
(n, fst (Cpdfimage.obj_of_jpeg_data (Pdfio.bytes_of_raw d))))
|
||||||
try
|
| None ->
|
||||||
let data = Pdfio.bytes_of_string (contents_of_file filename) in
|
let name, filename =
|
||||||
addop (Cpdfdraw.ImageXObject (name, fst (Cpdfimage.obj_of_jpeg_data data)))
|
match String.split_on_char '=' n with
|
||||||
with
|
| [name; filename] -> name, filename
|
||||||
_ -> error "addjpeg: could not load JPEG"
|
| _ -> error "addjpeg: bad file specification"
|
||||||
|
in
|
||||||
|
try
|
||||||
|
let data = Pdfio.bytes_of_string (contents_of_file filename) in
|
||||||
|
addop (Cpdfdraw.ImageXObject (name, fst (Cpdfimage.obj_of_jpeg_data data)))
|
||||||
|
with
|
||||||
|
_ -> error "addjpeg: could not load JPEG"
|
||||||
|
|
||||||
let addpng n =
|
let addpng ?data n =
|
||||||
let name, filename =
|
match data with
|
||||||
match String.split_on_char '=' n with
|
| Some d ->
|
||||||
| [name; filename] -> name, filename
|
addop
|
||||||
| _ -> error "addpng: bad file specification"
|
(Cpdfdraw.ImageXObject
|
||||||
in
|
(n, fst (Cpdfimage.obj_of_png_data (Pdfio.bytes_of_raw d))))
|
||||||
let data = Pdfio.bytes_of_string (contents_of_file filename) in
|
| None ->
|
||||||
addop (Cpdfdraw.ImageXObject (name, fst (Cpdfimage.obj_of_png_data data)))
|
let name, filename =
|
||||||
|
match String.split_on_char '=' n with
|
||||||
|
| [name; filename] -> name, filename
|
||||||
|
| _ -> error "addpng: bad file specification"
|
||||||
|
in
|
||||||
|
let data = Pdfio.bytes_of_string (contents_of_file filename) in
|
||||||
|
addop (Cpdfdraw.ImageXObject (name, fst (Cpdfimage.obj_of_png_data data)))
|
||||||
|
|
||||||
let addimage s =
|
let addimage s =
|
||||||
addop (Cpdfdraw.Image s)
|
addop (Cpdfdraw.Image s)
|
||||||
|
|
|
@ -48,8 +48,8 @@ val xobjbbox : string -> unit
|
||||||
val startxobj : string -> unit
|
val startxobj : string -> unit
|
||||||
val endxobj : unit -> unit
|
val endxobj : unit -> unit
|
||||||
val usexobj : string -> unit
|
val usexobj : string -> unit
|
||||||
val addjpeg : string -> unit
|
val addjpeg : ?data:Pdfio.rawbytes -> string -> unit
|
||||||
val addpng : string -> unit
|
val addpng : ?data:Pdfio.rawbytes -> string -> unit
|
||||||
val addimage : string -> unit
|
val addimage : string -> unit
|
||||||
val addopacity : float -> unit
|
val addopacity : float -> unit
|
||||||
val addsopacity : float -> unit
|
val addsopacity : float -> unit
|
||||||
|
|
Loading…
Reference in New Issue