more
This commit is contained in:
parent
794bedb91f
commit
d6a564daae
21
cpdfembed.ml
21
cpdfembed.ml
|
@ -1,6 +1,8 @@
|
||||||
(* Embed a font *)
|
(* Embed a font *)
|
||||||
open Pdfutil
|
open Pdfutil
|
||||||
|
|
||||||
|
type t = Pdftext.font list * (int, int * int) Hashtbl.t
|
||||||
|
|
||||||
let pdfcode_of_unicode_codepoint encoding_table glyphlist_table u =
|
let pdfcode_of_unicode_codepoint encoding_table glyphlist_table u =
|
||||||
try
|
try
|
||||||
Some (Hashtbl.find encoding_table (Hashtbl.find glyphlist_table [u]))
|
Some (Hashtbl.find encoding_table (Hashtbl.find glyphlist_table [u]))
|
||||||
|
@ -69,11 +71,22 @@ let make_single_font ~fontname ~encoding pdf f =
|
||||||
tounicode = f.TT.tounicode};
|
tounicode = f.TT.tounicode};
|
||||||
encoding})
|
encoding})
|
||||||
|
|
||||||
|
let make_fontpack_hashtable fs =
|
||||||
|
let indexes = indx0 fs in
|
||||||
|
let table = null_hash () in
|
||||||
|
iter2
|
||||||
|
(fun i (subset, f) ->
|
||||||
|
let charcode_extractor = Pdftext.charcode_extractor_of_font_real f in
|
||||||
|
iter
|
||||||
|
(fun u -> Hashtbl.add table u (i, unopt (charcode_extractor u)))
|
||||||
|
subset)
|
||||||
|
indexes fs;
|
||||||
|
table
|
||||||
|
|
||||||
let embed_truetype pdf ~fontfile ~fontname ~codepoints ~encoding =
|
let embed_truetype pdf ~fontfile ~fontname ~codepoints ~encoding =
|
||||||
let glyphlist_table = Pdfglyphlist.reverse_glyph_hashes () in
|
let glyphlist_table = Pdfglyphlist.reverse_glyph_hashes () in
|
||||||
let encoding_table = Pdftext.reverse_table_of_encoding encoding in
|
let encoding_table = Pdftext.reverse_table_of_encoding encoding in
|
||||||
let accepted_unicodepoints =
|
let accepted_unicodepoints = calc_accepted_unicodepoints encoding_table glyphlist_table codepoints in
|
||||||
calc_accepted_unicodepoints encoding_table glyphlist_table codepoints
|
|
||||||
in
|
|
||||||
let fs = Cpdftruetype.parse ~subset:accepted_unicodepoints fontfile encoding in
|
let fs = Cpdftruetype.parse ~subset:accepted_unicodepoints fontfile encoding in
|
||||||
map (make_single_font ~fontname ~encoding pdf) fs
|
let subsets_and_their_fonts = map (make_single_font ~fontname ~encoding pdf) fs in
|
||||||
|
(map snd subsets_and_their_fonts, make_fontpack_hashtable subsets_and_their_fonts)
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
(* Embed a TrueType font for the given set of unicode codepoints in the given
|
(* Embed a TrueType font for the given set of unicode codepoints in the given
|
||||||
encoding, adding the fontfiles to the PDF and returning the font objects,
|
encoding, adding the fontfiles to the PDF and returning a list of font objects,
|
||||||
together with the codepoints which appear in each. *)
|
together with a unicode codepoint --> (font number in list, charcode) table *)
|
||||||
|
|
||||||
|
type t = Pdftext.font list * (int, int * int) Hashtbl.t
|
||||||
|
|
||||||
val embed_truetype :
|
val embed_truetype :
|
||||||
Pdf.t -> fontfile:Pdfio.bytes -> fontname:string -> codepoints:int list ->
|
Pdf.t -> fontfile:Pdfio.bytes -> fontname:string -> codepoints:int list ->
|
||||||
encoding:Pdftext.encoding -> (int list * Pdftext.font) list
|
encoding:Pdftext.encoding -> t
|
||||||
|
|
Loading…
Reference in New Issue