From c9dfa1c95b2143a829e692570d5b75417cb9018e Mon Sep 17 00:00:00 2001 From: John Whitington Date: Fri, 27 Sep 2024 16:43:40 +0100 Subject: [PATCH] Plumbing for subformat, title to images and typesetting --- cpdfcommand.ml | 4 ++-- cpdfimage.ml | 2 +- cpdfimage.mli | 2 +- cpdfmanual.tex | 4 ++-- cpdftexttopdf.ml | 2 +- cpdftexttopdf.mli | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 2e23acd..c1f16a4 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1025,7 +1025,7 @@ let fixdashes s = let set_input_image f s = try let fh = open_in_bin s in - let pdf = Cpdfimage.image_of_input f (Pdfio.input_of_channel fh) in + let pdf = Cpdfimage.image_of_input ~subformat:args.subformat ~title:args.title f (Pdfio.input_of_channel fh) in begin try close_in fh with _ -> () end; args.original_filename <- s; args.create_objstm <- true; @@ -4560,7 +4560,7 @@ let go () = | Some (Typeset filename) -> let text = Pdfio.bytes_of_input_channel (open_in_bin filename) in let cpdffont = embed_font () in - let pdf = Cpdftexttopdf.typeset ~font:cpdffont ~papersize:args.createpdf_pagesize ~fontsize:args.fontsize text in + let pdf = Cpdftexttopdf.typeset ~subformat:args.subformat ~title:args.title ~font:cpdffont ~papersize:args.createpdf_pagesize ~fontsize:args.fontsize text in write_pdf false pdf | Some (TextWidth s) -> let rawwidth = diff --git a/cpdfimage.ml b/cpdfimage.ml index d605d0b..e2429fa 100644 --- a/cpdfimage.ml +++ b/cpdfimage.ml @@ -493,7 +493,7 @@ let obj_of_jbig2_data ?global data = in Pdf.Stream {contents = (Pdf.Dictionary d, Pdf.Got data)}, extra -let image_of_input fobj i = +let image_of_input ?subformat ?title 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 diff --git a/cpdfimage.mli b/cpdfimage.mli index a023310..040bb58 100644 --- a/cpdfimage.mli +++ b/cpdfimage.mli @@ -25,7 +25,7 @@ val process : path_to_jbig2enc:string -> path_to_convert:string -> int list -> Pdf.t -> unit (**/**) -val image_of_input : (unit -> Pdfio.bytes -> Pdf.pdfobject * (int * Pdf.pdfobject) list) -> Pdfio.input -> Pdf.t +val image_of_input : ?subformat:Cpdfua.subformat option -> ?title:string option -> (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 diff --git a/cpdfmanual.tex b/cpdfmanual.tex index 39e0d31..89ca1b9 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -1,5 +1,5 @@ -%Document -subformat for -jpg, -png etc. -%Document -subformat for -typeset +%Document -subformat and -title for -jpg, -png etc. +%Document -subformat and -title for -typeset \documentclass{book} % Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf, % dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc. diff --git a/cpdftexttopdf.ml b/cpdftexttopdf.ml index 0424084..ec9c8cf 100644 --- a/cpdftexttopdf.ml +++ b/cpdftexttopdf.ml @@ -43,7 +43,7 @@ let of_utf8_with_newlines fontpack fontsize t = if c <> [] then process_codepoints c; rev !items -let typeset ~papersize ~font ~fontsize text = +let typeset ?subformat ?title ~papersize ~font ~fontsize text = let pdf = Pdf.empty () in let codepoints = setify (Pdftext.codepoints_of_utf8 (Pdfio.string_of_bytes text)) in let fontpack = diff --git a/cpdftexttopdf.mli b/cpdftexttopdf.mli index 44b1e0d..2902cd4 100644 --- a/cpdftexttopdf.mli +++ b/cpdftexttopdf.mli @@ -1,4 +1,4 @@ (** Text to PDF *) (** Typeset a text file as a PDF. *) -val typeset : papersize:Pdfpaper.t -> font:Cpdfembed.cpdffont -> fontsize:float -> Pdfio.bytes -> Pdf.t +val typeset : ?subformat:Cpdfua.subformat option -> ?title:string option -> papersize:Pdfpaper.t -> font:Cpdfembed.cpdffont -> fontsize:float -> Pdfio.bytes -> Pdf.t