#include <stddef.h>
#include <vector>
-class _cfPDFToPDFIntervalSet {
+class _cfPDFToPDFIntervalSet
+{
typedef int key_t; // TODO?! template <typename T>
typedef std::pair<key_t, key_t> value_t;
typedef std::vector<value_t> data_t;
data_t data;
};
-#endif
+#endif // !_CUPS_FILTERS_PDFTOPDF_INTERVALSET_H_
#include <limits>
#include <algorithm>
-const _cfPDFToPDFIntervalSet::key_t _cfPDFToPDFIntervalSet::npos=std::numeric_limits<_cfPDFToPDFIntervalSet::key_t>::max();
+const _cfPDFToPDFIntervalSet::key_t _cfPDFToPDFIntervalSet::npos =
+ std::numeric_limits<_cfPDFToPDFIntervalSet::key_t>::max();
-void _cfPDFToPDFIntervalSet::clear() // {{{
+void
+_cfPDFToPDFIntervalSet::clear() // {{{
{
data.clear();
}
// }}}
-void _cfPDFToPDFIntervalSet::add(key_t start,key_t end) // {{{
+void
+_cfPDFToPDFIntervalSet::add(key_t start,
+ key_t end) // {{{
{
- if (start<end) {
- data.push_back(std::make_pair(start,end));
- }
+ if (start < end)
+ data.push_back(std::make_pair(start, end));
}
// }}}
-void _cfPDFToPDFIntervalSet::finish() // {{{
+void
+_cfPDFToPDFIntervalSet::finish() // {{{
{
- data_t::iterator it=data.begin(),end=data.end(),pos=it;
- if (it==end) {
+ data_t::iterator it = data.begin(),
+ end = data.end(),
+ pos = it;
+ if (it == end)
return;
- }
- std::sort(it,end);
+ std::sort(it, end);
- while (1) {
- ++it;
- if (it==end) {
- ++pos;
+ while (1)
+ {
+ ++ it;
+ if (it == end)
+ {
+ ++ pos;
break;
}
- if (pos->second>=it->first) {
- pos->second=it->second;
- } else {
- ++pos;
- if (pos!=it) {
- *pos=*it;
- }
+ if (pos->second >= it->first)
+ pos->second = it->second;
+ else
+ {
+ ++ pos;
+ if (pos != it)
+ *pos = *it;
}
}
- data.erase(pos,data.end());
+ data.erase(pos, data.end());
}
// }}}
-bool _cfPDFToPDFIntervalSet::contains(key_t val) const // {{{
+bool
+_cfPDFToPDFIntervalSet::contains(key_t val) const // {{{
{
- data_t::const_iterator it=std::upper_bound(data.begin(),data.end(),std::make_pair(val,npos));
- if (it==data.begin()) {
+ data_t::const_iterator it =
+ std::upper_bound(data.begin(), data.end(), std::make_pair(val, npos));
+ if (it == data.begin())
return false;
- }
- --it;
- return (val<it->second);
+ -- it;
+ return (val < it->second);
}
// }}}
-_cfPDFToPDFIntervalSet::key_t _cfPDFToPDFIntervalSet::next(key_t val) const // {{{
+_cfPDFToPDFIntervalSet::key_t
+_cfPDFToPDFIntervalSet::next(key_t val) const // {{{
{
- val++;
- data_t::const_iterator it=std::upper_bound(data.begin(),data.end(),std::make_pair(val,npos));
- if (it==data.begin()) {
- if (it==data.end()) { // empty
- return npos;
- }
- return it->first;
+ val ++;
+ data_t::const_iterator it =
+ std::upper_bound(data.begin(), data.end(), std::make_pair(val, npos));
+ if (it == data.begin()) {
+ if (it == data.end()) // empty
+ return (npos);
+ return (it->first);
}
- --it;
- if (val<it->second) {
- return val;
- }
- ++it;
- if (it==data.end()) {
+ -- it;
+ if (val < it->second)
+ return (val);
+ ++ it;
+ if (it == data.end())
return npos;
- }
- return it->first;
+ return (it->first);
}
// }}}
-bool _cfPDFToPDFIntervalSet::intersect(const value_t &a,const value_t &b) const // {{{
+bool
+_cfPDFToPDFIntervalSet::intersect(const value_t &a,
+ const value_t &b) const // {{{
{
- return ((a.first>=b.first) && (a.first<b.second)) ||
- ((b.first>=a.first) && (b.first<a.second));
+ return (((a.first >= b.first) && (a.first < b.second)) ||
+ ((b.first >= a.first) && (b.first < a.second)));
}
// }}}
-void _cfPDFToPDFIntervalSet::unite(value_t &aret,const value_t &b) const // {{{
+void
+_cfPDFToPDFIntervalSet::unite(value_t &aret,
+ const value_t &b) const // {{{
{
- DEBUG_assert(intersect(aret,b));
- if (b.first<aret.first) {
- aret.first=b.first;
- }
- if (b.second>aret.second) {
- aret.second=b.second;
- }
+ DEBUG_assert(intersect(aret, b));
+ if (b.first < aret.first)
+ aret.first = b.first;
+ if (b.second > aret.second)
+ aret.second = b.second;
}
// }}}
-void _cfPDFToPDFIntervalSet::dump(pdftopdf_doc_t *doc) const // {{{
+void
+_cfPDFToPDFIntervalSet::dump(pdftopdf_doc_t *doc) const // {{{
{
- int len=data.size();
- if (len==0) {
+ int len = data.size();
+ if (len == 0) {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: (empty)");
return;
}
- len--;
- for (int iA=0;iA<len;iA++) {
+ len --;
+ for (int iA = 0; iA < len; iA ++) {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: [%d,%d)",
data[iA].first, data[iA].second);
}
- if (data[len].second==npos) {
+ if (data[len].second == npos) {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: [%d,inf)",
data[len].first);
#include <utility>
// you have to provide this
-struct _cfPDFToPDFNupParameters {
+struct _cfPDFToPDFNupParameters
+{
_cfPDFToPDFNupParameters()
: nupX(1), nupY(1),
width(NAN), height(NAN),
static bool possible(int nup); // TODO? float in_ratio, float out_ratio
static void preset(int nup, _cfPDFToPDFNupParameters &ret);
static float calculate(int nup, float in_ratio, float out_ratio,
- _cfPDFToPDFNupParameters &ret); // returns "quality", 1 is best
+ _cfPDFToPDFNupParameters &ret); // returns "quality",
+ // 1 is best
void dump(pdftopdf_doc_t *doc) const;
};
// you get this
-struct _cfPDFToPDFNupPageEdit {
+struct _cfPDFToPDFNupPageEdit
+{
// required transformation: first translate, then scale
float xpos, ypos; // TODO: already given by sub.left, sub.bottom
// [but for rotation?]
}
*/
-class _cfPDFToPDFNupState {
+class _cfPDFToPDFNupState
+{
public:
_cfPDFToPDFNupState(const _cfPDFToPDFNupParameters ¶m);
// TODO? elsewhere
// parsing functions for cups parameters (will not calculate nupX, nupY!)
-bool _cfPDFToPDFParseNupLayout(const char *val, _cfPDFToPDFNupParameters &ret); // lrtb, btlr, ...
+bool _cfPDFToPDFParseNupLayout(const char *val, _cfPDFToPDFNupParameters &ret);
+ // lrtb, btlr, ...
-#endif
+#endif // !_CUPS_FILTERS_PDFTOPDF_NUP_H_
#include <string.h>
#include <utility>
-void _cfPDFToPDFNupParameters::dump(pdftopdf_doc_t *doc) const // {{{
+void
+_cfPDFToPDFNupParameters::dump(pdftopdf_doc_t *doc) const // {{{
{
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: NupX: %d, NupY: %d, "
"width: %f, height: %f",
- nupX,nupY,
- width,height);
+ nupX, nupY,
+ width, height);
- int opos=-1,fpos=-1,spos=-1;
- if (xstart==pdftopdf_position_e::LEFT) { // or Bottom
- fpos=0;
- } else if (xstart==pdftopdf_position_e::RIGHT) { // or Top
- fpos=1;
- }
- if (ystart==pdftopdf_position_e::LEFT) { // or Bottom
- spos=0;
- } else if (ystart==pdftopdf_position_e::RIGHT) { // or Top
- spos=1;
- }
- if (first==pdftopdf_axis_e::X) {
+ int opos = -1,
+ fpos = -1,
+ spos = -1;
+
+ if (xstart == pdftopdf_position_e::LEFT) // or Bottom
+ fpos = 0;
+ else if (xstart == pdftopdf_position_e::RIGHT) // or Top
+ fpos = 1;
+ if (ystart == pdftopdf_position_e::LEFT) // or Bottom
+ spos = 0;
+ else if (ystart == pdftopdf_position_e::RIGHT) // or Top
+ spos = 1;
+ if (first == pdftopdf_axis_e::X)
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: First Axis: X");
- opos=0;
- } else if (first==pdftopdf_axis_e::Y) {
+ opos = 0;
+ }
+ else if (first == pdftopdf_axis_e::Y)
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: First Axis: Y");
- opos=2;
- std::swap(fpos,spos);
+ opos = 2;
+ std::swap(fpos, spos);
}
- if ( (opos==-1)||(fpos==-1)||(spos==-1) ) {
+ if ((opos == -1) || (fpos == -1) || (spos == -1))
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: Bad Spec: %d; start: %d, %d",
- first,xstart,ystart);
- } else {
- static const char *order[4]={"lr","rl","bt","tb"};
+ first, xstart, ystart);
+ }
+ else
+ {
+ static const char *order[4] = {"lr", "rl", "bt", "tb"};
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: Order: %s%s",
- order[opos+fpos],order[(opos+2)%4+spos]);
+ order[opos + fpos],
+ order[(opos + 2) % 4 + spos]);
}
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: Alignment:");
- _cfPDFToPDFPositionDump(xalign,pdftopdf_axis_e::X,doc);
- _cfPDFToPDFPositionDump(yalign,pdftopdf_axis_e::Y,doc);
+ _cfPDFToPDFPositionDump(xalign, pdftopdf_axis_e::X,doc);
+ _cfPDFToPDFPositionDump(yalign, pdftopdf_axis_e::Y,doc);
}
// }}}
-bool _cfPDFToPDFNupParameters::possible(int nup) // {{{
+bool
+_cfPDFToPDFNupParameters::possible(int nup) // {{{
{
// 1 2 3 4 6 8 9 10 12 15 16
- return (nup>=1)&&(nup<=16)&&
- ( (nup!=5)&&(nup!=7)&&(nup!=11)&&(nup!=13)&&(nup!=14) );
+ return ((nup >= 1) && (nup <= 16) &&
+ ((nup != 5) && (nup != 7) && (nup != 11) && (nup != 13) &&
+ (nup != 14)));
}
// }}}
-void _cfPDFToPDFNupParameters::preset(int nup,_cfPDFToPDFNupParameters &ret) // {{{
+void
+_cfPDFToPDFNupParameters::preset(int nup,
+ _cfPDFToPDFNupParameters &ret) // {{{
{
- switch (nup) {
- case 1:
- ret.nupX=1;
- ret.nupY=1;
- break;
- case 2:
- ret.nupX=2;
- ret.nupY=1;
- ret.landscape=true;
- break;
- case 3:
- ret.nupX=3;
- ret.nupY=1;
- ret.landscape=true;
- break;
- case 4:
- ret.nupX=2;
- ret.nupY=2;
- break;
- case 6:
- ret.nupX=3;
- ret.nupY=2;
- ret.landscape=true;
- break;
- case 8:
- ret.nupX=4;
- ret.nupY=2;
- ret.landscape=true;
- break;
- case 9:
- ret.nupX=3;
- ret.nupY=3;
- break;
- case 10:
- ret.nupX=5;
- ret.nupY=2;
- ret.landscape=true;
- break;
- case 12:
- ret.nupX=3;
- ret.nupY=4;
- break;
- case 15:
- ret.nupX=5;
- ret.nupY=3;
- ret.landscape=true;
- break;
- case 16:
- ret.nupX=4;
- ret.nupY=4;
- break;
+ switch (nup)
+ {
+ case 1:
+ ret.nupX=1;
+ ret.nupY=1;
+ break;
+ case 2:
+ ret.nupX=2;
+ ret.nupY=1;
+ ret.landscape=true;
+ break;
+ case 3:
+ ret.nupX=3;
+ ret.nupY=1;
+ ret.landscape=true;
+ break;
+ case 4:
+ ret.nupX=2;
+ ret.nupY=2;
+ break;
+ case 6:
+ ret.nupX=3;
+ ret.nupY=2;
+ ret.landscape=true;
+ break;
+ case 8:
+ ret.nupX=4;
+ ret.nupY=2;
+ ret.landscape=true;
+ break;
+ case 9:
+ ret.nupX=3;
+ ret.nupY=3;
+ break;
+ case 10:
+ ret.nupX=5;
+ ret.nupY=2;
+ ret.landscape=true;
+ break;
+ case 12:
+ ret.nupX=3;
+ ret.nupY=4;
+ break;
+ case 15:
+ ret.nupX=5;
+ ret.nupY=3;
+ ret.landscape=true;
+ break;
+ case 16:
+ ret.nupX=4;
+ ret.nupY=4;
+ break;
}
}
// }}}
_cfPDFToPDFNupState::_cfPDFToPDFNupState(const _cfPDFToPDFNupParameters ¶m) // {{{
: param(param),
- in_pages(0),out_pages(0),
- nup(param.nupX*param.nupY),
+ in_pages(0), out_pages(0),
+ nup(param.nupX * param.nupY),
subpage(nup)
{
- DEBUG_assert( (param.nupX>0)&&(param.nupY>0) );
+ DEBUG_assert((param.nupX > 0) && (param.nupY > 0));
}
// }}}
-void _cfPDFToPDFNupState::reset() // {{{
+void
+_cfPDFToPDFNupState::reset() // {{{
{
- in_pages=0;
- out_pages=0;
-// nup=param.nupX*param.nupY;
- subpage=nup;
+ in_pages = 0;
+ out_pages = 0;
+// nup = param.nupX * param.nupY;
+ subpage = nup;
}
// }}}
{
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: xpos: %f, ypos: %f, scale: %f",
- xpos,ypos,scale);
+ xpos, ypos, scale);
sub.dump(doc);
}
// }}}
-std::pair<int,int> _cfPDFToPDFNupState::convert_order(int subpage) const // {{{
+std::pair<int,int>
+_cfPDFToPDFNupState::convert_order(int subpage) const // {{{
{
- int subx,suby;
+ int subx, suby;
if (param.first==pdftopdf_axis_e::X) {
- subx=subpage%param.nupX;
- suby=subpage/param.nupX;
+ subx = subpage % param.nupX;
+ suby = subpage / param.nupX;
} else {
- subx=subpage/param.nupY;
- suby=subpage%param.nupY;
+ subx = subpage / param.nupY;
+ suby = subpage % param.nupY;
}
- subx=(param.nupX-1)*(param.xstart+1)/2-param.xstart*subx;
- suby=(param.nupY-1)*(param.ystart+1)/2-param.ystart*suby;
+ subx = (param.nupX - 1) * (param.xstart + 1) / 2 - param.xstart * subx;
+ suby = (param.nupY - 1) * (param.ystart + 1) / 2 - param.ystart * suby;
- return std::make_pair(subx,suby);
+ return (std::make_pair(subx, suby));
}
// }}}
-static inline float lin(pdftopdf_position_e pos,float size) // {{{
+static inline float
+lin(pdftopdf_position_e pos,
+ float size) // {{{
{
- if (pos==-1) return 0;
- else if (pos==0) return size/2;
- else if (pos==1) return size;
- return size*(pos+1)/2;
+ if (pos == -1)
+ return (0);
+ else if (pos == 0)
+ return (size / 2);
+ else if (pos == 1)
+ return (size);
+ return (size * (pos + 1) / 2);
}
// }}}
-void _cfPDFToPDFNupState::calculate_edit(int subx,int suby,_cfPDFToPDFNupPageEdit &ret) const // {{{
+void
+_cfPDFToPDFNupState::calculate_edit(int subx,
+ int suby,
+ _cfPDFToPDFNupPageEdit &ret) const // {{{
{
// dimensions of a "nup cell"
- const float width=param.width/param.nupX,
- height=param.height/param.nupY;
+ const float width = param.width / param.nupX,
+ height = param.height / param.nupY;
// first calculate only for bottom-left corner
- ret.xpos=subx*width;
- ret.ypos=suby*height;
+ ret.xpos = subx * width;
+ ret.ypos = suby * height;
- const float scalex=width/ret.sub.width,
- scaley=height/ret.sub.height;
- float subwidth=ret.sub.width*scaley,
- subheight=ret.sub.height*scalex;
+ const float scalex = width / ret.sub.width,
+ scaley = height / ret.sub.height;
+ float subwidth = ret.sub.width * scaley,
+ subheight = ret.sub.height * scalex;
- // TODO? if ( (!fitPlot)&&(ret.scale>1) ) ret.scale=1.0;
- if (scalex>scaley) {
- ret.scale=scaley;
- subheight=height;
- ret.xpos+=lin(param.xalign,width-subwidth);
- } else {
- ret.scale=scalex;
- subwidth=width;
- ret.ypos+=lin(param.yalign,height-subheight);
+ // TODO? if ((!fitPlot) && (ret.scale > 1)) ret.scale = 1.0;
+ if (scalex > scaley)
+ {
+ ret.scale = scaley;
+ subheight = height;
+ ret.xpos += lin(param.xalign, width-subwidth);
+ }
+ else
+ {
+ ret.scale = scalex;
+ subwidth = width;
+ ret.ypos += lin(param.yalign, height-subheight);
}
- ret.sub.left=ret.xpos;
- ret.sub.bottom=ret.ypos;
- ret.sub.right=ret.sub.left+subwidth;
- ret.sub.top=ret.sub.bottom+subheight;
+ ret.sub.left = ret.xpos;
+ ret.sub.bottom = ret.ypos;
+ ret.sub.right = ret.sub.left + subwidth;
+ ret.sub.top = ret.sub.bottom + subheight;
}
// }}}
-bool _cfPDFToPDFNupState::mext_page(float in_width,float in_height,_cfPDFToPDFNupPageEdit &ret) // {{{
+bool
+_cfPDFToPDFNupState::mext_page(float in_width,
+ float in_height,
+ _cfPDFToPDFNupPageEdit &ret) // {{{
{
- in_pages++;
- subpage++;
- if (subpage>=nup) {
- subpage=0;
- out_pages++;
+ in_pages ++;
+ subpage ++;
+ if (subpage >= nup)
+ {
+ subpage = 0;
+ out_pages ++;
}
- ret.sub.width=in_width;
- ret.sub.height=in_height;
+ ret.sub.width = in_width;
+ ret.sub.height = in_height;
- auto sub=convert_order(subpage);
- calculate_edit(sub.first,sub.second,ret);
+ auto sub = convert_order(subpage);
+ calculate_edit(sub.first, sub.second, ret);
- return (subpage==0);
+ return (subpage == 0);
}
// }}}
-static std::pair<pdftopdf_axis_e,pdftopdf_position_e> parsePosition(char a,char b) // {{{ returns ,CENTER(0) on invalid
+static std::pair<pdftopdf_axis_e, pdftopdf_position_e>
+parsePosition(char a,
+ char b) // {{{ returns ,CENTER(0) on invalid
{
- a|=0x20; // make lowercase
- b|=0x20;
- if ( (a=='l')&&(b=='r') ) {
- return std::make_pair(pdftopdf_axis_e::X,pdftopdf_position_e::LEFT);
- } else if ( (a=='r')&&(b=='l') ) {
- return std::make_pair(pdftopdf_axis_e::X,pdftopdf_position_e::RIGHT);
- } else if ( (a=='t')&&(b=='b') ) {
- return std::make_pair(pdftopdf_axis_e::Y,pdftopdf_position_e::TOP);
- } else if ( (a=='b')&&(b=='t') ) {
- return std::make_pair(pdftopdf_axis_e::Y,pdftopdf_position_e::BOTTOM);
- }
- return std::make_pair(pdftopdf_axis_e::X,pdftopdf_position_e::CENTER);
+ a |= 0x20; // make lowercase
+ b |= 0x20;
+ if ((a == 'l') && (b == 'r'))
+ return (std::make_pair(pdftopdf_axis_e::X, pdftopdf_position_e::LEFT));
+ else if ((a == 'r') && (b == 'l'))
+ return (std::make_pair(pdftopdf_axis_e::X, pdftopdf_position_e::RIGHT));
+ else if ((a == 't') && (b == 'b'))
+ return (std::make_pair(pdftopdf_axis_e::Y, pdftopdf_position_e::TOP));
+ else if ((a == 'b') && (b == 't'))
+ return (std::make_pair(pdftopdf_axis_e::Y, pdftopdf_position_e::BOTTOM));
+ return (std::make_pair(pdftopdf_axis_e::X, pdftopdf_position_e::CENTER));
}
// }}}
-bool _cfPDFToPDFParseNupLayout(const char *val,_cfPDFToPDFNupParameters &ret) // {{{
+bool
+_cfPDFToPDFParseNupLayout(const char *val,
+ _cfPDFToPDFNupParameters &ret) // {{{
{
DEBUG_assert(val);
- auto pos0=parsePosition(val[0],val[1]);
- if (pos0.second==CENTER) {
- return false;
- }
- auto pos1=parsePosition(val[2],val[3]);
- if ( (pos1.second==CENTER)||(pos0.first==pos1.first) ) {
- return false;
- }
+ auto pos0 = parsePosition(val[0], val[1]);
+ if (pos0.second == CENTER)
+ return (false);
+ auto pos1 = parsePosition(val[2], val[3]);
+ if ((pos1.second == CENTER) || (pos0.first == pos1.first))
+ return (false);
- ret.first=pos0.first;
- if (ret.first==pdftopdf_axis_e::X) {
- ret.xstart=pos0.second;
- ret.ystart=pos1.second;
- } else {
- ret.xstart=pos1.second;
- ret.ystart=pos0.second;
+ ret.first = pos0.first;
+ if (ret.first == pdftopdf_axis_e::X)
+ {
+ ret.xstart = pos0.second;
+ ret.ystart = pos1.second;
+ }
+ else
+ {
+ ret.xstart = pos1.second;
+ ret.ystart = pos0.second;
}
- return (val[4]==0); // everything seen?
+ return (val[4] == 0); // everything seen?
}
// }}}
-
function, can be NULL */
} pdftopdf_doc_t;
-#endif
+#endif // !_CUPS_FILTERS_PDFTOPDF_PDFTOPDF_H
struct _cfPDFToPDFProcessingParameters {
_cfPDFToPDFProcessingParameters()
-: job_id(0),num_copies(1),
- user(0),title(0),
- pagesize_requested(false),
- fitplot(false),
- fillprint(false), //print-scaling = fill
- cropfit(false),
- autoprint(false),
- autofit(false),
- fidelity(false),
- no_orientation(false),
- orientation(ROT_0),normal_landscape(ROT_270),
- paper_is_landscape(false),
- duplex(false),
- border(NONE),
- reverse(false),
-
- page_label(),
- even_pages(true),odd_pages(true),
-
- mirror(false),
-
- xpos(CENTER),ypos(CENTER),
-
- collate(false),
- even_duplex(false),
-
- booklet(CF_PDFTOPDF_BOOKLET_OFF),book_signature(-1),
-
- auto_rotate(false),
-
- device_copies(1),
- device_collate(false),
- set_duplex(false),
-
- page_logging(-1)
+: job_id(0),
+ num_copies(1),
+ user(0),
+ title(0),
+ pagesize_requested(false),
+ fitplot(false),
+ fillprint(false), //print-scaling = fill
+ cropfit(false),
+ autoprint(false),
+ autofit(false),
+ fidelity(false),
+ no_orientation(false),
+ orientation(ROT_0),
+ normal_landscape(ROT_270),
+ paper_is_landscape(false),
+ duplex(false),
+ border(NONE),
+ reverse(false),
+
+ page_label(),
+ even_pages(true),
+ odd_pages(true),
+
+ mirror(false),
+
+ xpos(CENTER),
+ ypos(CENTER),
+
+ collate(false),
+ even_duplex(false),
+
+ booklet(CF_PDFTOPDF_BOOKLET_OFF),
+ book_signature(-1),
+
+ auto_rotate(false),
+
+ device_copies(1),
+ device_collate(false),
+ set_duplex(false),
+
+ page_logging(-1)
{
- page.width=612.0; // letter
- page.height=792.0;
- page.top=page.height-36.0;
- page.bottom=36.0;
- page.left=18.0;
- page.right=page.width-18.0;
+ page.width = 612.0; // Letter
+ page.height = 792.0;
+ page.top = page.height - 36.0;
+ page.bottom = 36.0;
+ page.left = 18.0;
+ page.right = page.width - 18.0;
// everything
input_page_ranges.add(1);
bool reverse;
std::string page_label;
- bool even_pages,odd_pages;
+ bool even_pages, odd_pages;
_cfPDFToPDFIntervalSet page_ranges;
_cfPDFToPDFIntervalSet input_page_ranges;
bool mirror;
- pdftopdf_position_e xpos,ypos;
+ pdftopdf_position_e xpos, ypos;
bool collate;
class _cfPDFToPDFPageHandle {
public:
virtual ~_cfPDFToPDFPageHandle() {}
- virtual _cfPDFToPDFPageRect get_rect() const =0;
- // fscale: inverse_scale (from nup, fitplot)
- virtual void add_border_rect(const _cfPDFToPDFPageRect &rect,pdftopdf_border_type_e border,float fscale) =0;
+
+ virtual _cfPDFToPDFPageRect get_rect() const = 0;
+
+ // fscale: inverse_scale (from nup, fitplot)
+
+ virtual void add_border_rect(const _cfPDFToPDFPageRect &rect,
+ pdftopdf_border_type_e border, float fscale) = 0;
+
// TODO?! add standalone crop(...) method (not only for subpages)
- virtual pdftopdf_rotation_e crop(const _cfPDFToPDFPageRect &cropRect,pdftopdf_rotation_e orientation,pdftopdf_rotation_e param_orientation,pdftopdf_position_e xpos,pdftopdf_position_e ypos,bool scale,bool autorotate,pdftopdf_doc_t *doc) =0;
- virtual bool is_landscape(pdftopdf_rotation_e orientation) =0 ;
- virtual void add_subpage(const std::shared_ptr<_cfPDFToPDFPageHandle> &sub,float xpos,float ypos,float scale,const _cfPDFToPDFPageRect *crop=NULL) =0;
- virtual void mirror() =0;
- virtual void rotate(pdftopdf_rotation_e rot) =0;
- virtual void add_label(const _cfPDFToPDFPageRect &rect, const std::string label) =0;
+
+ virtual pdftopdf_rotation_e crop(const _cfPDFToPDFPageRect &cropRect,
+ pdftopdf_rotation_e orientation,
+ pdftopdf_rotation_e param_orientation,
+ pdftopdf_position_e xpos,
+ pdftopdf_position_e ypos,
+ bool scale, bool autorotate,
+ pdftopdf_doc_t *doc) = 0;
+
+ virtual bool is_landscape(pdftopdf_rotation_e orientation) = 0;
+
+ virtual void add_subpage(const std::shared_ptr<_cfPDFToPDFPageHandle> &sub,
+ float xpos, float ypos, float scale,
+ const _cfPDFToPDFPageRect *crop=NULL) = 0;
+
+ virtual void mirror() = 0;
+
+ virtual void rotate(pdftopdf_rotation_e rot) = 0;
+
+ virtual void add_label(const _cfPDFToPDFPageRect &rect,
+ const std::string label) = 0;
};
// TODO: ... error output?
virtual ~_cfPDFToPDFProcessor() {}
// TODO: ... qpdf wants password at load time
- virtual bool load_file(FILE *f,pdftopdf_doc_t *doc,pdftopdf_arg_ownership_e take=CF_PDFTOPDF_WILL_STAY_ALIVE,int flatten_forms=1) =0;
- virtual bool load_filename(const char *name,pdftopdf_doc_t *doc,int flatten_forms=1) =0;
+ virtual bool load_file(FILE *f,pdftopdf_doc_t *doc,
+ pdftopdf_arg_ownership_e take =
+ CF_PDFTOPDF_WILL_STAY_ALIVE,
+ int flatten_forms = 1) = 0;
+
+ virtual bool load_filename(const char *name, pdftopdf_doc_t *doc,
+ int flatten_forms = 1) = 0;
// TODO? virtual bool may_modify/may_print/?
- virtual bool check_print_permissions(pdftopdf_doc_t *doc) =0;
+ virtual bool check_print_permissions(pdftopdf_doc_t *doc) = 0;
- virtual std::vector<std::shared_ptr<_cfPDFToPDFPageHandle>> get_pages(pdftopdf_doc_t *doc) =0; // shared_ptr because of type erasure (deleter)
+ virtual std::vector<std::shared_ptr<_cfPDFToPDFPageHandle>>
+ get_pages(pdftopdf_doc_t *doc) = 0; // shared_ptr because of type
+ // erasure (deleter)
- virtual std::shared_ptr<_cfPDFToPDFPageHandle> new_page(float width,float height,pdftopdf_doc_t *doc) =0;
+ virtual std::shared_ptr<_cfPDFToPDFPageHandle>
+ new_page(float width, float height, pdftopdf_doc_t *doc) = 0;
- virtual void add_page(std::shared_ptr<_cfPDFToPDFPageHandle> page,bool front) =0; // at back/front -- either from get_pages() or new_page()+add_subpage()-calls (or [also allowed]: empty)
+ virtual void add_page(std::shared_ptr<_cfPDFToPDFPageHandle> page,
+ bool front) = 0; // at back/front -- either from
+ // get_pages() or
+ // new_page()+add_subpage()-calls
+ // (or [also allowed]: empty)
- // void remove_page(std::shared_ptr<_cfPDFToPDFPageHandle> ph); // not needed: we construct from scratch, at least conceptually.
+ // void remove_page(std::shared_ptr<_cfPDFToPDFPageHandle> ph);
+ // not needed: we construct from scratch, at least conceptually.
- virtual void multiply(int copies,bool collate) =0;
+ virtual void multiply(int copies, bool collate) = 0;
- virtual void auto_rotate_all(bool dst_lscape,pdftopdf_rotation_e normal_landscape) =0; // TODO elsewhere?!
- virtual void add_cm(const char *defaulticc,const char *outputicc) =0;
+ virtual void auto_rotate_all(bool dst_lscape,
+ pdftopdf_rotation_e normal_landscape) = 0;
+ // TODO elsewhere?!
+ virtual void add_cm(const char *defaulticc, const char *outputicc) = 0;
- virtual void set_comments(const std::vector<std::string> &comments) =0;
+ virtual void set_comments(const std::vector<std::string> &comments) = 0;
- virtual void emit_file(FILE *dst,pdftopdf_doc_t *doc,pdftopdf_arg_ownership_e take=CF_PDFTOPDF_WILL_STAY_ALIVE) =0;
- virtual void emit_filename(const char *name,pdftopdf_doc_t *doc) =0; // NULL -> stdout
+ virtual void emit_file(FILE *dst,pdftopdf_doc_t *doc,
+ pdftopdf_arg_ownership_e take =
+ CF_PDFTOPDF_WILL_STAY_ALIVE) = 0;
+ virtual void emit_filename(const char *name,pdftopdf_doc_t *doc) = 0;
+ // NULL -> stdout
- virtual bool has_acro_form() =0;
+ virtual bool has_acro_form() = 0;
};
class _cfPDFToPDFFactory {
static _cfPDFToPDFProcessor *processor();
};
-//bool _cfPDFToPDFCheckBookletSignature(int signature) { return (signature%4==0); }
-std::vector<int> _cfPDFToPDFBookletShuffle(int numPages,int signature=-1);
+//bool _cfPDFToPDFCheckBookletSignature(int signature)
+// { return (signature%4==0); }
+
+std::vector<int> _cfPDFToPDFBookletShuffle(int numPages, int signature = -1);
// This is all we want:
-bool _cfProcessPDFToPDF(_cfPDFToPDFProcessor &proc,_cfPDFToPDFProcessingParameters ¶m,pdftopdf_doc_t *doc);
+bool _cfProcessPDFToPDF(_cfPDFToPDFProcessor &proc,
+ _cfPDFToPDFProcessingParameters ¶m,
+ pdftopdf_doc_t *doc);
-#endif
+#endif // !_CUPS_FILTERS_PDFTOPDF_PDFTOPDF_PROCESSOR_H
#include "cupsfilters/debug-internal.h"
#include <numeric>
-void BookletMode_dump(pdftopdf_booklet_mode_e bkm,pdftopdf_doc_t *doc) // {{{
+void
+BookletMode_dump(pdftopdf_booklet_mode_e bkm,
+ pdftopdf_doc_t *doc) // {{{
{
- static const char *bstr[3]={"Off","On","Shuffle-Only"};
- if ((bkm<CF_PDFTOPDF_BOOKLET_OFF) || (bkm>CF_PDFTOPDF_BOOKLET_JUST_SHUFFLE)) {
+ static const char *bstr[3] = {"Off", "On", "Shuffle-Only"};
+
+ if ((bkm < CF_PDFTOPDF_BOOKLET_OFF) ||
+ (bkm > CF_PDFTOPDF_BOOKLET_JUST_SHUFFLE))
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPDFToPDF: bookletMode: (bad booklet mode: "
- "%d)", bkm);
- } else {
+ "cfFilterPDFToPDF: Booklet mode: (Bad booklet mode: %d)",
+ bkm);
+ }
+ else
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPDFToPDF: bookletMode: %s", bstr[bkm]);
+ "cfFilterPDFToPDF: Booklet mode: %s",
+ bstr[bkm]);
}
}
// }}}
-bool _cfPDFToPDFProcessingParameters::with_page(int outno) const // {{{
+bool
+_cfPDFToPDFProcessingParameters::with_page(int outno) const // {{{
{
- if (outno%2 == 0) { // 1-based
- if (!even_pages) {
- return false;
- }
- } else if (!odd_pages) {
- return false;
+ if (outno % 2 == 0)
+ { // 1-based
+ if (!even_pages)
+ return (false);
}
- return page_ranges.contains(outno);
+ else if (!odd_pages)
+ return (false);
+ return (page_ranges.contains(outno));
}
// }}}
-bool _cfPDFToPDFProcessingParameters::have_page(int pageno) const
+
+bool
+_cfPDFToPDFProcessingParameters::have_page(int pageno) const
{
- return input_page_ranges.contains(pageno);
+ return (input_page_ranges.contains(pageno));
}
-void _cfPDFToPDFProcessingParameters::dump(pdftopdf_doc_t *doc) const // {{{
+void
+_cfPDFToPDFProcessingParameters::dump(pdftopdf_doc_t *doc) const // {{{
{
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: job_id: %d, num_copies: %d",
- job_id,num_copies);
+ job_id, num_copies);
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: user: %s, title: %s",
- (user)?user:"(null)",(title)?title:"(null)");
+ (user) ? user : "(null)",
+ (title) ? title : "(null)");
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: fitplot: %s",
- (fitplot)?"true":"false");
+ (fitplot) ? "true" : "false");
page.dump(doc);
- _cfPDFToPDFRotationDump(orientation,doc);
+ _cfPDFToPDFRotationDump(orientation, doc);
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: paper_is_landscape: %s",
- (paper_is_landscape)?"true":"false");
+ (paper_is_landscape) ? "true" : "false");
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: duplex: %s",
- (duplex)?"true":"false");
+ (duplex) ? "true" : "false");
- _cfPDFToPDFBorderTypeDump(border,doc);
+ _cfPDFToPDFBorderTypeDump(border, doc);
nup.dump(doc);
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: reverse: %s",
- (reverse)?"true":"false");
+ (reverse) ? "true" : "false");
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: even_pages: %s, odd_pages: %s",
- (even_pages)?"true":"false",
- (odd_pages)?"true":"false");
+ (even_pages) ? "true" : "false",
+ (odd_pages) ? "true" : "false");
- if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
+ if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: input page range:");
input_page_ranges.dump(doc);
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: mirror: %s",
- (mirror)?"true":"false");
+ (mirror) ? "true" : "false");
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: Position:");
- _cfPDFToPDFPositionDump(xpos,pdftopdf_axis_e::X,doc);
- _cfPDFToPDFPositionDump(ypos,pdftopdf_axis_e::Y,doc);
+ _cfPDFToPDFPositionDump(xpos, pdftopdf_axis_e::X,doc);
+ _cfPDFToPDFPositionDump(ypos, pdftopdf_axis_e::Y,doc);
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: collate: %s",
- (collate)?"true":"false");
+ (collate) ? "true" : "false");
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: even_duplex: %s",
- (even_duplex)?"true":"false");
+ (even_duplex) ? "true" : "false");
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: page_label: %s",
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: auto_rotate: %s",
- (auto_rotate)?"true":"false");
+ (auto_rotate) ? "true" : "false");
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: device_copies: %d",
device_copies);
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: device_collate: %s",
- (device_collate)?"true":"false");
+ (device_collate) ? "true" : "false");
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: set_duplex: %s",
- (set_duplex)?"true":"false");
+ (set_duplex) ? "true" : "false");
}
// }}}
-_cfPDFToPDFProcessor *_cfPDFToPDFFactory::processor()
+_cfPDFToPDFProcessor
+*_cfPDFToPDFFactory::processor()
{
return new _cfPDFToPDFQPDFProcessor();
}
+//
// (1-based)
-// 9: [*] [1] [2] [*] [*] [3] [4] [9] [8] [5] [6] [7] -> signature = 12 = 3*4 = ((9+3)/4)*4
-// 1 2 3 4 5 6 7 8 9 10 11 12
-// NOTE: psbook always fills the sig completely (results in completely white pages (4-set), depending on the input)
-
-// empty pages must be added for output values >=numPages
-std::vector<int> _cfPDFToPDFBookletShuffle(int numPages,int signature) // {{{
+// 9: [*] [1] [2] [*] [*] [3] [4] [9] [8] [5] [6] [7]
+// 1 2 3 4 5 6 7 8 9 10 11 12
+//
+// -> signature = 12 = 3*4 = ((9+3)/4)*4
+//
+// NOTE: psbook always fills the sig completely (results in completely
+// white pages (4-set), depending on the input)
+//
+// empty pages must be added for output values >= numPages
+//
+
+std::vector<int>
+_cfPDFToPDFBookletShuffle(int numPages,
+ int signature) // {{{
{
- if (signature<0) {
- signature=(numPages+3)&~0x3;
- }
- DEBUG_assert(signature%4==0);
+ if (signature < 0)
+ signature = (numPages + 3) & ~0x3;
+ DEBUG_assert(signature % 4 == 0);
std::vector<int> ret;
- ret.reserve(numPages+signature-1);
+ ret.reserve(numPages + signature - 1);
- int curpage=0;
- while (curpage<numPages) {
+ int curpage = 0;
+ while (curpage < numPages)
+ {
// as long as pages to be done -- i.e. multiple times the signature
- int firstpage=curpage,
- lastpage=curpage+signature-1;
+ int firstpage = curpage,
+ lastpage = curpage + signature - 1;
// one signature
- while (firstpage<lastpage) {
- ret.push_back(lastpage--);
- ret.push_back(firstpage++);
- ret.push_back(firstpage++);
- ret.push_back(lastpage--);
+ while (firstpage < lastpage)
+ {
+ ret.push_back(lastpage --);
+ ret.push_back(firstpage ++);
+ ret.push_back(firstpage ++);
+ ret.push_back(lastpage --);
}
- curpage+=signature;
+ curpage += signature;
}
- return ret;
+ return (ret);
}
// }}}
-bool _cfProcessPDFToPDF(_cfPDFToPDFProcessor &proc,_cfPDFToPDFProcessingParameters ¶m,pdftopdf_doc_t *doc) // {{{
+bool
+_cfProcessPDFToPDF(_cfPDFToPDFProcessor &proc,
+ _cfPDFToPDFProcessingParameters ¶m,
+ pdftopdf_doc_t *doc) // {{{
{
- if (!proc.check_print_permissions(doc)) {
+ if (!proc.check_print_permissions(doc))
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: Not allowed to print");
return false;
std::swap(param.nup.nupX, param.nup.nupY);
if (param.auto_rotate)
- proc.auto_rotate_all(dst_lscape,param.normal_landscape);
+ proc.auto_rotate_all(dst_lscape, param.normal_landscape);
- std::vector<std::shared_ptr<_cfPDFToPDFPageHandle>> pages=proc.get_pages(doc);
+ std::vector<std::shared_ptr<_cfPDFToPDFPageHandle>> pages =
+ proc.get_pages(doc);
std::vector<std::shared_ptr<_cfPDFToPDFPageHandle>> input_page_range_list;
- for(int i=1;i<=(int)pages.size();i++)
- if(param.have_page(i))
- input_page_range_list.push_back(pages[i-1]);
+ for (int i = 1; i <= (int)pages.size(); i ++)
+ if (param.have_page(i))
+ input_page_range_list.push_back(pages[i - 1]);
- const int numOrigPages=input_page_range_list.size();
+ const int numOrigPages = input_page_range_list.size();
// TODO FIXME? elsewhere
std::vector<int> shuffle;
- if (param.booklet!=CF_PDFTOPDF_BOOKLET_OFF) {
- shuffle=_cfPDFToPDFBookletShuffle(numOrigPages,param.book_signature);
- if (param.booklet==CF_PDFTOPDF_BOOKLET_ON) { // override options
+ if (param.booklet != CF_PDFTOPDF_BOOKLET_OFF)
+ {
+ shuffle = _cfPDFToPDFBookletShuffle(numOrigPages, param.book_signature);
+ if (param.booklet == CF_PDFTOPDF_BOOKLET_ON)
+ { // override options
// We do not "sides=two-sided-short-edge" / DuplexTumble here.
// We assume it done by caller, for example ppdFilterLoadPPD() of libppd
// param.duplex=true;
// param.set_duplex=true;
- _cfPDFToPDFNupParameters::preset(2,param.nup); // TODO?! better
+ _cfPDFToPDFNupParameters::preset(2, param.nup); // TODO?! better
}
- } else { // 0 1 2 3 ...
+ }
+ else
+ { // 0 1 2 3 ...
shuffle.resize(numOrigPages);
- std::iota(shuffle.begin(),shuffle.end(),0);
+ std::iota(shuffle.begin(), shuffle.end(), 0);
}
- const int numPages=std::max(shuffle.size(),input_page_range_list.size());
+ const int numPages=std::max(shuffle.size(), input_page_range_list.size());
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: \"print-scaling\" IPP attribute: %s",
(param.cropfit ? "none" :
"Not defined, should never happen"))))));
- if (param.autoprint || param.autofit) {
+ if (param.autoprint || param.autofit)
+ {
bool margin_defined = true;
bool document_large = false;
- int pw = param.page.right-param.page.left;
- int ph = param.page.top-param.page.bottom;
+ int pw = param.page.right - param.page.left;
+ int ph = param.page.top - param.page.bottom;
if ((param.page.width == pw) && (param.page.height == ph))
margin_defined = false;
orientation = param.normal_landscape;
else
orientation = ROT_0;
- page->crop(param.page, orientation, param.orientation, param.xpos, param.ypos,
+ page->crop(param.page, orientation, param.orientation,
+ param.xpos, param.ypos,
!param.cropfit, param.auto_rotate, doc);
}
if (param.fillprint)
}
std::shared_ptr<_cfPDFToPDFPageHandle> curpage;
- int outputpage=0;
- int outputno=0;
+ int outputpage = 0;
+ int outputno = 0;
if ((param.nup.nupX == 1) && (param.nup.nupY == 1) && !param.fitplot)
{
if ((param.even_duplex || !param.odd_pages) && (outputno & 1)) {
// need to output empty page to not confuse duplex
- proc.add_page(proc.new_page(param.page.width,param.page.height,doc),param.reverse);
+ proc.add_page(proc.new_page(param.page.width,
+ param.page.height, doc), param.reverse);
// Log page in /var/log/cups/page_log
if (param.page_logging == 1)
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_CONTROL,
param.copies_to_be_logged);
}
- proc.multiply(param.num_copies,param.collate);
+ proc.multiply(param.num_copies, param.collate);
- return true;
+ return (true);
}
// }}}
#include <config.h>
#include <stdio.h>
+#include <ctype.h>
#include "cupsfilters/debug-internal.h"
#include <cups/cups.h>
-#if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 6)
-#define HAVE_CUPS_1_7 1
-#endif
-#ifdef HAVE_CUPS_1_7
#include <cups/pwg.h>
-#endif /* HAVE_CUPS_1_7 */
#include <iomanip>
#include <sstream>
#include <memory>
// namespace {}
-static bool optGetInt(const char *name,int num_options,cups_option_t *options,int *ret) // {{{
+static bool
+optGetInt(const char *name,
+ int num_options,
+ cups_option_t *options,
+ int *ret) // {{{
{
DEBUG_assert(ret);
- const char *val=cupsGetOption(name,num_options,options);
- if (val) {
- *ret=atoi(val);
- return true;
+ const char *val = cupsGetOption(name, num_options, options);
+ if (val)
+ {
+ *ret = atoi(val);
+ return (true);
}
- return false;
+ return (false);
}
// }}}
-static bool optGetFloat(const char *name,int num_options,cups_option_t *options,float *ret) // {{{
+static bool
+optGetFloat(const char *name,
+ int num_options,
+ cups_option_t *options,
+ float *ret) // {{{
{
DEBUG_assert(ret);
- const char *val=cupsGetOption(name,num_options,options);
- if (val) {
- *ret=atof(val);
- return true;
+ const char *val = cupsGetOption(name, num_options, options);
+ if (val)
+ {
+ *ret = atof(val);
+ return (true);
}
- return false;
+ return (false);
}
// }}}
-static bool is_false(const char *value) // {{{
+static bool
+is_false(const char *value) // {{{
{
- if (!value) {
- return false;
- }
- return (strcasecmp(value,"no")==0)||
- (strcasecmp(value,"off")==0)||
- (strcasecmp(value,"false")==0);
+ if (!value)
+ return (false);
+ return ((strcasecmp(value, "no") == 0) ||
+ (strcasecmp(value, "off") == 0) ||
+ (strcasecmp(value, "false") == 0));
}
// }}}
-static bool is_true(const char *value) // {{{
+static bool
+is_true(const char *value) // {{{
{
- if (!value) {
- return false;
- }
- return (strcasecmp(value,"yes")==0)||
- (strcasecmp(value,"on")==0)||
- (strcasecmp(value,"true")==0);
+ if (!value)
+ return (false);
+ return ((strcasecmp(value, "yes") == 0) ||
+ (strcasecmp(value, "on") == 0) ||
+ (strcasecmp(value, "true") == 0));
}
// }}}
-static bool parsePosition(const char *value,pdftopdf_position_e &xpos,pdftopdf_position_e &ypos) // {{{
+static bool
+parsePosition(const char *value,
+ pdftopdf_position_e &xpos,
+ pdftopdf_position_e &ypos) // {{{
{
- // ['center','top','left','right','top-left','top-right','bottom','bottom-left','bottom-right']
- xpos=pdftopdf_position_e::CENTER;
- ypos=pdftopdf_position_e::CENTER;
- int next=0;
- if (strcasecmp(value,"center")==0) {
- return true;
- } else if (strncasecmp(value,"top",3)==0) {
- ypos=pdftopdf_position_e::TOP;
- next=3;
- } else if (strncasecmp(value,"bottom",6)==0) {
- ypos=pdftopdf_position_e::BOTTOM;
- next=6;
- }
- if (next) {
- if (value[next]==0) {
- return true;
- } else if (value[next]!='-') {
- return false;
- }
- value+=next+1;
+ // ['center','top','left','right','top-left','top-right','bottom',
+ // 'bottom-left','bottom-right']
+ xpos = pdftopdf_position_e::CENTER;
+ ypos = pdftopdf_position_e::CENTER;
+ int next = 0;
+ if (strcasecmp(value, "center") == 0)
+ return (true);
+ else if (strncasecmp(value, "top", 3) == 0)
+ {
+ ypos = pdftopdf_position_e::TOP;
+ next = 3;
}
- if (strcasecmp(value,"left")==0) {
- xpos=pdftopdf_position_e::LEFT;
- } else if (strcasecmp(value,"right")==0) {
- xpos=pdftopdf_position_e::RIGHT;
- } else {
- return false;
+ else if (strncasecmp(value, "bottom", 6) == 0)
+ {
+ ypos = pdftopdf_position_e::BOTTOM;
+ next = 6;
}
- return true;
+ if (next)
+ {
+ if (value[next] == 0)
+ return (true);
+ else if (value[next] != '-')
+ return (false);
+ value += next + 1;
+ }
+ if (strcasecmp(value, "left") == 0)
+ xpos = pdftopdf_position_e::LEFT;
+ else if (strcasecmp(value, "right") == 0)
+ xpos = pdftopdf_position_e::RIGHT;
+ else
+ return (false);
+ return (true);
}
// }}}
-#include <ctype.h>
-static void parseRanges(const char *range,_cfPDFToPDFIntervalSet &ret) // {{{
+static void
+parseRanges(const char *range, _cfPDFToPDFIntervalSet &ret) // {{{
{
ret.clear();
- if (!range) {
+ if (!range)
+ {
ret.add(1); // everything
ret.finish();
return;
}
- int lower,upper;
- while (*range) {
- if (*range=='-') {
- range++;
- upper=strtol(range,(char **)&range,10);
- if (upper>=2147483647) { // see also cups/encode.c
+ int lower, upper;
+ while (*range)
+ {
+ if (*range == '-')
+ {
+ range ++;
+ upper = strtol(range, (char **)&range, 10);
+ if (upper >= 2147483647) // see also cups/encode.c
ret.add(1);
- } else {
- ret.add(1,upper+1);
- }
- } else {
- lower=strtol(range,(char **)&range,10);
- if (*range=='-') {
- range++;
- if (!isdigit(*range)) {
+ else
+ ret.add(1, upper + 1);
+ }
+ else
+ {
+ lower = strtol(range, (char **)&range, 10);
+ if (*range == '-')
+ {
+ range ++;
+ if (!isdigit(*range))
ret.add(lower);
- } else {
- upper=strtol(range,(char **)&range,10);
- if (upper>=2147483647) {
+ else
+ {
+ upper=strtol(range, (char **)&range, 10);
+ if (upper>=2147483647)
ret.add(lower);
- } else {
- ret.add(lower,upper+1);
- }
+ else
+ ret.add(lower, upper + 1);
}
- } else {
- ret.add(lower,lower+1);
}
+ else
+ ret.add(lower, lower + 1);
}
- if (*range!=',') {
+ if (*range != ',')
break;
- }
range++;
}
ret.finish();
}
// }}}
-static bool _cfPDFToPDFParseBorder(const char *val,pdftopdf_border_type_e &ret) // {{{
+static bool
+_cfPDFToPDFParseBorder(const char *val,
+ pdftopdf_border_type_e &ret) // {{{
{
DEBUG_assert(val);
- if (strcasecmp(val,"none")==0) {
- ret=pdftopdf_border_type_e::NONE;
- } else if (strcasecmp(val,"single")==0) {
- ret=pdftopdf_border_type_e::ONE_THIN;
- } else if (strcasecmp(val,"single-thick")==0) {
- ret=pdftopdf_border_type_e::ONE_THICK;
- } else if (strcasecmp(val,"double")==0) {
- ret=pdftopdf_border_type_e::TWO_THIN;
- } else if (strcasecmp(val,"double-thick")==0) {
- ret=pdftopdf_border_type_e::TWO_THICK;
- } else {
- return false;
- }
- return true;
+ if (strcasecmp(val, "none") == 0)
+ ret = pdftopdf_border_type_e::NONE;
+ else if (strcasecmp(val, "single") == 0)
+ ret = pdftopdf_border_type_e::ONE_THIN;
+ else if (strcasecmp(val, "single-thick") == 0)
+ ret = pdftopdf_border_type_e::ONE_THICK;
+ else if (strcasecmp(val, "double") == 0)
+ ret = pdftopdf_border_type_e::TWO_THIN;
+ else if (strcasecmp(val, "double-thick") == 0)
+ ret = pdftopdf_border_type_e::TWO_THICK;
+ else
+ return (false);
+ return (true);
}
// }}}
-void getParameters(cf_filter_data_t *data,int num_options,cups_option_t *options,_cfPDFToPDFProcessingParameters ¶m,pdftopdf_doc_t *doc) // {{{
+void
+getParameters(cf_filter_data_t *data,
+ int num_options,
+ cups_option_t *options,
+ _cfPDFToPDFProcessingParameters ¶m,
+ pdftopdf_doc_t *doc) // {{{
{
char *final_content_type = data->final_content_type;
ipp_t *printer_attrs = data->printer_attrs;
ipp_t *job_attrs = data->job_attrs;
ipp_attribute_t *attr;
const char *val;
-
- if ((val = cupsGetOption("copies",num_options, options)) != NULL ||
+ int ipprot;
+ int nup;
+ std::string rawlabel;
+ char *classification;
+ std::ostringstream cookedlabel;
+
+
+ if ((val = cupsGetOption("copies", num_options, options)) != NULL ||
(val = cupsGetOption("Copies", num_options, options)) != NULL ||
(val = cupsGetOption("num-copies", num_options, options)) != NULL ||
(val = cupsGetOption("NumCopies", num_options, options)) != NULL)
param.num_copies = copies;
}
- if (param.num_copies==0) {
- param.num_copies=1;
- }
+ if (param.num_copies == 0)
+ param.num_copies = 1;
- if((val = cupsGetOption("ipp-attribute-fidelity",num_options,options))!=NULL) {
- if(!strcasecmp(val,"true")||!strcasecmp(val,"yes") ||
- !strcasecmp(val,"on"))
+ if ((val = cupsGetOption("ipp-attribute-fidelity", num_options, options)) !=
+ NULL)
+ {
+ if (!strcasecmp(val, "true") || !strcasecmp(val, "yes") ||
+ !strcasecmp(val, "on"))
param.fidelity = true;
}
- if((val = cupsGetOption("print-scaling",num_options,options)) != NULL) {
- if(!strcasecmp(val,"auto"))
+ if ((val = cupsGetOption("print-scaling", num_options, options)) != NULL)
+ {
+ if (!strcasecmp(val, "auto"))
param.autoprint = true;
- else if(!strcasecmp(val,"auto-fit"))
+ else if (!strcasecmp(val, "auto-fit"))
param.autofit = true;
- else if(!strcasecmp(val,"fill"))
+ else if (!strcasecmp(val, "fill"))
param.fillprint = true;
- else if(!strcasecmp(val,"fit"))
+ else if (!strcasecmp(val, "fit"))
param.fitplot = true;
else
param.cropfit = true;
}
- else {
- if ((val=cupsGetOption("fitplot",num_options,options)) == NULL) {
- if ((val=cupsGetOption("fit-to-page",num_options,options)) == NULL) {
- val=cupsGetOption("ipp-attribute-fidelity",num_options,options);
+ else
+ {
+ if ((val = cupsGetOption("fitplot", num_options, options)) == NULL)
+ {
+ if ((val = cupsGetOption("fit-to-page", num_options, options)) == NULL)
+ val = cupsGetOption("ipp-attribute-fidelity", num_options, options);
}
- }
- // TODO? pstops checks =="true", pdftops !is_false ... pstops says: fitplot only for PS (i.e. not for PDF, cmp. cgpdftopdf)
- param.fitplot=(val)&&(!is_false(val));
+ // TODO? pstops checks == "true", pdftops !is_false ... pstops says:
+ // fitplot only for PS (i.e. not for PDF, cmp. cgpdftopdf)
+ param.fitplot = (val) && (!is_false(val));
- if((val = cupsGetOption("fill",num_options,options))!=0) {
- if(!strcasecmp(val,"true")||!strcasecmp(val,"yes"))
+ if ((val = cupsGetOption("fill", num_options, options)) != 0)
{
- param.fillprint = true;
+ if (!strcasecmp(val, "true") || !strcasecmp(val, "yes"))
+ param.fillprint = true;
}
- }
- if((val = cupsGetOption("crop-to-fit",num_options,options))!= NULL){
- if(!strcasecmp(val,"true")||!strcasecmp(val,"yes"))
+ if ((val = cupsGetOption("crop-to-fit", num_options, options)) != NULL)
{
- param.cropfit=1;
+ if (!strcasecmp(val, "true") || !strcasecmp(val, "yes"))
+ param.cropfit=1;
}
- }
- if (!param.autoprint && !param.autofit && !param.fitplot &&
- !param.fillprint && !param.cropfit)
- param.autoprint = true;
+ if (!param.autoprint && !param.autofit && !param.fitplot &&
+ !param.fillprint && !param.cropfit)
+ param.autoprint = true;
}
// direction the printer rotates landscape
// (landscape-orientation-requested-preferred: 4: 90 or 5: -90)
if (printer_attrs != NULL &&
- (attr = ippFindAttribute(printer_attrs, "landscape-orientation-requested-preferred", IPP_TAG_ZERO)) != NULL &&
+ (attr = ippFindAttribute(printer_attrs,
+ "landscape-orientation-requested-preferred",
+ IPP_TAG_ZERO)) != NULL &&
ippGetInteger(attr, 0) == 5)
- param.normal_landscape=ROT_270;
+ param.normal_landscape = ROT_270;
else
- param.normal_landscape=ROT_90;
+ param.normal_landscape = ROT_90;
- int ipprot;
- param.orientation=ROT_0;
- if ((val=cupsGetOption("landscape",num_options,options)) != NULL) {
- if (!is_false(val)) {
- param.orientation=param.normal_landscape;
- }
- } else if (optGetInt("orientation-requested",num_options,options,&ipprot)) {
+ param.orientation = ROT_0;
+ if ((val = cupsGetOption("landscape", num_options, options)) != NULL)
+ {
+ if (!is_false(val))
+ param.orientation = param.normal_landscape;
+ }
+ else if (optGetInt("orientation-requested", num_options, options, &ipprot))
+ {
/* IPP orientation values are:
* 3: 0 degrees, 4: 90 degrees, 5: -90 degrees, 6: 180 degrees
*/
- if ((ipprot<3)||(ipprot>6)) {
+ if ((ipprot < 3) || (ipprot > 6))
+ {
if (ipprot && doc->logfunc)
doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
"cfFilterPDFToPDF: Bad value (%d) for "
"orientation-requested, using 0 degrees",
ipprot);
param.no_orientation = true;
- } else {
- static const pdftopdf_rotation_e ipp2rot[4]={ROT_0, ROT_90, ROT_270, ROT_180};
- param.orientation=ipp2rot[ipprot-3];
}
- } else {
- param.no_orientation = true;
+ else
+ {
+ static const pdftopdf_rotation_e
+ ipp2rot[4]={ROT_0, ROT_90, ROT_270, ROT_180};
+ param.orientation = ipp2rot[ipprot - 3];
+ }
}
+ else
+ param.no_orientation = true;
if (printer_attrs != NULL)
param.pagesize_requested =
else
param.page.top = param.page.height - param.page.top;
- param.paper_is_landscape=(param.page.width>param.page.height);
+ param.paper_is_landscape = (param.page.width > param.page.height);
_cfPDFToPDFPageRect tmp; // borders (before rotation)
- optGetFloat("page-top",num_options,options,&tmp.top);
- optGetFloat("page-left",num_options,options,&tmp.left);
- optGetFloat("page-right",num_options,options,&tmp.right);
- optGetFloat("page-bottom",num_options,options,&tmp.bottom);
+ optGetFloat("page-top", num_options, options, &tmp.top);
+ optGetFloat("page-left", num_options, options, &tmp.left);
+ optGetFloat("page-right", num_options, options, &tmp.right);
+ optGetFloat("page-bottom", num_options, options, &tmp.bottom);
if ((val = cupsGetOption("media-top-margin", num_options, options))
!= NULL)
!= NULL)
tmp.bottom = atof(val) * 72.0 / 2540.0;
- if ((param.orientation==ROT_90)||(param.orientation==ROT_270)) { // unrotate page
+ if ((param.orientation == ROT_90) || (param.orientation == ROT_270))
+ { // unrotate page
// NaN stays NaN
- tmp.right=param.page.height-tmp.right;
- tmp.top=param.page.width-tmp.top;
- tmp.rotate_move(param.orientation,param.page.height,param.page.width);
- } else {
- tmp.right=param.page.width-tmp.right;
- tmp.top=param.page.height-tmp.top;
- tmp.rotate_move(param.orientation,param.page.width,param.page.height);
+ tmp.right = param.page.height - tmp.right;
+ tmp.top = param.page.width - tmp.top;
+ tmp.rotate_move(param.orientation, param.page.height, param.page.width);
+ }
+ else
+ {
+ tmp.right = param.page.width - tmp.right;
+ tmp.top = param.page.height - tmp.top;
+ tmp.rotate_move(param.orientation, param.page.width, param.page.height);
}
- param.page.set(tmp); // replace values, where tmp.* != NaN (because tmp needed rotation, param.page not!)
+ param.page.set(tmp); // replace values, where tmp.* != NaN
+ // (because tmp needed rotation, param.page not!)
if ((val = cfIPPAttrEnumValForPrinter(printer_attrs, job_attrs, "sides")) !=
NULL &&
- strncmp(val, "two-sided-", 10) == 0) {
- param.duplex=true;
- } else if (is_true(cupsGetOption("Duplex", num_options, options))) {
- param.duplex=true;
- param.set_duplex=true;
- } else if ((val=cupsGetOption("sides",num_options,options)) != NULL) {
- if ((strcasecmp(val,"two-sided-long-edge")==0)||
- (strcasecmp(val,"two-sided-short-edge")==0)) {
- param.duplex=true;
- param.set_duplex=true;
- } else if (strcasecmp(val,"one-sided")!=0) {
+ strncmp(val, "two-sided-", 10) == 0)
+ param.duplex = true;
+ else if (is_true(cupsGetOption("Duplex", num_options, options)))
+ {
+ param.duplex = true;
+ param.set_duplex = true;
+ }
+ else if ((val = cupsGetOption("sides", num_options, options)) != NULL)
+ {
+ if ((strcasecmp(val, "two-sided-long-edge") == 0) ||
+ (strcasecmp(val, "two-sided-short-edge") == 0))
+ {
+ param.duplex = true;
+ param.set_duplex = true;
+ }
+ else if (strcasecmp(val, "one-sided") != 0)
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToPDF: Unsupported sides value %s, "
- "using sides=one-sided!", val);
+ "cfFilterPDFToPDF: Unsupported sides value %s, using sides=one-sided!",
+ val);
}
}
// default nup is 1
- int nup=1;
- if (optGetInt("number-up",num_options,options,&nup)) {
- if (!_cfPDFToPDFNupParameters::possible(nup)) {
+ nup = 1;
+ if (optGetInt("number-up", num_options, options, &nup))
+ {
+ if (!_cfPDFToPDFNupParameters::possible(nup))
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToPDF: Unsupported number-up value "
- "%d, using number-up=1!", nup);
- nup=1;
+ "cfFilterPDFToPDF: Unsupported number-up value %d, using number-up=1!",
+ nup);
+ nup = 1;
}
-// TODO ; TODO? nup enabled? ... fitplot
-// _cfPDFToPDFNupParameters::calculate(nup,param.nup);
- _cfPDFToPDFNupParameters::preset(nup,param.nup);
+ // TODO ; TODO? nup enabled? ... fitplot
+ // _cfPDFToPDFNupParameters::calculate(nup, param.nup);
+ _cfPDFToPDFNupParameters::preset(nup, param.nup);
}
- if ((val=cupsGetOption("number-up-layout",num_options,options)) != NULL) {
- if (!_cfPDFToPDFParseNupLayout(val,param.nup)) {
+ if ((val = cupsGetOption("number-up-layout", num_options, options)) != NULL)
+ {
+ if (!_cfPDFToPDFParseNupLayout(val, param.nup))
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToPDF: Unsupported number-up-layout "
- "%s, using number-up-layout=lrtb!" ,val);
- param.nup.first=pdftopdf_axis_e::X;
- param.nup.xstart=pdftopdf_position_e::LEFT;
- param.nup.ystart=pdftopdf_position_e::TOP;
+ "cfFilterPDFToPDF: Unsupported number-up-layout %s, using number-up-layout=lrtb!",
+ val);
+ param.nup.first = pdftopdf_axis_e::X;
+ param.nup.xstart = pdftopdf_position_e::LEFT;
+ param.nup.ystart = pdftopdf_position_e::TOP;
}
}
- if ((val=cupsGetOption("page-border",num_options,options)) != NULL) {
- if (!_cfPDFToPDFParseBorder(val,param.border)) {
+ if ((val = cupsGetOption("page-border", num_options, options)) != NULL)
+ {
+ if (!_cfPDFToPDFParseBorder(val, param.border))
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToPDF: Unsupported page-border value "
- "%s, using page-border=none!", val);
- param.border=pdftopdf_border_type_e::NONE;
+ "cfFilterPDFToPDF: Unsupported page-border value %s, using page-border=none!",
+ val);
+ param.border = pdftopdf_border_type_e::NONE;
}
}
else
param.reverse = cfIPPReverseOutput(printer_attrs, job_attrs);
- std::string rawlabel;
- char *classification = getenv("CLASSIFICATION");
+ classification = getenv("CLASSIFICATION");
if (classification)
rawlabel.append (classification);
- if ((val=cupsGetOption("page-label", num_options, options)) != NULL) {
+ if ((val = cupsGetOption("page-label", num_options, options)) != NULL)
+ {
if (!rawlabel.empty())
rawlabel.append (" - ");
- rawlabel.append(cupsGetOption("page-label",num_options,options));
+ rawlabel.append(cupsGetOption("page-label", num_options, options));
}
- std::ostringstream cookedlabel;
for (std::string::iterator it = rawlabel.begin();
it != rawlabel.end ();
- ++it) {
+ ++ it)
+ {
if (*it < 32 || *it > 126)
cookedlabel << "\\" << std::oct << std::setfill('0') << std::setw(3) << (unsigned int) *it;
else
}
param.page_label = cookedlabel.str ();
- if ((val=cupsGetOption("page-set",num_options,options)) != NULL) {
- if (strcasecmp(val,"even")==0) {
- param.odd_pages=false;
- } else if (strcasecmp(val,"odd")==0) {
- param.even_pages=false;
- } else if (strcasecmp(val,"all")!=0) {
+ if ((val = cupsGetOption("page-set", num_options, options)) != NULL)
+ {
+ if (strcasecmp(val, "even") == 0)
+ param.odd_pages = false;
+ else if (strcasecmp(val, "odd") == 0)
+ param.even_pages = false;
+ else if (strcasecmp(val, "all") != 0)
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToPDF: Unsupported page-set value %s, "
- "using page-set=all!", val);
+ "cfFilterPDFToPDF: Unsupported page-set value %s, using page-set=all!",
+ val);
}
}
- if ((val=cupsGetOption("page-ranges",num_options,options)) != NULL) {
- parseRanges(val,param.page_ranges);
- }
+ if ((val = cupsGetOption("page-ranges", num_options, options)) != NULL)
+ parseRanges(val, param.page_ranges);
- if ((val=cupsGetOption("input-page-ranges",num_options,options)) !=NULL){
- parseRanges(val,param.input_page_ranges);
- }
+ if ((val = cupsGetOption("input-page-ranges", num_options, options)) != NULL)
+ parseRanges(val, param.input_page_ranges);
- if((val = cupsGetOption("mirror", num_options, options)) != NULL ||
- (val = cupsGetOption("mirror-print", num_options, options)) != NULL)
- param.mirror=is_true(val);
+ if ((val = cupsGetOption("mirror", num_options, options)) != NULL ||
+ (val = cupsGetOption("mirror-print", num_options, options)) != NULL)
+ param.mirror = is_true(val);
- param.booklet=pdftopdf_booklet_mode_e::CF_PDFTOPDF_BOOKLET_OFF;
- if ((val=cupsGetOption("booklet",num_options,options)) != NULL) {
- if (strcasecmp(val,"shuffle-only")==0) {
- param.booklet=pdftopdf_booklet_mode_e::CF_PDFTOPDF_BOOKLET_JUST_SHUFFLE;
- } else if (is_true(val)) {
- param.booklet=pdftopdf_booklet_mode_e::CF_PDFTOPDF_BOOKLET_ON;
- } else if (!is_false(val)) {
+ param.booklet = pdftopdf_booklet_mode_e::CF_PDFTOPDF_BOOKLET_OFF;
+ if ((val = cupsGetOption("booklet", num_options, options)) != NULL)
+ {
+ if (strcasecmp(val, "shuffle-only") == 0)
+ param.booklet = pdftopdf_booklet_mode_e::CF_PDFTOPDF_BOOKLET_JUST_SHUFFLE;
+ else if (is_true(val))
+ param.booklet = pdftopdf_booklet_mode_e::CF_PDFTOPDF_BOOKLET_ON;
+ else if (!is_false(val))
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToPDF: Unsupported booklet value %s, "
- "using booklet=off!", val);
+ "cfFilterPDFToPDF: Unsupported booklet value %s, using booklet=off!",
+ val);
}
}
- param.book_signature=-1;
- if (optGetInt("booklet-signature",num_options,options,¶m.book_signature)) {
- if (param.book_signature==0) {
+ param.book_signature = -1;
+ if (optGetInt("booklet-signature", num_options, options,
+ ¶m.book_signature))
+ {
+ if (param.book_signature == 0)
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToPDF: Unsupported booklet-signature "
- "value, using booklet-signature=-1 "
- "(all)!", val);
- param.book_signature=-1;
+ "cfFilterPDFToPDF: Unsupported booklet-signature value, using booklet-signature=-1 (all)!",
+ val);
+ param.book_signature = -1;
}
}
- if ((val=cupsGetOption("position",num_options,options)) != NULL) {
- if (!parsePosition(val,param.xpos,param.ypos)) {
+ if ((val = cupsGetOption("position", num_options, options)) != NULL)
+ {
+ if (!parsePosition(val, param.xpos, param.ypos))
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToPDF: Unrecognized position value "
- "%s, using position=center!", val);
- param.xpos=pdftopdf_position_e::CENTER;
- param.ypos=pdftopdf_position_e::CENTER;
+ "cfFilterPDFToPDF: Unrecognized position value %s, using position=center!",
+ val);
+ param.xpos = pdftopdf_position_e::CENTER;
+ param.ypos = pdftopdf_position_e::CENTER;
}
}
(val = cfIPPAttrEnumValForPrinter(printer_attrs, job_attrs,
"multiple-document-handling")) !=
NULL)
- /* This IPP attribute is unnecessarily complicated:
- * single-document, separate-documents-collated-copies, single-document-new-sheet:
- * -> collate (true)
- * separate-documents-uncollated-copies:
- * -> can be uncollated (false)
- */
+ //
+ // This IPP attribute is unnecessarily complicated:
+ // single-document, separate-documents-collated-copies,
+ // single-document-new-sheet:
+ // -> collate (true)
+ // separate-documents-uncollated-copies:
+ // -> can be uncollated (false)
+ //
param.collate =
(strcasecmp(val, "separate-documents-uncollated-copies") != 0);
- /*
+#if 0
// TODO: scaling
// TODO: natural-scaling
- scaling
-
-
- if ((val = cupsGetOption("scaling",num_options,options)) != 0) {
+ // Scaling
+ if ((val = cupsGetOption("scaling", num_options, options)) != 0)
+ {
scaling = atoi(val) * 0.01;
fitplot = true;
- } else if (fitplot) {
- scaling = 1.0;
}
- if ((val = cupsGetOption("natural-scaling",num_options,options)) != 0) {
+ else if (fitplot)
+ scaling = 1.0;
+ if ((val = cupsGetOption("natural-scaling", num_options, options)) != 0)
naturalScaling = atoi(val) * 0.01;
- }
-
- */
+#endif
- // make pages a multiple of two (only considered when duplex is on).
+ // Make pages a multiple of two (only considered when duplex is on).
// i.e. printer has hardware-duplex, but needs pre-inserted filler pages
// FIXME? pdftopdf also supports it as cmdline option (via checkFeature())
param.even_duplex =
// TODO? pdftopdf* ?
// TODO?! pdftopdfAutoRotate
- // TODO?! choose default by whether pdfautoratate filter has already been run (e.g. by mimetype)
- param.auto_rotate=(!is_false(cupsGetOption("pdfAutoRotate",num_options,options)) &&
- !is_false(cupsGetOption("pdftopdfAutoRotate",num_options,options)));
+ // TODO?! Choose default by whether pdfautoratate filter has already been
+ // run (e.g. by mimetype)
+ param.auto_rotate =
+ (!is_false(cupsGetOption("pdfAutoRotate", num_options, options)) &&
+ !is_false(cupsGetOption("pdftopdfAutoRotate", num_options, options)));
+ //
// Do we have to do the page logging in page_log?
-
+ //
// CUPS standard is that the last filter (not the backend, usually the
// printer driver) does page logging in the /var/log/cups/page_log file
// by outputting "PAGE: <# of current page> <# of copies>" to stderr.
-
+ //
// cfFilterPDFToPDF() would have to do this only for PDF printers as
// in this case cfFilterPDFToPDF() is the last filter, but some of
// the other filters are not able to do the logging because they do
// not have access to the number of pages of the file to be printed,
// so cfFilterPDFToPDF() overtakes their logging duty.
+ //
// Check whether page logging is forced or suppressed by the options
if ((val = cupsGetOption("pdf-filter-page-logging",
- num_options, options)) != NULL) {
- if (strcasecmp(val,"auto") == 0) {
+ num_options, options)) != NULL)
+ {
+ if (strcasecmp(val, "auto") == 0)
+ {
param.page_logging = -1;
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPDFToPDF: Automatic page logging "
- "selected by options.");
- } else if (is_true(val)) {
+ "cfFilterPDFToPDF: Automatic page logging selected by options.");
+ }
+ else if (is_true(val))
+ {
param.page_logging = 1;
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPDFToPDF: Forced page logging "
- "selected by options.");
- } else if (is_false(val)) {
+ "cfFilterPDFToPDF: Forced page logging selected by options.");
+ }
+ else if (is_false(val))
+ {
param.page_logging = 0;
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPDFToPDF: Suppressed page "
- "logging selected by options.");
- } else {
+ "cfFilterPDFToPDF: Suppressed page logging selected by options.");
+ }
+ else
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToPDF: Unsupported page "
- "logging setting "
- "\"pdf-filter-page-logging=%s\", "
- "using \"auto\"!", val);
+ "cfFilterPDFToPDF: Unsupported page logging setting \"pdf-filter-page-logging=%s\", using \"auto\"!",
+ val);
param.page_logging = -1;
}
}
- if (param.page_logging == -1) {
+ if (param.page_logging == -1)
+ {
// We determine whether to log pages or not
// using the output data MIME type. log pages only when the output is
// either pdf or PWG Raster
// If final_content_type is not clearly available we are not sure whether
// to log pages or not
- if((char*)final_content_type==NULL ||
- sizeof(final_content_type)==0 ||
- final_content_type[0]=='\0'){
+ if ((char*)final_content_type == NULL ||
+ sizeof(final_content_type) == 0 ||
+ final_content_type[0] == '\0')
param.page_logging = -1;
- }
if (doc->logfunc)
{
doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPDFToPDF: Determined whether to "
- "log pages or not using output data type.");
+ "cfFilterPDFToPDF: Determined whether to log pages or not using output data type.");
doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"final_content_type = %s => page_logging = %d",
final_content_type ? final_content_type : "NULL",
}
// }}}
-void calculate(int num_options,
- cups_option_t *options,
- _cfPDFToPDFProcessingParameters ¶m,
- char *final_content_type) // {{{
+void
+calculate(int num_options,
+ cups_option_t *options,
+ _cfPDFToPDFProcessingParameters ¶m,
+ char *final_content_type) // {{{
{
const char *val;
bool hw_copies = false,
if (hw_copies)
{
if ((val = cupsGetOption("hardware-collate",
- num_options, options)) != NULL)
+ num_options, options)) != NULL)
// Use hardware collate according to the caller's instructions
hw_collate = is_true(val);
else
if (param.reverse && param.duplex)
// Enable even_duplex or the first page may be empty.
- param.even_duplex=true; // disabled later, if non-duplex
+ param.even_duplex = true; // disabled later, if non-duplex
- if (param.num_copies==1) {
- param.device_copies=1;
+ if (param.num_copies == 1)
+ {
+ param.device_copies = 1;
// collate is never needed for a single copy
- param.collate=false; // (does not make a big difference for us)
- } else if (hw_copies) { // hw copy generation available
- param.device_copies=param.num_copies;
- if (param.collate) { // collate requested by user
+ param.collate = false; // (does not make a big difference for us)
+ }
+ else if (hw_copies)
+ { // hw copy generation available
+ param.device_copies = param.num_copies;
+ if (param.collate)
+ { // collate requested by user
param.device_collate = hw_collate;
- if (!param.device_collate) {
+ if (!param.device_collate)
// printer can't hw collate -> we must copy collated in sw
- param.device_copies=1;
- }
+ param.device_copies = 1;
} // else: printer copies w/o collate and takes care of duplex/even_duplex
}
- else { // sw copies
- param.device_copies=1;
- if (param.duplex) { // &&(num_copies>1)
- // sw collate + even_duplex must be forced to prevent copies on the backsides
- param.collate=true;
- param.device_collate=false;
+ else
+ { // sw copies
+ param.device_copies = 1;
+ if (param.duplex)
+ { // &&(num_copies>1)
+ // sw collate + even_duplex must be forced to prevent copies on the
+ // back sides
+ param.collate = true;
+ param.device_collate = false;
}
}
- if (param.device_copies != 1) //hw copy
- param.num_copies=1; // disable sw copy
+ if (param.device_copies != 1) // hw copy
+ param.num_copies = 1; // disable sw copy
if (param.duplex &&
param.collate && !param.device_collate) // software collate
- param.even_duplex=true; // fillers always needed
+ param.even_duplex = true; // fillers always needed
if (!param.duplex)
- param.even_duplex=false;
+ param.even_duplex = false;
}
// }}}
// reads from stdin into temporary file. returns FILE * or NULL on error
-FILE *copy_fd_to_temp(int infd, pdftopdf_doc_t *doc) // {{{
+FILE *
+copy_fd_to_temp(int infd,
+ pdftopdf_doc_t *doc) // {{{
{
char buf[BUFSIZ];
int n;
// FIXME: what does >buf mean here?
- int outfd=cupsTempFd(buf,sizeof(buf));
- if (outfd<0) {
+ int outfd = cupsTempFd(buf, sizeof(buf));
+ if (outfd < 0)
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
"cfFilterPDFToPDF: Can't create temporary file");
- return NULL;
+ return (NULL);
}
// remove name
unlink(buf);
// copy stdin to the tmp file
- while ((n=read(infd,buf,BUFSIZ)) > 0) {
- if (write(outfd,buf,n) != n) {
+ while ((n = read(infd, buf, BUFSIZ)) > 0)
+ {
+ if (write(outfd, buf, n) != n)
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToPDF: Can't copy stdin to temporary "
- "file");
+ "cfFilterPDFToPDF: Can't copy stdin to temporary file");
close(outfd);
- return NULL;
+ return (NULL);
}
}
- if (lseek(outfd,0,SEEK_SET) < 0) {
+ if (lseek(outfd, 0, SEEK_SET) < 0)
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
"cfFilterPDFToPDF: Can't rewind temporary file");
close(outfd);
- return NULL;
+ return (NULL);
}
FILE *f;
- if ((f=fdopen(outfd,"rb")) == 0) {
+ if ((f = fdopen(outfd, "rb")) == 0)
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
"cfFilterPDFToPDF: Can't fdopen temporary file");
close(outfd);
- return NULL;
+ return (NULL);
}
return f;
}
// Try to read a single byte of data
if (fread(buf, 1, 1, f) == 0)
- return true;
+ return (true);
rewind(f);
- return false;
+ return (false);
}
// }}}
-int /* O - Error status */
-cfFilterPDFToPDF(int inputfd, /* I - File descriptor input stream */
- int outputfd, /* I - File descriptor output stream */
- int inputseekable, /* I - Is input stream seekable? */
- cf_filter_data_t *data, /* I - Job and printer data */
- void *parameters) /* I - Filter-specific parameters (unused) */
+int // O - Error status
+cfFilterPDFToPDF(int inputfd, // I - File descriptor input stream
+ int outputfd, // I - File descriptor output stream
+ int inputseekable, // I - Is input stream seekable?
+ cf_filter_data_t *data, // I - Job and printer data
+ void *parameters) // I - Filter-specific parameters
+ // (unused)
{
pdftopdf_doc_t doc; /* Document information */
char *final_content_type = data->final_content_type;
int streaming = 0;
size_t bytes;
char buf[BUFSIZ];
- cf_logfunc_t log = data->logfunc;
+ cf_logfunc_t log = data->logfunc;
void *ld = data->logdata;
cf_filter_iscanceledfunc_t iscanceled = data->iscanceledfunc;
void *icd = data->iscanceleddata;
- int num_options = 0;
- cups_option_t *options = NULL;
+ int num_options = 0;
+ cups_option_t *options = NULL;
- try {
+ try
+ {
_cfPDFToPDFProcessingParameters param;
- param.job_id=data->job_id;
- param.user=data->job_user;
- param.title=data->job_title;
- param.num_copies=data->copies;
- param.copies_to_be_logged=data->copies;
+ param.job_id = data->job_id;
+ param.user = data->job_user;
+ param.title = data->job_title;
+ param.num_copies = data->copies;
+ param.copies_to_be_logged = data->copies;
// TODO?! sanity checks
// job through QPDL (so no page management, form flattening,
// page size/orientation adjustment, ...)
if ((t = cupsGetOption("filter-streaming-mode",
- num_options, options)) !=
- NULL &&
- (strcasecmp(t, "false") && strcasecmp(t, "off") &
- strcasecmp(t, "no"))) {
+ num_options, options)) != NULL &&
+ (strcasecmp(t, "false") && strcasecmp(t, "off") &&
+ strcasecmp(t, "no")))
+ {
streaming = 1;
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: Streaming mode: No PDF processing, only adding of JCL");
std::unique_ptr<_cfPDFToPDFProcessor> proc(_cfPDFToPDFFactory::processor());
- if ((inputseekable && inputfd > 0) || streaming) {
+ if ((inputseekable && inputfd > 0) || streaming)
+ {
if ((inputfp = fdopen(inputfd, "rb")) == NULL)
- return 1;
- } else {
+ return (1);
+ }
+ else
+ {
if ((inputfp = copy_fd_to_temp(inputfd, &doc)) == NULL)
- return 1;
+ return (1);
}
- if (!streaming) {
- if (is_empty(inputfp)) {
+ if (!streaming)
+ {
+ if (is_empty(inputfp))
+ {
fclose(inputfp);
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: Input is empty, outputting empty file.");
- return 0;
+ return (0);
}
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: Processing PDF input with QPDF: Page-ranges, page-set, number-up, booklet, size adjustment, ...");
// Load the PDF input data into QPDF
- if (!proc->load_file(inputfp, &doc, CF_PDFTOPDF_WILL_STAY_ALIVE, 1)) {
+ if (!proc->load_file(inputfp, &doc, CF_PDFTOPDF_WILL_STAY_ALIVE, 1))
+ {
fclose(inputfp);
- return 1;
+ return (1);
}
// Process the PDF input data
if (!_cfProcessPDFToPDF(*proc, param, &doc))
- return 2;
+ return (2);
// Pass information to subsequent filters via PDF comments
std::vector<std::string> output;
outputfp = fdopen(outputfd, "w");
if (outputfp == NULL)
- return 1;
+ return (1);
- if (!streaming) {
+ if (!streaming)
+ {
// Pass on the processed input data
proc->emit_file(outputfp, &doc, CF_PDFTOPDF_WILL_STAY_ALIVE);
// proc->emit_filename(NULL);
- } else {
+ }
+ else
+ {
// Pass through the input data
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: Passing on unchanged PDF data from input");
}
fclose(outputfp);
- } catch (std::exception &e) {
+ }
+ catch (std::exception &e)
+ {
// TODO? exception type
if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToPDF: Exception: %s",e.what());
- return 5;
- } catch (...) {
+ "cfFilterPDFToPDF: Exception: %s", e.what());
+ return (5);
+ }
+ catch (...)
+ {
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterPDFToPDF: Unknown exception caught. Exiting.");
- return 6;
+ return (6);
}
- return 0;
+ return (0);
}
// namespace PPTypes {} TODO?
enum pdftopdf_axis_e { X, Y };
-enum pdftopdf_position_e { CENTER=0, LEFT=-1, RIGHT=1, TOP=1, BOTTOM=-1 }; // PS order
-void _cfPDFToPDFPositionDump(pdftopdf_position_e pos,pdftopdf_doc_t *doc);
-void _cfPDFToPDFPositionDump(pdftopdf_position_e pos,pdftopdf_axis_e axis,pdftopdf_doc_t *doc);
-
-enum pdftopdf_rotation_e { ROT_0, ROT_90, ROT_180, ROT_270 }; // CCW
-void _cfPDFToPDFRotationDump(pdftopdf_rotation_e rot,pdftopdf_doc_t *doc);
-pdftopdf_rotation_e operator+(pdftopdf_rotation_e lhs,pdftopdf_rotation_e rhs);
-pdftopdf_rotation_e operator-(pdftopdf_rotation_e lhs,pdftopdf_rotation_e rhs);
+enum pdftopdf_position_e { // PS order
+ CENTER = 0,
+ LEFT = -1,
+ RIGHT = 1,
+ TOP = 1,
+ BOTTOM = -1
+};
+
+void _cfPDFToPDFPositionDump(pdftopdf_position_e pos, pdftopdf_doc_t *doc);
+void _cfPDFToPDFPositionDump(pdftopdf_position_e pos, pdftopdf_axis_e axis,
+ pdftopdf_doc_t *doc);
+
+enum pdftopdf_rotation_e { ROT_0, ROT_90, ROT_180, ROT_270 }; // CCW
+
+void _cfPDFToPDFRotationDump(pdftopdf_rotation_e rot, pdftopdf_doc_t *doc);
+pdftopdf_rotation_e operator+(pdftopdf_rotation_e lhs, pdftopdf_rotation_e rhs);
+pdftopdf_rotation_e operator-(pdftopdf_rotation_e lhs, pdftopdf_rotation_e rhs);
pdftopdf_rotation_e operator-(pdftopdf_rotation_e rhs);
-//pdftopdf_rotation_e operator+=(pdftopdf_rotation_e &lhs,pdftopdf_rotation_e rhs);
+//pdftopdf_rotation_e operator+=(pdftopdf_rotation_e &lhs,
+// pdftopdf_rotation_e rhs);
+
+enum pdftopdf_border_type_e {
+ NONE = 0,
+ ONE_THIN = 2,
+ ONE_THICK = 3,
+ TWO_THIN = 4,
+ TWO_THICK = 5,
+ ONE = 0x02,
+ TWO = 0x04,
+ THICK = 0x01
+};
-enum pdftopdf_border_type_e { NONE=0, ONE_THIN=2, ONE_THICK=3, TWO_THIN=4, TWO_THICK=5,
- ONE=0x02, TWO=0x04, THICK=0x01};
-void _cfPDFToPDFBorderTypeDump(pdftopdf_border_type_e border,pdftopdf_doc_t *doc);
+void _cfPDFToPDFBorderTypeDump(pdftopdf_border_type_e border,
+ pdftopdf_doc_t *doc);
struct _cfPDFToPDFPageRect {
-_cfPDFToPDFPageRect() : top(NAN),left(NAN),right(NAN),bottom(NAN),width(NAN),height(NAN) {}
- float top,left,right,bottom; // i.e. margins
- float width,height;
+_cfPDFToPDFPageRect()
+ : top(NAN),
+ left(NAN),
+ right(NAN),
+ bottom(NAN),
+ width(NAN),
+ height(NAN) {}
+ float top, left, right, bottom; // i.e. margins
+ float width, height;
- void rotate_move(pdftopdf_rotation_e r,float pwidth,float pheight); // pwidth original "page size" (i.e. before rotation)
+ void rotate_move(pdftopdf_rotation_e r, float pwidth, float pheight);
+ // pwidth original "page size" (i.e. before rotation)
void scale(float mult);
- void translate(float tx,float ty);
+ void translate(float tx, float ty);
void set(const _cfPDFToPDFPageRect &rhs); // only for rhs.* != NAN
void dump(pdftopdf_doc_t *doc) const;
};
-// bool _cfPDFToPDFParseBorder(const char *val,pdftopdf_border_type_e &ret); // none,single,...,double-thick
+// bool _cfPDFToPDFParseBorder(const char *val,pdftopdf_border_type_e &ret);
+// // none, single, ..., double-thick
-#endif
+#endif // !_CUPS_FILTERS_PDFTOPDF_PPTYPES_H_
#include <stdio.h>
#include "cupsfilters/debug-internal.h"
-void _cfPDFToPDFPositionDump(pdftopdf_position_e pos,pdftopdf_doc_t *doc) // {{{
+void
+_cfPDFToPDFPositionDump(pdftopdf_position_e pos,
+ pdftopdf_doc_t *doc) // {{{
{
- static const char *pstr[3]={"Left/Bottom","Center","Right/Top"};
- if ((pos < LEFT) || (pos > RIGHT)) {
+ static const char *pstr[3] = {"Left/Bottom", "Center", "Right/Top"};
+ if ((pos < LEFT) || (pos > RIGHT))
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPDFToPDF: (bad position: %d)",pos);
- } else {
+ "cfFilterPDFToPDF: (bad position: %d)", pos);
+ }
+ else
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPDFToPDF: %s",pstr[pos+1]);
+ "cfFilterPDFToPDF: %s", pstr[pos+1]);
}
}
// }}}
-void _cfPDFToPDFPositionDump(pdftopdf_position_e pos,pdftopdf_axis_e axis,pdftopdf_doc_t *doc) // {{{
+void
+_cfPDFToPDFPositionDump(pdftopdf_position_e pos,
+ pdftopdf_axis_e axis,
+ pdftopdf_doc_t *doc) // {{{
{
DEBUG_assert((axis == pdftopdf_axis_e::X) || (axis == pdftopdf_axis_e::Y));
- if ((pos < LEFT) || (pos > RIGHT)) {
+ if ((pos < LEFT) || (pos > RIGHT))
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: Position %s: (bad position: %d)",
(axis == pdftopdf_axis_e::X) ? "X" : "Y", pos);
return;
}
- if (axis==pdftopdf_axis_e::X) {
- static const char *pxstr[3]={"Left","Center","Right"};
+ if (axis == pdftopdf_axis_e::X)
+ {
+ static const char *pxstr[3] = {"Left", "Center", "Right"};
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: Position X: %s", pxstr[pos+1]);
- } else {
- static const char *pystr[3]={"Bottom","Center","Top"};
+ }
+ else
+ {
+ static const char *pystr[3] = {"Bottom", "Center", "Top"};
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPDFToPDF: Position Y: %s",pystr[pos+1]);
+ "cfFilterPDFToPDF: Position Y: %s", pystr[pos+1]);
}
}
// }}}
-void _cfPDFToPDFRotationDump(pdftopdf_rotation_e rot,pdftopdf_doc_t *doc) // {{{
+void
+_cfPDFToPDFRotationDump(pdftopdf_rotation_e rot,
+ pdftopdf_doc_t *doc) // {{{
{
- static const char *rstr[4]={"0 deg","90 deg","180 deg","270 deg"}; // CCW
- if ((rot < ROT_0) || (rot > ROT_270)) {
+ static const char *rstr[4] = {"0 deg", "90 deg", "180 deg", "270 deg"}; // CCW
+ if ((rot < ROT_0) || (rot > ROT_270))
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPDFToPDF: Rotation(CCW): (bad rotation: %d)",rot);
- } else {
+ "cfFilterPDFToPDF: Rotation(CCW): (bad rotation: %d)", rot);
+ }
+ else
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPDFToPDF: Rotation(CCW): %s",rstr[rot]);
+ "cfFilterPDFToPDF: Rotation(CCW): %s", rstr[rot]);
}
}
// }}}
-pdftopdf_rotation_e operator+(pdftopdf_rotation_e lhs,pdftopdf_rotation_e rhs) // {{{
+pdftopdf_rotation_e
+operator+(pdftopdf_rotation_e lhs,
+ pdftopdf_rotation_e rhs) // {{{
{
- return (pdftopdf_rotation_e)(((int)lhs+(int)rhs)%4);
+ return (pdftopdf_rotation_e)(((int)lhs + (int)rhs) % 4);
}
// }}}
-pdftopdf_rotation_e operator-(pdftopdf_rotation_e lhs,pdftopdf_rotation_e rhs) // {{{
+pdftopdf_rotation_e
+operator-(pdftopdf_rotation_e lhs,
+ pdftopdf_rotation_e rhs) // {{{
{
- return (pdftopdf_rotation_e)((((int)lhs-(int)rhs)%4+4)%4);
+ return (pdftopdf_rotation_e)((((int)lhs - (int)rhs) % 4 + 4) % 4);
}
// }}}
-pdftopdf_rotation_e operator-(pdftopdf_rotation_e rhs) // {{{
+pdftopdf_rotation_e
+operator-(pdftopdf_rotation_e rhs) // {{{
{
- return (pdftopdf_rotation_e)((4-(int)rhs)%4);
+ return (pdftopdf_rotation_e)((4 - (int)rhs) % 4);
}
// }}}
-void _cfPDFToPDFBorderTypeDump(pdftopdf_border_type_e border,pdftopdf_doc_t *doc) // {{{
+void
+_cfPDFToPDFBorderTypeDump(pdftopdf_border_type_e border,
+ pdftopdf_doc_t *doc) // {{{
{
- if ((border < NONE) || (border == 1) || (border > TWO_THICK)) {
+ if ((border < NONE) || (border == 1) || (border > TWO_THICK))
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPDFToPDF: Border: (bad border: %d)",border);
- } else {
- static const char *bstr[6]={"None",NULL,"one thin","one thick","two thin","two thick"};
+ "cfFilterPDFToPDF: Border: (bad border: %d)", border);
+ }
+ else
+ {
+ static const char *bstr[6] =
+ {"None", NULL, "one thin", "one thick", "two thin", "two thick"};
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPDFToPDF: Border: %s",bstr[border]);
+ "cfFilterPDFToPDF: Border: %s", bstr[border]);
}
}
// }}}
-void _cfPDFToPDFPageRect::rotate_move(pdftopdf_rotation_e r,float pwidth,float pheight) // {{{
+void
+_cfPDFToPDFPageRect::rotate_move(pdftopdf_rotation_e r,
+ float pwidth,
+ float pheight) // {{{
{
#if 1
- if (r>=ROT_180) {
- std::swap(top,bottom);
- std::swap(left,right);
+ if (r >= ROT_180)
+ {
+ std::swap(top, bottom);
+ std::swap(left, right);
}
- if ((r == ROT_90) || (r == ROT_270)) {
- const float tmp=bottom;
- bottom=left;
- left=top;
- top=right;
- right=tmp;
-
- std::swap(width,height);
- std::swap(pwidth,pheight);
+ if ((r == ROT_90) || (r == ROT_270))
+ {
+ const float tmp = bottom;
+ bottom = left;
+ left = top;
+ top = right;
+ right = tmp;
+
+ std::swap(width, height);
+ std::swap(pwidth, pheight);
}
- if ((r == ROT_90) || (r == ROT_180)) {
- left=pwidth-left;
- right=pwidth-right;
+ if ((r == ROT_90) || (r == ROT_180))
+ {
+ left = pwidth - left;
+ right = pwidth - right;
}
- if ((r == ROT_270) || (r == ROT_180)) {
- top=pheight-top;
- bottom=pheight-bottom;
+ if ((r == ROT_270) || (r == ROT_180))
+ {
+ top = pheight - top;
+ bottom = pheight - bottom;
}
#else
- switch (r) {
- case ROT_0: // no-op
- break;
- case ROT_90:
- const float tmp0=bottom;
- bottom=left;
- left=pheight-top;
- top=right;
- right=pheight-tmp0;
-
- std::swap(width,height);
- break;
- case ROT_180:
- const float tmp1=left;
- left=pwidth-right;
- right=pwidth-tmp1;
-
- const float tmp2=top;
- top=pheight-bottom;
- bottom=pheight-tmp2;
- break;
- case ROT_270:
- const float tmp3=top;
- top=pwidth-left;
- left=bottom;
- bottom=pwidth-right;
- right=tmp3;
-
- std::swap(width,height);
- break;
+ switch (r)
+ {
+ case ROT_0: // no-op
+ break;
+ case ROT_90:
+ const float tmp0 = bottom;
+ bottom = left;
+ left = pheight - top;
+ top = right;
+ right = pheight - tmp0;
+
+ std::swap(width, height);
+ break;
+ case ROT_180:
+ const float tmp1 = left;
+ left = pwidth - right;
+ right = pwidth - tmp1;
+
+ const float tmp2 = top;
+ top = pheight - bottom;
+ bottom = pheight - tmp2;
+ break;
+ case ROT_270:
+ const float tmp3 = top;
+ top = pwidth - left;
+ left = bottom;
+ bottom = pwidth - right;
+ right = tmp3;
+
+ std::swap(width, height);
+ break;
}
#endif
}
// }}}
-void _cfPDFToPDFPageRect::scale(float mult) // {{{
+void
+_cfPDFToPDFPageRect::scale(float mult) // {{{
{
- if (mult==1.0) {
+ if (mult == 1.0)
return;
- }
- DEBUG_assert(mult!=0.0);
- bottom*=mult;
- left*=mult;
- top*=mult;
- right*=mult;
+ DEBUG_assert(mult != 0.0);
+
+ bottom *= mult;
+ left *= mult;
+ top *= mult;
+ right *= mult;
- width*=mult;
- height*=mult;
+ width *= mult;
+ height *= mult;
}
// }}}
-void _cfPDFToPDFPageRect::translate(float tx,float ty) // {{{
+void
+_cfPDFToPDFPageRect::translate(float tx,
+ float ty) // {{{
{
- left+=tx;
- bottom+=ty;
- right+=tx;
- top+=ty;
+ left += tx;
+ bottom += ty;
+ right += tx;
+ top += ty;
}
// }}}
-void _cfPDFToPDFPageRect::set(const _cfPDFToPDFPageRect &rhs) // {{{
+void
+_cfPDFToPDFPageRect::set(const _cfPDFToPDFPageRect &rhs) // {{{
{
- if (!std::isnan(rhs.top)) top=rhs.top;
- if (!std::isnan(rhs.left)) left=rhs.left;
- if (!std::isnan(rhs.right)) right=rhs.right;
- if (!std::isnan(rhs.bottom)) bottom=rhs.bottom;
+ if (!std::isnan(rhs.top))
+ top = rhs.top;
+ if (!std::isnan(rhs.left))
+ left = rhs.left;
+ if (!std::isnan(rhs.right))
+ right = rhs.right;
+ if (!std::isnan(rhs.bottom))
+ bottom = rhs.bottom;
}
// }}}
-void _cfPDFToPDFPageRect::dump(pdftopdf_doc_t *doc) const // {{{
+void
+_cfPDFToPDFPageRect::dump(pdftopdf_doc_t *doc) const // {{{
{
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: top: %f, left: %f, right: %f, bottom: %f, "
"width: %f, height: %f",
- top,left,right,bottom,
- width,height);
+ top, left, right, bottom,
+ width, height);
}
// }}}
#include <qpdf/QPDF.hh>
bool _cfPDFToPDFHasOutputIntent(QPDF &pdf);
-void _cfPDFToPDFAddOutputIntent(QPDF &pdf,const char *filename);
+void _cfPDFToPDFAddOutputIntent(QPDF &pdf, const char *filename);
-void _cfPDFToPDFAddDefaultRGB(QPDF &pdf,QPDFObjectHandle srcicc);
-QPDFObjectHandle _cfPDFToPDFSetDefaultICC(QPDF &pdf,const char *filename);
+void _cfPDFToPDFAddDefaultRGB(QPDF &pdf, QPDFObjectHandle srcicc);
+QPDFObjectHandle _cfPDFToPDFSetDefaultICC(QPDF &pdf, const char *filename);
-#endif
+#endif // !_CUPS_FILTERS_PDFTOPDF_QPDF_CM_H_
#include <stdexcept>
// TODO? instead use qpdf's StreamDataProvider, FileInputSource, Buffer etc.
-static std::string load_file(const char *filename) // {{{
+static std::string
+load_file(const char *filename) // {{{
{
- if (!filename) {
+ if (!filename)
throw std::invalid_argument("NULL filename not allowed");
- }
- FILE *f=fopen(filename,"r");
- if (!f) {
+ FILE *f = fopen(filename, "r");
+ if (!f)
throw std::runtime_error(std::string("file ") + filename + " could not be opened");
- }
- const int bsize=2048;
- int pos=0;
+ const int bsize = 2048;
+ int pos = 0;
std::string ret;
- while (!feof(f)) {
- ret.resize(pos+bsize);
- int res=fread(&ret[pos],1,bsize,f);
- pos+=res;
- if (res<bsize) {
+ while (!feof(f))
+ {
+ ret.resize(pos + bsize);
+ int res = fread(&ret[pos], 1, bsize, f);
+ pos += res;
+ if (res < bsize)
+ {
ret.resize(pos);
break;
}
}
fclose(f);
- return ret;
+ return (ret);
}
// }}}
// TODO?
// TODO? test
-bool _cfPDFToPDFHasOutputIntent(QPDF &pdf) // {{{
+bool
+_cfPDFToPDFHasOutputIntent(QPDF &pdf) // {{{
{
- auto catalog=pdf.getRoot();
- if (!catalog.hasKey("/OutputIntents")) {
- return false;
- }
- return true; // TODO?
+ auto catalog = pdf.getRoot();
+ if (!catalog.hasKey("/OutputIntents"))
+ return (false);
+ return (true); // TODO?
}
// }}}
// TODO: test
// TODO? find existing , replace and return (?)
-void _cfPDFToPDFAddOutputIntent(QPDF &pdf,const char *filename) // {{{
+void
+_cfPDFToPDFAddOutputIntent(QPDF &pdf,
+ const char *filename) // {{{
{
- std::string icc=load_file(filename);
+ std::string icc = load_file(filename);
// TODO: check icc fitness
// ICC data, subject to "version limitations" per pdf version...
- QPDFObjectHandle outicc=QPDFObjectHandle::newStream(&pdf,icc);
+ QPDFObjectHandle outicc = QPDFObjectHandle::newStream(&pdf, icc);
- auto sdict=outicc.getDict();
+ auto sdict = outicc.getDict();
sdict.replaceKey("/N",QPDFObjectHandle::newInteger(4)); // must match ICC
// /Range ? // must match ICC, default [0.0 1.0 ...]
// /Alternate ? (/DeviceCMYK for N=4)
- auto intent=QPDFObjectHandle::parse(
+ auto intent = QPDFObjectHandle::parse(
"<<"
" /Type /OutputIntent" // Must be so (the standard requires).
" /S /GTS_PDFX" // Must be so (the standard requires).
" /RegistryName (http://www.color.org)" // Must be so (the standard requires).
" /DestOutputProfile null "
">>");
- intent.replaceKey("/DestOutputProfile",outicc);
+ intent.replaceKey("/DestOutputProfile", outicc);
- auto catalog=pdf.getRoot();
- if (!catalog.hasKey("/OutputIntents")) {
- catalog.replaceKey("/OutputIntents",QPDFObjectHandle::newArray());
- }
+ auto catalog = pdf.getRoot();
+ if (!catalog.hasKey("/OutputIntents"))
+ catalog.replaceKey("/OutputIntents", QPDFObjectHandle::newArray());
catalog.getKey("/OutputIntents").appendItem(intent);
}
// }}}
+//
+// for color management:
+// Use /DefaultGray, /DefaultRGB, /DefaultCMYK ... from *current* resource
+// dictionary ...
+// i.e. set
+// /Resources <<
+// /ColorSpace << --- can use just one indirect ref for this (probably)
+// /DefaultRGB [/ICCBased 5 0 R] ... sensible use is sRGB for DefaultRGB, etc.
+// >>
+// >>
+// for every page (what with form /XObjects?) and most importantly RGB
+// (leave CMYK, Gray for now, as this is already printer native(?))
+//
+// ? also every form XObject, pattern, type3 font, annotation appearance
+// stream(=form xobject +X)
+//
+// ? what if page already defines /Default? -- probably keep!
+//
+// ? maybe we need to set /ColorSpace in /Images ?
+// [gs idea is to just add the /Default-key and then reprocess...]
+//
-/* for color management:
- Use /DefaultGray, /DefaultRGB, /DefaultCMYK ... from *current* resource dictionary ...
- i.e. set
- /Resources <<
- /ColorSpace << --- can use just one indirect ref for this (probably)
- /DefaultRGB [/ICCBased 5 0 R] ... sensible use is sRGB for DefaultRGB, etc.
- >>
- >>
- for every page (what with form /XObjects?) and most importantly RGB (leave CMYK, Gray for now, as this is already printer native(?))
-
- ? also every form XObject, pattern, type3 font, annotation appearance stream(=form xobject +X)
-
- ? what if page already defines /Default? -- probably keep!
-
- ? maybe we need to set /ColorSpace in /Images ? [gs idea is to just add the /Default-key and then reprocess...]
-
-*/
// TODO? test
-void _cfPDFToPDFAddDefaultRGB(QPDF &pdf,QPDFObjectHandle srcicc) // {{{
+void
+_cfPDFToPDFAddDefaultRGB(QPDF &pdf, QPDFObjectHandle srcicc) // {{{
{
srcicc.assertStream();
- auto pages=pdf.getAllPages();
- for (auto it=pages.begin(),end=pages.end();it!=end;++it) {
- if (!it->hasKey("/Resources")) {
- it->replaceKey("/Resources",QPDFObjectHandle::newDictionary());
- }
- auto rdict=it->getKey("/Resources");
+ auto pages = pdf.getAllPages();
+ for (auto it = pages.begin(), end = pages.end(); it != end; ++ it)
+ {
+ if (!it->hasKey("/Resources"))
+ it->replaceKey("/Resources", QPDFObjectHandle::newDictionary());
- if (!rdict.hasKey("/ColorSpace")) {
- rdict.replaceKey("/ColorSpace",QPDFObjectHandle::newDictionary());
- }
- auto cdict=rdict.getKey("/ColorSpace");
+ auto rdict = it->getKey("/Resources");
+
+ if (!rdict.hasKey("/ColorSpace"))
+ rdict.replaceKey("/ColorSpace", QPDFObjectHandle::newDictionary());
+
+ auto cdict = rdict.getKey("/ColorSpace");
- if (!cdict.hasKey("/DefaultRGB")) {
- cdict.replaceKey("/DefaultRGB",QPDFObjectHandle::parse("[/ICCBased ]"));
+ if (!cdict.hasKey("/DefaultRGB"))
+ {
+ cdict.replaceKey("/DefaultRGB", QPDFObjectHandle::parse("[/ICCBased ]"));
cdict.getKey("/DefaultRGB").appendItem(srcicc);
}
}
// TODO? test
// TODO: find existing , replace and return (?)
// TODO: check icc fitness
-QPDFObjectHandle _cfPDFToPDFSetDefaultICC(QPDF &pdf,const char *filename) // {{{
+QPDFObjectHandle
+_cfPDFToPDFSetDefaultICC(QPDF &pdf,
+ const char *filename) // {{{
{
- // TODO: find existing , replace and return (?)
+ // TODO: find existing, replace and return (?)
- std::string icc=load_file(filename);
+ std::string icc = load_file(filename);
// TODO: check icc fitness
// ICC data, subject to "version limitations" per pdf version...
- QPDFObjectHandle ret=QPDFObjectHandle::newStream(&pdf,icc);
+ QPDFObjectHandle ret = QPDFObjectHandle::newStream(&pdf, icc);
- auto sdict=ret.getDict();
- sdict.replaceKey("/N",QPDFObjectHandle::newInteger(3)); // must match ICC
+ auto sdict = ret.getDict();
+ sdict.replaceKey("/N", QPDFObjectHandle::newInteger(3)); // must match ICC
// /Range ? // must match ICC, default [0.0 1.0 ...]
// /Alternate ? (/DeviceRGB for N=3)
_cfPDFToPDFMatrix(QPDFObjectHandle ar);
_cfPDFToPDFMatrix &rotate(pdftopdf_rotation_e rot);
- _cfPDFToPDFMatrix &rotate_move(pdftopdf_rotation_e rot,double width,double height);
+ _cfPDFToPDFMatrix &rotate_move(pdftopdf_rotation_e rot, double width,
+ double height);
_cfPDFToPDFMatrix &rotate(double rad);
// _cfPDFToPDFMatrix &rotate_deg(double deg);
- _cfPDFToPDFMatrix &translate(double tx,double ty);
- _cfPDFToPDFMatrix &scale(double sx,double sy);
- _cfPDFToPDFMatrix &scale(double s) { return scale(s,s); }
+ _cfPDFToPDFMatrix &translate(double tx, double ty);
+ _cfPDFToPDFMatrix &scale(double sx, double sy);
+ _cfPDFToPDFMatrix &scale(double s) { return (scale(s, s)); }
_cfPDFToPDFMatrix &operator*=(const _cfPDFToPDFMatrix &rhs);
double ctm[6];
};
-#endif
+#endif // !_CUPS_FILTERS_PDFTOPDF_QPDF_PDFTOPDF_H
class _cfPDFToPDFQPDFPageHandle : public _cfPDFToPDFPageHandle {
public:
virtual _cfPDFToPDFPageRect get_rect() const;
- virtual void add_border_rect(const _cfPDFToPDFPageRect &rect,pdftopdf_border_type_e border,float fscale);
- virtual void add_subpage(const std::shared_ptr<_cfPDFToPDFPageHandle> &sub,float xpos,float ypos,float scale,const _cfPDFToPDFPageRect *crop=NULL);
+ virtual void add_border_rect(const _cfPDFToPDFPageRect &rect,
+ pdftopdf_border_type_e border, float fscale);
+ virtual void add_subpage(const std::shared_ptr<_cfPDFToPDFPageHandle> &sub,
+ float xpos, float ypos, float scale,
+ const _cfPDFToPDFPageRect *crop=NULL);
virtual void mirror();
virtual void rotate(pdftopdf_rotation_e rot);
- virtual void add_label(const _cfPDFToPDFPageRect &rect, const std::string label);
- virtual pdftopdf_rotation_e crop(const _cfPDFToPDFPageRect &cropRect,pdftopdf_rotation_e orientation,pdftopdf_rotation_e param_orientation,pdftopdf_position_e xpos,pdftopdf_position_e ypos,bool scale,bool autorotate,pdftopdf_doc_t *doc);
+ virtual void add_label(const _cfPDFToPDFPageRect &rect,
+ const std::string label);
+ virtual pdftopdf_rotation_e crop(const _cfPDFToPDFPageRect &cropRect,
+ pdftopdf_rotation_e orientation,
+ pdftopdf_rotation_e param_orientation,
+ pdftopdf_position_e xpos,
+ pdftopdf_position_e ypos,
+ bool scale, bool autorotate,
+ pdftopdf_doc_t *doc);
virtual bool is_landscape(pdftopdf_rotation_e orientation);
- void debug(const _cfPDFToPDFPageRect &rect,float xpos,float ypos);
+ void debug(const _cfPDFToPDFPageRect &rect, float xpos, float ypos);
private:
bool is_existing() const;
QPDFObjectHandle get(); // only once!
private:
friend class _cfPDFToPDFQPDFProcessor;
// 1st mode: existing
- _cfPDFToPDFQPDFPageHandle(QPDFObjectHandle page,int orig_no=-1);
+ _cfPDFToPDFQPDFPageHandle(QPDFObjectHandle page, int orig_no = -1);
QPDFObjectHandle page;
int no;
// 2nd mode: create new
- _cfPDFToPDFQPDFPageHandle(QPDF *pdf,float width,float height);
+ _cfPDFToPDFQPDFPageHandle(QPDF *pdf, float width, float height);
std::map<std::string,QPDFObjectHandle> xobjs;
std::string content;
class _cfPDFToPDFQPDFProcessor : public _cfPDFToPDFProcessor {
public:
- virtual bool load_file(FILE *f,pdftopdf_doc_t *doc,pdftopdf_arg_ownership_e take=CF_PDFTOPDF_WILL_STAY_ALIVE,int flatten_forms=1);
- virtual bool load_filename(const char *name,pdftopdf_doc_t *doc,int flatten_forms=1);
+ virtual bool load_file(FILE *f,pdftopdf_doc_t *doc,
+ pdftopdf_arg_ownership_e
+ take = CF_PDFTOPDF_WILL_STAY_ALIVE,
+ int flatten_forms = 1);
+ virtual bool load_filename(const char *name,
+ pdftopdf_doc_t *doc, int flatten_forms = 1);
// TODO: virtual bool may_modify/may_print/?
virtual bool check_print_permissions(pdftopdf_doc_t *doc);
- // virtual bool set_process(const _cfPDFToPDFProcessingParameters ¶m) =0;
+ // virtual bool set_process(const _cfPDFToPDFProcessingParameters ¶m) = 0;
- virtual std::vector<std::shared_ptr<_cfPDFToPDFPageHandle>> get_pages(pdftopdf_doc_t *doc);
- virtual std::shared_ptr<_cfPDFToPDFPageHandle> new_page(float width,float height,pdftopdf_doc_t *doc);
+ virtual std::vector<std::shared_ptr<_cfPDFToPDFPageHandle>>
+ get_pages(pdftopdf_doc_t *doc);
+ virtual std::shared_ptr<_cfPDFToPDFPageHandle> new_page(float width,
+ float height,
+ pdftopdf_doc_t *doc);
- virtual void add_page(std::shared_ptr<_cfPDFToPDFPageHandle> page,bool front);
+ virtual void add_page(std::shared_ptr<_cfPDFToPDFPageHandle> page,
+ bool front);
- virtual void multiply(int copies,bool collate);
+ virtual void multiply(int copies, bool collate);
- virtual void auto_rotate_all(bool dst_lscape,pdftopdf_rotation_e normal_landscape);
- virtual void add_cm(const char *defaulticc,const char *outputicc);
+ virtual void auto_rotate_all(bool dst_lscape,
+ pdftopdf_rotation_e normal_landscape);
+ virtual void add_cm(const char *defaulticc, const char *outputicc);
virtual void set_comments(const std::vector<std::string> &comments);
- virtual void emit_file(FILE *dst,pdftopdf_doc_t *doc,pdftopdf_arg_ownership_e take=CF_PDFTOPDF_WILL_STAY_ALIVE);
- virtual void emit_filename(const char *name,pdftopdf_doc_t *doc);
+ virtual void emit_file(FILE *dst, pdftopdf_doc_t *doc,
+ pdftopdf_arg_ownership_e
+ take = CF_PDFTOPDF_WILL_STAY_ALIVE);
+ virtual void emit_filename(const char *name, pdftopdf_doc_t *doc);
virtual bool has_acro_form();
private:
std::string extraheader;
};
-#endif
+#endif // !_CUPS_FILTERS_PDFTOPDF_QPDF_PDFTOPDF_PROCESSOR_H
-#include "qpdf-pdftopdf-processor-private.h"
#include <stdio.h>
#include <stdarg.h>
#include "cupsfilters/debug-internal.h"
#include "qpdf-tools-private.h"
#include "qpdf-xobject-private.h"
#include "qpdf-pdftopdf-private.h"
+#include "qpdf-pdftopdf-processor-private.h"
+#include "qpdf-cm-private.h"
#include "pdftopdf-private.h"
-// Use: content.append(debug_box(pe.sub,xpos,ypos));
-static std::string debug_box(const _cfPDFToPDFPageRect &box,float xshift,float yshift) // {{{
+// Use: content.append(debug_box(pe.sub, xpos, ypos));
+static std::string
+debug_box(const _cfPDFToPDFPageRect &box,
+ float xshift,
+ float yshift) // {{{
{
- return std::string("q 1 w 0.1 G\n ")+
- QUtil::double_to_string(box.left+xshift)+" "+QUtil::double_to_string(box.bottom+yshift)+" m "+
- QUtil::double_to_string(box.right+xshift)+" "+QUtil::double_to_string(box.top+yshift)+" l "+"S \n "+
-
- QUtil::double_to_string(box.right+xshift)+" "+QUtil::double_to_string(box.bottom+yshift)+" m "+
- QUtil::double_to_string(box.left+xshift)+" "+QUtil::double_to_string(box.top+yshift)+" l "+"S \n "+
-
- QUtil::double_to_string(box.left+xshift)+" "+QUtil::double_to_string(box.bottom+yshift)+" "+
- QUtil::double_to_string(box.right-box.left)+" "+QUtil::double_to_string(box.top-box.bottom)+" re "+"S Q\n";
+ return (std::string("q 1 w 0.1 G\n ") +
+ QUtil::double_to_string(box.left + xshift) + " " +
+ QUtil::double_to_string(box.bottom + yshift) + " m " +
+ QUtil::double_to_string(box.right + xshift) + " " +
+ QUtil::double_to_string(box.top + yshift) + " l " + "S \n " +
+
+ QUtil::double_to_string(box.right + xshift) + " " +
+ QUtil::double_to_string(box.bottom + yshift) + " m " +
+ QUtil::double_to_string(box.left + xshift) + " " +
+ QUtil::double_to_string(box.top + yshift) + " l " + "S \n " +
+
+ QUtil::double_to_string(box.left + xshift) + " " +
+ QUtil::double_to_string(box.bottom + yshift) + " " +
+ QUtil::double_to_string(box.right - box.left) + " " +
+ QUtil::double_to_string(box.top - box.bottom) + " re " + "S Q\n");
}
// }}}
-_cfPDFToPDFQPDFPageHandle::_cfPDFToPDFQPDFPageHandle(QPDFObjectHandle page,int orig_no) // {{{
+_cfPDFToPDFQPDFPageHandle::_cfPDFToPDFQPDFPageHandle(QPDFObjectHandle page,
+ int orig_no) // {{{
: page(page),
no(orig_no),
rotation(ROT_0)
}
// }}}
-_cfPDFToPDFQPDFPageHandle::_cfPDFToPDFQPDFPageHandle(QPDF *pdf,float width,float height) // {{{
+_cfPDFToPDFQPDFPageHandle::_cfPDFToPDFQPDFPageHandle(QPDF *pdf,
+ float width,
+ float height) // {{{
: no(0),
rotation(ROT_0)
{
DEBUG_assert(pdf);
- page=QPDFObjectHandle::parse(
+ page = QPDFObjectHandle::parse(
"<<"
" /Type /Page"
" /Resources <<"
" /MediaBox null "
" /Contents null "
">>");
- page.replaceKey("/MediaBox",_cfPDFToPDFMakeBox(0,0,width,height));
- page.replaceKey("/Contents",QPDFObjectHandle::newStream(pdf));
+ page.replaceKey("/MediaBox", _cfPDFToPDFMakeBox(0, 0, width, height));
+ page.replaceKey("/Contents", QPDFObjectHandle::newStream(pdf));
// xobjects: later (in get())
content.assign("q\n"); // TODO? different/not needed
- page=pdf->makeIndirectObject(page); // stores *pdf
+ page = pdf->makeIndirectObject(page); // stores *pdf
}
// }}}
// Note: _cfPDFToPDFProcessor always works with "/Rotate"d and "/UserUnit"-scaled pages/coordinates/..., having 0,0 at left,bottom of the TrimBox
-_cfPDFToPDFPageRect _cfPDFToPDFQPDFPageHandle::get_rect() const // {{{
+_cfPDFToPDFPageRect
+_cfPDFToPDFQPDFPageHandle::get_rect() const // {{{
{
page.assertInitialized();
- _cfPDFToPDFPageRect ret=_cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page));
- ret.translate(-ret.left,-ret.bottom);
- ret.rotate_move(_cfPDFToPDFGetRotate(page),ret.width,ret.height);
+ _cfPDFToPDFPageRect ret =
+ _cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page));
+ ret.translate(-ret.left, -ret.bottom);
+ ret.rotate_move(_cfPDFToPDFGetRotate(page), ret.width, ret.height);
ret.scale(_cfPDFToPDFGetUserUnit(page));
- return ret;
+ return (ret);
}
// }}}
-bool _cfPDFToPDFQPDFPageHandle::is_existing() const // {{{
+bool
+_cfPDFToPDFQPDFPageHandle::is_existing() const // {{{
{
page.assertInitialized();
- return content.empty();
+ return (content.empty());
}
// }}}
-QPDFObjectHandle _cfPDFToPDFQPDFPageHandle::get() // {{{
+QPDFObjectHandle
+_cfPDFToPDFQPDFPageHandle::get() // {{{
{
- QPDFObjectHandle ret=page;
- if (!is_existing()) { // finish up page
- page.getKey("/Resources").replaceKey("/XObject",QPDFObjectHandle::newDictionary(xobjs));
+ QPDFObjectHandle ret = page;
+
+ if (!is_existing())
+ { // finish up page
+ page.getKey("/Resources").replaceKey("/XObject",
+ QPDFObjectHandle::newDictionary(xobjs));
content.append("Q\n");
- page.getKey("/Contents").replaceStreamData(content,QPDFObjectHandle::newNull(),QPDFObjectHandle::newNull());
- page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(rotation));
- } else {
- pdftopdf_rotation_e rot=_cfPDFToPDFGetRotate(page)+rotation;
- page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(rot));
+ page.getKey("/Contents").replaceStreamData(content,
+ QPDFObjectHandle::newNull(),
+ QPDFObjectHandle::newNull());
+ page.replaceOrRemoveKey("/Rotate", _cfPDFToPDFMakeRotate(rotation));
}
- page=QPDFObjectHandle(); // i.e. uninitialized
- return ret;
+ else
+ {
+ pdftopdf_rotation_e rot = _cfPDFToPDFGetRotate(page) + rotation;
+ page.replaceOrRemoveKey("/Rotate", _cfPDFToPDFMakeRotate(rot));
+ }
+ page = QPDFObjectHandle(); // i.e. uninitialized
+ return (ret);
}
// }}}
-// TODO: we probably need a function "ungetRect()" to transform to page/form space
-// TODO: as member
-static _cfPDFToPDFPageRect ungetRect(_cfPDFToPDFPageRect rect,const _cfPDFToPDFQPDFPageHandle &ph,pdftopdf_rotation_e rotation,QPDFObjectHandle page)
+// TODO: We probably need a function "ungetRect()" to transform to page/form
+// space, as member
+static _cfPDFToPDFPageRect
+ungetRect(_cfPDFToPDFPageRect rect,
+ const _cfPDFToPDFQPDFPageHandle &ph,
+ pdftopdf_rotation_e rotation,
+ QPDFObjectHandle page)
{
- _cfPDFToPDFPageRect pg1=ph.get_rect();
- _cfPDFToPDFPageRect pg2=_cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page));
+ _cfPDFToPDFPageRect pg1 = ph.get_rect();
+ _cfPDFToPDFPageRect pg2 =
+ _cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page));
- // we have to invert /Rotate, /UserUnit and the left,bottom (TrimBox) translation
+ // we have to invert /Rotate, /UserUnit and the left,bottom (TrimBox)
+ // translation
//_cfPDFToPDFRotationDump(rotation);
//_cfPDFToPDFRotationDump(_cfPDFToPDFGetRotate(page));
- rect.width=pg1.width;
- rect.height=pg1.height;
- //std::swap(rect.width,rect.height);
- //rect.rotate_move(-rotation,rect.width,rect.height);
+ rect.width = pg1.width;
+ rect.height = pg1.height;
+ //std::swap(rect.width, rect.height);
+ //rect.rotate_move(-rotation, rect.width, rect.height);
- rect.rotate_move(-_cfPDFToPDFGetRotate(page),pg1.width,pg1.height);
- rect.scale(1.0/_cfPDFToPDFGetUserUnit(page));
+ rect.rotate_move(-_cfPDFToPDFGetRotate(page), pg1.width, pg1.height);
+ rect.scale(1.0 / _cfPDFToPDFGetUserUnit(page));
- // _cfPDFToPDFPageRect pg2=_cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page));
- rect.translate(pg2.left,pg2.bottom);
+ //_cfPDFToPDFPageRect pg2=_cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page));
+ rect.translate(pg2.left, pg2.bottom);
//rect.dump();
- return rect;
+ return (rect);
}
// TODO FIXME rotations are strange ... (via ungetRect)
-// TODO? for non-existing (either drop comment or facility to create split streams needed)
-void _cfPDFToPDFQPDFPageHandle::add_border_rect(const _cfPDFToPDFPageRect &_rect,pdftopdf_border_type_e border,float fscale) // {{{
+// TODO? for non-existing (either drop comment or facility to create split
+// streams needed)
+void
+_cfPDFToPDFQPDFPageHandle::add_border_rect(const _cfPDFToPDFPageRect &_rect,
+ pdftopdf_border_type_e border,
+ float fscale) // {{{
{
DEBUG_assert(is_existing());
- DEBUG_assert(border!=pdftopdf_border_type_e::NONE);
+ DEBUG_assert(border != pdftopdf_border_type_e::NONE);
// straight from pstops
- const double lw=(border&THICK)?0.5:0.24;
- double line_width=lw*fscale;
- double margin=2.25*fscale;
- // (PageLeft+margin,PageBottom+margin) rect (PageRight-PageLeft-2*margin,...) ... for nup>1: PageLeft=0,etc.
- // if (double) margin+=2*fscale ...rect...
+ const double lw = (border & THICK) ? 0.5 : 0.24;
+ double line_width = lw * fscale;
+ double margin = 2.25 * fscale;
+ // (PageLeft + margin, PageBottom + margin)
+ // rect (PageRight - PageLeft - 2 * margin, ...) ...
+ // for nup > 1: PageLeft = 0, etc.
+ // if (double) margin += 2 * fscale ...rect...
- _cfPDFToPDFPageRect rect=ungetRect(_rect,*this,rotation,page);
+ _cfPDFToPDFPageRect rect = ungetRect(_rect, *this, rotation, page);
- DEBUG_assert(rect.left<=rect.right);
- DEBUG_assert(rect.bottom<=rect.top);
+ DEBUG_assert(rect.left <= rect.right);
+ DEBUG_assert(rect.bottom <= rect.top);
std::string boxcmd="q\n";
- boxcmd+=" "+QUtil::double_to_string(line_width)+" w 0 G \n";
- boxcmd+=" "+QUtil::double_to_string(rect.left+margin)+" "+QUtil::double_to_string(rect.bottom+margin)+" "+
- QUtil::double_to_string(rect.right-rect.left-2*margin)+" "+QUtil::double_to_string(rect.top-rect.bottom-2*margin)+" re S \n";
- if (border&TWO) {
- margin+=2*fscale;
- boxcmd+=" "+QUtil::double_to_string(rect.left+margin)+" "+QUtil::double_to_string(rect.bottom+margin)+" "+
- QUtil::double_to_string(rect.right-rect.left-2*margin)+" "+QUtil::double_to_string(rect.top-rect.bottom-2*margin)+" re S \n";
+ boxcmd += " " +QUtil::double_to_string(line_width) + " w 0 G \n";
+ boxcmd += " " +QUtil::double_to_string(rect.left + margin) + " " +
+ QUtil::double_to_string(rect.bottom + margin) + " " +
+ QUtil::double_to_string(rect.right - rect.left - 2 * margin) + " " +
+ QUtil::double_to_string(rect.top - rect.bottom - 2 * margin) + " re S \n";
+ if (border & TWO)
+ {
+ margin += 2 * fscale;
+ boxcmd += " " + QUtil::double_to_string(rect.left + margin) + " " +
+ QUtil::double_to_string(rect.bottom + margin) + " " +
+ QUtil::double_to_string(rect.right - rect.left - 2 * margin) + " " +
+ QUtil::double_to_string(rect.top - rect.bottom - 2 * margin) + " re S \n";
}
- boxcmd+="Q\n";
+ boxcmd += "Q\n";
- // if (!is_existing()) {
+ // if (!is_existing())
// // TODO: only after
// return;
- // }
DEBUG_assert(page.getOwningQPDF()); // existing pages are always indirect
#ifdef DEBUG // draw it on top
- static const char *pre="%pdftopdf q\n"
+ static const char *pre = "%pdftopdf q\n"
"q\n",
- *post="%pdftopdf Q\n"
+ *post = "%pdftopdf Q\n"
"Q\n";
- QPDFObjectHandle stm1=QPDFObjectHandle::newStream(page.getOwningQPDF(),pre),
- stm2=QPDFObjectHandle::newStream(page.getOwningQPDF(),std::string(post)+boxcmd);
+ QPDFObjectHandle stm1 = QPDFObjectHandle::newStream(page.getOwningQPDF(),
+ pre),
+ stm2 = QPDFObjectHandle::newStream(page.getOwningQPDF(),
+ std::string(post) +
+ boxcmd);
- page.addPageContents(stm1,true); // before
- page.addPageContents(stm2,false); // after
+ page.addPageContents(stm1, true); // before
+ page.addPageContents(stm2, false); // after
#else
- QPDFObjectHandle stm=QPDFObjectHandle::newStream(page.getOwningQPDF(),boxcmd);
- page.addPageContents(stm,true); // before
+ QPDFObjectHandle stm = QPDFObjectHandle::newStream(page.getOwningQPDF(),
+ boxcmd);
+ page.addPageContents(stm, true); // before
#endif
}
// }}}
+
/*
* This crop function is written for print-scaling=fill option.
* Trim Box is used for trimming the page in required size.
* scale tells if we need to scale input file.
*/
-pdftopdf_rotation_e _cfPDFToPDFQPDFPageHandle::crop(const _cfPDFToPDFPageRect &cropRect,pdftopdf_rotation_e orientation,pdftopdf_rotation_e param_orientation,pdftopdf_position_e xpos,pdftopdf_position_e ypos,bool scale,bool autorotate,pdftopdf_doc_t *doc)
+pdftopdf_rotation_e
+_cfPDFToPDFQPDFPageHandle::crop(const _cfPDFToPDFPageRect &cropRect,
+ pdftopdf_rotation_e orientation,
+ pdftopdf_rotation_e param_orientation,
+ pdftopdf_position_e xpos,
+ pdftopdf_position_e ypos,
+ bool scale,
+ bool autorotate,
+ pdftopdf_doc_t *doc)
{
page.assertInitialized();
pdftopdf_rotation_e save_rotate = _cfPDFToPDFGetRotate(page);
- if(orientation==ROT_0||orientation==ROT_180)
- page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(ROT_90));
+ if (orientation == ROT_0 || orientation == ROT_180)
+ page.replaceOrRemoveKey("/Rotate", _cfPDFToPDFMakeRotate(ROT_90));
else
- page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(ROT_0));
+ page.replaceOrRemoveKey("/Rotate", _cfPDFToPDFMakeRotate(ROT_0));
- _cfPDFToPDFPageRect currpage= _cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page));
- double width = currpage.right-currpage.left;
- double height = currpage.top-currpage.bottom;
- double pageWidth = cropRect.right-cropRect.left;
- double pageHeight = cropRect.top-cropRect.bottom;
- double final_w,final_h; //Width and height of cropped image.
+ _cfPDFToPDFPageRect currpage =
+ _cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page));
+ double width = currpage.right - currpage.left;
+ double height = currpage.top - currpage.bottom;
+ double pageWidth = cropRect.right - cropRect.left;
+ double pageHeight = cropRect.top - cropRect.bottom;
+ double final_w, final_h; //Width and height of cropped image.
pdftopdf_rotation_e pageRot = _cfPDFToPDFGetRotate(page);
if ((autorotate &&
pageWidth > pageHeight))) ||
(!autorotate &&
(param_orientation == ROT_90 || param_orientation == ROT_270)))
+ std::swap(pageHeight, pageWidth);
+ if (scale)
{
- std::swap(pageHeight,pageWidth);
- }
- if(scale)
- {
- if(width*pageHeight/pageWidth<=height)
+ if(width * pageHeight / pageWidth <= height)
{
final_w = width;
- final_h = width*pageHeight/pageWidth;
+ final_h = width * pageHeight / pageWidth;
}
- else{
- final_w = height*pageWidth/pageHeight;
+ else
+ {
+ final_w = height * pageWidth / pageHeight;
final_h = height;
}
}
}
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: After Cropping: %lf %lf %lf %lf",
- width,height,final_w,final_h);
- double posw = (width-final_w)/2,
- posh = (height-final_h)/2;
+ width, height, final_w, final_h);
+ double posw = (width - final_w) / 2,
+ posh = (height - final_h) / 2;
// posw, posh : pdftopdf_position_e along width and height respectively.
// Calculating required position.
- if(xpos==pdftopdf_position_e::LEFT)
- posw =0;
- else if(xpos==pdftopdf_position_e::RIGHT)
- posw*=2;
+ if (xpos == pdftopdf_position_e::LEFT)
+ posw = 0;
+ else if (xpos == pdftopdf_position_e::RIGHT)
+ posw *= 2;
- if(ypos==pdftopdf_position_e::TOP)
- posh*=2;
- else if(ypos==pdftopdf_position_e::BOTTOM)
- posh=0;
+ if (ypos == pdftopdf_position_e::TOP)
+ posh *= 2;
+ else if (ypos == pdftopdf_position_e::BOTTOM)
+ posh = 0;
// making _cfPDFToPDFPageRect for cropping.
currpage.left += posw;
currpage.bottom += posh;
- currpage.top =currpage.bottom+final_h;
- currpage.right=currpage.left+final_w;
- //Cropping.
+ currpage.top = currpage.bottom + final_h;
+ currpage.right = currpage.left + final_w;
+ // Cropping.
// TODO: Borders are covered by the image. buffer space?
- page.replaceKey("/TrimBox",_cfPDFToPDFMakeBox(currpage.left,currpage.bottom,currpage.right,currpage.top));
- page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(save_rotate));
- return _cfPDFToPDFGetRotate(page);
+ page.replaceKey("/TrimBox",
+ _cfPDFToPDFMakeBox(currpage.left, currpage.bottom,
+ currpage.right, currpage.top));
+ page.replaceOrRemoveKey("/Rotate", _cfPDFToPDFMakeRotate(save_rotate));
+
+ return (_cfPDFToPDFGetRotate(page));
}
-bool _cfPDFToPDFQPDFPageHandle::is_landscape(pdftopdf_rotation_e orientation)
+bool
+_cfPDFToPDFQPDFPageHandle::is_landscape(pdftopdf_rotation_e orientation)
{
page.assertInitialized();
pdftopdf_rotation_e save_rotate = _cfPDFToPDFGetRotate(page);
- if(orientation==ROT_0||orientation==ROT_180)
- page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(ROT_90));
+ if (orientation == ROT_0 || orientation == ROT_180)
+ page.replaceOrRemoveKey("/Rotate", _cfPDFToPDFMakeRotate(ROT_90));
else
- page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(ROT_0));
-
- _cfPDFToPDFPageRect currpage= _cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page));
- double width = currpage.right-currpage.left;
- double height = currpage.top-currpage.bottom;
- page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(save_rotate));
- if(width>height)
- return true;
- return false;
+ page.replaceOrRemoveKey("/Rotate", _cfPDFToPDFMakeRotate(ROT_0));
+
+ _cfPDFToPDFPageRect currpage =
+ _cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page));
+ double width = currpage.right - currpage.left;
+ double height = currpage.top - currpage.bottom;
+ page.replaceOrRemoveKey("/Rotate", _cfPDFToPDFMakeRotate(save_rotate));
+ if (width > height)
+ return (true);
+ return (false);
}
// TODO: better cropping
// TODO: test/fix with qsub rotation
-void _cfPDFToPDFQPDFPageHandle::add_subpage(const std::shared_ptr<_cfPDFToPDFPageHandle> &sub,float xpos,float ypos,float scale,const _cfPDFToPDFPageRect *crop) // {{{
+void
+_cfPDFToPDFQPDFPageHandle::add_subpage
+ (const std::shared_ptr<_cfPDFToPDFPageHandle> &sub,
+ float xpos,
+ float ypos,
+ float scale,
+ const _cfPDFToPDFPageRect *crop) // {{{
{
- auto qsub=dynamic_cast<_cfPDFToPDFQPDFPageHandle *>(sub.get());
+ auto qsub = dynamic_cast<_cfPDFToPDFQPDFPageHandle *>(sub.get());
DEBUG_assert(qsub);
- std::string xoname="/X"+QUtil::int_to_string((qsub->no!=-1)?qsub->no:++no);
- if (crop) {
- _cfPDFToPDFPageRect pg=qsub->get_rect(),tmp=*crop;
+ std::string xoname =
+ "/X" + QUtil::int_to_string((qsub->no != -1) ? qsub->no : ++ no);
+ if (crop)
+ {
+ _cfPDFToPDFPageRect pg = qsub->get_rect(),
+ tmp = *crop;
// we need to fix a too small cropbox.
- tmp.width=tmp.right-tmp.left;
- tmp.height=tmp.top-tmp.bottom;
- tmp.rotate_move(-_cfPDFToPDFGetRotate(qsub->page),tmp.width,tmp.height); // TODO TODO (pg.width? / unneeded?)
+ tmp.width = tmp.right - tmp.left;
+ tmp.height = tmp.top - tmp.bottom;
+ tmp.rotate_move(-_cfPDFToPDFGetRotate(qsub->page), tmp.width, tmp.height);
+ // TODO TODO (pg.width? / unneeded?)
// TODO: better
// TODO: we need to obey page./Rotate
- if (pg.width<tmp.width) {
- pg.right=pg.left+tmp.width;
- }
- if (pg.height<tmp.height) {
- pg.top=pg.bottom+tmp.height;
- }
+ if (pg.width < tmp.width)
+ pg.right = pg.left + tmp.width;
+ if (pg.height < tmp.height)
+ pg.top = pg.bottom + tmp.height;
- _cfPDFToPDFPageRect rect=ungetRect(pg,*qsub,ROT_0,qsub->page);
+ _cfPDFToPDFPageRect rect = ungetRect(pg, *qsub, ROT_0, qsub->page);
- qsub->page.replaceKey("/TrimBox",_cfPDFToPDFMakeBox(rect.left,rect.bottom,rect.right,rect.top));
+ qsub->page.replaceKey("/TrimBox",
+ _cfPDFToPDFMakeBox(rect.left, rect.bottom,
+ rect.right, rect.top));
// TODO? do everything for cropping here?
}
- xobjs[xoname]=_cfPDFToPDFMakeXObject(qsub->page.getOwningQPDF(),qsub->page); // trick: should be the same as page->getOwningQPDF() [only after it's made indirect]
+ xobjs[xoname] = _cfPDFToPDFMakeXObject(qsub->page.getOwningQPDF(),
+ qsub->page); // trick: should be the
+ // same as
+ // page->getOwningQPDF()
+ // [only after it's made
+ // indirect]
_cfPDFToPDFMatrix mtx;
- mtx.translate(xpos,ypos);
+ mtx.translate(xpos, ypos);
mtx.scale(scale);
- mtx.rotate(qsub->rotation); // TODO? -sub.rotation ? // TODO FIXME: this might need another translation!?
- if (crop) { // TODO? other technique: set trim-box before _cfPDFToPDFMakeXObject (but this modifies original page)
- mtx.translate(crop->left,crop->bottom);
+ mtx.rotate(qsub->rotation); // TODO? -sub.rotation ?
+ // TODO FIXME: this might need another
+ // translation!?
+ if (crop) // TODO? other technique: set trim-box before
+ // _cfPDFToPDFMakeXObject (but this modifies original page)
+ {
+ mtx.translate(crop->left, crop->bottom);
// crop->dump();
}
content.append("q\n ");
- content.append(mtx.get_string()+" cm\n ");
- if (crop) {
- content.append("0 0 "+QUtil::double_to_string(crop->right-crop->left)+" "+QUtil::double_to_string(crop->top-crop->bottom)+" re W n\n ");
- // content.append("0 0 "+QUtil::double_to_string(crop->right-crop->left)+" "+QUtil::double_to_string(crop->top-crop->bottom)+" re S\n ");
- }
- content.append(xoname+" Do\n");
+ content.append(mtx.get_string() + " cm\n ");
+ if (crop)
+ {
+ content.append("0 0 " + QUtil::double_to_string(crop->right-crop->left) +
+ " " + QUtil::double_to_string(crop->top-crop->bottom) +
+ " re W n\n ");
+ //content.append("0 0 " + QUtil::double_to_string(crop->right-crop->left) +
+ // " " + QUtil::double_to_string(crop->top-crop->bottom) +
+ // " re S\n ");
+ }
+ content.append(xoname + " Do\n");
content.append("Q\n");
}
// }}}
-void _cfPDFToPDFQPDFPageHandle::mirror() // {{{
+void
+_cfPDFToPDFQPDFPageHandle::mirror() // {{{
{
- _cfPDFToPDFPageRect orig=get_rect();
+ _cfPDFToPDFPageRect orig = get_rect();
- if (is_existing()) {
+ if (is_existing())
+ {
// need to wrap in XObject to keep patterns correct
// TODO? refactor into internal ..._subpage fn ?
- std::string xoname="/X"+QUtil::int_to_string(no);
+ std::string xoname = "/X" + QUtil::int_to_string(no);
- QPDFObjectHandle subpage=get(); // this->page, with rotation
+ QPDFObjectHandle subpage = get(); // this->page, with rotation
// replace all our data
- *this=_cfPDFToPDFQPDFPageHandle(subpage.getOwningQPDF(),orig.width,orig.height);
+ *this = _cfPDFToPDFQPDFPageHandle(subpage.getOwningQPDF(),
+ orig.width, orig.height);
- xobjs[xoname]=_cfPDFToPDFMakeXObject(subpage.getOwningQPDF(),subpage); // we can only now set this->xobjs
+ xobjs[xoname] = _cfPDFToPDFMakeXObject(subpage.getOwningQPDF(), subpage);
+ // we can only now set this->xobjs
// content.append(std::string("1 0 0 1 0 0 cm\n ");
- content.append(xoname+" Do\n");
+ content.append(xoname + " Do\n");
DEBUG_assert(!is_existing());
}
- static const char *pre="%pdftopdf cm\n";
+ static const char *pre = "%pdftopdf cm\n";
// Note: we don't change (TODO need to?) the media box
- std::string mrcmd("-1 0 0 1 "+
- QUtil::double_to_string(orig.right)+" 0 cm\n");
+ std::string mrcmd("-1 0 0 1 " +
+ QUtil::double_to_string(orig.right) + " 0 cm\n");
- content.insert(0,std::string(pre)+mrcmd);
+ content.insert(0, std::string(pre) + mrcmd);
}
// }}}
-void _cfPDFToPDFQPDFPageHandle::rotate(pdftopdf_rotation_e rot) // {{{
+void
+_cfPDFToPDFQPDFPageHandle::rotate(pdftopdf_rotation_e rot) // {{{
{
- rotation=rot; // "rotation += rot;" ?
+ rotation = rot; // "rotation += rot;" ?
}
// }}}
-void _cfPDFToPDFQPDFPageHandle::add_label(const _cfPDFToPDFPageRect &_rect, const std::string label) // {{{
+void
+_cfPDFToPDFQPDFPageHandle::add_label(const _cfPDFToPDFPageRect &_rect,
+ const std::string label) // {{{
{
DEBUG_assert(is_existing());
_cfPDFToPDFPageRect rect = ungetRect (_rect, *this, rotation, page);
- assert (rect.left <= rect.right);
- assert (rect.bottom <= rect.top);
+ DEBUG_assert(rect.left <= rect.right);
+ DEBUG_assert(rect.bottom <= rect.top);
// TODO: Only add in the font once, not once per page.
QPDFObjectHandle font = page.getOwningQPDF()->makeIndirectObject
boxcmd += "Q\n";
DEBUG_assert(page.getOwningQPDF()); // existing pages are always indirect
- static const char *pre="%pdftopdf q\n"
+ static const char *pre = "%pdftopdf q\n"
"q\n",
*post="%pdftopdf Q\n"
"Q\n";
- QPDFObjectHandle stm1=QPDFObjectHandle::newStream(page.getOwningQPDF(),
- std::string(pre)),
- stm2=QPDFObjectHandle::newStream(page.getOwningQPDF(),
- std::string(post) + boxcmd);
+ QPDFObjectHandle stm1 = QPDFObjectHandle::newStream(page.getOwningQPDF(),
+ std::string(pre)),
+ stm2 = QPDFObjectHandle::newStream(page.getOwningQPDF(),
+ std::string(post) +
+ boxcmd);
- page.addPageContents(stm1,true); // before
- page.addPageContents(stm2,false); // after
+ page.addPageContents(stm1, true); // before
+ page.addPageContents(stm2, false); // after
}
// }}}
-void _cfPDFToPDFQPDFPageHandle::debug(const _cfPDFToPDFPageRect &rect,float xpos,float ypos) // {{{
+void
+_cfPDFToPDFQPDFPageHandle::debug(const _cfPDFToPDFPageRect &rect,
+ float xpos,
+ float ypos) // {{{
{
DEBUG_assert(!is_existing());
- content.append(debug_box(rect,xpos,ypos));
+ content.append(debug_box(rect, xpos, ypos));
}
// }}}
-void _cfPDFToPDFQPDFProcessor::close_file() // {{{
+void
+_cfPDFToPDFQPDFProcessor::close_file() // {{{
{
pdf.reset();
- hasCM=false;
+ hasCM = false;
}
// }}}
// TODO? try/catch for PDF parsing errors?
-bool _cfPDFToPDFQPDFProcessor::load_file(FILE *f,pdftopdf_doc_t *doc,pdftopdf_arg_ownership_e take,int flatten_forms) // {{{
+bool
+_cfPDFToPDFQPDFProcessor::load_file(FILE *f,
+ pdftopdf_doc_t *doc,
+ pdftopdf_arg_ownership_e take,
+ int flatten_forms) // {{{
{
close_file();
- if (!f) {
- throw std::invalid_argument("load_file(NULL,...) not allowed");
- }
- try {
+
+ if (!f)
+ throw std::invalid_argument("load_file(NULL, ...) not allowed");
+ try
+ {
pdf.reset(new QPDF);
- } catch (...) {
- if (take==CF_PDFTOPDF_TAKE_OWNERSHIP) {
+ }
+ catch (...)
+ {
+ if (take == CF_PDFTOPDF_TAKE_OWNERSHIP)
fclose(f);
- }
throw;
}
- switch (take) {
- case CF_PDFTOPDF_WILL_STAY_ALIVE:
- try {
- pdf->processFile("temp file",f,false);
- } catch (const std::exception &e) {
- if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToPDF: load_file failed: %s", e.what());
- return false;
- }
- break;
- case CF_PDFTOPDF_TAKE_OWNERSHIP:
- try {
- pdf->processFile("temp file",f,true);
- } catch (const std::exception &e) {
- if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToPDF: load_file failed: %s", e.what());
- return false;
- }
- break;
- case CF_PDFTOPDF_MUST_DUPLICATE:
- if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToPDF: load_file with CF_PDFTOPDF_MUST_DUPLICATE is not supported");
- return false;
+
+ switch (take)
+ {
+ case CF_PDFTOPDF_WILL_STAY_ALIVE:
+ try
+ {
+ pdf->processFile("temp file", f, false);
+ }
+ catch (const std::exception &e)
+ {
+ if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
+ "cfFilterPDFToPDF: load_file failed: %s", e.what());
+ return (false);
+ }
+ break;
+ case CF_PDFTOPDF_TAKE_OWNERSHIP:
+ try
+ {
+ pdf->processFile("temp file", f, true);
+ }
+ catch (const std::exception &e)
+ {
+ if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
+ "cfFilterPDFToPDF: load_file failed: %s", e.what());
+ return (false);
+ }
+ break;
+ case CF_PDFTOPDF_MUST_DUPLICATE:
+ if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
+ "cfFilterPDFToPDF: load_file with CF_PDFTOPDF_MUST_DUPLICATE is not supported");
+ return (false);
}
+
start(flatten_forms);
- return true;
+ return (true);
}
// }}}
-bool _cfPDFToPDFQPDFProcessor::load_filename(const char *name,pdftopdf_doc_t *doc,int flatten_forms) // {{{
+bool
+_cfPDFToPDFQPDFProcessor::load_filename(const char *name,
+ pdftopdf_doc_t *doc,
+ int flatten_forms) // {{{
{
close_file();
- try {
+
+ try
+ {
pdf.reset(new QPDF);
pdf->processFile(name);
- } catch (const std::exception &e) {
+ }
+ catch (const std::exception &e)
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
"cfFilterPDFToPDF: load_filename failed: %s",e.what());
- return false;
+ return (false);
}
+
start(flatten_forms);
- return true;
+ return (true);
}
// }}}
-void _cfPDFToPDFQPDFProcessor::start(int flatten_forms) // {{{
+void
+_cfPDFToPDFQPDFProcessor::start(int flatten_forms) // {{{
{
DEBUG_assert(pdf);
- if (flatten_forms) {
+ if (flatten_forms)
+ {
QPDFAcroFormDocumentHelper afdh(*pdf);
afdh.generateAppearancesIfNeeded();
}
pdf->pushInheritedAttributesToPage();
- orig_pages=pdf->getAllPages();
+ orig_pages = pdf->getAllPages();
// remove them (just unlink, data still there)
- const int len=orig_pages.size();
- for (int iA=0;iA<len;iA++) {
+ const int len = orig_pages.size();
+ for (int iA = 0; iA < len; iA ++)
pdf->removePage(orig_pages[iA]);
- }
// we remove stuff that becomes defunct (probably) TODO
pdf->getRoot().removeKey("/PageMode");
}
// }}}
-bool _cfPDFToPDFQPDFProcessor::check_print_permissions(pdftopdf_doc_t *doc) // {{{
+bool
+_cfPDFToPDFQPDFProcessor::check_print_permissions(pdftopdf_doc_t *doc) // {{{
{
- if (!pdf) {
+ if (!pdf)
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
"cfFilterPDFToPDF: No PDF loaded");
- return false;
+ return (false);
}
- return pdf->allowPrintHighRes() || pdf->allowPrintLowRes(); // from legacy pdftopdf
+ return (pdf->allowPrintHighRes() ||
+ pdf->allowPrintLowRes()); // from legacy pdftopdf
}
// }}}
-std::vector<std::shared_ptr<_cfPDFToPDFPageHandle>> _cfPDFToPDFQPDFProcessor::get_pages(pdftopdf_doc_t *doc) // {{{
+std::vector<std::shared_ptr<_cfPDFToPDFPageHandle>>
+_cfPDFToPDFQPDFProcessor::get_pages(pdftopdf_doc_t *doc) // {{{
{
std::vector<std::shared_ptr<_cfPDFToPDFPageHandle>> ret;
- if (!pdf) {
+ if (!pdf)
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
"cfFilterPDFToPDF: No PDF loaded");
DEBUG_assert(0);
- return ret;
+ return (ret);
}
- const int len=orig_pages.size();
+ const int len = orig_pages.size();
ret.reserve(len);
- for (int iA=0;iA<len;iA++) {
- ret.push_back(std::shared_ptr<_cfPDFToPDFPageHandle>(new _cfPDFToPDFQPDFPageHandle(orig_pages[iA],iA+1)));
- }
- return ret;
+ for (int iA = 0; iA < len; iA ++)
+ ret.push_back(std::shared_ptr<_cfPDFToPDFPageHandle>(new _cfPDFToPDFQPDFPageHandle(orig_pages[iA], iA+1)));
+ return (ret);
}
// }}}
-std::shared_ptr<_cfPDFToPDFPageHandle> _cfPDFToPDFQPDFProcessor::new_page(float width,float height,pdftopdf_doc_t *doc) // {{{
+std::shared_ptr<_cfPDFToPDFPageHandle>
+_cfPDFToPDFQPDFProcessor::new_page(float width,
+ float height,
+ pdftopdf_doc_t *doc) // {{{
{
- if (!pdf) {
+ if (!pdf)
+ {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
"cfFilterPDFToPDF: No PDF loaded");
DEBUG_assert(0);
- return std::shared_ptr<_cfPDFToPDFPageHandle>();
+ return (std::shared_ptr<_cfPDFToPDFPageHandle>());
}
- return std::shared_ptr<_cfPDFToPDFQPDFPageHandle>(new _cfPDFToPDFQPDFPageHandle(pdf.get(),width,height));
- // return std::make_shared<_cfPDFToPDFQPDFPageHandle>(pdf.get(),width,height);
+ return (std::shared_ptr<_cfPDFToPDFQPDFPageHandle>(new _cfPDFToPDFQPDFPageHandle(pdf.get(), width, height)));
+ // return std::make_shared<_cfPDFToPDFQPDFPageHandle>(pdf.get(), width, height);
// problem: make_shared not friend
}
// }}}
-void _cfPDFToPDFQPDFProcessor::add_page(std::shared_ptr<_cfPDFToPDFPageHandle> page,bool front) // {{{
+void
+_cfPDFToPDFQPDFProcessor::add_page(std::shared_ptr<_cfPDFToPDFPageHandle> page,
+ bool front) // {{{
{
DEBUG_assert(pdf);
- auto qpage=dynamic_cast<_cfPDFToPDFQPDFPageHandle *>(page.get());
- if (qpage) {
- pdf->addPage(qpage->get(),front);
- }
+ auto qpage = dynamic_cast<_cfPDFToPDFQPDFPageHandle *>(page.get());
+ if (qpage)
+ pdf->addPage(qpage->get(), front);
}
// }}}
pdf->getRoot().removeKey("/PageLabels");
#endif
-void _cfPDFToPDFQPDFProcessor::multiply(int copies,bool collate) // {{{
+void
+_cfPDFToPDFQPDFProcessor::multiply(int copies,
+ bool collate) // {{{
{
DEBUG_assert(pdf);
- DEBUG_assert(copies>0);
+ DEBUG_assert(copies > 0);
- std::vector<QPDFObjectHandle> pages=pdf->getAllPages(); // need copy
- const int len=pages.size();
+ std::vector<QPDFObjectHandle> pages = pdf->getAllPages(); // need copy
+ const int len = pages.size();
- if (collate) {
- for (int iA=1;iA<copies;iA++) {
- for (int iB=0;iB<len;iB++) {
- pdf->addPage(pages[iB].shallowCopy(),false);
- }
- }
- } else {
- for (int iB=0;iB<len;iB++) {
- for (int iA=1;iA<copies;iA++) {
- pdf->addPageAt(pages[iB].shallowCopy(),false,pages[iB]);
- }
- }
+ if (collate)
+ {
+ for (int iA = 1; iA < copies; iA ++)
+ for (int iB = 0; iB < len; iB ++)
+ pdf->addPage(pages[iB].shallowCopy(), false);
+ }
+ else
+ {
+ for (int iB = 0; iB < len; iB ++)
+ for (int iA = 1; iA < copies; iA ++)
+ pdf->addPageAt(pages[iB].shallowCopy(), false, pages[iB]);
}
}
// }}}
// TODO? elsewhere?
-void _cfPDFToPDFQPDFProcessor::auto_rotate_all(bool dst_lscape,pdftopdf_rotation_e normal_landscape) // {{{
+void
+_cfPDFToPDFQPDFProcessor::auto_rotate_all(bool dst_lscape,
+ pdftopdf_rotation_e normal_landscape) // {{{
{
DEBUG_assert(pdf);
- const int len=orig_pages.size();
- for (int iA=0;iA<len;iA++) {
- QPDFObjectHandle page=orig_pages[iA];
+ const int len = orig_pages.size();
+ for (int iA = 0; iA < len; iA ++)
+ {
+ QPDFObjectHandle page = orig_pages[iA];
- pdftopdf_rotation_e src_rot=_cfPDFToPDFGetRotate(page);
+ pdftopdf_rotation_e src_rot = _cfPDFToPDFGetRotate(page);
// copy'n'paste from _cfPDFToPDFQPDFPageHandle::get_rect
- _cfPDFToPDFPageRect ret=_cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page));
- // ret.translate(-ret.left,-ret.bottom);
- ret.rotate_move(src_rot,ret.width,ret.height);
+ _cfPDFToPDFPageRect ret =
+ _cfPDFToPDFGetBoxAsRect(_cfPDFToPDFGetTrimBox(page));
+ // ret.translate(-ret.left, -ret.bottom);
+ ret.rotate_move(src_rot, ret.width, ret.height);
// ret.scale(_cfPDFToPDFGetUserUnit(page));
- const bool src_lscape=(ret.width>ret.height);
- if (src_lscape!=dst_lscape) {
- pdftopdf_rotation_e rotation=normal_landscape;
- // TODO? other rotation direction, e.g. if (src_rot==ROT_0)&&(param.orientation==ROT_270) ... etc.
- // rotation=ROT_270;
+ const bool src_lscape = (ret.width > ret.height);
+ if (src_lscape != dst_lscape)
+ {
+ pdftopdf_rotation_e rotation = normal_landscape;
+ // TODO? other rotation direction, e.g.
+ // if (src_rot == ROT_0) && (param.orientation == ROT_270) ... etc.
+ // rotation = ROT_270;
- page.replaceOrRemoveKey("/Rotate",_cfPDFToPDFMakeRotate(src_rot+rotation));
+ page.replaceOrRemoveKey("/Rotate",
+ _cfPDFToPDFMakeRotate(src_rot + rotation));
}
}
}
// }}}
-#include "qpdf-cm-private.h"
-
// TODO
-void _cfPDFToPDFQPDFProcessor::add_cm(const char *defaulticc,const char *outputicc) // {{{
+void
+_cfPDFToPDFQPDFProcessor::add_cm(const char *defaulticc,
+ const char *outputicc) // {{{
{
DEBUG_assert(pdf);
- if (_cfPDFToPDFHasOutputIntent(*pdf)) {
+ if (_cfPDFToPDFHasOutputIntent(*pdf))
return; // nothing to do
- }
- QPDFObjectHandle srcicc=_cfPDFToPDFSetDefaultICC(*pdf,defaulticc); // TODO? rename to putDefaultICC?
- _cfPDFToPDFAddDefaultRGB(*pdf,srcicc);
+ QPDFObjectHandle srcicc = _cfPDFToPDFSetDefaultICC(*pdf, defaulticc);
+ // TODO? rename to putDefaultICC?
+ _cfPDFToPDFAddDefaultRGB(*pdf, srcicc);
- _cfPDFToPDFAddOutputIntent(*pdf,outputicc);
+ _cfPDFToPDFAddOutputIntent(*pdf, outputicc);
- hasCM=true;
+ hasCM = true;
}
// }}}
-void _cfPDFToPDFQPDFProcessor::set_comments(const std::vector<std::string> &comments) // {{{
+void
+_cfPDFToPDFQPDFProcessor::set_comments
+ (const std::vector<std::string> &comments) // {{{
{
extraheader.clear();
- const int len=comments.size();
- for (int iA=0;iA<len;iA++) {
- DEBUG_assert(comments[iA].at(0)=='%');
+ const int len = comments.size();
+ for (int iA = 0; iA < len; iA ++)
+ {
+ DEBUG_assert(comments[iA].at(0) == '%');
extraheader.append(comments[iA]);
extraheader.push_back('\n');
}
}
// }}}
-void _cfPDFToPDFQPDFProcessor::emit_file(FILE *f,pdftopdf_doc_t *doc,pdftopdf_arg_ownership_e take) // {{{
+void
+_cfPDFToPDFQPDFProcessor::emit_file(FILE *f,
+ pdftopdf_doc_t *doc,
+ pdftopdf_arg_ownership_e take) // {{{
{
- if (!pdf) {
+ if (!pdf)
return;
- }
+
QPDFWriter out(*pdf);
- switch (take) {
- case CF_PDFTOPDF_WILL_STAY_ALIVE:
- out.setOutputFile("temp file",f,false);
- break;
- case CF_PDFTOPDF_TAKE_OWNERSHIP:
- out.setOutputFile("temp file",f,true);
- break;
- case CF_PDFTOPDF_MUST_DUPLICATE:
- if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
- "cfFilterPDFToPDF: emit_file with CF_PDFTOPDF_MUST_DUPLICATE is not supported");
- return;
- }
- if (hasCM) {
+ switch (take)
+ {
+ case CF_PDFTOPDF_WILL_STAY_ALIVE:
+ out.setOutputFile("temp file", f, false);
+ break;
+ case CF_PDFTOPDF_TAKE_OWNERSHIP:
+ out.setOutputFile("temp file", f, true);
+ break;
+ case CF_PDFTOPDF_MUST_DUPLICATE:
+ if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
+ "cfFilterPDFToPDF: emit_file with CF_PDFTOPDF_MUST_DUPLICATE is not supported");
+ return;
+ }
+ if (hasCM)
out.setMinimumPDFVersion("1.4");
- } else {
+ else
out.setMinimumPDFVersion("1.2");
- }
- if (!extraheader.empty()) {
+ if (!extraheader.empty())
out.setExtraHeaderText(extraheader);
- }
out.setPreserveEncryption(false);
out.write();
}
// }}}
-void _cfPDFToPDFQPDFProcessor::emit_filename(const char *name,pdftopdf_doc_t *doc) // {{{
+void
+_cfPDFToPDFQPDFProcessor::emit_filename(const char *name,
+ pdftopdf_doc_t *doc) // {{{
{
- if (!pdf) {
+ if (!pdf)
return;
- }
- // special case: name==NULL -> stdout
- QPDFWriter out(*pdf,name);
- if (hasCM) {
+
+ // special case: name == NULL -> stdout
+ QPDFWriter out(*pdf, name);
+ if (hasCM)
out.setMinimumPDFVersion("1.4");
- } else {
+ else
out.setMinimumPDFVersion("1.2");
- }
- if (!extraheader.empty()) {
+ if (!extraheader.empty())
out.setExtraHeaderText(extraheader);
- }
out.setPreserveEncryption(false);
- std::vector<QPDFObjectHandle> pages=pdf->getAllPages();
- int len=pages.size();
+ std::vector<QPDFObjectHandle> pages = pdf->getAllPages();
+ int len = pages.size();
if (len)
- out.write();
+ out.write();
else
- if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
- "cfFilterPDFToPDF: No pages left, outputting empty file.");
+ if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
+ "cfFilterPDFToPDF: No pages left, outputting empty file.");
}
// }}}
// TODO:
// loadPDF(); success?
-bool _cfPDFToPDFQPDFProcessor::has_acro_form() // {{{
+bool
+_cfPDFToPDFQPDFProcessor::has_acro_form() // {{{
{
- if (!pdf) {
- return false;
- }
- QPDFObjectHandle root=pdf->getRoot();
- if (!root.hasKey("/AcroForm")) {
+ if (!pdf)
return false;
- }
- return true;
+
+ QPDFObjectHandle root = pdf->getRoot();
+ if (!root.hasKey("/AcroForm"))
+ return (false);
+ return (true);
}
// }}}
#include "qpdf-pdftopdf-private.h"
+#include "qpdf-tools-private.h"
#include "cupsfilters/debug-internal.h"
#include <stdexcept>
#include <qpdf/QUtil.hh>
-_cfPDFToPDFPageRect _cfPDFToPDFGetBoxAsRect(QPDFObjectHandle box) // {{{
+
+_cfPDFToPDFPageRect
+_cfPDFToPDFGetBoxAsRect(QPDFObjectHandle box) // {{{
{
_cfPDFToPDFPageRect ret;
- ret.left=box.getArrayItem(0).getNumericValue();
- ret.bottom=box.getArrayItem(1).getNumericValue();
- ret.right=box.getArrayItem(2).getNumericValue();
- ret.top=box.getArrayItem(3).getNumericValue();
+ ret.left = box.getArrayItem(0).getNumericValue();
+ ret.bottom = box.getArrayItem(1).getNumericValue();
+ ret.right = box.getArrayItem(2).getNumericValue();
+ ret.top = box.getArrayItem(3).getNumericValue();
- ret.width=ret.right-ret.left;
- ret.height=ret.top-ret.bottom;
+ ret.width = ret.right - ret.left;
+ ret.height = ret.top - ret.bottom;
- return ret;
+ return (ret);
}
// }}}
-pdftopdf_rotation_e _cfPDFToPDFGetRotate(QPDFObjectHandle page) // {{{
+pdftopdf_rotation_e
+_cfPDFToPDFGetRotate(QPDFObjectHandle page) // {{{
{
- if (!page.hasKey("/Rotate")) {
- return ROT_0;
- }
- double rot=page.getKey("/Rotate").getNumericValue();
- rot=fmod(rot,360.0);
- if (rot<0) {
- rot+=360.0;
- }
- if (rot==90.0) { // CW
- return ROT_270; // CCW
- } else if (rot==180.0) {
- return ROT_180;
- } else if (rot==270.0) {
- return ROT_90;
- } else if (rot!=0.0) {
- throw std::runtime_error("Unexpected /Rotate value: "+QUtil::double_to_string(rot));
- }
- return ROT_0;
+ if (!page.hasKey("/Rotate"))
+ return (ROT_0);
+ double rot = page.getKey("/Rotate").getNumericValue();
+ rot = fmod(rot, 360.0);
+ if (rot < 0)
+ rot += 360.0;
+ if (rot == 90.0) // CW
+ return (ROT_270); // CCW
+ else if (rot == 180.0)
+ return (ROT_180);
+ else if (rot == 270.0)
+ return (ROT_90);
+ else if (rot != 0.0)
+ throw std::runtime_error("Unexpected /Rotate value: " +
+ QUtil::double_to_string(rot));
+ return (ROT_0);
}
// }}}
-double _cfPDFToPDFGetUserUnit(QPDFObjectHandle page) // {{{
+double
+_cfPDFToPDFGetUserUnit(QPDFObjectHandle page) // {{{
{
- if (!page.hasKey("/UserUnit")) {
+ if (!page.hasKey("/UserUnit"))
return 1.0;
- }
- return page.getKey("/UserUnit").getNumericValue();
+ return (page.getKey("/UserUnit").getNumericValue());
}
// }}}
-QPDFObjectHandle _cfPDFToPDFMakeRotate(pdftopdf_rotation_e rot) // {{{
+QPDFObjectHandle
+_cfPDFToPDFMakeRotate(pdftopdf_rotation_e rot) // {{{
{
- switch (rot) {
- case ROT_0:
- return QPDFObjectHandle::newNull();
- case ROT_90: // CCW
- return QPDFObjectHandle::newInteger(270); // CW
- case ROT_180:
- return QPDFObjectHandle::newInteger(180);
- case ROT_270:
- return QPDFObjectHandle::newInteger(90);
- default:
- throw std::invalid_argument("Bad rotation");
+ switch (rot)
+ {
+ case ROT_0:
+ return (QPDFObjectHandle::newNull());
+ case ROT_90: // CCW
+ return (QPDFObjectHandle::newInteger(270)); // CW
+ case ROT_180:
+ return (QPDFObjectHandle::newInteger(180));
+ case ROT_270:
+ return (QPDFObjectHandle::newInteger(90));
+ default:
+ throw std::invalid_argument("Bad rotation");
}
}
// }}}
-#include "qpdf-tools-private.h"
-
-QPDFObjectHandle _cfPDFToPDFGetRectAsBox(const _cfPDFToPDFPageRect &rect) // {{{
+QPDFObjectHandle
+_cfPDFToPDFGetRectAsBox(const _cfPDFToPDFPageRect &rect) // {{{
{
- return _cfPDFToPDFMakeBox(rect.left,rect.bottom,rect.right,rect.top);
+ return (_cfPDFToPDFMakeBox(rect.left, rect.bottom, rect.right, rect.top));
}
// }}}
-#include <qpdf/QUtil.hh>
-
_cfPDFToPDFMatrix::_cfPDFToPDFMatrix() // {{{
: ctm{1,0,0,1,0,0}
{
_cfPDFToPDFMatrix::_cfPDFToPDFMatrix(QPDFObjectHandle ar) // {{{
{
- if (ar.getArrayNItems()!=6) {
+ if (ar.getArrayNItems() != 6)
throw std::runtime_error("Not a ctm matrix");
- }
- for (int iA=0;iA<6;iA++) {
- ctm[iA]=ar.getArrayItem(iA).getNumericValue();
- }
+ for (int iA = 0; iA < 6; iA ++)
+ ctm[iA] = ar.getArrayItem(iA).getNumericValue();
}
// }}}
-_cfPDFToPDFMatrix &_cfPDFToPDFMatrix::rotate(pdftopdf_rotation_e rot) // {{{
+_cfPDFToPDFMatrix
+&_cfPDFToPDFMatrix::rotate(pdftopdf_rotation_e rot) // {{{
{
- switch (rot) {
- case ROT_0:
- break;
- case ROT_90:
- std::swap(ctm[0],ctm[2]);
- std::swap(ctm[1],ctm[3]);
- ctm[2]=-ctm[2];
- ctm[3]=-ctm[3];
- break;
- case ROT_180:
- ctm[0]=-ctm[0];
- ctm[3]=-ctm[3];
- break;
- case ROT_270:
- std::swap(ctm[0],ctm[2]);
- std::swap(ctm[1],ctm[3]);
- ctm[0]=-ctm[0];
- ctm[1]=-ctm[1];
- break;
- default:
- DEBUG_assert(0);
+ switch (rot)
+ {
+ case ROT_0:
+ break;
+ case ROT_90:
+ std::swap(ctm[0], ctm[2]);
+ std::swap(ctm[1], ctm[3]);
+ ctm[2] = -ctm[2];
+ ctm[3] = -ctm[3];
+ break;
+ case ROT_180:
+ ctm[0] = -ctm[0];
+ ctm[3] = -ctm[3];
+ break;
+ case ROT_270:
+ std::swap(ctm[0], ctm[2]);
+ std::swap(ctm[1], ctm[3]);
+ ctm[0] = -ctm[0];
+ ctm[1] = -ctm[1];
+ break;
+ default:
+ DEBUG_assert(0);
}
- return *this;
+ return (*this);
}
// }}}
// TODO: test
-_cfPDFToPDFMatrix &_cfPDFToPDFMatrix::rotate_move(pdftopdf_rotation_e rot,double width,double height) // {{{
+_cfPDFToPDFMatrix
+&_cfPDFToPDFMatrix::rotate_move(pdftopdf_rotation_e rot,
+ double width,
+ double height) // {{{
{
rotate(rot);
- switch (rot) {
- case ROT_0:
- break;
- case ROT_90:
- translate(width,0);
- break;
- case ROT_180:
- translate(width,height);
- break;
- case ROT_270:
- translate(0,height);
- break;
+ switch (rot)
+ {
+ case ROT_0:
+ break;
+ case ROT_90:
+ translate(width, 0);
+ break;
+ case ROT_180:
+ translate(width, height);
+ break;
+ case ROT_270:
+ translate(0, height);
+ break;
}
- return *this;
+ return (*this);
}
// }}}
-_cfPDFToPDFMatrix &_cfPDFToPDFMatrix::rotate(double rad) // {{{
+_cfPDFToPDFMatrix
+&_cfPDFToPDFMatrix::rotate(double rad) // {{{
{
_cfPDFToPDFMatrix tmp;
- tmp.ctm[0]=cos(rad);
- tmp.ctm[1]=sin(rad);
- tmp.ctm[2]=-sin(rad);
- tmp.ctm[3]=cos(rad);
+ tmp.ctm[0] = cos(rad);
+ tmp.ctm[1] = sin(rad);
+ tmp.ctm[2] = -sin(rad);
+ tmp.ctm[3] = cos(rad);
- return (*this*=tmp);
+ return (*this *= tmp);
}
// }}}
-_cfPDFToPDFMatrix &_cfPDFToPDFMatrix::translate(double tx,double ty) // {{{
+_cfPDFToPDFMatrix
+&_cfPDFToPDFMatrix::translate(double tx,
+ double ty) // {{{
{
- ctm[4]+=ctm[0]*tx+ctm[2]*ty;
- ctm[5]+=ctm[1]*tx+ctm[3]*ty;
- return *this;
+ ctm[4] += ctm[0] * tx + ctm[2] * ty;
+ ctm[5] += ctm[1] * tx + ctm[3] * ty;
+ return (*this);
}
// }}}
-_cfPDFToPDFMatrix &_cfPDFToPDFMatrix::scale(double sx,double sy) // {{{
+_cfPDFToPDFMatrix
+&_cfPDFToPDFMatrix::scale(double sx,
+ double sy) // {{{
{
- ctm[0]*=sx;
- ctm[1]*=sx;
- ctm[2]*=sy;
- ctm[3]*=sy;
- return *this;
+ ctm[0] *= sx;
+ ctm[1] *= sx;
+ ctm[2] *= sy;
+ ctm[3] *= sy;
+ return (*this);
}
// }}}
-_cfPDFToPDFMatrix &_cfPDFToPDFMatrix::operator*=(const _cfPDFToPDFMatrix &rhs) // {{{
+_cfPDFToPDFMatrix
+&_cfPDFToPDFMatrix::operator*=(const _cfPDFToPDFMatrix &rhs) // {{{
{
double tmp[6];
- std::copy(ctm,ctm+6,tmp);
- ctm[0] = tmp[0]*rhs.ctm[0] + tmp[2]*rhs.ctm[1];
- ctm[1] = tmp[1]*rhs.ctm[0] + tmp[3]*rhs.ctm[1];
+ std::copy(ctm, ctm + 6, tmp);
+
+ ctm[0] = tmp[0] * rhs.ctm[0] + tmp[2] * rhs.ctm[1];
+ ctm[1] = tmp[1] * rhs.ctm[0] + tmp[3] * rhs.ctm[1];
- ctm[2] = tmp[0]*rhs.ctm[2] + tmp[2]*rhs.ctm[3];
- ctm[3] = tmp[1]*rhs.ctm[2] + tmp[3]*rhs.ctm[3];
+ ctm[2] = tmp[0] * rhs.ctm[2] + tmp[2] * rhs.ctm[3];
+ ctm[3] = tmp[1] * rhs.ctm[2] + tmp[3] * rhs.ctm[3];
- ctm[4] = tmp[0]*rhs.ctm[4] + tmp[2]*rhs.ctm[5] + tmp[4];
- ctm[5] = tmp[1]*rhs.ctm[4] + tmp[3]*rhs.ctm[5] + tmp[5];
+ ctm[4] = tmp[0] * rhs.ctm[4] + tmp[2] * rhs.ctm[5] + tmp[4];
+ ctm[5] = tmp[1] * rhs.ctm[4] + tmp[3] * rhs.ctm[5] + tmp[5];
- return *this;
+ return (*this);
}
// }}}
-QPDFObjectHandle _cfPDFToPDFMatrix::get() const // {{{
+QPDFObjectHandle
+_cfPDFToPDFMatrix::get() const // {{{
{
- QPDFObjectHandle ret=QPDFObjectHandle::newArray();
+ QPDFObjectHandle ret = QPDFObjectHandle::newArray();
+
ret.appendItem(QPDFObjectHandle::newReal(ctm[0]));
ret.appendItem(QPDFObjectHandle::newReal(ctm[1]));
ret.appendItem(QPDFObjectHandle::newReal(ctm[2]));
ret.appendItem(QPDFObjectHandle::newReal(ctm[3]));
ret.appendItem(QPDFObjectHandle::newReal(ctm[4]));
ret.appendItem(QPDFObjectHandle::newReal(ctm[5]));
- return ret;
+
+ return (ret);
}
// }}}
-std::string _cfPDFToPDFMatrix::get_string() const // {{{
+std::string
+_cfPDFToPDFMatrix::get_string() const // {{{
{
std::string ret;
+
ret.append(QUtil::double_to_string(ctm[0]));
ret.append(" ");
ret.append(QUtil::double_to_string(ctm[1]));
ret.append(QUtil::double_to_string(ctm[4]));
ret.append(" ");
ret.append(QUtil::double_to_string(ctm[5]));
- return ret;
+
+ return (ret);
}
// }}}
QPDFObjectHandle _cfPDFToPDFGetTrimBox(QPDFObjectHandle page);
QPDFObjectHandle _cfPDFToPDFGetArtBox(QPDFObjectHandle page);
-QPDFObjectHandle _cfPDFToPDFMakePage(QPDF &pdf,const std::map<std::string,QPDFObjectHandle> &xobjs,QPDFObjectHandle mediabox,const std::string &content);
+QPDFObjectHandle _cfPDFToPDFMakePage(QPDF &pdf, const std::map<std::string,
+ QPDFObjectHandle> &xobjs,
+ QPDFObjectHandle mediabox,
+ const std::string &content);
-QPDFObjectHandle _cfPDFToPDFMakeBox(double x1,double y1,double x2,double y2);
+QPDFObjectHandle _cfPDFToPDFMakeBox(double x1, double y1, double x2, double y2);
-#endif
+#endif // !_CUPS_FILTERS_PDFTOPDF_QPDF_TOOLS_H_
#include "qpdf-tools-private.h"
-QPDFObjectHandle _cfPDFToPDFGetMediaBox(QPDFObjectHandle page) // {{{
+QPDFObjectHandle
+_cfPDFToPDFGetMediaBox(QPDFObjectHandle page) // {{{
{
- return page.getKey("/MediaBox");
+ return (page.getKey("/MediaBox"));
}
// }}}
-QPDFObjectHandle _cfPDFToPDFGetCropBox(QPDFObjectHandle page) // {{{
+QPDFObjectHandle
+_cfPDFToPDFGetCropBox(QPDFObjectHandle page) // {{{
{
- if (page.hasKey("/CropBox")) {
- return page.getKey("/CropBox");
- }
- return page.getKey("/MediaBox");
+ if (page.hasKey("/CropBox"))
+ return (page.getKey("/CropBox"));
+ return (page.getKey("/MediaBox"));
}
// }}}
-QPDFObjectHandle _cfPDFToPDFGetBleedBox(QPDFObjectHandle page) // {{{
+QPDFObjectHandle
+_cfPDFToPDFGetBleedBox(QPDFObjectHandle page) // {{{
{
- if (page.hasKey("/BleedBox")) {
- return page.getKey("/BleedBox");
- }
- return _cfPDFToPDFGetCropBox(page);
+ if (page.hasKey("/BleedBox"))
+ return (page.getKey("/BleedBox"));
+ return (_cfPDFToPDFGetCropBox(page));
}
// }}}
-QPDFObjectHandle _cfPDFToPDFGetTrimBox(QPDFObjectHandle page) // {{{
+QPDFObjectHandle
+_cfPDFToPDFGetTrimBox(QPDFObjectHandle page) // {{{
{
- if (page.hasKey("/TrimBox")) {
- return page.getKey("/TrimBox");
- }
- return _cfPDFToPDFGetCropBox(page);
+ if (page.hasKey("/TrimBox"))
+ return (page.getKey("/TrimBox"));
+ return (_cfPDFToPDFGetCropBox(page));
}
// }}}
-QPDFObjectHandle _cfPDFToPDFGetArtBox(QPDFObjectHandle page) // {{{
+QPDFObjectHandle
+_cfPDFToPDFGetArtBox(QPDFObjectHandle page) // {{{
{
- if (page.hasKey("/ArtBox")) {
- return page.getKey("/ArtBox");
- }
- return _cfPDFToPDFGetCropBox(page);
+ if (page.hasKey("/ArtBox"))
+ return (page.getKey("/ArtBox"));
+ return (_cfPDFToPDFGetCropBox(page));
}
// }}}
-QPDFObjectHandle _cfPDFToPDFMakePage(QPDF &pdf,const std::map<std::string,QPDFObjectHandle> &xobjs,QPDFObjectHandle mediabox,const std::string &content) // {{{
+QPDFObjectHandle
+_cfPDFToPDFMakePage(QPDF &pdf,
+ const std::map<std::string,QPDFObjectHandle> &xobjs,
+ QPDFObjectHandle mediabox,
+ const std::string &content) // {{{
{
- QPDFObjectHandle ret=QPDFObjectHandle::newDictionary();
- ret.replaceKey("/Type",QPDFObjectHandle::newName("/Page"));
+ QPDFObjectHandle ret = QPDFObjectHandle::newDictionary();
+ ret.replaceKey("/Type", QPDFObjectHandle::newName("/Page"));
- auto resdict=QPDFObjectHandle::newDictionary();
- resdict.replaceKey("/XObject",QPDFObjectHandle::newDictionary(xobjs));
- ret.replaceKey("/Resources",resdict);
- ret.replaceKey("/MediaBox",mediabox);
- ret.replaceKey("/Contents",QPDFObjectHandle::newStream(&pdf,content));
+ auto resdict = QPDFObjectHandle::newDictionary();
+ resdict.replaceKey("/XObject", QPDFObjectHandle::newDictionary(xobjs));
+ ret.replaceKey("/Resources", resdict);
+ ret.replaceKey("/MediaBox", mediabox);
+ ret.replaceKey("/Contents", QPDFObjectHandle::newStream(&pdf, content));
- return ret;
+ return (ret);
}
// }}}
-QPDFObjectHandle _cfPDFToPDFMakeBox(double x1,double y1,double x2,double y2) // {{{
+QPDFObjectHandle
+_cfPDFToPDFMakeBox(double x1,
+ double y1,
+ double x2,
+ double y2) // {{{
{
- QPDFObjectHandle ret=QPDFObjectHandle::newArray();
+ QPDFObjectHandle ret = QPDFObjectHandle::newArray();
ret.appendItem(QPDFObjectHandle::newReal(x1));
ret.appendItem(QPDFObjectHandle::newReal(y1));
ret.appendItem(QPDFObjectHandle::newReal(x2));
ret.appendItem(QPDFObjectHandle::newReal(y2));
- return ret;
+ return (ret);
}
// }}}
QPDFObjectHandle _cfPDFToPDFMakeXObject(QPDF *pdf, QPDFObjectHandle page);
-#endif
+#endif // !_CUPS_FILTERS_PDFTOPDF_QPDF_XOBJECT_H_
// TODO: need to remove Struct Parent stuff (or fix)
-// NOTE: use /TrimBox to position content inside Nup cell, /BleedBox to clip against
+// NOTE: use /TrimBox to position content inside Nup cell,
+// /BleedBox to clip against
class CombineFromContents_Provider : public QPDFObjectHandle::StreamDataProvider {
public:
{
}
-void CombineFromContents_Provider::provideStreamData(int objid, int generation, Pipeline* pipeline)
+void
+CombineFromContents_Provider::provideStreamData(int objid,
+ int generation,
+ Pipeline* pipeline)
{
Pl_Concatenate concat("concat", pipeline);
- const int clen=contents.size();
- for (int iA=0;iA<clen;iA++) {
+ const int clen = contents.size();
+ for (int iA = 0; iA < clen; iA ++)
contents[iA].pipeStreamData(&concat, true, false, false);
- }
concat.manualFinish();
}
-/*
- To convert a page to an XObject there are several keys to consider:
-
- /Type /Page -> /Type /XObject (/Type optional for XObject)
- -> /Subtype /Form
- -> [/FormType 1] (optional)
- /Parent ? ? R -> remove
- /Resources dict -> copy
- /MediaBox rect [/CropBox /BleedBox /TrimBox /ArtBox]
- -> /BBox (use TrimBox [+ Bleed consideration?], with fallback to /MediaBox)
- note that /BBox is in *Form Space*, see /Matrix!
- [/BoxColorInfo dict] (used for guidelines that may be shown by viewer)
- -> ignore/remove
- [/Contents asfd] -> concatenate into stream data of the XObject (page is a dict, XObject a stream)
-
- [/Rotate 90] ... must be handled (either use CTM where XObject is /used/ -- or set /Matrix)
- [/UserUnit] (PDF 1.6) -> to /Matrix ? -- it MUST be handled.
-
- [/Group dict] -> copy
- [/Thumb stream] -> remove, not needed any more / would have to be regenerated (combined)
- [/B] article beads -- ignore for now
- [/Dur] -> remove (transition duration)
- [/Trans] -> remove (transitions)
- [/AA] -> remove (additional-actions)
-
- [/Metadata] what shall we do?? (kill: we can't combine XML)
- [/PieceInfo] -> remove, we can't combine private app data (?)
- [/LastModified date] (opt except /PieceInfo) -> see there
-
- [/PZ] -> remove, can't combine/keep (preferred zoom level)
- [/SeparationInfo] -> remove, no way to keep this (needed for separation)
-
- [/ID] related to web capture -- ignore/kill?
- [/StructParents] (opt except pdf contains "structural content items")
- -> copy (is this correct?)
-
- [/Annots] annotations -- ignore for now
- [/Tabs] tab order for annotations (/R row, /C column, /S structure order) -- see /Annots
-
- [/TemplateInstantiated] (reqd, if page was created from named page obj, 1.5) -- ? just ignore?
- [/PresSteps] -> remove (sub-page navigation for presentations) [no subpage navigation for printing / nup]
- [/VP] viewport rects -- ignore/drop or recalculate into new page
-
-*/
-QPDFObjectHandle _cfPDFToPDFMakeXObject(QPDF *pdf,QPDFObjectHandle page)
+//
+// To convert a page to an XObject there are several keys to consider:
+//
+// /Type /Page -> /Type /XObject (/Type optional for XObject)
+// -> /Subtype /Form
+// -> [/FormType 1] (optional)
+// /Parent ? ? R -> remove
+// /Resources dict -> copy
+// /MediaBox rect [/CropBox /BleedBox /TrimBox /ArtBox]
+// -> /BBox (use TrimBox [+ Bleed consideration?],
+// with fallback to /MediaBox)
+// note that /BBox is in *Form Space*, see /Matrix!
+// [/BoxColorInfo dict] (used for guidelines that may be shown by viewer)
+// -> ignore/remove
+// [/Contents asfd] -> concatenate into stream data of the XObject
+// (page is a dict, XObject a stream)
+//
+// [/Rotate 90] ... must be handled (either use CTM where XObject is
+// /used/ -- or set /Matrix)
+// [/UserUnit] (PDF 1.6) -> to /Matrix ? -- it MUST be handled.
+//
+// [/Group dict] -> copy
+// [/Thumb stream] -> remove, not needed any more / would have to be
+// regenerated (combined)
+// [/B] article beads -- ignore for now
+// [/Dur] -> remove (transition duration)
+// [/Trans] -> remove (transitions)
+// [/AA] -> remove (additional-actions)
+//
+// [/Metadata] what shall we do?? (kill: we can't combine XML)
+// [/PieceInfo] -> remove, we can't combine private app data (?)
+// [/LastModified date] (opt except /PieceInfo) -> see there
+//
+// [/PZ] -> remove, can't combine/keep (preferred zoom level)
+// [/SeparationInfo] -> remove, no way to keep this (needed for separation)
+//
+// [/ID] related to web capture -- ignore/kill?
+// [/StructParents] (opt except pdf contains "structural content items")
+// -> copy (is this correct?)
+//
+// [/Annots] annotations -- ignore for now
+// [/Tabs] tab order for annotations (/R row, /C column,
+// /S structure order) -- see /Annots
+//
+// [/TemplateInstantiated] (reqd, if page was created from named page obj,
+// 1.5) -- ? just ignore?
+// [/PresSteps] -> remove (sub-page navigation for presentations)
+// [no subpage navigation for printing / nup]
+// [/VP] viewport rects -- ignore/drop or recalculate into new
+// page
+//
+
+QPDFObjectHandle
+_cfPDFToPDFMakeXObject(QPDF *pdf, QPDFObjectHandle page)
{
page.assertPageObject();
- QPDFObjectHandle ret=QPDFObjectHandle::newStream(pdf);
- QPDFObjectHandle dict=ret.getDict();
+ QPDFObjectHandle ret = QPDFObjectHandle::newStream(pdf);
+ QPDFObjectHandle dict = ret.getDict();
- dict.replaceKey("/Type",QPDFObjectHandle::newName("/XObject")); // optional
- dict.replaceKey("/Subtype",QPDFObjectHandle::newName("/Form")); // required
- // dict.replaceKey("/FormType",QPDFObjectHandle::newInteger(1)); // optional
+ dict.replaceKey("/Type", QPDFObjectHandle::newName("/XObject")); // optional
+ dict.replaceKey("/Subtype", QPDFObjectHandle::newName("/Form")); // required
+ // dict.replaceKey("/FormType", QPDFObjectHandle::newInteger(1)); // optional
- QPDFObjectHandle box=_cfPDFToPDFGetTrimBox(page); // already in "form space"
- dict.replaceKey("/BBox",box); // reqd
+ QPDFObjectHandle box = _cfPDFToPDFGetTrimBox(page); // already in "form space"
+ dict.replaceKey("/BBox", box); // reqd
- // [/Matrix .] ... default is [1 0 0 1 0 0]; we incorporate /UserUnit and /Rotate here
+ // [/Matrix .] ... default is [1 0 0 1 0 0]; we incorporate /UserUnit and
+ // /Rotate here
_cfPDFToPDFMatrix mtx;
- if (page.hasKey("/UserUnit")) {
+ if (page.hasKey("/UserUnit"))
mtx.scale(page.getKey("/UserUnit").getNumericValue());
- }
// transform, so that bbox is [0 0 w h] (in outer space, but after UserUnit)
- pdftopdf_rotation_e rot=_cfPDFToPDFGetRotate(page);
+ pdftopdf_rotation_e rot = _cfPDFToPDFGetRotate(page);
// calculate rotation effect on [0 0 w h]
- _cfPDFToPDFPageRect bbox=_cfPDFToPDFGetBoxAsRect(box),tmp;
- tmp.left=0;
- tmp.bottom=0;
- tmp.right=0;
- tmp.top=0;
- tmp.rotate_move(rot,bbox.width,bbox.height);
+ _cfPDFToPDFPageRect bbox = _cfPDFToPDFGetBoxAsRect(box),
+ tmp;
+ tmp.left = 0;
+ tmp.bottom = 0;
+ tmp.right = 0;
+ tmp.top = 0;
+ tmp.rotate_move(rot, bbox.width, bbox.height);
// tmp.rotate_move moves the bbox; we must achieve this move with the matrix.
- mtx.translate(tmp.left,tmp.bottom); // 1. move origin to end up at left,bottom after rotation
+ mtx.translate(tmp.left, tmp.bottom); // 1. move origin to end up at
+ // left,bottom after rotation
mtx.rotate(rot); // 2. rotate coordinates according to /Rotate
- mtx.translate(-bbox.left,-bbox.bottom); // 3. move origin from 0,0 to "form space"
+ mtx.translate(-bbox.left, -bbox.bottom); // 3. move origin from 0,0 to
+ // "form space"
- dict.replaceKey("/Matrix",mtx.get());
+ dict.replaceKey("/Matrix", mtx.get());
- dict.replaceKey("/Resources",page.getKey("/Resources"));
- if (page.hasKey("/Group")) {
- dict.replaceKey("/Group",page.getKey("/Group")); // (transparency); opt, copy if there
- }
+ dict.replaceKey("/Resources", page.getKey("/Resources"));
+ if (page.hasKey("/Group"))
+ dict.replaceKey("/Group", page.getKey("/Group")); // (transparency); opt,
+ // copy if there
- // ?? /StructParents ... can basically copy from page, but would need fixup in Structure Tree
+ // ?? /StructParents ... can basically copy from page, but would need
+ // fixup in Structure Tree
// FIXME: remove (globally) Tagged spec (/MarkInfo), and Structure Tree
- // Note: [/Name] (reqd. only in 1.0 -- but there we even can't use our normal img/patter procedures)
+ // Note: [/Name] (reqd. only in 1.0 -- but there we even can't use our
+ // normal img/patter procedures)
// none:
- // QPDFObjectHandle filter=QPDFObjectHandle::newArray();
- // QPDFObjectHandle decode_parms=QPDFObjectHandle::newArray();
+ // QPDFObjectHandle filter = QPDFObjectHandle::newArray();
+ // QPDFObjectHandle decode_parms = QPDFObjectHandle::newArray();
// null leads to use of "default filters" from qpdf's settings
- QPDFObjectHandle filter=QPDFObjectHandle::newNull();
- QPDFObjectHandle decode_parms=QPDFObjectHandle::newNull();
+ QPDFObjectHandle filter = QPDFObjectHandle::newNull();
+ QPDFObjectHandle decode_parms = QPDFObjectHandle::newNull();
- std::vector<QPDFObjectHandle> contents=page.getPageContents(); // (will assertPageObject)
+ std::vector<QPDFObjectHandle> contents = page.getPageContents();
+ // (will assertPageObject)
- auto ph=PointerHolder<QPDFObjectHandle::StreamDataProvider>(new CombineFromContents_Provider(contents));
- ret.replaceStreamData(ph,filter,decode_parms);
+ auto ph = PointerHolder<QPDFObjectHandle::StreamDataProvider>(new CombineFromContents_Provider(contents));
+ ret.replaceStreamData(ph, filter, decode_parms);
- return ret;
+ return (ret);
}
-/*
- we will have to fix up the structure tree (e.g. /K in element), when copying /StructParents;
- (there is /Pg, which has to point to the containing page, /Stm when it's not part of the page's content stream
- i.e. when it is in our XObject!; then there is /StmOwn ...)
- when not copying, we have to remove the structure tree completely (also /MarkInfo dict)
- Still this might not be sufficient(?), as there are probably BDC and EMC operators in the stream.
-*/
-
-/* /XObject /Form has
- [/Type /XObject]
- /Subtype /Form
- [/FormType 1]
- /BBox rect from crop box, or recalculate
- [/Matrix .] ... default is [1 0 0 1 0 0] --- we have to incorporate /UserUnit here?!
- [/Resources dict] from page.
- [/Group dict] used for transparency -- can copy from page
- [/Ref dict] not needed; for external reference
- [/Metadata] not, as long we can not combine.
- [/PieceInfo] can copy, but not combine
- [/LastModified date] copy if /PieceInfo there
- [/StructParent] . don't want to be one ... have to read more spec
- [/StructParents] . copy from page!
- [/OPI] no opi version. don't set
- [/OC] is this optional content? NO! not needed.
- [/Name] (only reqd. in 1.0 -- but there we even can't use our normal img/patter procedures)
-*/
+//
+// we will have to fix up the structure tree (e.g. /K in element), when copying
+// /StructParents;
+// (there is /Pg, which has to point to the containing page, /Stm when it's not
+// part of the page's content stream
+// i.e. when it is in our XObject!; then there is /StmOwn ...)
+// when not copying, we have to remove the structure tree completely
+// (also /MarkInfo dict)
+// Still this might not be sufficient(?), as there are probably BDC and EMC
+// operators in the stream.
+//
+//
+// /XObject /Form has
+// [/Type /XObject]
+// /Subtype /Form
+// [/FormType 1]
+// /BBox rect from crop box, or recalculate
+// [/Matrix .] ... default is [1 0 0 1 0 0] --- we have to incorporate
+// /UserUnit here?!
+// [/Resources dict] from page.
+// [/Group dict] used for transparency -- can copy from page
+// [/Ref dict] not needed; for external reference
+// [/Metadata] not, as long we can not combine.
+// [/PieceInfo] can copy, but not combine
+// [/LastModified date] copy if /PieceInfo there
+// [/StructParent] . don't want to be one ... have to read more spec
+// [/StructParents] . copy from page!
+// [/OPI] no opi version. don't set
+// [/OC] is this optional content? NO! not needed.
+// [/Name] (only reqd. in 1.0 -- but there we even can't use our
+// normal img/patter procedures)
+//