More positions
This commit is contained in:
parent
1fe429bd61
commit
449a3c2e29
|
@ -527,7 +527,7 @@ let args =
|
|||
fontencoding = Pdftext.WinAnsiEncoding;
|
||||
color = Cpdfaddtext.RGB (0., 0., 0.);
|
||||
opacity = 1.;
|
||||
position = Cpdfposition.TopLeft 100.;
|
||||
position = Cpdfposition.TopLeft (100., 100.);
|
||||
underneath = false;
|
||||
linespacing = 1.;
|
||||
midline = false;
|
||||
|
@ -648,7 +648,7 @@ let reset_arguments () =
|
|||
args.fontencoding <- Pdftext.WinAnsiEncoding;
|
||||
args.color <- Cpdfaddtext.RGB (0., 0., 0.);
|
||||
args.opacity <- 1.;
|
||||
args.position <- Cpdfposition.TopLeft 100.;
|
||||
args.position <- Cpdfposition.TopLeft (100., 100.);
|
||||
args.underneath <- false;
|
||||
args.linespacing <- 1.;
|
||||
args.midline <- false;
|
||||
|
@ -1177,11 +1177,11 @@ let setlistannotationsjson () =
|
|||
let setstampon f =
|
||||
setop (StampOn f) ();
|
||||
(* 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 =
|
||||
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 =
|
||||
setop (StampAsXObject f) ()
|
||||
|
@ -1206,28 +1206,48 @@ let settop n =
|
|||
args.justification <- Cpdfaddtext.CentreJustify
|
||||
|
||||
let settopleft n =
|
||||
args.position <- Cpdfposition.TopLeft (Cpdfcoord.parse_single_number empty n);
|
||||
args.justification <- Cpdfaddtext.LeftJustify
|
||||
let coord =
|
||||
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 =
|
||||
args.position <- Cpdfposition.TopRight (Cpdfcoord.parse_single_number empty n);
|
||||
args.justification <- Cpdfaddtext.RightJustify
|
||||
let coord =
|
||||
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 =
|
||||
args.position <- Cpdfposition.Left (Cpdfcoord.parse_single_number empty n);
|
||||
args.justification <- Cpdfaddtext.LeftJustify
|
||||
|
||||
let setbottomleft n =
|
||||
args.position <- Cpdfposition.BottomLeft (Cpdfcoord.parse_single_number empty n);
|
||||
args.justification <- Cpdfaddtext.LeftJustify
|
||||
let coord =
|
||||
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 =
|
||||
args.position <- Cpdfposition.Bottom (Cpdfcoord.parse_single_number empty n);
|
||||
args.justification <- Cpdfaddtext.CentreJustify
|
||||
|
||||
let setbottomright n =
|
||||
args.position <- Cpdfposition.BottomRight (Cpdfcoord.parse_single_number empty n);
|
||||
args.justification <- Cpdfaddtext.RightJustify
|
||||
let coord =
|
||||
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 =
|
||||
args.position <- Cpdfposition.Right (Cpdfcoord.parse_single_number empty n);
|
||||
|
|
|
@ -172,7 +172,7 @@ let make_space fit ~fast spacing pdf =
|
|||
(Cpdfpage.shift_pdf
|
||||
~fast
|
||||
(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)
|
||||
else
|
||||
(Cpdfpage.set_mediabox
|
||||
|
@ -187,7 +187,7 @@ let add_border linewidth ~fast pdf =
|
|||
let firstpage = hd (Pdfpage.pages_of_pagetree pdf) in
|
||||
let _, _, w, h = Pdf.parse_rectangle pdf firstpage.Pdfpage.mediabox in
|
||||
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
|
||||
|
||||
let impose ~x ~y ~fit ~columns ~rtl ~btt ~center ~margin ~spacing ~linewidth ~fast pdf =
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
%Document discourage GhostScript usage, since it can strip data (-gs-malformed, embed missing fonts)
|
||||
%Document [ ] pagespecs
|
||||
%Document extensions to -info
|
||||
%Document Topleft2 etc.
|
||||
\documentclass{book}
|
||||
% Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf,
|
||||
% dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc.
|
||||
|
|
18
cpdfpage.ml
18
cpdfpage.ml
|
@ -216,12 +216,12 @@ let scale_page_contents ?(fast=false) scale position pdf pnum page =
|
|||
let open Cpdfposition in
|
||||
match position with
|
||||
| Top t -> 0., -.t
|
||||
| TopLeft t -> t, -.t
|
||||
| TopRight t -> -.t, -.t
|
||||
| TopLeft (a, b) -> a, -.b
|
||||
| TopRight (a, b) -> -.a, -.b
|
||||
| Left t -> t, 0.
|
||||
| BottomLeft t -> t, t
|
||||
| BottomLeft (a, b) -> a, b
|
||||
| Bottom t -> 0., t
|
||||
| BottomRight t -> -.t, t
|
||||
| BottomRight (a, b) -> -.a, b
|
||||
| Right t -> -.t, 0.
|
||||
| _ -> 0., 0. (* centre it... FIXME: We will add a center position, eventually, for text and this... *)
|
||||
in
|
||||
|
@ -516,12 +516,12 @@ let stamp_shift_of_position topline midline sw sh w h p =
|
|||
| PosLeft (ox, oy) -> ox, oy -. dy
|
||||
| PosRight (ox, oy) -> ox -. sw, oy -. dy
|
||||
| Top o -> half w -. half sw, h -. o -. sh -. dy
|
||||
| TopLeft o -> o, h -. sh -. o -. dy
|
||||
| TopRight o -> w -. sw -. o, h -. sh -. o -. dy
|
||||
| TopLeft (a, b) -> a, h -. sh -. b -. dy
|
||||
| TopRight (a, b) -> w -. sw -. a, h -. sh -. b -. 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
|
||||
| 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
|
||||
| Diagonal | ReverseDiagonal | Centre ->
|
||||
half w -. half sw, half h -. half sh -. dy
|
||||
|
@ -701,7 +701,7 @@ let combine_pages fast under over scaletofit swap equalize =
|
|||
map2
|
||||
(fun o u ->
|
||||
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
|
||||
in
|
||||
(* Build the changes. 123456 -> 123123 *)
|
||||
|
|
|
@ -5,12 +5,12 @@ type position =
|
|||
| PosLeft of float * float
|
||||
| PosRight of float * float
|
||||
| Top of float
|
||||
| TopLeft of float
|
||||
| TopRight of float
|
||||
| TopLeft of float * float
|
||||
| TopRight of float * float
|
||||
| Left of float
|
||||
| BottomLeft of float
|
||||
| BottomLeft of float * float
|
||||
| Bottom of float
|
||||
| BottomRight of float
|
||||
| BottomRight of float * float
|
||||
| Right of float
|
||||
| Diagonal
|
||||
| ReverseDiagonal
|
||||
|
@ -21,12 +21,12 @@ let string_of_position = function
|
|||
| PosLeft (a, b) -> Printf.sprintf "PosLeft %f %f" a b
|
||||
| PosRight (a, b) -> Printf.sprintf "PosRight %f %f" a b
|
||||
| Top a -> Printf.sprintf "Top %f" a
|
||||
| TopLeft a -> Printf.sprintf "TopLeft %f" a
|
||||
| TopRight a -> Printf.sprintf "TopRight %f" a
|
||||
| TopLeft (a, b) -> Printf.sprintf "TopLeft %f %f" a b
|
||||
| TopRight (a, b) -> Printf.sprintf "TopRight %f %f" a b
|
||||
| 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
|
||||
| BottomRight a -> Printf.sprintf "BottomRight %f" a
|
||||
| BottomRight (a, b) -> Printf.sprintf "BottomRight %f %f" a b
|
||||
| Right a -> Printf.sprintf "Right %f" a
|
||||
| Diagonal -> "Diagonal"
|
||||
| ReverseDiagonal -> "Reverse Diagonal"
|
||||
|
@ -60,24 +60,28 @@ let calculate_position ignore_d w (xmin, ymin, xmax, ymax) pos =
|
|||
| Top d ->
|
||||
let d = if ignore_d then 0. else d in
|
||||
(xmin +. xmax) /. 2. -. w /. 2., ymax -. d, rot
|
||||
| TopLeft d ->
|
||||
let d = if ignore_d then 0. else d in
|
||||
xmin +. d, ymax -. d, rot
|
||||
| TopRight d ->
|
||||
let d = if ignore_d then 0. else d in
|
||||
xmax -. d -. w, ymax -. d, rot
|
||||
| TopLeft (a, b) ->
|
||||
let a = if ignore_d then 0. else a in
|
||||
let b = if ignore_d then 0. else b in
|
||||
xmin +. a, ymax -. b, rot
|
||||
| TopRight (a, b) ->
|
||||
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 ->
|
||||
let d = if ignore_d then 0. else d in
|
||||
xmin +. d, (ymax +. ymin) /. 2., rot
|
||||
| BottomLeft d ->
|
||||
let d = if ignore_d then 0. else d in
|
||||
xmin +. d, ymin +. d, rot
|
||||
| BottomLeft (a, b) ->
|
||||
let a = if ignore_d then 0. else a in
|
||||
let b = if ignore_d then 0. else b in
|
||||
xmin +. a, ymin +. b, rot
|
||||
| Bottom d ->
|
||||
let d = if ignore_d then 0. else d in
|
||||
(xmin +. xmax) /. 2. -. w /. 2., ymin +. d, rot
|
||||
| BottomRight d ->
|
||||
let d = if ignore_d then 0. else d in
|
||||
xmax -. d -. w, ymin +. d, rot
|
||||
| BottomRight (a, b) ->
|
||||
let a = if ignore_d then 0. else a in
|
||||
let b = if ignore_d then 0. else b in
|
||||
xmax -. a -. w, ymin +. b, rot
|
||||
| Right d ->
|
||||
let d = if ignore_d then 0. else d in
|
||||
xmax -. d -. w, (ymax +. ymin) /. 2., rot
|
||||
|
|
|
@ -6,12 +6,12 @@ type position =
|
|||
| PosLeft of float * float
|
||||
| PosRight of float * float
|
||||
| Top of float
|
||||
| TopLeft of float
|
||||
| TopRight of float
|
||||
| TopLeft of float * float
|
||||
| TopRight of float * float
|
||||
| Left of float
|
||||
| BottomLeft of float
|
||||
| BottomLeft of float * float
|
||||
| Bottom of float
|
||||
| BottomRight of float
|
||||
| BottomRight of float * float
|
||||
| Right of float
|
||||
| Diagonal
|
||||
| ReverseDiagonal
|
||||
|
|
Loading…
Reference in New Issue