Beginning -add-text/TTF

This commit is contained in:
John Whitington 2023-07-18 14:05:17 +01:00
parent 7408a79186
commit 6a92be56cf
3 changed files with 28 additions and 28 deletions

View File

@ -231,7 +231,7 @@ let expand_lines text time pdf endpage extract_text_font_size filename bates bat
let addtext
time lines linewidth outline fast colour fontname encoding bates batespad
fontsize fontpack font fontpdfobj underneath position hoffset voffset text pages
fontsize fontpack font fontpdfobj fontpackpdfobjs underneath position hoffset voffset text pages
cropbox opacity justification filename extract_text_font_size shift raw pdf
=
let endpage = Pdfpage.endpage pdf in
@ -512,29 +512,27 @@ let
| Some (Pdftext.StandardFont (_, e)) -> e
| Some (Pdftext.SimpleFont {encoding}) -> encoding
| _ -> Pdftext.WinAnsiEncoding
in
let fontpackpdfobjs =
match cpdffont with
| Cpdfembed.EmbedInfo {fontfile; fontname; encoding} ->
let codepoints = map fst (list_of_hashtbl used) in
let fonts = fst (Cpdfembed.embed_truetype !pdf ~fontfile ~fontname ~codepoints ~encoding) in
map (Pdftext.write_font !pdf) fonts
| _ -> []
in
iter
(fun line ->
let voff, hoff = !voffset, 0. in
pdf :=
addtext time lines linewidth outline fast colour !realfontname encoding
bates batespad fontsize fontpack font fontpdfobj underneath position hoff voff line
pages cropbox opacity justification filename extract_text_font_size shift
raw !pdf;
bates batespad fontsize fontpack font fontpdfobj fontpackpdfobjs underneath
position hoff voff line pages cropbox opacity justification filename
extract_text_font_size shift raw !pdf;
voffset := !voffset +. (linespacing *. fontsize))
lines;
(* FIXME Here we need to embed all the fonts, not just one *)
begin match cpdffont with
| Cpdfembed.EmbedInfo {fontfile; fontname; encoding} ->
let codepoints = map fst (list_of_hashtbl used) in
let objnum = match fontpdfobj with Pdf.Indirect i -> i | _ -> failwith "bad fontpdfobj" in
let font = hd (fst (Cpdfembed.embed_truetype !pdf ~fontfile ~fontname ~codepoints ~encoding)) in
ignore (Pdftext.write_font ~objnum !pdf font)
| _ -> ()
end;
!pdf
let addrectangle
fast (w, h) colour outline linewidth opacity position relative_to_cropbox
underneath range pdf

View File

@ -106,4 +106,3 @@ let rec collate_runs cfn a = function
let collate_runs = function
| [] -> []
| (_, fontnum, _)::_ as l -> collate_runs fontnum [] l

View File

@ -6,6 +6,8 @@ let dbg =
(* Pdfe.logger := (fun s -> print_string s; flush stdout) *)
ref false
let test_subsetting = true
type t =
{flags : int;
minx : int;
@ -496,6 +498,7 @@ let write_font filename data =
close_out fh
let find_main encoding subset =
if test_subsetting then (take subset 3, [drop subset 3]) else
let encoding_table = Pdftext.table_of_encoding encoding in
let first, rest =
List.partition