This commit is contained in:
John Whitington 2022-09-12 17:02:48 +01:00
parent 79dd9607c9
commit f2ed7580b3
4 changed files with 10 additions and 54 deletions

View File

@ -43,32 +43,6 @@ let width_of_text font text =
end
| _ -> 0.
type ops_metrics =
{metrics_text : string;
metrics_x : float;
metrics_y : float;
metrics_rot : float}
let ops_metrics : ops_metrics list ref = ref []
let ops_baseline_adjustment = ref 0.
let metrics_howmany () = length !ops_metrics
let metrics_text n =
utf8_of_winansi (select n !ops_metrics).metrics_text
let metrics_x n =
(select n !ops_metrics).metrics_x
let metrics_y n =
(select n !ops_metrics).metrics_y
let metrics_rot n =
(select n !ops_metrics).metrics_rot
let metrics_baseline_adjustment () = !ops_baseline_adjustment
let colour_op = function
| RGB (r, g, b) -> Pdfops.Op_rg (r, g, b)
| Grey g -> Pdfops.Op_g g
@ -80,10 +54,6 @@ let colour_op_stroke = function
| 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 =
if metrics then
ops_metrics :=
{metrics_text = text; metrics_x = x -. hoffset; metrics_y = y -. voffset; metrics_rot = rotate}
::!ops_metrics;
[Pdfops.Op_q;
Pdfops.Op_BMC "/CPDFSTAMP";
Pdfops.Op_cm
@ -556,7 +526,6 @@ let
flprint "\n";
Printf.printf "relative-to-cropbox = %b" cropbox;
flprint "\n";*)
ops_metrics := [];
let realfontname = ref fontname in
let fontpdfobj =
match font with
@ -607,10 +576,8 @@ let
let baseline_adjustment =
(fontsize *. float (Pdfstandard14.baseline_adjustment font)) /. 1000.
in
ops_baseline_adjustment := baseline_adjustment;
voffset := !voffset +. baseline_adjustment
| _ ->
ops_baseline_adjustment := 0.
| _ -> ()
end
else
if topline then
@ -619,13 +586,10 @@ let
let baseline_adjustment =
(fontsize *. float (Pdfstandard14.baseline_adjustment font) *. 2.0) /. 1000.
in
ops_baseline_adjustment := baseline_adjustment;
voffset := !voffset +. baseline_adjustment
| _ ->
ops_baseline_adjustment := 0.
| _ -> ()
end
else
ops_baseline_adjustment := 0.;
iter
(fun line ->
let voff, hoff =
@ -639,7 +603,6 @@ let
!pdf;
voffset := !voffset +. (linespacing *. fontsize))
lines;
ops_metrics := rev !ops_metrics;
!pdf
let removetext range pdf =
@ -733,7 +696,6 @@ let addrectangle
else Pdfpage.postpend_operators pdf ops ~fast:fast page
in
Cpdfpage.process_pages (Cpdfutil.ppstub addrectangle_page) pdf range
open Pdfutil
let rec remove_all_text_ops pdf resources content =
let is_textop = function

View File

@ -19,7 +19,7 @@ type justification =
position linespacing fontsize underneath text pages orientation
relative_to_cropbox midline_adjust topline filename pdf]. For details see cpdfmanual.pdf *)
val addtexts :
bool -> (*metrics*)
bool -> (*metrics - defunct*)
float -> (*linewidth*)
bool -> (*outline*)
bool -> (*fast*)
@ -59,19 +59,11 @@ val addrectangle :
Cpdfposition.position ->
bool -> bool -> int list -> Pdf.t -> Pdf.t
val metrics_howmany : unit -> int
val metrics_text : int -> string
val metrics_x : int -> float
val metrics_y : int -> float
val metrics_rot : int -> float
val metrics_baseline_adjustment : unit -> float
(** These functions returns some details about the text if [addtexts] is called with [metrics] true. The integer arguments are 1 for the first one, 2 for the second etc. Call [metrics_howmany] first to find out how many. *)
(** Remove text from the given pages. *)
(** Remove text added by Cpdfaddtext from the given pages. *)
val removetext : int list -> Pdf.t -> Pdf.t
(** Extract text *)
val extract_text : float option -> Pdf.t -> int list -> string
(** Remove text *)
(** Remove all text from the given pages *)
val remove_all_text : int list -> Pdf.t -> Pdf.t

View File

@ -380,7 +380,7 @@ type args =
mutable direction : int;
mutable effect_duration : float;
mutable font : font;
mutable fontfile : string option;
mutable fontfile : Pdfio.bytes option;
mutable fontencoding : Pdftext.encoding;
mutable fontname : string;
mutable fontsize : float;
@ -1724,7 +1724,7 @@ let setnowarnrotate () =
args.no_warn_rotate <- true
let setfontttf s =
args.fontfile <- Some s
args.fontfile <- Some (Pdfio.bytes_of_string (contents_of_file s))
let setfontttfencoding s =
args.fontencoding <-

View File

@ -1,4 +1,6 @@
(* Embed a TrueType font for the given set of UTF8 characters in the given
encoding, adding it as an object to the PDF, and returning the number of
that object. *)
val embed_truetype : Pdf.t -> fontfile:Pdfio.bytes -> fontname:string -> text:string -> encoding:Pdftext.encoding -> int
val embed_truetype :
Pdf.t -> fontfile:Pdfio.bytes -> fontname:string -> text:string ->
encoding:Pdftext.encoding -> int