]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
Setting orientation for crop-to-fit and fill. 98/head
authordh <dhirajyadav135@gmail.com>
Thu, 7 Mar 2019 12:52:10 +0000 (18:22 +0530)
committerdh <dhirajyadav135@gmail.com>
Thu, 7 Mar 2019 12:52:10 +0000 (18:22 +0530)
When the input format is other than pdf(like ps), pdftopdf is unable to set orientation
for crop-to-fit and fill. New function is_landsape is added to get orientation
of input file and orientation is set accordingly.

filter/pdftopdf/pdftopdf.cc
filter/pdftopdf/pdftopdf_processor.cc
filter/pdftopdf/pdftopdf_processor.h
filter/pdftopdf/qpdf_pdftopdf_processor.cc
filter/pdftopdf/qpdf_pdftopdf_processor.h

index bf29ec0f6fc8097993e996ffb2f1cd1714e01f7c..3b9bb3043ec8d8f97989c6c1bea332511cedcc29 100644 (file)
@@ -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;
index 7f62b4f16d45b9aaa2ffd2b59a3a16eb6e43a862..850bddc90084d3577760eed39f1ba26caab8429e 100644 (file)
@@ -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];
index d71fc16af18716848de7353ad854c767dec258af..b1bbac5493597db87266750c6685ab07c62107f1 100644 (file)
@@ -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),
@@ -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;
@@ -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;
index 0761a4240f71112f319e64409808e463ad84286d..7321e427cf7ffec0af1a194cc34fcedc19c104fd 100644 (file)
@@ -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) // {{{
index d1394a8afea78957dcf23c86114da5b0326288eb..f721d93909fb59cb8bc51ae52e15a102b13ed0b7 100644 (file)
@@ -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;