This commit is contained in:
John Whitington 2023-05-01 14:39:42 +01:00
parent 2f0574fdc5
commit f481824d1f
3 changed files with 58 additions and 9 deletions

View File

@ -2056,9 +2056,32 @@ let addsopacity f =
let addtext s =
let font = match args.font with StandardFont s -> s | _ -> error "-text: not a standard font" in
addop (Cpdfdraw.Font (font, args.fontsize));
addop (Cpdfdraw.SetLeading (args.fontsize *. 1.2));
addop (Cpdfdraw.Text s)
let addleading f =
addop (Cpdfdraw.Leading f)
let addbt () =
addop Cpdfdraw.BT
let addet () =
addop Cpdfdraw.ET
let addcharspace f =
addop (Cpdfdraw.CharSpace f)
let addwordspace f =
addop (Cpdfdraw.WordSpace f)
let addtextscale f =
addop (Cpdfdraw.TextScale f)
let addrendermode i =
addop (Cpdfdraw.RenderMode i)
let addrise f =
addop (Cpdfdraw.Rise f)
let addurl s =
addop (Cpdfdraw.URL s)
@ -2066,7 +2089,7 @@ let addendurl () =
addop Cpdfdraw.EndURL
let addleading f =
addop (Cpdfdraw.SetLeading f)
addop (Cpdfdraw.Leading f)
let addnewline () =
addop Cpdfdraw.Newline
@ -2908,10 +2931,17 @@ and specs =
("-newpage", Arg.Unit addnewpage, " Move to a fresh page");
("-opacity", Arg.Float addopacity, " Set opacity");
("-sopacity", Arg.Float addsopacity, " Set stroke opacity");
("-bt", Arg.Unit addbt, " Begin text");
("-et", Arg.Unit addet, " End text");
("-text", Arg.String addtext, " Draw text and move position. ");
("-url", Arg.String addurl, " Begin URL");
("-endurl", Arg.Unit addendurl, " End URL");
("-leading", Arg.Float addleading, " Set leading");
("-charspace", Arg.Float addcharspace, " Set character spacing");
("-wordspace", Arg.Float addwordspace, " Set word space");
("-textscale", Arg.Float addtextscale, " Set text scale");
("-rendermode", Arg.Int addrendermode, " Set text rendering mode");
("-rise", Arg.Float addrise, " Set text rise");
("-nl", Arg.Unit addnewline, " New line");
(* Getting information before or whilst drawing *)
(*("-textwidth", ...., "Get width of line of text");*)

View File

@ -40,9 +40,16 @@ type drawops =
| Opacity of float
| SOpacity of float
| Font of Pdftext.standard_font * float
| BT
| ET
| Text of string
| Newline
| SetLeading of float
| Leading of float
| CharSpace of float
| WordSpace of float
| TextScale of float
| RenderMode of int
| Rise of float
| URL of string
| EndURL
@ -132,15 +139,20 @@ let rec ops_of_drawop pdf = function
| Font (s, f) ->
let n = fresh_font_name pdf (Pdftext.StandardFont (s, Pdftext.WinAnsiEncoding)) in
[Pdfops.Op_Tf (n, f)]
| BT -> [Pdfops.Op_BT]
| ET -> [Pdfops.Op_ET]
| Text s ->
let charcodes =
implode (map char_of_int (option_map (Pdftext.charcode_extractor_of_font_real !current_font) (Pdftext.codepoints_of_utf8 s)))
in
[Pdfops.Op_BT; Pdfops.Op_Tj charcodes; Pdfops.Op_ET]
| SetLeading f ->
[Pdfops.Op_TL f]
| Newline ->
[Pdfops.Op_T']
[Pdfops.Op_Tj charcodes]
| Leading f -> [Pdfops.Op_TL f]
| CharSpace f -> [Pdfops.Op_Tc f]
| WordSpace f -> [Pdfops.Op_Tw f]
| TextScale f -> [Pdfops.Op_Tz f]
| RenderMode i -> [Pdfops.Op_Tr i]
| Rise f -> [Pdfops.Op_Ts f]
| Newline -> [Pdfops.Op_T']
and ops_of_drawops pdf drawops =
flatten (map (ops_of_drawop pdf) drawops)

View File

@ -38,9 +38,16 @@ type drawops =
| Opacity of float
| SOpacity of float
| Font of Pdftext.standard_font * float
| BT
| ET
| Text of string
| Newline
| SetLeading of float
| Leading of float
| CharSpace of float
| WordSpace of float
| TextScale of float
| RenderMode of int
| Rise of float
| URL of string
| EndURL