string -> char list in typesetter

This commit is contained in:
John Whitington 2021-12-01 16:11:33 -08:00
parent d5111ccfcf
commit fb190868d1
3 changed files with 14 additions and 14 deletions

View File

@ -2937,7 +2937,7 @@ let rec of_utf8_with_newlines t =
(function (function
| '\n' -> | '\n' ->
let c = Buffer.contents buf in let c = Buffer.contents buf in
if c <> "" then items := Cpdftype.Text c::!items; if c <> "" then items := Cpdftype.Text (explode c)::!items;
items := Cpdftype.NewLine::!items; items := Cpdftype.NewLine::!items;
Buffer.clear buf Buffer.clear buf
| x -> | x ->
@ -2945,7 +2945,7 @@ let rec of_utf8_with_newlines t =
t; t;
(* Do last one *) (* Do last one *)
let c = Buffer.contents buf in let c = Buffer.contents buf in
if c <> "" then items := Text c::!items; if c <> "" then items := Text (explode c)::!items;
rev !items rev !items
let typeset text = let typeset text =
@ -2977,7 +2977,7 @@ let typeset_table_of_contents ~font pdf =
(fun mark -> (fun mark ->
[Cpdftype.BeginDest mark.Pdfmarks.target; [Cpdftype.BeginDest mark.Pdfmarks.target;
Cpdftype.HGlue {Cpdftype.glen = float mark.Pdfmarks.level *. args.fontsize *. 2.; Cpdftype.gstretch = 0.}; Cpdftype.HGlue {Cpdftype.glen = float mark.Pdfmarks.level *. args.fontsize *. 2.; Cpdftype.gstretch = 0.};
Cpdftype.Text (of_pdfdocencoding f mark.Pdfmarks.text); Cpdftype.Text (explode (of_pdfdocencoding f mark.Pdfmarks.text));
Cpdftype.EndDest; Cpdftype.EndDest;
Cpdftype.NewLine]) Cpdftype.NewLine])
(Pdfmarks.read_bookmarks pdf) (Pdfmarks.read_bookmarks pdf)
@ -2985,7 +2985,7 @@ let typeset_table_of_contents ~font pdf =
let toc_pages = let toc_pages =
Cpdftype.typeset 50. 50. 50. 50. firstpage_papersize pdf Cpdftype.typeset 50. 50. 50. 50. firstpage_papersize pdf
([Cpdftype.Font big; ([Cpdftype.Font big;
Cpdftype.Text args.toc_title; Cpdftype.Text (explode args.toc_title);
Cpdftype.NewLine; Cpdftype.NewLine;
Cpdftype.VGlue {glen = args.fontsize *. 2.; gstretch = 0.}; Cpdftype.VGlue {glen = args.fontsize *. 2.; gstretch = 0.};
Cpdftype.Font f] @ flatten lines) Cpdftype.Font f] @ flatten lines)

View File

@ -15,7 +15,7 @@ type glue =
(* Main type *) (* Main type *)
type element = type element =
Text of string (* WinAnsiEncoding *) Text of char list (* charcodes 0..255 *)
| HGlue of glue | HGlue of glue
| VGlue of glue | VGlue of glue
| NewLine | NewLine
@ -25,7 +25,7 @@ type element =
| EndDest | EndDest
let to_string_elt = function let to_string_elt = function
| Text t -> t | Text t -> implode t
| HGlue {glen} -> "HGLUE" ^ string_of_float glen | HGlue {glen} -> "HGLUE" ^ string_of_float glen
| VGlue _ -> "VGLUE" | VGlue _ -> "VGLUE"
| NewLine -> "NewLine" | NewLine -> "NewLine"
@ -69,11 +69,11 @@ let width_of_string ws s =
word would overflow. Return (text, needs_newline, remaining_text) *) word would overflow. Return (text, needs_newline, remaining_text) *)
(* FIXME efficiency *) (* FIXME efficiency *)
let split_text space_left widths t = let split_text space_left widths t =
let chars = ref (explode t) in let chars = ref t in
let words = ref [] in let words = ref [] in
let space_left = ref space_left in let space_left = ref space_left in
let return needs_newline = let return needs_newline =
(implode (flatten (rev !words)), needs_newline, implode !chars) (flatten (rev !words), needs_newline, !chars)
in in
try try
while !chars <> [] do while !chars <> [] do
@ -107,15 +107,15 @@ let layout lmargin rmargin papersize i =
s.width_table <- font_widths f fontsize; s.width_table <- font_widths f fontsize;
o := Font (f, fontsize) :: !o o := Font (f, fontsize) :: !o
| Text text -> | Text text ->
if text = "" then () else if text = [] then () else
begin begin
let this_line, needs_newline, remaining_text = let this_line, needs_newline, remaining_text =
split_text (xpos_max -. s.xpos) s.width_table text split_text (xpos_max -. s.xpos) s.width_table text
in in
o := Text this_line :: !o; o := Text this_line :: !o;
s.xpos <- s.xpos +. width_of_string s.width_table (explode this_line); s.xpos <- s.xpos +. width_of_string s.width_table this_line;
if needs_newline then layout_element NewLine; if needs_newline then layout_element NewLine;
if remaining_text <> "" then layout_element (Text remaining_text) if remaining_text <> [] then layout_element (Text remaining_text)
end end
| HGlue {glen} as glue -> | HGlue {glen} as glue ->
s.xpos <- s.xpos +. glen; s.xpos <- s.xpos +. glen;
@ -203,7 +203,7 @@ let typeset lmargin rmargin tmargin bmargin papersize pdf i =
ops := ops :=
Pdfops.Op_Q Pdfops.Op_Q
::Pdfops.Op_ET ::Pdfops.Op_ET
::Pdfops.Op_Tj cps ::Pdfops.Op_Tj (implode cps)
::Pdfops.Op_BT ::Pdfops.Op_BT
::Pdfops.Op_cm (Pdftransform.mktranslate s.xpos (height -. s.ypos)) ::Pdfops.Op_cm (Pdftransform.mktranslate s.xpos (height -. s.ypos))
::Pdfops.Op_q ::Pdfops.Op_q
@ -212,7 +212,7 @@ let typeset lmargin rmargin tmargin bmargin papersize pdf i =
if s.dest <> None then if s.dest <> None then
thisdestrectangles := thisdestrectangles :=
let minx, miny = s.xpos, height -. s.ypos in let minx, miny = s.xpos, height -. s.ypos in
(minx, miny, minx +. width_of_string s.width_table (explode cps), miny +. s.fontsize)::!thisdestrectangles (minx, miny, minx +. width_of_string s.width_table cps, miny +. s.fontsize)::!thisdestrectangles
| Font (f, fontsize) -> | Font (f, fontsize) ->
let name, objnum = let name, objnum =
match List.assoc_opt f !fonts with match List.assoc_opt f !fonts with

View File

@ -3,7 +3,7 @@ type glue =
gstretch : float} gstretch : float}
type element = type element =
Text of string Text of char list
| HGlue of glue | HGlue of glue
| VGlue of glue | VGlue of glue
| NewLine | NewLine