Scaffolding for -stretch

This commit is contained in:
John Whitington 2024-09-21 17:35:29 +01:00
parent 368beebaa4
commit b5a71b2504
5 changed files with 27 additions and 4 deletions

View File

@ -15,6 +15,7 @@ New features:
* Add structure information to -typeset, add -typeset-subformat
* -typeset can make PDF/UA documents
* -jpeg, -png and friends can make PDF/UA documents
o -stretch scales without preserving aspect ratio
* = Supported by a grant from NLnet

View File

@ -105,6 +105,7 @@ type op =
| ShiftBoxes
| Scale
| ScaleToFit
| Stretch
| ScaleContents of float
| AttachFile of string list
| RemoveAttachedFiles
@ -257,6 +258,7 @@ let string_of_op = function
| ShiftBoxes -> "ShiftBoxes"
| Scale -> "Scale"
| ScaleToFit -> "ScaleToFit"
| Stretch -> "Stretch"
| ScaleContents _ -> "ScaleContents"
| AttachFile _ -> "AttachFile"
| RemoveAttachedFiles -> "RemoveAttachedFiles"
@ -926,7 +928,7 @@ let banned banlist = function
| Rotateby _ | Upright | VFlip | HFlip | Impose _ | Chop _ | ChopHV _ ->
mem Pdfcrypt.NoAssemble banlist
| TwoUp | TwoUpStack | RemoveBookmarks | AddRectangle | RemoveText|
Draft|Shift|ShiftBoxes | Scale|ScaleToFit|RemoveAttachedFiles|
Draft | Shift | ShiftBoxes | Scale | ScaleToFit|Stretch|RemoveAttachedFiles|
RemoveAnnotations|RemoveFonts|Crop|RemoveCrop|Trim|RemoveTrim|Bleed|RemoveBleed|Art|RemoveArt|
CopyBox|MediaBox|HardBox _|SetTrapped|SetUntrapped|Presentation|
BlackText|BlackLines|BlackFills|CopyFont _|StampOn _|StampUnder _|StampAsXObject _|
@ -1209,6 +1211,10 @@ let setscaletofit s =
setop ScaleToFit ();
args.coord <- s
let setstretch s =
setop Stretch ();
args.coord <- s
let setattachfile s =
match args.op with
| Some (AttachFile t) ->
@ -2044,6 +2050,9 @@ let specs =
("-scale-to-fit",
Arg.String setscaletofit,
" -scale-to-fit \"x y\" scales to page size (x, y)");
("-stretch",
Arg.String setstretch,
" -stretch \"x y\" scales without preserving aspect ratio");
("-scale-contents",
Arg.Float setscalecontents,
" Scale contents by the given factor");
@ -4159,6 +4168,13 @@ let go () =
let xylist = Cpdfcoord.parse_coordinates pdf args.coord
and scale = args.scale in
write_pdf false (Cpdfpage.scale_to_fit_pdf ~fast:args.fast args.position scale xylist args.op pdf range)
| Some Stretch ->
let pdf = get_single_pdf args.op false in
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
warn_prerotate range pdf;
let pdf = if args.prerotate then prerotate range pdf else pdf in
let xylist = Cpdfcoord.parse_coordinates pdf args.coord in
write_pdf false (Cpdfpage.stretch ~fast:args.fast xylist pdf range)
| Some (ScaleContents scale) ->
let pdf = get_single_pdf args.op false in
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in

View File

@ -1,5 +1,4 @@
%Document new drawing stuff for PDF/UA
%Document typesetting for PDF/UA
%Document -stretch
\documentclass{book}
% Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf,
% dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc.

View File

@ -363,6 +363,8 @@ let scale_page_contents ?(fast=false) scale position pdf pnum page =
let scale_contents ?(fast=false) position scale pdf range =
process_pages (scale_page_contents ~fast scale position pdf) pdf range
(* Set media box *)
let set_mediabox xywhlist pdf range =
let crop_page pnum page =
@ -532,6 +534,9 @@ let scale_pdf ?(fast=false) sxsylist pdf range =
in
process_pages scale_page pdf range
let stretch ?(fast=false) xylist pdf range =
pdf
(* Scale to fit page of size x * y *)
let scale_to_fit_pdf ?(fast=false) position input_scale xylist op pdf range =
let scale_page_to_fit pnum page =

View File

@ -79,6 +79,8 @@ page size given by (x, y) and by the [input_scale] (e.g 1.0 = scale to fit, 0.9
= scale to fit leaving a border etc.). [op] is unused. *)
val scale_to_fit_pdf : ?fast:bool -> Cpdfposition.position -> float -> (float * float) list -> 'a -> Pdf.t -> int list -> Pdf.t
val stretch : ?fast:bool -> (float * float) list -> Pdf.t -> int list -> Pdf.t
(** {2 Stamping} *)
(** [combine_pages fast under over scaletofit swap equalize] combines the page