Subversion Repositories Scribus

Rev

Rev 2295 | Rev 2380 | 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
 
8 paul 18
#include <qstring.h>
19
#include <qpixmap.h>
20
#include <qbitmap.h>
21
#include <qpainter.h>
22
#include <qfile.h>
23
#include <qfileinfo.h>
24
#include <qtextstream.h>
1541 fschmid 25
#include <qdatastream.h>
8 paul 26
#include <qstringlist.h>
27
#include <qmap.h>
2295 cbradney 28
#include <qregexp.h>
8 paul 29
#include <qdom.h>
30
#include <qimage.h>
19 Franz 31
#include <qdir.h>
8 paul 32
#include <qpointarray.h>
90 Franz 33
#include <qmessagebox.h>
8 paul 34
#include <cstdlib>
35
#include <cmath>
213 Franz 36
#include <unistd.h>
8 paul 37
#include "md5.h"
201 Franz 38
#include <setjmp.h>
204 Franz 39
#include "qprocess.h"
1693 craig 40
#include "scpaths.h"
128 Franz 41
 
617 cbradney 42
#ifdef _MSC_VER
43
 #if (_MSC_VER >= 1200)
44
  #include "win-config.h"
45
 #endif
128 Franz 46
#else
47
 #include "config.h"
48
#endif
49
 
1555 fschmid 50
extern "C"
51
{
201 Franz 52
#define XMD_H           // shut JPEGlib up
53
#if defined(Q_OS_UNIXWARE)
54
#  define HAVE_BOOLEAN  // libjpeg under Unixware seems to need this
55
#endif
56
#include <jpeglib.h>
57
#include <jerror.h>
58
#undef HAVE_STDLIB_H
59
#ifdef const
60
#  undef const          // remove crazy C hackery in jconfig.h
61
#endif
62
}
63
 
214 Franz 64
#include "scribus.h"
8 paul 65
#include "libpdf/pdflib.h"
68 Franz 66
#include <ft2build.h>
67
#include FT_FREETYPE_H
68
#include FT_OUTLINE_H
69
#include FT_GLYPH_H
8 paul 70
#ifdef HAVE_LIBZ
71
        #include <zlib.h>
72
#endif
73
#ifdef HAVE_TIFF
74
        #include <tiffio.h>
75
#endif
76
#ifdef HAVE_CMS
44 Franz 77
        #include CMS_INC
1555 fschmid 78
extern cmsHPROFILE CMSoutputProf;
79
extern cmsHPROFILE CMSprinterProf;
1781 fschmid 80
extern cmsHTRANSFORM stdTransG;
81
extern cmsHTRANSFORM stdProofG;
82
extern cmsHTRANSFORM stdTransImgG;
83
extern cmsHTRANSFORM stdProofImgG;
1555 fschmid 84
extern bool BlackPoint;
85
extern bool SoftProofing;
86
extern bool Gamut;
87
extern bool CMSuse;
88
extern int IntentMonitor;
89
extern int IntentPrinter;
8 paul 90
#endif
91
extern ProfilesL InputProfiles;
214 Franz 92
extern ScribusApp* ScApp;
8 paul 93
 
690 cbradney 94
using namespace std;
95
 
96
 
97
QColor SetColor(ScribusDoc *currentDoc, QString color, int shad);
1065 cbradney 98
void GetItemProps(bool newVersion, QDomElement *obj, struct CopyPasteBuffer *OB);
456 fschmid 99
QStringList sortQStringList(QStringList aList);
690 cbradney 100
void ReOrderText(ScribusDoc *currentDoc, ScribusView *view);
1957 cbradney 101
void WordAndPara(PageItem *currItem, int *w, int *p, int *c, int *wN, int *pN, int *cN);
102
void CopyPageItem(struct CopyPasteBuffer *Buffer, PageItem *currItem);
90 Franz 103
bool overwrite(QWidget *parent, QString filename);
1065 cbradney 104
int setBestEncoding(FT_Face face);
220 Franz 105
FPointArray traceChar(FT_Face face, uint chr, int chs, double *x, double *y, bool &err);
1065 cbradney 106
FPoint getMaxClipF(FPointArray* Clip);
107
FPoint getMinClipF(FPointArray* Clip);
2295 cbradney 108
QPixmap FontSample(Foi * fnt, int s, QString ts, QColor back, bool force = false);
109
QPixmap fontSamples(Foi * fnt, int s, QString ts, QColor back);
19 Franz 110
QString Path2Relative(QString Path);
690 cbradney 111
QPixmap LoadPDF(QString fn, int Page, int Size, int *w, int *h);
2295 cbradney 112
bool GlyNames(Foi * fnt, QMap<uint, QString> *GList);
113
bool GlyIndex(Foi * fnt, QMap<uint, PDFlib::GlNamInd> *GListInd);
8 paul 114
QByteArray ComputeMD5Sum(QByteArray *in);
115
char *toHex( uchar u );
116
QString String2Hex(QString *in, bool lang = true);
117
QString CompressStr(QString *in);
690 cbradney 118
void Level2Layer(ScribusDoc *currentDoc, struct Layer *ll, int Level);
2122 fschmid 119
int Layer2Level(ScribusDoc *currentDoc, int LayerNr);
8 paul 120
void BezierPoints(QPointArray *ar, QPoint n1, QPoint n2, QPoint n3, QPoint n4);
80 Franz 121
double xy2Deg(double x, double y);
8 paul 122
QPointArray FlattenPath(FPointArray ina, QValueList<uint> &Segs);
80 Franz 123
QPointArray RegularPolygon(double w, double h, uint c, bool star, double factor, double rota);
124
FPointArray RegularPolygonF(double w, double h, uint c, bool star, double factor, double rota);
8 paul 125
QPixmap loadIcon(QString nam);
1109 fschmid 126
uint getDouble(QString in, bool raw);
8 paul 127
bool loadText(QString nam, QString *Buffer);
1789 fschmid 128
double Cwidth(ScribusDoc *currentDoc, Foi* name, QString ch, int Siz, QString ch2 = " ");
129
double RealCWidth(ScribusDoc *currentDoc, Foi* name, QString ch, int Siz);
2284 fschmid 130
double RealCAscent(ScribusDoc *currentDoc, Foi* name, QString ch, int Size);
131
double RealCHeight(ScribusDoc *currentDoc, Foi* name, QString ch, int Size);
2309 fschmid 132
double RealFHeight(ScribusDoc *currentDoc, Foi* name, int Size);
80 Franz 133
double QStodouble(QString in);
8 paul 134
int QStoInt(QString in);
135
QString GetAttr(QDomElement *el, QString at, QString def="0");
136
QImage ProofImage(QImage *Im);
204 Franz 137
int System(const QStringList & args);
138
int callGS(const QStringList & args_in);
139
int copyFile(QString source, QString target);
140
int moveFile(QString source, QString target);
8 paul 141
 
690 cbradney 142
QImage ProofImage(QImage *Image)
8 paul 143
{
144
#ifdef HAVE_CMS
690 cbradney 145
        QImage out = Image->copy();
8 paul 146
        if ((CMSuse) && (SoftProofing))
167 Franz 147
        {
148
                for (int i=0; i < out.height(); ++i)
8 paul 149
                {
150
                        LPBYTE ptr = out.scanLine(i);
1781 fschmid 151
                        cmsDoTransform(stdProofImgG, ptr, ptr, out.width());
8 paul 152
                }
167 Franz 153
        }
8 paul 154
        else
167 Franz 155
        {
156
                if (CMSuse)
8 paul 157
                {
167 Franz 158
                        for (int i=0; i < out.height(); ++i)
8 paul 159
                        {
160
                                LPBYTE ptr = out.scanLine(i);
1781 fschmid 161
                                cmsDoTransform(stdTransImgG, ptr, ptr, out.width());
8 paul 162
                        }
163
                }
167 Franz 164
        }
8 paul 165
        return out;
166
#else
690 cbradney 167
        return Image->copy();
8 paul 168
#endif
169
}
170
 
204 Franz 171
/******************************************************************
172
 * Function System()
173
 *  
174
 * Create a new process via QProcess and wait until finished.
175
 * return the process exit code.
176
 *
177
 ******************************************************************/
178
 
179
int System(const QStringList & args)
180
{
181
        QProcess *proc = new QProcess(NULL);
182
        proc->setArguments(args);
183
        if ( !proc->start() )
184
        {
214 Franz 185
                delete proc;
204 Franz 186
                return 1;
187
        }
188
        /* start was OK */
690 cbradney 189
        /* wait a little bit */
190
        while( proc->isRunning() )
204 Franz 191
                usleep(5000);
690 cbradney 192
 
204 Franz 193
        int ex = proc->exitStatus();
194
        delete proc;
195
        return ex;
196
}
197
 
198
/******************************************************************
199
 * Function callGS()
200
 *   build the complete list of arguments for the call of our
201
 *   System() function.
202
 *
203
 *   The gs commands are all similar and consist of a few constant
204
 *   arguments, the variablke arguments and the end arguments which
205
 *   are also invariant.
206
 ******************************************************************/
1555 fschmid 207
 
204 Franz 208
int callGS(const QStringList & args_in)
209
{
1186 fschmid 210
        QString cmd1 = ScApp->Prefs.gs_exe;
211
        cmd1 += " -q -dNOPAUSE";
214 Franz 212
        if (ScApp->HavePngAlpha != 0)
1186 fschmid 213
                cmd1 += " -sDEVICE=png16m";
214 Franz 214
        else
1186 fschmid 215
                cmd1 += " -sDEVICE=pngalpha";
1545 cbradney 216
        if (ScApp->Prefs.gs_AntiAliasText)
1186 fschmid 217
                cmd1 += " -dTextAlphaBits=4";
1545 cbradney 218
        if (ScApp->Prefs.gs_AntiAliasGraphics)
1186 fschmid 219
                cmd1 += " -dGraphicsAlphaBits=4";
220
        QString extArgs = args_in.join(" ");
221
        cmd1 += " " + extArgs + " -c showpage -c quit";
222
        return system(cmd1);
204 Franz 223
}
224
 
225
int copyFile(QString source, QString target)
226
{
227
        if ((source.isNull()) || (target.isNull()))
228
                return -1;
229
        if (source == target)
230
                return -1;
231
        QFile s(source);
232
        QFile t(target);
233
        if (!s.exists())
234
                return -1;
235
        QByteArray bb(s.size());
236
        if (s.open(IO_ReadOnly))
237
        {
238
                s.readBlock(bb.data(), s.size());
239
                s.close();
240
                if (t.open(IO_WriteOnly))
241
                {
242
                        t.writeBlock(bb.data(), bb.size());
243
                        t.close();
244
                }
245
        }
246
        return 0;
247
}
248
 
249
int moveFile(QString source, QString target)
250
{
251
        if ((source.isNull()) || (target.isNull()))
252
                return -1;
253
        if (source == target)
254
                return -1;
255
        copyFile(source, target);
256
        unlink(source);
257
        return 0;
258
}
259
 
690 cbradney 260
QPixmap LoadPDF(QString fn, int Page, int Size, int *w, int *h)
19 Franz 261
{
262
        QString tmp, cmd1, cmd2;
282 Franz 263
        QString tmpFile = QDir::convertSeparators(QDir::homeDirPath()+"/.scribus/sc.png");
19 Franz 264
        QPixmap pm;
265
        int ret = -1;
690 cbradney 266
        tmp.setNum(Page);
204 Franz 267
        QStringList args;
268
        args.append("-r72");
269
        args.append("-sOutputFile="+tmpFile);
270
        args.append("-dFirstPage="+tmp);
271
        args.append("-dLastPage="+tmp);
1816 fschmid 272
        args.append("\""+fn+"\"");
204 Franz 273
        ret = callGS(args);
19 Franz 274
        if (ret == 0)
167 Franz 275
        {
19 Franz 276
                QImage image;
159 Franz 277
                image.load(tmpFile);
204 Franz 278
                unlink(tmpFile);
1555 fschmid 279
                QImage im2;
20 Franz 280
                *h = image.height();
281
                *w = image.width();
80 Franz 282
                double sx = image.width() / static_cast<double>(Size);
283
                double sy = image.height() / static_cast<double>(Size);
167 Franz 284
                double t = (sy < sx ? sx : sy);
285
                im2 = image.smoothScale(static_cast<int>(image.width() / t), static_cast<int>(image.height() / t));
19 Franz 286
                pm.convertFromImage(im2);
287
                QPainter p;
288
                p.begin(&pm);
289
                p.setBrush(Qt::NoBrush);
290
                p.setPen(Qt::black);
291
                p.drawRect(0, 0, pm.width(), pm.height());
292
                p.end();
293
                im2.detach();
167 Franz 294
        }
19 Franz 295
        return pm;
296
}
297
 
8 paul 298
QString GetAttr(QDomElement *el, QString at, QString def)
299
{
300
        return el->attribute(at, def);
301
}
302
 
303
int QStoInt(QString in)
304
{
2093 cbradney 305
        /* Dont need this, toInt returns 0 on failure, dont even need this function really.
8 paul 306
        bool ok = false;
307
        int c = in.toInt(&ok);
167 Franz 308
        return ok ? c : 0;
2093 cbradney 309
        */
310
        return in.toInt();
8 paul 311
}
312
 
80 Franz 313
double QStodouble(QString in)
8 paul 314
{
315
        bool ok = false;
80 Franz 316
        double c = in.toDouble(&ok);
167 Franz 317
        return ok ? c : 0.0;
8 paul 318
}
319
 
320
QPixmap loadIcon(QString nam)
321
{
1693 craig 322
        QString iconFilePath = QString("%1/%2").arg(ScPaths::instance().iconDir()).arg(nam);
8 paul 323
        QPixmap pm;
1672 craig 324
        if (!QFile::exists(iconFilePath))
325
                qWarning("Unable to load icon %s: File not found", iconFilePath.ascii());
326
        else
327
        {
328
                pm.load(iconFilePath);
329
                if (pm.isNull())
330
                        qWarning("Unable to load icon %s: Got null pixmap", iconFilePath.ascii());
331
        }
8 paul 332
        return pm;
333
}
334
 
1109 fschmid 335
uint getDouble(QString in, bool raw)
336
{
337
        QByteArray bb(4);
338
        if (raw)
339
        {
340
                bb[3] = static_cast<uchar>(QChar(in.at(0)));
341
                bb[2] = static_cast<uchar>(QChar(in.at(1)));
342
                bb[1] = static_cast<uchar>(QChar(in.at(2)));
343
                bb[0] = static_cast<uchar>(QChar(in.at(3)));
344
        }
345
        else
346
        {
347
                bb[0] = static_cast<uchar>(QChar(in.at(0)));
348
                bb[1] = static_cast<uchar>(QChar(in.at(1)));
349
                bb[2] = static_cast<uchar>(QChar(in.at(2)));
350
                bb[3] = static_cast<uchar>(QChar(in.at(3)));
351
        }
352
        uint ret;
353
        ret = bb[0] & 0xff;
354
        ret |= (bb[1] << 8) & 0xff00;
355
        ret |= (bb[2] << 16) & 0xff0000;
356
        ret |= (bb[3] << 24) & 0xff000000;
357
        return ret;
358
}
359
 
690 cbradney 360
bool loadText(QString filename, QString *Buffer)
8 paul 361
{
690 cbradney 362
        QFile f(filename);
8 paul 363
        QFileInfo fi(f);
364
        if (!fi.exists())
365
                return false;
167 Franz 366
        bool ret;
8 paul 367
        QByteArray bb(f.size());
368
        if (f.open(IO_ReadOnly))
167 Franz 369
        {
8 paul 370
                f.readBlock(bb.data(), f.size());
371
                f.close();
690 cbradney 372
                for (uint posi = 0; posi < bb.size(); ++posi)
8 paul 373
                        *Buffer += bb[posi];
374
                ret = true;
167 Franz 375
        }
8 paul 376
        else
377
                ret = false;
378
        return ret;
379
}
380
 
1789 fschmid 381
double Cwidth(ScribusDoc *currentDoc, Foi* name, QString ch, int Size, QString ch2)
8 paul 382
{
690 cbradney 383
        double width;
8 paul 384
        FT_Vector  delta;
1786 fschmid 385
        FT_Face      face;
8 paul 386
        uint c1 = ch.at(0).unicode();
387
        uint c2 = ch2.at(0).unicode();
2035 cbradney 388
        double size10=Size/10.0;
1789 fschmid 389
        if (name->CharWidth.contains(c1))
167 Franz 390
        {
2035 cbradney 391
                width = name->CharWidth[c1]*size10;
1789 fschmid 392
                if (name->HasKern)
167 Franz 393
                {
1789 fschmid 394
                        face = currentDoc->FFonts[name->SCName];
1786 fschmid 395
                        uint cl = FT_Get_Char_Index(face, c1);
396
                        uint cr = FT_Get_Char_Index(face, c2);
397
                        FT_Get_Kerning(face, cl, cr, ft_kerning_unscaled, &delta);
2035 cbradney 398
                        width += delta.x / name->uniEM * size10;
167 Franz 399
                }
690 cbradney 400
                return width;
167 Franz 401
        }
8 paul 402
        else
2035 cbradney 403
                return size10;
8 paul 404
}
405
 
1789 fschmid 406
double RealCWidth(ScribusDoc *currentDoc, Foi* name, QString ch, int Size)
220 Franz 407
{
221 Franz 408
        double w, ww;
1788 fschmid 409
        uint c1 = ch.at(0).unicode();
1786 fschmid 410
        FT_Face      face;
1789 fschmid 411
        if (name->CharWidth.contains(c1))
220 Franz 412
        {
1789 fschmid 413
                face = currentDoc->FFonts[name->SCName];
1786 fschmid 414
                uint cl = FT_Get_Char_Index(face, c1);
1788 fschmid 415
                FT_Load_Glyph(face, cl, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP );
1789 fschmid 416
                w = (face->glyph->metrics.width + fabs((double)face->glyph->metrics.horiBearingX)) / name->uniEM * (Size / 10.0);
417
                ww = face->glyph->metrics.horiAdvance / name->uniEM * (Size / 10.0);
221 Franz 418
                return QMAX(ww, w);
220 Franz 419
        }
420
        else
690 cbradney 421
                return static_cast<double>(Size / 10.0);
220 Franz 422
}
423
 
2284 fschmid 424
double RealCHeight(ScribusDoc *currentDoc, Foi* name, QString ch, int Size)
425
{
426
        double w;
427
        uint c1 = ch.at(0).unicode();
428
        FT_Face      face;
429
        if (name->CharWidth.contains(c1))
430
        {
431
                face = currentDoc->FFonts[name->SCName];
432
                uint cl = FT_Get_Char_Index(face, c1);
433
                FT_Load_Glyph(face, cl, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP );
434
                w = face->glyph->metrics.height / name->uniEM * (Size / 10.0);
435
                return w;
436
        }
437
        else
438
                return static_cast<double>(Size / 10.0);
439
}
440
 
441
double RealCAscent(ScribusDoc *currentDoc, Foi* name, QString ch, int Size)
442
{
443
        double w;
444
        uint c1 = ch.at(0).unicode();
445
        FT_Face      face;
446
        if (name->CharWidth.contains(c1))
447
        {
448
                face = currentDoc->FFonts[name->SCName];
449
                uint cl = FT_Get_Char_Index(face, c1);
450
                FT_Load_Glyph(face, cl, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP );
451
                w = face->glyph->metrics.horiBearingY / name->uniEM * (Size / 10.0);
452
                return w;
453
        }
454
        else
455
                return static_cast<double>(Size / 10.0);
456
}
457
 
2309 fschmid 458
double RealFHeight(ScribusDoc *currentDoc, Foi* name, int Size)
459
{
460
        FT_Face face = currentDoc->FFonts[name->SCName];
461
        return face->height / name->uniEM * (Size / 10.0);
462
}
463
 
80 Franz 464
QPointArray RegularPolygon(double w, double h, uint c, bool star, double factor, double rota)
8 paul 465
{
167 Franz 466
        uint cx = star ? c * 2 : c;
80 Franz 467
        double seg = 360.0 / cx;
468
        double sc = rota + 180.0;
469
        double di = factor;
8 paul 470
        int mx = 0;
471
        int my = 0;
472
        QPointArray pts = QPointArray();
473
        for (uint x = 0; x < cx; ++x)
167 Franz 474
        {
8 paul 475
                sc = seg * x + 180.0 + rota;
476
                if (star)
167 Franz 477
                {
478
                        double wf = x % 2 == 0 ? w / 2 : w / 2 * di;
479
                        double hf = x % 2 == 0 ? h / 2 : h / 2 * di;
480
                        mx = qRound(sin(sc / 180 * M_PI) * (wf) + (w/2));
481
                        my = qRound(cos(sc / 180 * M_PI) * (hf) + (h/2));
482
                }
8 paul 483
                else
167 Franz 484
                {
8 paul 485
                        mx = qRound(sin(sc / 180 * M_PI) * (w/2) + (w/2));
486
                        my = qRound(cos(sc / 180 * M_PI) * (h/2) + (h/2));
167 Franz 487
                }
8 paul 488
                pts.resize(x+1);
489
                pts.setPoint(x, mx, my);
167 Franz 490
        }
8 paul 491
        return pts;
492
}
493
 
80 Franz 494
FPointArray RegularPolygonF(double w, double h, uint c, bool star, double factor, double rota)
8 paul 495
{
167 Franz 496
        uint cx = star ? c * 2 : c;
80 Franz 497
        double seg = 360.0 / cx;
498
        double sc = rota + 180.0;
499
        double di = factor;
500
        double mx = 0;
501
        double my = 0;
1884 fschmid 502
        FPointArray pts;
8 paul 503
        for (uint x = 0; x < cx; ++x)
167 Franz 504
        {
8 paul 505
                sc = seg * x + 180.0 + rota;
506
                if (star)
167 Franz 507
                {
508
                        double wf = x % 2 == 0 ? w / 2 : w / 2 * di;
509
                        double hf = x % 2 == 0 ? h / 2 : h / 2 * di;
510
                        mx = qRound(sin(sc / 180 * M_PI) * (wf) + (w/2));
511
                        my = qRound(cos(sc / 180 * M_PI) * (hf) + (h/2));
512
                }
8 paul 513
                else
167 Franz 514
                {
8 paul 515
                        mx = sin(sc / 180 * M_PI) * (w/2) + (w/2);
516
                        my = cos(sc / 180 * M_PI) * (h/2) + (h/2);
167 Franz 517
                }
8 paul 518
                pts.resize(x+1);
519
                pts.setPoint(x, mx, my);
167 Franz 520
        }
8 paul 521
        return pts;
522
}
523
 
524
QPointArray FlattenPath(FPointArray ina, QValueList<uint> &Segs)
525
{
526
        QPointArray Bez(4);
527
        QPointArray outa, cli;
528
        Segs.clear();
529
        if (ina.size() > 3)
167 Franz 530
        {
531
                for (uint poi=0; poi<ina.size()-3; poi += 4)
8 paul 532
                {
167 Franz 533
                        if (ina.point(poi).x() > 900000)
8 paul 534
                        {
535
                                outa.resize(outa.size()+1);
536
                                outa.setPoint(outa.size()-1, cli.point(cli.size()-1));
80 Franz 537
                                Segs.append(outa.size());
8 paul 538
                                continue;
167 Franz 539
                        }
8 paul 540
                        BezierPoints(&Bez, ina.pointQ(poi), ina.pointQ(poi+1), ina.pointQ(poi+3), ina.pointQ(poi+2));
541
                        cli = Bez.cubicBezier();
542
                        outa.putPoints(outa.size(), cli.size()-1, cli);
167 Franz 543
                }
8 paul 544
                outa.resize(outa.size()+1);
545
                outa.setPoint(outa.size()-1, cli.point(cli.size()-1));
167 Franz 546
        }
8 paul 547
        return outa;
548
}
549
 
80 Franz 550
double xy2Deg(double x, double y)
8 paul 551
{
552
        return (atan2(y,x)*(180.0/M_PI));
553
}
554
 
555
void BezierPoints(QPointArray *ar, QPoint n1, QPoint n2, QPoint n3, QPoint n4)
556
{
557
        ar->setPoint(0, n1);
558
        ar->setPoint(1, n2);
559
        ar->setPoint(2, n3);
560
        ar->setPoint(3, n4);
561
        return;
562
}
563
 
690 cbradney 564
void Level2Layer(ScribusDoc *currentDoc, struct Layer *ll, int Level)
8 paul 565
{
690 cbradney 566
        for (uint la2 = 0; la2 < currentDoc->Layers.count(); ++la2)
167 Franz 567
        {
690 cbradney 568
                if (currentDoc->Layers[la2].Level == Level)
8 paul 569
                {
1065 cbradney 570
                        ll->isViewable = currentDoc->Layers[la2].isViewable;
571
                        ll->isPrintable = currentDoc->Layers[la2].isPrintable;
690 cbradney 572
                        ll->LNr = currentDoc->Layers[la2].LNr;
1737 fschmid 573
                        ll->Name = currentDoc->Layers[la2].Name;
8 paul 574
                        break;
575
                }
167 Franz 576
        }
8 paul 577
}
578
 
2122 fschmid 579
int Layer2Level(ScribusDoc *currentDoc, int LayerNr)
580
{
581
        for (uint la2 = 0; la2 < currentDoc->Layers.count(); ++la2)
582
        {
583
                if (currentDoc->Layers[la2].LNr == LayerNr)
584
                        return currentDoc->Layers[la2].Level;
585
        }
586
        return 0;
587
}
588
 
8 paul 589
QString CompressStr(QString *in)
590
{
591
        QString out = "";
592
#ifdef HAVE_LIBZ
593
        QByteArray bb(in->length());
594
        for (uint ax = 0; ax < in->length(); ++ax)
595
                bb[ax] = uchar(QChar(in->at(ax)));
596
        uLong exlen = uint(bb.size() * 0.001 + 16) + bb.size();
597
        QByteArray bc(exlen);
2295 cbradney 598
        int errcode = compress2((Byte *)bc.data(), &exlen, (Byte *)bb.data(), uLong(bb.size()), 9);
599
        if (errcode != Z_OK) {
600
                qDebug(QString("compress2 failed with code %1").arg(errcode));
601
                out = *in;
602
        }
603
        else {
604
                for (uint cl = 0; cl < exlen; ++cl)
605
                        out += bc[cl];
606
        }
8 paul 607
#else
608
        out = *in;
609
#endif
610
        return out;
611
}
612
 
613
char *toHex( uchar u )
614
{
1555 fschmid 615
        static char hexVal[3];
616
        int i = 1;
617
        while ( i >= 0 )
167 Franz 618
        {
619
                ushort hex = (u & 0x000f);
620
                if ( hex < 0x0a )
1555 fschmid 621
                        hexVal[i] = '0'+hex;
167 Franz 622
                else
1555 fschmid 623
                        hexVal[i] = 'A'+(hex-0x0a);
167 Franz 624
                u = u >> 4;
1555 fschmid 625
                i--;
626
        }
627
        hexVal[2] = '\0';
628
        return hexVal;
8 paul 629
}
630
 
631
QString String2Hex(QString *in, bool lang)
632
{
633
        int i = 0;
634
        QString out = "";
635
        for( uint xi = 0; xi < in->length(); ++xi )
167 Franz 636
        {
8 paul 637
                out += toHex(uchar(QChar(in->at(xi))));
638
                ++i;
639
                if ((i>40) && (lang))
167 Franz 640
                {
8 paul 641
                        out += '\n';
642
                        i=0;
643
                }
167 Franz 644
        }
8 paul 645
        return out;
646
}
647
 
648
QByteArray ComputeMD5Sum(QByteArray *in)
649
{
650
        QByteArray MDsum(16);
49 paul 651
        md5_buffer (in->data(), in->size(), reinterpret_cast<void*>(MDsum.data()));
8 paul 652
        return MDsum;
653
}
654
 
19 Franz 655
QString Path2Relative(QString Path)
656
{
657
        QString Ndir = "";
658
        QStringList Pdir = QStringList::split("/", QDir::currentDirPath());
659
        QFileInfo Bfi = QFileInfo(Path);
660
        QStringList Bdir = QStringList::split("/", Bfi.dirPath(true));
690 cbradney 661
        bool end = true;
19 Franz 662
        uint dcoun = 0;
663
        uint dcoun2 = 0;
690 cbradney 664
        while (end)
167 Franz 665
        {
19 Franz 666
                if (Pdir[dcoun] == Bdir[dcoun])
667
                        dcoun++;
668
                else
669
                        break;
670
                if (dcoun > Pdir.count())
671
                        break;
167 Franz 672
        }
19 Franz 673
        dcoun2 = dcoun;
674
        for (uint ddx2 = dcoun; ddx2 < Pdir.count(); ddx2++)
675
                Ndir += "../";
676
        for (uint ddx = dcoun2; ddx < Bdir.count(); ddx++)
677
                Ndir += Bdir[ddx]+"/";
678
        Ndir += Bfi.fileName();
679
        return Ndir;
680
}
681
 
1065 cbradney 682
int setBestEncoding(FT_Face face)
8 paul 683
{
684
        FT_ULong  charcode;
896 fschmid 685
        FT_UInt   gindex;
876 fschmid 686
        bool foundEncoding = false;
896 fschmid 687
        int countUniCode = 0;
688
        int chmapUniCode = 0;
689
        int chmapCustom = 0;
1065 cbradney 690
        int retVal = 0;
896 fschmid 691
        FT_CharMap defaultEncoding = face->charmap;
391 Franz 692
        for(int u = 0; u < face->num_charmaps; u++)
693
        {
896 fschmid 694
                if (face->charmaps[u]->encoding == FT_ENCODING_UNICODE )
391 Franz 695
                {
896 fschmid 696
                        FT_Set_Charmap(face, face->charmaps[u]);
697
                        chmapUniCode = u;
698
                        gindex = 0;
699
                        charcode = FT_Get_First_Char( face, &gindex );
700
                        while ( gindex != 0 )
876 fschmid 701
                        {
896 fschmid 702
                                countUniCode++;
703
                                charcode = FT_Get_Next_Char( face, charcode, &gindex );
876 fschmid 704
                        }
705
                }
896 fschmid 706
                if (face->charmaps[u]->encoding == FT_ENCODING_ADOBE_CUSTOM)
876 fschmid 707
                {
896 fschmid 708
                        chmapCustom = u;
709
                        foundEncoding = true;
1065 cbradney 710
                        retVal = 1;
711
                        break;
876 fschmid 712
                }
1065 cbradney 713
                else if (face->charmaps[u]->encoding == FT_ENCODING_MS_SYMBOL)
714
                {
715
                        chmapCustom = u;
716
                        foundEncoding = true;
717
                        retVal = 2;
718
                        break;
719
                }
876 fschmid 720
        }
2012 fschmid 721
        if (countUniCode >= face->num_glyphs-1)
1065 cbradney 722
        {
896 fschmid 723
                FT_Set_Charmap(face, face->charmaps[chmapUniCode]);
1065 cbradney 724
                retVal = 0;
725
        }
896 fschmid 726
        else if (foundEncoding)
727
                FT_Set_Charmap(face, face->charmaps[chmapCustom]);
728
        else
1065 cbradney 729
        {
896 fschmid 730
                FT_Set_Charmap(face, defaultEncoding);
1065 cbradney 731
                retVal = 0;
732
        }
733
        return retVal;
896 fschmid 734
}
735
 
2295 cbradney 736
 
737
static QMap<FT_ULong, QString> adobeGlyphNames;
738
static const char* table[] = {
739
//#include "glyphnames.txt.q"
740
                                        NULL};
741
 
742
/// init the Adobe Glyph List
743
void readAdobeGlyphNames() {
744
        adobeGlyphNames.clear();
745
        QRegExp pattern("(\\w*);([0-9A-Fa-f]{4})");
746
        for (uint i=0; table[i]; ++i) {
747
                if (pattern.search(table[i]) >= 0) {
748
                        FT_ULong unicode = pattern.cap(2).toULong(0, 16);
749
                        qDebug(QString("reading glyph name %1 fo unicode %2(%3)").arg(pattern.cap(1)).arg(unicode).arg(pattern.cap(2)));
750
                        adobeGlyphNames[unicode] = pattern.cap(1);
751
                }
752
        }
753
}
754
 
755
 
756
/// if in AGL, use that name, else use "uni1234" or "u12345"
757
QString adobeGlyphName(FT_ULong charcode) {
758
        static const char HEX[] = "0123456789ABCDEF";
759
        QString result = adobeGlyphNames[charcode];
760
        if (result.length() == 0 && charcode < 0x10000) {
761
                result = QString("uni") + HEX[charcode>>12 & 0xF]
762
                                        + HEX[charcode>> 8 & 0xF]
763
                                        + HEX[charcode>> 4 & 0xF]
764
                                        + HEX[charcode     & 0xF];
765
        }
766
        else if (result.length() == 0) {
767
                result = QString("u");
768
                for (int i= 28; i >= 0; i-=4) {
769
                        if (charcode & (0xF << i))
770
                                result += HEX[charcode >> i & 0xF];
771
                }
772
        }
773
        return result;
774
}
775
 
776
bool GlyNames(Foi * fnt, QMap<uint, QString> *GList)
896 fschmid 777
{
778
        bool error;
2295 cbradney 779
        char buf[50];
896 fschmid 780
        FT_Library library;
781
        FT_Face face;
782
        FT_ULong  charcode;
783
        FT_UInt gindex;
784
        error = FT_Init_FreeType(&library);
2295 cbradney 785
        error = FT_New_Face(library, fnt->Datei, fnt->faceIndex, &face);
896 fschmid 786
        setBestEncoding(face);
77 Franz 787
        gindex = 0;
167 Franz 788
        charcode = FT_Get_First_Char(face, &gindex );
2295 cbradney 789
        const bool hasPSNames = FT_HAS_GLYPH_NAMES(face);
790
        if (adobeGlyphNames.empty())
791
                readAdobeGlyphNames();
167 Franz 792
        while (gindex != 0)
793
        {
2295 cbradney 794
                bool notfound = true;
795
                if (hasPSNames)
796
                        notfound = FT_Get_Glyph_Name(face, gindex, &buf, 50);
797
 
798
                // just in case FT gives empty string or ".notdef"
799
                // no valid glyphname except ".notdef" starts with '.'          
800
                if (notfound || buf[0] == '\0' || buf[0] == '.')
801
                        GList->insert(charcode, adobeGlyphName(charcode));
802
                else
803
                        GList->insert(charcode, QString(reinterpret_cast<char*>(buf)));
804
 
1555 fschmid 805
                charcode = FT_Get_Next_Char(face, charcode, &gindex );
167 Franz 806
        }
8 paul 807
        FT_Done_FreeType( library );
808
        return true;
809
}
810
 
2295 cbradney 811
bool GlyIndex(Foi * fnt, QMap<uint, PDFlib::GlNamInd> *GListInd)
8 paul 812
{
813
        struct PDFlib::GlNamInd gln;
814
        bool error;
2295 cbradney 815
        char buf[50];
8 paul 816
        FT_Library library;
817
        FT_Face face;
818
        FT_ULong  charcode;
167 Franz 819
        FT_UInt   gindex;
820
        uint counter1 = 32;
821
        uint counter2 = 0;
8 paul 822
        error = FT_Init_FreeType(&library);
2295 cbradney 823
        error = FT_New_Face(library, fnt->Datei, fnt->faceIndex, &face);
896 fschmid 824
        setBestEncoding(face);
77 Franz 825
        gindex = 0;
167 Franz 826
        charcode = FT_Get_First_Char(face, &gindex );
2295 cbradney 827
        const bool hasPSNames = FT_HAS_GLYPH_NAMES(face);
828
        if (adobeGlyphNames.empty())
829
                readAdobeGlyphNames();
167 Franz 830
        while (gindex != 0)
831
        {
2295 cbradney 832
                bool notfound = true;
833
                if (hasPSNames)
834
                        notfound = FT_Get_Glyph_Name(face, gindex, buf, 50);
835
 
836
                // just in case FT gives empty string or ".notdef"
837
                // no valid glyphname except ".notdef" starts with '.'          
838
                if (notfound || buf[0] == '\0' || buf[0] == '.')
839
                        gln.Name = "/" + adobeGlyphName(charcode);
840
                else
841
                        gln.Name = "/" + QString(buf);
842
 
8 paul 843
                gln.Code = counter1 + counter2;
844
                GListInd->insert(charcode, gln);
1555 fschmid 845
                charcode = FT_Get_Next_Char(face, charcode, &gindex );
846
                counter1++;
847
                if (counter1 > 255)
167 Franz 848
                {
8 paul 849
                        counter1 = 32;
850
                        counter2 += 0x100;
851
                }
167 Franz 852
        }
8 paul 853
        FT_Done_FreeType( library );
854
        return true;
855
}
856
 
857
FPoint firstP;
858
bool FirstM;
859
 
860
int traceMoveto( FT_Vector *to, FPointArray *composite )
861
{
862
        double tox = ( to->x / 64.0 );
863
        double toy = ( to->y / 64.0 );
864
        if (!FirstM)
167 Franz 865
        {
68 Franz 866
                composite->addPoint(firstP);
867
                composite->addPoint(firstP);
868
                composite->setMarker();
167 Franz 869
        }
8 paul 870
        else
871
                FirstM = false;
1884 fschmid 872
        composite->addPoint(tox, toy);
873
        composite->addPoint(tox, toy);
1955 fschmid 874
        firstP.setXY(tox, toy);
8 paul 875
        return 0;
876
}
877
 
878
int traceLineto( FT_Vector *to, FPointArray *composite )
879
{
880
        double tox = ( to->x / 64.0 );
881
        double toy = ( to->y / 64.0 );
1992 fschmid 882
        if ( !composite->hasLastQuadPoint(tox, toy, tox, toy, tox, toy, tox, toy))
883
                composite->addQuadPoint(tox, toy, tox, toy, tox, toy, tox, toy);
8 paul 884
        return 0;
885
}
886
 
887
int traceQuadraticBezier( FT_Vector *control, FT_Vector *to, FPointArray *composite )
888
{
889
        double x1 = ( control->x / 64.0 );
890
        double y1 = ( control->y / 64.0 );
891
        double x2 = ( to->x / 64.0 );
892
        double y2 = ( to->y / 64.0 );
1992 fschmid 893
        if ( !composite->hasLastQuadPoint(x2, y2, x1, y1, x2, y2, x2, y2))
894
                composite->addQuadPoint(x2, y2, x1, y1, x2, y2, x2, y2);
8 paul 895
        return 0;
167 Franz 896
}
8 paul 897
 
898
int traceCubicBezier( FT_Vector *p, FT_Vector *q, FT_Vector *to, FPointArray *composite )
899
{
900
        double x1 = ( p->x / 64.0 );
901
        double y1 = ( p->y / 64.0 );
902
        double x2 = ( q->x / 64.0 );
903
        double y2 = ( q->y / 64.0 );
904
        double x3 = ( to->x / 64.0 );
905
        double y3 = ( to->y / 64.0 );
1992 fschmid 906
        if ( !composite->hasLastQuadPoint(x3, y3, x2, y2, x3, y3, x3, y3) )
167 Franz 907
        {
1955 fschmid 908
                composite->setPoint(composite->size()-1, FPoint(x1, y1));
1992 fschmid 909
                composite->addQuadPoint(x3, y3, x2, y2, x3, y3, x3, y3);
1955 fschmid 910
        }
8 paul 911
        return 0;
912
}
913
 
914
FT_Outline_Funcs OutlineMethods =
1555 fschmid 915
    {
916
        (FT_Outline_MoveTo_Func) traceMoveto,
917
        (FT_Outline_LineTo_Func) traceLineto,
918
        (FT_Outline_ConicTo_Func) traceQuadraticBezier,
919
        (FT_Outline_CubicTo_Func) traceCubicBezier,
920
        0,
921
 
922
    };
8 paul 923
 
220 Franz 924
FPointArray traceChar(FT_Face face, uint chr, int chs, double *x, double *y, bool *err)
8 paul 925
{
220 Franz 926
        bool error = false;
8 paul 927
        FT_UInt glyphIndex;
1884 fschmid 928
        //AV: not threadsave, but tracechar is only used in ReadMetrics() and fontSample()
929
        static FPointArray pts;
930
        FPointArray pts2;
8 paul 931
        pts.resize(0);
220 Franz 932
        pts2.resize(0);
8 paul 933
        firstP = FPoint(0,0);
934
        FirstM = true;
220 Franz 935
        error = FT_Set_Char_Size( face, 0, chs*64, 72, 72 );
936
        if (error)
937
        {
938
                *err = error;
939
                return pts2;
940
        }
8 paul 941
        glyphIndex = FT_Get_Char_Index(face, chr);
220 Franz 942
        if (glyphIndex == 0)
943
        {
944
                *err = true;
945
                return pts2;
946
        }
947
        error = FT_Load_Glyph( face, glyphIndex, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP );
948
        if (error)
949
        {
950
                *err = error;
951
                return pts2;
952
        }
953
        error = FT_Outline_Decompose(&face->glyph->outline, &OutlineMethods, reinterpret_cast<void*>(&pts));
954
        if (error)
955
        {
956
                *err = error;
957
                return pts2;
958
        }
87 Franz 959
        *x = face->glyph->metrics.horiBearingX / 64.0;
960
        *y = face->glyph->metrics.horiBearingY / 64.0;
8 paul 961
        QWMatrix ma;
962
        ma.scale(1, -1);
963
        pts.map(ma);
964
        pts.translate(0, chs);
965
        pts2.putPoints(0, pts.size()-2, pts, 0);
1884 fschmid 966
 
8 paul 967
        return pts2;
968
}
90 Franz 969
 
1065 cbradney 970
FPoint getMaxClipF(FPointArray* Clip)
95 Franz 971
{
972
        FPoint np, rp;
973
        double mx = 0;
974
        double my = 0;
1065 cbradney 975
        for (uint c = 0; c < Clip->size(); ++c)
167 Franz 976
        {
1065 cbradney 977
                np = Clip->point(c);
95 Franz 978
                if (np.x() > 900000)
979
                        continue;
980
                if (np.x() > mx)
981
                        mx = np.x();
982
                if (np.y() > my)
983
                        my = np.y();
167 Franz 984
        }
1955 fschmid 985
        rp.setXY(mx, my);
95 Franz 986
        return rp;
987
}
988
 
1065 cbradney 989
FPoint getMinClipF(FPointArray* Clip)
740 fschmid 990
{
991
        FPoint np, rp;
992
        double mx = 99999;
993
        double my = 99999;
1065 cbradney 994
        for (uint c = 0; c < Clip->size(); ++c)
740 fschmid 995
        {
1065 cbradney 996
                np = Clip->point(c);
740 fschmid 997
                if (np.x() > 900000)
998
                        continue;
999
                if (np.x() < mx)
1000
                        mx = np.x();
1001
                if (np.y() < my)
1002
                        my = np.y();
1003
        }
1955 fschmid 1004
        rp.setXY(mx, my);
740 fschmid 1005
        return rp;
1006
}
1007
 
2295 cbradney 1008
QPixmap FontSample(Foi * fnt, int s, QString ts, QColor back, bool force)
92 Franz 1009
{
1010
        FT_Face face;
1011
        FT_Library library;
95 Franz 1012
        double x, y, ymax;
92 Franz 1013
        bool error;
1014
        int  pen_x;
95 Franz 1015
        FPoint gp;
92 Franz 1016
        error = FT_Init_FreeType( &library );
2295 cbradney 1017
        error = FT_New_Face( library, fnt->Datei, fnt->faceIndex, &face );
1065 cbradney 1018
        int encode = setBestEncoding(face);
92 Franz 1019
        double uniEM = static_cast<double>(face->units_per_EM);
95 Franz 1020
        int h = qRound(face->height / uniEM) * s + 1;
1021
        double a = static_cast<double>(face->descender) / uniEM * s + 1;
92 Franz 1022
        int w = qRound((face->bbox.xMax - face->bbox.xMin) / uniEM) * s * (ts.length()+1);
1992 fschmid 1023
        if (w < 1)
1024
                w = s * (ts.length()+1);
1025
        if (h < 1)
1026
                h = s;
92 Franz 1027
        QPixmap pm(w, h);
1028
        pm.fill();
1029
        pen_x = 0;
95 Franz 1030
        ymax = 0.0;
92 Franz 1031
        ScPainter *p = new ScPainter(&pm, pm.width(), pm.height());
1032
        p->setFillMode(1);
1033
        p->setLineWidth(0.0);
1034
        p->setBrush(back);
1035
        p->drawRect(0.0, 0.0, static_cast<double>(w), static_cast<double>(h));
1036
        p->setBrush(Qt::black);
1065 cbradney 1037
        FPointArray gly;
1038
        uint dv;
1039
        dv = ts[0].unicode();
1040
        error = false;
1041
        gly = traceChar(face, dv, s, &x, &y, &error);
1068 fschmid 1042
        if (((encode != 0) || (error)) && (!force))
167 Franz 1043
        {
221 Franz 1044
                error = false;
1065 cbradney 1045
                FT_ULong  charcode;
1046
                FT_UInt gindex;
1047
                gindex = 0;
1048
                charcode = FT_Get_First_Char(face, &gindex );
1049
                for (uint n = 0; n < ts.length(); ++n)
167 Franz 1050
                {
1065 cbradney 1051
                        gly = traceChar(face, charcode, s, &x, &y, &error);
1052
                        if (error)
1053
                                break;
1054
                        if (gly.size() > 3)
1055
                        {
1056
                                gly.translate(static_cast<double>(pen_x) / 64.0, a);
1057
                                gp = getMaxClipF(&gly);
1058
                                ymax = QMAX(ymax, gp.y());
1059
                                p->setupPolygon(&gly);
1060
                                p->fillPath();
1061
                        }
1062
                        pen_x += face->glyph->advance.x;
1063
                        charcode = FT_Get_Next_Char(face, charcode, &gindex );
1064
                        if (gindex == 0)
1065
                                break;
167 Franz 1066
                }
1067
        }
1065 cbradney 1068
        else
1069
        {
1070
                for (uint n = 0; n < ts.length(); ++n)
1071
                {
1072
                        dv = ts[n].unicode();
1073
                        error = false;
1074
                        gly = traceChar(face, dv, s, &x, &y, &error);
1075
                        if (gly.size() > 3)
1076
                        {
1077
                                gly.translate(static_cast<double>(pen_x) / 64.0, a);
1078
                                gp = getMaxClipF(&gly);
1079
                                ymax = QMAX(ymax, gp.y());
1080
                                p->setupPolygon(&gly);
1081
                                p->fillPath();
1082
                        }
1083
                        pen_x += face->glyph->advance.x;
1084
                }
1085
        }
92 Franz 1086
        p->end();
95 Franz 1087
        pm.resize(QMIN(qRound(gp.x()), w), QMIN(qRound(ymax), h));
92 Franz 1088
        delete p;
1089
        FT_Done_FreeType( library );
1090
        return pm;
1091
}
1555 fschmid 1092
 
418 Franz 1093
/** Same as FontSample() with \n strings support added.
1094
09/26/2004 petr vanek
1095
*/
2295 cbradney 1096
QPixmap fontSamples(Foi * fnt, int s, QString ts, QColor back)
418 Franz 1097
{
1098
        QStringList lines = QStringList::split("\n", ts);
1099
        QPixmap ret(640, 480);
1100
        QPixmap sample;
1101
        QPainter *painter = new QPainter(&ret);
1102
        int y = 0;
1103
        int x = 0;
1104
        ret.fill(back);
1555 fschmid 1105
        for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it )
1106
        {
2295 cbradney 1107
                sample = FontSample(fnt, s, *it, back);
1065 cbradney 1108
                if (!sample.isNull())
1109
                        painter->drawPixmap(0, y, sample, 0, 0);
418 Franz 1110
                y = y + sample.height();
1111
                if (x < sample.width())
1112
                        x = sample.width();
1113
        } // for
1114
        delete(painter);
1115
        QPixmap final(x, y);
1065 cbradney 1116
        if ((x != 0) && (y != 0))
1117
        {
1118
                QPainter *fpainter = new QPainter(&final);
1119
                fpainter->drawPixmap(0, 0, ret, 0, 0, x, y);
1120
                delete(fpainter);
1121
        }
418 Franz 1122
        return final;
1123
}
1124
 
90 Franz 1125
/***************************************************************************
1126
    begin                : Wed Oct 29 2003
1127
    copyright            : (C) 2003 The Scribus Team
1128
    email                : paul@all-the-johnsons.co.uk
1129
 ***************************************************************************/
1130
// check if the file exists, if it does, ask if they're sure
1131
// return true if they're sure, else return false;
1132
 
1133
bool overwrite(QWidget *parent, QString filename)
1134
{
167 Franz 1135
        bool retval = true;
1136
        QFileInfo fi(filename);
1137
        if (fi.exists())
1555 fschmid 1138
        {
1139
                int t = QMessageBox::warning(parent, QObject::tr("File exists"),
1140
                                             QObject::tr("A file named '%1' already exists.\nDo you want to replace it with the file you are saving?").arg(filename),
1141
                                             QObject::tr("&Cancel"), QObject::tr("&Replace"), "", 1, 0);
1142
                if (t == 0)
90 Franz 1143
                        retval = false;
1555 fschmid 1144
        }
1145
        return retval;
90 Franz 1146
}
124 Franz 1147
 
1957 cbradney 1148
void CopyPageItem(struct CopyPasteBuffer *Buffer, PageItem *currItem)
124 Franz 1149
{
1150
        uint a;
1957 cbradney 1151
        Buffer->PType = currItem->itemType();
1152
        Buffer->Xpos = currItem->Xpos;
1153
        Buffer->Ypos = currItem->Ypos;
1154
        Buffer->Width = currItem->Width;
1155
        Buffer->Height = currItem->Height;
1156
        Buffer->RadRect = currItem->RadRect;
1157
        Buffer->FrameType = currItem->FrameType;
1158
        Buffer->ClipEdited = currItem->ClipEdited;
1159
        Buffer->Pwidth = currItem->Pwidth;
1160
        Buffer->Pcolor = currItem->fillColor();
1161
        Buffer->Pcolor2 = currItem->lineColor();
1162
        Buffer->Shade = currItem->fillShade();
1163
        Buffer->Shade2 = currItem->lineShade();
295 Franz 1164
        Buffer->GrColor = "";
1165
        Buffer->GrColor2 = "";
1166
        Buffer->GrShade = 100;
1167
        Buffer->GrShade2 = 100;
1957 cbradney 1168
        Buffer->fill_gradient = currItem->fill_gradient;
1169
        Buffer->GrType = currItem->GrType;
1170
        Buffer->GrStartX = currItem->GrStartX;
1171
        Buffer->GrStartY = currItem->GrStartY;
1172
        Buffer->GrEndX = currItem->GrEndX;
1173
        Buffer->GrEndY = currItem->GrEndY;
1174
        Buffer->TxtStroke = currItem->TxtStroke;
1175
        Buffer->TxtFill = currItem->TxtFill;
1176
        Buffer->ShTxtStroke = currItem->ShTxtStroke;
1177
        Buffer->ShTxtFill = currItem->ShTxtFill;
1178
        Buffer->TxtScale = currItem->TxtScale;
2230 fschmid 1179
        Buffer->TxtScaleV = currItem->TxtScaleV;
2234 fschmid 1180
        Buffer->TxTBase = currItem->TxtBase;
1957 cbradney 1181
        Buffer->TxTStyle = currItem->TxTStyle;
2247 fschmid 1182
        Buffer->TxtShadowX = currItem->TxtShadowX;
1183
        Buffer->TxtShadowY = currItem->TxtShadowY;
2257 fschmid 1184
        Buffer->TxtOutline = currItem->TxtOutline;
2262 fschmid 1185
        Buffer->TxtUnderPos = currItem->TxtUnderPos;
1186
        Buffer->TxtUnderWidth = currItem->TxtUnderWidth;
2272 fschmid 1187
        Buffer->TxtStrikePos = currItem->TxtStrikePos;
1188
        Buffer->TxtStrikeWidth = currItem->TxtStrikeWidth;
1957 cbradney 1189
        Buffer->Rot = currItem->Rot;
1190
        Buffer->PLineArt = currItem->PLineArt;
1191
        Buffer->PLineEnd = currItem->PLineEnd;
1192
        Buffer->PLineJoin = currItem->PLineJoin;
1193
        Buffer->LineSp = currItem->LineSp;
1194
        Buffer->LocalScX = currItem->LocalScX;
1195
        Buffer->LocalScY = currItem->LocalScY;
1196
        Buffer->LocalX = currItem->LocalX;
1197
        Buffer->LocalY = currItem->LocalY;
1198
        Buffer->PicArt = currItem->PicArt;
1199
        Buffer->flippedH = currItem->imageFlippedH();
1200
        Buffer->flippedV = currItem->imageFlippedV();
1201
        Buffer->BBoxX = currItem->BBoxX;
1202
        Buffer->BBoxH = currItem->BBoxH;
1203
        Buffer->isPrintable = currItem->isPrintable;
1204
        Buffer->isBookmark = currItem->isBookmark;
1205
        Buffer->BMnr = currItem->BMnr;
1206
        Buffer->isAnnotation = currItem->isAnnotation;
1207
        Buffer->AnType = currItem->AnType;
1208
        Buffer->AnAction = currItem->AnAction;
1209
        Buffer->An_E_act = currItem->An_E_act;
1210
        Buffer->An_X_act = currItem->An_X_act;
1211
        Buffer->An_D_act = currItem->An_D_act;
1212
        Buffer->An_Fo_act = currItem->An_Fo_act;
1213
        Buffer->An_Bl_act = currItem->An_Bl_act;
1214
        Buffer->An_K_act = currItem->An_K_act;
1215
        Buffer->An_F_act = currItem->An_F_act;
1216
        Buffer->An_V_act = currItem->An_V_act;
1217
        Buffer->An_C_act = currItem->An_C_act;
1218
        Buffer->An_Extern = currItem->An_Extern;
1219
        Buffer->AnZiel = currItem->AnZiel;
1220
        Buffer->AnName = currItem->itemName();
1221
        Buffer->AnActType = currItem->AnActType;
1222
        Buffer->AnToolTip = currItem->AnToolTip;
1223
        Buffer->AnBwid = currItem->AnBwid;
1224
        Buffer->AnBsty = currItem->AnBsty;
1225
        Buffer->AnFeed = currItem->AnFeed;
1226
        Buffer->AnFlag = currItem->AnFlag;
1227
        Buffer->AnFont = currItem->AnFont;
1228
        Buffer->AnRollOver = currItem->AnRollOver;
1229
        Buffer->AnDown = currItem->AnDown;
1230
        Buffer->AnFormat = currItem->AnFormat;
1231
        Buffer->AnVis = currItem->AnVis;
1232
        Buffer->AnMaxChar = currItem->AnMaxChar;
1233
        Buffer->AnChkStil = currItem->AnChkStil;
1234
        Buffer->AnIsChk = currItem->AnIsChk;
1235
        Buffer->AnAAact = currItem->AnAAact;
1236
        Buffer->AnBColor = currItem->AnBColor;
1237
        Buffer->AnHTML = currItem->AnHTML;
1238
        Buffer->AnUseIcons = currItem->AnUseIcons;
1239
        Buffer->AnIPlace = currItem->AnIPlace;
1240
        Buffer->AnScaleW = currItem->AnScaleW;
1241
        Buffer->Extra = currItem->Extra;
1242
        Buffer->TExtra = currItem->TExtra;
1243
        Buffer->BExtra = currItem->BExtra;
1244
        Buffer->RExtra = currItem->RExtra;
1245
        Buffer->Pfile = currItem->Pfile;
1246
        Buffer->Pfile2 = currItem->Pfile2;
1247
        Buffer->Pfile3 = currItem->Pfile3;
124 Franz 1248
        QString Text = "";
1957 cbradney 1249
        if (currItem->itemText.count() != 0)
167 Franz 1250
        {
1957 cbradney 1251
                for (a=0; a<currItem->itemText.count(); ++a)
124 Franz 1252
                {
1957 cbradney 1253
                        if( (currItem->itemText.at(a)->ch == "\n") || (currItem->itemText.at(a)->ch == "\r"))
124 Franz 1254
                                Text += QString(QChar(5))+"\t";
1957 cbradney 1255
                        else if(currItem->itemText.at(a)->ch == "\t")
139 Franz 1256
                                Text += QString(QChar(4))+"\t";
124 Franz 1257
                        else
1957 cbradney 1258
                                Text += currItem->itemText.at(a)->ch+"\t";
1259
                        Text += currItem->itemText.at(a)->cfont->SCName+"\t";
1260
                        Text += QString::number(currItem->itemText.at(a)->csize / 10.0)+"\t";
1261
                        Text += currItem->itemText.at(a)->ccolor+"\t";
1262
                        Text += QString::number(currItem->itemText.at(a)->cextra)+"\t";
1263
                        Text += QString::number(currItem->itemText.at(a)->cshade)+'\t';
1264
                        Text += QString::number(currItem->itemText.at(a)->cstyle)+'\t';
1265
                        Text += QString::number(currItem->itemText.at(a)->cab)+'\t';
1266
                        Text += currItem->itemText.at(a)->cstroke+"\t";
1267
                        Text += QString::number(currItem->itemText.at(a)->cshade2)+'\t';
2234 fschmid 1268
                        Text += QString::number(currItem->itemText.at(a)->cscale)+'\t';
1269
                        Text += QString::number(currItem->itemText.at(a)->cscalev)+'\t';
2247 fschmid 1270
                        Text += QString::number(currItem->itemText.at(a)->cbase)+'\t';
1271
                        Text += QString::number(currItem->itemText.at(a)->cshadowx)+'\t';
2257 fschmid 1272
                        Text += QString::number(currItem->itemText.at(a)->cshadowy)+'\t';
2262 fschmid 1273
                        Text += QString::number(currItem->itemText.at(a)->coutline)+'\t';
1274
                        Text += QString::number(currItem->itemText.at(a)->cunderpos)+'\t';
2272 fschmid 1275
                        Text += QString::number(currItem->itemText.at(a)->cunderwidth)+'\t';
1276
                        Text += QString::number(currItem->itemText.at(a)->cstrikepos)+'\t';
1277
                        Text += QString::number(currItem->itemText.at(a)->cstrikewidth)+'\n';
124 Franz 1278
                }
167 Franz 1279
        }
1065 cbradney 1280
        Buffer->itemText = Text;
1957 cbradney 1281
        Buffer->Clip = currItem->Clip.copy();
1282
        Buffer->PoLine = currItem->PoLine.copy();
1283
        Buffer->ContourLine = currItem->ContourLine.copy();
1284
        Buffer->UseContour = currItem->textFlowUsesContourLine();
1285
        Buffer->TabValues = currItem->TabValues;
1286
        Buffer->DashValues = currItem->DashValues;
1287
        Buffer->DashOffset = currItem->DashOffset;
1288
        Buffer->PoShow = currItem->PoShow;
1289
        Buffer->BaseOffs = currItem->BaseOffs;
1290
        Buffer->Textflow = currItem->textFlowsAroundFrame();
1291
        Buffer->Textflow2 = currItem->textFlowUsesBoundingBox();
1292
        Buffer->textAlignment = currItem->textAlignment;
1293
        Buffer->IFont = currItem->IFont;
1294
        Buffer->ISize = currItem->ISize;
1295
        Buffer->ExtraV = currItem->ExtraV;
1296
        Buffer->Groups = currItem->Groups;
1297
        Buffer->IProfile = currItem->IProfile;
1298
        Buffer->IRender = currItem->IRender;
1299
        Buffer->UseEmbedded = currItem->UseEmbedded;
1300
        Buffer->EmProfile = currItem->EmProfile;
1301
        Buffer->LayerNr = currItem->LayerNr;
1302
        Buffer->ScaleType = currItem->ScaleType;
1303
        Buffer->AspectRatio = currItem->AspectRatio;
1304
        Buffer->Locked = currItem->locked();
1305
        Buffer->LockRes = currItem->sizeLocked();
1306
        Buffer->Transparency = currItem->fillTransparency();
1307
        Buffer->TranspStroke = currItem->lineTransparency();
1308
        Buffer->Reverse = currItem->Reverse;
1309
        Buffer->NamedLStyle = currItem->NamedLStyle;
1310
        Buffer->Language = currItem->Language;
1311
        Buffer->Cols = currItem->Cols;
1312
        Buffer->ColGap = currItem->ColGap;
1313
        Buffer->isTableItem = currItem->isTableItem;
1314
        Buffer->TopLine = currItem->TopLine;
1315
        Buffer->LeftLine = currItem->LeftLine;
1316
        Buffer->RightLine = currItem->RightLine;
1317
        Buffer->BottomLine = currItem->BottomLine;
1318
        if (currItem->isTableItem)
234 Franz 1319
        {
1957 cbradney 1320
                if (currItem->TopLink != 0)
1321
                        Buffer->TopLinkID = currItem->TopLink->ItemNr;
234 Franz 1322
                else
1323
                        Buffer->TopLinkID = -1;
1957 cbradney 1324
                if (currItem->LeftLink != 0)
1325
                        Buffer->LeftLinkID = currItem->LeftLink->ItemNr;
234 Franz 1326
                else
1327
                        Buffer->LeftLinkID = -1;
1957 cbradney 1328
                if (currItem->RightLink != 0)
1329
                        Buffer->RightLinkID = currItem->RightLink->ItemNr;
234 Franz 1330
                else
1331
                        Buffer->RightLinkID = -1;
1957 cbradney 1332
                if (currItem->BottomLink != 0)
1333
                        Buffer->BottomLinkID = currItem->BottomLink->ItemNr;
234 Franz 1334
                else
1335
                        Buffer->BottomLinkID = -1;
1336
        }
1957 cbradney 1337
        Buffer->startArrowIndex = currItem->startArrowIndex;
1338
        Buffer->endArrowIndex = currItem->endArrowIndex;
124 Franz 1339
}
125 Franz 1340
 
1957 cbradney 1341
void WordAndPara(PageItem* currItem, int *w, int *p, int *c, int *wN, int *pN, int *cN)
125 Franz 1342
{
1343
        QChar Dat = QChar(32);
1344
        int para = 0;
1345
        int ww = 0;
1346
        int cc = 0;
1347
        int paraN = 0;
1348
        int wwN = 0;
1349
        int ccN = 0;
1350
        bool first = true;
1957 cbradney 1351
        PageItem *nextItem = currItem;
1352
        PageItem *nbl = currItem;
1353
        while (nextItem != 0)
167 Franz 1354
        {
1957 cbradney 1355
                if (nextItem->BackBox != 0)
1356
                        nextItem = nextItem->BackBox;
125 Franz 1357
                else
1358
                        break;
167 Franz 1359
        }
1957 cbradney 1360
        while (nextItem != 0)
167 Franz 1361
        {
1957 cbradney 1362
                for (uint a = 0; a < nextItem->itemText.count(); ++a)
1555 fschmid 1363
                {
1957 cbradney 1364
                        QChar b = nextItem->itemText.at(a)->ch[0];
125 Franz 1365
                        if (b == QChar(13))
167 Franz 1366
                        {
1957 cbradney 1367
                                if (a >= nextItem->MaxChars)
125 Franz 1368
                                        paraN++;
1369
                                else
1370
                                        para++;
167 Franz 1371
                        }
125 Franz 1372
                        if ((!b.isLetterOrNumber()) && (Dat.isLetterOrNumber()) && (!first))
167 Franz 1373
                        {
1957 cbradney 1374
                                if (a >= nextItem->MaxChars)
125 Franz 1375
                                        wwN++;
1376
                                else
1377
                                        ww++;
167 Franz 1378
                        }
1957 cbradney 1379
                        if (a >= nextItem->MaxChars)
125 Franz 1380
                                ccN++;
1381
                        else
1382
                                cc++;
1555 fschmid 1383
                        Dat = b;
125 Franz 1384
                        first = false;
1555 fschmid 1385
                }
1957 cbradney 1386
                nbl = nextItem;
1387
                nextItem = nextItem->NextBox;
167 Franz 1388
        }
1065 cbradney 1389
        if (nbl->MaxChars < nbl->itemText.count())
125 Franz 1390
                paraN++;
1391
        else
1392
                para++;
1393
        if (Dat.isLetterOrNumber())
167 Franz 1394
        {
1065 cbradney 1395
                if (nbl->MaxChars < nbl->itemText.count())
125 Franz 1396
                        wwN++;
1397
                else
1398
                        ww++;
167 Franz 1399
        }
125 Franz 1400
        *w = ww;
1401
        *p = para;
1402
        *c = cc;
1403
        *wN = wwN;
1404
        *pN = paraN;
1405
        *cN = ccN;
1406
}
203 Franz 1407
 
690 cbradney 1408
void ReOrderText(ScribusDoc *currentDoc, ScribusView *view)
203 Franz 1409
{
456 fschmid 1410
        double savScale = view->Scale;
1411
        view->Scale = 1.0;
690 cbradney 1412
        currentDoc->RePos = true;
203 Franz 1413
        QPixmap pgPix(10, 10);
1414
        QRect rd = QRect(0,0,9,9);
1415
        ScPainter *painter = new ScPainter(&pgPix, pgPix.width(), pgPix.height());
690 cbradney 1416
        for (uint azz=0; azz<currentDoc->MasterItems.count(); ++azz)
203 Franz 1417
        {
1957 cbradney 1418
                PageItem *currItem = currentDoc->MasterItems.at(azz);
1419
                if (currItem->itemType() == PageItem::PathText)
1420
                        currItem->DrawObj(painter, rd);
203 Franz 1421
        }
690 cbradney 1422
        for (uint azz=0; azz<currentDoc->Items.count(); ++azz)
203 Franz 1423
        {
1957 cbradney 1424
                PageItem *currItem = currentDoc->Items.at(azz);
1425
                if ((currItem->itemType() == PageItem::TextFrame) || (currItem->itemType() == PageItem::PathText))
1426
                        currItem->DrawObj(painter, rd);
203 Franz 1427
        }
690 cbradney 1428
        currentDoc->RePos = false;
456 fschmid 1429
        view->Scale = savScale;
203 Franz 1430
        delete painter;
1431
}
447 cbradney 1432
 
1433
/*! 10/06/2004 - pv
1434
\param QString s1 first string
1435
\param QString s2 second string
1436
\retval bool t/f related s1>s2
1437
 */
1438
bool compareQStrings(QString s1, QString s2)
1439
{
1440
        if (QString::localeAwareCompare(s1, s2) >= 0)
1441
                return FALSE;
1442
        return TRUE;
1443
}
1444
 
1445
/*! 10/06/2004 - pv
1446
Returns a sorted list of QStrings - sorted by locale specific
1447
rules! Uses compareQStrings() as rule. There is STL used!
1448
TODO: Maybe we can implement one cass for various sorting...
1449
\param QStringList aList unsorted string list
1450
\retval QStringList sorted string list
1451
*/
1452
QStringList sortQStringList(QStringList aList)
1453
{
1454
        std::vector<QString> sortList;
1455
        QStringList retList;
1456
        QStringList::Iterator it;
1457
        for (it = aList.begin(); it != aList.end(); ++it)
1458
                sortList.push_back(*it);
1459
        std::sort(sortList.begin(), sortList.end(), compareQStrings);
456 fschmid 1460
        for(uint i = 0; i < sortList.size(); i++)
447 cbradney 1461
                retList.append(sortList[i]);
1462
        return retList;
1463
}
517 fschmid 1464
 
1065 cbradney 1465
void GetItemProps(bool newVersion, QDomElement *obj, struct CopyPasteBuffer *OB)
517 fschmid 1466
{
1467
        QString tmp;
1468
        int x, y;
2282 fschmid 1469
        double xf, yf, xf2;
1460 cbradney 1470
        OB->PType = static_cast<PageItem::ItemType>(QStoInt(obj->attribute("PTYPE")));
517 fschmid 1471
        OB->Width=QStodouble(obj->attribute("WIDTH"));
1472
        OB->Height=QStodouble(obj->attribute("HEIGHT"));
1473
        OB->RadRect = QStodouble(obj->attribute("RADRECT","0"));
1474
        OB->ClipEdited = QStoInt(obj->attribute("CLIPEDIT", "0"));
1475
        OB->FrameType = QStoInt(obj->attribute("FRTYPE", "0"));
1476
        OB->Pwidth=QStodouble(obj->attribute("PWIDTH"));
1394 cbradney 1477
        OB->Pcolor = obj->attribute("PCOLOR");
517 fschmid 1478
        if ((!newVersion) && (OB->PType == 4))
1479
        {
1480
                OB->TxtFill = obj->attribute("PCOLOR2");
1481
                OB->Pcolor2 = "None";
1482
        }
1483
        else
1484
        {
1485
                OB->Pcolor2 = obj->attribute("PCOLOR2");
1486
                OB->TxtFill = obj->attribute("TXTFILL", "Black");
1487
        }
1394 cbradney 1488
        OB->Shade = QStoInt(obj->attribute("SHADE"));
1489
        OB->Shade2 = QStoInt(obj->attribute("SHADE2"));
517 fschmid 1490
        OB->TxtStroke=obj->attribute("TXTSTROKE", "None");
1491
        OB->ShTxtFill=QStoInt(obj->attribute("TXTFILLSH", "100"));
1492
        OB->ShTxtStroke=QStoInt(obj->attribute("TXTSTRSH", "100"));
2242 fschmid 1493
        OB->TxtScale=qRound(QStodouble(obj->attribute("TXTSCALE", "100")) * 10);
1494
        OB->TxtScaleV=qRound(QStodouble(obj->attribute("TXTSCALEV", "100")) * 10);
1495
        OB->TxTBase=qRound(QStodouble(obj->attribute("TXTBASE", "0")) * 10);
517 fschmid 1496
        OB->TxTStyle=QStoInt(obj->attribute("TXTSTYLE", "0"));
2247 fschmid 1497
        OB->TxtShadowX=qRound(QStodouble(obj->attribute("TXTSHX", "5")) * 10);
1498
        OB->TxtShadowY=qRound(QStodouble(obj->attribute("TXTSHY", "-5")) * 10);
2257 fschmid 1499
        OB->TxtOutline=qRound(QStodouble(obj->attribute("TXTOUT", "1")) * 10);
2262 fschmid 1500
        OB->TxtUnderPos=qRound(QStodouble(obj->attribute("TXTULP", "-0.1")) * 10);
1501
        OB->TxtUnderWidth=qRound(QStodouble(obj->attribute("TXTULW", "-0.1")) * 10);
2272 fschmid 1502
        OB->TxtStrikePos=qRound(QStodouble(obj->attribute("TXTSTP", "-0.1")) * 10);
1503
        OB->TxtStrikeWidth=qRound(QStodouble(obj->attribute("TXTSTW", "-0.1")) * 10);
517 fschmid 1504
        OB->Cols = QStoInt(obj->attribute("COLUMNS","1"));
1505
        OB->ColGap = QStodouble(obj->attribute("COLGAP","0.0"));
1506
        OB->GrType = QStoInt(obj->attribute("GRTYP","0"));
1507
        OB->fill_gradient.clearStops();
1508
        if (OB->GrType != 0)
1509
        {
1510
                OB->GrStartX = QStodouble(obj->attribute("GRSTARTX","0.0"));
1511
                OB->GrStartY = QStodouble(obj->attribute("GRSTARTY","0.0"));
1512
                OB->GrEndX = QStodouble(obj->attribute("GRENDX","0.0"));
1513
                OB->GrEndY = QStodouble(obj->attribute("GRENDY","0.0"));
1514
                OB->GrColor = obj->attribute("GRCOLOR","");
2179 fschmid 1515
                if (OB->GrColor == "")
1516
                        OB->GrColor = "Black";
1517
                OB->GrColor2 = obj->attribute("GRCOLOR2","Black");
1518
                if (OB->GrColor2 == "")
1519
                        OB->GrColor2 = "Black";
1520
                OB->GrShade = QStoInt(obj->attribute("GRSHADE","100"));
1521
                OB->GrShade2 = QStoInt(obj->attribute("GRSHADE2","100"));
517 fschmid 1522
        }
1523
        OB->Rot=QStodouble(obj->attribute("ROT"));
1524
        OB->PLineArt=Qt::PenStyle(QStoInt(obj->attribute("PLINEART")));
1525
        OB->PLineEnd=Qt::PenCapStyle(QStoInt(obj->attribute("PLINEEND","0")));
1526
        OB->PLineJoin=Qt::PenJoinStyle(QStoInt(obj->attribute("PLINEJOIN","0")));
1527
        OB->LineSp=QStodouble(obj->attribute("LINESP"));
2309 fschmid 1528
        OB->LineSpMode = QStoInt(obj->attribute("LINESPMode","0"));
517 fschmid 1529
        OB->ExtraV=QStodouble(obj->attribute("EXTRAV","0"));
1530
        OB->LocalScX=QStodouble(obj->attribute("LOCALSCX"));
1531
        OB->LocalScY=QStodouble(obj->attribute("LOCALSCY"));
1532
        OB->LocalX=QStodouble(obj->attribute("LOCALX"));
1533
        OB->LocalY=QStodouble(obj->attribute("LOCALY"));
1534
        OB->PicArt=QStoInt(obj->attribute("PICART"));
2258 fschmid 1535
        OB->flippedH = QStoInt(obj->attribute("FLIPPEDH")) % 2;
1536
        OB->flippedV = QStoInt(obj->attribute("FLIPPEDV")) % 2;
517 fschmid 1537
        OB->BBoxX=QStodouble(obj->attribute("BBOXX"));
1538
        OB->BBoxH=QStodouble(obj->attribute("BBOXH"));
1539
        OB->ScaleType = QStoInt(obj->attribute("SCALETYPE","1"));
1540
        OB->AspectRatio = QStoInt(obj->attribute("RATIO","0"));
1541
        OB->isPrintable=QStoInt(obj->attribute("PRINTABLE"));
1542
        OB->isAnnotation=QStoInt(obj->attribute("ANNOTATION","0"));
1543
        OB->AnType = QStoInt(obj->attribute("ANTYPE","0"));
1544
        OB->AnAction = obj->attribute("ANACTION","");
1545
        OB->An_E_act = obj->attribute("ANEACT","");
1546
        OB->An_X_act = obj->attribute("ANXACT","");
1547
        OB->An_D_act = obj->attribute("ANDACT","");
1548
        OB->An_Fo_act = obj->attribute("ANFOACT","");
1549
        OB->An_Bl_act = obj->attribute("ANBLACT","");
1550
        OB->An_K_act = obj->attribute("ANKACT","");
1551
        OB->An_F_act = obj->attribute("ANFACT","");
1552
        OB->An_V_act = obj->attribute("ANVACT","");
1553
        OB->An_C_act = obj->attribute("ANCACT","");
1554
        OB->AnActType = QStoInt(obj->attribute("ANACTYP","0"));
1555
        OB->An_Extern = obj->attribute("ANEXTERN","");
1556
        if ((OB->An_Extern != "") && (OB->AnActType != 8))
1557
        {
1558
                QFileInfo efp(OB->An_Extern);
1559
                OB->An_Extern = efp.absFilePath();
1560
        }
1561
        OB->AnZiel = QStoInt(obj->attribute("ANZIEL","0"));
1562
        OB->AnName = obj->attribute("ANNAME","");
1563
        OB->AnToolTip = obj->attribute("ANTOOLTIP","");
1564
        OB->AnRollOver = obj->attribute("ANROLL","");
1565
        OB->AnDown = obj->attribute("ANDOWN","");
1566
        OB->AnBwid = QStoInt(obj->attribute("ANBWID","1"));
1567
        OB->AnBsty = QStoInt(obj->attribute("ANBSTY","0"));
1568
        OB->AnFeed = QStoInt(obj->attribute("ANFEED","1"));
1569
        OB->AnFlag = QStoInt(obj->attribute("ANFLAG","0"));
1570
        OB->AnFont = QStoInt(obj->attribute("ANFONT","4"));
1571
        OB->AnFormat = QStoInt(obj->attribute("ANFORMAT","0"));
1572
        OB->AnVis = QStoInt(obj->attribute("ANVIS","0"));
1573
        OB->AnIsChk = static_cast<bool>(QStoInt(obj->attribute("ANCHK","0")));
1574
        OB->AnAAact = static_cast<bool>(QStoInt(obj->attribute("ANAA","0")));
1575
        OB->AnHTML = static_cast<bool>(QStoInt(obj->attribute("ANHTML","0")));
1576
        OB->AnUseIcons = static_cast<bool>(QStoInt(obj->attribute("ANICON","0")));
1577
        OB->AnChkStil = QStoInt(obj->attribute("ANCHKS","0"));
1578
        OB->AnMaxChar = QStoInt(obj->attribute("ANMC","-1"));
1579
        OB->AnBColor = obj->attribute("ANBCOL","None");
1580
        OB->AnIPlace = QStoInt(obj->attribute("ANPLACE","1"));
1581
        OB->AnScaleW = QStoInt(obj->attribute("ANSCALE","0"));
1582
        if (QStoInt(obj->attribute("TRANSPARENT","0")) == 1)
1583
                OB->Pcolor = "None";
1584
        OB->Textflow=QStoInt(obj->attribute("TEXTFLOW"));
1585
        OB->Textflow2 =QStoInt(obj->attribute("TEXTFLOW2","0"));
1586
        OB->UseContour = QStoInt(obj->attribute("TEXTFLOW3","0"));
1587
        OB->Extra=QStodouble(obj->attribute("EXTRA"));
1588
        OB->TExtra=QStodouble(obj->attribute("TEXTRA", "1"));
1589
        OB->BExtra=QStodouble(obj->attribute("BEXTRA", "1"));
1590
        OB->RExtra=QStodouble(obj->attribute("REXTRA", "1"));
1525 cbradney 1591
        OB->PoShow = QStoInt(obj->attribute("PLTSHOW","0"));
517 fschmid 1592
        OB->BaseOffs = QStodouble(obj->attribute("BASEOF","0"));
1593
        OB->ISize = qRound(QStodouble(obj->attribute("ISIZE","12")) * 10);
1594
        OB->Pfile=obj->attribute("PFILE");
1595
        OB->Pfile2=obj->attribute("PFILE2","");
1596
        OB->Pfile3=obj->attribute("PFILE3","");
1597
        OB->IProfile=obj->attribute("PRFILE","");
1598
        OB->EmProfile=obj->attribute("EPROF","");
1599
        OB->IRender = QStoInt(obj->attribute("IRENDER","1"));
1600
        OB->UseEmbedded = QStoInt(obj->attribute("EMBEDDED","1"));
1601
        OB->Locked = static_cast<bool>(QStoInt(obj->attribute("LOCK","0")));
1602
        OB->LockRes = static_cast<bool>(QStoInt(obj->attribute("LOCKR","0")));
1603
        OB->Reverse = static_cast<bool>(QStoInt(obj->attribute("REVERS","0")));
1604
        OB->isTableItem = static_cast<bool>(QStoInt(obj->attribute("isTableItem","0")));
1605
        OB->TopLine = static_cast<bool>(QStoInt(obj->attribute("TopLine","0")));
1606
        OB->LeftLine = static_cast<bool>(QStoInt(obj->attribute("LeftLine","0")));
1607
        OB->RightLine = static_cast<bool>(QStoInt(obj->attribute("RightLine","0")));
1608
        OB->BottomLine = static_cast<bool>(QStoInt(obj->attribute("BottomLine","0")));
1609
        OB->TopLinkID =  QStoInt(obj->attribute("TopLINK","-1"));
1610
        OB->LeftLinkID =  QStoInt(obj->attribute("LeftLINK","-1"));
1611
        OB->RightLinkID =  QStoInt(obj->attribute("RightLINK","-1"));
1612
        OB->BottomLinkID =  QStoInt(obj->attribute("BottomLINK","-1"));
1613
        OB->Transparency = QStodouble(obj->attribute("TransValue","0.0"));
1614
        if (obj->hasAttribute("TransValueS"))
1615
                OB->TranspStroke = QStodouble(obj->attribute("TransValueS","0.0"));
1616
        else
1617
                OB->TranspStroke = OB->Transparency;
1618
        tmp = "";
1619
        if (obj->hasAttribute("NUMCLIP"))
1620
        {
1621
                OB->Clip.resize(obj->attribute("NUMCLIP").toUInt());
1622
                tmp = obj->attribute("CLIPCOOR");
1623
                QTextStream fc(&tmp, IO_ReadOnly);
1624
                for (uint c=0; c<obj->attribute("NUMCLIP").toUInt(); ++c)
1625
                {
1626
                        fc >> x;
1627
                        fc >> y;
1628
                        OB->Clip.setPoint(c, x, y);
1629
                }
1630
        }
1631
        else
1632
                OB->Clip.resize(0);
1633
        tmp = "";
1634
        if (obj->hasAttribute("NUMPO"))
1635
        {
1636
                OB->PoLine.resize(obj->attribute("NUMPO").toUInt());
1637
                tmp = obj->attribute("POCOOR");
1638
                QTextStream fp(&tmp, IO_ReadOnly);
1639
                for (uint cx=0; cx<obj->attribute("NUMPO").toUInt(); ++cx)
1640
                {
1641
                        fp >> xf;
1642
                        fp >> yf;
1643
                        OB->PoLine.setPoint(cx, xf, yf);
1644
                }
1645
        }
1646
        else
1647
                OB->PoLine.resize(0);
1648
        tmp = "";
1649
        if (obj->hasAttribute("NUMCO"))
1650
        {
1651
                OB->ContourLine.resize(obj->attribute("NUMCO").toUInt());
1652
                tmp = obj->attribute("COCOOR");
1653
                QTextStream fp(&tmp, IO_ReadOnly);
1654
                for (uint cx=0; cx<obj->attribute("NUMCO").toUInt(); ++cx)
1655
                {
1656
                        fp >> xf;
1657
                        fp >> yf;
1658
                        OB->ContourLine.setPoint(cx, xf, yf);
1659
                }
1660
        }
1661
        else
1662
                OB->ContourLine.resize(0);
1663
        tmp = "";
1664
        if ((obj->hasAttribute("NUMTAB")) && (QStoInt(obj->attribute("NUMTAB","0")) != 0))
1665
        {
2282 fschmid 1666
                struct PageItem::TabRecord tb;
517 fschmid 1667
                tmp = obj->attribute("TABS");
1668
                QTextStream tgv(&tmp, IO_ReadOnly);
1669
                OB->TabValues.clear();
2282 fschmid 1670
                for (int cxv = 0; cxv < QStoInt(obj->attribute("NUMTAB","0")); cxv += 2)
517 fschmid 1671
                {
1672
                        tgv >> xf;
2282 fschmid 1673
                        tgv >> xf2;
1674
                        tb.tabPosition = xf2;
1675
                        tb.tabType = static_cast<int>(xf);
1676
                        tb.tabFillChar = QChar();
1677
                        OB->TabValues.append(tb);
517 fschmid 1678
                }
1679
                tmp = "";
1680
        }
1681
        else
1682
                OB->TabValues.clear();
1683
        if ((obj->hasAttribute("NUMDASH")) && (QStoInt(obj->attribute("NUMDASH","0")) != 0))
1684
        {
1685
                tmp = obj->attribute("DASHS");
1686
                QTextStream dgv(&tmp, IO_ReadOnly);
1687
                OB->DashValues.clear();
1688
                for (int cxv = 0; cxv < QStoInt(obj->attribute("NUMDASH","0")); ++cxv)
1689
                {
1690
                        dgv >> xf;
1691
                        OB->DashValues.append(xf);
1692
                }
1693
                tmp = "";
1694
        }
1695
        else
1696
                OB->DashValues.clear();
1697
        OB->DashOffset = QStodouble(obj->attribute("DASHOFF","0.0"));
1698
}
1699
 
690 cbradney 1700
QColor SetColor(ScribusDoc *currentDoc, QString color, int shad)
517 fschmid 1701
{
1488 fschmid 1702
        return currentDoc->PageColors[color].getShadeColorProof(shad);
517 fschmid 1703
}