diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 989caaf..82e05f1 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -2918,6 +2918,9 @@ let of_utf8 (f, fontsize) t = |> map char_of_int |> implode +let of_pdfdocencoding (f, fontsize) t = + of_utf8 (f, fontsize) (Pdftext.utf8_of_pdfdocstring t) + let typeset text = let pdf = Pdf.empty () in let f = (Pdftext.StandardFont (Pdftext.Courier, Pdftext.WinAnsiEncoding), 12.) in @@ -2945,7 +2948,7 @@ let typeset_table_of_contents pdf = (fun mark -> [Cpdftype.BeginDest mark.Pdfmarks.target; Cpdftype.HGlue {Cpdftype.glen = float mark.Pdfmarks.level *. 20.; Cpdftype.gstretch = 0.}; - Cpdftype.Text (of_utf8 f mark.Pdfmarks.text); + Cpdftype.Text (of_pdfdocencoding f mark.Pdfmarks.text); Cpdftype.EndDest; Cpdftype.NewLine]) (Pdfmarks.read_bookmarks pdf) diff --git a/cpdftype.ml b/cpdftype.ml index 266d926..6f404c2 100644 --- a/cpdftype.ml +++ b/cpdftype.ml @@ -99,8 +99,9 @@ let font_widths f fontsize = let width_of_string ws s = fold_left ( +. ) 0. (map (fun s -> ws.(int_of_char s)) (explode s)) +(* Takes ws, the width table and text, and returns (this_line, needs_newline, remaining_text) *) let split_text space_left ws t = - (t, false, "", 0.) + (t, false, "") let layout lmargin rmargin papersize i = let width = @@ -115,7 +116,7 @@ let layout lmargin rmargin papersize i = s.width_table <- font_widths f fontsize; o := Font (f, fontsize) :: !o | Text text -> - let this_line, needs_newline, remaining_text, space_used = + let this_line, needs_newline, remaining_text = split_text (xpos_max -. s.xpos) s.width_table text in o := Text this_line :: !o;