This commit is contained in:
John Whitington 2022-10-13 19:33:52 +01:00
parent e29add66b1
commit 44f62e49ca
1 changed files with 12 additions and 8 deletions

View File

@ -499,8 +499,11 @@ let parse ?(subset=[]) data encoding =
| (_, _, o, l)::_ -> o, l | (_, _, o, l)::_ -> o, l
| [] -> raise (Pdf.PDFError "No loca table found in TrueType font") | [] -> raise (Pdf.PDFError "No loca table found in TrueType font")
in in
let subset_1 = if subset = [] then [] else tl subset in
let subset_2 = if subset = [] then [] else [hd subset] in
let flags = calculate_flags italicangle in let flags = calculate_flags italicangle in
let firstchar, lastchar = calculate_limits subset in let firstchar_1, lastchar_1 = calculate_limits subset_1 in
let firstchar_2, lastchar_2 = calculate_limits subset_2 in
let numOfLongHorMetrics = let numOfLongHorMetrics =
match keep (function (t, _, _, _) -> string_of_tag t = "hhea") !tables with match keep (function (t, _, _, _) -> string_of_tag t = "hhea") !tables with
| (_, _, o, l)::_ -> let b = mk_b (i32toi o) in read_hhea_table b | (_, _, o, l)::_ -> let b = mk_b (i32toi o) in read_hhea_table b
@ -511,7 +514,8 @@ let parse ?(subset=[]) data encoding =
| (_, _, o, _)::_ -> read_hmtx_table numOfLongHorMetrics (mk_b (i32toi o)) | (_, _, o, _)::_ -> read_hmtx_table numOfLongHorMetrics (mk_b (i32toi o))
| [] -> raise (Pdf.PDFError "No hmtx table found in TrueType font") | [] -> raise (Pdf.PDFError "No hmtx table found in TrueType font")
in in
let widths = calculate_widths unitsPerEm encoding firstchar lastchar subset !glyphcodes hmtxdata in let widths_1 = calculate_widths unitsPerEm encoding firstchar_1 lastchar_1 subset_1 !glyphcodes hmtxdata in
let widths_2 = calculate_widths unitsPerEm encoding firstchar_2 lastchar_2 subset_2 !glyphcodes hmtxdata in
let maxwidth = calculate_maxwidth unitsPerEm hmtxdata in let maxwidth = calculate_maxwidth unitsPerEm hmtxdata in
let stemv = calculate_stemv () in let stemv = calculate_stemv () in
let b = mk_b (i32toi locaoffset) in let b = mk_b (i32toi locaoffset) in
@ -522,11 +526,11 @@ let parse ?(subset=[]) data encoding =
| [] -> raise (Pdf.PDFError "No glyf table found in TrueType font") | [] -> raise (Pdf.PDFError "No glyf table found in TrueType font")
in in
let main_subset = let main_subset =
subset_font major minor !tables indexToLocFormat (if subset = [] then [] else tl subset) subset_font major minor !tables indexToLocFormat subset_1
encoding !glyphcodes loca mk_b glyfoffset data encoding !glyphcodes loca mk_b glyfoffset data
in in
let second_subset = let second_subset =
subset_font major minor !tables indexToLocFormat (if subset = [] then [] else [hd subset]) subset_font major minor !tables indexToLocFormat subset_2
encoding !glyphcodes loca mk_b glyfoffset data encoding !glyphcodes loca mk_b glyfoffset data
in in
let second_tounicode = let second_tounicode =
@ -536,9 +540,9 @@ let parse ?(subset=[]) data encoding =
Some h Some h
in in
[{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 = firstchar_1; lastchar = lastchar_1;
widths; subset_fontfile = main_subset; subset = if subset = [] then [] else tl subset; tounicode = None}; widths = widths_1; subset_fontfile = main_subset; subset = subset_1; 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 = firstchar_2; lastchar = lastchar_2;
widths; subset_fontfile = second_subset; subset = if subset = [] then [] else [hd subset]; widths = widths_2; subset_fontfile = second_subset; subset = subset_2;
tounicode = second_tounicode}] tounicode = second_tounicode}]