Pagination of tags with paragraph splitting
This commit is contained in:
parent
9d50e3588f
commit
3d8f233c0d
|
@ -47,12 +47,12 @@ let of_utf8_with_newlines fontpack fontsize t =
|
||||||
(* Post process, adding Tag / EndTag around paragraphs *)
|
(* Post process, adding Tag / EndTag around paragraphs *)
|
||||||
let rec tag_paragraphs = function
|
let rec tag_paragraphs = function
|
||||||
| Cpdftype.NewLine::Cpdftype.NewLine::t ->
|
| Cpdftype.NewLine::Cpdftype.NewLine::t ->
|
||||||
Cpdftype.EndTag::Cpdftype.NewLine::Cpdftype.NewLine::Cpdftype.Tag "P"::tag_paragraphs t
|
Cpdftype.EndTag::Cpdftype.NewLine::Cpdftype.NewLine::Cpdftype.Tag ("P", 0)::tag_paragraphs t
|
||||||
| x::t -> x::tag_paragraphs t
|
| x::t -> x::tag_paragraphs t
|
||||||
| [] -> [Cpdftype.EndTag]
|
| [] -> [Cpdftype.EndTag]
|
||||||
|
|
||||||
let tag_paragraphs l =
|
let tag_paragraphs l =
|
||||||
Cpdftype.Tag "P"::tag_paragraphs l
|
Cpdftype.Tag ("P", 0)::tag_paragraphs l
|
||||||
|
|
||||||
let typeset ~process_struct_tree ?subformat ?title ~papersize ~font ~fontsize text =
|
let typeset ~process_struct_tree ?subformat ?title ~papersize ~font ~fontsize text =
|
||||||
let process_struct_tree =
|
let process_struct_tree =
|
||||||
|
|
21
cpdftype.ml
21
cpdftype.ml
|
@ -18,7 +18,7 @@ type element =
|
||||||
| BeginDest of Pdfdest.t
|
| BeginDest of Pdfdest.t
|
||||||
| EndDest
|
| EndDest
|
||||||
| BeginDocument
|
| BeginDocument
|
||||||
| Tag of string
|
| Tag of string * int
|
||||||
| EndTag
|
| EndTag
|
||||||
|
|
||||||
let to_string_elt = function
|
let to_string_elt = function
|
||||||
|
@ -31,7 +31,7 @@ let to_string_elt = function
|
||||||
| BeginDest _ -> "BeginDest"
|
| BeginDest _ -> "BeginDest"
|
||||||
| EndDest -> "EndDest"
|
| EndDest -> "EndDest"
|
||||||
| BeginDocument -> "BeginDocument"
|
| BeginDocument -> "BeginDocument"
|
||||||
| Tag s -> "Tag " ^ s
|
| Tag (s, i) -> "Tag " ^ s ^ " " ^ string_of_int i
|
||||||
| EndTag -> "EndTag"
|
| EndTag -> "EndTag"
|
||||||
|
|
||||||
let to_string es = fold_left (fun a b -> a ^ "\n" ^ b) "" (map to_string_elt es)
|
let to_string es = fold_left (fun a b -> a ^ "\n" ^ b) "" (map to_string_elt es)
|
||||||
|
@ -183,13 +183,16 @@ let layout lmargin rmargin papersize i =
|
||||||
iter layout_element i;
|
iter layout_element i;
|
||||||
rev !o
|
rev !o
|
||||||
|
|
||||||
(* Paginate, simply line-based. When ypos + lineheight exceeds max_ypos, we insert a page break. *)
|
(* Paginate, simply line-based. When ypos + lineheight exceeds max_ypos, we
|
||||||
|
insert a page break. In addition, we re-write any paragraph tag/endtag to
|
||||||
|
make sure they appear on both pages. *)
|
||||||
let paginate tmargin bmargin papersize i =
|
let paginate tmargin bmargin papersize i =
|
||||||
let height = Pdfunits.points (Pdfpaper.height papersize) (Pdfpaper.unit papersize) in
|
let height = Pdfunits.points (Pdfpaper.height papersize) (Pdfpaper.unit papersize) in
|
||||||
let o = ref [] in
|
let o = ref [] in
|
||||||
let s = initial_state () in
|
let s = initial_state () in
|
||||||
s.ypos <- tmargin;
|
s.ypos <- tmargin;
|
||||||
let max_ypos = height -. bmargin in
|
let max_ypos = height -. bmargin in
|
||||||
|
let tag = ref None in
|
||||||
let rec process = function
|
let rec process = function
|
||||||
| VGlue len as glue ->
|
| VGlue len as glue ->
|
||||||
s.ypos <- s.ypos +. len;
|
s.ypos <- s.ypos +. len;
|
||||||
|
@ -206,10 +209,18 @@ let paginate tmargin bmargin papersize i =
|
||||||
o := Font (id, f, fs)::!o
|
o := Font (id, f, fs)::!o
|
||||||
| NewPage ->
|
| NewPage ->
|
||||||
s.ypos <- tmargin +. s.fontsize;
|
s.ypos <- tmargin +. s.fontsize;
|
||||||
o := NewPage::!o
|
begin match !tag with Some (s, i) -> o := EndTag::!o | None -> () end;
|
||||||
|
o := NewPage::!o;
|
||||||
|
begin match !tag with Some (s, i) -> o := Tag (s, i)::!o | None -> () end
|
||||||
| BeginDocument ->
|
| BeginDocument ->
|
||||||
s.ypos <- tmargin +. s.fontsize;
|
s.ypos <- tmargin +. s.fontsize;
|
||||||
o := BeginDocument::!o
|
o := BeginDocument::!o
|
||||||
|
| Tag (s, i) ->
|
||||||
|
tag := Some (s, i);
|
||||||
|
o := Tag (s, i)::!o
|
||||||
|
| EndTag ->
|
||||||
|
tag := None;
|
||||||
|
o := EndTag::!o
|
||||||
| x -> o := x::!o
|
| x -> o := x::!o
|
||||||
in
|
in
|
||||||
iter process i;
|
iter process i;
|
||||||
|
@ -323,7 +334,7 @@ let typeset ~process_struct_tree lmargin rmargin tmargin bmargin papersize pdf i
|
||||||
thispageannotations := map annot !thisdestrectangles @ !thispageannotations;
|
thispageannotations := map annot !thisdestrectangles @ !thispageannotations;
|
||||||
s.dest <- None;
|
s.dest <- None;
|
||||||
thisdestrectangles := []
|
thisdestrectangles := []
|
||||||
| Tag s -> ops := Pdfops.Op_BDC ("/" ^ s, Pdf.Dictionary [("/MCID", Pdf.Integer (mcid ()))])::!ops
|
| Tag (s, _) -> ops := Pdfops.Op_BDC ("/" ^ s, Pdf.Dictionary [("/MCID", Pdf.Integer (mcid ()))])::!ops
|
||||||
| EndTag -> ops := Pdfops.Op_EMC::!ops
|
| EndTag -> ops := Pdfops.Op_EMC::!ops
|
||||||
in
|
in
|
||||||
iter typeset_element i;
|
iter typeset_element i;
|
||||||
|
|
|
@ -9,7 +9,7 @@ type element =
|
||||||
| BeginDest of Pdfdest.t
|
| BeginDest of Pdfdest.t
|
||||||
| EndDest
|
| EndDest
|
||||||
| BeginDocument
|
| BeginDocument
|
||||||
| Tag of string
|
| Tag of string * int
|
||||||
| EndTag
|
| EndTag
|
||||||
|
|
||||||
type t = element list
|
type t = element list
|
||||||
|
|
Loading…
Reference in New Issue