~ubuntu-branches/ubuntu/wily/scribus/wily-proposed

« back to all changes in this revision

Viewing changes to scribus/pdflib.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Oleksandr Moskalenko
  • Date: 2009-01-23 16:19:28 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090123161928-15mux08ba81ouz2p
Tags: 1.3.3.13.dfsg~svn20081228-2
debian/control: Fix a typo on build depends that somehow passed through
my pbuilder test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
201
201
                if (!abortExport)
202
202
                {
203
203
                        if (doc.PDF_Options.Version == PDFOptions::PDFVersion_X3)
204
 
                                PDF_End_Doc(ScMW->PrinterProfiles[doc.PDF_Options.PrintProf], nam, Components);
 
204
                                ret = PDF_End_Doc(ScMW->PrinterProfiles[doc.PDF_Options.PrintProf], nam, Components);
205
205
                        else
206
 
                                PDF_End_Doc();
 
206
                                ret = PDF_End_Doc();
207
207
                }
208
208
                else
209
209
                        closeAndCleanup();
980
980
                        else */
981
981
//                      {
982
982
                                
983
 
                                GListeInd glyphIndexes;
984
983
                                struct GlNamInd glIndexName;
985
 
                                GlyphsIdxOfFont.insert(it.key(), glyphIndexes);
 
984
                                QMap<uint,uint>      glUniToIndex;
 
985
                                QMap<uint, GlNamInd> glIndexToNames;
986
986
                                QMap<uint,std::pair<uint,QString> > gl;
987
 
                                GlyNames2(AllFonts[it.key()], &gl);
 
987
                                GlyMaps(AllFonts[it.key()], &glUniToIndex, &gl);
988
988
                                int nglyphs = 0;
989
989
                                QMap<uint,std::pair<uint,QString> >::Iterator gli;
990
990
                                for (gli = gl.begin(); gli != gl.end(); ++gli)
1011
1011
                                                        PutDoc(QString::number(static_cast<int>(AllFonts[it.key()]->CharWidth[gl[glyph].first] * 1000))+" ");
1012
1012
                                                        glIndexName.Code = chCount + Fc * 256;
1013
1013
                                                        glIndexName.Name = "/" + gl[glyph].second;
1014
 
                                                        glyphIndexes[gl[glyph].first] = glIndexName;
 
1014
                                                        glIndexToNames[glyph] = glIndexName;
1015
1015
                                                }
1016
1016
                                                else
1017
1017
                                                        PutDoc("0 ");
1116
1116
                                        Seite.FObjects["Fo"+QString::number(a)+"S"+QString::number(Fc)] = ObjCounter;
1117
1117
                                        ObjCounter++;
1118
1118
                                } // for(Fc)
 
1119
                                GListeInd glyphIndexes;
 
1120
                                glyphIndexes.uniToIndex   = glUniToIndex;
 
1121
                                glyphIndexes.indexToNames = glIndexToNames;
1119
1122
                                GlyphsIdxOfFont.insert(it.key(), glyphIndexes);
1120
1123
                                StartObj(ObjCounter);
1121
1124
                                PutDoc("[ 0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 ");
1240
1243
                dataD.ResName = ResNam+QString::number(ResCount);
1241
1244
                dataD.ICCArray = "[ /ICCBased "+QString::number(ObjCounter-1)+" 0 R ]";
1242
1245
                dataD.ResNum = ObjCounter;
 
1246
                dataD.components = Options.SComp;
1243
1247
                ICCProfiles[Options.SolidProf] = dataD;
1244
1248
                PutDoc("[ /ICCBased "+QString::number(ObjCounter-1)+" 0 R ]\n");
1245
1249
                PutDoc("endobj\n");
3440
3444
                chx = out2.mid(d-za2, 1);
3441
3445
        }
3442
3446
        uint cc = chx[0].unicode();
3443
 
        uint idx = 0;
3444
 
        if (GlyphsIdxOfFont[hl->cfont->scName()].contains(cc))
3445
 
                idx = GlyphsIdxOfFont[hl->cfont->scName()][cc].Code;
 
3447
        uint idx = 0, ind;
 
3448
        const GListeInd& listIndexes = GlyphsIdxOfFont[hl->cfont->scName()];
 
3449
        QMap<uint, uint>::ConstIterator itl = listIndexes.uniToIndex.find(cc);
 
3450
        if (itl != listIndexes.uniToIndex.end())
 
3451
        {
 
3452
                ind = itl.data();
 
3453
                QMap<uint, GlNamInd>::ConstIterator itx = listIndexes.indexToNames.find(ind);
 
3454
                if( itx != listIndexes.indexToNames.end())
 
3455
                        idx = itx.data().Code;
 
3456
        }
3446
3457
        uint idx1 = (idx >> 8) & 0xFF;
3447
3458
        if (hl->cstyle & 32)
3448
3459
        {
3594
3605
        }
3595
3606
        else
3596
3607
        {
3597
 
                cc = chx[0].unicode();
 
3608
                cc  = chx[0].unicode();
3598
3609
                idx = 0;
3599
 
                if (GlyphsIdxOfFont[hl->cfont->scName()].contains(cc))
3600
 
                        idx = GlyphsIdxOfFont[hl->cfont->scName()][cc].Code;
 
3610
                itl = listIndexes.uniToIndex.find(cc);
 
3611
                if (itl != listIndexes.uniToIndex.end())
 
3612
                {
 
3613
                        ind = itl.data();
 
3614
                        QMap<uint, GlNamInd>::ConstIterator itx = listIndexes.indexToNames.find(ind);
 
3615
                        if( itx != listIndexes.indexToNames.end())
 
3616
                                idx = itx.data().Code;
 
3617
                }
3601
3618
                idx1 = (idx >> 8) & 0xFF;
3602
3619
                tmp += UsedFontsP[hl->cfont->scName()]+"S"+QString::number(idx1)+" "+FToStr(tsz / 10.0)+" Tf\n";
3603
3620
                if (hl->cstroke != CommonStrings::None)
3651
3668
                                double wtr = Cwidth(&doc, hl->cfont, chx, chs) * (hl->cscale / 1000.0);
3652
3669
                                tmp += "1 0 0 1 "+FToStr(hl->xp+wtr)+" "+FToStr(-hl->yp+(hl->csize / 10.0) * (hl->cbase / 1000.0))+" Tm\n";
3653
3670
                                chx = "-";
3654
 
                                cc = chx[0].unicode();
 
3671
                                cc  = chx[0].unicode();
3655
3672
                                idx = 0;
3656
 
                                if (GlyphsIdxOfFont[hl->cfont->scName()].contains(cc))
3657
 
                                        idx = GlyphsIdxOfFont[hl->cfont->scName()][cc].Code;
 
3673
                                itl = listIndexes.uniToIndex.find(cc);
 
3674
                                if (itl != listIndexes.uniToIndex.end())
 
3675
                                {
 
3676
                                        ind = itl.data();
 
3677
                                        QMap<uint, GlNamInd>::ConstIterator itx = listIndexes.indexToNames.find(ind);
 
3678
                                        if( itx != listIndexes.indexToNames.end())
 
3679
                                                idx = itx.data().Code;
 
3680
                                }
3658
3681
                                idx1 = (idx >> 8) & 0xFF;
3659
3682
                                tmp += UsedFontsP[hl->cfont->scName()]+"S"+QString::number(idx1)+" "+FToStr(tsz / 10.0)+" Tf\n";
3660
3683
                                idx2 = idx & 0xFF;
5193
5216
        bool found = false;
5194
5217
        bool alphaM = false;
5195
5218
        bool realCMYK = false;
 
5219
        bool hasGrayProfile = false;
 
5220
        QString profInUse = Profil;
5196
5221
        int afl = Options.Resolution;
5197
5222
        double x2, ax, ay, a2, a1;
5198
5223
        double sxn = 0;
5375
5400
                        }
5376
5401
                        aufl = 1;
5377
5402
                }
 
5403
                bool hasColorEffect = false;
 
5404
                for (uint a = 0; a < c->effectsInUse.count(); ++a)
 
5405
                {
 
5406
                        if ((*c->effectsInUse.at(a)).effectCode == ScImage::EF_COLORIZE)
 
5407
                        {
 
5408
                                hasColorEffect = true;
 
5409
                                break;
 
5410
                        }
 
5411
                }
5378
5412
#ifdef HAVE_CMS
5379
5413
                if ((CMSuse) && (Options.UseProfiles2))
5380
5414
                {
5387
5421
                                QString dataP = "";
5388
5422
                                struct ICCD dataD;
5389
5423
                                if ((Embedded) && (!Options.EmbeddedI))
5390
 
                                {
5391
5424
                                        img3.getEmbeddedProfile(fn, &dataP, &components);
5392
 
                                        if (dataP.isEmpty())
5393
 
                                        {
5394
 
                                                if (img.imgInfo.colorspace == 1)
5395
 
                                                {
5396
 
                                                        loadText((Embedded ? ScMW->InputProfilesCMYK[Options.ImageProf] : ScMW->InputProfilesCMYK[Profil]), &dataP);
5397
 
                                                        components = 4;
5398
 
                                                }
5399
 
                                                else
5400
 
                                                {
5401
 
                                                        loadText((Embedded ? ScMW->InputProfiles[Options.ImageProf] : ScMW->InputProfiles[Profil]), &dataP);
5402
 
                                                        components = 3;
5403
 
                                                }
5404
 
                                        }
5405
 
                                }
5406
 
                                else
 
5425
                                if ((dataP.isEmpty()) || ((img.imgInfo.colorspace == 2) && (hasColorEffect) && (components == 1)))
5407
5426
                                {
 
5427
                                        dataP.setLength(0);
5408
5428
                                        if (img.imgInfo.colorspace == 1)
5409
5429
                                        {
5410
 
                                                loadText((Embedded ? ScMW->InputProfilesCMYK[Options.ImageProf] : ScMW->InputProfilesCMYK[Profil]), &dataP);
 
5430
                                                QString profilePath;
 
5431
                                                if (Embedded && ScMW->InputProfilesCMYK.contains(Options.ImageProf))
 
5432
                                                {
 
5433
                                                        profilePath = ScMW->InputProfilesCMYK[Options.ImageProf];
 
5434
                                                        profInUse = Options.ImageProf;
 
5435
                                                }
 
5436
                                                else if (ScMW->InputProfilesCMYK.contains(Profil))
 
5437
                                                        profilePath = ScMW->InputProfilesCMYK[Profil];
 
5438
                                                else
 
5439
                                                {
 
5440
                                                        profilePath = ScMW->InputProfilesCMYK[c->document()->CMSSettings.DefaultImageCMYKProfile];
 
5441
                                                        profInUse = c->document()->CMSSettings.DefaultImageCMYKProfile;
 
5442
                                                }
 
5443
                                                loadText(profilePath, &dataP);
5411
5444
                                                components = 4;
5412
5445
                                        }
5413
5446
                                        else
5414
5447
                                        {
 
5448
                                                QString profilePath;
 
5449
                                                if (Embedded && ScMW->InputProfiles.contains(Options.ImageProf))
 
5450
                                                {
 
5451
                                                        profilePath = ScMW->InputProfiles[Options.ImageProf];
 
5452
                                                        profInUse = Options.ImageProf;
 
5453
                                                }
 
5454
                                                else if (ScMW->InputProfiles.contains(Profil))
 
5455
                                                        profilePath = ScMW->InputProfiles[Profil];
 
5456
                                                else
 
5457
                                                {
 
5458
                                                        profilePath = ScMW->InputProfiles[c->document()->CMSSettings.DefaultImageRGBProfile];
 
5459
                                                        profInUse = c->document()->CMSSettings.DefaultImageRGBProfile;
 
5460
                                                }
5415
5461
                                                loadText((Embedded ? ScMW->InputProfiles[Options.ImageProf] : ScMW->InputProfiles[Profil]), &dataP);
5416
5462
                                                components = 3;
5417
5463
                                        }
5429
5475
                                dataD.ResName = ResNam+QString::number(ResCount);
5430
5476
                                dataD.ICCArray = "[ /ICCBased "+QString::number(ObjCounter-1)+" 0 R ]";
5431
5477
                                dataD.ResNum = ObjCounter;
5432
 
                                ICCProfiles[Profil] = dataD;
 
5478
                                dataD.components = components;
 
5479
                                ICCProfiles[profInUse] = dataD;
5433
5480
                                PutDoc("[ /ICCBased "+QString::number(ObjCounter-1)+" 0 R ]\n");
5434
5481
                                PutDoc("endobj\n");
5435
5482
                                ResCount++;
5436
5483
                                ObjCounter++;
 
5484
                                hasGrayProfile = (components == 1);
 
5485
                        }
 
5486
                        else
 
5487
                        {
 
5488
                                if (ICCProfiles[Profil].components == 1)
 
5489
                                {
 
5490
                                        if ((img.imgInfo.colorspace == 2) && (hasColorEffect))
 
5491
                                        {
 
5492
                                                profInUse = c->document()->CMSSettings.DefaultImageRGBProfile;
 
5493
                                                if (!ICCProfiles.contains(profInUse))
 
5494
                                                {
 
5495
                                                        int components = 3;
 
5496
                                                        StartObj(ObjCounter);
 
5497
                                                        ObjCounter++;
 
5498
                                                        QString dataP = "";
 
5499
                                                        struct ICCD dataD;
 
5500
                                                        loadText(ScMW->InputProfiles[c->document()->CMSSettings.DefaultImageRGBProfile], &dataP);
 
5501
                                                        components = 3;
 
5502
                                                        PutDoc("<<\n");
 
5503
                                                        if ((Options.CompressMethod != 3) && (CompAvail) && Options.Compress)
 
5504
                                                        {
 
5505
                                                                PutDoc("/Filter /FlateDecode\n");
 
5506
                                                                dataP = CompressStr(&dataP);
 
5507
                                                        }
 
5508
                                                        PutDoc("/Length "+QString::number(dataP.length()+1)+"\n");
 
5509
                                                        PutDoc("/N "+QString::number(components)+"\n");
 
5510
                                                        PutDoc(">>\nstream\n"+EncStream(dataP, ObjCounter-1)+"\nendstream\nendobj\n");
 
5511
                                                        StartObj(ObjCounter);
 
5512
                                                        dataD.ResName = ResNam+QString::number(ResCount);
 
5513
                                                        dataD.ICCArray = "[ /ICCBased "+QString::number(ObjCounter-1)+" 0 R ]";
 
5514
                                                        dataD.ResNum = ObjCounter;
 
5515
                                                        dataD.components = components;
 
5516
                                                        ICCProfiles[profInUse] = dataD;
 
5517
                                                        PutDoc("[ /ICCBased "+QString::number(ObjCounter-1)+" 0 R ]\n");
 
5518
                                                        PutDoc("endobj\n");
 
5519
                                                        ResCount++;
 
5520
                                                        ObjCounter++;
 
5521
                                                }
 
5522
                                        }
 
5523
                                        else
 
5524
                                                hasGrayProfile = true;
 
5525
                                }
5437
5526
                        }
5438
5527
                }
5439
5528
#endif
5493
5582
                        Seite.ImgObjects[ResNam+QString::number(ResCount)] = ObjCounter-1;
5494
5583
                        ResCount++;
5495
5584
                }
 
5585
                bool exportToGrayscale = Options.isGrayscale;
 
5586
                if ((hasGrayProfile) && (doc.HasCMS) && (Options.UseProfiles2) && (!hasColorEffect))
 
5587
                        exportToGrayscale = true;
5496
5588
                if (Options.UseRGB)
5497
5589
                        im = img.ImageToTxt();
5498
5590
                else
5503
5595
                        {
5504
5596
#ifdef HAVE_CMS
5505
5597
                                if ((CMSuse) && (Options.UseProfiles2) && (!realCMYK))
5506
 
                                        im = img.ImageToTxt();
 
5598
                                        im = img.ImageToTxt((hasGrayProfile) && (!hasColorEffect));
5507
5599
                                else
5508
5600
#endif
5509
5601
                                im = img.ImageToCMYK_PDF(true);
5519
5611
#ifdef HAVE_CMS
5520
5612
                if ((CMSuse) && (Options.UseProfiles2))
5521
5613
                {
5522
 
                        PutDoc("/ColorSpace "+ICCProfiles[Profil].ICCArray+"\n");
 
5614
                        PutDoc("/ColorSpace "+ICCProfiles[profInUse].ICCArray+"\n");
5523
5615
                        PutDoc("/Intent /");
5524
5616
                        int inte2 = Intent;
5525
5617
                        if (Options.EmbeddedI)
5565
5657
                                {
5566
5658
                                        QString tmpFile = QDir::convertSeparators(QDir::homeDirPath()+"/.scribus/sc.jpg");
5567
5659
                                        if ((Options.UseRGB) || (Options.UseProfiles2) && (!realCMYK))
5568
 
                                                img.Convert2JPG(tmpFile, Options.Quality, false, false);
 
5660
                                                img.Convert2JPG(tmpFile, Options.Quality, false, (hasGrayProfile) && (!hasColorEffect));
5569
5661
                                        else
5570
5662
                                        {
5571
5663
                                                if (Options.isGrayscale)
5591
5683
                        {
5592
5684
                                QString tmpFile = QDir::convertSeparators(QDir::homeDirPath()+"/.scribus/sc.jpg");
5593
5685
                                if ((Options.UseRGB) || (Options.UseProfiles2) && (!realCMYK))
5594
 
                                        img.Convert2JPG(tmpFile, Options.Quality, false, false);
 
5686
                                        img.Convert2JPG(tmpFile, Options.Quality, false, (hasGrayProfile) && (!hasColorEffect));
5595
5687
                                else
5596
5688
                                {
5597
5689
                                        if (Options.isGrayscale)
5682
5774
                return "";
5683
5775
}
5684
5776
 
5685
 
void PDFlib::PDF_End_Doc(const QString& PrintPr, const QString& Name, int Components)
 
5777
bool PDFlib::PDF_End_Doc(const QString& PrintPr, const QString& Name, int Components)
5686
5778
{
5687
5779
        QString tmp;
5688
5780
        uint StX;
6066
6158
                PutDoc("/Encrypt "+QString::number(Encrypt)+" 0 R\n");
6067
6159
        PutDoc(">>\nstartxref\n");
6068
6160
        PutDoc(QString::number(StX)+"\n%%EOF\n");
6069
 
        closeAndCleanup();
 
6161
        return closeAndCleanup();
6070
6162
}
6071
6163
 
6072
 
void PDFlib::closeAndCleanup()
 
6164
bool PDFlib::closeAndCleanup()
6073
6165
{
 
6166
        bool writeSucceed = (Spool.status() == IO_Ok);
 
6167
        if (!writeSucceed)
 
6168
                PDF_Error_WriteFailure();
6074
6169
        Spool.close();
6075
 
        if (abortExport)
 
6170
        if (abortExport || !writeSucceed)
6076
6171
        {
6077
6172
                if (Spool.exists())
6078
6173
                        Spool.remove();
6086
6181
        Shadings.clear();
6087
6182
        Transpar.clear();
6088
6183
        ICCProfiles.clear();
6089
 
 
 
6184
        return writeSucceed;
 
6185
}
 
6186
 
 
6187
void PDFlib::PDF_Error(const QString& errorMsg)
 
6188
{
 
6189
        ErrorMessage = errorMsg;
 
6190
        if (!ScQApp->usingGUI())
 
6191
                qDebug(errorMsg.local8Bit().data());
 
6192
}
 
6193
 
 
6194
void PDFlib::PDF_Error_WriteFailure(void)
 
6195
{
 
6196
        PDF_Error( tr("A write error occured, please check available disk space"));
6090
6197
}
6091
6198
 
6092
6199
void PDFlib::cancelRequested()