More positions

This commit is contained in:
John Whitington 2023-04-07 15:31:21 +01:00
parent 1fe429bd61
commit 449a3c2e29
6 changed files with 72 additions and 47 deletions

View File

@ -527,7 +527,7 @@ let args =
fontencoding = Pdftext.WinAnsiEncoding; fontencoding = Pdftext.WinAnsiEncoding;
color = Cpdfaddtext.RGB (0., 0., 0.); color = Cpdfaddtext.RGB (0., 0., 0.);
opacity = 1.; opacity = 1.;
position = Cpdfposition.TopLeft 100.; position = Cpdfposition.TopLeft (100., 100.);
underneath = false; underneath = false;
linespacing = 1.; linespacing = 1.;
midline = false; midline = false;
@ -648,7 +648,7 @@ let reset_arguments () =
args.fontencoding <- Pdftext.WinAnsiEncoding; args.fontencoding <- Pdftext.WinAnsiEncoding;
args.color <- Cpdfaddtext.RGB (0., 0., 0.); args.color <- Cpdfaddtext.RGB (0., 0., 0.);
args.opacity <- 1.; args.opacity <- 1.;
args.position <- Cpdfposition.TopLeft 100.; args.position <- Cpdfposition.TopLeft (100., 100.);
args.underneath <- false; args.underneath <- false;
args.linespacing <- 1.; args.linespacing <- 1.;
args.midline <- false; args.midline <- false;
@ -1177,11 +1177,11 @@ let setlistannotationsjson () =
let setstampon f = let setstampon f =
setop (StampOn f) (); setop (StampOn f) ();
(* Due to an earlier bad decision (default position), we have this nasty hack *) (* Due to an earlier bad decision (default position), we have this nasty hack *)
if args.position = Cpdfposition.TopLeft 100. then args.position <- Cpdfposition.BottomLeft 0. if args.position = Cpdfposition.TopLeft (100., 100.) then args.position <- Cpdfposition.BottomLeft (0., 0.)
let setstampunder f = let setstampunder f =
setop (StampUnder f) (); setop (StampUnder f) ();
if args.position = Cpdfposition.TopLeft 100. then args.position <- Cpdfposition.BottomLeft 0. if args.position = Cpdfposition.TopLeft (100., 100.) then args.position <- Cpdfposition.BottomLeft (0., 0.)
let setstampasxobject f = let setstampasxobject f =
setop (StampAsXObject f) () setop (StampAsXObject f) ()
@ -1206,28 +1206,48 @@ let settop n =
args.justification <- Cpdfaddtext.CentreJustify args.justification <- Cpdfaddtext.CentreJustify
let settopleft n = let settopleft n =
args.position <- Cpdfposition.TopLeft (Cpdfcoord.parse_single_number empty n); let coord =
args.justification <- Cpdfaddtext.LeftJustify match Cpdfcoord.parse_coordinate empty n with
| (a, b) -> Cpdfposition.TopLeft (a, b)
| exception _ -> Cpdfposition.TopLeft (Cpdfcoord.parse_single_number empty n, 0.)
in
args.position <- coord;
args.justification <- Cpdfaddtext.LeftJustify
let settopright n = let settopright n =
args.position <- Cpdfposition.TopRight (Cpdfcoord.parse_single_number empty n); let coord =
args.justification <- Cpdfaddtext.RightJustify match Cpdfcoord.parse_coordinate empty n with
| (a, b) -> Cpdfposition.TopRight (a, b)
| exception _ -> Cpdfposition.TopRight (Cpdfcoord.parse_single_number empty n, 0.)
in
args.position <- coord;
args.justification <- Cpdfaddtext.RightJustify
let setleft n = let setleft n =
args.position <- Cpdfposition.Left (Cpdfcoord.parse_single_number empty n); args.position <- Cpdfposition.Left (Cpdfcoord.parse_single_number empty n);
args.justification <- Cpdfaddtext.LeftJustify args.justification <- Cpdfaddtext.LeftJustify
let setbottomleft n = let setbottomleft n =
args.position <- Cpdfposition.BottomLeft (Cpdfcoord.parse_single_number empty n); let coord =
args.justification <- Cpdfaddtext.LeftJustify match Cpdfcoord.parse_coordinate empty n with
| (a, b) -> Cpdfposition.BottomLeft (a, b)
| exception _ -> Cpdfposition.BottomLeft (Cpdfcoord.parse_single_number empty n, 0.)
in
args.position <- coord;
args.justification <- Cpdfaddtext.LeftJustify
let setbottom n = let setbottom n =
args.position <- Cpdfposition.Bottom (Cpdfcoord.parse_single_number empty n); args.position <- Cpdfposition.Bottom (Cpdfcoord.parse_single_number empty n);
args.justification <- Cpdfaddtext.CentreJustify args.justification <- Cpdfaddtext.CentreJustify
let setbottomright n = let setbottomright n =
args.position <- Cpdfposition.BottomRight (Cpdfcoord.parse_single_number empty n); let coord =
args.justification <- Cpdfaddtext.RightJustify match Cpdfcoord.parse_coordinate empty n with
| (a, b) -> Cpdfposition.BottomRight (a, b)
| exception _ -> Cpdfposition.BottomRight (Cpdfcoord.parse_single_number empty n, 0.)
in
args.position <- coord;
args.justification <- Cpdfaddtext.RightJustify
let setright n = let setright n =
args.position <- Cpdfposition.Right (Cpdfcoord.parse_single_number empty n); args.position <- Cpdfposition.Right (Cpdfcoord.parse_single_number empty n);

View File

@ -172,7 +172,7 @@ let make_space fit ~fast spacing pdf =
(Cpdfpage.shift_pdf (Cpdfpage.shift_pdf
~fast ~fast
(many (margin, margin) endpage) (many (margin, margin) endpage)
(Cpdfpage.scale_contents ~fast (Cpdfposition.BottomLeft 0.) ((width -. spacing) /. width) pdf all) (Cpdfpage.scale_contents ~fast (Cpdfposition.BottomLeft (0., 0.)) ((width -. spacing) /. width) pdf all)
all) all)
else else
(Cpdfpage.set_mediabox (Cpdfpage.set_mediabox
@ -187,7 +187,7 @@ let add_border linewidth ~fast pdf =
let firstpage = hd (Pdfpage.pages_of_pagetree pdf) in let firstpage = hd (Pdfpage.pages_of_pagetree pdf) in
let _, _, w, h = Pdf.parse_rectangle pdf firstpage.Pdfpage.mediabox in let _, _, w, h = Pdf.parse_rectangle pdf firstpage.Pdfpage.mediabox in
Cpdfaddtext.addrectangle Cpdfaddtext.addrectangle
fast (w -. linewidth, h -. linewidth) (RGB (0., 0., 0.)) true linewidth 1. (Cpdfposition.BottomLeft (linewidth /. 2.)) fast (w -. linewidth, h -. linewidth) (RGB (0., 0., 0.)) true linewidth 1. (Cpdfposition.BottomLeft (linewidth /. 2., linewidth /. 2.))
false false (ilist 1 (Pdfpage.endpage pdf)) pdf false false (ilist 1 (Pdfpage.endpage pdf)) pdf
let impose ~x ~y ~fit ~columns ~rtl ~btt ~center ~margin ~spacing ~linewidth ~fast pdf = let impose ~x ~y ~fit ~columns ~rtl ~btt ~center ~margin ~spacing ~linewidth ~fast pdf =

View File

@ -9,6 +9,7 @@
%Document discourage GhostScript usage, since it can strip data (-gs-malformed, embed missing fonts) %Document discourage GhostScript usage, since it can strip data (-gs-malformed, embed missing fonts)
%Document [ ] pagespecs %Document [ ] pagespecs
%Document extensions to -info %Document extensions to -info
%Document Topleft2 etc.
\documentclass{book} \documentclass{book}
% Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf, % Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf,
% dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc. % dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc.

View File

@ -216,12 +216,12 @@ let scale_page_contents ?(fast=false) scale position pdf pnum page =
let open Cpdfposition in let open Cpdfposition in
match position with match position with
| Top t -> 0., -.t | Top t -> 0., -.t
| TopLeft t -> t, -.t | TopLeft (a, b) -> a, -.b
| TopRight t -> -.t, -.t | TopRight (a, b) -> -.a, -.b
| Left t -> t, 0. | Left t -> t, 0.
| BottomLeft t -> t, t | BottomLeft (a, b) -> a, b
| Bottom t -> 0., t | Bottom t -> 0., t
| BottomRight t -> -.t, t | BottomRight (a, b) -> -.a, b
| Right t -> -.t, 0. | Right t -> -.t, 0.
| _ -> 0., 0. (* centre it... FIXME: We will add a center position, eventually, for text and this... *) | _ -> 0., 0. (* centre it... FIXME: We will add a center position, eventually, for text and this... *)
in in
@ -516,12 +516,12 @@ let stamp_shift_of_position topline midline sw sh w h p =
| PosLeft (ox, oy) -> ox, oy -. dy | PosLeft (ox, oy) -> ox, oy -. dy
| PosRight (ox, oy) -> ox -. sw, oy -. dy | PosRight (ox, oy) -> ox -. sw, oy -. dy
| Top o -> half w -. half sw, h -. o -. sh -. dy | Top o -> half w -. half sw, h -. o -. sh -. dy
| TopLeft o -> o, h -. sh -. o -. dy | TopLeft (a, b) -> a, h -. sh -. b -. dy
| TopRight o -> w -. sw -. o, h -. sh -. o -. dy | TopRight (a, b) -> w -. sw -. a, h -. sh -. b -. dy
| Left o -> o, half h -. half sh -. dy | Left o -> o, half h -. half sh -. dy
| BottomLeft o -> o, o -. dy | BottomLeft (a, b) -> a, b -. dy
| Bottom o -> half w -. half sw, o -. dy | Bottom o -> half w -. half sw, o -. dy
| BottomRight o -> w -. sw -. o, o -. dy | BottomRight (a, b) -> w -. sw -. a, b -. dy
| Right o -> w -. sw -. o, half h -. half sh -. dy | Right o -> w -. sw -. o, half h -. half sh -. dy
| Diagonal | ReverseDiagonal | Centre -> | Diagonal | ReverseDiagonal | Centre ->
half w -. half sw, half h -. half sh -. dy half w -. half sw, half h -. half sh -. dy
@ -701,7 +701,7 @@ let combine_pages fast under over scaletofit swap equalize =
map2 map2
(fun o u -> (fun o u ->
do_stamp do_stamp
false fast (BottomLeft 0.) false false scaletofit (not swap) merged o u over) false fast (BottomLeft (0., 0.)) false false scaletofit (not swap) merged o u over)
over_pages under_pages over_pages under_pages
in in
(* Build the changes. 123456 -> 123123 *) (* Build the changes. 123456 -> 123123 *)

View File

@ -5,12 +5,12 @@ type position =
| PosLeft of float * float | PosLeft of float * float
| PosRight of float * float | PosRight of float * float
| Top of float | Top of float
| TopLeft of float | TopLeft of float * float
| TopRight of float | TopRight of float * float
| Left of float | Left of float
| BottomLeft of float | BottomLeft of float * float
| Bottom of float | Bottom of float
| BottomRight of float | BottomRight of float * float
| Right of float | Right of float
| Diagonal | Diagonal
| ReverseDiagonal | ReverseDiagonal
@ -21,12 +21,12 @@ let string_of_position = function
| PosLeft (a, b) -> Printf.sprintf "PosLeft %f %f" a b | PosLeft (a, b) -> Printf.sprintf "PosLeft %f %f" a b
| PosRight (a, b) -> Printf.sprintf "PosRight %f %f" a b | PosRight (a, b) -> Printf.sprintf "PosRight %f %f" a b
| Top a -> Printf.sprintf "Top %f" a | Top a -> Printf.sprintf "Top %f" a
| TopLeft a -> Printf.sprintf "TopLeft %f" a | TopLeft (a, b) -> Printf.sprintf "TopLeft %f %f" a b
| TopRight a -> Printf.sprintf "TopRight %f" a | TopRight (a, b) -> Printf.sprintf "TopRight %f %f" a b
| Left a -> Printf.sprintf "Left %f" a | Left a -> Printf.sprintf "Left %f" a
| BottomLeft a -> Printf.sprintf "BottomLeft %f" a | BottomLeft (a, b) -> Printf.sprintf "BottomLeft %f %f" a b
| Bottom a -> Printf.sprintf "Bottom %f" a | Bottom a -> Printf.sprintf "Bottom %f" a
| BottomRight a -> Printf.sprintf "BottomRight %f" a | BottomRight (a, b) -> Printf.sprintf "BottomRight %f %f" a b
| Right a -> Printf.sprintf "Right %f" a | Right a -> Printf.sprintf "Right %f" a
| Diagonal -> "Diagonal" | Diagonal -> "Diagonal"
| ReverseDiagonal -> "Reverse Diagonal" | ReverseDiagonal -> "Reverse Diagonal"
@ -60,24 +60,28 @@ let calculate_position ignore_d w (xmin, ymin, xmax, ymax) pos =
| Top d -> | Top d ->
let d = if ignore_d then 0. else d in let d = if ignore_d then 0. else d in
(xmin +. xmax) /. 2. -. w /. 2., ymax -. d, rot (xmin +. xmax) /. 2. -. w /. 2., ymax -. d, rot
| TopLeft d -> | TopLeft (a, b) ->
let d = if ignore_d then 0. else d in let a = if ignore_d then 0. else a in
xmin +. d, ymax -. d, rot let b = if ignore_d then 0. else b in
| TopRight d -> xmin +. a, ymax -. b, rot
let d = if ignore_d then 0. else d in | TopRight (a, b) ->
xmax -. d -. w, ymax -. d, rot let a = if ignore_d then 0. else a in
let b = if ignore_d then 0. else b in
xmax -. a -. w, ymax -. b, rot
| Left d -> | Left d ->
let d = if ignore_d then 0. else d in let d = if ignore_d then 0. else d in
xmin +. d, (ymax +. ymin) /. 2., rot xmin +. d, (ymax +. ymin) /. 2., rot
| BottomLeft d -> | BottomLeft (a, b) ->
let d = if ignore_d then 0. else d in let a = if ignore_d then 0. else a in
xmin +. d, ymin +. d, rot let b = if ignore_d then 0. else b in
xmin +. a, ymin +. b, rot
| Bottom d -> | Bottom d ->
let d = if ignore_d then 0. else d in let d = if ignore_d then 0. else d in
(xmin +. xmax) /. 2. -. w /. 2., ymin +. d, rot (xmin +. xmax) /. 2. -. w /. 2., ymin +. d, rot
| BottomRight d -> | BottomRight (a, b) ->
let d = if ignore_d then 0. else d in let a = if ignore_d then 0. else a in
xmax -. d -. w, ymin +. d, rot let b = if ignore_d then 0. else b in
xmax -. a -. w, ymin +. b, rot
| Right d -> | Right d ->
let d = if ignore_d then 0. else d in let d = if ignore_d then 0. else d in
xmax -. d -. w, (ymax +. ymin) /. 2., rot xmax -. d -. w, (ymax +. ymin) /. 2., rot

View File

@ -6,12 +6,12 @@ type position =
| PosLeft of float * float | PosLeft of float * float
| PosRight of float * float | PosRight of float * float
| Top of float | Top of float
| TopLeft of float | TopLeft of float * float
| TopRight of float | TopRight of float * float
| Left of float | Left of float
| BottomLeft of float | BottomLeft of float * float
| Bottom of float | Bottom of float
| BottomRight of float | BottomRight of float * float
| Right of float | Right of float
| Diagonal | Diagonal
| ReverseDiagonal | ReverseDiagonal