Added range to -list-fonts

This commit is contained in:
John Whitington 2021-11-03 16:51:28 +00:00
parent 16aad662f4
commit c6df45109e
3 changed files with 20 additions and 10 deletions

14
cpdf.ml
View File

@ -1094,23 +1094,27 @@ let list_font pdf page (name, dict) =
in
(page, name, subtype, basefont, encoding)
let list_fonts pdf =
let list_fonts pdf range =
let pages = Pdfpage.pages_of_pagetree pdf in
flatten
(map
(fun (num, page) ->
match Pdf.lookup_direct pdf "/Font" page.Pdfpage.resources with
if mem num range then
begin match Pdf.lookup_direct pdf "/Font" page.Pdfpage.resources with
| Some (Pdf.Dictionary fontdict) ->
map (list_font pdf num) fontdict
| _ -> [])
| _ -> []
end
else
[])
(combine (ilist 1 (length pages)) pages))
let string_of_font (p, n, s, b, e) =
Printf.sprintf "%i %s %s %s %s\n" p n s b e
let print_fonts pdf =
let print_fonts pdf range =
flprint
(fold_left ( ^ ) "" (map string_of_font (list_fonts pdf)))
(fold_left ( ^ ) "" (map string_of_font (list_fonts pdf range)))
(* \section{Superimpose text, page numbers etc.} *)

View File

@ -149,10 +149,10 @@ val split_on_bookmarks : Pdf.t -> int -> Pdf.t list
(** {2 Listing fonts} *)
(** Print font list to stdout *)
val print_fonts : Pdf.t -> unit
val print_fonts : Pdf.t -> int list -> unit
(** Return font list. Page number, name, subtype, basefont, encoding. *)
val list_fonts : Pdf.t -> (int * string * string * string * string) list
val list_fonts : Pdf.t -> int list -> (int * string * string * string * string) list
(** {2 Adding text} *)

View File

@ -3532,7 +3532,13 @@ let go () =
| Some Metadata ->
Cpdf.print_metadata (get_single_pdf (Some Metadata) true)
| Some Fonts ->
Cpdf.print_fonts (get_single_pdf (Some Fonts) true)
begin match args.inputs, args.out with
| (_, pagespec, _, _, _, _)::_, _ ->
let pdf = get_single_pdf (Some Fonts) true in
let range = parse_pagespec_allow_empty pdf pagespec in
Cpdf.print_fonts pdf range
| _ -> error "-list-fonts: bad command line"
end
| Some ListBookmarks ->
begin match args.inputs, args.out with
| (_, pagespec, _, _, _, _)::_, _ ->