This commit is contained in:
John Whitington 2022-10-19 14:47:20 +01:00
parent be610916d4
commit e3421cdcc2
3 changed files with 9 additions and 8 deletions

View File

@ -8,6 +8,11 @@ type cpdffont =
| EmbedInfo of {fontfile : Pdfio.bytes; fontname : string; encoding : Pdftext.encoding}
| ExistingNamedFont of string
let get_char (fonts, table) u =
match Hashtbl.find table u with
| (n, charcode) -> Some (charcode, n, List.nth fonts n)
| exception Not_found -> None
let pdfcode_of_unicode_codepoint encoding_table glyphlist_table u =
try
Some (Hashtbl.find encoding_table (Hashtbl.find glyphlist_table [u]))

View File

@ -9,6 +9,8 @@ type cpdffont =
| EmbedInfo of {fontfile : Pdfio.bytes; fontname : string; encoding : Pdftext.encoding}
| ExistingNamedFont of string
val get_char : t -> int -> (int * int * Pdftext.font) option
val embed_truetype :
Pdf.t -> fontfile:Pdfio.bytes -> fontname:string -> codepoints:int list ->
encoding:Pdftext.encoding -> t

View File

@ -5,12 +5,6 @@ let used_characters t =
let codepoints = Pdftext.codepoints_of_utf8 t in
setify codepoints
(* Just first font, expand later. Move into cpdfembed? *)
let get_char (fonts, table) u =
match Hashtbl.find table u with
| (n, charcode) -> Some charcode
| exception Not_found -> None
let rec of_utf8_with_newlines fontpack t =
let items = ref [] in
let buf = ref [] in
@ -18,8 +12,8 @@ let rec of_utf8_with_newlines fontpack t =
let charcodes_of_codepoints cs =
option_map
(fun u ->
match get_char fontpack u with
| Some c -> Some (char_of_int c)
match Cpdfembed.get_char fontpack u with
| Some (c, _, _) -> Some (char_of_int c)
| None -> Printf.printf "No glyph for unicode U+%04X in this font\n" u; None)
cs
in