This commit is contained in:
John Whitington 2022-10-04 16:51:54 +01:00
parent 22f6f34686
commit a671c032cc

View File

@ -131,22 +131,28 @@ let read_loca_table indexToLocFormat numGlyphs b =
| 1 -> Array.init (numGlyphs + 1) (function _ -> read_ulong b) | 1 -> Array.init (numGlyphs + 1) (function _ -> read_ulong b)
| _ -> raise (Pdf.PDFError "Unknown indexToLocFormat in read_loca_table") | _ -> raise (Pdf.PDFError "Unknown indexToLocFormat in read_loca_table")
let write_loca_table subset encoding cmap indexToLocFormat bs arr = let write_loca_table subset cmap indexToLocFormat bs arr =
let missing_char_glyph_loca = arr.(0) in let locnums = null_hash () in
let is_included u = iter
true (fun u ->
in let locnum = Hashtbl.find cmap u in
Array.iter Printf.printf "Unicode %i is at location number %i\n" u locnum;
(fun x -> Hashtbl.add locnums locnum ())
subset;
let last = ref 0l in
Array.iteri
(fun i x ->
match indexToLocFormat with match indexToLocFormat with
| 0 -> | 0 ->
if is_included x begin match Hashtbl.find locnums i with
then putval bs 16 (i32div x 2l) | () -> putval bs 16 (i32div x 2l); last := i32div x 2l
else putval bs 16 (i32div missing_char_glyph_loca 2l) | exception Not_found -> putval bs 16 !last
end
| 1 -> | 1 ->
if is_included x begin match Hashtbl.find locnums i with
then putval bs 32 x | () -> putval bs 32 x; last := x
else putval bs 32 missing_char_glyph_loca | exception Not_found -> putval bs 32 !last
end
| _ -> raise (Pdf.PDFError "Unknown indexToLocFormat in write_loca_table")) | _ -> raise (Pdf.PDFError "Unknown indexToLocFormat in write_loca_table"))
arr arr
@ -294,7 +300,7 @@ let remove_unneeded_tables major minor tables indexToLocFormat subset encoding c
(fun (tag, _, _, _) -> (fun (tag, _, _, _) ->
if !dbg then Printf.printf "Writing %s table\n" (string_of_tag tag); if !dbg then Printf.printf "Writing %s table\n" (string_of_tag tag);
if string_of_tag tag = "loca" then if string_of_tag tag = "loca" then
write_loca_table subset encoding cmap indexToLocFormat bs loca write_loca_table subset cmap indexToLocFormat bs loca
else else
match findtag tag with match findtag tag with
| (og_off, Some len) -> | (og_off, Some len) ->