Skip to content

Commit

Permalink
Merge pull request #98 from dheeraj135/fillprint_bug_fix
Browse files Browse the repository at this point in the history
pdftopdf: Set orientation for crop-to-fit and fill
  • Loading branch information
tillkamppeter authored Mar 7, 2019
2 parents f0fc1ce + 5af73c2 commit 0af3245
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions filter/pdftopdf/pdftopdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ void getParameters(ppd_file_t *ppd,int num_options,cups_option_t *options,Proces
static const Rotation ipp2rot[4]={ROT_0, ROT_90, ROT_270, ROT_180};
param.orientation=ipp2rot[ipprot-3];
}
} else {
param.noOrientation = true;
}

ppd_size_t *pagesize;
Expand Down
6 changes: 6 additions & 0 deletions filter/pdftopdf/pdftopdf_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters &param) // {{

if(param.fillprint||param.cropfit){
fprintf(stderr,"[DEBUG]: Cropping input pdf and Enabling fitplot.\n");
if(param.noOrientation&&pages.size())
{
bool land = pages[0]->is_landscape(param.orientation);
if(land)
param.orientation = param.normal_landscape;
}
for(int i=0;i<(int)pages.size();i++)
{
std::shared_ptr<PDFTOPDF_PageHandle> page = pages[i];
Expand Down
3 changes: 3 additions & 0 deletions filter/pdftopdf/pdftopdf_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ProcessingParameters()
fitplot(false),
fillprint(false), //print-scaling = fill
cropfit(false),
noOrientation(false),
orientation(ROT_0),normal_landscape(ROT_270),
paper_is_landscape(false),
duplex(false),
Expand Down Expand Up @@ -58,6 +59,7 @@ ProcessingParameters()
bool fitplot;
bool fillprint; //print-scaling = fill
bool cropfit; // -o crop-to-fit
bool noOrientation;
PageRect page;
Rotation orientation,normal_landscape; // normal_landscape (i.e. default direction) is e.g. needed for number-up=2
bool paper_is_landscape;
Expand Down Expand Up @@ -111,6 +113,7 @@ class PDFTOPDF_PageHandle {
virtual void add_border_rect(const PageRect &rect,BorderType border,float fscale) =0;
// TODO?! add standalone crop(...) method (not only for subpages)
virtual Rotation crop(const PageRect &cropRect,Rotation orientation,Position xpos,Position ypos,bool scale) =0;
virtual bool is_landscape(Rotation orientation) =0 ;
virtual void add_subpage(const std::shared_ptr<PDFTOPDF_PageHandle> &sub,float xpos,float ypos,float scale,const PageRect *crop=NULL) =0;
virtual void mirror() =0;
virtual void rotate(Rotation rot) =0;
Expand Down
16 changes: 16 additions & 0 deletions filter/pdftopdf/qpdf_pdftopdf_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,22 @@ Rotation QPDF_PDFTOPDF_PageHandle::crop(const PageRect &cropRect,Rotation orient
return getRotate(page);
}

bool QPDF_PDFTOPDF_PageHandle::is_landscape(Rotation orientation)
{
page.assertInitialized();
if(orientation==ROT_0||orientation==ROT_180)
page.replaceOrRemoveKey("/Rotate",makeRotate(ROT_90));
else
page.replaceOrRemoveKey("/Rotate",makeRotate(ROT_0));

PageRect currpage= getBoxAsRect(getTrimBox(page));
double width = currpage.right-currpage.left;
double height = currpage.top-currpage.bottom;
if(width>height)
return true;
return false;
}

// TODO: better cropping
// TODO: test/fix with qsub rotation
void QPDF_PDFTOPDF_PageHandle::add_subpage(const std::shared_ptr<PDFTOPDF_PageHandle> &sub,float xpos,float ypos,float scale,const PageRect *crop) // {{{
Expand Down
1 change: 1 addition & 0 deletions filter/pdftopdf/qpdf_pdftopdf_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class QPDF_PDFTOPDF_PageHandle : public PDFTOPDF_PageHandle {
virtual void rotate(Rotation rot);
virtual void add_label(const PageRect &rect, const std::string label);
virtual Rotation crop(const PageRect &cropRect,Rotation orientation,Position xpos,Position ypos,bool scale);
virtual bool is_landscape(Rotation orientation);
void debug(const PageRect &rect,float xpos,float ypos);
private:
bool isExisting() const;
Expand Down

0 comments on commit 0af3245

Please sign in to comment.