From 2d794a2a99d9f09edb62c7c6e9c2dbc69d7679b1 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Fri, 12 Nov 2021 11:03:17 -0800 Subject: [PATCH] DUP page ranges --- Changes | 1 + cpdfpagespec.ml | 12 ++++++++++++ cpdfpagespec.mli | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index cdf7457..a07960f 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ 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 New operation -print-font-table gives (charcode, unicode, glyph name) triples o Can now search for a font by real name with -font diff --git a/cpdfpagespec.ml b/cpdfpagespec.ml index e383421..194d59c 100644 --- a/cpdfpagespec.ml +++ b/cpdfpagespec.ml @@ -92,7 +92,11 @@ let fixup_negatives endpage = function let invert_range endpage r = 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 spec = if spec = "" then "all" else 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 let numbers = @@ -100,6 +104,14 @@ let rec parse_pagespec_inner endpage pdf spec = match explode spec with | 'N'::'O'::'T'::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 | ['n'; 'e'; 'v'; 'e'] -> diff --git a/cpdfpagespec.mli b/cpdfpagespec.mli index aa575e6..018a4d0 100644 --- a/cpdfpagespec.mli +++ b/cpdfpagespec.mli @@ -12,7 +12,8 @@ {- The word all is the same as 1-end.} {- 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.} -{- 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. } } *)