This commit is contained in:
John Whitington 2021-12-17 16:12:03 +00:00
parent ca267b3de4
commit 265b4c71d0
6 changed files with 70 additions and 67 deletions

View File

@ -1,7 +1,8 @@
# Build the cpdf command line tools and top level
MODS = cpdfyojson cpdfxmlm \
cpdfunicodedata cpdferror cpdfjson cpdfstrftime cpdfcoord cpdfattach \
cpdfpagespec cpdfposition cpdf cpdffont cpdftype cpdftexttopdf cpdftoc cpdfcommand
cpdfpagespec cpdfposition cpdf cpdfpresent cpdffont cpdftype \
cpdftexttopdf cpdftoc cpdfcommand
SOURCES = $(foreach x,$(MODS),$(x).ml $(x).mli) cpdfcommandrun.ml

57
cpdf.ml
View File

@ -489,63 +489,6 @@ let combine_pdf_resources pdf a b =
(Pdf.Dictionary [])
(unknown_keys_a @ unknown_keys_b @ combined_known_entries)
(* \section{Build PDF Presentations} *)
let change_page_effect t d horizontal inward direction effect_duration page =
let checkname = function
| "Split" | "Blinds" | "Box" | "Wipe" | "Dissolve" | "Glitter" -> ()
| _ -> error "Unknown presentation type"
in
let rest = page.Pdfpage.rest in
let transdict =
match t with
| None ->
Pdf.Dictionary []
| Some name ->
checkname name;
Pdf.Dictionary [("/S", Pdf.Name ("/" ^ name))]
in
let transdict = Pdf.add_dict_entry transdict "/D" (Pdf.Real effect_duration) in
let transdict =
match t with
| Some ("Split" | "Blinds") ->
Pdf.add_dict_entry
transdict "/Dm" (Pdf.Name (if horizontal then "/H" else "/V"))
| _ -> transdict
in
let transdict =
match t with
| Some ("Split" | "Box") ->
Pdf.add_dict_entry
transdict "/M" (Pdf.Name (if inward then "/I" else "/O"))
| _ -> transdict
in
let transdict =
match t with
| Some ("Wipe" | "Glitter") ->
Pdf.add_dict_entry transdict "/Di" (Pdf.Integer direction)
| _ -> transdict
in
let rest = Pdf.add_dict_entry rest "/Trans" transdict in
let rest =
match d with
| None -> Pdf.remove_dict_entry rest "/Dur"
| Some delay -> Pdf.add_dict_entry rest "/Dur" (Pdf.Real delay)
in
{page with Pdfpage.rest = rest}
let presentation range t d h i dir effect_dur pdf =
let pages = Pdfpage.pages_of_pagetree pdf in
let pages' =
map2
(fun page num ->
if mem num range
then change_page_effect t d h i dir effect_dur page
else page)
pages
(indx pages)
in
Pdfpage.change_pages true pdf pages'
(* \section{Copy an /ID from one file to another} *)
let copy_id keepversion copyfrom copyto =
match Pdf.lookup_direct copyfrom "/ID" copyfrom.Pdf.trailerdict with

View File

@ -85,14 +85,6 @@ val output_info : encoding -> Pdf.t -> unit
(** Output to standard output information from any XMP metadata stream in a PDF. *)
val output_xmp_info : encoding -> Pdf.t -> unit
(** {2 Presentations} *)
(** [presentation range t d horizontal inward direction effect_duration pdf]
adds a presentation on the pages in [range]. See cpdfmanual.pdf for details.
*)
val presentation : int list -> string option ->
float option -> bool -> bool -> int -> float -> Pdf.t -> Pdf.t
(** {2 Bookmarks} *)
(** [parse_bookmark_file verify pdf input] parses the bookmark file in [input].

View File

@ -3441,7 +3441,7 @@ let go () =
let pdf = get_single_pdf args.op false in
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
let pdf' =
Cpdf.presentation
Cpdfpresent.presentation
range
args.transition args.duration args.horizontal
args.inward args.direction args.effect_duration pdf

59
cpdfpresent.ml Normal file
View File

@ -0,0 +1,59 @@
(* Build PDF Presentations *)
open Pdfutil
let change_page_effect t d horizontal inward direction effect_duration page =
let checkname = function
| "Split" | "Blinds" | "Box" | "Wipe" | "Dissolve" | "Glitter" -> ()
| _ -> Cpdferror.error "Unknown presentation type"
in
let rest = page.Pdfpage.rest in
let transdict =
match t with
| None ->
Pdf.Dictionary []
| Some name ->
checkname name;
Pdf.Dictionary [("/S", Pdf.Name ("/" ^ name))]
in
let transdict = Pdf.add_dict_entry transdict "/D" (Pdf.Real effect_duration) in
let transdict =
match t with
| Some ("Split" | "Blinds") ->
Pdf.add_dict_entry
transdict "/Dm" (Pdf.Name (if horizontal then "/H" else "/V"))
| _ -> transdict
in
let transdict =
match t with
| Some ("Split" | "Box") ->
Pdf.add_dict_entry
transdict "/M" (Pdf.Name (if inward then "/I" else "/O"))
| _ -> transdict
in
let transdict =
match t with
| Some ("Wipe" | "Glitter") ->
Pdf.add_dict_entry transdict "/Di" (Pdf.Integer direction)
| _ -> transdict
in
let rest = Pdf.add_dict_entry rest "/Trans" transdict in
let rest =
match d with
| None -> Pdf.remove_dict_entry rest "/Dur"
| Some delay -> Pdf.add_dict_entry rest "/Dur" (Pdf.Real delay)
in
{page with Pdfpage.rest = rest}
let presentation range t d h i dir effect_dur pdf =
let pages = Pdfpage.pages_of_pagetree pdf in
let pages' =
map2
(fun page num ->
if mem num range
then change_page_effect t d h i dir effect_dur page
else page)
pages
(indx pages)
in
Pdfpage.change_pages true pdf pages'

8
cpdfpresent.mli Normal file
View File

@ -0,0 +1,8 @@
(** {2 Presentations} *)
(** [presentation range t d horizontal inward direction effect_duration pdf]
adds a presentation on the pages in [range]. See cpdfmanual.pdf for details.
*)
val presentation : int list -> string option ->
float option -> bool -> bool -> int -> float -> Pdf.t -> Pdf.t