Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for orientation option #2

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/orientation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef ORIENTATION_H
#define ORIENTATION_H

#define ORIENTATION_MAP \
{{"portrait", PrintParameters::Portrait}, \
{"landscape", PrintParameters::Landscape}, \
{"reverse-portrait", PrintParameters::ReversePortrait}, \
{"reverse-landscape", PrintParameters::ReverseLandscape}}

#endif //ORIENTATION_H
5 changes: 5 additions & 0 deletions lib/ppm2pwg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ void make_pwg_hdr(Bytestream& outBts, const PrintParameters& params, bool backsi
outHdr.MediaPosition = media_position_from_name(params.mediaPosition);
}

outHdr.Orientation = (params.orientation == PrintParameters::Portrait ? PwgPgHdr::Portrait
: (params.orientation == PrintParameters::Landscape ? PwgPgHdr::Landscape
: (params.orientation == PrintParameters::ReversePortrait ? PwgPgHdr::ReversePortrait
: (params.orientation == PrintParameters::ReverseLandscape ? PwgPgHdr::ReverseLandscape
: PwgPgHdr::Portrait)))); // portrait means "no rotation" and is a safe default

if(verbose)
{
Expand Down
10 changes: 10 additions & 0 deletions lib/printparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ class PrintParameters
TwoSidedShortEdge
};

enum Orientation
{
Portrait = 0,
Landscape,
ReversePortrait,
ReverseLandscape
};

Orientation orientation = Portrait;

std::string mediaType;
std::string mediaPosition;

Expand Down
6 changes: 5 additions & 1 deletion utils/pdf2printable_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "pdf2printable.h"
#include "argget.h"
#include "orientation.h"

#define HELPTEXT "Options from 'resolution' and onwards only affect raster output formats.\n" \
"Use \"-\" as filename for stdin/stdout."
Expand Down Expand Up @@ -91,6 +92,9 @@ int main(int argc, char** argv)
SwitchArg<bool> antiAliasOpt(params.antiAlias, {"-aa", "--antaialias"}, "Enable antialiasing in rasterization");
SwitchArg<std::string> mediaTypeOpt(params.mediaType, {"-mt", "--media-type"}, "The media type, e.g.: card-stock");
SwitchArg<std::string> mediaPositionOpt(params.mediaPosition, {"-mp", "--media-pos"}, "The media position, e.g.: Top");
EnumSwitchArg<PrintParameters::Orientation> orientationOpt(params.orientation, ORIENTATION_MAP,
{"-o", "--orientation"},
"Orientation, one of: portrait (default), landscape, reverse-portrait, reverse-landscape");

PosArg pdfArg(infile, "PDF-file");
PosArg outArg(outfile, "out-file", true);
Expand All @@ -99,7 +103,7 @@ int main(int argc, char** argv)
&copiesOpt, /*&pageCopiesOpt,*/ &paperSizeOpt, &resolutionOpt,
&resolutionXOpt, &resolutionYOpt, &duplexOpt, &tumbleOpt,
&backXformOpt, &colorModeOpt, &qualityOpt, &antiAliasOpt,
&mediaTypeOpt, &mediaPositionOpt},
&mediaTypeOpt, &mediaPositionOpt, &orientationOpt},
{&pdfArg, &outArg});

bool correctArgs = args.get_args(argc, argv);
Expand Down
6 changes: 5 additions & 1 deletion utils/ppm2pwg_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "ppm2pwg.h"
#include "argget.h"
#include "orientation.h"

inline void ignore_comments(std::istream* in)
{
Expand Down Expand Up @@ -64,14 +65,17 @@ int PPM2PWG_MAIN(int argc, char** argv)
"Quality setting in raster header (draft/normal/high)");
SwitchArg<std::string> mediaTypeOpt(params.mediaType, {"--media-type"}, "The media type, e.g.: card-stock");
SwitchArg<std::string> mediaPositionOpt(params.mediaPosition, {"-mp", "--media-pos"}, "The media position, e.g.: Top");
EnumSwitchArg<PrintParameters::Orientation> orientationOpt(params.orientation, ORIENTATION_MAP,
{"-o", "--orientation"},
"Orientation, one of: portrait (default), landscape, reverse-portrait, reverse-landscape");

PosArg inArg(inFile, "in-file");
PosArg outArg(outFile, "out-file");

ArgGet args({&helpOpt, &verboseOpt, &urfOpt, &pagesOpt, &paperSizeOpt,
&resolutionOpt, &resolutionXOpt, &resolutionYOpt,
&duplexOpt, &tumbleOpt, &backXformOpt, &qualityOpt,
&mediaTypeOpt, &mediaPositionOpt},
&mediaTypeOpt, &mediaPositionOpt, &orientationOpt},
{&inArg, &outArg});

bool correctArgs = args.get_args(argc, argv);
Expand Down