mirror of
https://github.com/johnwhitington/cpdf-source.git
synced 2025-06-05 22:09:39 +02:00
Extend -list-fonts to list fonts within Xobjects
This commit is contained in:
1
Changes
1
Changes
@ -15,6 +15,7 @@ o Show OpenAction in -info
|
|||||||
o Show more form information in -info
|
o Show more form information in -info
|
||||||
o Allow JSON / PDF syntax in dict processing and object exploration
|
o Allow JSON / PDF syntax in dict processing and object exploration
|
||||||
o Show %Bookmark text when stamping text
|
o Show %Bookmark text when stamping text
|
||||||
|
o Font operations now include fonts within xobjects
|
||||||
|
|
||||||
Fixes:
|
Fixes:
|
||||||
|
|
||||||
|
40
cpdffont.ml
40
cpdffont.ml
@ -277,16 +277,52 @@ let list_font pdf page (name, dict) =
|
|||||||
in
|
in
|
||||||
(page, name, subtype, basefont, encoding)
|
(page, name, subtype, basefont, encoding)
|
||||||
|
|
||||||
|
(* List the fonts used in an xobject, and in any of the xobjects it has. Do not
|
||||||
|
process an xobject twice. *)
|
||||||
|
let xobjs_processed = null_hash ()
|
||||||
|
|
||||||
|
let rec list_fonts_xobject pdf pagenum xobjname xobjnum =
|
||||||
|
match Hashtbl.find_opt xobjs_processed xobjnum with
|
||||||
|
| None ->
|
||||||
|
let from_xobjs =
|
||||||
|
match Pdf.lookup_direct pdf "/Resources" (Pdf.lookup_obj pdf xobjnum) with
|
||||||
|
| Some r ->
|
||||||
|
begin match Pdf.lookup_direct pdf "/XObject" r with
|
||||||
|
| Some (Pdf.Dictionary xobjs) ->
|
||||||
|
flatten (option_map (function (n, Pdf.Indirect i) -> Some (list_fonts_xobject pdf pagenum (xobjname ^ n) i) | _ -> None) xobjs)
|
||||||
|
| _ -> []
|
||||||
|
end
|
||||||
|
| _ -> []
|
||||||
|
in
|
||||||
|
begin match Pdf.lookup_direct pdf "/Resources" (Pdf.lookup_obj pdf xobjnum) with
|
||||||
|
| Some r ->
|
||||||
|
begin match Pdf.lookup_direct pdf "/Font" r with
|
||||||
|
| Some (Pdf.Dictionary fonts) -> map (list_font pdf pagenum) (map (function (n, f) -> (xobjname ^ n, f)) fonts) @ from_xobjs
|
||||||
|
| _ -> from_xobjs
|
||||||
|
end
|
||||||
|
| None -> from_xobjs
|
||||||
|
end
|
||||||
|
| Some _ ->
|
||||||
|
Hashtbl.add xobjs_processed xobjnum ();
|
||||||
|
[]
|
||||||
|
|
||||||
let list_fonts pdf range =
|
let list_fonts pdf range =
|
||||||
|
Hashtbl.clear xobjs_processed;
|
||||||
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) ->
|
||||||
if mem num range then
|
if mem num range then
|
||||||
|
let from_xobjs =
|
||||||
|
match Pdf.lookup_direct pdf "/XObject" page.Pdfpage.resources with
|
||||||
|
| Some (Pdf.Dictionary xobjs) ->
|
||||||
|
flatten (option_map (function (n, Pdf.Indirect i) -> Some (list_fonts_xobject pdf num n i) | _ -> None) xobjs)
|
||||||
|
| _ -> []
|
||||||
|
in
|
||||||
begin match Pdf.lookup_direct pdf "/Font" page.Pdfpage.resources with
|
begin match Pdf.lookup_direct pdf "/Font" page.Pdfpage.resources with
|
||||||
| Some (Pdf.Dictionary fontdict) ->
|
| Some (Pdf.Dictionary fontdict) ->
|
||||||
map (list_font pdf num) fontdict
|
map (list_font pdf num) fontdict @ from_xobjs
|
||||||
| _ -> []
|
| _ -> from_xobjs
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
[])
|
[])
|
||||||
|
Reference in New Issue
Block a user