This commit is contained in:
John Whitington 2022-12-21 16:09:04 +00:00
parent dc2380298a
commit f0d503a983
3 changed files with 35 additions and 9 deletions

View File

@ -1759,6 +1759,8 @@ let addop o =
let v = Hashtbl.find drawops !currstash in let v = Hashtbl.find drawops !currstash in
Hashtbl.replace drawops !currstash (o::v) Hashtbl.replace drawops !currstash (o::v)
let readfloats s = map float_of_string (String.split_on_char ' ' s)
let col_of_string s = let col_of_string s =
match parse_color s with match parse_color s with
| Cpdfaddtext.RGB (r, g, b) -> Cpdfdraw.RGB (r, g, b) | Cpdfaddtext.RGB (r, g, b) -> Cpdfdraw.RGB (r, g, b)
@ -1784,6 +1786,27 @@ let addline s =
let x, y = Cpdfcoord.parse_coordinate (Pdf.empty ()) s in let x, y = Cpdfcoord.parse_coordinate (Pdf.empty ()) s in
addop (Cpdfdraw.Line (x, y)) addop (Cpdfdraw.Line (x, y))
let addbezier s =
match readfloats s with
| [a; b; c; d; e; f] -> addop (Cpdfdraw.Bezier (a, b, c, d, e, f))
| _ -> error "-bez requires siz numbers"
| exception _ -> error "malformed -bez"
let addcircle s =
match readfloats s with
| [x; y; r] ->
let _, _, segs = hd (snd (Pdfshapes.circle x y r)) in
(match segs with
| Pdfgraphics.Bezier ((a, b), _, _, _)::_ -> addop (Cpdfdraw.To (a, b))
| _ -> assert false);
iter
(function
| Pdfgraphics.Bezier (_, (c, d), (e, f), (g, h)) -> addop (Cpdfdraw.Bezier (c, d, e, f, g, h))
| Pdfgraphics.Straight _ -> assert false)
segs
| _ -> error "-circle requires three numbers"
| exception _ -> error "malformed -circle"
let stroke () = let stroke () =
addop Cpdfdraw.Stroke addop Cpdfdraw.Stroke
@ -1834,8 +1857,6 @@ let setmiter s =
with with
_ -> error "Miter limit must be a number" _ -> error "Miter limit must be a number"
let readfloats s = map float_of_string (String.split_on_char ' ' s)
let setdash s = let setdash s =
try try
let x, y = let x, y =
@ -2678,7 +2699,9 @@ and specs =
("-draw", Arg.Unit (setop Draw), " Begin drawing"); ("-draw", Arg.Unit (setop Draw), " Begin drawing");
("-rect", Arg.String addrect, " Draw rectangle"); ("-rect", Arg.String addrect, " Draw rectangle");
("-to", Arg.String addto, " Move to"); ("-to", Arg.String addto, " Move to");
("-line", Arg.String addline, " Line to"); ("-line", Arg.String addline, " Add line to");
("-bez", Arg.String addbezier, " Add Bezier curve to path");
("-circle", Arg.String addcircle, " Add circle to path");
("-strokecol", Arg.String setstroke, " Set stroke colour"); ("-strokecol", Arg.String setstroke, " Set stroke colour");
("-fillcol", Arg.String setfill, " Set fill colour"); ("-fillcol", Arg.String setfill, " Set fill colour");
("-stroke", Arg.Unit stroke, " Stroke"); ("-stroke", Arg.Unit stroke, " Stroke");

View File

@ -7,7 +7,8 @@ type drawops_colspec =
| CYMK of float * float * float * float | CYMK of float * float * float * float
type drawops = type drawops =
| Rect of float * float * float * float (* x, y, w, h *) | Rect of 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
@ -34,6 +35,7 @@ let rec ops_of_drawop = function
| Pop -> [Pdfops.Op_Q] | Pop -> [Pdfops.Op_Q]
| Matrix m -> [Pdfops.Op_cm m] | Matrix m -> [Pdfops.Op_cm m]
| Rect (x, y, w, h) -> [Pdfops.Op_re (x, y, w, h)] | Rect (x, y, w, h) -> [Pdfops.Op_re (x, y, w, h)]
| Bezier (a, b, c, d, e, f) -> [Pdfops.Op_c (a, b, c, d, e, f)]
| To (x, y) -> [Pdfops.Op_m (x, y)] | To (x, y) -> [Pdfops.Op_m (x, y)]
| Line (x, y) -> [Pdfops.Op_l (x, y)] | Line (x, y) -> [Pdfops.Op_l (x, y)]
| SetFill x -> | SetFill x ->

View File

@ -5,7 +5,8 @@ type drawops_colspec =
| CYMK of float * float * float * float | CYMK of float * float * float * float
type drawops = type drawops =
| Rect of float * float * float * float (* x, y, w, h *) | Rect of 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