1 #ifndef NUP_H_ 2 #define NUP_H_ 3 4 #include "pptypes.h" 5 #include <utility> 6 7 // you have to provide this 8 struct NupParameters { NupParametersNupParameters9 NupParameters() 10 : nupX(1),nupY(1), 11 width(NAN),height(NAN), 12 landscape(false), 13 first(X), 14 xstart(LEFT),ystart(TOP), 15 xalign(CENTER),yalign(CENTER) 16 {} 17 18 // --- "calculated" parameters --- 19 int nupX,nupY; 20 float width,height; 21 bool landscape; // post-rotate! 22 23 // --- other settings --- 24 // ordering 25 Axis first; 26 Position xstart,ystart; 27 28 Position xalign,yalign; 29 30 static bool possible(int nup); // TODO? float in_ratio,float out_ratio 31 static void preset(int nup,NupParameters &ret); 32 static float calculate(int nup, float in_ratio, float out_ratio,NupParameters &ret); // returns "quality", 1 is best 33 34 void dump() const; 35 }; 36 37 // you get this 38 struct NupPageEdit { 39 // required transformation: first translate, then scale 40 float xpos,ypos; // TODO: already given by sub.left,sub.bottom [but for rotation?] 41 float scale; // uniform 42 43 // ? "landscape" e.g. to rotate labels 44 45 // for border, clip, ... 46 // also stores in_width/in_height, unscaled! 47 // everything in "outer"-page coordinates 48 PageRect sub; 49 50 void dump() const; 51 }; 52 53 /* 54 This class does the number-up calculation. Example: 55 56 NupParameters param; 57 param.xyz=...; // fill it with your data! 58 59 NupState nup(param); 60 NupPageEdit edit; 61 for (auto page : your_pages) { 62 bool newPage=nup.nextPage(page.w,page.h,edit); // w,h from input page 63 // create newPage, if required; then place current page as specified in edit 64 } 65 */ 66 class NupState { 67 public: 68 NupState(const NupParameters ¶m); 69 70 void reset(); 71 72 // will overwrite ret with the new parameters 73 // returns true, if a new output page should be started first 74 bool nextPage(float in_width,float in_height,NupPageEdit &ret); 75 76 private: 77 std::pair<int,int> convert_order(int subpage) const; 78 void calculate_edit(int subx,int suby,NupPageEdit &ret) const; 79 private: 80 NupParameters param; 81 82 int in_pages,out_pages; 83 int nup; // max. per page (==nupX*nupY) 84 int subpage; // on the current output-page 85 }; 86 87 // TODO? elsewhere 88 // parsing functions for cups parameters (will not calculate nupX,nupY!) 89 bool parseNupLayout(const char *val,NupParameters &ret); // lrtb, btlr, ... 90 91 #endif 92