diff --git a/Changes b/Changes index 9f129fc..1a3c010 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ Version 2.2 o -keep-l keeps existing linearization status o -remove-dict-entry te remove the contents of a dictionary entry +o -topline in addition to -midline Version 2.1 (November 2014) diff --git a/cpdf.ml b/cpdf.ml index 28def5f..a1e0f2c 100755 --- a/cpdf.ml +++ b/cpdf.ml @@ -1696,7 +1696,8 @@ let unescape_string s = let addtexts metrics linewidth outline fast fontname font bates colour position linespacing - fontsize underneath text pages orientation cropbox opacity justification midline filename pdf + fontsize underneath text pages orientation cropbox opacity justification + midline topline filename pdf = (*flprint "addtexts:\n"; iter (Printf.printf "%C ") (explode text); @@ -1749,6 +1750,18 @@ let | _ -> ops_baseline_adjustment := 0. end + else + if topline then + begin match font with + | Some font -> + 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 diff --git a/cpdf.mli b/cpdf.mli index 8593b6e..9b906a5 100644 --- a/cpdf.mli +++ b/cpdf.mli @@ -292,7 +292,7 @@ val calculate_position : (** Call [add_texts metrics linewidth outline fast fontname font bates colour position linespacing fontsize underneath text pages orientation -relative_to_cropbox midline_adjust filename pdf]. For details see cpdfmanual.pdf *) +relative_to_cropbox midline_adjust topline filename pdf]. For details see cpdfmanual.pdf *) val addtexts : bool -> (*metrics*) float -> (*linewidth*) @@ -313,6 +313,7 @@ val addtexts : float ->(*opacity*) justification ->(*justification*) bool ->(*midline adjust?*) + bool ->(*topline adjust?*) string ->(*filename*) Pdf.t ->(*pdf*) Pdf.t diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 3453e2c..42970f9 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1,9 +1,9 @@ (* cpdf command line tools *) -let demo = false +let demo = true let noncomp = false let major_version = 2 let minor_version = 2 -let version_date = "(build of 7th January 2015)" +let version_date = "(build of 20th January 2015)" open Pdfutil open Pdfio @@ -316,6 +316,7 @@ type args = mutable underneath : bool; mutable linespacing : float; mutable midline : bool; + mutable topline : bool; mutable justification : Cpdf.justification; mutable bates : int; mutable prerotate : bool; @@ -394,6 +395,7 @@ let args = underneath = false; linespacing = 1.; midline = false; + topline = false; justification = Cpdf.LeftJustify; bates = 0; prerotate = false; @@ -472,6 +474,7 @@ let reset_arguments () = args.underneath <- false; args.linespacing <- 1.; args.midline <- false; + args.topline <- false; args.justification <- Cpdf.LeftJustify; args.bates <- 0; args.prerotate <- false; @@ -1127,6 +1130,9 @@ let setlinespacing f = let setmidline () = args.midline <- true +let settopline () = + args.topline <- true + let setscaletofitscale f = args.scale <- f @@ -1640,6 +1646,9 @@ and specs = ("-midline", Arg.Unit setmidline, " Adjust text to midline rather than baseline"); + ("-topline", + Arg.Unit settopline, + " Adjust text to topline rather than baseline"); ("-relative-to-cropbox", Arg.Unit setrelativetocropbox, " Add text relative to Crop Box not Media Box"); @@ -3458,7 +3467,7 @@ let go () = false args.linewidth args.outline args.fast args.fontname font args.bates args.color args.position args.linespacing args.fontsize args.underneath text range args.orientation args.relative_to_cropbox args.opacity - args.justification args.midline filename pdf) + args.justification args.midline args.topline filename pdf) | Some RemoveText -> let pdf = get_single_pdf args.op false in let range = parse_pagespec pdf (get_pagespec ()) in