mirror of
https://github.com/johnwhitington/cpdf-source.git
synced 2025-05-29 02:14:20 +02:00
Progress on PDF/UA-2 TOC
This commit is contained in:
parent
960b444e6e
commit
f81920c997
62
cpdftoc.ml
62
cpdftoc.ml
@ -171,7 +171,7 @@ let typeset_table_of_contents ~font ~fontsize ~title ~bookmark ~dotleader ~proce
|
|||||||
let optional l = if process_struct_tree then l else [] in
|
let optional l = if process_struct_tree then l else [] in
|
||||||
if process_struct_tree then ensure_minimal_struct_tree pdf;
|
if process_struct_tree then ensure_minimal_struct_tree pdf;
|
||||||
Hashtbl.clear width_table_cache;
|
Hashtbl.clear width_table_cache;
|
||||||
let marks = Pdfmarks.read_bookmarks ~preserve_actions:false pdf in
|
let marks = Pdfmarks.read_bookmarks ~preserve_actions:true pdf in
|
||||||
if marks = [] then (Pdfe.log "No bookmarks, not making table of contents\n"; pdf) else
|
if marks = [] then (Pdfe.log "No bookmarks, not making table of contents\n"; pdf) else
|
||||||
let labels = Pdfpagelabels.read pdf in
|
let labels = Pdfpagelabels.read pdf in
|
||||||
let refnums = Pdf.page_reference_numbers pdf in
|
let refnums = Pdf.page_reference_numbers pdf in
|
||||||
@ -273,22 +273,22 @@ let typeset_table_of_contents ~font ~fontsize ~title ~bookmark ~dotleader ~proce
|
|||||||
Pdfpagelabels.startpage = 1;
|
Pdfpagelabels.startpage = 1;
|
||||||
Pdfpagelabels.startvalue = 1}
|
Pdfpagelabels.startvalue = 1}
|
||||||
in
|
in
|
||||||
if process_struct_tree then
|
(* Get indirect of top-level /Document *)
|
||||||
begin
|
let top_level_document =
|
||||||
(* Get indirect of top-level /Document *)
|
match subformat with Some Cpdfua.PDFUA2 ->
|
||||||
let top_level_document =
|
begin match Pdf.lookup_chain pdf pdf.Pdf.trailerdict ["/Root"; "/StructTreeRoot"] with
|
||||||
match subformat with Some Cpdfua.PDFUA2 ->
|
| Some d ->
|
||||||
begin match Pdf.lookup_chain pdf pdf.Pdf.trailerdict ["/Root"; "/StructTreeRoot"] with
|
begin match Pdf.lookup_immediate "/K" d with
|
||||||
| Some d ->
|
| Some (Pdf.Indirect i) -> i
|
||||||
begin match Pdf.lookup_immediate "/K" d with
|
| Some (Pdf.Array [Pdf.Indirect i]) -> i
|
||||||
| Some (Pdf.Indirect i) -> i
|
|
||||||
| Some (Pdf.Array [Pdf.Indirect i]) -> i
|
|
||||||
| _ -> 0
|
|
||||||
end
|
|
||||||
| _ -> 0
|
| _ -> 0
|
||||||
end
|
end
|
||||||
| _ -> 0
|
| _ -> 0
|
||||||
in
|
end
|
||||||
|
| _ -> 0
|
||||||
|
in
|
||||||
|
if process_struct_tree then
|
||||||
|
begin
|
||||||
let struct_tree_root =
|
let struct_tree_root =
|
||||||
if top_level_document > 0 then top_level_document else
|
if top_level_document > 0 then top_level_document else
|
||||||
match Pdf.lookup_immediate "/StructTreeRoot" (Pdf.lookup_obj pdf pdf.Pdf.root) with
|
match Pdf.lookup_immediate "/StructTreeRoot" (Pdf.lookup_obj pdf pdf.Pdf.root) with
|
||||||
@ -367,22 +367,20 @@ let typeset_table_of_contents ~font ~fontsize ~title ~bookmark ~dotleader ~proce
|
|||||||
assumption is ok because /P entries must have an indirect to point
|
assumption is ok because /P entries must have an indirect to point
|
||||||
to. So if the document contains anything, the /Document structelem
|
to. So if the document contains anything, the /Document structelem
|
||||||
must be indirect. *)
|
must be indirect. *)
|
||||||
(* FIXME Move this code up, and return i so we can put the proper /P parent entries in our structure elements. They should point to /Document now not the /StructTreeRoot. *)
|
|
||||||
begin match Pdf.lookup_chain pdf pdf.Pdf.trailerdict ["/Root"; "/StructTreeRoot"] with
|
begin match Pdf.lookup_chain pdf pdf.Pdf.trailerdict ["/Root"; "/StructTreeRoot"] with
|
||||||
| Some d ->
|
| Some d ->
|
||||||
|
if top_level_document = 0 then () else
|
||||||
if top_level_document = 0 then () else
|
let obj = Pdf.lookup_obj pdf top_level_document in
|
||||||
let obj = Pdf.lookup_obj pdf top_level_document in
|
let obj' =
|
||||||
let obj' =
|
let k' =
|
||||||
let k' =
|
match Pdf.lookup_direct pdf "/K" obj with
|
||||||
match Pdf.lookup_direct pdf "/K" obj with
|
| Some (Pdf.Array a) -> Pdf.Array (prepending_structitems @ a)
|
||||||
| Some (Pdf.Array a) -> Pdf.Array (prepending_structitems @ a)
|
| Some (Pdf.Dictionary d) -> Pdf.Array (prepending_structitems @ [Pdf.Dictionary d])
|
||||||
| Some (Pdf.Dictionary d) -> Pdf.Array (prepending_structitems @ [Pdf.Dictionary d])
|
| _ -> Pdf.Null
|
||||||
| _ -> Pdf.Null
|
|
||||||
in
|
|
||||||
Pdf.add_dict_entry obj "/K" k'
|
|
||||||
in
|
in
|
||||||
Pdf.addobj_given_num pdf (top_level_document, obj')
|
Pdf.add_dict_entry obj "/K" k'
|
||||||
|
in
|
||||||
|
Pdf.addobj_given_num pdf (top_level_document, obj')
|
||||||
| _ -> ()
|
| _ -> ()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -398,12 +396,16 @@ let typeset_table_of_contents ~font ~fontsize ~title ~bookmark ~dotleader ~proce
|
|||||||
let labels' = label::map (fun l -> {l with Pdfpagelabels.startpage = l.Pdfpagelabels.startpage + toc_pages_len}) labels in
|
let labels' = label::map (fun l -> {l with Pdfpagelabels.startpage = l.Pdfpagelabels.startpage + toc_pages_len}) labels in
|
||||||
Pdfpagelabels.write pdf labels';
|
Pdfpagelabels.write pdf labels';
|
||||||
if bookmark then
|
if bookmark then
|
||||||
let marks = Pdfmarks.read_bookmarks ~preserve_actions:false pdf in
|
let marks = Pdfmarks.read_bookmarks ~preserve_actions:true pdf in
|
||||||
let refnums = Pdf.page_reference_numbers pdf in
|
let refnums = Pdf.page_reference_numbers pdf in
|
||||||
let newmark =
|
let newmark =
|
||||||
{Pdfmarks.level = 0;
|
{Pdfmarks.level = 0;
|
||||||
Pdfmarks.text = Pdftext.pdfdocstring_of_utf8 (implode (real_newline (explode title)));
|
Pdfmarks.text = Pdftext.pdfdocstring_of_utf8 (implode (real_newline (explode title)));
|
||||||
Pdfmarks.target = Pdfdest.XYZ (Pdfdest.PageObject (hd refnums), None, None, None);
|
Pdfmarks.target =
|
||||||
|
if subformat = Some Cpdfua.PDFUA2 then
|
||||||
|
Pdfdest.XYZ (Pdfdest.PageObject top_level_document, None, None, None)
|
||||||
|
else
|
||||||
|
Pdfdest.XYZ (Pdfdest.PageObject (hd refnums), None, None, None);
|
||||||
Pdfmarks.isopen = false;
|
Pdfmarks.isopen = false;
|
||||||
Pdfmarks.colour = (0., 0., 0.);
|
Pdfmarks.colour = (0., 0., 0.);
|
||||||
Pdfmarks.flags = 0}
|
Pdfmarks.flags = 0}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user