Back to index

scribus-ng  1.3.4.dfsg+svn20071115
objpdffile.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "objpdffile.h"
00008 #include "cmdutil.h"
00009 #include "bookpalette.h"
00010 #include "prefsmanager.h"
00011 #include "scribusdoc.h"
00012 #include "scribuscore.h"
00013 
00014 #include <structmember.h>
00015 #include <qfileinfo.h>
00016 #include <vector>
00017 
00018 // these functions are located at utils.cpp
00019 void SCRIBUS_API ReOrderText(ScribusDoc *doc, ScribusView *view);
00020 // end of utils.cpp
00021 //this is in file scribus.cpp
00022 
00023 
00024 static int minmaxi(int val, int min, int max)
00025 {
00026        if (val < min)
00027               return min;
00028        else if (val > max)
00029               return max;
00030        else return val;
00031 }
00032 
00033 static double minmaxd(double val, double min, double max)
00034 {
00035        if (val < min)
00036               return min;
00037        else if (val > max)
00038               return max;
00039        else return val;
00040 }
00041 
00042 typedef struct
00043 {
00044        PyObject_HEAD
00045        PyObject *file; // string - file to save into
00046        PyObject *fonts; // list of string - fonts to  embed
00047        PyObject *pages; // list of int - pages to print
00048        int thumbnails; // bool -
00049        int compress; // bool -
00050        int compressmtd; // int - 0=automatic 1=jpeg 2=zip 3=none
00051        int quality; // int - 0=Maximum 4=minimum
00052        PyObject *resolution; // int - 35 - 4000 default=300 dpi
00053        PyObject *downsample; // int - 35 - 4000 default=0 do not downsample ; other downsample to this resolution
00054        int bookmarks; // bool -
00055        int binding; // bool - 0 -left margin 1 -right margin
00056        int presentation; // bool -
00057        PyObject *effval; // list of list of 5 int - effect to apply to each page during presentation
00058        int article; // bool -
00059        int encrypt; // bool -
00060        int uselpi; // bool -
00061        int usespot;
00062        int domulti;
00063        PyObject *lpival; // list of elements which has structure [siii]
00064        PyObject *owner; // string - owner's password
00065        PyObject *user; // string - user's password
00066        int aprint; // bool -  allow printing
00067        int achange; // bool - allow changing
00068        int acopy; // bool - allow copying
00069        int aanot; // bool - allow adding annotation and fields
00070        int version; // int - version of pdf (12=1.2; 13=1.3; 14=1.4)
00071        int outdst; // int - output destination 0 - screen, 1 - printer
00072 
00073        int profiles; // bool
00074        int profilei; // bool
00075        int intents; // int - 0 - 3 QString tmp_ip[] = { tr("Perceptual"), tr("Relative Colorimetric"), tr("Saturation"), tr("Absolute Colorimetric")};
00076        int intenti; // int - 0 - 3 QString tmp_ip[] = { tr("Perceptual"), tr("Relative Colorimetric"), tr("Saturation"), tr("Absolute Colorimetric")};
00077        int noembicc; // bool - "Don't use embedded ICC profiles"
00078        PyObject *solidpr; // string
00079        PyObject *imagepr; // string
00080        PyObject *printprofc; // string
00081        PyObject *info; // string
00082        double bleedt; // double - 0 to hight of page
00083        double bleedl; // double - 0 to width of page
00084        double bleedr; // double - 0 to width of page
00085        double bleedb; // double - 0 to hight of page
00086 
00087 } PDFfile;
00088 
00089 static void PDFfile_dealloc(PDFfile *self)
00090 {
00091        Py_XDECREF(self->file);
00092        Py_XDECREF(self->fonts);
00093        Py_XDECREF(self->pages);
00094        Py_XDECREF(self->resolution);
00095        Py_XDECREF(self->downsample);
00096        Py_XDECREF(self->effval);
00097        Py_XDECREF(self->lpival);
00098        Py_XDECREF(self->owner);
00099        Py_XDECREF(self->user);
00100        Py_XDECREF(self->solidpr);
00101        Py_XDECREF(self->imagepr);
00102        Py_XDECREF(self->printprofc);
00103        Py_XDECREF(self->info);
00104        self->ob_type->tp_free((PyObject *)self);
00105 }
00106 
00107 static PyObject * PDFfile_new(PyTypeObject *type, PyObject */*args*/, PyObject */*kwds*/)
00108 {
00109 // do not create new object if there is no opened document
00110        if (!ScCore->primaryMainWindow()->HaveDoc) {
00111               PyErr_SetString(PyExc_SystemError, "Need to open document first");
00112               return NULL;
00113        }
00114 
00115        PDFfile *self;
00116 
00117        self = (PDFfile *)type->tp_alloc(type, 0);
00118        if (self) {
00119 // set file attribute
00120               self->file = PyString_FromString("");
00121               if (!self->file){
00122                      Py_DECREF(self);
00123                      return NULL;
00124               }
00125 // set fonts attribute
00126               self->fonts = PyList_New(0);
00127               if (!self->fonts){
00128                      Py_DECREF(self);
00129                      return NULL;
00130               }
00131 // set pages attribute
00132               self->pages = PyList_New(0);
00133               if (self->pages == NULL){
00134                      Py_DECREF(self);
00135                      return NULL;
00136               }
00137 // set thumbnails attribute
00138               self->thumbnails = 0;
00139 // set compress attribute
00140               self->compress = 0;
00141 // set compressmtd attribute
00142               self->compressmtd = 0;
00143 // set quality attribute
00144               self->quality = 0;
00145 // set resolution attribute
00146               self->resolution = PyInt_FromLong(300);
00147               if (!self->resolution){
00148                      Py_DECREF(self);
00149                      return NULL;
00150               }
00151 // set downsample attribute
00152               self->downsample = PyInt_FromLong(0);
00153               if (!self->downsample){
00154                      Py_DECREF(self);
00155                      return NULL;
00156               }
00157 // set bookmarks attribute
00158               self->bookmarks = 0;
00159 // set binding attribute
00160               self->binding = 0;
00161 // set presentation attribute
00162               self->presentation = 0;
00163 // set effval attribute
00164               self->effval = PyList_New(0);
00165               if (!self->effval){
00166                      Py_DECREF(self);
00167                      return NULL;
00168               }
00169 // set article attribute
00170               self->article = 0;
00171 // set encrypt attribute
00172               self->encrypt = 0;
00173 // set uselpi attribute
00174               self->uselpi = 0;
00175               self->usespot = 1;
00176               self->domulti = 0;
00177 // set lpival attribute
00178               self->lpival = PyList_New(0);
00179               if (!self->lpival){
00180                      Py_DECREF(self);
00181                      return NULL;
00182               }
00183 // set owner attribute
00184               self->owner = PyString_FromString("");
00185               if (!self->owner){
00186                      Py_DECREF(self);
00187                      return NULL;
00188               }
00189 // set user attribute
00190               self->user = PyString_FromString("");
00191               if (!self->user){
00192                      Py_DECREF(self);
00193                      return NULL;
00194               }
00195 // set aprint attribute
00196               self->aprint = 1;
00197 // set achange attribute
00198               self->achange = 1;
00199 // set acopy attribute
00200               self->acopy = 1;
00201 // set aanot attribute
00202               self->aanot = 1;
00203 // set version attribute
00204               self->version = 14;
00205 // set output attribute
00206               self->outdst = 0;
00207 
00208 
00209               self->profiles = 0; // bool
00210               self->profilei = 0; // bool
00211               self->intents = 0; // int - 0 - ?
00212               self->intenti = 0; // int - 0 - ?
00213               self->noembicc = 0; // bool
00214               self->solidpr = PyString_FromString("");
00215               if (!self->solidpr){
00216                      Py_DECREF(self);
00217                      return NULL;
00218               }
00219               self->imagepr = PyString_FromString("");
00220               if (!self->imagepr){
00221                      Py_DECREF(self);
00222                      return NULL;
00223               }
00224               self->printprofc = PyString_FromString("");
00225               if (!self->printprofc){
00226                      Py_DECREF(self);
00227                      return NULL;
00228               }
00229               self->info = PyString_FromString("");
00230               if (!self->info){
00231                      Py_DECREF(self);
00232                      return NULL;
00233               }
00234               self->bleedt = 0; // double -
00235               self->bleedl = 0; // double -
00236               self->bleedr = 0; // double -
00237               self->bleedb = 0; // double -
00238        }
00239        return (PyObject *) self;
00240 }
00241 
00242 static int PDFfile_init(PDFfile *self, PyObject */*args*/, PyObject */*kwds*/)
00243 {
00244        int i;
00245        if (!ScCore->primaryMainWindow()->HaveDoc) {
00246               PyErr_SetString(PyExc_SystemError, "Must open doc first");
00247               return -1;
00248        }
00249 // defaut save into file
00250        QString tf = ScCore->primaryMainWindow()->doc->PDF_Options.Datei;
00251        if (tf.isEmpty()) {
00252               QFileInfo fi = QFileInfo(ScCore->primaryMainWindow()->doc->DocName);
00253               tf = fi.dirPath()+"/"+fi.baseName()+".pdf";
00254        }
00255        PyObject *file = NULL;
00256        file = PyString_FromString(tf.ascii());
00257        if (file){
00258               Py_DECREF(self->file);
00259               self->file = file;
00260        } else {
00261               PyErr_SetString(PyExc_SystemError, "Can not initialize 'file' attribute");
00262               return -1;
00263        }
00264 // embed all used fonts
00265        PyObject *fonts = NULL;
00266        fonts = PyList_New(0);
00267        if (fonts){
00268               Py_DECREF(self->fonts);
00269               self->fonts = fonts;
00270        } else {
00271               PyErr_SetString(PyExc_SystemError, "Can not initialize 'fonts' attribute");
00272               return -1;
00273        }
00274        // get all used fonts
00275        QMap<QString,int> ReallyUsed = ScCore->primaryMainWindow()->doc->UsedFonts;
00276        // create list of all used fonts
00277        QValueList<QString> tmpEm;
00278        tmpEm = ReallyUsed.keys();
00279        QValueList<QString>::Iterator itef;
00280        for (itef = tmpEm.begin(); itef != tmpEm.end(); ++itef) {
00281 // AV: dunno what this is for, but it looks as if it's the only place where HasMetrics is used...
00282 //            if (PrefsManager::instance()->appPrefs.AvailFonts[(*itef).ascii()]->HasMetrics) {
00283                      PyObject *tmp= NULL;
00284                      tmp = PyString_FromString((*itef).ascii());
00285                      if (tmp) {
00286                             PyList_Append(self->fonts, tmp);
00287 // do i need Py_DECREF(tmp) here?
00288 // Does PyList_Append increase reference or 'steal' one from provided argument
00289 // If it 'steal' reference comment next line
00290                             Py_DECREF(tmp);
00291                      }
00292                      else {
00293                             PyErr_SetString(PyExc_SystemError, "Can not initialize 'fonts' attribute");
00294                             return -1;
00295                      }
00296 //            }
00297        }
00298 // set to print all pages
00299        PyObject *pages = NULL;
00300        int num = 0;
00301        // which one should I use ???
00302        // new = ScCore->primaryMainWindow()->view->Pages.count()
00303        num = ScCore->primaryMainWindow()->doc->Pages->count();
00304        pages = PyList_New(num);
00305        if (!pages){
00306               PyErr_SetString(PyExc_SystemError, "Can not initialize 'pages' attribute");
00307               return -1;
00308        }
00309        for (i = 0; i<num; ++i) {
00310               PyObject *tmp;
00311               tmp = PyInt_FromLong((long)i+1L);
00312               if (tmp)
00313                      PyList_SetItem(pages, i, tmp);
00314               else {
00315                      PyErr_SetString(PyExc_SystemError, "Can not initialize 'pages' attribute");
00316                      return -1;
00317               }
00318        }
00319        Py_DECREF(self->pages);
00320        self->pages = pages;
00321 // do not print thumbnails
00322        self->thumbnails = ScCore->primaryMainWindow()->doc->PDF_Options.Thumbnails;
00323 // set automatic compression
00324        self->compress = ScCore->primaryMainWindow()->doc->PDF_Options.Compress;
00325        self->compressmtd = ScCore->primaryMainWindow()->doc->PDF_Options.CompressMethod;
00326 // use maximum image quality
00327        self->quality = ScCore->primaryMainWindow()->doc->PDF_Options.Quality;
00328 // default resolution
00329        PyObject *resolution = NULL;
00330        resolution = PyInt_FromLong(300);
00331        if (resolution){
00332               Py_DECREF(self->resolution);
00333               self->resolution = resolution;
00334        } else {
00335               PyErr_SetString(PyExc_SystemError, "Can not initialize 'resolutin' attribute");
00336               return -1;
00337        }
00338 // do not downsample images
00339        int down = ScCore->primaryMainWindow()->doc->PDF_Options.RecalcPic ? ScCore->primaryMainWindow()->doc->PDF_Options.PicRes : 0;
00340        PyObject *downsample = NULL;
00341        downsample = PyInt_FromLong(down);
00342        if (downsample){
00343               Py_DECREF(self->downsample);
00344               self->downsample = downsample;
00345        } else {
00346               PyErr_SetString(PyExc_SystemError, "Can not initialize 'downsamle' attribute");
00347               return -1;
00348        }
00349        // no bookmarks
00350        self->bookmarks = ScCore->primaryMainWindow()->doc->PDF_Options.Bookmarks;
00351        // left margin binding
00352        self->binding = ScCore->primaryMainWindow()->doc->PDF_Options.Binding;
00353        // do not enable presentation effects
00354        self->presentation = ScCore->primaryMainWindow()->doc->PDF_Options.PresentMode;
00355        // set effects values for all pages
00356        PyObject *effval = NULL;
00357        num = 0;
00358        // which one should I use ???
00359        // new = ScCore->primaryMainWindow()->view->Pages.count();
00360        num = ScCore->primaryMainWindow()->doc->Pages->count();
00361        effval = PyList_New(num);
00362        if (!effval){
00363               PyErr_SetString(PyExc_SystemError, "Can not initialize 'effval' attribute");
00364               return -1;
00365        }
00366        int num2 = ScCore->primaryMainWindow()->doc->PDF_Options.PresentVals.count();
00367        for (i = 0; i<num2; ++i) {
00368               PyObject *tmp;
00369               PDFPresentationData t = ScCore->primaryMainWindow()->doc->PDF_Options.PresentVals[i];
00370               tmp = Py_BuildValue(const_cast<char*>("[iiiiii]"), t.pageEffectDuration, t.pageViewDuration, t.effectType, t.Dm, t.M, t.Di );
00371               if (tmp)
00372                      PyList_SetItem(effval, i, tmp);
00373               else {
00374                      PyErr_SetString(PyExc_SystemError, "Can not initialize 'effval' attribute");
00375                      return -1;
00376               }
00377               for (; i<num; ++i) {
00378                      PyObject *tmp;
00379                      tmp = Py_BuildValue(const_cast<char*>("[iiiiii]"), 1, 1, 0, 0, 0, 0);
00380                      if (tmp)
00381                             PyList_SetItem(effval, i, tmp);
00382                      else {
00383                             PyErr_SetString(PyExc_SystemError, "Can not initialize 'effval' attribute");
00384                             return -1;
00385                      }
00386               }
00387        }
00388        Py_DECREF(self->effval);
00389        self->effval = effval;
00390 // do not save linked text frames as PDF article
00391        self->article = ScCore->primaryMainWindow()->doc->PDF_Options.Articles;
00392 // do not encrypt file
00393        self->encrypt = ScCore->primaryMainWindow()->doc->PDF_Options.Encrypt;
00394 // do not Use Custom Rendering Settings
00395        self->uselpi = ScCore->primaryMainWindow()->doc->PDF_Options.UseLPI;
00396        self->usespot = ScCore->primaryMainWindow()->doc->PDF_Options.UseSpotColors;
00397        self->domulti = ScCore->primaryMainWindow()->doc->PDF_Options.doMultiFile;
00398 // get default values for lpival
00399        int n = ScCore->primaryMainWindow()->doc->PDF_Options.LPISettings.size();
00400        PyObject *lpival=PyList_New(n);
00401        if (!lpival){
00402               PyErr_SetString(PyExc_SystemError, "Can not initialize 'lpival' attribute");
00403               return -1;
00404        }
00405        QMap<QString,LPIData>::Iterator it = ScCore->primaryMainWindow()->doc->PDF_Options.LPISettings.begin();
00406        while (it != ScCore->primaryMainWindow()->doc->PDF_Options.LPISettings.end()) {
00407               PyObject *tmp;
00408               tmp = Py_BuildValue(const_cast<char*>("[siii]"), it.key().ascii(), it.data().Frequency, it.data().Angle, it.data().SpotFunc);
00409               if (!tmp) {
00410                      PyErr_SetString(PyExc_SystemError, "Can not initialize 'lpival' attribute");
00411                      return -1;
00412               }
00413               PyList_SetItem(lpival, --n, tmp);
00414               ++it;
00415        }
00416        PyList_Reverse(lpival);
00417        Py_DECREF(self->lpival);
00418        self->lpival = lpival;
00419 // set owner's password
00420        PyObject *owner = NULL;
00421        owner = PyString_FromString(ScCore->primaryMainWindow()->doc->PDF_Options.PassOwner.ascii());
00422        if (owner){
00423               Py_DECREF(self->owner);
00424               self->owner = owner;
00425        } else {
00426               PyErr_SetString(PyExc_SystemError, "Can not initialize 'owner' attribute");
00427               return -1;
00428        }
00429 // set user'a password
00430        PyObject *user = NULL;
00431        user = PyString_FromString(ScCore->primaryMainWindow()->doc->PDF_Options.PassUser.ascii());
00432        if (user){
00433               Py_DECREF(self->user);
00434               self->user = user;
00435        } else {
00436               PyErr_SetString(PyExc_SystemError, "Can not initialize 'user' attribute");
00437               return -1;
00438        }
00439 // allow printing document
00440        self->aprint = ScCore->primaryMainWindow()->doc->PDF_Options.Permissions & 4;
00441 // allow changing document
00442        self->achange = ScCore->primaryMainWindow()->doc->PDF_Options.Permissions & 8;
00443 // allow copying document
00444        self->acopy = ScCore->primaryMainWindow()->doc->PDF_Options.Permissions & 16;
00445 // allow adding annotation and fields
00446        self->aanot = ScCore->primaryMainWindow()->doc->PDF_Options.Permissions & 32;
00447 // use 1.4 pdf version *aka. Acrobat 5)
00448        self->version = ScCore->primaryMainWindow()->doc->PDF_Options.Version;
00449 // output destination is screen
00450        self->outdst = ScCore->primaryMainWindow()->doc->PDF_Options.UseRGB ? 0 : 1;
00451 
00452        self->profiles = ScCore->primaryMainWindow()->doc->PDF_Options.UseProfiles; // bool
00453        self->profilei = ScCore->primaryMainWindow()->doc->PDF_Options.UseProfiles2; // bool
00454        self->noembicc = ScCore->primaryMainWindow()->doc->PDF_Options.EmbeddedI; // bool
00455        self->intents = ScCore->primaryMainWindow()->doc->PDF_Options.Intent; // int - 0 - 3
00456        self->intenti = ScCore->primaryMainWindow()->doc->PDF_Options.Intent2; // int - 0 - 3
00457        QString tp = ScCore->primaryMainWindow()->doc->PDF_Options.SolidProf;
00458        if (!ScCore->InputProfiles.contains(tp))
00459               tp = ScCore->primaryMainWindow()->view->Doc->CMSSettings.DefaultSolidColorRGBProfile;
00460        PyObject *solidpr = NULL;
00461        solidpr = PyString_FromString(tp.ascii());
00462        if (solidpr){
00463               Py_DECREF(self->solidpr);
00464               self->solidpr = solidpr;
00465        } else {
00466               PyErr_SetString(PyExc_SystemError, "Can not initialize 'solidpr' attribute");
00467               return -1;
00468        }
00469        QString tp2 = ScCore->primaryMainWindow()->doc->PDF_Options.ImageProf;
00470        if (!ScCore->InputProfiles.contains(tp2))
00471               tp2 = ScCore->primaryMainWindow()->view->Doc->CMSSettings.DefaultSolidColorRGBProfile;
00472        PyObject *imagepr = NULL;
00473        imagepr = PyString_FromString(tp2.ascii());
00474        if (imagepr){
00475               Py_DECREF(self->imagepr);
00476               self->imagepr = imagepr;
00477        } else {
00478               PyErr_SetString(PyExc_SystemError, "Can not initialize 'imagepr' attribute");
00479               return -1;
00480        }
00481        QString tp3 = ScCore->primaryMainWindow()->doc->PDF_Options.PrintProf;
00482        if (!ScCore->PDFXProfiles.contains(tp3))
00483               tp3 = ScCore->primaryMainWindow()->view->Doc->CMSSettings.DefaultPrinterProfile;
00484        PyObject *printprofc = NULL;
00485        printprofc = PyString_FromString(tp3.ascii());
00486        if (printprofc){
00487               Py_DECREF(self->printprofc);
00488               self->printprofc = printprofc;
00489        } else {
00490               PyErr_SetString(PyExc_SystemError, "Can not initialize 'printprofc' attribute");
00491               return -1;
00492        }
00493        QString tinfo = ScCore->primaryMainWindow()->doc->PDF_Options.Info;
00494        PyObject *info = NULL;
00495        info = PyString_FromString(tinfo.ascii());
00496        if (info){
00497               Py_DECREF(self->info);
00498               self->info = info;
00499        } else {
00500               PyErr_SetString(PyExc_SystemError, "Can not initialize 'info' attribute");
00501               return -1;
00502        }
00503        self->bleedt = ScCore->primaryMainWindow()->doc->PDF_Options.bleeds.Top*ScCore->primaryMainWindow()->doc->unitRatio(); // double -
00504        self->bleedl = ScCore->primaryMainWindow()->doc->PDF_Options.bleeds.Left*ScCore->primaryMainWindow()->doc->unitRatio(); // double -
00505        self->bleedr = ScCore->primaryMainWindow()->doc->PDF_Options.bleeds.Right*ScCore->primaryMainWindow()->doc->unitRatio(); // double -
00506        self->bleedb = ScCore->primaryMainWindow()->doc->PDF_Options.bleeds.Bottom*ScCore->primaryMainWindow()->doc->unitRatio(); // double -
00507 
00508        return 0;
00509 }
00510 
00511 static PyMemberDef PDFfile_members[] = {
00512        {const_cast<char*>("thumbnails"), T_INT, offsetof(PDFfile, thumbnails), 0, const_cast<char*>("Generate thumbnails. Bool value.")},
00513        {const_cast<char*>("compress"), T_INT, offsetof(PDFfile, compress), 0, const_cast<char*>("Compression switch. Bool value.")},
00514        {const_cast<char*>("compressmtd"), T_INT, offsetof(PDFfile, compressmtd), 0, const_cast<char*>("Compression method.\n\t0 - Automatic\n\t1 - JPEG\n\t2 - zip\n\t3 - None.")},
00515        {const_cast<char*>("quality"), T_INT, offsetof(PDFfile, quality), 0, const_cast<char*>("Image quality\n\t0 - Maximum\n\t1 - High\n\t2 - Medium\n\t3 - Low\n\t4 - Minimum")},
00516        {const_cast<char*>("bookmarks"), T_INT, offsetof(PDFfile, bookmarks), 0, const_cast<char*>("Embed the bookmarks you created in your document.\nThese are useful for navigating long PDF documents.\nBool value")},
00517        {const_cast<char*>("binding"), T_INT, offsetof(PDFfile, binding), 0, const_cast<char*>("Choose binding.\n\t0 - Left binding\n\t1 - Right binding")},
00518        {const_cast<char*>("presentation"), T_INT, offsetof(PDFfile, presentation), 0, const_cast<char*>("Enable Presentation Effects.Bool value")},
00519        {const_cast<char*>("article"), T_INT, offsetof(PDFfile, article), 0, const_cast<char*>("Save Linked Text Frames as PDF Articles\n\tBool value")},
00520        {const_cast<char*>("encrypt"), T_INT, offsetof(PDFfile, encrypt), 0, const_cast<char*>("Use Encription. Bool value")},
00521        {const_cast<char*>("uselpi"), T_INT, offsetof(PDFfile, uselpi), 0, const_cast<char*>("Use Custom Rendering Settings. Bool value")},
00522        {const_cast<char*>("usespot"), T_INT, offsetof(PDFfile, usespot), 0, const_cast<char*>("Use Spot Colors. Bool value")},
00523        {const_cast<char*>("domulti"), T_INT, offsetof(PDFfile, domulti), 0, const_cast<char*>("Produce a PDF File for every Page. Bool value")},
00524        {const_cast<char*>("aprint"), T_INT, offsetof(PDFfile, aprint), 0, const_cast<char*>("Allow Printing the Document. Bool value")},
00525        {const_cast<char*>("achange"), T_INT, offsetof(PDFfile, achange), 0, const_cast<char*>("Allow Changing the Document. Bool value")},
00526        {const_cast<char*>("acopy"), T_INT, offsetof(PDFfile, acopy), 0, const_cast<char*>("Allow Copying Text and Graphics. Bool value")},
00527        {const_cast<char*>("aanot"), T_INT, offsetof(PDFfile, aanot), 0, const_cast<char*>("Allow Adding Annotations and Fields. Bool value")},
00528        {const_cast<char*>("version"), T_INT, offsetof(PDFfile, version), 0, const_cast<char*>("Choose PDF version to use:\n\t12 = PDF/X-3\n\t13 = PDF 1.3 (Acrobat 4)\n\t14 = PDF 1.4 (Acrobat 5)")},
00529        {const_cast<char*>("outdst"), T_INT, offsetof(PDFfile, outdst), 0, const_cast<char*>("Output destination.\n\t0 - screen\n\t1 - printer")},
00530        {const_cast<char*>("profiles"), T_INT, offsetof(PDFfile, profiles), 0, const_cast<char*>("Embed a color profile for solid colors. Bool value.")},
00531        {const_cast<char*>("profilei"), T_INT, offsetof(PDFfile, profilei), 0, const_cast<char*>("Embed a color profile for images. Bool value.")},
00532        {const_cast<char*>("intents"), T_INT, offsetof(PDFfile, intents), 0, const_cast<char*>("Rendering intent for solid colors\n\t0 - Perceptual\n\t1 - Relative Colorimetric\n\t2 - Saturation\n\t3 - Absolute Colorimetric")},
00533        {const_cast<char*>("intenti"), T_INT, offsetof(PDFfile, intenti), 0, const_cast<char*>("Rendering intent for images\n\t0 - Perceptual\n\t1 - Relative Colorimetric\n\t2 - Saturation\n\t3 - Absolute Colorimetric")},
00534        {const_cast<char*>("noembicc"), T_INT, offsetof(PDFfile, noembicc), 0, const_cast<char*>("Don't use embedded ICC profiles. Bool value")},
00535        {const_cast<char*>("bleedt"), T_DOUBLE, offsetof(PDFfile, bleedt), 0, const_cast<char*>("Bleed Top\n""Distance for bleed from the top of the physical page")},
00536        {const_cast<char*>("bleedl"), T_DOUBLE, offsetof(PDFfile, bleedl), 0, const_cast<char*>("Bleed Left\n""Distance for bleed from the left of the physical page")},
00537        {const_cast<char*>("bleedr"), T_DOUBLE, offsetof(PDFfile, bleedr), 0, const_cast<char*>("Bleed Right\n""Distance for bleed from the right of the physical page")},
00538        {const_cast<char*>("bleedb"), T_DOUBLE, offsetof(PDFfile, bleedb), 0, const_cast<char*>("Bleed Bottom\n""Distance for bleed from the bottom of the physical page")},
00539        {NULL, 0, 0, 0, NULL} // sentinel
00540 };
00541 
00542 
00543 /* Here begins Getter & Setter functions */
00544 
00545 static PyObject *PDFfile_getfile(PDFfile *self, void */*closure*/)
00546 {
00547        Py_INCREF(self->file);
00548        return self->file;
00549 }
00550 
00551 static int PDFfile_setfile(PDFfile *self, PyObject *value, void */*closure*/)
00552 {
00553        if (value == NULL) {
00554               PyErr_SetString(PyExc_TypeError, "Cannot delete 'file' attribute.");
00555               return -1;
00556        }
00557        if (!PyString_Check(value)) {
00558               PyErr_SetString(PyExc_TypeError, "The 'file' attribute value must be string.");
00559               return -1;
00560        }
00561        Py_DECREF(self->file);
00562        Py_INCREF(value);
00563        self->file = value;
00564        return 0;
00565 }
00566 
00567 static PyObject *PDFfile_getfonts(PDFfile *self, void */*closure*/)
00568 {
00569        Py_INCREF(self->fonts);
00570        return self->fonts;
00571 }
00572 
00573 static int PDFfile_setfonts(PDFfile *self, PyObject *value, void */*closure*/)
00574 {
00575        if (value == NULL) {
00576               PyErr_SetString(PyExc_TypeError, "Cannot delete 'fonts' attribute.");
00577               return -1;
00578        }
00579        if (!PyList_Check(value)) {
00580               PyErr_SetString(PyExc_TypeError, "The 'fonts' attribute value must be list of strings.");
00581               return -1;
00582        }
00583        int n;
00584        n = PyList_Size(value);
00585        for (int i=0; i<n; ++i)
00586               if (!PyString_Check(PyList_GetItem(value, i))) {
00587                      PyErr_SetString(PyExc_TypeError, "The 'fonts' list must contain only strings.");
00588                      return -1;
00589               }
00590 // Do I need to check if supplied string is really
00591 // name of available font???
00592 // this is not implemented yet
00593        Py_DECREF(self->fonts);
00594        Py_INCREF(value);
00595        self->fonts = value;
00596        PyList_Sort(self->fonts);
00597        return 0;
00598 }
00599 
00600 static PyObject *PDFfile_getpages(PDFfile *self, void */*closure*/)
00601 {
00602        Py_INCREF(self->pages);
00603        return self->pages;
00604 }
00605 
00606 static int PDFfile_setpages(PDFfile *self, PyObject *value, void */*closure*/)
00607 {
00608        if (value == NULL) {
00609               PyErr_SetString(PyExc_TypeError, "Cannot delete 'pages' attribute.");
00610               return -1;
00611        }
00612        if (!PyList_Check(value)) {
00613               PyErr_SetString(PyExc_TypeError, "'pages' attribute value must be list of integers.");
00614               return -1;
00615        }
00616        int len = PyList_Size(value);
00617        for (int i = 0; i<len; i++){
00618               PyObject *tmp = PyList_GetItem(value, i);
00619               // I did not check if tmp is NULL
00620               // how can PyList_GetItem fail in this case (my guess: short of available memory?)
00621               // Also do I need Py_INCREF or Py_DECREF here?
00622               if (!PyInt_Check(tmp)){
00623                      PyErr_SetString(PyExc_TypeError, "'pages' list must contain only integers.");
00624                      return -1;
00625               }
00626               if (PyInt_AsLong(tmp) > static_cast<int>(ScCore->primaryMainWindow()->doc->Pages->count()) || PyInt_AsLong(tmp) < 1) {
00627                      PyErr_SetString(PyExc_ValueError, "'pages' value out of range.");
00628                      return -1;
00629               }
00630        }
00631        Py_DECREF(self->pages);
00632        Py_INCREF(value);
00633        self->pages = value;
00634        PyList_Sort(self->pages);
00635        return 0;
00636 }
00637 
00638 
00639 static PyObject *PDFfile_getresolution(PDFfile *self, void */*closure*/)
00640 {
00641        Py_INCREF(self->resolution);
00642        return self->resolution;
00643 }
00644 
00645 static int PDFfile_setresolution(PDFfile *self, PyObject *value, void */*closure*/)
00646 {
00647        if (value == NULL) {
00648               PyErr_SetString(PyExc_TypeError, "Cannot delete 'resolution' attribute.");
00649               return -1;
00650        }
00651        if (!PyInt_Check(value)) {
00652               PyErr_SetString(PyExc_TypeError, "'resolution' attribute value must be integer.");
00653               return -1;
00654        }
00655        int n = PyInt_AsLong(value);
00656        if (n<35 || n>4000) {
00657               PyErr_SetString(PyExc_ValueError, "'compress' value must be in interval from 35 to 4000");
00658               return -1;
00659        }
00660        Py_DECREF(self->resolution);
00661        Py_INCREF(value);
00662        self->resolution = value;
00663        return 0;
00664 }
00665 
00666 static PyObject *PDFfile_getdownsample(PDFfile *self, void */*closure*/)
00667 {
00668        Py_INCREF(self->downsample);
00669        return self->downsample;
00670 }
00671 
00672 static int PDFfile_setdownsample(PDFfile *self, PyObject *value, void */*closure*/)
00673 {
00674        if (value == NULL) {
00675               PyErr_SetString(PyExc_TypeError, "Cannot delete 'downsample' attribute.");
00676               return -1;
00677        }
00678        if (!PyInt_Check(value)) {
00679               PyErr_SetString(PyExc_TypeError, "'downsample' attribute value must be integer.");
00680               return -1;
00681        }
00682        int n = PyInt_AsLong(value);
00683        if (n!=0 && (n<35 || n>PyInt_AsLong(self->resolution))) {
00684               PyErr_SetString(PyExc_TypeError, "'downsample' value must be 0 or in interval from 35 to value of 'resolutin'");
00685               return -1;
00686        }
00687        Py_DECREF(self->downsample);
00688        Py_INCREF(value);
00689        self->downsample = value;
00690        return 0;
00691 }
00692 
00693 static PyObject *PDFfile_geteffval(PDFfile *self, void */*closure*/)
00694 {
00695        Py_INCREF(self->effval);
00696        return self->effval;
00697 }
00698 
00699 static int PDFfile_seteffval(PDFfile *self, PyObject *value, void */*closure*/)
00700 {
00701        if (value == NULL) {
00702               PyErr_SetString(PyExc_TypeError, "Cannot delete 'effval' attribute.");
00703               return -1;
00704        }
00705        if (!PyList_Check(value)) {
00706               PyErr_SetString(PyExc_TypeError, "'effval' must be list.");
00707               return -1;
00708        }
00709        int n = PyList_Size(value);
00710        for (int i=0; i<n; ++i) {
00711               PyObject *tmp = PyList_GetItem(value, i);
00712               if (!PyList_Check(tmp)) {
00713                      PyErr_SetString(PyExc_TypeError, "elemets of 'effval' must be list of five integers.");
00714                      return -1;
00715               }
00716               int j = PyList_Size(tmp);
00717               if (j != 6) {
00718                      PyErr_SetString(PyExc_TypeError, "elemets of 'effval' must have exactly six integers.");
00719                      return -1;
00720               }
00721               for ( --j; j > -1; --j) {
00722                      if (!PyInt_Check(PyList_GetItem(tmp, j))) {
00723                             PyErr_SetString(PyExc_TypeError, "innermost element of 'effval' must be integers.");
00724                             return -1;
00725                      }
00726               }
00727        }
00728        Py_DECREF(self->effval);
00729        Py_INCREF(value);
00730        self->effval = value;
00731        return 0;
00732 }
00733 
00734 static PyObject *PDFfile_getlpival(PDFfile *self, void */*closure*/)
00735 {
00736        Py_INCREF(self->lpival);
00737        return self->lpival;
00738 }
00739 
00740 static int PDFfile_setlpival(PDFfile *self, PyObject *value, void */*closure*/)
00741 {
00742        if (value == NULL) {
00743               PyErr_SetString(PyExc_TypeError, "Cannot delete 'lpival' attribute.");
00744               return -1;
00745        }
00746        if (!PyList_Check(value)) {
00747               PyErr_SetString(PyExc_TypeError, "'lpival' must be list.");
00748               return -1;
00749        }
00750        // Do I need Py_INCREF or Py_DECREF here?
00751        int n = PyList_Size(value);
00752        for (int i=0; i<n; ++i) {
00753               PyObject *tmp = PyList_GetItem(value, i);
00754               if (!PyList_Check(tmp)) {
00755                      PyErr_SetString(PyExc_TypeError, "elemets of 'lpival' must be list of five integers.");
00756                      return -1;
00757               }
00758               int j = PyList_Size(tmp);
00759               if (j != 4) {
00760                      PyErr_SetString(PyExc_TypeError, "elemets of 'lpival' must have exactly four members.");
00761                      return -1;
00762               }
00763               for ( --j; j > 0; --j) {
00764                      if (!PyInt_Check(PyList_GetItem(tmp, j))) {
00765                             PyErr_SetString(PyExc_TypeError, "'lpival'elements must have structure [siii]");
00766                             return -1;
00767                      }
00768               }
00769               if (!PyString_Check(PyList_GetItem(tmp, 0))) {
00770                      PyErr_SetString(PyExc_TypeError, "'lpival'elements must have structure [siii]");
00771                      return -1;
00772               }
00773        }
00774        Py_DECREF(self->lpival);
00775        Py_INCREF(value);
00776        self->lpival = value;
00777        return 0;
00778 }
00779 
00780 static PyObject *PDFfile_getowner(PDFfile *self, void */*closure*/)
00781 {
00782        Py_INCREF(self->owner);
00783        return self->owner;
00784 }
00785 
00786 static int PDFfile_setowner(PDFfile *self, PyObject *value, void */*closure*/)
00787 {
00788        if (value == NULL) {
00789               PyErr_SetString(PyExc_TypeError, "Cannot delete 'owner' attribute.");
00790               return -1;
00791        }
00792        if (!PyString_Check(value)) {
00793               PyErr_SetString(PyExc_TypeError, "'owner' attribute value must be string.");
00794               return -1;
00795        }
00796        Py_DECREF(self->owner);
00797        Py_INCREF(value);
00798        self->owner = value;
00799        return 0;
00800 }
00801 
00802 static PyObject *PDFfile_getuser(PDFfile *self, void */*closure*/)
00803 {
00804        Py_INCREF(self->user);
00805        return self->user;
00806 }
00807 
00808 static int PDFfile_setuser(PDFfile *self, PyObject *value, void */*closure*/)
00809 {
00810        if (value == NULL) {
00811               PyErr_SetString(PyExc_TypeError, "Cannot delete 'user' attribute.");
00812               return -1;
00813        }
00814        if (!PyString_Check(value)) {
00815               PyErr_SetString(PyExc_TypeError, "'user' attribute value must be string.");
00816               return -1;
00817        }
00818        Py_DECREF(self->user);
00819        Py_INCREF(value);
00820        self->user = value;
00821        return 0;
00822 }
00823 
00824 static PyObject *PDFfile_getsolidpr(PDFfile *self, void */*closure*/)
00825 {
00826        Py_INCREF(self->solidpr);
00827        return self->solidpr;
00828 }
00829 
00830 static int PDFfile_setsolidpr(PDFfile *self, PyObject *value, void */*closure*/)
00831 {
00832        if (value == NULL) {
00833               PyErr_SetString(PyExc_TypeError, "Cannot delete 'solidpr' attribute.");
00834               return -1;
00835        }
00836        if (!PyString_Check(value)) {
00837               PyErr_SetString(PyExc_TypeError, "The 'solidpr' attribute value must be string.");
00838               return -1;
00839        }
00840        Py_DECREF(self->solidpr);
00841        Py_INCREF(value);
00842        self->solidpr = value;
00843        return 0;
00844 }
00845 
00846 static PyObject *PDFfile_getimagepr(PDFfile *self, void */*closure*/)
00847 {
00848        Py_INCREF(self->imagepr);
00849        return self->imagepr;
00850 }
00851 
00852 static int PDFfile_setimagepr(PDFfile *self, PyObject *value, void */*closure*/)
00853 {
00854        if (value == NULL) {
00855               PyErr_SetString(PyExc_TypeError, "Cannot delete 'imagepr' attribute.");
00856               return -1;
00857        }
00858        if (!PyString_Check(value)) {
00859               PyErr_SetString(PyExc_TypeError, "The 'imagepr' attribute value must be string.");
00860               return -1;
00861        }
00862        Py_DECREF(self->imagepr);
00863        Py_INCREF(value);
00864        self->imagepr = value;
00865        return 0;
00866 }
00867 
00868 static PyObject *PDFfile_getprintprofc(PDFfile *self, void */*closure*/)
00869 {
00870        Py_INCREF(self->printprofc);
00871        return self->printprofc;
00872 }
00873 
00874 static int PDFfile_setprintprofc(PDFfile *self, PyObject *value, void */*closure*/)
00875 {
00876        if (value == NULL) {
00877               PyErr_SetString(PyExc_TypeError, "Cannot delete 'printprofc' attribute.");
00878               return -1;
00879        }
00880        if (!PyString_Check(value)) {
00881               PyErr_SetString(PyExc_TypeError, "The 'printprofc' attribute value must be string.");
00882               return -1;
00883        }
00884        Py_DECREF(self->printprofc);
00885        Py_INCREF(value);
00886        self->printprofc = value;
00887        return 0;
00888 }
00889 
00890 static PyObject *PDFfile_getinfo(PDFfile *self, void */*closure*/)
00891 {
00892        Py_INCREF(self->info);
00893        return self->info;
00894 }
00895 
00896 static int PDFfile_setinfo(PDFfile *self, PyObject *value, void */*closure*/)
00897 {
00898        if (value == NULL) {
00899               PyErr_SetString(PyExc_TypeError, "Cannot delete 'info' attribute.");
00900               return -1;
00901        }
00902        if (!PyString_Check(value)) {
00903               PyErr_SetString(PyExc_TypeError, "The 'info' attribute value must be string.");
00904               return -1;
00905        }
00906        Py_DECREF(self->info);
00907        Py_INCREF(value);
00908        self->info = value;
00909        return 0;
00910 }
00911 
00912 static char *effval_doc = const_cast<char*>(
00913 "List of effection values for each saved page.\n"
00914 "It is list of list of six integers. Those int has followin meaning:\n\t"
00915 "- Length of time the page is shown before the presentation\n\tstarts on the selected page. (1-3600)\n\t"
00916 "- Length of time the effect runs. (1 - 3600)\n\t\tA shorter time will speed up the effect,\n\t\ta longer one will slow it down\n\t"
00917 "- Type of the display effect\n\t\t0 - No Effect\n\t\t1 - Blinds\n\t\t2 - Box\n\t\t3 - Dissolve\n\t\t4 - Glitter\n\t\t5 - Split\n\t\t6 - Wipe\n\t"
00918 "- Direction of the effect of moving lines\n\tfor the split and blind effects.\n\t\t0 - Horizontal\n\t\t1 - Vertical\n\t"
00919 "- Starting position for the box and split effects.\n\t\t0 - Inside\n\t\t1 - Outside\n\t"
00920 "- Direction of the glitter or wipe effects.\n\t\t0 - Left to Right\n\t\t1 - Top to Bottom\n\t\t2 - Bottom to Top\n\t\t3 - Right to Left\n\t\t4 - Top-left to Bottom-Right");
00921 
00922 static char *lpival_doc = const_cast<char*>(
00923 "Rendering Settings for individual colors.\n\n"
00924 "This is list of values for each color\n"
00925 "Color values have structure [siii] which stand for:\n\t"
00926 "s - Color name ('Black', 'Cyan', 'Magenta', 'Yellow')\n\t"
00927 "i - Frequency (10 to 1000)\n\t"
00928 "i - Angle (-180 to 180)\n\t"
00929 "i - Spot Function\n\t\t0 - Simple Dot\n\t\t1 - Line\n\t\t2 - Round\n\t\t3 - Ellipse\n"
00930 "Be carefull when supplying these values as they\nare not checked for validity.");
00931 
00932 static PyGetSetDef PDFfile_getseters [] = {
00933        {const_cast<char*>("file"), (getter)PDFfile_getfile, (setter)PDFfile_setfile, const_cast<char*>("Name of file to save into"), NULL},
00934        {const_cast<char*>("fonts"), (getter)PDFfile_getfonts, (setter)PDFfile_setfonts, const_cast<char*>("List of fonts to embed."), NULL},
00935        {const_cast<char*>("pages"), (getter)PDFfile_getpages, (setter)PDFfile_setpages, const_cast<char*>("List of pages to print"), NULL},
00936        {const_cast<char*>("resolution"), (getter)PDFfile_getresolution, (setter)PDFfile_setresolution, const_cast<char*>("Resolution of output file. Values from 35 to 4000."), NULL},
00937        {const_cast<char*>("downsample"), (getter)PDFfile_getdownsample, (setter)PDFfile_setdownsample, const_cast<char*>("Downsample image resolusion to this value. Values from 35 to 4000\nSet 0 for not to downsample"), NULL},
00938        {const_cast<char*>("effval"), (getter)PDFfile_geteffval, (setter)PDFfile_seteffval, effval_doc, NULL},
00939        {const_cast<char*>("lpival"), (getter)PDFfile_getlpival, (setter)PDFfile_setlpival, lpival_doc, NULL},
00940        {const_cast<char*>("owner"), (getter)PDFfile_getowner, (setter)PDFfile_setowner, const_cast<char*>("Owner's password"), NULL},
00941        {const_cast<char*>("user"), (getter)PDFfile_getuser, (setter)PDFfile_setuser, const_cast<char*>("User's password"), NULL},
00942        {const_cast<char*>("solidpr"), (getter)PDFfile_getsolidpr, (setter)PDFfile_setsolidpr, const_cast<char*>("Color profile for solid colors"), NULL},
00943        {const_cast<char*>("imagepr"), (getter)PDFfile_getimagepr, (setter)PDFfile_setimagepr, const_cast<char*>("Color profile for images"), NULL},
00944        {const_cast<char*>("printprofc"), (getter)PDFfile_getprintprofc, (setter)PDFfile_setprintprofc, const_cast<char*>("Output profile for printing. If possible, get some guidance from your printer on profile selection."), NULL},
00945        {const_cast<char*>("info"), (getter)PDFfile_getinfo, (setter)PDFfile_setinfo, const_cast<char*>("Mandatory string for PDF/X-3 or the PDF will fail\nPDF/X-3 conformance. We recommend you use the title of the document."), NULL},
00946        {NULL, NULL, NULL, NULL, NULL}  // sentinel
00947 };
00948 
00949 static PyObject *PDFfile_save(PDFfile *self)
00950 {
00951        if (!ScCore->primaryMainWindow()->HaveDoc) {
00952               PyErr_SetString(PyExc_SystemError, "Need to open document first");
00953               return NULL;
00954        };
00955 
00956 // copied from file scribus.cpp
00957 //void ScribusMainWindow::SaveAsPDF()
00958        int Components = 3;
00959        QString nam = "";
00960        if (ScCore->primaryMainWindow()->bookmarkPalette->BView->childCount() == 0)
00961               ScCore->primaryMainWindow()->doc->PDF_Options.Bookmarks = false;
00962 
00963 // apply fonts attribute
00964        ScCore->primaryMainWindow()->doc->PDF_Options.EmbedList.clear();
00965        int n = PyList_Size(self->fonts);
00966        for ( int i=0; i<n; ++i){
00967               QString tmpFon;
00968               tmpFon = QString(PyString_AsString(PyList_GetItem(self->fonts, i)));
00969               ScCore->primaryMainWindow()->doc->PDF_Options.EmbedList.append(tmpFon);
00970        }
00971 // apply file attribute
00972        QString fn;
00973        fn = QString(PyString_AsString(self->file));
00974        ScCore->primaryMainWindow()->doc->PDF_Options.Datei = fn;
00975 // apply pages attribute
00976        std::vector<int> pageNs;
00977        int nn=PyList_Size(self->pages);
00978        for (int i = 0; i < nn; ++i) {
00979               pageNs.push_back((int)PyInt_AsLong(PyList_GetItem(self->pages, i)));
00980        }
00981 // apply thumbnails attribute
00982        ScCore->primaryMainWindow()->doc->PDF_Options.Thumbnails = self->thumbnails;
00983 // apply compress attribute
00984        self->compressmtd = minmaxi(self->compressmtd, 0, 3);
00985        ScCore->primaryMainWindow()->doc->PDF_Options.Compress = self->compress;
00986        ScCore->primaryMainWindow()->doc->PDF_Options.CompressMethod = self->compressmtd;
00987 // apply quality attribute
00988        self->quality = minmaxi(self->quality, 0, 4);
00989        ScCore->primaryMainWindow()->doc->PDF_Options.Quality = self->quality;
00990 // apply resolusion attribute
00991        ScCore->primaryMainWindow()->doc->PDF_Options.Resolution = PyInt_AsLong(self->resolution);
00992 // apply downsample attribute
00993        ScCore->primaryMainWindow()->doc->PDF_Options.RecalcPic = PyInt_AsLong(self->downsample);
00994        if (ScCore->primaryMainWindow()->doc->PDF_Options.RecalcPic)
00995               ScCore->primaryMainWindow()->doc->PDF_Options.PicRes = PyInt_AsLong(self->downsample);
00996        else
00997               ScCore->primaryMainWindow()->doc->PDF_Options.PicRes = ScCore->primaryMainWindow()->doc->PDF_Options.Resolution;
00998 // apply bookmarks attribute
00999        ScCore->primaryMainWindow()->doc->PDF_Options.Bookmarks = self->bookmarks;
01000 // apply binding attribute
01001        ScCore->primaryMainWindow()->doc->PDF_Options.Binding = self->binding;
01002 // apply presentation attribute
01003        ScCore->primaryMainWindow()->doc->PDF_Options.PresentMode = self->presentation;
01004 
01005        QValueList<PDFPresentationData> PresentVals;
01006        PresentVals.clear();
01007        int tmpnum;
01008        tmpnum=PyList_Size(self->effval);
01009        for (int i=0; i<tmpnum; ++i) {
01010               PDFPresentationData t;
01011 // How do I make this commented piece of code to work?
01012 // I always get an error here
01013               PyObject *ti = PyList_GetItem(self->effval, i);
01014 //             if (!PyArg_ParseTuple(ti , "[iiiiii]",
01015 //                            &t.pageEffectDuration, &t.pageViewDuration, &t.effectType, &t.Dm,
01016 //                            &t.M, &t.Di)) {
01017 //                    PyErr_SetString(PyExc_SystemError, "while parsing 'effval'. WHY THIS HAPPENED????");
01018 //                    return NULL;
01019 //             }
01020 //             PresentVals.append(t);
01021                             // pv 10/03/2004 crashed when pt is null
01022                             if (ti)
01023                             {
01024                                    // Do I Need to check if every PyInt_AsLong and PyList_GetItem funtion succeed???
01025                                    t.pageEffectDuration = PyInt_AsLong(PyList_GetItem(ti, 0));
01026                                    t.pageViewDuration = PyInt_AsLong(PyList_GetItem(ti, 1));
01027                                    t.effectType = PyInt_AsLong(PyList_GetItem(ti, 2));
01028                                    t.Dm = PyInt_AsLong(PyList_GetItem(ti, 3));
01029                                    t.M = PyInt_AsLong(PyList_GetItem(ti, 4));
01030                                    t.Di = PyInt_AsLong(PyList_GetItem(ti, 5));
01031                                    PresentVals.append(t);
01032                             } // if ti=NULL
01033 
01034        }
01035 
01036        ScCore->primaryMainWindow()->doc->PDF_Options.PresentVals = PresentVals;
01037 // apply lpival
01038        int n2 = PyList_Size(self->lpival);
01039        for (int i=0; i<n2; ++i){
01040               LPIData lpi;
01041               PyObject *t = PyList_GetItem(self->lpival, i);
01042 // This code always raise exception - WHY???
01043 //            char *s;
01044 //             if (!PyArg_ParseTuple(t, "[siii]", &s, &lpi.Frequency,
01045 //                            &lpi.Angle, &lpi.SpotFunc)) {
01046 //                    PyErr_SetString(PyExc_SystemError, "while parsing 'lpival'. WHY THIS HAPPENED????");
01047 //                    return NULL;
01048 //             }
01049 //             ScCore->primaryMainWindow()->doc->PDF_Options.LPISettings[QString(s)]=lpi;
01050               QString st;
01051               st = QString(PyString_AsString(PyList_GetItem(t,0)));
01052               lpi.Frequency = PyInt_AsLong(PyList_GetItem(t, 1));
01053               lpi.Angle = PyInt_AsLong(PyList_GetItem(t, 2));
01054               lpi.SpotFunc = PyInt_AsLong(PyList_GetItem(t, 3));
01055               ScCore->primaryMainWindow()->doc->PDF_Options.LPISettings[st]=lpi;
01056        }
01057 
01058        ScCore->primaryMainWindow()->doc->PDF_Options.Articles = self->article;
01059        ScCore->primaryMainWindow()->doc->PDF_Options.Encrypt = self->encrypt;
01060        ScCore->primaryMainWindow()->doc->PDF_Options.UseLPI = self->uselpi;
01061        ScCore->primaryMainWindow()->doc->PDF_Options.UseSpotColors = self->usespot;
01062        ScCore->primaryMainWindow()->doc->PDF_Options.doMultiFile = self->domulti;
01063        self->version = minmaxi(self->version, 12, 14);
01064        // FIXME: Sanity check version
01065        ScCore->primaryMainWindow()->doc->PDF_Options.Version = (PDFOptions::PDFVersion)self->version;
01066        if (self->encrypt)
01067        {
01068               int Perm = -64;
01069               if (ScCore->primaryMainWindow()->doc->PDF_Options.Version == PDFOptions::PDFVersion_14)
01070                      Perm &= ~0x00240000;
01071               if (self->aprint)
01072                      Perm += 4;
01073               if (self->achange)
01074                      Perm += 8;
01075               if (self->acopy)
01076                      Perm += 16;
01077               if (self->aanot)
01078                      Perm += 32;
01079               ScCore->primaryMainWindow()->doc->PDF_Options.Permissions = Perm;
01080               ScCore->primaryMainWindow()->doc->PDF_Options.PassOwner = QString(PyString_AsString(self->owner));
01081               ScCore->primaryMainWindow()->doc->PDF_Options.PassUser = QString(PyString_AsString(self->user));
01082        }
01083        if (self->outdst == 0)
01084        {
01085               ScCore->primaryMainWindow()->doc->PDF_Options.UseRGB = true;
01086               ScCore->primaryMainWindow()->doc->PDF_Options.UseProfiles = false;
01087               ScCore->primaryMainWindow()->doc->PDF_Options.UseProfiles2 = false;
01088        }
01089        else
01090        {
01091               ScCore->primaryMainWindow()->doc->PDF_Options.UseRGB = false;
01092               if (ScCore->primaryMainWindow()->doc->HasCMS)
01093               {
01094                      ScCore->primaryMainWindow()->doc->PDF_Options.UseProfiles = self->profiles;
01095                      ScCore->primaryMainWindow()->doc->PDF_Options.UseProfiles2 = self->profilei;
01096                      self->intents = minmaxi(self->intents, 0, 3);
01097                      ScCore->primaryMainWindow()->doc->PDF_Options.Intent = self->intents;
01098                      self->intenti = minmaxi(self->intenti, 0, 3);
01099                      ScCore->primaryMainWindow()->doc->PDF_Options.Intent2 = self->intenti;
01100                      ScCore->primaryMainWindow()->doc->PDF_Options.EmbeddedI = self->noembicc;
01101                      ScCore->primaryMainWindow()->doc->PDF_Options.SolidProf = PyString_AsString(self->solidpr);
01102                      ScCore->primaryMainWindow()->doc->PDF_Options.ImageProf = PyString_AsString(self->imagepr);
01103                      ScCore->primaryMainWindow()->doc->PDF_Options.PrintProf = PyString_AsString(self->printprofc);
01104                      if (ScCore->primaryMainWindow()->doc->PDF_Options.Version == PDFOptions::PDFVersion_X3)
01105                      {
01106 // Where does compiler find cms function when I have not included header for it
01107                             const char *Descriptor;
01108                             cmsHPROFILE hIn;
01109                             hIn = cmsOpenProfileFromFile(ScCore->PrinterProfiles[ScCore->primaryMainWindow()->doc->PDF_Options.PrintProf], "r");
01110                             Descriptor = cmsTakeProductDesc(hIn);
01111                             nam = QString(Descriptor);
01112                             if (static_cast<int>(cmsGetColorSpace(hIn)) == icSigRgbData)
01113                                    Components = 3;
01114                             if (static_cast<int>(cmsGetColorSpace(hIn)) == icSigCmykData)
01115                                    Components = 4;
01116                             if (static_cast<int>(cmsGetColorSpace(hIn)) == icSigCmyData)
01117                                    Components = 3;
01118                             cmsCloseProfile(hIn);
01119                             ScCore->primaryMainWindow()->doc->PDF_Options.Info = PyString_AsString(self->info);
01120                             self->bleedt = minmaxd(self->bleedt, 0, ScCore->primaryMainWindow()->view->Doc->pageHeight*ScCore->primaryMainWindow()->view->Doc->unitRatio());
01121                             ScCore->primaryMainWindow()->doc->PDF_Options.bleeds.Top = self->bleedt/ScCore->primaryMainWindow()->view->Doc->unitRatio();
01122                             self->bleedl = minmaxd(self->bleedl, 0, ScCore->primaryMainWindow()->view->Doc->pageWidth*ScCore->primaryMainWindow()->view->Doc->unitRatio());
01123                             ScCore->primaryMainWindow()->doc->PDF_Options.bleeds.Left = self->bleedl/ScCore->primaryMainWindow()->view->Doc->unitRatio();
01124                             self->bleedr = minmaxd(self->bleedr, 0, ScCore->primaryMainWindow()->view->Doc->pageWidth*ScCore->primaryMainWindow()->view->Doc->unitRatio());
01125                             ScCore->primaryMainWindow()->doc->PDF_Options.bleeds.Right = self->bleedr/ScCore->primaryMainWindow()->view->Doc->unitRatio();
01126                             self->bleedb = minmaxd(self->bleedb, 0, ScCore->primaryMainWindow()->view->Doc->pageHeight*ScCore->primaryMainWindow()->view->Doc->unitRatio());
01127                             ScCore->primaryMainWindow()->doc->PDF_Options.bleeds.Bottom = self->bleedb/ScCore->primaryMainWindow()->view->Doc->unitRatio();
01128                             ScCore->primaryMainWindow()->doc->PDF_Options.Encrypt = false;
01129                             ScCore->primaryMainWindow()->doc->PDF_Options.PresentMode = false;
01130                      }
01131               }
01132               else
01133               {
01134                      ScCore->primaryMainWindow()->doc->PDF_Options.UseProfiles = false;
01135                      ScCore->primaryMainWindow()->doc->PDF_Options.UseProfiles2 = false;
01136               }
01137 
01138        }
01139        QMap<int,QPixmap> thumbs;
01140        for (uint ap = 0; ap < pageNs.size(); ++ap)
01141        {
01142               QPixmap pm(10,10);
01143               if (ScCore->primaryMainWindow()->doc->PDF_Options.Thumbnails)
01144                      pm = ScCore->primaryMainWindow()->view->PageToPixmap(pageNs[ap]-1, 100);
01145               thumbs.insert(pageNs[ap], pm);
01146        }
01147        ReOrderText(ScCore->primaryMainWindow()->doc, ScCore->primaryMainWindow()->view);
01148        if (!ScCore->primaryMainWindow()->getPDFDriver(fn, nam, Components, pageNs, thumbs)) {
01149               fn = "Cannot write the File: " + fn;
01150               PyErr_SetString(PyExc_SystemError, fn.ascii());
01151               return NULL;
01152        }
01153 //     Py_INCREF(Py_None);
01154 //     return Py_None;
01155        Py_RETURN_NONE;
01156 }
01157 
01158 static PyMethodDef PDFfile_methods[] = {
01159        {const_cast<char*>("save"), (PyCFunction)PDFfile_save, METH_NOARGS, const_cast<char*>("Save selected pages to pdf file")},
01160        {NULL, (PyCFunction)(0), 0, NULL} // sentinel
01161 };
01162 
01163 PyTypeObject PDFfile_Type = {
01164        PyObject_HEAD_INIT(NULL) // PyObject_VAR_HEAD
01165        0,                  //
01166        const_cast<char*>("PDFfile"), // char *tp_name; /* For printing, in format "<module>.<name>" */
01167        sizeof(PDFfile),     // int tp_basicsize, /* For allocation */
01168        0,                // int tp_itemsize; /* For allocation */
01169 
01170        /* Methods to implement standard operations */
01171 
01172        (destructor) PDFfile_dealloc, //     destructor tp_dealloc;
01173        0, //     printfunc tp_print;
01174        0, //     getattrfunc tp_getattr;
01175        0, //     setattrfunc tp_setattr;
01176        0, //     cmpfunc tp_compare;
01177        0, //     reprfunc tp_repr;
01178 
01179        /* Method suites for standard classes */
01180 
01181        0, //     PyNumberMethods *tp_as_number;
01182        0, //     PySequenceMethods *tp_as_sequence;
01183        0, //     PyMappingMethods *tp_as_mapping;
01184 
01185        /* More standard operations (here for binary compatibility) */
01186 
01187        0, //     hashfunc tp_hash;
01188        0, //     ternaryfunc tp_call;
01189        0, //     reprfunc tp_str;
01190        0, //     getattrofunc tp_getattro;
01191        0, //     setattrofunc tp_setattro;
01192 
01193        /* Functions to access object as input/output buffer */
01194        0, //     PyBufferProcs *tp_as_buffer;
01195 
01196        /* Flags to define presence of optional/expanded features */
01197        Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,    // long tp_flags;
01198 
01199        pdffile__doc__,      // char *tp_doc; /* Documentation string */
01200 
01201        /* Assigned meaning in release 2.0 */
01202        /* call function for all accessible objects */
01203        0, //     traverseproc tp_traverse;
01204 
01205        /* delete references to contained objects */
01206        0, //     inquiry tp_clear;
01207 
01208        /* Assigned meaning in release 2.1 */
01209        /* rich comparisons */
01210        0, //     richcmpfunc tp_richcompare;
01211 
01212        /* weak reference enabler */
01213        0, //     long tp_weaklistoffset;
01214 
01215        /* Added in release 2.2 */
01216        /* Iterators */
01217        0, //     getiterfunc tp_iter;
01218        0, //     iternextfunc tp_iternext;
01219 
01220        /* Attribute descriptor and subclassing stuff */
01221        PDFfile_methods, //     struct PyMethodDef *tp_methods;
01222        PDFfile_members, //     struct PyMemberDef *tp_members;
01223        PDFfile_getseters, //     struct PyGetSetDef *tp_getset;
01224        0, //     struct _typeobject *tp_base;
01225        0, //     PyObject *tp_dict;
01226        0, //     descrgetfunc tp_descr_get;
01227        0, //     descrsetfunc tp_descr_set;
01228        0, //     long tp_dictoffset;
01229        (initproc)PDFfile_init, //     initproc tp_init;
01230        0, //     allocfunc tp_alloc;
01231        PDFfile_new, //     newfunc tp_new;
01232        0, //     freefunc tp_free; /* Low-level free-memory routine */
01233        0, //     inquiry tp_is_gc; /* For PyObject_IS_GC */
01234        0, //     PyObject *tp_bases;
01235        0, //     PyObject *tp_mro; /* method resolution order */
01236        0, //     PyObject *tp_cache;
01237        0, //     PyObject *tp_subclasses;
01238        0, //     PyObject *tp_weaklist;
01239        0, //     destructor tp_del;
01240 
01241 #ifdef COUNT_ALLOCS
01242        /* these must be last and never explicitly initialized */
01243        //    int tp_allocs;
01244        //    int tp_frees;
01245        //    int tp_maxalloc;
01246        //    struct _typeobject *tp_next;
01247 #endif
01248 };