Added -bates-pad-to

This commit is contained in:
John Whitington 2015-07-17 16:34:47 +01:00
parent b199297040
commit 87998ea7ec
4 changed files with 30 additions and 10 deletions

23
cpdf.ml
View File

@ -1577,12 +1577,12 @@ let make_font embed fontname =
("/BaseFont", Pdf.Name ("/" ^ fontname))]
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
justification filename pdf
=
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;
"%Roman", roman_upper num;
"%roman", roman_lower num;
@ -1590,7 +1590,15 @@ let addtext
"%Label", pagelabel pdf num;
"%EndPage", string_of_int 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 resources', unique_extgstatename =
if opacity < 1.0 then
@ -1615,7 +1623,7 @@ let addtext
in
let unique_fontname = Pdf.unique_key "F" fontdict in
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 =
match font with
| Some f ->
@ -1639,7 +1647,8 @@ let addtext
(rawwidth *. fontsize) /. 1000.
in
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
let textwidth = calc_textwidth text
and allwidths = map calc_textwidth expanded_lines in
@ -1709,7 +1718,7 @@ let unescape_string s =
implode (unescape_chars [] (explode s))
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
midline topline filename pdf
=
@ -1785,7 +1794,7 @@ let
in
pdf :=
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
!pdf;
voffset := !voffset +. (linespacing *. fontsize))

View File

@ -290,7 +290,7 @@ val calculate_position :
float * 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
relative_to_cropbox midline_adjust topline filename pdf]. For details see cpdfmanual.pdf *)
val addtexts :
@ -301,7 +301,8 @@ val addtexts :
string -> (*fontname*)
Pdftext.standard_font option -> (*font*)
bool -> (* embed font *)
int -> (*bates number *)
int -> (* bates number *)
int option -> (* bates padding width *)
float * float * float -> (*colour*)
position -> (*position*)
float -> (*linespacing*)

View File

@ -319,6 +319,7 @@ type args =
mutable topline : bool;
mutable justification : Cpdf.justification;
mutable bates : int;
mutable batespad : int option;
mutable prerotate : bool;
mutable orientation : Cpdf.orientation;
mutable relative_to_cropbox : bool;
@ -401,6 +402,7 @@ let args =
topline = false;
justification = Cpdf.LeftJustify;
bates = 0;
batespad = None;
prerotate = false;
orientation = Cpdf.Horizontal;
relative_to_cropbox = false;
@ -483,6 +485,7 @@ let reset_arguments () =
args.topline <- false;
args.justification <- Cpdf.LeftJustify;
args.bates <- 0;
args.batespad <- None;
args.prerotate <- false;
args.orientation <- Cpdf.Horizontal;
args.relative_to_cropbox <- false;
@ -1058,6 +1061,9 @@ let setscalecenter n =
args.position <- Cpdf.ReverseDiagonal;
args.justification <- Cpdf.CentreJustify
let setbatespad n =
args.batespad <- Some n
let setbates n =
args.bates <- n
@ -1587,6 +1593,9 @@ and specs =
("-bates",
Arg.Int setbates,
" Set the base bates number");
("-bates-pad-to",
Arg.Int setbatespad,
" Pad the bates number with leading zeroes to width");
("-font",
Arg.String setfont,
" Set the font");
@ -3508,7 +3517,7 @@ let go () =
write_pdf false
(Cpdf.addtexts
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.orientation args.relative_to_cropbox args.opacity
args.justification args.midline args.topline filename pdf)

View File

@ -1,4 +1,5 @@
%FIXME: Document -no-embed-font and encoding switch
%Documents bates enhancements
\documentclass{book}
\usepackage{palatino}
\usepackage{microtype}