more
This commit is contained in:
parent
512122d405
commit
771eb18538
|
@ -1924,6 +1924,15 @@ let usexobj s =
|
||||||
with
|
with
|
||||||
_ -> error (Printf.sprintf "Could not find stashed graphics %s\n" s)
|
_ -> error (Printf.sprintf "Could not find stashed graphics %s\n" s)
|
||||||
|
|
||||||
|
let addjpeg n =
|
||||||
|
let objnum =
|
||||||
|
0
|
||||||
|
in
|
||||||
|
addop (Cpdfdraw.ImageXObject (n, objnum))
|
||||||
|
|
||||||
|
let addimage s =
|
||||||
|
addop (Cpdfdraw.Image s)
|
||||||
|
|
||||||
(* Parse a control file, make an argv, and then make Arg parse it. *)
|
(* Parse a control file, make an argv, and then make Arg parse it. *)
|
||||||
let rec make_control_argv_and_parse filename =
|
let rec make_control_argv_and_parse filename =
|
||||||
control_args := !control_args @ parse_control_file filename
|
control_args := !control_args @ parse_control_file filename
|
||||||
|
@ -2734,6 +2743,8 @@ and specs =
|
||||||
("-save", Arg.String savexobj, " Begin to save graphics operators");
|
("-save", Arg.String savexobj, " Begin to save graphics operators");
|
||||||
("-endsave", Arg.String endsave, " End saving of graphics operators");
|
("-endsave", Arg.String endsave, " End saving of graphics operators");
|
||||||
("-use", Arg.String usexobj, " Use a saved sequence of graphics operators");
|
("-use", Arg.String usexobj, " Use a saved sequence of graphics operators");
|
||||||
|
("-jpeg", Arg.String addjpeg, " Load a JPEG from file and name it");
|
||||||
|
("-image", Arg.String addimage, " Draw an image which has already been loaded");
|
||||||
(* These items are undocumented *)
|
(* These items are undocumented *)
|
||||||
("-remove-unused-resources", Arg.Unit (setop RemoveUnusedResources), "");
|
("-remove-unused-resources", Arg.Unit (setop RemoveUnusedResources), "");
|
||||||
("-stay-on-error", Arg.Unit setstayonerror, "");
|
("-stay-on-error", Arg.Unit setstayonerror, "");
|
||||||
|
|
24
cpdfdraw.ml
24
cpdfdraw.ml
|
@ -1,19 +1,22 @@
|
||||||
open Pdfutil
|
open Pdfutil
|
||||||
|
|
||||||
type drawops_colspec =
|
type colspec =
|
||||||
NoCol
|
NoCol
|
||||||
| RGB of float * float * float
|
| RGB of float * float * float
|
||||||
| Grey of float
|
| Grey of float
|
||||||
| CYMK of float * float * float * float
|
| CYMK of float * float * float * float
|
||||||
|
|
||||||
|
type image =
|
||||||
|
JPEG
|
||||||
|
|
||||||
type drawops =
|
type drawops =
|
||||||
| Rect of float * float * float * float
|
| Rect of float * float * float * float
|
||||||
| Bezier of float * float * float * float * float * float
|
| Bezier of float * float * float * float * float * float
|
||||||
| To of float * float
|
| To of float * float
|
||||||
| Line of float * float
|
| Line of float * float
|
||||||
| ClosePath
|
| ClosePath
|
||||||
| SetFill of drawops_colspec
|
| SetFill of colspec
|
||||||
| SetStroke of drawops_colspec
|
| SetStroke of colspec
|
||||||
| SetLineThickness of float
|
| SetLineThickness of float
|
||||||
| SetLineCap of int
|
| SetLineCap of int
|
||||||
| SetLineJoin of int
|
| SetLineJoin of int
|
||||||
|
@ -31,6 +34,14 @@ type drawops =
|
||||||
| ClipEvenOdd
|
| ClipEvenOdd
|
||||||
| SoftXObject of drawops list
|
| SoftXObject of drawops list
|
||||||
| HardXObject of drawops list
|
| HardXObject of drawops list
|
||||||
|
| Image of string
|
||||||
|
| ImageXObject of string * int
|
||||||
|
|
||||||
|
(* Hash table of (human name, (resources name, object number)) for image xobjects *)
|
||||||
|
let images = null_hash ()
|
||||||
|
|
||||||
|
(* Fresh XObject names. If we are stamping over another page, manage clashes later. *)
|
||||||
|
let fresh_xobj_name () = "/Img0"
|
||||||
|
|
||||||
let rec ops_of_drawop = function
|
let rec ops_of_drawop = function
|
||||||
| Push -> [Pdfops.Op_q]
|
| Push -> [Pdfops.Op_q]
|
||||||
|
@ -69,11 +80,16 @@ let rec ops_of_drawop = function
|
||||||
| SetDashPattern (x, y) -> [Pdfops.Op_d (x, y)]
|
| SetDashPattern (x, y) -> [Pdfops.Op_d (x, y)]
|
||||||
| SoftXObject l | HardXObject l ->
|
| SoftXObject l | HardXObject l ->
|
||||||
[Pdfops.Op_q] @ ops_of_drawops l @ [Pdfops.Op_Q]
|
[Pdfops.Op_q] @ ops_of_drawops l @ [Pdfops.Op_Q]
|
||||||
|
| Image s -> [Pdfops.Op_Do (try fst (Hashtbl.find images s) with _ -> Cpdferror.error ("Image not found: " ^ s))]
|
||||||
|
| ImageXObject (s, i) ->
|
||||||
|
Hashtbl.add images s (fresh_xobj_name (), i);
|
||||||
|
[]
|
||||||
|
|
||||||
and ops_of_drawops drawops =
|
and ops_of_drawops drawops =
|
||||||
flatten (map ops_of_drawop drawops)
|
flatten (map ops_of_drawop drawops)
|
||||||
|
|
||||||
(* Draw all the accumulated operators *)
|
(* Draw all the accumulated operators. FIXME: Manage name clashes in Xobjects etc,
|
||||||
|
by using something more robust than append_page_content! *)
|
||||||
let draw fast range pdf drawops =
|
let draw fast range pdf drawops =
|
||||||
let s = Pdfops.string_of_ops (ops_of_drawops drawops) in
|
let s = Pdfops.string_of_ops (ops_of_drawops drawops) in
|
||||||
Cpdftweak.append_page_content s false fast range pdf
|
Cpdftweak.append_page_content s false fast range pdf
|
||||||
|
|
11
cpdfdraw.mli
11
cpdfdraw.mli
|
@ -1,17 +1,20 @@
|
||||||
type drawops_colspec =
|
type colspec =
|
||||||
NoCol
|
NoCol
|
||||||
| RGB of float * float * float
|
| RGB of float * float * float
|
||||||
| Grey of float
|
| Grey of float
|
||||||
| CYMK of float * float * float * float
|
| CYMK of float * float * float * float
|
||||||
|
|
||||||
|
type image =
|
||||||
|
JPEG
|
||||||
|
|
||||||
type drawops =
|
type drawops =
|
||||||
| Rect of float * float * float * float
|
| Rect of float * float * float * float
|
||||||
| Bezier of float * float * float * float * float * float
|
| Bezier of float * float * float * float * float * float
|
||||||
| To of float * float
|
| To of float * float
|
||||||
| Line of float * float
|
| Line of float * float
|
||||||
| ClosePath
|
| ClosePath
|
||||||
| SetFill of drawops_colspec
|
| SetFill of colspec
|
||||||
| SetStroke of drawops_colspec
|
| SetStroke of colspec
|
||||||
| SetLineThickness of float
|
| SetLineThickness of float
|
||||||
| SetLineCap of int
|
| SetLineCap of int
|
||||||
| SetLineJoin of int
|
| SetLineJoin of int
|
||||||
|
@ -29,5 +32,7 @@ type drawops =
|
||||||
| ClipEvenOdd
|
| ClipEvenOdd
|
||||||
| SoftXObject of drawops list
|
| SoftXObject of drawops list
|
||||||
| HardXObject of drawops list
|
| HardXObject of drawops list
|
||||||
|
| Image of string
|
||||||
|
| ImageXObject of string * int
|
||||||
|
|
||||||
val draw : bool -> int list -> Pdf.t -> drawops list -> Pdf.t
|
val draw : bool -> int list -> Pdf.t -> drawops list -> Pdf.t
|
||||||
|
|
Loading…
Reference in New Issue