Added range to -list-fonts
This commit is contained in:
parent
16aad662f4
commit
c6df45109e
18
cpdf.ml
18
cpdf.ml
|
@ -1094,23 +1094,27 @@ let list_font pdf page (name, dict) =
|
||||||
in
|
in
|
||||||
(page, name, subtype, basefont, encoding)
|
(page, name, subtype, basefont, encoding)
|
||||||
|
|
||||||
let list_fonts pdf =
|
let list_fonts pdf range =
|
||||||
let pages = Pdfpage.pages_of_pagetree pdf in
|
let pages = Pdfpage.pages_of_pagetree pdf in
|
||||||
flatten
|
flatten
|
||||||
(map
|
(map
|
||||||
(fun (num, page) ->
|
(fun (num, page) ->
|
||||||
match Pdf.lookup_direct pdf "/Font" page.Pdfpage.resources with
|
if mem num range then
|
||||||
| Some (Pdf.Dictionary fontdict) ->
|
begin match Pdf.lookup_direct pdf "/Font" page.Pdfpage.resources with
|
||||||
map (list_font pdf num) fontdict
|
| Some (Pdf.Dictionary fontdict) ->
|
||||||
| _ -> [])
|
map (list_font pdf num) fontdict
|
||||||
|
| _ -> []
|
||||||
|
end
|
||||||
|
else
|
||||||
|
[])
|
||||||
(combine (ilist 1 (length pages)) pages))
|
(combine (ilist 1 (length pages)) pages))
|
||||||
|
|
||||||
let string_of_font (p, n, s, b, e) =
|
let string_of_font (p, n, s, b, e) =
|
||||||
Printf.sprintf "%i %s %s %s %s\n" 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
|
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.} *)
|
(* \section{Superimpose text, page numbers etc.} *)
|
||||||
|
|
||||||
|
|
4
cpdf.mli
4
cpdf.mli
|
@ -149,10 +149,10 @@ val split_on_bookmarks : Pdf.t -> int -> Pdf.t list
|
||||||
(** {2 Listing fonts} *)
|
(** {2 Listing fonts} *)
|
||||||
|
|
||||||
(** Print font list to stdout *)
|
(** 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. *)
|
(** 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} *)
|
(** {2 Adding text} *)
|
||||||
|
|
||||||
|
|
|
@ -3532,7 +3532,13 @@ let go () =
|
||||||
| Some Metadata ->
|
| Some Metadata ->
|
||||||
Cpdf.print_metadata (get_single_pdf (Some Metadata) true)
|
Cpdf.print_metadata (get_single_pdf (Some Metadata) true)
|
||||||
| Some Fonts ->
|
| 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 ->
|
| Some ListBookmarks ->
|
||||||
begin match args.inputs, args.out with
|
begin match args.inputs, args.out with
|
||||||
| (_, pagespec, _, _, _, _)::_, _ ->
|
| (_, pagespec, _, _, _, _)::_, _ ->
|
||||||
|
|
Loading…
Reference in New Issue