more
This commit is contained in:
parent
337139a75f
commit
e1d01c3914
23
cpdfembed.ml
23
cpdfembed.ml
|
@ -24,13 +24,7 @@ let basename () =
|
||||||
incr fontnum;
|
incr fontnum;
|
||||||
"AAAAA" ^ string_of_char (char_of_int (!fontnum + 65))
|
"AAAAA" ^ string_of_char (char_of_int (!fontnum + 65))
|
||||||
|
|
||||||
let embed_truetype pdf ~fontfile ~fontname ~codepoints ~encoding =
|
let make_single_font ~fontname ~encoding pdf f =
|
||||||
let glyphlist_table = Pdfglyphlist.reverse_glyph_hashes () in
|
|
||||||
let encoding_table = Pdftext.reverse_table_of_encoding encoding in
|
|
||||||
let accepted_unicodepoints =
|
|
||||||
calc_accepted_unicodepoints encoding_table glyphlist_table codepoints
|
|
||||||
in
|
|
||||||
let f = hd (Cpdftruetype.parse ~subset:accepted_unicodepoints fontfile encoding) in
|
|
||||||
let name_1 = basename () in
|
let name_1 = basename () in
|
||||||
let module TT = Cpdftruetype in
|
let module TT = Cpdftruetype in
|
||||||
let fontfile =
|
let fontfile =
|
||||||
|
@ -50,7 +44,7 @@ let embed_truetype pdf ~fontfile ~fontname ~codepoints ~encoding =
|
||||||
done;
|
done;
|
||||||
a
|
a
|
||||||
in
|
in
|
||||||
[(codepoints,
|
(f.TT.subset,
|
||||||
SimpleFont
|
SimpleFont
|
||||||
{fonttype = Truetype;
|
{fonttype = Truetype;
|
||||||
basefont = Printf.sprintf "/%s+%s" name_1 fontname;
|
basefont = Printf.sprintf "/%s+%s" name_1 fontname;
|
||||||
|
@ -72,5 +66,14 @@ let embed_truetype pdf ~fontfile ~fontname ~codepoints ~encoding =
|
||||||
float_of_int f.TT.maxx, float_of_int f.TT.maxy);
|
float_of_int f.TT.maxx, float_of_int f.TT.maxy);
|
||||||
fontfile = Some (FontFile2 fontfile_num);
|
fontfile = Some (FontFile2 fontfile_num);
|
||||||
charset = None;
|
charset = None;
|
||||||
tounicode = None};
|
tounicode = f.TT.tounicode};
|
||||||
encoding})]
|
encoding})
|
||||||
|
|
||||||
|
let embed_truetype pdf ~fontfile ~fontname ~codepoints ~encoding =
|
||||||
|
let glyphlist_table = Pdfglyphlist.reverse_glyph_hashes () in
|
||||||
|
let encoding_table = Pdftext.reverse_table_of_encoding encoding in
|
||||||
|
let accepted_unicodepoints =
|
||||||
|
calc_accepted_unicodepoints encoding_table glyphlist_table codepoints
|
||||||
|
in
|
||||||
|
let fs = Cpdftruetype.parse ~subset:accepted_unicodepoints fontfile encoding in
|
||||||
|
map (make_single_font ~fontname ~encoding pdf) fs
|
||||||
|
|
|
@ -21,44 +21,10 @@ type t =
|
||||||
widths : int array;
|
widths : int array;
|
||||||
subset_fontfile : Pdfio.bytes;
|
subset_fontfile : Pdfio.bytes;
|
||||||
subset : int list;
|
subset : int list;
|
||||||
tounicode : Pdfio.bytes option}
|
tounicode : (int, string) Hashtbl.t option}
|
||||||
|
|
||||||
let dbg = ref false
|
let dbg = ref false
|
||||||
|
|
||||||
let tounicode_preamble =
|
|
||||||
"/CIDInit /ProcSet findresource begin\n\
|
|
||||||
12 dict begin\n\
|
|
||||||
begincmap\n\
|
|
||||||
/CIDSystemInfo <<\n\
|
|
||||||
/Registry (Adobe)\n\
|
|
||||||
/Ordering (UCS)\n\
|
|
||||||
/Supplement 0\n\
|
|
||||||
>> def\n\
|
|
||||||
/CMapName /Adobe-Identity-UCS def\n\
|
|
||||||
/CMapType 2 def\n\
|
|
||||||
1 begincodespacerange\n\
|
|
||||||
<00><FF>\n\
|
|
||||||
endcodespacerange\n"
|
|
||||||
|
|
||||||
let tounicode_postamble =
|
|
||||||
"endbfrange\n\
|
|
||||||
endcmap\n\
|
|
||||||
CMapName currentdict /CMap defineresource pop\n\
|
|
||||||
end\n\
|
|
||||||
end\n"
|
|
||||||
|
|
||||||
let tounicode_map s us =
|
|
||||||
let b = Buffer.create 1024 in
|
|
||||||
let s = ref s in
|
|
||||||
Buffer.add_string b tounicode_preamble;
|
|
||||||
Buffer.add_string b (Printf.sprintf "%i beginbfrange\n" (length us));
|
|
||||||
iter
|
|
||||||
(fun u -> Buffer.add_string b (Printf.sprintf "<%02x><%02x><%04x>" !s !s u);
|
|
||||||
s := !s + 1)
|
|
||||||
us;
|
|
||||||
Buffer.add_string b tounicode_postamble;
|
|
||||||
bytes_of_string (Buffer.contents b)
|
|
||||||
|
|
||||||
let required_tables =
|
let required_tables =
|
||||||
["head"; "hhea"; "loca"; "cmap"; "maxp"; "cvt "; "glyf"; "prep"; "hmtx"; "fpgm"]
|
["head"; "hhea"; "loca"; "cmap"; "maxp"; "cvt "; "glyf"; "prep"; "hmtx"; "fpgm"]
|
||||||
|
|
||||||
|
@ -563,13 +529,13 @@ let parse ?(subset=[]) data encoding =
|
||||||
subset_font major minor !tables indexToLocFormat (if subset = [] then [] else [hd subset])
|
subset_font major minor !tables indexToLocFormat (if subset = [] then [] else [hd subset])
|
||||||
encoding !glyphcodes loca mk_b glyfoffset data
|
encoding !glyphcodes loca mk_b glyfoffset data
|
||||||
in
|
in
|
||||||
let subset_tounicode =
|
(*let subset_tounicode =
|
||||||
if subset = [] then None else Some (tounicode_map 0 [hd subset])
|
if subset = [] then None else Some (tounicode_map 0 [hd subset])
|
||||||
in
|
in*)
|
||||||
begin match subset_tounicode with Some x -> Printf.printf "%S\n" (string_of_bytes x) | None -> () end;
|
(*begin match subset_tounicode with Some x -> Printf.printf "%S\n" (string_of_bytes x) | None -> () end;*)
|
||||||
[{flags; minx; miny; maxx; maxy; italicangle; ascent; descent;
|
[{flags; minx; miny; maxx; maxy; italicangle; ascent; descent;
|
||||||
capheight; stemv; xheight; avgwidth; maxwidth; firstchar; lastchar;
|
capheight; stemv; xheight; avgwidth; maxwidth; firstchar; lastchar;
|
||||||
widths; subset_fontfile = main_subset; subset = if subset = [] then [] else tl subset; tounicode = None};
|
widths; subset_fontfile = main_subset; subset = if subset = [] then [] else tl subset; tounicode = None};
|
||||||
{flags; minx; miny; maxx; maxy; italicangle; ascent; descent;
|
{flags; minx; miny; maxx; maxy; italicangle; ascent; descent;
|
||||||
capheight; stemv; xheight; avgwidth; maxwidth; firstchar; lastchar;
|
capheight; stemv; xheight; avgwidth; maxwidth; firstchar; lastchar;
|
||||||
widths; subset_fontfile = second_subset; subset = if subset = [] then [] else [hd subset]; tounicode = subset_tounicode}]
|
widths; subset_fontfile = second_subset; subset = if subset = [] then [] else [hd subset]; tounicode = None}]
|
||||||
|
|
|
@ -20,7 +20,7 @@ type t =
|
||||||
widths : int array;
|
widths : int array;
|
||||||
subset_fontfile : Pdfio.bytes;
|
subset_fontfile : Pdfio.bytes;
|
||||||
subset : int list;
|
subset : int list;
|
||||||
tounicode : Pdfio.bytes option}
|
tounicode : (int, string) Hashtbl.t option}
|
||||||
|
|
||||||
(* Parse the given TrueType font file. It will return one or more fonts. The
|
(* Parse the given TrueType font file. It will return one or more fonts. The
|
||||||
first, a plain Latin font in the given encoding. Others are for the
|
first, a plain Latin font in the given encoding. Others are for the
|
||||||
|
|
Loading…
Reference in New Issue