From e3421cdcc2f136e633a200727de5921f64e8b6f5 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Wed, 19 Oct 2022 14:47:20 +0100 Subject: [PATCH] more --- cpdfembed.ml | 5 +++++ cpdfembed.mli | 2 ++ cpdftexttopdf.ml | 10 ++-------- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cpdfembed.ml b/cpdfembed.ml index d483fed..17cd493 100644 --- a/cpdfembed.ml +++ b/cpdfembed.ml @@ -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])) diff --git a/cpdfembed.mli b/cpdfembed.mli index 5b42742..3b3fdcb 100644 --- a/cpdfembed.mli +++ b/cpdfembed.mli @@ -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 diff --git a/cpdftexttopdf.ml b/cpdftexttopdf.ml index 99014c0..4960d86 100644 --- a/cpdftexttopdf.ml +++ b/cpdftexttopdf.ml @@ -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