This commit is contained in:
John Whitington 2022-09-13 17:20:37 +01:00
parent 69b76f4746
commit 5503952a9a
2 changed files with 12 additions and 0 deletions

View File

@ -50,6 +50,7 @@ let string_of_encoding = function
| Pdftext.StandardEncoding -> "/StandardEncoding" | Pdftext.StandardEncoding -> "/StandardEncoding"
| _ -> failwith "unknown encoding" | _ -> failwith "unknown encoding"
(* FIXME add "" = full subset *)
let embed_truetype pdf ~fontfile ~fontname ~text ~encoding = let embed_truetype pdf ~fontfile ~fontname ~text ~encoding =
let unicodepoints = Pdftext.codepoints_of_utf8 text in let unicodepoints = Pdftext.codepoints_of_utf8 text in
let glyphlist_table = Pdfglyphlist.reverse_glyph_hashes () in let glyphlist_table = Pdfglyphlist.reverse_glyph_hashes () in
@ -101,3 +102,9 @@ let embed_truetype pdf ~fontfile ~fontname ~text ~encoding =
widths widths
in in
Pdf.addobj pdf font Pdf.addobj pdf font
(* For now, to get a Pdftext.font, we build it with the function above using an empty (i.e. full) subset, put it in an empty PDF and then read it back. This will be fixed later. *)
let font_of_truetype ~fontfile ~fontname ~encoding =
let pdf = Pdf.empty () in
let fontobjnum = embed_truetype pdf ~fontfile ~fontname ~text:"" ~encoding in
Pdftext.read_font pdf (Pdf.lookup_obj pdf fontobjnum)

View File

@ -4,3 +4,8 @@
val embed_truetype : val embed_truetype :
Pdf.t -> fontfile:Pdfio.bytes -> fontname:string -> text:string -> Pdf.t -> fontfile:Pdfio.bytes -> fontname:string -> text:string ->
encoding:Pdftext.encoding -> int encoding:Pdftext.encoding -> int
(* Eventually, we will just have this, and a subsetting function. Then we will
use Pdftext.write_font to write it. *)
val font_of_truetype :
fontfile:Pdfio.bytes -> fontname:string -> encoding:Pdftext.encoding -> Pdftext.font