Subversion Repositories Scribus

Rev

Rev 2702 | Rev 2834 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8 paul 1
/***************************************************************************
2
                          util.cpp  -  description
3
                             -------------------
4
    begin                : Fri Sep 14 2001
5
    copyright            : (C) 2001 by Franz Schmid
6
    email                : Franz.Schmid@altmuehlnet.de
7
 ***************************************************************************/
8
 
9
/***************************************************************************
10
 *                                                                         *
11
 *   This program is free software; you can redistribute it and/or modify  *
12
 *   it under the terms of the GNU General Public License as published by  *
13
 *   the Free Software Foundation; either version 2 of the License, or     *
14
 *   (at your option) any later version.                                   *
15
 *                                                                         *
16
 ***************************************************************************/
9 Franz 17
 
2529 craig 18
#include "util.h"
8 paul 19
#include <qbitmap.h>
20
#include <qpainter.h>
21
#include <qfile.h>
22
#include <qfileinfo.h>
23
#include <qtextstream.h>
1541 fschmid 24
#include <qdatastream.h>
2295 cbradney 25
#include <qregexp.h>
19 Franz 26
#include <qdir.h>
90 Franz 27
#include <qmessagebox.h>
2632 craig 28
#include <algorithm>
8 paul 29
#include <cstdlib>
30
#include <cmath>
2702 craig 31
 
32
#include "scconfig.h"
33
 
34
#ifdef HAVE_UNISTD_H
213 Franz 35
#include <unistd.h>
2702 craig 36
#endif
37
 
2730 cbradney 38
#if defined(_WIN32)
39
#if defined(_MSC_VER)
40
#define __STDC__ 1 // hack to get md5_buffer correctly identified
41
#endif
42
#include <windows.h>
43
#endif
44
 
8 paul 45
#include "md5.h"
2730 cbradney 46
 
201 Franz 47
#include <setjmp.h>
204 Franz 48
#include "qprocess.h"
1693 craig 49
#include "scpaths.h"
2517 craig 50
#include "prefsfile.h"
51
#include "prefscontext.h"
52
#include "prefstable.h"
128 Franz 53
 
2517 craig 54
extern PrefsFile *prefsFile;
55
 
1555 fschmid 56
extern "C"
57
{
201 Franz 58
#define XMD_H           // shut JPEGlib up
59
#if defined(Q_OS_UNIXWARE)
60
#  define HAVE_BOOLEAN  // libjpeg under Unixware seems to need this
61
#endif
62
#include <jpeglib.h>
63
#include <jerror.h>
64
#undef HAVE_STDLIB_H
65
#ifdef const
66
#  undef const          // remove crazy C hackery in jconfig.h
67
#endif
68
}
69
 
214 Franz 70
#include "scribus.h"
68 Franz 71
#include <ft2build.h>
72
#include FT_FREETYPE_H
73
#include FT_OUTLINE_H
74
#include FT_GLYPH_H
8 paul 75
#ifdef HAVE_LIBZ
76
        #include <zlib.h>
77
#endif
78
#ifdef HAVE_TIFF
79
        #include <tiffio.h>
80
#endif
81
#ifdef HAVE_CMS
44 Franz 82
        #include CMS_INC
1555 fschmid 83
extern cmsHPROFILE CMSoutputProf;
84
extern cmsHPROFILE CMSprinterProf;
1781 fschmid 85
extern cmsHTRANSFORM stdTransG;
86
extern cmsHTRANSFORM stdProofG;
87
extern cmsHTRANSFORM stdTransImgG;
88
extern cmsHTRANSFORM stdProofImgG;
1555 fschmid 89
extern bool BlackPoint;
90
extern bool SoftProofing;
91
extern bool Gamut;
92
extern bool CMSuse;
93
extern int IntentMonitor;
94
extern int IntentPrinter;
8 paul 95
#endif
96
extern ProfilesL InputProfiles;
214 Franz 97
extern ScribusApp* ScApp;
8 paul 98
 
690 cbradney 99
using namespace std;
100
 
101
QImage ProofImage(QImage *Image)
8 paul 102
{
103
#ifdef HAVE_CMS
690 cbradney 104
        QImage out = Image->copy();
8 paul 105
        if ((CMSuse) && (SoftProofing))
167 Franz 106
        {
107
                for (int i=0; i < out.height(); ++i)
8 paul 108
                {
109
                        LPBYTE ptr = out.scanLine(i);
1781 fschmid 110
                        cmsDoTransform(stdProofImgG, ptr, ptr, out.width());
8 paul 111
                }
167 Franz 112
        }
8 paul 113
        else
167 Franz 114
        {
115
                if (CMSuse)
8 paul 116
                {
167 Franz 117
                        for (int i=0; i < out.height(); ++i)
8 paul 118
                        {
119
                                LPBYTE ptr = out.scanLine(i);
1781 fschmid 120
                                cmsDoTransform(stdTransImgG, ptr, ptr, out.width());
8 paul 121
                        }
122
                }
167 Franz 123
        }
8 paul 124
        return out;
125
#else
690 cbradney 126
        return Image->copy();
8 paul 127
#endif
128
}
129
 
204 Franz 130
/******************************************************************
131
 * Function System()
132
 *  
133
 * Create a new process via QProcess and wait until finished.
134
 * return the process exit code.
135
 *
136
 ******************************************************************/
137
 
138
int System(const QStringList & args)
139
{
140
        QProcess *proc = new QProcess(NULL);
141
        proc->setArguments(args);
142
        if ( !proc->start() )
143
        {
214 Franz 144
                delete proc;
204 Franz 145
                return 1;
146
        }
147
        /* start was OK */
690 cbradney 148
        /* wait a little bit */
149
        while( proc->isRunning() )
2730 cbradney 150
#ifndef _WIN32
204 Franz 151
                usleep(5000);
2730 cbradney 152
#else
153
                Sleep(5);
154
#endif
690 cbradney 155
 
204 Franz 156
        int ex = proc->exitStatus();
157
        delete proc;
158
        return ex;
159
}
160
 
2529 craig 161
/**
162
 * @brief Return common gs args used across Scribus
163
 */
164
 
204 Franz 165
/******************************************************************
166
 * Function callGS()
167
 *   build the complete list of arguments for the call of our
168
 *   System() function.
169
 *
170
 *   The gs commands are all similar and consist of a few constant
171
 *   arguments, the variablke arguments and the end arguments which
2529 craig 172
 *   are also invariant. It will always use -q -dNOPAUSE and
173
 *   will always end with -c showpage -c quit. It also does automatic
174
 *   device selection unless overridden, and uses the user's antialiasing
175
 *   preferences and font search path.
204 Franz 176
 ******************************************************************/
1555 fschmid 177
 
2529 craig 178
int callGS(const QStringList& args_in, const QString device)
204 Franz 179
{
2529 craig 180
        return callGS(args_in.join(" "), device);
181
}
182
 
183
int callGS(const QString& args_in, const QString device)
184
{
1186 fschmid 185
        QString cmd1 = ScApp->Prefs.gs_exe;
186
        cmd1 += " -q -dNOPAUSE";
2529 craig 187
        // Choose rendering device
188
        if (device != "")
189
                // user specified device
190
                cmd1 += " -sDEVICE="+device;
191
        else if (ScApp->HavePngAlpha != 0)
1186 fschmid 192
                cmd1 += " -sDEVICE=png16m";
214 Franz 193
        else
1186 fschmid 194
                cmd1 += " -sDEVICE=pngalpha";
2529 craig 195
        // and antialiasing
1545 cbradney 196
        if (ScApp->Prefs.gs_AntiAliasText)
1186 fschmid 197
                cmd1 += " -dTextAlphaBits=4";
1545 cbradney 198
        if (ScApp->Prefs.gs_AntiAliasGraphics)
1186 fschmid 199
                cmd1 += " -dGraphicsAlphaBits=4";
2517 craig 200
 
201
        // Add any extra font paths being used by Scribus to gs's font search path
202
        PrefsContext *pc = prefsFile->getContext("Fonts");
203
        PrefsTable *extraFonts = pc->getTable("ExtraFontDirs");
204
        if (extraFonts->getRowCount() >= 1)
205
                cmd1 += QString(" -sFONTPATH='%1'").arg(extraFonts->get(0,0));
206
        for (int i = 1; i < extraFonts->getRowCount(); ++i)
207
                cmd1 += QString(":'%1'").arg(extraFonts->get(i,0));
208
 
209
        // then add any user specified args and run gs
2529 craig 210
        cmd1 += " " + args_in + " -c showpage -c quit";
2621 fschmid 211
//      qDebug("Calling gs as: %s", cmd1.ascii());
2642 craig 212
        return system(cmd1.local8Bit());
204 Franz 213
}
214
 
215
int copyFile(QString source, QString target)
216
{
217
        if ((source.isNull()) || (target.isNull()))
218
                return -1;
219
        if (source == target)
220
                return -1;
221
        QFile s(source);
222
        QFile t(target);
223
        if (!s.exists())
224
                return -1;
225
        QByteArray bb(s.size());
226
        if (s.open(IO_ReadOnly))
227
        {
228
                s.readBlock(bb.data(), s.size());
229
                s.close();
230
                if (t.open(IO_WriteOnly))
231
                {
232
                        t.writeBlock(bb.data(), bb.size());
233
                        t.close();
234
                }
235
        }
236
        return 0;
237
}
238
 
239
int moveFile(QString source, QString target)
240
{
241
        if ((source.isNull()) || (target.isNull()))
242
                return -1;
243
        if (source == target)
244
                return -1;
245
        copyFile(source, target);
246
        unlink(source);
247
        return 0;
248
}
249
 
690 cbradney 250
QPixmap LoadPDF(QString fn, int Page, int Size, int *w, int *h)
19 Franz 251
{
252
        QString tmp, cmd1, cmd2;
282 Franz 253
        QString tmpFile = QDir::convertSeparators(QDir::homeDirPath()+"/.scribus/sc.png");
19 Franz 254
        QPixmap pm;
255
        int ret = -1;
690 cbradney 256
        tmp.setNum(Page);
204 Franz 257
        QStringList args;
258
        args.append("-r72");
259
        args.append("-sOutputFile="+tmpFile);
260
        args.append("-dFirstPage="+tmp);
261
        args.append("-dLastPage="+tmp);
1816 fschmid 262
        args.append("\""+fn+"\"");
204 Franz 263
        ret = callGS(args);
19 Franz 264
        if (ret == 0)
167 Franz 265
        {
19 Franz 266
                QImage image;
159 Franz 267
                image.load(tmpFile);
204 Franz 268
                unlink(tmpFile);
1555 fschmid 269
                QImage im2;
20 Franz 270
                *h = image.height();
271
                *w = image.width();
80 Franz 272
                double sx = image.width() / static_cast<double>(Size);
273
                double sy = image.height() / static_cast<double>(Size);
167 Franz 274
                double t = (sy < sx ? sx : sy);
275
                im2 = image.smoothScale(static_cast<int>(image.width() / t), static_cast<int>(image.height() / t));
19 Franz 276
                pm.convertFromImage(im2);
277
                QPainter p;
278
                p.begin(&pm);
279
                p.setBrush(Qt::NoBrush);
280
                p.setPen(Qt::black);
281
                p.drawRect(0, 0, pm.width(), pm.height());
282
                p.end();
283
                im2.detach();
167 Franz 284
        }
19 Franz 285
        return pm;
286
}
287
 
8 paul 288
QString GetAttr(QDomElement *el, QString at, QString def)
289
{
290
        return el->attribute(at, def);
291
}
292
 
293
int QStoInt(QString in)
294
{
2093 cbradney 295
        /* Dont need this, toInt returns 0 on failure, dont even need this function really.
8 paul 296
        bool ok = false;
297
        int c = in.toInt(&ok);
167 Franz 298
        return ok ? c : 0;
2093 cbradney 299
        */
300
        return in.toInt();
8 paul 301
}
302
 
80 Franz 303
double QStodouble(QString in)
8 paul 304
{
305
        bool ok = false;
80 Franz 306
        double c = in.toDouble(&ok);
167 Franz 307
        return ok ? c : 0.0;
8 paul 308
}
309
 
310
QPixmap loadIcon(QString nam)
311
{
1693 craig 312
        QString iconFilePath = QString("%1/%2").arg(ScPaths::instance().iconDir()).arg(nam);
8 paul 313
        QPixmap pm;
1672 craig 314
        if (!QFile::exists(iconFilePath))
315
                qWarning("Unable to load icon %s: File not found", iconFilePath.ascii());
316
        else
317
        {
318
                pm.load(iconFilePath);
319
                if (pm.isNull())
320
                        qWarning("Unable to load icon %s: Got null pixmap", iconFilePath.ascii());
321
        }
8 paul 322
        return pm;
323
}
324
 
1109 fschmid 325
uint getDouble(QString in, bool raw)
326
{
327
        QByteArray bb(4);
328
        if (raw)
329
        {
330
                bb[3] = static_cast<uchar>(QChar(in.at(0)));
331
                bb[2] = static_cast<uchar>(QChar(in.at(1)));
332
                bb[1] = static_cast<uchar>(QChar(in.at(2)));
333
                bb[0] = static_cast<uchar>(QChar(in.at(3)));
334
        }
335
        else
336
        {
337
                bb[0] = static_cast<uchar>(QChar(in.at(0)));
338
                bb[1] = static_cast<uchar>(QChar(in.at(1)));
339
                bb[2] = static_cast<uchar>(QChar(in.at(2)));
340
                bb[3] = static_cast<uchar>(QChar(in.at(3)));
341
        }
342
        uint ret;
343
        ret = bb[0] & 0xff;
344
        ret |= (bb[1] << 8) & 0xff00;
345
        ret |= (bb[2] << 16) & 0xff0000;
346
        ret |= (bb[3] << 24) & 0xff000000;
347
        return ret;
348
}
349
 
690 cbradney 350
bool loadText(QString filename, QString *Buffer)
8 paul 351
{
690 cbradney 352
        QFile f(filename);
8 paul 353
        QFileInfo fi(f);
354
        if (!fi.exists())
355
                return false;
167 Franz 356
        bool ret;
8 paul 357
        QByteArray bb(f.size());
358
        if (f.open(IO_ReadOnly))
167 Franz 359
        {
8 paul 360
                f.readBlock(bb.data(), f.size());
361
                f.close();
690 cbradney 362
                for (uint posi = 0; posi < bb.size(); ++posi)
8 paul 363
                        *Buffer += bb[posi];
364
                ret = true;
167 Franz 365
        }
8 paul 366
        else
367
                ret = false;
368
        return ret;
369
}
370
 
80 Franz 371
QPointArray RegularPolygon(double w, double h, uint c, bool star, double factor, double rota)
8 paul 372
{
167 Franz 373
        uint cx = star ? c * 2 : c;
80 Franz 374
        double seg = 360.0 / cx;
375
        double sc = rota + 180.0;
376
        double di = factor;
8 paul 377
        int mx = 0;
378
        int my = 0;
379
        QPointArray pts = QPointArray();
380
        for (uint x = 0; x < cx; ++x)
167 Franz 381
        {
8 paul 382
                sc = seg * x + 180.0 + rota;
383
                if (star)
167 Franz 384
                {
385
                        double wf = x % 2 == 0 ? w / 2 : w / 2 * di;
386
                        double hf = x % 2 == 0 ? h / 2 : h / 2 * di;
387
                        mx = qRound(sin(sc / 180 * M_PI) * (wf) + (w/2));
388
                        my = qRound(cos(sc / 180 * M_PI) * (hf) + (h/2));
389
                }
8 paul 390
                else
167 Franz 391
                {
8 paul 392
                        mx = qRound(sin(sc / 180 * M_PI) * (w/2) + (w/2));
393
                        my = qRound(cos(sc / 180 * M_PI) * (h/2) + (h/2));
167 Franz 394
                }
8 paul 395
                pts.resize(x+1);
396
                pts.setPoint(x, mx, my);
167 Franz 397
        }
8 paul 398
        return pts;
399
}
400
 
80 Franz 401
FPointArray RegularPolygonF(double w, double h, uint c, bool star, double factor, double rota)
8 paul 402
{
167 Franz 403
        uint cx = star ? c * 2 : c;
80 Franz 404
        double seg = 360.0 / cx;
405
        double sc = rota + 180.0;
406
        double di = factor;
407
        double mx = 0;
408
        double my = 0;
1884 fschmid 409
        FPointArray pts;
8 paul 410
        for (uint x = 0; x < cx; ++x)
167 Franz 411
        {
8 paul 412
                sc = seg * x + 180.0 + rota;
413
                if (star)
167 Franz 414
                {
415
                        double wf = x % 2 == 0 ? w / 2 : w / 2 * di;
416
                        double hf = x % 2 == 0 ? h / 2 : h / 2 * di;
417
                        mx = qRound(sin(sc / 180 * M_PI) * (wf) + (w/2));
418
                        my = qRound(cos(sc / 180 * M_PI) * (hf) + (h/2));
419
                }
8 paul 420
                else
167 Franz 421
                {
8 paul 422
                        mx = sin(sc / 180 * M_PI) * (w/2) + (w/2);
423
                        my = cos(sc / 180 * M_PI) * (h/2) + (h/2);
167 Franz 424
                }
8 paul 425
                pts.resize(x+1);
426
                pts.setPoint(x, mx, my);
167 Franz 427
        }
8 paul 428
        return pts;
429
}
430
 
431
QPointArray FlattenPath(FPointArray ina, QValueList<uint> &Segs)
432
{
433
        QPointArray Bez(4);
434
        QPointArray outa, cli;
435
        Segs.clear();
436
        if (ina.size() > 3)
167 Franz 437
        {
438
                for (uint poi=0; poi<ina.size()-3; poi += 4)
8 paul 439
                {
167 Franz 440
                        if (ina.point(poi).x() > 900000)
8 paul 441
                        {
442
                                outa.resize(outa.size()+1);
443
                                outa.setPoint(outa.size()-1, cli.point(cli.size()-1));
80 Franz 444
                                Segs.append(outa.size());
8 paul 445
                                continue;
167 Franz 446
                        }
8 paul 447
                        BezierPoints(&Bez, ina.pointQ(poi), ina.pointQ(poi+1), ina.pointQ(poi+3), ina.pointQ(poi+2));
448
                        cli = Bez.cubicBezier();
449
                        outa.putPoints(outa.size(), cli.size()-1, cli);
167 Franz 450
                }
8 paul 451
                outa.resize(outa.size()+1);
452
                outa.setPoint(outa.size()-1, cli.point(cli.size()-1));
167 Franz 453
        }
8 paul 454
        return outa;
455
}
456
 
80 Franz 457
double xy2Deg(double x, double y)
8 paul 458
{
459
        return (atan2(y,x)*(180.0/M_PI));
460
}
461
 
462
void BezierPoints(QPointArray *ar, QPoint n1, QPoint n2, QPoint n3, QPoint n4)
463
{
464
        ar->setPoint(0, n1);
465
        ar->setPoint(1, n2);
466
        ar->setPoint(2, n3);
467
        ar->setPoint(3, n4);
468
        return;
469
}
470
 
690 cbradney 471
void Level2Layer(ScribusDoc *currentDoc, struct Layer *ll, int Level)
8 paul 472
{
690 cbradney 473
        for (uint la2 = 0; la2 < currentDoc->Layers.count(); ++la2)
167 Franz 474
        {
690 cbradney 475
                if (currentDoc->Layers[la2].Level == Level)
8 paul 476
                {
1065 cbradney 477
                        ll->isViewable = currentDoc->Layers[la2].isViewable;
478
                        ll->isPrintable = currentDoc->Layers[la2].isPrintable;
690 cbradney 479
                        ll->LNr = currentDoc->Layers[la2].LNr;
1737 fschmid 480
                        ll->Name = currentDoc->Layers[la2].Name;
8 paul 481
                        break;
482
                }
167 Franz 483
        }
8 paul 484
}
485
 
2122 fschmid 486
int Layer2Level(ScribusDoc *currentDoc, int LayerNr)
487
{
488
        for (uint la2 = 0; la2 < currentDoc->Layers.count(); ++la2)
489
        {
490
                if (currentDoc->Layers[la2].LNr == LayerNr)
491
                        return currentDoc->Layers[la2].Level;
492
        }
493
        return 0;
494
}
495
 
8 paul 496
QString CompressStr(QString *in)
497
{
498
        QString out = "";
499
#ifdef HAVE_LIBZ
500
        QByteArray bb(in->length());
501
        for (uint ax = 0; ax < in->length(); ++ax)
502
                bb[ax] = uchar(QChar(in->at(ax)));
503
        uLong exlen = uint(bb.size() * 0.001 + 16) + bb.size();
504
        QByteArray bc(exlen);
2295 cbradney 505
        int errcode = compress2((Byte *)bc.data(), &exlen, (Byte *)bb.data(), uLong(bb.size()), 9);
506
        if (errcode != Z_OK) {
507
                qDebug(QString("compress2 failed with code %1").arg(errcode));
508
                out = *in;
509
        }
510
        else {
511
                for (uint cl = 0; cl < exlen; ++cl)
512
                        out += bc[cl];
513
        }
8 paul 514
#else
515
        out = *in;
516
#endif
517
        return out;
518
}
519
 
520
char *toHex( uchar u )
521
{
1555 fschmid 522
        static char hexVal[3];
523
        int i = 1;
524
        while ( i >= 0 )
167 Franz 525
        {
526
                ushort hex = (u & 0x000f);
527
                if ( hex < 0x0a )
1555 fschmid 528
                        hexVal[i] = '0'+hex;
167 Franz 529
                else
1555 fschmid 530
                        hexVal[i] = 'A'+(hex-0x0a);
167 Franz 531
                u = u >> 4;
1555 fschmid 532
                i--;
533
        }
534
        hexVal[2] = '\0';
535
        return hexVal;
8 paul 536
}
537
 
538
QString String2Hex(QString *in, bool lang)
539
{
540
        int i = 0;
541
        QString out = "";
542
        for( uint xi = 0; xi < in->length(); ++xi )
167 Franz 543
        {
8 paul 544
                out += toHex(uchar(QChar(in->at(xi))));
545
                ++i;
546
                if ((i>40) && (lang))
167 Franz 547
                {
8 paul 548
                        out += '\n';
549
                        i=0;
550
                }
167 Franz 551
        }
8 paul 552
        return out;
553
}
554
 
555
QByteArray ComputeMD5Sum(QByteArray *in)
556
{
557
        QByteArray MDsum(16);
49 paul 558
        md5_buffer (in->data(), in->size(), reinterpret_cast<void*>(MDsum.data()));
8 paul 559
        return MDsum;
560
}
561
 
19 Franz 562
QString Path2Relative(QString Path)
563
{
564
        QString Ndir = "";
565
        QStringList Pdir = QStringList::split("/", QDir::currentDirPath());
566
        QFileInfo Bfi = QFileInfo(Path);
567
        QStringList Bdir = QStringList::split("/", Bfi.dirPath(true));
690 cbradney 568
        bool end = true;
19 Franz 569
        uint dcoun = 0;
570
        uint dcoun2 = 0;
690 cbradney 571
        while (end)
167 Franz 572
        {
19 Franz 573
                if (Pdir[dcoun] == Bdir[dcoun])
574
                        dcoun++;
575
                else
576
                        break;
577
                if (dcoun > Pdir.count())
578
                        break;
167 Franz 579
        }
19 Franz 580
        dcoun2 = dcoun;
581
        for (uint ddx2 = dcoun; ddx2 < Pdir.count(); ddx2++)
582
                Ndir += "../";
583
        for (uint ddx = dcoun2; ddx < Bdir.count(); ddx++)
584
                Ndir += Bdir[ddx]+"/";
585
        Ndir += Bfi.fileName();
586
        return Ndir;
587
}
588
 
90 Franz 589
/***************************************************************************
590
    begin                : Wed Oct 29 2003
591
    copyright            : (C) 2003 The Scribus Team
592
    email                : paul@all-the-johnsons.co.uk
593
 ***************************************************************************/
594
// check if the file exists, if it does, ask if they're sure
595
// return true if they're sure, else return false;
596
 
597
bool overwrite(QWidget *parent, QString filename)
598
{
167 Franz 599
        bool retval = true;
600
        QFileInfo fi(filename);
601
        if (fi.exists())
1555 fschmid 602
        {
603
                int t = QMessageBox::warning(parent, QObject::tr("File exists"),
604
                                             QObject::tr("A file named '%1' already exists.\nDo you want to replace it with the file you are saving?").arg(filename),
605
                                             QObject::tr("&Cancel"), QObject::tr("&Replace"), "", 1, 0);
606
                if (t == 0)
90 Franz 607
                        retval = false;
1555 fschmid 608
        }
609
        return retval;
90 Franz 610
}
124 Franz 611
 
1957 cbradney 612
void CopyPageItem(struct CopyPasteBuffer *Buffer, PageItem *currItem)
124 Franz 613
{
614
        uint a;
1957 cbradney 615
        Buffer->PType = currItem->itemType();
616
        Buffer->Xpos = currItem->Xpos;
617
        Buffer->Ypos = currItem->Ypos;
618
        Buffer->Width = currItem->Width;
619
        Buffer->Height = currItem->Height;
620
        Buffer->RadRect = currItem->RadRect;
621
        Buffer->FrameType = currItem->FrameType;
622
        Buffer->ClipEdited = currItem->ClipEdited;
623
        Buffer->Pwidth = currItem->Pwidth;
624
        Buffer->Pcolor = currItem->fillColor();
625
        Buffer->Pcolor2 = currItem->lineColor();
626
        Buffer->Shade = currItem->fillShade();
627
        Buffer->Shade2 = currItem->lineShade();
295 Franz 628
        Buffer->GrColor = "";
629
        Buffer->GrColor2 = "";
630
        Buffer->GrShade = 100;
631
        Buffer->GrShade2 = 100;
1957 cbradney 632
        Buffer->fill_gradient = currItem->fill_gradient;
633
        Buffer->GrType = currItem->GrType;
634
        Buffer->GrStartX = currItem->GrStartX;
635
        Buffer->GrStartY = currItem->GrStartY;
636
        Buffer->GrEndX = currItem->GrEndX;
637
        Buffer->GrEndY = currItem->GrEndY;
638
        Buffer->TxtStroke = currItem->TxtStroke;
639
        Buffer->TxtFill = currItem->TxtFill;
640
        Buffer->ShTxtStroke = currItem->ShTxtStroke;
641
        Buffer->ShTxtFill = currItem->ShTxtFill;
642
        Buffer->TxtScale = currItem->TxtScale;
2230 fschmid 643
        Buffer->TxtScaleV = currItem->TxtScaleV;
2234 fschmid 644
        Buffer->TxTBase = currItem->TxtBase;
1957 cbradney 645
        Buffer->TxTStyle = currItem->TxTStyle;
2247 fschmid 646
        Buffer->TxtShadowX = currItem->TxtShadowX;
647
        Buffer->TxtShadowY = currItem->TxtShadowY;
2257 fschmid 648
        Buffer->TxtOutline = currItem->TxtOutline;
2262 fschmid 649
        Buffer->TxtUnderPos = currItem->TxtUnderPos;
650
        Buffer->TxtUnderWidth = currItem->TxtUnderWidth;
2272 fschmid 651
        Buffer->TxtStrikePos = currItem->TxtStrikePos;
652
        Buffer->TxtStrikeWidth = currItem->TxtStrikeWidth;
1957 cbradney 653
        Buffer->Rot = currItem->Rot;
654
        Buffer->PLineArt = currItem->PLineArt;
655
        Buffer->PLineEnd = currItem->PLineEnd;
656
        Buffer->PLineJoin = currItem->PLineJoin;
657
        Buffer->LineSp = currItem->LineSp;
658
        Buffer->LocalScX = currItem->LocalScX;
659
        Buffer->LocalScY = currItem->LocalScY;
660
        Buffer->LocalX = currItem->LocalX;
661
        Buffer->LocalY = currItem->LocalY;
662
        Buffer->PicArt = currItem->PicArt;
663
        Buffer->flippedH = currItem->imageFlippedH();
664
        Buffer->flippedV = currItem->imageFlippedV();
665
        Buffer->BBoxX = currItem->BBoxX;
666
        Buffer->BBoxH = currItem->BBoxH;
2449 cbradney 667
        Buffer->isPrintable = currItem->printable();
1957 cbradney 668
        Buffer->isBookmark = currItem->isBookmark;
669
        Buffer->BMnr = currItem->BMnr;
670
        Buffer->isAnnotation = currItem->isAnnotation;
671
        Buffer->AnType = currItem->AnType;
672
        Buffer->AnAction = currItem->AnAction;
673
        Buffer->An_E_act = currItem->An_E_act;
674
        Buffer->An_X_act = currItem->An_X_act;
675
        Buffer->An_D_act = currItem->An_D_act;
676
        Buffer->An_Fo_act = currItem->An_Fo_act;
677
        Buffer->An_Bl_act = currItem->An_Bl_act;
678
        Buffer->An_K_act = currItem->An_K_act;
679
        Buffer->An_F_act = currItem->An_F_act;
680
        Buffer->An_V_act = currItem->An_V_act;
681
        Buffer->An_C_act = currItem->An_C_act;
682
        Buffer->An_Extern = currItem->An_Extern;
683
        Buffer->AnZiel = currItem->AnZiel;
684
        Buffer->AnName = currItem->itemName();
685
        Buffer->AnActType = currItem->AnActType;
686
        Buffer->AnToolTip = currItem->AnToolTip;
687
        Buffer->AnBwid = currItem->AnBwid;
688
        Buffer->AnBsty = currItem->AnBsty;
689
        Buffer->AnFeed = currItem->AnFeed;
690
        Buffer->AnFlag = currItem->AnFlag;
691
        Buffer->AnFont = currItem->AnFont;
692
        Buffer->AnRollOver = currItem->AnRollOver;
693
        Buffer->AnDown = currItem->AnDown;
694
        Buffer->AnFormat = currItem->AnFormat;
695
        Buffer->AnVis = currItem->AnVis;
696
        Buffer->AnMaxChar = currItem->AnMaxChar;
697
        Buffer->AnChkStil = currItem->AnChkStil;
698
        Buffer->AnIsChk = currItem->AnIsChk;
699
        Buffer->AnAAact = currItem->AnAAact;
700
        Buffer->AnBColor = currItem->AnBColor;
701
        Buffer->AnHTML = currItem->AnHTML;
702
        Buffer->AnUseIcons = currItem->AnUseIcons;
703
        Buffer->AnIPlace = currItem->AnIPlace;
704
        Buffer->AnScaleW = currItem->AnScaleW;
705
        Buffer->Extra = currItem->Extra;
706
        Buffer->TExtra = currItem->TExtra;
707
        Buffer->BExtra = currItem->BExtra;
708
        Buffer->RExtra = currItem->RExtra;
709
        Buffer->Pfile = currItem->Pfile;
710
        Buffer->Pfile2 = currItem->Pfile2;
711
        Buffer->Pfile3 = currItem->Pfile3;
124 Franz 712
        QString Text = "";
1957 cbradney 713
        if (currItem->itemText.count() != 0)
167 Franz 714
        {
1957 cbradney 715
                for (a=0; a<currItem->itemText.count(); ++a)
124 Franz 716
                {
1957 cbradney 717
                        if( (currItem->itemText.at(a)->ch == "\n") || (currItem->itemText.at(a)->ch == "\r"))
124 Franz 718
                                Text += QString(QChar(5))+"\t";
1957 cbradney 719
                        else if(currItem->itemText.at(a)->ch == "\t")
139 Franz 720
                                Text += QString(QChar(4))+"\t";
124 Franz 721
                        else
1957 cbradney 722
                                Text += currItem->itemText.at(a)->ch+"\t";
723
                        Text += currItem->itemText.at(a)->cfont->SCName+"\t";
724
                        Text += QString::number(currItem->itemText.at(a)->csize / 10.0)+"\t";
725
                        Text += currItem->itemText.at(a)->ccolor+"\t";
726
                        Text += QString::number(currItem->itemText.at(a)->cextra)+"\t";
727
                        Text += QString::number(currItem->itemText.at(a)->cshade)+'\t';
728
                        Text += QString::number(currItem->itemText.at(a)->cstyle)+'\t';
729
                        Text += QString::number(currItem->itemText.at(a)->cab)+'\t';
730
                        Text += currItem->itemText.at(a)->cstroke+"\t";
731
                        Text += QString::number(currItem->itemText.at(a)->cshade2)+'\t';
2234 fschmid 732
                        Text += QString::number(currItem->itemText.at(a)->cscale)+'\t';
733
                        Text += QString::number(currItem->itemText.at(a)->cscalev)+'\t';
2247 fschmid 734
                        Text += QString::number(currItem->itemText.at(a)->cbase)+'\t';
735
                        Text += QString::number(currItem->itemText.at(a)->cshadowx)+'\t';
2257 fschmid 736
                        Text += QString::number(currItem->itemText.at(a)->cshadowy)+'\t';
2262 fschmid 737
                        Text += QString::number(currItem->itemText.at(a)->coutline)+'\t';
738
                        Text += QString::number(currItem->itemText.at(a)->cunderpos)+'\t';
2272 fschmid 739
                        Text += QString::number(currItem->itemText.at(a)->cunderwidth)+'\t';
740
                        Text += QString::number(currItem->itemText.at(a)->cstrikepos)+'\t';
741
                        Text += QString::number(currItem->itemText.at(a)->cstrikewidth)+'\n';
124 Franz 742
                }
167 Franz 743
        }
1065 cbradney 744
        Buffer->itemText = Text;
1957 cbradney 745
        Buffer->Clip = currItem->Clip.copy();
746
        Buffer->PoLine = currItem->PoLine.copy();
747
        Buffer->ContourLine = currItem->ContourLine.copy();
748
        Buffer->UseContour = currItem->textFlowUsesContourLine();
749
        Buffer->TabValues = currItem->TabValues;
750
        Buffer->DashValues = currItem->DashValues;
751
        Buffer->DashOffset = currItem->DashOffset;
752
        Buffer->PoShow = currItem->PoShow;
753
        Buffer->BaseOffs = currItem->BaseOffs;
754
        Buffer->Textflow = currItem->textFlowsAroundFrame();
755
        Buffer->Textflow2 = currItem->textFlowUsesBoundingBox();
756
        Buffer->textAlignment = currItem->textAlignment;
757
        Buffer->IFont = currItem->IFont;
758
        Buffer->ISize = currItem->ISize;
759
        Buffer->ExtraV = currItem->ExtraV;
760
        Buffer->Groups = currItem->Groups;
761
        Buffer->IProfile = currItem->IProfile;
762
        Buffer->IRender = currItem->IRender;
763
        Buffer->UseEmbedded = currItem->UseEmbedded;
764
        Buffer->EmProfile = currItem->EmProfile;
765
        Buffer->LayerNr = currItem->LayerNr;
766
        Buffer->ScaleType = currItem->ScaleType;
767
        Buffer->AspectRatio = currItem->AspectRatio;
768
        Buffer->Locked = currItem->locked();
769
        Buffer->LockRes = currItem->sizeLocked();
770
        Buffer->Transparency = currItem->fillTransparency();
771
        Buffer->TranspStroke = currItem->lineTransparency();
772
        Buffer->Reverse = currItem->Reverse;
773
        Buffer->NamedLStyle = currItem->NamedLStyle;
774
        Buffer->Language = currItem->Language;
775
        Buffer->Cols = currItem->Cols;
776
        Buffer->ColGap = currItem->ColGap;
777
        Buffer->isTableItem = currItem->isTableItem;
778
        Buffer->TopLine = currItem->TopLine;
779
        Buffer->LeftLine = currItem->LeftLine;
780
        Buffer->RightLine = currItem->RightLine;
781
        Buffer->BottomLine = currItem->BottomLine;
782
        if (currItem->isTableItem)
234 Franz 783
        {
1957 cbradney 784
                if (currItem->TopLink != 0)
785
                        Buffer->TopLinkID = currItem->TopLink->ItemNr;
234 Franz 786
                else
787
                        Buffer->TopLinkID = -1;
1957 cbradney 788
                if (currItem->LeftLink != 0)
789
                        Buffer->LeftLinkID = currItem->LeftLink->ItemNr;
234 Franz 790
                else
791
                        Buffer->LeftLinkID = -1;
1957 cbradney 792
                if (currItem->RightLink != 0)
793
                        Buffer->RightLinkID = currItem->RightLink->ItemNr;
234 Franz 794
                else
795
                        Buffer->RightLinkID = -1;
1957 cbradney 796
                if (currItem->BottomLink != 0)
797
                        Buffer->BottomLinkID = currItem->BottomLink->ItemNr;
234 Franz 798
                else
799
                        Buffer->BottomLinkID = -1;
800
        }
1957 cbradney 801
        Buffer->startArrowIndex = currItem->startArrowIndex;
802
        Buffer->endArrowIndex = currItem->endArrowIndex;
124 Franz 803
}
125 Franz 804
 
1957 cbradney 805
void WordAndPara(PageItem* currItem, int *w, int *p, int *c, int *wN, int *pN, int *cN)
125 Franz 806
{
807
        QChar Dat = QChar(32);
808
        int para = 0;
809
        int ww = 0;
810
        int cc = 0;
811
        int paraN = 0;
812
        int wwN = 0;
813
        int ccN = 0;
814
        bool first = true;
1957 cbradney 815
        PageItem *nextItem = currItem;
816
        PageItem *nbl = currItem;
817
        while (nextItem != 0)
167 Franz 818
        {
1957 cbradney 819
                if (nextItem->BackBox != 0)
820
                        nextItem = nextItem->BackBox;
125 Franz 821
                else
822
                        break;
167 Franz 823
        }
1957 cbradney 824
        while (nextItem != 0)
167 Franz 825
        {
1957 cbradney 826
                for (uint a = 0; a < nextItem->itemText.count(); ++a)
1555 fschmid 827
                {
1957 cbradney 828
                        QChar b = nextItem->itemText.at(a)->ch[0];
125 Franz 829
                        if (b == QChar(13))
167 Franz 830
                        {
1957 cbradney 831
                                if (a >= nextItem->MaxChars)
125 Franz 832
                                        paraN++;
833
                                else
834
                                        para++;
167 Franz 835
                        }
125 Franz 836
                        if ((!b.isLetterOrNumber()) && (Dat.isLetterOrNumber()) && (!first))
167 Franz 837
                        {
1957 cbradney 838
                                if (a >= nextItem->MaxChars)
125 Franz 839
                                        wwN++;
840
                                else
841
                                        ww++;
167 Franz 842
                        }
1957 cbradney 843
                        if (a >= nextItem->MaxChars)
125 Franz 844
                                ccN++;
845
                        else
846
                                cc++;
1555 fschmid 847
                        Dat = b;
125 Franz 848
                        first = false;
1555 fschmid 849
                }
1957 cbradney 850
                nbl = nextItem;
851
                nextItem = nextItem->NextBox;
167 Franz 852
        }
1065 cbradney 853
        if (nbl->MaxChars < nbl->itemText.count())
125 Franz 854
                paraN++;
855
        else
856
                para++;
857
        if (Dat.isLetterOrNumber())
167 Franz 858
        {
1065 cbradney 859
                if (nbl->MaxChars < nbl->itemText.count())
125 Franz 860
                        wwN++;
861
                else
862
                        ww++;
167 Franz 863
        }
125 Franz 864
        *w = ww;
865
        *p = para;
866
        *c = cc;
867
        *wN = wwN;
868
        *pN = paraN;
869
        *cN = ccN;
870
}
203 Franz 871
 
690 cbradney 872
void ReOrderText(ScribusDoc *currentDoc, ScribusView *view)
203 Franz 873
{
2380 cbradney 874
        double savScale = view->getScale();
875
        view->setScale(1.0);
690 cbradney 876
        currentDoc->RePos = true;
203 Franz 877
        QPixmap pgPix(10, 10);
878
        QRect rd = QRect(0,0,9,9);
879
        ScPainter *painter = new ScPainter(&pgPix, pgPix.width(), pgPix.height());
690 cbradney 880
        for (uint azz=0; azz<currentDoc->MasterItems.count(); ++azz)
203 Franz 881
        {
1957 cbradney 882
                PageItem *currItem = currentDoc->MasterItems.at(azz);
883
                if (currItem->itemType() == PageItem::PathText)
884
                        currItem->DrawObj(painter, rd);
203 Franz 885
        }
690 cbradney 886
        for (uint azz=0; azz<currentDoc->Items.count(); ++azz)
203 Franz 887
        {
1957 cbradney 888
                PageItem *currItem = currentDoc->Items.at(azz);
889
                if ((currItem->itemType() == PageItem::TextFrame) || (currItem->itemType() == PageItem::PathText))
890
                        currItem->DrawObj(painter, rd);
203 Franz 891
        }
690 cbradney 892
        currentDoc->RePos = false;
2380 cbradney 893
        view->setScale(savScale);
203 Franz 894
        delete painter;
895
}
447 cbradney 896
 
897
/*! 10/06/2004 - pv
898
\param QString s1 first string
899
\param QString s2 second string
900
\retval bool t/f related s1>s2
901
 */
902
bool compareQStrings(QString s1, QString s2)
903
{
904
        if (QString::localeAwareCompare(s1, s2) >= 0)
2680 cbradney 905
                return false;
906
        return true;
447 cbradney 907
}
908
 
909
/*! 10/06/2004 - pv
910
Returns a sorted list of QStrings - sorted by locale specific
911
rules! Uses compareQStrings() as rule. There is STL used!
912
TODO: Maybe we can implement one cass for various sorting...
913
\param QStringList aList unsorted string list
914
\retval QStringList sorted string list
915
*/
916
QStringList sortQStringList(QStringList aList)
917
{
918
        std::vector<QString> sortList;
919
        QStringList retList;
920
        QStringList::Iterator it;
921
        for (it = aList.begin(); it != aList.end(); ++it)
922
                sortList.push_back(*it);
923
        std::sort(sortList.begin(), sortList.end(), compareQStrings);
456 fschmid 924
        for(uint i = 0; i < sortList.size(); i++)
447 cbradney 925
                retList.append(sortList[i]);
926
        return retList;
927
}
517 fschmid 928
 
1065 cbradney 929
void GetItemProps(bool newVersion, QDomElement *obj, struct CopyPasteBuffer *OB)
517 fschmid 930
{
931
        QString tmp;
932
        int x, y;
2282 fschmid 933
        double xf, yf, xf2;
1460 cbradney 934
        OB->PType = static_cast<PageItem::ItemType>(QStoInt(obj->attribute("PTYPE")));
517 fschmid 935
        OB->Width=QStodouble(obj->attribute("WIDTH"));
936
        OB->Height=QStodouble(obj->attribute("HEIGHT"));
937
        OB->RadRect = QStodouble(obj->attribute("RADRECT","0"));
938
        OB->ClipEdited = QStoInt(obj->attribute("CLIPEDIT", "0"));
939
        OB->FrameType = QStoInt(obj->attribute("FRTYPE", "0"));
940
        OB->Pwidth=QStodouble(obj->attribute("PWIDTH"));
1394 cbradney 941
        OB->Pcolor = obj->attribute("PCOLOR");
517 fschmid 942
        if ((!newVersion) && (OB->PType == 4))
943
        {
944
                OB->TxtFill = obj->attribute("PCOLOR2");
945
                OB->Pcolor2 = "None";
946
        }
947
        else
948
        {
949
                OB->Pcolor2 = obj->attribute("PCOLOR2");
950
                OB->TxtFill = obj->attribute("TXTFILL", "Black");
951
        }
1394 cbradney 952
        OB->Shade = QStoInt(obj->attribute("SHADE"));
953
        OB->Shade2 = QStoInt(obj->attribute("SHADE2"));
517 fschmid 954
        OB->TxtStroke=obj->attribute("TXTSTROKE", "None");
955
        OB->ShTxtFill=QStoInt(obj->attribute("TXTFILLSH", "100"));
956
        OB->ShTxtStroke=QStoInt(obj->attribute("TXTSTRSH", "100"));
2242 fschmid 957
        OB->TxtScale=qRound(QStodouble(obj->attribute("TXTSCALE", "100")) * 10);
958
        OB->TxtScaleV=qRound(QStodouble(obj->attribute("TXTSCALEV", "100")) * 10);
959
        OB->TxTBase=qRound(QStodouble(obj->attribute("TXTBASE", "0")) * 10);
517 fschmid 960
        OB->TxTStyle=QStoInt(obj->attribute("TXTSTYLE", "0"));
2247 fschmid 961
        OB->TxtShadowX=qRound(QStodouble(obj->attribute("TXTSHX", "5")) * 10);
962
        OB->TxtShadowY=qRound(QStodouble(obj->attribute("TXTSHY", "-5")) * 10);
2257 fschmid 963
        OB->TxtOutline=qRound(QStodouble(obj->attribute("TXTOUT", "1")) * 10);
2262 fschmid 964
        OB->TxtUnderPos=qRound(QStodouble(obj->attribute("TXTULP", "-0.1")) * 10);
965
        OB->TxtUnderWidth=qRound(QStodouble(obj->attribute("TXTULW", "-0.1")) * 10);
2272 fschmid 966
        OB->TxtStrikePos=qRound(QStodouble(obj->attribute("TXTSTP", "-0.1")) * 10);
967
        OB->TxtStrikeWidth=qRound(QStodouble(obj->attribute("TXTSTW", "-0.1")) * 10);
517 fschmid 968
        OB->Cols = QStoInt(obj->attribute("COLUMNS","1"));
969
        OB->ColGap = QStodouble(obj->attribute("COLGAP","0.0"));
970
        OB->GrType = QStoInt(obj->attribute("GRTYP","0"));
971
        OB->fill_gradient.clearStops();
972
        if (OB->GrType != 0)
973
        {
974
                OB->GrStartX = QStodouble(obj->attribute("GRSTARTX","0.0"));
975
                OB->GrStartY = QStodouble(obj->attribute("GRSTARTY","0.0"));
976
                OB->GrEndX = QStodouble(obj->attribute("GRENDX","0.0"));
977
                OB->GrEndY = QStodouble(obj->attribute("GRENDY","0.0"));
978
                OB->GrColor = obj->attribute("GRCOLOR","");
2179 fschmid 979
                if (OB->GrColor == "")
980
                        OB->GrColor = "Black";
981
                OB->GrColor2 = obj->attribute("GRCOLOR2","Black");
982
                if (OB->GrColor2 == "")
983
                        OB->GrColor2 = "Black";
984
                OB->GrShade = QStoInt(obj->attribute("GRSHADE","100"));
985
                OB->GrShade2 = QStoInt(obj->attribute("GRSHADE2","100"));
517 fschmid 986
        }
987
        OB->Rot=QStodouble(obj->attribute("ROT"));
988
        OB->PLineArt=Qt::PenStyle(QStoInt(obj->attribute("PLINEART")));
989
        OB->PLineEnd=Qt::PenCapStyle(QStoInt(obj->attribute("PLINEEND","0")));
990
        OB->PLineJoin=Qt::PenJoinStyle(QStoInt(obj->attribute("PLINEJOIN","0")));
991
        OB->LineSp=QStodouble(obj->attribute("LINESP"));
2309 fschmid 992
        OB->LineSpMode = QStoInt(obj->attribute("LINESPMode","0"));
517 fschmid 993
        OB->LocalScX=QStodouble(obj->attribute("LOCALSCX"));
994
        OB->LocalScY=QStodouble(obj->attribute("LOCALSCY"));
995
        OB->LocalX=QStodouble(obj->attribute("LOCALX"));
996
        OB->LocalY=QStodouble(obj->attribute("LOCALY"));
997
        OB->PicArt=QStoInt(obj->attribute("PICART"));
2258 fschmid 998
        OB->flippedH = QStoInt(obj->attribute("FLIPPEDH")) % 2;
999
        OB->flippedV = QStoInt(obj->attribute("FLIPPEDV")) % 2;
517 fschmid 1000
        OB->BBoxX=QStodouble(obj->attribute("BBOXX"));
1001
        OB->BBoxH=QStodouble(obj->attribute("BBOXH"));
1002
        OB->ScaleType = QStoInt(obj->attribute("SCALETYPE","1"));
1003
        OB->AspectRatio = QStoInt(obj->attribute("RATIO","0"));
1004
        OB->isPrintable=QStoInt(obj->attribute("PRINTABLE"));
1005
        OB->isAnnotation=QStoInt(obj->attribute("ANNOTATION","0"));
1006
        OB->AnType = QStoInt(obj->attribute("ANTYPE","0"));
1007
        OB->AnAction = obj->attribute("ANACTION","");
1008
        OB->An_E_act = obj->attribute("ANEACT","");
1009
        OB->An_X_act = obj->attribute("ANXACT","");
1010
        OB->An_D_act = obj->attribute("ANDACT","");
1011
        OB->An_Fo_act = obj->attribute("ANFOACT","");
1012
        OB->An_Bl_act = obj->attribute("ANBLACT","");
1013
        OB->An_K_act = obj->attribute("ANKACT","");
1014
        OB->An_F_act = obj->attribute("ANFACT","");
1015
        OB->An_V_act = obj->attribute("ANVACT","");
1016
        OB->An_C_act = obj->attribute("ANCACT","");
1017
        OB->AnActType = QStoInt(obj->attribute("ANACTYP","0"));
1018
        OB->An_Extern = obj->attribute("ANEXTERN","");
1019
        if ((OB->An_Extern != "") && (OB->AnActType != 8))
1020
        {
1021
                QFileInfo efp(OB->An_Extern);
1022
                OB->An_Extern = efp.absFilePath();
1023
        }
1024
        OB->AnZiel = QStoInt(obj->attribute("ANZIEL","0"));
1025
        OB->AnName = obj->attribute("ANNAME","");
1026
        OB->AnToolTip = obj->attribute("ANTOOLTIP","");
1027
        OB->AnRollOver = obj->attribute("ANROLL","");
1028
        OB->AnDown = obj->attribute("ANDOWN","");
1029
        OB->AnBwid = QStoInt(obj->attribute("ANBWID","1"));
1030
        OB->AnBsty = QStoInt(obj->attribute("ANBSTY","0"));
1031
        OB->AnFeed = QStoInt(obj->attribute("ANFEED","1"));
1032
        OB->AnFlag = QStoInt(obj->attribute("ANFLAG","0"));
1033
        OB->AnFont = QStoInt(obj->attribute("ANFONT","4"));
1034
        OB->AnFormat = QStoInt(obj->attribute("ANFORMAT","0"));
1035
        OB->AnVis = QStoInt(obj->attribute("ANVIS","0"));
1036
        OB->AnIsChk = static_cast<bool>(QStoInt(obj->attribute("ANCHK","0")));
1037
        OB->AnAAact = static_cast<bool>(QStoInt(obj->attribute("ANAA","0")));
1038
        OB->AnHTML = static_cast<bool>(QStoInt(obj->attribute("ANHTML","0")));
1039
        OB->AnUseIcons = static_cast<bool>(QStoInt(obj->attribute("ANICON","0")));
1040
        OB->AnChkStil = QStoInt(obj->attribute("ANCHKS","0"));
1041
        OB->AnMaxChar = QStoInt(obj->attribute("ANMC","-1"));
1042
        OB->AnBColor = obj->attribute("ANBCOL","None");
1043
        OB->AnIPlace = QStoInt(obj->attribute("ANPLACE","1"));
1044
        OB->AnScaleW = QStoInt(obj->attribute("ANSCALE","0"));
1045
        if (QStoInt(obj->attribute("TRANSPARENT","0")) == 1)
1046
                OB->Pcolor = "None";
1047
        OB->Textflow=QStoInt(obj->attribute("TEXTFLOW"));
1048
        OB->Textflow2 =QStoInt(obj->attribute("TEXTFLOW2","0"));
1049
        OB->UseContour = QStoInt(obj->attribute("TEXTFLOW3","0"));
1050
        OB->Extra=QStodouble(obj->attribute("EXTRA"));
1051
        OB->TExtra=QStodouble(obj->attribute("TEXTRA", "1"));
1052
        OB->BExtra=QStodouble(obj->attribute("BEXTRA", "1"));
1053
        OB->RExtra=QStodouble(obj->attribute("REXTRA", "1"));
1525 cbradney 1054
        OB->PoShow = QStoInt(obj->attribute("PLTSHOW","0"));
517 fschmid 1055
        OB->BaseOffs = QStodouble(obj->attribute("BASEOF","0"));
1056
        OB->ISize = qRound(QStodouble(obj->attribute("ISIZE","12")) * 10);
2382 fschmid 1057
        if (obj->hasAttribute("EXTRAV"))
1058
                OB->ExtraV = qRound(QStodouble(obj->attribute("EXTRAV","0")) / QStodouble(obj->attribute("ISIZE","12")) * 1000.0);
1059
        else
1060
                OB->ExtraV = QStoInt(obj->attribute("TXTKERN"));
517 fschmid 1061
        OB->Pfile=obj->attribute("PFILE");
1062
        OB->Pfile2=obj->attribute("PFILE2","");
1063
        OB->Pfile3=obj->attribute("PFILE3","");
1064
        OB->IProfile=obj->attribute("PRFILE","");
1065
        OB->EmProfile=obj->attribute("EPROF","");
1066
        OB->IRender = QStoInt(obj->attribute("IRENDER","1"));
1067
        OB->UseEmbedded = QStoInt(obj->attribute("EMBEDDED","1"));
1068
        OB->Locked = static_cast<bool>(QStoInt(obj->attribute("LOCK","0")));
1069
        OB->LockRes = static_cast<bool>(QStoInt(obj->attribute("LOCKR","0")));
1070
        OB->Reverse = static_cast<bool>(QStoInt(obj->attribute("REVERS","0")));
1071
        OB->isTableItem = static_cast<bool>(QStoInt(obj->attribute("isTableItem","0")));
1072
        OB->TopLine = static_cast<bool>(QStoInt(obj->attribute("TopLine","0")));
1073
        OB->LeftLine = static_cast<bool>(QStoInt(obj->attribute("LeftLine","0")));
1074
        OB->RightLine = static_cast<bool>(QStoInt(obj->attribute("RightLine","0")));
1075
        OB->BottomLine = static_cast<bool>(QStoInt(obj->attribute("BottomLine","0")));
1076
        OB->TopLinkID =  QStoInt(obj->attribute("TopLINK","-1"));
1077
        OB->LeftLinkID =  QStoInt(obj->attribute("LeftLINK","-1"));
1078
        OB->RightLinkID =  QStoInt(obj->attribute("RightLINK","-1"));
1079
        OB->BottomLinkID =  QStoInt(obj->attribute("BottomLINK","-1"));
1080
        OB->Transparency = QStodouble(obj->attribute("TransValue","0.0"));
1081
        if (obj->hasAttribute("TransValueS"))
1082
                OB->TranspStroke = QStodouble(obj->attribute("TransValueS","0.0"));
1083
        else
1084
                OB->TranspStroke = OB->Transparency;
1085
        tmp = "";
1086
        if (obj->hasAttribute("NUMCLIP"))
1087
        {
1088
                OB->Clip.resize(obj->attribute("NUMCLIP").toUInt());
1089
                tmp = obj->attribute("CLIPCOOR");
1090
                QTextStream fc(&tmp, IO_ReadOnly);
1091
                for (uint c=0; c<obj->attribute("NUMCLIP").toUInt(); ++c)
1092
                {
1093
                        fc >> x;
1094
                        fc >> y;
1095
                        OB->Clip.setPoint(c, x, y);
1096
                }
1097
        }
1098
        else
1099
                OB->Clip.resize(0);
1100
        tmp = "";
1101
        if (obj->hasAttribute("NUMPO"))
1102
        {
1103
                OB->PoLine.resize(obj->attribute("NUMPO").toUInt());
1104
                tmp = obj->attribute("POCOOR");
1105
                QTextStream fp(&tmp, IO_ReadOnly);
1106
                for (uint cx=0; cx<obj->attribute("NUMPO").toUInt(); ++cx)
1107
                {
1108
                        fp >> xf;
1109
                        fp >> yf;
1110
                        OB->PoLine.setPoint(cx, xf, yf);
1111
                }
1112
        }
1113
        else
1114
                OB->PoLine.resize(0);
1115
        tmp = "";
1116
        if (obj->hasAttribute("NUMCO"))
1117
        {
1118
                OB->ContourLine.resize(obj->attribute("NUMCO").toUInt());
1119
                tmp = obj->attribute("COCOOR");
1120
                QTextStream fp(&tmp, IO_ReadOnly);
1121
                for (uint cx=0; cx<obj->attribute("NUMCO").toUInt(); ++cx)
1122
                {
1123
                        fp >> xf;
1124
                        fp >> yf;
1125
                        OB->ContourLine.setPoint(cx, xf, yf);
1126
                }
1127
        }
1128
        else
1129
                OB->ContourLine.resize(0);
1130
        tmp = "";
1131
        if ((obj->hasAttribute("NUMTAB")) && (QStoInt(obj->attribute("NUMTAB","0")) != 0))
1132
        {
2282 fschmid 1133
                struct PageItem::TabRecord tb;
517 fschmid 1134
                tmp = obj->attribute("TABS");
1135
                QTextStream tgv(&tmp, IO_ReadOnly);
1136
                OB->TabValues.clear();
2282 fschmid 1137
                for (int cxv = 0; cxv < QStoInt(obj->attribute("NUMTAB","0")); cxv += 2)
517 fschmid 1138
                {
1139
                        tgv >> xf;
2282 fschmid 1140
                        tgv >> xf2;
1141
                        tb.tabPosition = xf2;
1142
                        tb.tabType = static_cast<int>(xf);
1143
                        tb.tabFillChar = QChar();
1144
                        OB->TabValues.append(tb);
517 fschmid 1145
                }
1146
                tmp = "";
1147
        }
1148
        else
1149
                OB->TabValues.clear();
1150
        if ((obj->hasAttribute("NUMDASH")) && (QStoInt(obj->attribute("NUMDASH","0")) != 0))
1151
        {
1152
                tmp = obj->attribute("DASHS");
1153
                QTextStream dgv(&tmp, IO_ReadOnly);
1154
                OB->DashValues.clear();
1155
                for (int cxv = 0; cxv < QStoInt(obj->attribute("NUMDASH","0")); ++cxv)
1156
                {
1157
                        dgv >> xf;
1158
                        OB->DashValues.append(xf);
1159
                }
1160
                tmp = "";
1161
        }
1162
        else
1163
                OB->DashValues.clear();
1164
        OB->DashOffset = QStodouble(obj->attribute("DASHOFF","0.0"));
1165
}
1166
 
690 cbradney 1167
QColor SetColor(ScribusDoc *currentDoc, QString color, int shad)
517 fschmid 1168
{
1488 fschmid 1169
        return currentDoc->PageColors[color].getShadeColorProof(shad);
517 fschmid 1170
}
2529 craig 1171
 
2636 cbradney 1172
 
1173
/**
1174
 * QPixmaps are really slow with Qt/Mac 3.3.4. Really, *really*, slow.
1175
 * So we better cache them.
1176
 */
1177
QPixmap * getSmallPixmap(QColor rgb)
1178
{
1179
        static QMap<QRgb, QPixmap*> pxCache;
1180
 
1181
        QPixmap * pm = pxCache[rgb.rgb()];
1182
        if (!pm) {
1183
                pm = new QPixmap(15, 15);
1184
                pm->fill(rgb);
1185
                pxCache[rgb.rgb()] = pm;
1186
        }
1187
        return pm;
1188
}
1189
 
1190
QPixmap * getWidePixmap(QColor rgb)
1191
{
1192
        static QMap<QRgb, QPixmap*> pxCache;
1193
 
1194
        QPixmap * pm = pxCache[rgb.rgb()];
1195
        if (!pm) {
1196
                pm = new QPixmap(30, 15);
1197
                pm->fill(rgb);
1198
                pxCache[rgb.rgb()] = pm;
1199
        }
1200
        return pm;
1201
}
1202
 
2529 craig 1203
FPoint getMaxClipF(FPointArray* Clip)
1204
{
1205
        FPoint np, rp;
1206
        double mx = 0;
1207
        double my = 0;
1208
        for (uint c = 0; c < Clip->size(); ++c)
1209
        {
1210
                np = Clip->point(c);
1211
                if (np.x() > 900000)
1212
                        continue;
1213
                if (np.x() > mx)
1214
                        mx = np.x();
1215
                if (np.y() > my)
1216
                        my = np.y();
1217
        }
1218
        rp.setXY(mx, my);
1219
        return rp;
1220
}
1221
 
1222
FPoint getMinClipF(FPointArray* Clip)
1223
{
1224
        FPoint np, rp;
1225
        double mx = 99999;
1226
        double my = 99999;
1227
        for (uint c = 0; c < Clip->size(); ++c)
1228
        {
1229
                np = Clip->point(c);
1230
                if (np.x() > 900000)
1231
                        continue;
1232
                if (np.x() < mx)
1233
                        mx = np.x();
1234
                if (np.y() < my)
1235
                        my = np.y();
1236
        }
1237
        rp.setXY(mx, my);
1238
        return rp;
1239
}
1240