This commit is contained in:
John Whitington 2022-09-12 17:05:20 +01:00
parent f2ed7580b3
commit f1792ce448
3 changed files with 9 additions and 37 deletions

View File

@ -53,7 +53,7 @@ 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 metrics x y rotate hoffset voffset outline linewidth unique_fontname unique_extgstatename colour fontsize text = let ops longest_w x y rotate hoffset voffset outline linewidth unique_fontname unique_extgstatename colour fontsize text =
[Pdfops.Op_q; [Pdfops.Op_q;
Pdfops.Op_BMC "/CPDFSTAMP"; Pdfops.Op_BMC "/CPDFSTAMP";
Pdfops.Op_cm Pdfops.Op_cm
@ -290,7 +290,7 @@ let pagelabel pdf num =
(Pdfpagelabels.complete (Pdfpagelabels.read pdf)) (Pdfpagelabels.complete (Pdfpagelabels.read pdf))
let addtext let addtext
metrics lines linewidth outline fast colour fontname embed bates batespad fontsize font lines linewidth outline fast colour fontname embed bates batespad fontsize font
underneath position hoffset voffset text pages orientation cropbox opacity 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
= =
@ -408,11 +408,11 @@ let addtext
in in
match font with match font with
| Some f -> | Some f ->
ops longest_w metrics (x +. shift_x) (y +. shift_y) rotate (hoffset +. joffset) voffset outline linewidth ops 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 metrics (x +. shift_x) (y +. shift_y) rotate (hoffset +. joffset) voffset outline linewidth ops 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
@ -469,9 +469,6 @@ let addtext
then Pdfpage.prepend_operators pdf ops ~fast:fast page then Pdfpage.prepend_operators pdf ops ~fast:fast page
else Pdfpage.postpend_operators pdf ops ~fast:fast page else Pdfpage.postpend_operators pdf ops ~fast:fast page
in in
if metrics then
(ignore (Cpdfpage.iter_pages (fun a b -> ignore (addtext_page a b)) pdf pages); pdf)
else
Cpdfpage.process_pages (Cpdfutil.ppstub addtext_page) pdf pages Cpdfpage.process_pages (Cpdfutil.ppstub addtext_page) pdf pages
(* Prev is a list of lists of characters *) (* Prev is a list of lists of characters *)
@ -497,35 +494,11 @@ let unescape_string s =
implode (unescape_chars [] (explode s)) implode (unescape_chars [] (explode s))
let let
addtexts metrics linewidth outline fast fontname (font : Pdftext.standard_font option) embed bates batespad colour position linespacing addtexts linewidth outline fast fontname (font : Pdftext.standard_font option) embed bates batespad colour position linespacing
fontsize underneath text pages orientation cropbox opacity justification fontsize underneath text pages orientation cropbox opacity justification
midline topline filename extract_text_font_size shift ?(raw=false) pdf midline topline filename extract_text_font_size shift ?(raw=false) pdf
= =
if pages = [] then error "addtexts: empty page range" else if pages = [] then error "addtexts: empty page range" else
(*flprint "addtexts:\n";
iter (Printf.printf "%C ") (explode text);
flprint "\n";
Printf.printf "\nCpdf.addtexts: metrics = %b" metrics;
flprint "\n";*)
(*Printf.printf "linewidth = %f\n" linewidth;
Printf.printf "outline = %b\n" outline;
Printf.printf "fast = %b\n" fast;
Printf.printf "fontname = %s\n" fontname;
Printf.printf "winansi text = %s\n" text;
Printf.printf "position = %s\n" (string_of_position position);
Printf.printf "bates = %i\n" bates;
Printf.printf "linespacing = %f\n" linespacing;
Printf.printf "fontsize = %f\n" fontsize;
Printf.printf "underneath = %b\n" underneath;
Printf.printf "font = %s\n" begin match font with None -> "None" | Some x -> Pdftext.string_of_standard_font x end;
Printf.printf "justification = %s\n"
begin match justification with LeftJustify -> "left" | RightJustify -> "right" | CentreJustify -> "centre" end;
Printf.printf "midline = %b\n" midline;
begin match colour with r, g, b -> Printf.printf "%f, %f, %f\n" r g b end;
Printf.printf "opacity = %f\n" opacity;
flprint "\n";
Printf.printf "relative-to-cropbox = %b" cropbox;
flprint "\n";*)
let realfontname = ref fontname in let realfontname = ref fontname in
let fontpdfobj = let fontpdfobj =
match font with match font with
@ -596,7 +569,7 @@ let
if orientation = Cpdfposition.Vertical then 0., -.(!voffset) else !voffset, 0. if orientation = Cpdfposition.Vertical then 0., -.(!voffset) else !voffset, 0.
in in
pdf := pdf :=
addtext metrics 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 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

View File

@ -15,11 +15,10 @@ type justification =
| CentreJustify | CentreJustify
| RightJustify | RightJustify
(** Call [add_texts metrics linewidth outline fast fontname font bates batespad colour (** Call [add_texts linewidth outline fast fontname font bates batespad colour
position linespacing fontsize underneath text pages orientation position linespacing fontsize underneath text pages orientation
relative_to_cropbox midline_adjust topline filename pdf]. For details see cpdfmanual.pdf *) relative_to_cropbox midline_adjust topline filename pdf]. For details see cpdfmanual.pdf *)
val addtexts : val addtexts :
bool -> (*metrics - defunct*)
float -> (*linewidth*) float -> (*linewidth*)
bool -> (*outline*) bool -> (*outline*)
bool -> (*fast*) bool -> (*fast*)

View File

@ -3724,7 +3724,7 @@ let go () =
in in
write_pdf false write_pdf false
(Cpdfaddtext.addtexts (Cpdfaddtext.addtexts
false args.linewidth args.outline args.fast args.fontname args.linewidth args.outline args.fast args.fontname
font args.embedfonts args.bates args.batespad args.color args.position font args.embedfonts args.bates args.batespad args.color args.position
args.linespacing args.fontsize args.underneath text range args.linespacing args.fontsize args.underneath text range
args.orientation args.relative_to_cropbox args.opacity args.orientation args.relative_to_cropbox args.opacity