-add-text now only a single caller to Cpdfembed
This commit is contained in:
parent
566b4ba304
commit
6cbfc84150
|
@ -2,13 +2,6 @@
|
|||
open Pdfutil
|
||||
open Cpdferror
|
||||
|
||||
(* Keep a record of charcodes used for font subsetting. *)
|
||||
let used = null_hash ()
|
||||
|
||||
(* If we have used a TTF font, put its name and object number here. Then we
|
||||
know we put it there, and can avoid writing it anew across ANDS. *)
|
||||
let glob_pdfobjnum = null_hash ()
|
||||
|
||||
type color =
|
||||
Grey of float
|
||||
| RGB of float * float * float
|
||||
|
@ -58,14 +51,6 @@ let colour_op_stroke = function
|
|||
| CYMK (c, y, m, k) -> Pdfops.Op_K (c, y, m, k)
|
||||
|
||||
let ops fontname longest_w x y rotate hoffset voffset outline linewidth unique_fontname unique_extgstatename colour fontsize text =
|
||||
begin match Hashtbl.find used fontname with
|
||||
| exception Not_found ->
|
||||
let thisused = null_hash () in
|
||||
String.iter (fun x -> Hashtbl.replace thisused x ()) text;
|
||||
Hashtbl.add used fontname thisused
|
||||
| thisused ->
|
||||
String.iter (fun x -> Hashtbl.replace thisused x ()) text;
|
||||
end;
|
||||
[Pdfops.Op_q;
|
||||
Pdfops.Op_BMC "/CPDFSTAMP";
|
||||
Pdfops.Op_cm
|
||||
|
@ -234,6 +219,16 @@ let replace_pairs pdf endpage extract_text_font_size filename bates batespad num
|
|||
then numstring
|
||||
else implode (many '0' (w - String.length numstring)) ^ numstring))]
|
||||
|
||||
let expand_lines text time pdf endpage extract_text_font_size filename bates batespad num page lines =
|
||||
let expanded_lines =
|
||||
map
|
||||
(function text ->
|
||||
process_text time text (replace_pairs pdf endpage extract_text_font_size filename bates batespad num page))
|
||||
lines
|
||||
in
|
||||
(* process URLs for justification too *)
|
||||
map (fun line -> fst (get_urls_line line)) expanded_lines
|
||||
|
||||
let addtext
|
||||
time lines linewidth outline fast colour fontname encoding bates batespad
|
||||
fontsize font fontpdfobj underneath position hoffset voffset text pages
|
||||
|
@ -300,16 +295,7 @@ let addtext
|
|||
let ops, urls, x, y, hoffset, voffset, text, joffset =
|
||||
let text = process_text time text (replace_pairs pdf endpage extract_text_font_size filename bates batespad num page) in
|
||||
let text, urls = get_urls_line text in
|
||||
|
||||
let expanded_lines =
|
||||
map
|
||||
(function text ->
|
||||
process_text time text (replace_pairs pdf endpage extract_text_font_size filename bates batespad num page))
|
||||
lines
|
||||
in
|
||||
let expanded_lines = (* process URLs for justification too *)
|
||||
map (fun line -> fst (get_urls_line line)) expanded_lines
|
||||
in
|
||||
let expanded_lines = expand_lines text time pdf endpage extract_text_font_size filename bates batespad num page lines in
|
||||
let textwidth = calc_textwidth text
|
||||
and allwidths = map calc_textwidth expanded_lines in
|
||||
let longest_w = last (sort compare allwidths) in
|
||||
|
@ -426,8 +412,19 @@ let
|
|||
justification midline topline filename extract_text_font_size shift
|
||||
?(raw=false) pdf
|
||||
=
|
||||
let time = Cpdfstrftime.current_time () in
|
||||
if pages = [] then error "addtexts: empty page range" else
|
||||
let time = Cpdfstrftime.current_time () in
|
||||
let endpage = Pdfpage.endpage pdf in
|
||||
let ps = Pdfpage.pages_of_pagetree pdf in
|
||||
let used = null_hash () in
|
||||
let lines = map unescape_string (split_at_newline text) in
|
||||
iter2
|
||||
(fun num page ->
|
||||
let expanded_lines = expand_lines text time pdf endpage extract_text_font_size filename bates batespad num page lines in
|
||||
let codepoints = map Pdftext.codepoints_of_utf8 expanded_lines in
|
||||
iter (iter (fun x -> Hashtbl.replace used x ())) codepoints)
|
||||
pages
|
||||
(map (fun x -> List.nth ps (x - 1)) pages);
|
||||
let realfontname = ref fontname in
|
||||
let font =
|
||||
match cpdffont with
|
||||
|
@ -436,7 +433,7 @@ let
|
|||
Some (hd (fst f))
|
||||
| Cpdfembed.EmbedInfo {fontfile; fontname; encoding} ->
|
||||
(*Printf.printf "Cpdfaddtext.addtexts: EmbedInfo\n";*)
|
||||
let embedded = Cpdfembed.embed_truetype pdf ~fontfile ~fontname ~codepoints:[] ~encoding in
|
||||
let embedded = Cpdfembed.embed_truetype pdf ~fontfile ~fontname ~codepoints:(map fst (list_of_hashtbl used)) ~encoding in
|
||||
Some (hd (fst embedded))
|
||||
| Cpdfembed.ExistingNamedFont -> None
|
||||
in
|
||||
|
@ -445,13 +442,7 @@ let
|
|||
| Some (Pdftext.StandardFont _ as font) ->
|
||||
Pdf.Indirect (Pdftext.write_font pdf font)
|
||||
| Some f ->
|
||||
begin match Hashtbl.find glob_pdfobjnum fontname with
|
||||
| exception Not_found ->
|
||||
let i = Pdftext.write_font pdf f in
|
||||
Hashtbl.add glob_pdfobjnum fontname i; Pdf.Indirect i
|
||||
| i ->
|
||||
Pdf.Indirect i
|
||||
end
|
||||
Pdf.Indirect (Pdftext.write_font pdf f)
|
||||
| None ->
|
||||
let firstpage =
|
||||
List.nth (Pdfpage.pages_of_pagetree pdf) (hd pages - 1)
|
||||
|
@ -532,23 +523,14 @@ let
|
|||
!pdf;
|
||||
voffset := !voffset +. (linespacing *. fontsize))
|
||||
lines;
|
||||
begin match cpdffont with
|
||||
(*begin match cpdffont with
|
||||
| Cpdfembed.EmbedInfo {fontfile; fontname; encoding} ->
|
||||
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 glyphlist_table = Pdfglyphlist.glyph_hashes () in
|
||||
let codepoints =
|
||||
map (fun c -> unicode_codepoint_of_pdfcode encoding_table glyphlist_table (int_of_char c)) charcodes
|
||||
in
|
||||
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;
|
||||
end;*)
|
||||
!pdf
|
||||
|
||||
|
||||
|
|
|
@ -2,9 +2,6 @@
|
|||
open Pdfutil
|
||||
open Pdfio
|
||||
|
||||
(* FIXME Make sure -add-text calls subset once only *)
|
||||
(* FIXME Make it work with -draw *)
|
||||
(* FIXME Check proper use of fontpacks and maximal sharing in -toc -typeset -add-text -draw *)
|
||||
(* FIXME Proper widths for .notdef, and warn on .notdef being produced *)
|
||||
(* FIXME Add suport for composite glyphs *)
|
||||
(* FIXME Make sure -embed-std14 works for all commands *)
|
||||
|
|
Loading…
Reference in New Issue