Back to drawing

This commit is contained in:
John Whitington 2023-04-27 19:14:58 +01:00
parent c30c49e90e
commit 38ee3525f3
3 changed files with 46 additions and 0 deletions

View File

@ -2044,6 +2044,27 @@ let set_input_png s =
let addimage s = let addimage s =
addop (Cpdfdraw.Image s) addop (Cpdfdraw.Image s)
let addnewpage s =
addop Cpdfdraw.NewPage
let addopacity f =
addop (Cpdfdraw.Opacity f)
let addsopacity f =
addop (Cpdfdraw.SOpacity f)
let addtext s =
addop (Cpdfdraw.Text s)
let addblock s =
addop (Cpdfdraw.Block ())
let addurl s =
addop (Cpdfdraw.URL s)
let addendurl () =
addop Cpdfdraw.EndURL
let setstderrtostdout () = let setstderrtostdout () =
Pdfe.logger := (fun s -> print_string s; flush stdout) Pdfe.logger := (fun s -> print_string s; flush stdout)
@ -2878,6 +2899,16 @@ and specs =
("-draw-jpeg", Arg.String addjpeg, " Load a JPEG from file and name it"); ("-draw-jpeg", Arg.String addjpeg, " Load a JPEG from file and name it");
("-draw-png", Arg.String addpng, " Load a PNG from file and name it"); ("-draw-png", Arg.String addpng, " Load a PNG from file and name it");
("-image", Arg.String addimage, " Draw an image which has already been loaded"); ("-image", Arg.String addimage, " Draw an image which has already been loaded");
("-newpage", Arg.Unit addnewpage, " Move to a fresh page");
("-opacity", Arg.Float addopacity, " Set opacity");
("-sopacity", Arg.Float addsopacity, " Set stroke opacity");
("-text", Arg.String addtext, " Draw text and move position. ");
("-block", Arg.String addblock, " Set up text block");
("-url", Arg.String addurl, " Begin URL");
("-endurl", Arg.Unit addendurl, " End URL");
(* Getting information before or whilst drawing *)
(*("-textwidth", ...., "Get width of line of text");
("-blocklines", ...., "Get number of lines of text block");*)
(* These items are undocumented *) (* These items are undocumented *)
("-debug", Arg.Unit setdebug, ""); ("-debug", Arg.Unit setdebug, "");
("-debug-crypt", Arg.Unit setdebugcrypt, ""); ("-debug-crypt", Arg.Unit setdebugcrypt, "");

View File

@ -36,6 +36,13 @@ type drawops =
| HardXObject of drawops list | HardXObject of drawops list
| Image of string | Image of string
| ImageXObject of string * Pdf.pdfobject | ImageXObject of string * Pdf.pdfobject
| NewPage
| Opacity of float
| SOpacity of float
| Text of string
| Block of unit (* to fix *)
| URL of string
| EndURL
(* Hash table of (human name, (resources name, object)) for image xobjects *) (* Hash table of (human name, (resources name, object)) for image xobjects *)
let images = null_hash () let images = null_hash ()
@ -84,6 +91,7 @@ let rec ops_of_drawop pdf = function
| ImageXObject (s, obj) -> | ImageXObject (s, obj) ->
Hashtbl.add images s (fresh_xobj_name (), Pdf.addobj pdf obj); Hashtbl.add images s (fresh_xobj_name (), Pdf.addobj pdf obj);
[] []
| NewPage -> Pdfe.log ("NewPage remaining in graphic stream"); assert false
and ops_of_drawops pdf drawops = and ops_of_drawops pdf drawops =
flatten (map (ops_of_drawop pdf) drawops) flatten (map (ops_of_drawop pdf) drawops)

View File

@ -34,5 +34,12 @@ type drawops =
| HardXObject of drawops list | HardXObject of drawops list
| Image of string | Image of string
| ImageXObject of string * Pdf.pdfobject | ImageXObject of string * Pdf.pdfobject
| NewPage
| Opacity of float
| SOpacity of float
| Text of string
| Block of unit (* to fix *)
| URL of string
| EndURL
val draw : bool -> int list -> Pdf.t -> drawops list -> Pdf.t val draw : bool -> int list -> Pdf.t -> drawops list -> Pdf.t