Added -bates-pad-to
This commit is contained in:
parent
b199297040
commit
87998ea7ec
23
cpdf.ml
23
cpdf.ml
|
@ -1577,12 +1577,12 @@ let make_font embed fontname =
|
||||||
("/BaseFont", Pdf.Name ("/" ^ fontname))]
|
("/BaseFont", Pdf.Name ("/" ^ fontname))]
|
||||||
|
|
||||||
let addtext
|
let addtext
|
||||||
metrics lines linewidth outline fast colour fontname embed bates fontsize font
|
metrics 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 pdf
|
justification filename pdf
|
||||||
=
|
=
|
||||||
let endpage = Pdfpage.endpage pdf in
|
let endpage = Pdfpage.endpage pdf in
|
||||||
let replace_pairs pdf filename bates num =
|
let replace_pairs pdf filename bates batespad num =
|
||||||
["%Page", string_of_int num;
|
["%Page", string_of_int num;
|
||||||
"%Roman", roman_upper num;
|
"%Roman", roman_upper num;
|
||||||
"%roman", roman_lower num;
|
"%roman", roman_lower num;
|
||||||
|
@ -1590,7 +1590,15 @@ let addtext
|
||||||
"%Label", pagelabel pdf num;
|
"%Label", pagelabel pdf num;
|
||||||
"%EndPage", string_of_int endpage;
|
"%EndPage", string_of_int endpage;
|
||||||
"%EndLabel", pagelabel pdf endpage;
|
"%EndLabel", pagelabel pdf endpage;
|
||||||
"%Bates", string_of_int (bates + num - 1)] in
|
"%Bates",
|
||||||
|
(let numstring = string_of_int (bates + num - 1) in
|
||||||
|
match batespad with
|
||||||
|
None -> numstring
|
||||||
|
| Some w ->
|
||||||
|
if String.length numstring >= w
|
||||||
|
then numstring
|
||||||
|
else implode (many '0' (w - String.length numstring)) ^ numstring)]
|
||||||
|
in
|
||||||
let addtext_page num page =
|
let addtext_page num page =
|
||||||
let resources', unique_extgstatename =
|
let resources', unique_extgstatename =
|
||||||
if opacity < 1.0 then
|
if opacity < 1.0 then
|
||||||
|
@ -1615,7 +1623,7 @@ let addtext
|
||||||
in
|
in
|
||||||
let unique_fontname = Pdf.unique_key "F" fontdict in
|
let unique_fontname = Pdf.unique_key "F" fontdict in
|
||||||
let ops =
|
let ops =
|
||||||
let text = process_text text (replace_pairs pdf filename bates num) in
|
let text = process_text text (replace_pairs pdf filename bates batespad num) in
|
||||||
let calc_textwidth text =
|
let calc_textwidth text =
|
||||||
match font with
|
match font with
|
||||||
| Some f ->
|
| Some f ->
|
||||||
|
@ -1639,7 +1647,8 @@ let addtext
|
||||||
(rawwidth *. fontsize) /. 1000.
|
(rawwidth *. fontsize) /. 1000.
|
||||||
in
|
in
|
||||||
let expanded_lines =
|
let expanded_lines =
|
||||||
map (function text -> process_text text (replace_pairs pdf filename bates num)) lines
|
map (function text -> process_text text (replace_pairs pdf
|
||||||
|
filename bates batespad num)) lines
|
||||||
in
|
in
|
||||||
let textwidth = calc_textwidth text
|
let textwidth = calc_textwidth text
|
||||||
and allwidths = map calc_textwidth expanded_lines in
|
and allwidths = map calc_textwidth expanded_lines in
|
||||||
|
@ -1709,7 +1718,7 @@ let unescape_string s =
|
||||||
implode (unescape_chars [] (explode s))
|
implode (unescape_chars [] (explode s))
|
||||||
|
|
||||||
let
|
let
|
||||||
addtexts metrics linewidth outline fast fontname font embed bates colour position linespacing
|
addtexts metrics linewidth outline fast fontname font 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 pdf
|
midline topline filename pdf
|
||||||
=
|
=
|
||||||
|
@ -1785,7 +1794,7 @@ let
|
||||||
in
|
in
|
||||||
pdf :=
|
pdf :=
|
||||||
addtext metrics lines linewidth outline fast colour fontname
|
addtext metrics lines linewidth outline fast colour fontname
|
||||||
embed bates 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
|
||||||
!pdf;
|
!pdf;
|
||||||
voffset := !voffset +. (linespacing *. fontsize))
|
voffset := !voffset +. (linespacing *. fontsize))
|
||||||
|
|
5
cpdf.mli
5
cpdf.mli
|
@ -290,7 +290,7 @@ val calculate_position :
|
||||||
float * float * float * float ->
|
float * float * float * float ->
|
||||||
orientation -> position -> float * float * float
|
orientation -> position -> float * float * float
|
||||||
|
|
||||||
(** Call [add_texts metrics linewidth outline fast fontname font bates colour
|
(** Call [add_texts metrics 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 :
|
||||||
|
@ -301,7 +301,8 @@ val addtexts :
|
||||||
string -> (*fontname*)
|
string -> (*fontname*)
|
||||||
Pdftext.standard_font option -> (*font*)
|
Pdftext.standard_font option -> (*font*)
|
||||||
bool -> (* embed font *)
|
bool -> (* embed font *)
|
||||||
int -> (*bates number *)
|
int -> (* bates number *)
|
||||||
|
int option -> (* bates padding width *)
|
||||||
float * float * float -> (*colour*)
|
float * float * float -> (*colour*)
|
||||||
position -> (*position*)
|
position -> (*position*)
|
||||||
float -> (*linespacing*)
|
float -> (*linespacing*)
|
||||||
|
|
|
@ -319,6 +319,7 @@ type args =
|
||||||
mutable topline : bool;
|
mutable topline : bool;
|
||||||
mutable justification : Cpdf.justification;
|
mutable justification : Cpdf.justification;
|
||||||
mutable bates : int;
|
mutable bates : int;
|
||||||
|
mutable batespad : int option;
|
||||||
mutable prerotate : bool;
|
mutable prerotate : bool;
|
||||||
mutable orientation : Cpdf.orientation;
|
mutable orientation : Cpdf.orientation;
|
||||||
mutable relative_to_cropbox : bool;
|
mutable relative_to_cropbox : bool;
|
||||||
|
@ -401,6 +402,7 @@ let args =
|
||||||
topline = false;
|
topline = false;
|
||||||
justification = Cpdf.LeftJustify;
|
justification = Cpdf.LeftJustify;
|
||||||
bates = 0;
|
bates = 0;
|
||||||
|
batespad = None;
|
||||||
prerotate = false;
|
prerotate = false;
|
||||||
orientation = Cpdf.Horizontal;
|
orientation = Cpdf.Horizontal;
|
||||||
relative_to_cropbox = false;
|
relative_to_cropbox = false;
|
||||||
|
@ -483,6 +485,7 @@ let reset_arguments () =
|
||||||
args.topline <- false;
|
args.topline <- false;
|
||||||
args.justification <- Cpdf.LeftJustify;
|
args.justification <- Cpdf.LeftJustify;
|
||||||
args.bates <- 0;
|
args.bates <- 0;
|
||||||
|
args.batespad <- None;
|
||||||
args.prerotate <- false;
|
args.prerotate <- false;
|
||||||
args.orientation <- Cpdf.Horizontal;
|
args.orientation <- Cpdf.Horizontal;
|
||||||
args.relative_to_cropbox <- false;
|
args.relative_to_cropbox <- false;
|
||||||
|
@ -1058,6 +1061,9 @@ let setscalecenter n =
|
||||||
args.position <- Cpdf.ReverseDiagonal;
|
args.position <- Cpdf.ReverseDiagonal;
|
||||||
args.justification <- Cpdf.CentreJustify
|
args.justification <- Cpdf.CentreJustify
|
||||||
|
|
||||||
|
let setbatespad n =
|
||||||
|
args.batespad <- Some n
|
||||||
|
|
||||||
let setbates n =
|
let setbates n =
|
||||||
args.bates <- n
|
args.bates <- n
|
||||||
|
|
||||||
|
@ -1587,6 +1593,9 @@ and specs =
|
||||||
("-bates",
|
("-bates",
|
||||||
Arg.Int setbates,
|
Arg.Int setbates,
|
||||||
" Set the base bates number");
|
" Set the base bates number");
|
||||||
|
("-bates-pad-to",
|
||||||
|
Arg.Int setbatespad,
|
||||||
|
" Pad the bates number with leading zeroes to width");
|
||||||
("-font",
|
("-font",
|
||||||
Arg.String setfont,
|
Arg.String setfont,
|
||||||
" Set the font");
|
" Set the font");
|
||||||
|
@ -3508,7 +3517,7 @@ let go () =
|
||||||
write_pdf false
|
write_pdf false
|
||||||
(Cpdf.addtexts
|
(Cpdf.addtexts
|
||||||
false args.linewidth args.outline args.fast args.fontname
|
false args.linewidth args.outline args.fast args.fontname
|
||||||
font args.embedfonts args.bates 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
|
||||||
args.justification args.midline args.topline filename pdf)
|
args.justification args.midline args.topline filename pdf)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
%FIXME: Document -no-embed-font and encoding switch
|
%FIXME: Document -no-embed-font and encoding switch
|
||||||
|
%Documents bates enhancements
|
||||||
\documentclass{book}
|
\documentclass{book}
|
||||||
\usepackage{palatino}
|
\usepackage{palatino}
|
||||||
\usepackage{microtype}
|
\usepackage{microtype}
|
||||||
|
|
Loading…
Reference in New Issue