Support memory JPEGs and PNGs for cpdflib

This commit is contained in:
John Whitington 2024-03-26 20:02:41 +00:00
parent aacc8cf633
commit 718d93713a
2 changed files with 33 additions and 21 deletions

View File

@ -237,7 +237,13 @@ let setmsheary s =
let usexobj s = let usexobj s =
addop (Cpdfdraw.Use s) addop (Cpdfdraw.Use s)
let addjpeg n = let addjpeg ?data n =
match data with
| Some d ->
addop
(Cpdfdraw.ImageXObject
(n, fst (Cpdfimage.obj_of_jpeg_data (Pdfio.bytes_of_raw d))))
| None ->
let name, filename = let name, filename =
match String.split_on_char '=' n with match String.split_on_char '=' n with
| [name; filename] -> name, filename | [name; filename] -> name, filename
@ -249,7 +255,13 @@ let addjpeg n =
with with
_ -> error "addjpeg: could not load JPEG" _ -> error "addjpeg: could not load JPEG"
let addpng n = let addpng ?data n =
match data with
| Some d ->
addop
(Cpdfdraw.ImageXObject
(n, fst (Cpdfimage.obj_of_png_data (Pdfio.bytes_of_raw d))))
| None ->
let name, filename = let name, filename =
match String.split_on_char '=' n with match String.split_on_char '=' n with
| [name; filename] -> name, filename | [name; filename] -> name, filename

View File

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