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 * Add structure information to -typeset, add -typeset-subformat
* -typeset can make PDF/UA documents * -typeset can make PDF/UA documents
* -jpeg, -png and friends 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 * = Supported by a grant from NLnet

View File

@ -105,6 +105,7 @@ type op =
| ShiftBoxes | ShiftBoxes
| Scale | Scale
| ScaleToFit | ScaleToFit
| Stretch
| ScaleContents of float | ScaleContents of float
| AttachFile of string list | AttachFile of string list
| RemoveAttachedFiles | RemoveAttachedFiles
@ -257,6 +258,7 @@ let string_of_op = function
| ShiftBoxes -> "ShiftBoxes" | ShiftBoxes -> "ShiftBoxes"
| Scale -> "Scale" | Scale -> "Scale"
| ScaleToFit -> "ScaleToFit" | ScaleToFit -> "ScaleToFit"
| Stretch -> "Stretch"
| ScaleContents _ -> "ScaleContents" | ScaleContents _ -> "ScaleContents"
| AttachFile _ -> "AttachFile" | AttachFile _ -> "AttachFile"
| RemoveAttachedFiles -> "RemoveAttachedFiles" | RemoveAttachedFiles -> "RemoveAttachedFiles"
@ -926,7 +928,7 @@ let banned banlist = function
| Rotateby _ | Upright | VFlip | HFlip | Impose _ | Chop _ | ChopHV _ -> | Rotateby _ | Upright | VFlip | HFlip | Impose _ | Chop _ | ChopHV _ ->
mem Pdfcrypt.NoAssemble banlist mem Pdfcrypt.NoAssemble banlist
| TwoUp | TwoUpStack | RemoveBookmarks | AddRectangle | RemoveText| | 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| RemoveAnnotations|RemoveFonts|Crop|RemoveCrop|Trim|RemoveTrim|Bleed|RemoveBleed|Art|RemoveArt|
CopyBox|MediaBox|HardBox _|SetTrapped|SetUntrapped|Presentation| CopyBox|MediaBox|HardBox _|SetTrapped|SetUntrapped|Presentation|
BlackText|BlackLines|BlackFills|CopyFont _|StampOn _|StampUnder _|StampAsXObject _| BlackText|BlackLines|BlackFills|CopyFont _|StampOn _|StampUnder _|StampAsXObject _|
@ -1209,6 +1211,10 @@ let setscaletofit s =
setop ScaleToFit (); setop ScaleToFit ();
args.coord <- s args.coord <- s
let setstretch s =
setop Stretch ();
args.coord <- s
let setattachfile s = let setattachfile s =
match args.op with match args.op with
| Some (AttachFile t) -> | Some (AttachFile t) ->
@ -2044,6 +2050,9 @@ let specs =
("-scale-to-fit", ("-scale-to-fit",
Arg.String setscaletofit, Arg.String setscaletofit,
" -scale-to-fit \"x y\" scales to page size (x, y)"); " -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", ("-scale-contents",
Arg.Float setscalecontents, Arg.Float setscalecontents,
" Scale contents by the given factor"); " Scale contents by the given factor");
@ -4159,6 +4168,13 @@ let go () =
let xylist = Cpdfcoord.parse_coordinates pdf args.coord let xylist = Cpdfcoord.parse_coordinates pdf args.coord
and scale = args.scale in and scale = args.scale in
write_pdf false (Cpdfpage.scale_to_fit_pdf ~fast:args.fast args.position scale xylist args.op pdf range) 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) -> | Some (ScaleContents scale) ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) 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 -stretch
%Document typesetting for PDF/UA
\documentclass{book} \documentclass{book}
% Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf, % Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf,
% dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc. % 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 = let scale_contents ?(fast=false) position scale pdf range =
process_pages (scale_page_contents ~fast scale position pdf) pdf range process_pages (scale_page_contents ~fast scale position pdf) pdf range
(* Set media box *) (* Set media box *)
let set_mediabox xywhlist pdf range = let set_mediabox xywhlist pdf range =
let crop_page pnum page = let crop_page pnum page =
@ -532,6 +534,9 @@ let scale_pdf ?(fast=false) sxsylist pdf range =
in in
process_pages scale_page pdf range process_pages scale_page pdf range
let stretch ?(fast=false) xylist pdf range =
pdf
(* Scale to fit page of size x * y *) (* Scale to fit page of size x * y *)
let scale_to_fit_pdf ?(fast=false) position input_scale xylist op pdf range = let scale_to_fit_pdf ?(fast=false) position input_scale xylist op pdf range =
let scale_page_to_fit pnum page = 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. *) = 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 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} *) (** {2 Stamping} *)
(** [combine_pages fast under over scaletofit swap equalize] combines the page (** [combine_pages fast under over scaletofit swap equalize] combines the page