mirror of
https://github.com/johnwhitington/cpdf-source.git
synced 2025-04-17 11:37:33 +02:00
Widths for accented characters fixed when embedding fonts
This commit is contained in:
parent
4ade9ab7ed
commit
0980928b77
44
cpdf.ml
44
cpdf.ml
@ -1601,31 +1601,27 @@ let extract_fontbbox header s =
|
|||||||
[a; b; c; d] -> [num a; num b; num c; num d]
|
[a; b; c; d] -> [num a; num b; num c; num d]
|
||||||
| _ -> raise (Failure "extract_fontbbox")
|
| _ -> raise (Failure "extract_fontbbox")
|
||||||
|
|
||||||
(* Get the widths for each character from the hash table, in order, noting the
|
let remove_slash s =
|
||||||
first and last *)
|
match explode s with
|
||||||
let extract_widths_firstlast width_data =
|
'/'::x -> implode x
|
||||||
let sorted = List.sort compare (list_of_hashtbl width_data) in
|
| _ -> raise (Failure "remove_slash")
|
||||||
match sorted, rev sorted with
|
|
||||||
(first, _)::_, (last, _)::_ ->
|
let extract_widths chars_and_widths =
|
||||||
for x = first to last do
|
let win_to_name = List.map (fun (x, y) -> (y, x)) Pdfglyphlist.name_to_win in
|
||||||
if not (Hashtbl.mem width_data x) then
|
List.map
|
||||||
begin
|
(fun x ->
|
||||||
Printf.printf "Failed to find width for char %i\n" x;
|
try
|
||||||
Hashtbl.add width_data x 0
|
let name = List.assoc x win_to_name in
|
||||||
end
|
let width = List.assoc (remove_slash name) chars_and_widths in
|
||||||
done;
|
width
|
||||||
(first, last,
|
with
|
||||||
map snd (List.sort compare (list_of_hashtbl width_data)))
|
_ -> 0)
|
||||||
| _ -> raise (Failure "extract_widths_firstlast")
|
(ilist 0 255)
|
||||||
|
|
||||||
let make_font embed fontname =
|
let make_font embed fontname =
|
||||||
let font = unopt (Pdftext.standard_font_of_name ("/" ^ fontname)) in
|
let font = unopt (Pdftext.standard_font_of_name ("/" ^ fontname)) in
|
||||||
let header, width_data, _, _ = Pdfstandard14.afm_data font in
|
let header, width_data, _, chars_and_widths = Pdfstandard14.afm_data font in
|
||||||
(* Print out the width data *)
|
let widths = extract_widths (list_of_hashtbl chars_and_widths) in
|
||||||
(*Hashtbl.iter
|
|
||||||
(Printf.printf "%i -> %i\n")
|
|
||||||
width_data;*)
|
|
||||||
let firstchar, lastchar, widths = extract_widths_firstlast width_data in
|
|
||||||
let flags = Pdfstandard14.flags_of_standard_font font in
|
let flags = Pdfstandard14.flags_of_standard_font font in
|
||||||
let fontbbox = extract_fontbbox header "FontBBox" in
|
let fontbbox = extract_fontbbox header "FontBBox" in
|
||||||
let italicangle = extract_num header "ItalicAngle" in
|
let italicangle = extract_num header "ItalicAngle" in
|
||||||
@ -1654,8 +1650,8 @@ let make_font embed fontname =
|
|||||||
("/Subtype", Pdf.Name "/Type1");
|
("/Subtype", Pdf.Name "/Type1");
|
||||||
("/BaseFont", Pdf.Name ("/" ^ fontname));
|
("/BaseFont", Pdf.Name ("/" ^ fontname));
|
||||||
("/Encoding", Pdf.Name "/WinAnsiEncoding");
|
("/Encoding", Pdf.Name "/WinAnsiEncoding");
|
||||||
("/FirstChar", Pdf.Integer firstchar);
|
("/FirstChar", Pdf.Integer 0);
|
||||||
("/LastChar", Pdf.Integer lastchar);
|
("/LastChar", Pdf.Integer 255);
|
||||||
("/Widths", Pdf.Array (map (fun x -> Pdf.Integer x) widths));
|
("/Widths", Pdf.Array (map (fun x -> Pdf.Integer x) widths));
|
||||||
("/FontDescriptor", fontdescriptor)]
|
("/FontDescriptor", fontdescriptor)]
|
||||||
else
|
else
|
||||||
|
BIN
text.pdf
BIN
text.pdf
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user