Optional absolute rectangles
This commit is contained in:
parent
6495daba8c
commit
b676ab4923
4
Changes
4
Changes
|
@ -19,6 +19,10 @@ New features:
|
|||
o -stretch scales without preserving aspect ratio
|
||||
o -redact removes whole pages
|
||||
|
||||
Extended features:
|
||||
|
||||
o Rectangle may be specified as x y x2 y2 rather than x y w h
|
||||
|
||||
* = Supported by a grant from NLnet
|
||||
|
||||
2.7.1 (July 2024)
|
||||
|
|
17
cpdfcoord.ml
17
cpdfcoord.ml
|
@ -207,20 +207,33 @@ let parse_units_string pdf page s =
|
|||
fs
|
||||
|
||||
let parse_rectangle pdf s =
|
||||
(* If it begins with ? it's absolute *)
|
||||
let s, absolute =
|
||||
match explode s with
|
||||
| '?'::r -> implode r, true
|
||||
| _ -> s, false
|
||||
in
|
||||
try
|
||||
match parse_units_string pdf emptypage s with
|
||||
| [x; y; w; h] -> x, y, w, h
|
||||
| [x; y; w; h] ->
|
||||
if absolute then x, y, w -. x, h -. y else x, y, w, h
|
||||
| _ -> error ("Bad rectangle specification " ^ s)
|
||||
with
|
||||
e -> error ("Bad rectangle specification " ^ s ^ " : " ^ Printexc.to_string e)
|
||||
|
||||
let parse_rectangles pdf s =
|
||||
(* If it begins with ? it's absolute *)
|
||||
let s, absolute =
|
||||
match explode s with
|
||||
| '?'::r -> implode r, true
|
||||
| _ -> s, false
|
||||
in
|
||||
try
|
||||
let pages = Pdfpage.pages_of_pagetree pdf in
|
||||
let groups = List.map (fun page -> parse_units_string pdf page s) pages in
|
||||
List.map
|
||||
(function
|
||||
| [x; y; w; h] -> (x, y, w, h)
|
||||
| [x; y; w; h] -> if absolute then x, y, w -. x, h -. y else x, y, w, h
|
||||
| _ -> error ("Bad rectangle specification " ^ s))
|
||||
groups
|
||||
with
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
%Document -stretch
|
||||
%Document -redact
|
||||
%Document ?x0 y0 x1 y1 rectangle specifications
|
||||
\documentclass{book}
|
||||
% Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf,
|
||||
% dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc.
|
||||
|
|
Loading…
Reference in New Issue