From fb190868d11c480c7b80f20db7b004c5897ccb71 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Wed, 1 Dec 2021 16:11:33 -0800 Subject: [PATCH] string -> char list in typesetter --- cpdfcommand.ml | 8 ++++---- cpdftype.ml | 18 +++++++++--------- cpdftype.mli | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index c7ca3d0..228abf8 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -2937,7 +2937,7 @@ let rec of_utf8_with_newlines t = (function | '\n' -> 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; Buffer.clear buf | x -> @@ -2945,7 +2945,7 @@ let rec of_utf8_with_newlines t = t; (* Do last one *) let c = Buffer.contents buf in - if c <> "" then items := Text c::!items; + if c <> "" then items := Text (explode c)::!items; rev !items let typeset text = @@ -2977,7 +2977,7 @@ let typeset_table_of_contents ~font pdf = (fun mark -> [Cpdftype.BeginDest mark.Pdfmarks.target; 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.NewLine]) (Pdfmarks.read_bookmarks pdf) @@ -2985,7 +2985,7 @@ let typeset_table_of_contents ~font pdf = let toc_pages = Cpdftype.typeset 50. 50. 50. 50. firstpage_papersize pdf ([Cpdftype.Font big; - Cpdftype.Text args.toc_title; + Cpdftype.Text (explode args.toc_title); Cpdftype.NewLine; Cpdftype.VGlue {glen = args.fontsize *. 2.; gstretch = 0.}; Cpdftype.Font f] @ flatten lines) diff --git a/cpdftype.ml b/cpdftype.ml index 555561d..0999067 100644 --- a/cpdftype.ml +++ b/cpdftype.ml @@ -15,7 +15,7 @@ type glue = (* Main type *) type element = - Text of string (* WinAnsiEncoding *) + Text of char list (* charcodes 0..255 *) | HGlue of glue | VGlue of glue | NewLine @@ -25,7 +25,7 @@ type element = | EndDest let to_string_elt = function - | Text t -> t + | Text t -> implode t | HGlue {glen} -> "HGLUE" ^ string_of_float glen | VGlue _ -> "VGLUE" | NewLine -> "NewLine" @@ -69,11 +69,11 @@ let width_of_string ws s = word would overflow. Return (text, needs_newline, remaining_text) *) (* FIXME efficiency *) let split_text space_left widths t = - let chars = ref (explode t) in + let chars = ref t in let words = ref [] in let space_left = ref space_left in let return needs_newline = - (implode (flatten (rev !words)), needs_newline, implode !chars) + (flatten (rev !words), needs_newline, !chars) in try while !chars <> [] do @@ -107,15 +107,15 @@ let layout lmargin rmargin papersize i = s.width_table <- font_widths f fontsize; o := Font (f, fontsize) :: !o | Text text -> - if text = "" then () else + if text = [] then () else begin let this_line, needs_newline, remaining_text = split_text (xpos_max -. s.xpos) s.width_table text in 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 remaining_text <> "" then layout_element (Text remaining_text) + if remaining_text <> [] then layout_element (Text remaining_text) end | HGlue {glen} as glue -> s.xpos <- s.xpos +. glen; @@ -203,7 +203,7 @@ let typeset lmargin rmargin tmargin bmargin papersize pdf i = ops := Pdfops.Op_Q ::Pdfops.Op_ET - ::Pdfops.Op_Tj cps + ::Pdfops.Op_Tj (implode cps) ::Pdfops.Op_BT ::Pdfops.Op_cm (Pdftransform.mktranslate s.xpos (height -. s.ypos)) ::Pdfops.Op_q @@ -212,7 +212,7 @@ let typeset lmargin rmargin tmargin bmargin papersize pdf i = if s.dest <> None then thisdestrectangles := 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) -> let name, objnum = match List.assoc_opt f !fonts with diff --git a/cpdftype.mli b/cpdftype.mli index 0c5db7f..b35c322 100644 --- a/cpdftype.mli +++ b/cpdftype.mli @@ -3,7 +3,7 @@ type glue = gstretch : float} type element = - Text of string + Text of char list | HGlue of glue | VGlue of glue | NewLine