Back to index

scribus-ng  1.3.4.dfsg+svn20071115
documentchecker.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 /***************************************************************************
00008        begin                : 2005
00009        copyright            : (C) 2005 by Franz Schmid
00010        email                : Franz.Schmid@altmuehlnet.de
00011        copyright            : (C) 2005 by Craig Bradney
00012        email                : cbradney@zip.com.au
00013 ***************************************************************************/
00014 
00015 /***************************************************************************
00016 *                                                                         *
00017 *   ScMW program is free software; you can redistribute it and/or modify  *
00018 *   it under the terms of the GNU General Public License as published by  *
00019 *   the Free Software Foundation; either version 2 of the License, or     *
00020 *   (at your option) any later version.                                   *
00021 *                                                                         *
00022 ***************************************************************************/
00023 
00024 #include "documentchecker.h"
00025 #include "pageitem.h"
00026 #include "scribusstructs.h"
00027 #include "scribusdoc.h"
00028 #include "page.h"
00029 #include "text/nlsconfig.h"
00030 #include "util.h"
00031 
00032 bool DocumentChecker::checkDocument(ScribusDoc *currDoc)
00033 {
00034        PageItem* currItem;
00035        QString chstr;
00036        struct checkerPrefs checkerSettings;
00037        checkerSettings.ignoreErrors = currDoc->checkerProfiles[currDoc->curCheckProfile].ignoreErrors;
00038        checkerSettings.autoCheck = currDoc->checkerProfiles[currDoc->curCheckProfile].autoCheck;
00039        checkerSettings.checkGlyphs = currDoc->checkerProfiles[currDoc->curCheckProfile].checkGlyphs;
00040        checkerSettings.checkOrphans = currDoc->checkerProfiles[currDoc->curCheckProfile].checkOrphans;
00041        checkerSettings.checkOverflow = currDoc->checkerProfiles[currDoc->curCheckProfile].checkOverflow;
00042        checkerSettings.checkPictures = currDoc->checkerProfiles[currDoc->curCheckProfile].checkPictures;
00043        checkerSettings.checkResolution = currDoc->checkerProfiles[currDoc->curCheckProfile].checkResolution;
00044        checkerSettings.checkTransparency = currDoc->checkerProfiles[currDoc->curCheckProfile].checkTransparency;
00045        checkerSettings.minResolution = currDoc->checkerProfiles[currDoc->curCheckProfile].minResolution;
00046        checkerSettings.maxResolution = currDoc->checkerProfiles[currDoc->curCheckProfile].maxResolution;
00047        checkerSettings.checkAnnotations = currDoc->checkerProfiles[currDoc->curCheckProfile].checkAnnotations;
00048        checkerSettings.checkRasterPDF = currDoc->checkerProfiles[currDoc->curCheckProfile].checkRasterPDF;
00049        checkerSettings.checkForGIF = currDoc->checkerProfiles[currDoc->curCheckProfile].checkForGIF;
00050        checkerSettings.ignoreOffLayers = currDoc->checkerProfiles[currDoc->curCheckProfile].ignoreOffLayers;
00051        currDoc->docItemErrors.clear();
00052        currDoc->masterItemErrors.clear();
00053        currDoc->docLayerErrors.clear();
00054        errorCodes itemError;
00055        errorCodes layerError;
00056        int Lnr;
00057        struct Layer ll;
00058        ll.LNr = 0;
00059        Lnr = 0;
00060        uint layerCount= currDoc->layerCount();
00061        for (uint la = 0; la < layerCount; ++la)
00062        {
00063               layerError.clear();
00064               Level2Layer(currDoc, &ll, Lnr);
00065               if ((!ll.isViewable) && (checkerSettings.ignoreOffLayers))
00066                      continue;
00067               if ((!ll.isPrintable) && (checkerSettings.ignoreOffLayers))
00068                      continue;
00069               if ((ll.transparency != 1.0) && (checkerSettings.checkTransparency))
00070                      layerError.insert(Transparency, 0);
00071               if ((ll.blendMode != 0) && (checkerSettings.checkTransparency))
00072                      layerError.insert(BlendMode, 1);
00073               Lnr++;
00074               if (layerError.count() != 0)
00075                      currDoc->docLayerErrors.insert(ll.LNr, layerError);
00076        }
00077        for (uint d = 0; d < currDoc->MasterItems.count(); ++d)
00078        {
00079               currItem = currDoc->MasterItems.at(d);
00080               if (!currItem->printEnabled())
00081                      continue;
00082               if (!(currDoc->layerPrintable(currItem->LayerNr)) && (checkerSettings.ignoreOffLayers))
00083                      continue;
00084               itemError.clear();
00085               if (((currItem->isAnnotation()) || (currItem->isBookmark)) && (checkerSettings.checkAnnotations))
00086                      itemError.insert(PDFAnnotField, 0);
00087               if (((currItem->fillTransparency() != 0.0) || (currItem->lineTransparency() != 0.0) || (currItem->fillBlendmode() != 0) || (currItem->lineBlendmode() != 0)) && (checkerSettings.checkTransparency))
00088                      itemError.insert(Transparency, 0);
00089               if ((currItem->GrType != 0) && (checkerSettings.checkTransparency))
00090               {
00091                      QPtrVector<VColorStop> colorStops = currItem->fill_gradient.colorStops();
00092                      for( uint offset = 0 ; offset < colorStops.count() ; offset++ )
00093                      {
00094                             if (colorStops[offset]->opacity != 1.0)
00095                             {
00096                                    itemError.insert(Transparency, 0);
00097                                    break;
00098                             }
00099                      }
00100               }
00101               if ((currItem->OwnPage == -1) && (checkerSettings.checkOrphans))
00102                      itemError.insert(ObjectNotOnPage, 0);
00103               if (currItem->asImageFrame())
00104               {
00105                      if ((!currItem->PicAvail) && (checkerSettings.checkPictures))
00106                             itemError.insert(MissingImage, 0);
00107                      else
00108                      {
00109                             if  (((qRound(72.0 / currItem->imageXScale()) < checkerSettings.minResolution) || (qRound(72.0 / currItem->imageYScale()) < checkerSettings.minResolution))
00110                                       && (currItem->isRaster) && (checkerSettings.checkResolution))
00111                                    itemError.insert(ImageDPITooLow, 0);
00112                             if  (((qRound(72.0 / currItem->imageXScale()) > checkerSettings.maxResolution) || (qRound(72.0 / currItem->imageYScale()) > checkerSettings.maxResolution))
00113                                       && (currItem->isRaster) && (checkerSettings.checkResolution))
00114                                    itemError.insert(ImageDPITooHigh, 0);
00115                             QFileInfo fi = QFileInfo(currItem->Pfile);
00116                             QString ext = fi.extension(false).lower();
00117                             if ((ext == "pdf") && (checkerSettings.checkRasterPDF))
00118                                    itemError.insert(PlacedPDF, 0);
00119                             if ((ext == "gif") && (checkerSettings.checkForGIF))
00120                                    itemError.insert(ImageIsGIF, 0);
00121                      }
00122               }
00123               if ((currItem->asTextFrame()) || (currItem->asPathText()))
00124               {
00125 #ifndef NLS_PROTO
00126                      if ( currItem->frameOverflows() && (checkerSettings.checkOverflow) && (!((currItem->isAnnotation()) && ((currItem->annotation().Type() == 5) || (currItem->annotation().Type() == 6)))))
00127                             itemError.insert(TextOverflow, 0);
00128                      if (currItem->isAnnotation()) 
00129                      {
00130                             ScFace::FontFormat fformat = currItem->itemText.defaultStyle().charStyle().font().format();
00131                             if (!(fformat == ScFace::SFNT || fformat == ScFace::TTCF))
00132                                    itemError.insert(WrongFontInAnnotation, 0);
00133                      }
00134                      for (int e = 0; e < currItem->itemText.length(); ++e)
00135                      {
00136                             uint chr = currItem->itemText.text(e).unicode();
00137                             if ((chr == 13) || (chr == 32) || (chr == 29) || (chr == 28) || (chr == 27) || (chr == 26) || (chr == 25))
00138                                    continue;
00139                             if ((currItem->itemText.charStyle(e).effects() & ScStyle_SmallCaps) || (currItem->itemText.charStyle(e).effects() & ScStyle_AllCaps))
00140                             {
00141                                    chstr = currItem->itemText.text(e);
00142                                    if (chstr.upper() != currItem->itemText.text(e))
00143                                           chstr = chstr.upper();
00144                                    chr = chstr[0].unicode();
00145                             }
00146                             if (chr == 9)
00147                             {
00148                                    for (uint t1 = 0; t1 < currItem->itemText.paragraphStyle(e).tabValues().count(); t1++)
00149                                    {
00150                                           if (currItem->itemText.paragraphStyle(e).tabValues()[t1].tabFillChar.isNull())
00151                                                  continue;
00152                                           chstr = QString(currItem->itemText.paragraphStyle(e).tabValues()[t1].tabFillChar);
00153                                           if ((currItem->itemText.charStyle(e).effects() & ScStyle_SmallCaps) || (currItem->itemText.charStyle(e).effects() & ScStyle_AllCaps))
00154                                           {
00155                                                  if (chstr.upper() != QString(currItem->itemText.paragraphStyle(e).tabValues()[t1].tabFillChar))
00156                                                         chstr = chstr.upper();
00157                                           }
00158                                           chr = chstr[0].unicode();
00159                                           if ((!currItem->itemText.charStyle(e).font().canRender(chr)) && (checkerSettings.checkGlyphs))
00160                                                  itemError.insert(MissingGlyph, 0);
00161                                    }
00162                                    for (uint t1 = 0; t1 < currItem->itemText.defaultStyle().tabValues().count(); t1++)
00163                                    {
00164                                           if (currItem->itemText.defaultStyle().tabValues()[t1].tabFillChar.isNull())
00165                                                  continue;
00166                                           chstr = QString(currItem->itemText.defaultStyle().tabValues()[t1].tabFillChar);
00167                                           if ((currItem->itemText.charStyle(e).effects() & ScStyle_SmallCaps) || (currItem->itemText.charStyle(e).effects() & ScStyle_AllCaps))
00168                                           {
00169                                                  if (chstr.upper() != QString(currItem->itemText.defaultStyle().tabValues()[t1].tabFillChar))
00170                                                         chstr = chstr.upper();
00171                                           }
00172                                           chr = chstr[0].unicode();
00173                                           if ((!currItem->itemText.charStyle(e).font().canRender(chr)) && (checkerSettings.checkGlyphs))
00174                                                  itemError.insert(MissingGlyph, 0);
00175                                    }
00176                                    continue;
00177                             }
00178                             if (chr == 30)
00179                             {
00180                                    for (uint numco = 0x30; numco < 0x3A; ++numco)
00181                                    {
00182                                           if ((!currItem->itemText.charStyle(e).font().canRender(numco)) && (checkerSettings.checkGlyphs))
00183                                                  itemError.insert(MissingGlyph, 0);
00184                                    }
00185                                    continue;
00186                             }
00187                             if ((!currItem->itemText.charStyle(e).font().canRender(chr)) && (checkerSettings.checkGlyphs))
00188                                    itemError.insert(MissingGlyph, 0);
00189                      }
00190 #endif
00191               }
00192               if (itemError.count() != 0)
00193                      currDoc->masterItemErrors.insert(currItem->ItemNr, itemError);
00194        }
00195        for (uint d = 0; d < currDoc->DocItems.count(); ++d)
00196        {
00197               currItem = currDoc->DocItems.at(d);
00198               if (!currItem->printEnabled())
00199                      continue;
00200               if (!(currDoc->layerPrintable(currItem->LayerNr)) && (checkerSettings.ignoreOffLayers))
00201                      continue;
00202               itemError.clear();
00203               if (((currItem->fillTransparency() != 0.0) || (currItem->lineTransparency() != 0.0) || (currItem->fillBlendmode() != 0) || (currItem->lineBlendmode() != 0)) && (checkerSettings.checkTransparency))
00204                      itemError.insert(Transparency, 0);
00205               if ((currItem->GrType != 0) && (checkerSettings.checkTransparency))
00206               {
00207                      QPtrVector<VColorStop> colorStops = currItem->fill_gradient.colorStops();
00208                      for( uint offset = 0 ; offset < colorStops.count() ; offset++ )
00209                      {
00210                             if (colorStops[offset]->opacity != 1.0)
00211                             {
00212                                    itemError.insert(Transparency, 0);
00213                                    break;
00214                             }
00215                      }
00216               }
00217               if (((currItem->isAnnotation()) || (currItem->isBookmark)) && (checkerSettings.checkAnnotations))
00218                      itemError.insert(PDFAnnotField, 0);
00219               if ((currItem->OwnPage == -1) && (checkerSettings.checkOrphans))
00220                      itemError.insert(ObjectNotOnPage, 0);
00221               if (currItem->asImageFrame())
00222               {
00223                      if ((!currItem->PicAvail) && (checkerSettings.checkPictures))
00224                             itemError.insert(MissingImage, 0);
00225                      else
00226                      {
00227                             if  (((qRound(72.0 / currItem->imageYScale()) < checkerSettings.minResolution) || (qRound(72.0 / currItem->imageYScale()) < checkerSettings.minResolution))
00228                                        && (currItem->isRaster) && (checkerSettings.checkResolution))
00229                                    itemError.insert(ImageDPITooLow, 0);
00230                             if  (((qRound(72.0 / currItem->imageXScale()) > checkerSettings.maxResolution) || (qRound(72.0 / currItem->imageYScale()) > checkerSettings.maxResolution))
00231                                       && (currItem->isRaster) && (checkerSettings.checkResolution))
00232                                    itemError.insert(ImageDPITooHigh, 0);
00233                             QFileInfo fi = QFileInfo(currItem->Pfile);
00234                             QString ext = fi.extension(false).lower();
00235                             if ((ext == "pdf") && (checkerSettings.checkRasterPDF))
00236                                    itemError.insert(PlacedPDF, 0);
00237                             if ((ext == "gif") && (checkerSettings.checkForGIF))
00238                                    itemError.insert(ImageIsGIF, 0);
00239                      }
00240               }
00241               if ((currItem->asTextFrame()) || (currItem->asPathText()))
00242               {
00243 #ifndef NLS_PROTO
00244                      if ( currItem->frameOverflows() && (checkerSettings.checkOverflow) && (!((currItem->isAnnotation()) && ((currItem->annotation().Type() == 5) || (currItem->annotation().Type() == 6)))))
00245                             itemError.insert(TextOverflow, 0);
00246                      if (currItem->isAnnotation()) 
00247                      {
00248                             ScFace::FontFormat fformat = currItem->itemText.defaultStyle().charStyle().font().format();
00249                             if (!(fformat == ScFace::SFNT || fformat == ScFace::TTCF))
00250                                    itemError.insert(WrongFontInAnnotation, 0);
00251                      }
00252                      for (int e = 0; e < currItem->itemText.length(); ++e)
00253                      {
00254                             uint chr = currItem->itemText.text(e).unicode();
00255                             if ((chr == 13) || (chr == 32) || (chr == 29) || (chr == 28) || (chr == 27) || (chr == 26) || (chr == 25))
00256                                    continue;
00257                             if ((currItem->itemText.charStyle(e).effects() & ScStyle_SmallCaps) || (currItem->itemText.charStyle(e).effects() & ScStyle_AllCaps))
00258                             {
00259                                    chstr = currItem->itemText.text(e,1);
00260                                    if (chstr.upper() != currItem->itemText.text(e,1))
00261                                           chstr = chstr.upper();
00262                                    chr = chstr[0].unicode();
00263                             }
00264                             if (chr == 9)
00265                             {
00266                                    for (uint t1 = 0; t1 < currItem->itemText.paragraphStyle(e).tabValues().count(); t1++)
00267                                    {
00268                                           if (currItem->itemText.paragraphStyle(e).tabValues()[t1].tabFillChar.isNull())
00269                                                  continue;
00270                                           chstr = QString(currItem->itemText.paragraphStyle(e).tabValues()[t1].tabFillChar);
00271                                           if ((currItem->itemText.charStyle(e).effects() & ScStyle_SmallCaps) || (currItem->itemText.charStyle(e).effects() & ScStyle_AllCaps))
00272                                           {
00273                                                  if (chstr.upper() != QString(currItem->itemText.paragraphStyle(e).tabValues()[t1].tabFillChar))
00274                                                         chstr = chstr.upper();
00275                                           }
00276                                           chr = chstr[0].unicode();
00277                                           if ((!currItem->itemText.charStyle(e).font().canRender(chr)) && (checkerSettings.checkGlyphs))
00278                                                  itemError.insert(MissingGlyph, 0);
00279                                    }
00280                                    for (uint t1 = 0; t1 < currItem->itemText.defaultStyle().tabValues().count(); t1++)
00281                                    {
00282                                           if (currItem->itemText.defaultStyle().tabValues()[t1].tabFillChar.isNull())
00283                                                  continue;
00284                                           chstr = QString(currItem->itemText.defaultStyle().tabValues()[t1].tabFillChar);
00285                                           if ((currItem->itemText.charStyle(e).effects() & ScStyle_SmallCaps) || (currItem->itemText.charStyle(e).effects() & ScStyle_AllCaps))
00286                                           {
00287                                                  if (chstr.upper() != QString(currItem->itemText.defaultStyle().tabValues()[t1].tabFillChar))
00288                                                         chstr = chstr.upper();
00289                                           }
00290                                           chr = chstr[0].unicode();
00291                                           if ((!currItem->itemText.charStyle(e).font().canRender(chr)) && (checkerSettings.checkGlyphs))
00292                                                  itemError.insert(MissingGlyph, 0);
00293                                    }
00294                                    continue;
00295                             }
00296                             if (chr == 30)
00297                             {
00298                                    for (uint numco = 0x30; numco < 0x3A; ++numco)
00299                                    {
00300                                           if ((!currItem->itemText.charStyle(e).font().canRender(numco)) && (checkerSettings.checkGlyphs))
00301                                                  itemError.insert(MissingGlyph, 0);
00302                                    }
00303                                    continue;
00304                             }
00305                             if ((!currItem->itemText.charStyle(e).font().canRender(chr)) && (checkerSettings.checkGlyphs))
00306                                    itemError.insert(MissingGlyph, 0);
00307                      }
00308 #endif
00309               }
00310               if (itemError.count() != 0)
00311                      currDoc->docItemErrors.insert(currItem->ItemNr, itemError);
00312        }
00313        
00314        return ((currDoc->docItemErrors.count() != 0) || (currDoc->masterItemErrors.count() != 0) || (currDoc->docLayerErrors.count() != 0));
00315 }