This commit is contained in:
John Whitington 2022-09-24 17:29:04 +01:00
parent 6589824a8f
commit 983b087020
1 changed files with 34 additions and 23 deletions

View File

@ -55,26 +55,33 @@ let colour_op_stroke = function
| Grey g -> Pdfops.Op_G g | Grey g -> Pdfops.Op_G g
| CYMK (c, y, m, k) -> Pdfops.Op_K (c, y, m, k) | CYMK (c, y, m, k) -> Pdfops.Op_K (c, y, m, k)
let ops longest_w x y rotate hoffset voffset outline linewidth unique_fontname unique_extgstatename colour fontsize text = let ops fontname longest_w x y rotate hoffset voffset outline linewidth unique_fontname unique_extgstatename colour fontsize text =
String.iter (fun x -> Hashtbl.replace used x ()) text; begin match Hashtbl.find used fontname with
[Pdfops.Op_q; | exception Not_found ->
Pdfops.Op_BMC "/CPDFSTAMP"; let thisused = null_hash () in
Pdfops.Op_cm String.iter (fun x -> Hashtbl.replace thisused x ()) text;
(Pdftransform.matrix_of_transform Hashtbl.add used fontname thisused
[Pdftransform.Translate (x -. hoffset, y -. voffset); | thisused ->
Pdftransform.Rotate ((0., 0.), rotate)]); String.iter (fun x -> Hashtbl.replace thisused x ()) text;
Pdfops.Op_BT; end;
] @ [Pdfops.Op_q;
(if outline then [Pdfops.Op_w linewidth; Pdfops.Op_Tr 1] else [Pdfops.Op_Tr 0]) @ Pdfops.Op_BMC "/CPDFSTAMP";
[colour_op colour; colour_op_stroke colour] Pdfops.Op_cm
@ (Pdftransform.matrix_of_transform
(match unique_extgstatename with None -> [] | Some n -> [Pdfops.Op_gs n]) [Pdftransform.Translate (x -. hoffset, y -. voffset);
@ Pdftransform.Rotate ((0., 0.), rotate)]);
[Pdfops.Op_Tf (unique_fontname, fontsize); Pdfops.Op_BT;
Pdfops.Op_Tj text; ] @
Pdfops.Op_ET; (if outline then [Pdfops.Op_w linewidth; Pdfops.Op_Tr 1] else [Pdfops.Op_Tr 0]) @
Pdfops.Op_EMC; [colour_op colour; colour_op_stroke colour]
Pdfops.Op_Q] @
(match unique_extgstatename with None -> [] | Some n -> [Pdfops.Op_gs n])
@
[Pdfops.Op_Tf (unique_fontname, fontsize);
Pdfops.Op_Tj text;
Pdfops.Op_ET;
Pdfops.Op_EMC;
Pdfops.Op_Q]
type justification = LeftJustify | CentreJustify | RightJustify type justification = LeftJustify | CentreJustify | RightJustify
@ -417,11 +424,11 @@ let addtext
in in
match font with match font with
| Some f -> | Some f ->
ops longest_w (x +. shift_x) (y +. shift_y) rotate (hoffset +. joffset) voffset outline linewidth ops fontname longest_w (x +. shift_x) (y +. shift_y) rotate (hoffset +. joffset) voffset outline linewidth
unique_fontname unique_extgstatename colour fontsize text, unique_fontname unique_extgstatename colour fontsize text,
urls, x, y, hoffset, voffset, text, joffset urls, x, y, hoffset, voffset, text, joffset
| None -> | None ->
ops longest_w (x +. shift_x) (y +. shift_y) rotate (hoffset +. joffset) voffset outline linewidth ops fontname longest_w (x +. shift_x) (y +. shift_y) rotate (hoffset +. joffset) voffset outline linewidth
fontname None colour fontsize text, fontname None colour fontsize text,
urls, x, y, hoffset, voffset, text, joffset urls, x, y, hoffset, voffset, text, joffset
in in
@ -611,7 +618,11 @@ let
begin match embedinfo with begin match embedinfo with
| None -> () | None -> ()
| Some (_, fontfile, fontname, encoding) -> | Some (_, fontfile, fontname, encoding) ->
let charcodes = map fst (list_of_hashtbl used) in let charcodes =
match Hashtbl.find used fontname with
| exception Not_found -> []
| thisused -> map fst (list_of_hashtbl thisused)
in
let encoding_table = Pdftext.table_of_encoding encoding in let encoding_table = Pdftext.table_of_encoding encoding in
let glyphlist_table = Pdfglyphlist.glyph_hashes () in let glyphlist_table = Pdfglyphlist.glyph_hashes () in
let codepoints = let codepoints =