DUP page ranges

This commit is contained in:
John Whitington 2021-11-12 11:03:17 -08:00
parent 847b120090
commit 2d794a2a99
3 changed files with 15 additions and 1 deletions

View File

@ -1,5 +1,6 @@
2.5 (Upcoming 2022) 2.5 (Upcoming 2022)
o Append e.g DUP2 to a page range to make 1,2,3 --> 1,1,2,2,3,3 etc.
o The -list-fonts operation now obeys the range o The -list-fonts operation now obeys the range
o New operation -print-font-table gives (charcode, unicode, glyph name) triples o New operation -print-font-table gives (charcode, unicode, glyph name) triples
o Can now search for a font by real name with -font o Can now search for a font by real name with -font

View File

@ -92,7 +92,11 @@ let fixup_negatives endpage = function
let invert_range endpage r = let invert_range endpage r =
option_map (fun p -> if mem p r then None else Some p) (ilist 1 endpage) option_map (fun p -> if mem p r then None else Some p) (ilist 1 endpage)
let duplicate_range n r =
flatten (map (fun x -> many x n) r)
let rec parse_pagespec_inner endpage pdf spec = let rec parse_pagespec_inner endpage pdf spec =
let spec = if spec = "" then "all" else spec in
let spec = space_string spec in let spec = space_string spec in
if endpage < 1 then raise (Pdf.PDFError "This PDF file has no pages and is therefore malformed") else if endpage < 1 then raise (Pdf.PDFError "This PDF file has no pages and is therefore malformed") else
let numbers = let numbers =
@ -100,6 +104,14 @@ let rec parse_pagespec_inner endpage pdf spec =
match explode spec with match explode spec with
| 'N'::'O'::'T'::r -> | 'N'::'O'::'T'::r ->
invert_range endpage (parse_pagespec_inner endpage pdf (implode r)) invert_range endpage (parse_pagespec_inner endpage pdf (implode r))
| x::'D'::'U'::'P'::r ->
duplicate_range (int_of_string (implode [x])) (parse_pagespec_inner endpage pdf (implode r))
| x::y::'D'::'U'::'P'::r ->
duplicate_range (int_of_string (implode [x; y])) (parse_pagespec_inner endpage pdf (implode r))
| x::y::z::'D'::'U'::'P'::r ->
duplicate_range (int_of_string (implode [x; y; z])) (parse_pagespec_inner endpage pdf (implode r))
| x::y::z::a::'D'::'U'::'P'::r ->
duplicate_range (int_of_string (implode [x; y; z; a])) (parse_pagespec_inner endpage pdf (implode r))
| _ -> | _ ->
match rev (explode spec) with match rev (explode spec) with
| ['n'; 'e'; 'v'; 'e'] -> | ['n'; 'e'; 'v'; 'e'] ->

View File

@ -12,7 +12,8 @@
{- The word all is the same as 1-end.} {- The word all is the same as 1-end.}
{- A range must contain no spaces.} {- A range must contain no spaces.}
{- A tilde (~) defines a page number counting from the end of the document rather than the beginning. Page ~1 is the last page, ~2 the penultimate page etc.} {- A tilde (~) defines a page number counting from the end of the document rather than the beginning. Page ~1 is the last page, ~2 the penultimate page etc.}
{- Prepending NOT to a whole page range inverts it.} {- Prepending NOT to a whole page range inverts it, once the whole is parsed. }
{- Appending DUP2 to a whole page range duplicates each page twice (or 3, or 4 etc. times), once the whole is parsed. }
} }
*) *)