This commit is contained in:
John Whitington 2022-09-16 19:09:41 +01:00
parent 89401d7c2f
commit 54d67ae413
1 changed files with 13 additions and 11 deletions

View File

@ -1,9 +1,3 @@
(* Notes on ttf fonts:
FIXME: baseline / midline adjustments need to be added for ttf fonts.
FIXME: calc_textwidth
*)
open Pdfutil open Pdfutil
open Cpdferror open Cpdferror
@ -297,7 +291,7 @@ let pagelabel pdf num =
let addtext let addtext
lines linewidth outline fast colour fontname embed bates batespad fontsize (font : Pdftext.font option) lines linewidth outline fast colour fontname embed bates batespad fontsize (font : Pdftext.font option)
underneath position hoffset voffset text pages orientation cropbox opacity fontpdfobj underneath position hoffset voffset text pages orientation cropbox opacity
justification filename extract_text_font_size shift pdf justification filename extract_text_font_size shift pdf
= =
let time = Cpdfstrftime.current_time () in let time = Cpdfstrftime.current_time () in
@ -358,6 +352,9 @@ let addtext
text text
in in
(float rawwidth *. fontsize) /. 1000. (float rawwidth *. fontsize) /. 1000.
| Some font ->
let rawwidth = width_of_text font text in
(rawwidth *. fontsize) /. 1000.
| None -> | None ->
let font = let font =
match Pdf.lookup_direct pdf "/Font" page.Pdfpage.resources with match Pdf.lookup_direct pdf "/Font" page.Pdfpage.resources with
@ -424,11 +421,16 @@ let addtext
in in
let newresources = let newresources =
match font with match font with
| Some _ -> | Some (Pdftext.StandardFont _) ->
let newfontdict = let newfontdict =
Pdf.add_dict_entry fontdict unique_fontname (make_font embed fontname) Pdf.add_dict_entry fontdict unique_fontname (make_font embed fontname)
in in
Pdf.add_dict_entry resources' "/Font" newfontdict Pdf.add_dict_entry resources' "/Font" newfontdict
| Some f ->
let newfontdict =
Pdf.add_dict_entry fontdict unique_fontname fontpdfobj
in
Pdf.add_dict_entry resources' "/Font" newfontdict
| None -> page.Pdfpage.resources | None -> page.Pdfpage.resources
in in
(* Build annotations from URL data (get_urls and some sense of metrics) *) (* Build annotations from URL data (get_urls and some sense of metrics) *)
@ -510,8 +512,8 @@ let
match font with match font with
| Some (StandardFont (f, _)) -> | Some (StandardFont (f, _)) ->
make_font embed (Pdftext.string_of_standard_font f) make_font embed (Pdftext.string_of_standard_font f)
| Some _ -> | Some f ->
failwith "unknown font in addtext" Pdf.Indirect (Pdftext.write_font pdf f)
| None -> | None ->
let firstpage = let firstpage =
List.nth (Pdfpage.pages_of_pagetree pdf) (hd pages - 1) List.nth (Pdfpage.pages_of_pagetree pdf) (hd pages - 1)
@ -578,7 +580,7 @@ let
in in
pdf := pdf :=
addtext lines linewidth outline fast colour !realfontname addtext lines linewidth outline fast colour !realfontname
embed bates batespad fontsize font underneath position hoff voff line embed bates batespad fontsize font fontpdfobj underneath position hoff voff line
pages orientation cropbox opacity justification filename pages orientation cropbox opacity justification filename
extract_text_font_size shift extract_text_font_size shift
!pdf; !pdf;