more
This commit is contained in:
parent
79dd9607c9
commit
f2ed7580b3
|
@ -43,32 +43,6 @@ let width_of_text font text =
|
||||||
end
|
end
|
||||||
| _ -> 0.
|
| _ -> 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
|
let colour_op = function
|
||||||
| RGB (r, g, b) -> Pdfops.Op_rg (r, g, b)
|
| RGB (r, g, b) -> Pdfops.Op_rg (r, g, b)
|
||||||
| Grey g -> Pdfops.Op_g g
|
| 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)
|
| 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 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_q;
|
||||||
Pdfops.Op_BMC "/CPDFSTAMP";
|
Pdfops.Op_BMC "/CPDFSTAMP";
|
||||||
Pdfops.Op_cm
|
Pdfops.Op_cm
|
||||||
|
@ -556,7 +526,6 @@ let
|
||||||
flprint "\n";
|
flprint "\n";
|
||||||
Printf.printf "relative-to-cropbox = %b" cropbox;
|
Printf.printf "relative-to-cropbox = %b" cropbox;
|
||||||
flprint "\n";*)
|
flprint "\n";*)
|
||||||
ops_metrics := [];
|
|
||||||
let realfontname = ref fontname in
|
let realfontname = ref fontname in
|
||||||
let fontpdfobj =
|
let fontpdfobj =
|
||||||
match font with
|
match font with
|
||||||
|
@ -607,10 +576,8 @@ let
|
||||||
let baseline_adjustment =
|
let baseline_adjustment =
|
||||||
(fontsize *. float (Pdfstandard14.baseline_adjustment font)) /. 1000.
|
(fontsize *. float (Pdfstandard14.baseline_adjustment font)) /. 1000.
|
||||||
in
|
in
|
||||||
ops_baseline_adjustment := baseline_adjustment;
|
|
||||||
voffset := !voffset +. baseline_adjustment
|
voffset := !voffset +. baseline_adjustment
|
||||||
| _ ->
|
| _ -> ()
|
||||||
ops_baseline_adjustment := 0.
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if topline then
|
if topline then
|
||||||
|
@ -619,13 +586,10 @@ let
|
||||||
let baseline_adjustment =
|
let baseline_adjustment =
|
||||||
(fontsize *. float (Pdfstandard14.baseline_adjustment font) *. 2.0) /. 1000.
|
(fontsize *. float (Pdfstandard14.baseline_adjustment font) *. 2.0) /. 1000.
|
||||||
in
|
in
|
||||||
ops_baseline_adjustment := baseline_adjustment;
|
|
||||||
voffset := !voffset +. baseline_adjustment
|
voffset := !voffset +. baseline_adjustment
|
||||||
| _ ->
|
| _ -> ()
|
||||||
ops_baseline_adjustment := 0.
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
ops_baseline_adjustment := 0.;
|
|
||||||
iter
|
iter
|
||||||
(fun line ->
|
(fun line ->
|
||||||
let voff, hoff =
|
let voff, hoff =
|
||||||
|
@ -639,7 +603,6 @@ let
|
||||||
!pdf;
|
!pdf;
|
||||||
voffset := !voffset +. (linespacing *. fontsize))
|
voffset := !voffset +. (linespacing *. fontsize))
|
||||||
lines;
|
lines;
|
||||||
ops_metrics := rev !ops_metrics;
|
|
||||||
!pdf
|
!pdf
|
||||||
|
|
||||||
let removetext range pdf =
|
let removetext range pdf =
|
||||||
|
@ -733,7 +696,6 @@ let addrectangle
|
||||||
else Pdfpage.postpend_operators pdf ops ~fast:fast page
|
else Pdfpage.postpend_operators pdf ops ~fast:fast page
|
||||||
in
|
in
|
||||||
Cpdfpage.process_pages (Cpdfutil.ppstub addrectangle_page) pdf range
|
Cpdfpage.process_pages (Cpdfutil.ppstub addrectangle_page) pdf range
|
||||||
open Pdfutil
|
|
||||||
|
|
||||||
let rec remove_all_text_ops pdf resources content =
|
let rec remove_all_text_ops pdf resources content =
|
||||||
let is_textop = function
|
let is_textop = function
|
||||||
|
|
|
@ -19,7 +19,7 @@ type justification =
|
||||||
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*)
|
bool -> (*metrics - defunct*)
|
||||||
float -> (*linewidth*)
|
float -> (*linewidth*)
|
||||||
bool -> (*outline*)
|
bool -> (*outline*)
|
||||||
bool -> (*fast*)
|
bool -> (*fast*)
|
||||||
|
@ -59,19 +59,11 @@ val addrectangle :
|
||||||
Cpdfposition.position ->
|
Cpdfposition.position ->
|
||||||
bool -> bool -> int list -> Pdf.t -> Pdf.t
|
bool -> bool -> int list -> Pdf.t -> Pdf.t
|
||||||
|
|
||||||
val metrics_howmany : unit -> int
|
(** Remove text added by Cpdfaddtext from the given pages. *)
|
||||||
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. *)
|
|
||||||
val removetext : int list -> Pdf.t -> Pdf.t
|
val removetext : int list -> Pdf.t -> Pdf.t
|
||||||
|
|
||||||
(** Extract text *)
|
(** Extract text *)
|
||||||
val extract_text : float option -> Pdf.t -> int list -> string
|
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
|
val remove_all_text : int list -> Pdf.t -> Pdf.t
|
||||||
|
|
|
@ -380,7 +380,7 @@ type args =
|
||||||
mutable direction : int;
|
mutable direction : int;
|
||||||
mutable effect_duration : float;
|
mutable effect_duration : float;
|
||||||
mutable font : font;
|
mutable font : font;
|
||||||
mutable fontfile : string option;
|
mutable fontfile : Pdfio.bytes option;
|
||||||
mutable fontencoding : Pdftext.encoding;
|
mutable fontencoding : Pdftext.encoding;
|
||||||
mutable fontname : string;
|
mutable fontname : string;
|
||||||
mutable fontsize : float;
|
mutable fontsize : float;
|
||||||
|
@ -1724,7 +1724,7 @@ let setnowarnrotate () =
|
||||||
args.no_warn_rotate <- true
|
args.no_warn_rotate <- true
|
||||||
|
|
||||||
let setfontttf s =
|
let setfontttf s =
|
||||||
args.fontfile <- Some s
|
args.fontfile <- Some (Pdfio.bytes_of_string (contents_of_file s))
|
||||||
|
|
||||||
let setfontttfencoding s =
|
let setfontttfencoding s =
|
||||||
args.fontencoding <-
|
args.fontencoding <-
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
(* Embed a TrueType font for the given set of UTF8 characters in the given
|
(* 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
|
encoding, adding it as an object to the PDF, and returning the number of
|
||||||
that object. *)
|
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
|
||||||
|
|
Loading…
Reference in New Issue