Rev 895 | 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> |
||
25 | #include <qstringlist.h> |
||
26 | #include <qmap.h> |
||
27 | #include <qdom.h> |
||
28 | #include <qimage.h> |
||
19 | Franz | 29 | #include <qdir.h> |
8 | paul | 30 | #include <qpointarray.h> |
90 | Franz | 31 | #include <qmessagebox.h> |
8 | paul | 32 | #include <cstdlib> |
33 | #include <cmath> |
||
213 | Franz | 34 | #include <unistd.h> |
8 | paul | 35 | #include "md5.h" |
201 | Franz | 36 | #include <setjmp.h> |
204 | Franz | 37 | #include "qprocess.h" |
128 | Franz | 38 | |
612 | cbradney | 39 | #ifdef _MSC_VER |
40 | #if (_MSC_VER >= 1200) |
||
41 | #include "win-config.h" |
||
42 | #endif |
||
128 | Franz | 43 | #else |
44 | #include "config.h" |
||
45 | #endif |
||
46 | |||
201 | Franz | 47 | extern "C" { |
48 | #define XMD_H // shut JPEGlib up |
||
49 | #if defined(Q_OS_UNIXWARE) |
||
50 | # define HAVE_BOOLEAN // libjpeg under Unixware seems to need this |
||
51 | #endif |
||
52 | #include <jpeglib.h> |
||
53 | #include <jerror.h> |
||
54 | #undef HAVE_STDLIB_H |
||
55 | #ifdef const |
||
56 | # undef const // remove crazy C hackery in jconfig.h |
||
57 | #endif |
||
58 | } |
||
59 | |||
214 | Franz | 60 | #include "scribus.h" |
8 | paul | 61 | #include "libpdf/pdflib.h" |
68 | Franz | 62 | #include <ft2build.h> |
63 | #include FT_FREETYPE_H |
||
64 | #include FT_OUTLINE_H |
||
65 | #include FT_GLYPH_H |
||
8 | paul | 66 | #ifdef HAVE_LIBZ |
67 | #include <zlib.h> |
||
68 | #endif |
||
69 | #ifdef HAVE_TIFF |
||
70 | #include <tiffio.h> |
||
71 | #endif |
||
72 | #ifdef HAVE_CMS |
||
44 | Franz | 73 | #include CMS_INC |
8 | paul | 74 | extern cmsHPROFILE CMSoutputProf; |
75 | extern cmsHPROFILE CMSprinterProf; |
||
76 | extern cmsHTRANSFORM stdTrans; |
||
77 | extern cmsHTRANSFORM stdProof; |
||
78 | extern cmsHTRANSFORM stdTransImg; |
||
79 | extern cmsHTRANSFORM stdProofImg; |
||
80 | extern bool SoftProofing; |
||
81 | extern bool Gamut; |
||
82 | extern bool CMSuse; |
||
83 | extern int IntentMonitor; |
||
84 | extern int IntentPrinter; |
||
85 | #endif |
||
86 | extern ProfilesL InputProfiles; |
||
214 | Franz | 87 | extern ScribusApp* ScApp; |
8 | paul | 88 | |
503 | cbradney | 89 | using namespace std; |
90 | |||
203 | Franz | 91 | void ReOrderText(ScribusDoc *doc, ScribusView *view); |
125 | Franz | 92 | void WordAndPara(PageItem* b, int *w, int *p, int *c, int *wN, int *pN, int *cN); |
124 | Franz | 93 | void CopyPageItem(struct CLBuf *Buffer, PageItem *b); |
90 | Franz | 94 | bool overwrite(QWidget *parent, QString filename); |
895 | fschmid | 95 | void setBestEncoding(FT_Face face); |
220 | Franz | 96 | FPointArray traceChar(FT_Face face, uint chr, int chs, double *x, double *y, bool &err); |
95 | Franz | 97 | FPoint GetMaxClipF(FPointArray Clip); |
92 | Franz | 98 | QPixmap FontSample(QString da, int s, QString ts, QColor back); |
418 | Franz | 99 | QPixmap fontSamples(QString da, int s, QString ts, QColor back); |
19 | Franz | 100 | QString Path2Relative(QString Path); |
20 | Franz | 101 | QPixmap LoadPDF(QString fn, int Seite, int Size, int *w, int *h); |
8 | paul | 102 | bool GlyNames(QMap<uint, QString> *GList, QString Dat); |
103 | bool GlyIndex(QMap<uint, PDFlib::GlNamInd> *GListInd, QString Dat); |
||
104 | QByteArray ComputeMD5Sum(QByteArray *in); |
||
105 | char *toHex( uchar u ); |
||
106 | QString String2Hex(QString *in, bool lang = true); |
||
107 | QString CompressStr(QString *in); |
||
108 | QString ImageToTxt(QImage *im); |
||
109 | QString ImageToCMYK(QImage *im); |
||
110 | QString ImageToCMYK_PS(QImage *im, int pl, bool pre); |
||
202 | Franz | 111 | void Convert2JPG(QString fn, QImage *image, int Quality, bool isCMYK); |
8 | paul | 112 | QString MaskToTxt(QImage *im, bool PDF = true); |
203 | Franz | 113 | QString MaskToTxt14(QImage *im); |
8 | paul | 114 | void Level2Layer(ScribusDoc *doc, struct Layer *ll, int Level); |
115 | void BezierPoints(QPointArray *ar, QPoint n1, QPoint n2, QPoint n3, QPoint n4); |
||
80 | Franz | 116 | double xy2Deg(double x, double y); |
8 | paul | 117 | QPointArray FlattenPath(FPointArray ina, QValueList<uint> &Segs); |
80 | Franz | 118 | QPointArray RegularPolygon(double w, double h, uint c, bool star, double factor, double rota); |
119 | FPointArray RegularPolygonF(double w, double h, uint c, bool star, double factor, double rota); |
||
8 | paul | 120 | QPixmap loadIcon(QString nam); |
121 | bool loadText(QString nam, QString *Buffer); |
||
80 | Franz | 122 | double Cwidth(ScribusDoc *doc, QString name, QString ch, int Siz, QString ch2 = " "); |
220 | Franz | 123 | double RealCWidth(ScribusDoc *doc, QString name, QString ch, int Siz); |
80 | Franz | 124 | double QStodouble(QString in); |
8 | paul | 125 | int QStoInt(QString in); |
126 | QString GetAttr(QDomElement *el, QString at, QString def="0"); |
||
201 | Franz | 127 | QImage LoadPict(QString fn, bool *gray = 0); |
8 | paul | 128 | #ifdef HAVE_CMS |
129 | QImage ProofPict(QImage *Im, QString Prof, int Rend, cmsHPROFILE emPr=0); |
||
130 | QImage LoadPictCol(QString fn, QString Prof, bool UseEmbedded, bool *realCMYK); |
||
131 | #else |
||
132 | QImage ProofPict(QImage *Im, QString Prof, int Rend); |
||
133 | #endif |
||
134 | QImage ProofImage(QImage *Im); |
||
204 | Franz | 135 | int System(const QStringList & args); |
136 | int callGS(const QStringList & args_in); |
||
137 | int copyFile(QString source, QString target); |
||
138 | int moveFile(QString source, QString target); |
||
8 | paul | 139 | |
140 | #ifdef HAVE_CMS |
||
141 | QImage ProofPict(QImage *Im, QString Prof, int Rend, cmsHPROFILE emPr) |
||
142 | #else |
||
143 | QImage ProofPict(QImage *Im, QString Prof, int Rend) |
||
144 | #endif |
||
145 | { |
||
146 | bool emp = false; |
||
147 | if (Prof == "") |
||
148 | return Im->copy(); |
||
149 | #ifdef HAVE_CMS |
||
150 | QImage out = Im->copy(); |
||
151 | if ((CMSuse) && (SoftProofing)) |
||
167 | Franz | 152 | { |
8 | paul | 153 | cmsHTRANSFORM xform; |
154 | cmsHPROFILE inputProf; |
||
167 | Franz | 155 | if (emPr != 0) |
156 | inputProf = emPr; |
||
157 | else |
||
158 | { |
||
159 | inputProf = cmsOpenProfileFromFile(InputProfiles[Prof], "r"); |
||
8 | paul | 160 | emp = true; |
167 | Franz | 161 | } |
8 | paul | 162 | int dcmsFlags = 0; |
167 | Franz | 163 | dcmsFlags |= Gamut ? cmsFLAGS_GAMUTCHECK : cmsFLAGS_SOFTPROOFING; |
8 | paul | 164 | xform = cmsCreateProofingTransform(inputProf, TYPE_RGBA_8, |
167 | Franz | 165 | CMSoutputProf, TYPE_RGBA_8, |
166 | CMSprinterProf, |
||
167 | IntentPrinter, |
||
168 | Rend, dcmsFlags); |
||
8 | paul | 169 | for (int i=0; i < out.height(); ++i) |
167 | Franz | 170 | { |
8 | paul | 171 | LPBYTE ptr = out.scanLine(i); |
172 | cmsDoTransform(xform, ptr, ptr, out.width()); |
||
167 | Franz | 173 | } |
8 | paul | 174 | cmsDeleteTransform(xform); |
175 | if (emp) |
||
176 | cmsCloseProfile(inputProf); |
||
167 | Franz | 177 | } |
8 | paul | 178 | else |
167 | Franz | 179 | { |
180 | if (CMSuse) |
||
8 | paul | 181 | { |
182 | cmsHTRANSFORM xform; |
||
183 | cmsHPROFILE inputProf; |
||
167 | Franz | 184 | if (emPr != 0) |
185 | inputProf = emPr; |
||
186 | else |
||
187 | { |
||
188 | inputProf = cmsOpenProfileFromFile(InputProfiles[Prof], "r"); |
||
8 | paul | 189 | emp = true; |
167 | Franz | 190 | } |
8 | paul | 191 | xform = cmsCreateTransform(inputProf, TYPE_RGBA_8, |
167 | Franz | 192 | CMSoutputProf, TYPE_RGBA_8, |
193 | Rend, |
||
194 | 0); |
||
8 | paul | 195 | for (int i=0; i < out.height(); ++i) |
167 | Franz | 196 | { |
8 | paul | 197 | LPBYTE ptr = out.scanLine(i); |
198 | cmsDoTransform(xform, ptr, ptr, out.width()); |
||
167 | Franz | 199 | } |
8 | paul | 200 | cmsDeleteTransform(xform); |
201 | if (emp) |
||
202 | cmsCloseProfile(inputProf); |
||
203 | } |
||
167 | Franz | 204 | } |
8 | paul | 205 | return out; |
206 | #else |
||
207 | return Im->copy(); |
||
208 | #endif |
||
209 | } |
||
210 | |||
211 | QImage ProofImage(QImage *Im) |
||
212 | { |
||
213 | #ifdef HAVE_CMS |
||
214 | QImage out = Im->copy(); |
||
215 | if ((CMSuse) && (SoftProofing)) |
||
167 | Franz | 216 | { |
217 | for (int i=0; i < out.height(); ++i) |
||
8 | paul | 218 | { |
219 | LPBYTE ptr = out.scanLine(i); |
||
220 | cmsDoTransform(stdProofImg, ptr, ptr, out.width()); |
||
221 | } |
||
167 | Franz | 222 | } |
8 | paul | 223 | else |
167 | Franz | 224 | { |
225 | if (CMSuse) |
||
8 | paul | 226 | { |
167 | Franz | 227 | for (int i=0; i < out.height(); ++i) |
8 | paul | 228 | { |
229 | LPBYTE ptr = out.scanLine(i); |
||
230 | cmsDoTransform(stdTransImg, ptr, ptr, out.width()); |
||
231 | } |
||
232 | } |
||
167 | Franz | 233 | } |
8 | paul | 234 | return out; |
235 | #else |
||
236 | return Im->copy(); |
||
237 | #endif |
||
238 | } |
||
239 | |||
204 | Franz | 240 | /****************************************************************** |
241 | * Function System() |
||
242 | * |
||
243 | * Create a new process via QProcess and wait until finished. |
||
244 | * return the process exit code. |
||
245 | * |
||
246 | ******************************************************************/ |
||
247 | |||
248 | int System(const QStringList & args) |
||
249 | { |
||
250 | QProcess *proc = new QProcess(NULL); |
||
251 | proc->setArguments(args); |
||
252 | if ( !proc->start() ) |
||
253 | { |
||
214 | Franz | 254 | delete proc; |
204 | Franz | 255 | return 1; |
256 | } |
||
257 | /* start was OK */ |
||
258 | while(proc->isRunning()) |
||
259 | { |
||
260 | /* wait a little bit */ |
||
261 | usleep(5000); |
||
262 | } |
||
263 | int ex = proc->exitStatus(); |
||
264 | delete proc; |
||
265 | return ex; |
||
266 | } |
||
267 | |||
268 | /****************************************************************** |
||
269 | * Function callGS() |
||
270 | * build the complete list of arguments for the call of our |
||
271 | * System() function. |
||
272 | * |
||
273 | * The gs commands are all similar and consist of a few constant |
||
274 | * arguments, the variablke arguments and the end arguments which |
||
275 | * are also invariant. |
||
276 | ******************************************************************/ |
||
277 | |||
278 | int callGS(const QStringList & args_in) |
||
279 | { |
||
280 | QStringList args; |
||
281 | |||
282 | /* these parameters are always the same */ |
||
220 | Franz | 283 | args.append(ScApp->Prefs.gs_exe); |
204 | Franz | 284 | args.append("-q"); |
285 | args.append("-dNOPAUSE"); |
||
214 | Franz | 286 | if (ScApp->HavePngAlpha != 0) |
287 | args.append("-sDEVICE=png16m"); |
||
288 | else |
||
289 | args.append("-sDEVICE=pngalpha"); |
||
220 | Franz | 290 | if (ScApp->Prefs.gs_antiText) |
291 | args.append("-dTextAlphaBits=4"); |
||
292 | if (ScApp->Prefs.gs_antiGraph) |
||
293 | args.append("-dGraphicsAlphaBits=4"); |
||
204 | Franz | 294 | |
295 | /* insert specific arguments */ |
||
296 | QStringList p; |
||
297 | p = args_in; |
||
298 | args += args_in; |
||
299 | /* insert last unspecific arguments */ |
||
300 | args.append("-c"); |
||
301 | args.append("showpage"); |
||
302 | args.append("-c"); |
||
303 | args.append("quit"); |
||
304 | return System(args); |
||
305 | } |
||
306 | |||
307 | int copyFile(QString source, QString target) |
||
308 | { |
||
309 | if ((source.isNull()) || (target.isNull())) |
||
310 | return -1; |
||
311 | if (source == target) |
||
312 | return -1; |
||
313 | QFile s(source); |
||
314 | QFile t(target); |
||
315 | if (!s.exists()) |
||
316 | return -1; |
||
317 | QByteArray bb(s.size()); |
||
318 | if (s.open(IO_ReadOnly)) |
||
319 | { |
||
320 | s.readBlock(bb.data(), s.size()); |
||
321 | s.close(); |
||
322 | if (t.open(IO_WriteOnly)) |
||
323 | { |
||
324 | t.writeBlock(bb.data(), bb.size()); |
||
325 | t.close(); |
||
326 | } |
||
327 | } |
||
328 | return 0; |
||
329 | } |
||
330 | |||
331 | int moveFile(QString source, QString target) |
||
332 | { |
||
333 | if ((source.isNull()) || (target.isNull())) |
||
334 | return -1; |
||
335 | if (source == target) |
||
336 | return -1; |
||
337 | copyFile(source, target); |
||
338 | unlink(source); |
||
339 | return 0; |
||
340 | } |
||
341 | |||
20 | Franz | 342 | QPixmap LoadPDF(QString fn, int Seite, int Size, int *w, int *h) |
19 | Franz | 343 | { |
344 | QString tmp, cmd1, cmd2; |
||
282 | Franz | 345 | QString tmpFile = QDir::convertSeparators(QDir::homeDirPath()+"/.scribus/sc.png"); |
19 | Franz | 346 | QPixmap pm; |
347 | int ret = -1; |
||
348 | tmp.setNum(Seite); |
||
204 | Franz | 349 | QStringList args; |
350 | args.append("-r72"); |
||
351 | args.append("-sOutputFile="+tmpFile); |
||
352 | args.append("-dFirstPage="+tmp); |
||
353 | args.append("-dLastPage="+tmp); |
||
354 | args.append(fn); |
||
355 | ret = callGS(args); |
||
19 | Franz | 356 | if (ret == 0) |
167 | Franz | 357 | { |
19 | Franz | 358 | QImage image; |
159 | Franz | 359 | image.load(tmpFile); |
204 | Franz | 360 | unlink(tmpFile); |
167 | Franz | 361 | QImage im2; |
20 | Franz | 362 | *h = image.height(); |
363 | *w = image.width(); |
||
80 | Franz | 364 | double sx = image.width() / static_cast<double>(Size); |
365 | double sy = image.height() / static_cast<double>(Size); |
||
167 | Franz | 366 | double t = (sy < sx ? sx : sy); |
367 | im2 = image.smoothScale(static_cast<int>(image.width() / t), static_cast<int>(image.height() / t)); |
||
19 | Franz | 368 | pm.convertFromImage(im2); |
369 | QPainter p; |
||
370 | p.begin(&pm); |
||
371 | p.setBrush(Qt::NoBrush); |
||
372 | p.setPen(Qt::black); |
||
373 | p.drawRect(0, 0, pm.width(), pm.height()); |
||
374 | p.end(); |
||
375 | im2.detach(); |
||
167 | Franz | 376 | } |
19 | Franz | 377 | return pm; |
378 | } |
||
379 | |||
201 | Franz | 380 | QImage LoadPict(QString fn, bool *gray) |
8 | paul | 381 | { |
84 | Franz | 382 | QString tmp, dummy, cmd1, cmd2, BBox, tmp2; |
8 | paul | 383 | QChar tc; |
384 | QImage Bild; |
||
80 | Franz | 385 | double x, y, b, h; |
8 | paul | 386 | bool found = false; |
387 | int ret = -1; |
||
282 | Franz | 388 | QString tmpFile = QDir::convertSeparators(QDir::homeDirPath()+"/.scribus/sc.png"); |
8 | paul | 389 | QFileInfo fi = QFileInfo(fn); |
390 | QString ext = fi.extension(false).lower(); |
||
16 | Franz | 391 | if (ext == "pdf") |
167 | Franz | 392 | { |
204 | Franz | 393 | QStringList args; |
394 | args.append("-r72"); |
||
395 | args.append("-sOutputFile="+tmpFile); |
||
396 | args.append("-dFirstPage=1"); |
||
397 | args.append("-dLastPage=1"); |
||
398 | args.append(fn); |
||
399 | ret = callGS(args); |
||
16 | Franz | 400 | if (ret == 0) |
167 | Franz | 401 | { |
16 | Franz | 402 | QImage image; |
159 | Franz | 403 | image.load(tmpFile); |
167 | Franz | 404 | Bild = image.convertDepth(32); |
204 | Franz | 405 | unlink(tmpFile); |
16 | Franz | 406 | } |
167 | Franz | 407 | } |
8 | paul | 408 | if ((ext == "eps") || (ext == "ps")) |
167 | Franz | 409 | { |
8 | paul | 410 | QFile f(fn); |
411 | if (f.open(IO_ReadOnly)) |
||
167 | Franz | 412 | { |
8 | paul | 413 | QTextStream ts(&f); |
414 | while (!ts.atEnd()) |
||
167 | Franz | 415 | { |
8 | paul | 416 | tc = ' '; |
417 | tmp = ""; |
||
418 | while ((tc != '\n') && (tc != '\r')) |
||
167 | Franz | 419 | { |
8 | paul | 420 | ts >> tc; |
421 | if ((tc != '\n') && (tc != '\r')) |
||
422 | tmp += tc; |
||
167 | Franz | 423 | } |
286 | Franz | 424 | if (tmp.startsWith("%%BoundingBox:")) |
167 | Franz | 425 | { |
8 | paul | 426 | found = true; |
286 | Franz | 427 | BBox = tmp.remove("%%BoundingBox:"); |
167 | Franz | 428 | } |
286 | Franz | 429 | if (!found) |
430 | { |
||
431 | if (tmp.startsWith("%%BoundingBox")) |
||
432 | { |
||
433 | found = true; |
||
434 | BBox = tmp.remove("%%BoundingBox"); |
||
435 | } |
||
436 | } |
||
8 | paul | 437 | if (tmp.startsWith("%%EndComments")) |
438 | break; |
||
167 | Franz | 439 | } |
8 | paul | 440 | f.close(); |
441 | if (found) |
||
167 | Franz | 442 | { |
8 | paul | 443 | QTextStream ts2(&BBox, IO_ReadOnly); |
286 | Franz | 444 | ts2 >> x >> y >> b >> h; |
204 | Franz | 445 | QStringList args; |
446 | args.append("-r72"); |
||
447 | args.append("-sOutputFile="+tmpFile); |
||
448 | args.append("-g"+tmp.setNum(qRound(b))+"x"+tmp2.setNum(qRound(h))); |
||
449 | args.append(fn); |
||
450 | ret = callGS(args); |
||
8 | paul | 451 | if (ret == 0) |
167 | Franz | 452 | { |
8 | paul | 453 | QImage image; |
159 | Franz | 454 | image.load(tmpFile); |
188 | Franz | 455 | image = image.convertDepth(32); |
456 | image.setAlphaBuffer(true); |
||
214 | Franz | 457 | if (ScApp->HavePngAlpha != 0) |
458 | { |
||
459 | int wi = image.width(); |
||
460 | int hi = image.height(); |
||
461 | for( int yi=0; yi < hi; ++yi ) |
||
8 | paul | 462 | { |
214 | Franz | 463 | QRgb *s = (QRgb*)(image.scanLine( yi )); |
464 | for(int xi=0; xi < wi; ++xi ) |
||
8 | paul | 465 | { |
214 | Franz | 466 | if((*s) == 0xffffffff) |
467 | (*s) &= 0x00ffffff; |
||
468 | s++; |
||
188 | Franz | 469 | } |
470 | } |
||
214 | Franz | 471 | } |
188 | Franz | 472 | Bild = image.copy(static_cast<int>(x), 0, static_cast<int>(b-x), static_cast<int>(h-y)); |
204 | Franz | 473 | unlink(tmpFile); |
8 | paul | 474 | } |
475 | } |
||
476 | } |
||
167 | Franz | 477 | } |
8 | paul | 478 | #ifdef HAVE_TIFF |
479 | if (ext == "tif") |
||
167 | Franz | 480 | { |
8 | paul | 481 | QImage img; |
482 | QImage inI2; |
||
483 | TIFF* tif = TIFFOpen(fn, "r"); |
||
484 | if(tif) |
||
167 | Franz | 485 | { |
8 | paul | 486 | unsigned width, height,size; |
487 | TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width); |
||
488 | TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height); |
||
489 | size=width*height; |
||
490 | uint32 *bits=(uint32*) _TIFFmalloc(size * sizeof (uint32)); |
||
491 | if(bits) |
||
167 | Franz | 492 | { |
493 | if (TIFFReadRGBAImage(tif, width, height, bits, 0)) |
||
8 | paul | 494 | { |
189 | Franz | 495 | img.create(width,height,32); |
496 | img.setAlphaBuffer(true); |
||
8 | paul | 497 | if(TIFFGetR(0x1234567)==qRed (0x1234567) && |
498 | TIFFGetG(0x1234567)==qGreen(0x1234567) && |
||
499 | TIFFGetB(0x1234567)==qBlue (0x1234567)) |
||
167 | Franz | 500 | { |
8 | paul | 501 | for(unsigned y=0; y<height; ++y) |
502 | memcpy(img.scanLine(height-1-y),bits+y*width,width*4); |
||
167 | Franz | 503 | } |
8 | paul | 504 | else |
167 | Franz | 505 | { |
8 | paul | 506 | uint32 *inp=bits; |
507 | for(unsigned y=0; y<height; ++y) |
||
167 | Franz | 508 | { |
8 | paul | 509 | QRgb *row=(QRgb*) (img.scanLine(height-1-y)); |
510 | for(unsigned x=0; x<width; ++x) |
||
167 | Franz | 511 | { |
8 | paul | 512 | const uint32 col=*(inp++); |
189 | Franz | 513 | row[x]=qRgba(TIFFGetR(col), TIFFGetG(col), TIFFGetB(col), TIFFGetA(col)); |
8 | paul | 514 | } |
515 | } |
||
167 | Franz | 516 | } |
8 | paul | 517 | Bild = img.copy(); |
167 | Franz | 518 | } |
8 | paul | 519 | _TIFFfree(bits); |
167 | Franz | 520 | } |
8 | paul | 521 | TIFFClose(tif); |
522 | } |
||
167 | Franz | 523 | } |
8 | paul | 524 | #endif |
525 | else |
||
167 | Franz | 526 | { |
868 | fschmid | 527 | if (Bild.load(fn)) |
201 | Franz | 528 | { |
868 | fschmid | 529 | if (gray != 0) |
530 | { |
||
531 | if ((Bild.depth() == 8) && (Bild.isGrayscale())) |
||
532 | *gray = true; |
||
533 | else |
||
534 | *gray = false; |
||
535 | } |
||
536 | Bild = Bild.convertDepth(32); |
||
201 | Franz | 537 | } |
167 | Franz | 538 | } |
8 | paul | 539 | return Bild; |
540 | } |
||
541 | |||
542 | #ifdef HAVE_CMS |
||
543 | QImage LoadPictCol(QString fn, QString Prof, bool UseEmbedded, bool *realCMYK) |
||
544 | { |
||
84 | Franz | 545 | QString tmp, dummy, cmd1, cmd2, BBox, tmp2; |
8 | paul | 546 | QChar tc; |
547 | QImage Bild; |
||
80 | Franz | 548 | double x, y, b, h; |
8 | paul | 549 | bool found = false; |
550 | int ret = -1; |
||
282 | Franz | 551 | QString tmpFile = QDir::convertSeparators(QDir::homeDirPath()+"/.scribus/sc.png"); |
8 | paul | 552 | QFileInfo fi = QFileInfo(fn); |
553 | QString ext = fi.extension(false).lower(); |
||
16 | Franz | 554 | if (ext == "pdf") |
167 | Franz | 555 | { |
204 | Franz | 556 | QStringList args; |
557 | args.append("-r72"); |
||
558 | args.append("-sOutputFile="+tmpFile); |
||
559 | args.append("-dFirstPage=1"); |
||
560 | args.append("-dLastPage=1"); |
||
561 | args.append(fn); |
||
562 | ret = callGS(args); |
||
16 | Franz | 563 | if (ret == 0) |
167 | Franz | 564 | { |
16 | Franz | 565 | QImage image; |
159 | Franz | 566 | image.load(tmpFile); |
167 | Franz | 567 | Bild = image.convertDepth(32); |
204 | Franz | 568 | unlink(tmpFile); |
16 | Franz | 569 | *realCMYK = false; |
570 | } |
||
167 | Franz | 571 | } |
572 | if ((ext == "eps") || (ext == "ps")) |
||
8 | paul | 573 | { |
167 | Franz | 574 | QFile f(fn); |
575 | if (f.open(IO_ReadOnly)) |
||
8 | paul | 576 | { |
167 | Franz | 577 | QTextStream ts(&f); |
578 | while (!ts.atEnd()) |
||
8 | paul | 579 | { |
167 | Franz | 580 | tc = ' '; |
581 | tmp = ""; |
||
582 | while ((tc != '\n') && (tc != '\r')) |
||
8 | paul | 583 | { |
167 | Franz | 584 | ts >> tc; |
585 | if ((tc != '\n') && (tc != '\r')) |
||
586 | tmp += tc; |
||
8 | paul | 587 | } |
286 | Franz | 588 | if (tmp.startsWith("%%BoundingBox:")) |
8 | paul | 589 | { |
167 | Franz | 590 | found = true; |
286 | Franz | 591 | BBox = tmp.remove("%%BoundingBox:"); |
8 | paul | 592 | } |
286 | Franz | 593 | if (!found) |
594 | { |
||
595 | if (tmp.startsWith("%%BoundingBox")) |
||
596 | { |
||
597 | found = true; |
||
598 | BBox = tmp.remove("%%BoundingBox"); |
||
599 | } |
||
600 | } |
||
167 | Franz | 601 | if (tmp.startsWith("%%EndComments")) |
602 | break; |
||
8 | paul | 603 | } |
167 | Franz | 604 | f.close(); |
605 | if (found) |
||
8 | paul | 606 | { |
167 | Franz | 607 | QTextStream ts2(&BBox, IO_ReadOnly); |
286 | Franz | 608 | ts2 >> x >> y >> b >> h; |
204 | Franz | 609 | QStringList args; |
610 | args.append("-r72"); |
||
611 | args.append("-sOutputFile="+tmpFile); |
||
612 | args.append("-g"+tmp.setNum(qRound(b))+"x"+tmp2.setNum(qRound(h))); |
||
613 | args.append(fn); |
||
614 | ret = callGS(args); |
||
167 | Franz | 615 | if (ret == 0) |
8 | paul | 616 | { |
167 | Franz | 617 | QImage image; |
618 | image.load(tmpFile); |
||
188 | Franz | 619 | image = image.convertDepth(32); |
620 | image.setAlphaBuffer(true); |
||
214 | Franz | 621 | if (ScApp->HavePngAlpha != 0) |
622 | { |
||
623 | int wi = image.width(); |
||
624 | int hi = image.height(); |
||
625 | for( int yi=0; yi < hi; ++yi ) |
||
8 | paul | 626 | { |
214 | Franz | 627 | QRgb *s = (QRgb*)(image.scanLine( yi )); |
628 | for(int xi=0; xi < wi; ++xi ) |
||
8 | paul | 629 | { |
214 | Franz | 630 | if((*s) == 0xffffffff) |
631 | (*s) &= 0x00ffffff; |
||
632 | s++; |
||
188 | Franz | 633 | } |
214 | Franz | 634 | } |
635 | } |
||
188 | Franz | 636 | Bild = image.copy(static_cast<int>(x), 0, static_cast<int>(b-x), static_cast<int>(h-y)); |
204 | Franz | 637 | unlink(tmpFile); |
167 | Franz | 638 | *realCMYK = false; |
8 | paul | 639 | } |
640 | } |
||
641 | } |
||
642 | } |
||
643 | #ifdef HAVE_TIFF |
||
167 | Franz | 644 | if (ext == "tif") |
8 | paul | 645 | { |
167 | Franz | 646 | QImage img; |
647 | QImage inI2; |
||
648 | TIFF* tif = TIFFOpen(fn, "r"); |
||
649 | if(tif) |
||
8 | paul | 650 | { |
167 | Franz | 651 | DWORD EmbedLen = 0; |
652 | LPBYTE EmbedBuffer; |
||
653 | unsigned width, height,size; |
||
654 | TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width); |
||
655 | TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height); |
||
656 | size=width*height; |
||
657 | uint32 *bits=(uint32*) _TIFFmalloc(size * sizeof (uint32)); |
||
658 | if(bits) |
||
8 | paul | 659 | { |
167 | Franz | 660 | if (TIFFReadRGBAImage(tif, width, height, bits, 0)) |
8 | paul | 661 | { |
167 | Franz | 662 | img.create(width,height,32); |
189 | Franz | 663 | img.setAlphaBuffer(true); |
167 | Franz | 664 | if(TIFFGetR(0x1234567)==qRed (0x1234567) && |
665 | TIFFGetG(0x1234567)==qGreen(0x1234567) && |
||
666 | TIFFGetB(0x1234567)==qBlue (0x1234567)) |
||
8 | paul | 667 | { |
167 | Franz | 668 | for(unsigned y=0; y<height; ++y) |
669 | memcpy(img.scanLine(height-1-y),bits+y*width,width*4); |
||
8 | paul | 670 | } |
167 | Franz | 671 | else |
8 | paul | 672 | { |
167 | Franz | 673 | uint32 *inp=bits; |
674 | for(unsigned y=0; y<height; ++y) |
||
8 | paul | 675 | { |
167 | Franz | 676 | QRgb *row=(QRgb*) (img.scanLine(height-1-y)); |
677 | for(unsigned x=0; x<width; ++x) |
||
8 | paul | 678 | { |
167 | Franz | 679 | const uint32 col=*(inp++); |
189 | Franz | 680 | row[x]=qRgba(TIFFGetR(col), TIFFGetG(col), TIFFGetB(col), TIFFGetA(col)); |
8 | paul | 681 | } |
682 | } |
||
683 | } |
||
167 | Franz | 684 | Bild = img.copy(); |
8 | paul | 685 | } |
167 | Franz | 686 | _TIFFfree(bits); |
687 | cmsHTRANSFORM xform; |
||
688 | cmsHPROFILE inputProf; |
||
689 | if((TIFFGetField(tif, TIFFTAG_ICCPROFILE, &EmbedLen, &EmbedBuffer)) && (UseEmbedded)) |
||
8 | paul | 690 | { |
167 | Franz | 691 | inputProf = cmsOpenProfileFromMem(EmbedBuffer, EmbedLen); |
692 | if (static_cast<int>(cmsGetColorSpace(inputProf)) == icSigRgbData) |
||
8 | paul | 693 | { |
167 | Franz | 694 | switch (static_cast<int>(cmsGetColorSpace(CMSprinterProf))) |
8 | paul | 695 | { |
167 | Franz | 696 | case icSigRgbData: |
697 | *realCMYK = false; |
||
698 | xform = cmsCreateTransform(inputProf, TYPE_RGBA_8, CMSprinterProf, |
||
699 | TYPE_RGBA_8, IntentPrinter, 0); |
||
700 | break; |
||
701 | case icSigCmykData: |
||
702 | *realCMYK = true; |
||
703 | xform = cmsCreateTransform(inputProf, TYPE_RGBA_8, CMSprinterProf, |
||
704 | TYPE_CMYK_8, IntentPrinter, 0); |
||
705 | break; |
||
8 | paul | 706 | } |
167 | Franz | 707 | for (int i=0; i < Bild.height(); ++i) |
8 | paul | 708 | { |
167 | Franz | 709 | LPBYTE ptr = Bild.scanLine(i); |
710 | cmsDoTransform(xform, ptr, ptr, Bild.width()); |
||
8 | paul | 711 | } |
712 | } |
||
713 | } |
||
167 | Franz | 714 | else |
8 | paul | 715 | { |
167 | Franz | 716 | inputProf = cmsOpenProfileFromFile(InputProfiles[Prof], "r"); |
717 | switch (static_cast<int>(cmsGetColorSpace(CMSprinterProf))) |
||
8 | paul | 718 | { |
167 | Franz | 719 | case icSigRgbData: |
720 | *realCMYK = false; |
||
721 | xform = cmsCreateTransform(inputProf, TYPE_RGBA_8, CMSprinterProf, |
||
722 | TYPE_RGBA_8, IntentPrinter, 0); |
||
723 | break; |
||
724 | case icSigCmykData: |
||
725 | *realCMYK = true; |
||
726 | xform = cmsCreateTransform(inputProf, TYPE_RGBA_8, CMSprinterProf, |
||
727 | TYPE_CMYK_8, IntentPrinter, 0); |
||
728 | break; |
||
8 | paul | 729 | } |
167 | Franz | 730 | for (int i=0; i < Bild.height(); ++i) |
8 | paul | 731 | { |
167 | Franz | 732 | LPBYTE ptr = Bild.scanLine(i); |
733 | cmsDoTransform(xform, ptr, ptr, Bild.width()); |
||
8 | paul | 734 | } |
735 | } |
||
167 | Franz | 736 | cmsDeleteTransform(xform); |
737 | cmsCloseProfile(inputProf); |
||
8 | paul | 738 | } |
167 | Franz | 739 | TIFFClose(tif); |
8 | paul | 740 | } |
741 | } |
||
742 | #endif |
||
743 | else |
||
167 | Franz | 744 | { |
8 | paul | 745 | cmsHTRANSFORM xform; |
746 | cmsHPROFILE inputProf; |
||
747 | Bild.load(fn); |
||
167 | Franz | 748 | Bild = Bild.convertDepth(32); |
8 | paul | 749 | inputProf = cmsOpenProfileFromFile(InputProfiles[Prof], "r"); |
49 | paul | 750 | switch (static_cast<int>(cmsGetColorSpace(CMSprinterProf))) |
167 | Franz | 751 | { |
8 | paul | 752 | case icSigRgbData: |
753 | *realCMYK = false; |
||
754 | xform = cmsCreateTransform(inputProf, TYPE_RGBA_8, CMSprinterProf, TYPE_RGBA_8, IntentPrinter, 0); |
||
755 | break; |
||
756 | case icSigCmykData: |
||
757 | *realCMYK = true; |
||
758 | xform = cmsCreateTransform(inputProf, TYPE_RGBA_8, CMSprinterProf, TYPE_CMYK_8, IntentPrinter, 0); |
||
759 | break; |
||
167 | Franz | 760 | } |
8 | paul | 761 | for (int i=0; i < Bild.height(); ++i) |
167 | Franz | 762 | { |
8 | paul | 763 | LPBYTE ptr = Bild.scanLine(i); |
764 | cmsDoTransform(xform, ptr, ptr, Bild.width()); |
||
167 | Franz | 765 | } |
8 | paul | 766 | cmsDeleteTransform(xform); |
150 | Franz | 767 | cmsCloseProfile(inputProf); |
167 | Franz | 768 | } |
8 | paul | 769 | return Bild; |
770 | } |
||
771 | #endif |
||
772 | |||
773 | QString GetAttr(QDomElement *el, QString at, QString def) |
||
774 | { |
||
775 | return el->attribute(at, def); |
||
776 | } |
||
777 | |||
778 | int QStoInt(QString in) |
||
779 | { |
||
780 | bool ok = false; |
||
781 | int c = in.toInt(&ok); |
||
167 | Franz | 782 | return ok ? c : 0; |
8 | paul | 783 | } |
784 | |||
80 | Franz | 785 | double QStodouble(QString in) |
8 | paul | 786 | { |
787 | bool ok = false; |
||
80 | Franz | 788 | double c = in.toDouble(&ok); |
167 | Franz | 789 | return ok ? c : 0.0; |
8 | paul | 790 | } |
791 | |||
792 | QPixmap loadIcon(QString nam) |
||
793 | { |
||
870 | cbradney | 794 | QString pfad = ICONDIR; |
795 | pfad += nam; |
||
8 | paul | 796 | QPixmap pm; |
797 | pm.load(pfad); |
||
798 | return pm; |
||
799 | } |
||
800 | |||
801 | bool loadText(QString nam, QString *Buffer) |
||
802 | { |
||
803 | QFile f(nam); |
||
804 | QFileInfo fi(f); |
||
805 | if (!fi.exists()) |
||
806 | return false; |
||
807 | uint posi; |
||
167 | Franz | 808 | bool ret; |
8 | paul | 809 | QByteArray bb(f.size()); |
810 | if (f.open(IO_ReadOnly)) |
||
167 | Franz | 811 | { |
8 | paul | 812 | f.readBlock(bb.data(), f.size()); |
813 | f.close(); |
||
814 | for (posi = 0; posi < bb.size(); ++posi) |
||
815 | *Buffer += bb[posi]; |
||
816 | ret = true; |
||
167 | Franz | 817 | } |
8 | paul | 818 | else |
819 | ret = false; |
||
820 | return ret; |
||
821 | } |
||
822 | |||
80 | Franz | 823 | double Cwidth(ScribusDoc *doc, QString name, QString ch, int Siz, QString ch2) |
8 | paul | 824 | { |
80 | Franz | 825 | double w; |
8 | paul | 826 | FT_Vector delta; |
827 | uint c1 = ch.at(0).unicode(); |
||
828 | uint c2 = ch2.at(0).unicode(); |
||
829 | Foi* fo = (*doc->AllFonts)[name]; |
||
830 | if (fo->CharWidth.contains(c1)) |
||
167 | Franz | 831 | { |
111 | Franz | 832 | w = fo->CharWidth[c1]*(Siz / 10.0); |
8 | paul | 833 | if (fo->HasKern) |
167 | Franz | 834 | { |
8 | paul | 835 | uint cl = FT_Get_Char_Index(doc->FFonts[name], c1); |
836 | uint cr = FT_Get_Char_Index(doc->FFonts[name], c2); |
||
9 | Franz | 837 | FT_Get_Kerning(doc->FFonts[name], cl, cr, ft_kerning_unscaled, &delta); |
111 | Franz | 838 | w += delta.x / fo->uniEM * (Siz / 10.0); |
167 | Franz | 839 | } |
8 | paul | 840 | return w; |
167 | Franz | 841 | } |
8 | paul | 842 | else |
111 | Franz | 843 | return static_cast<double>(Siz / 10.0); |
8 | paul | 844 | } |
845 | |||
220 | Franz | 846 | double RealCWidth(ScribusDoc *doc, QString name, QString ch, int Siz) |
847 | { |
||
221 | Franz | 848 | double w, ww; |
220 | Franz | 849 | uint c1 = ch.at(0).unicode(); |
850 | Foi* fo = (*doc->AllFonts)[name]; |
||
851 | if (fo->CharWidth.contains(c1)) |
||
852 | { |
||
853 | uint cl = FT_Get_Char_Index(doc->FFonts[name], c1); |
||
854 | FT_Load_Glyph( doc->FFonts[name], cl, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP ); |
||
503 | cbradney | 855 | w = (doc->FFonts[name]->glyph->metrics.width + fabs((double)doc->FFonts[name]->glyph->metrics.horiBearingX)) / fo->uniEM * (Siz / 10.0); |
221 | Franz | 856 | ww = doc->FFonts[name]->glyph->metrics.horiAdvance / fo->uniEM * (Siz / 10.0); |
857 | return QMAX(ww, w); |
||
220 | Franz | 858 | } |
859 | else |
||
860 | return static_cast<double>(Siz / 10.0); |
||
861 | } |
||
862 | |||
80 | Franz | 863 | QPointArray RegularPolygon(double w, double h, uint c, bool star, double factor, double rota) |
8 | paul | 864 | { |
167 | Franz | 865 | uint cx = star ? c * 2 : c; |
80 | Franz | 866 | double seg = 360.0 / cx; |
867 | double sc = rota + 180.0; |
||
868 | double di = factor; |
||
8 | paul | 869 | int mx = 0; |
870 | int my = 0; |
||
871 | QPointArray pts = QPointArray(); |
||
872 | for (uint x = 0; x < cx; ++x) |
||
167 | Franz | 873 | { |
8 | paul | 874 | sc = seg * x + 180.0 + rota; |
875 | if (star) |
||
167 | Franz | 876 | { |
877 | double wf = x % 2 == 0 ? w / 2 : w / 2 * di; |
||
878 | double hf = x % 2 == 0 ? h / 2 : h / 2 * di; |
||
879 | mx = qRound(sin(sc / 180 * M_PI) * (wf) + (w/2)); |
||
880 | my = qRound(cos(sc / 180 * M_PI) * (hf) + (h/2)); |
||
881 | } |
||
8 | paul | 882 | else |
167 | Franz | 883 | { |
8 | paul | 884 | mx = qRound(sin(sc / 180 * M_PI) * (w/2) + (w/2)); |
885 | my = qRound(cos(sc / 180 * M_PI) * (h/2) + (h/2)); |
||
167 | Franz | 886 | } |
8 | paul | 887 | pts.resize(x+1); |
888 | pts.setPoint(x, mx, my); |
||
167 | Franz | 889 | } |
8 | paul | 890 | return pts; |
891 | } |
||
892 | |||
80 | Franz | 893 | FPointArray RegularPolygonF(double w, double h, uint c, bool star, double factor, double rota) |
8 | paul | 894 | { |
167 | Franz | 895 | uint cx = star ? c * 2 : c; |
80 | Franz | 896 | double seg = 360.0 / cx; |
897 | double sc = rota + 180.0; |
||
898 | double di = factor; |
||
899 | double mx = 0; |
||
900 | double my = 0; |
||
8 | paul | 901 | FPointArray pts = FPointArray(); |
902 | for (uint x = 0; x < cx; ++x) |
||
167 | Franz | 903 | { |
8 | paul | 904 | sc = seg * x + 180.0 + rota; |
905 | if (star) |
||
167 | Franz | 906 | { |
907 | double wf = x % 2 == 0 ? w / 2 : w / 2 * di; |
||
908 | double hf = x % 2 == 0 ? h / 2 : h / 2 * di; |
||
909 | mx = qRound(sin(sc / 180 * M_PI) * (wf) + (w/2)); |
||
910 | my = qRound(cos(sc / 180 * M_PI) * (hf) + (h/2)); |
||
911 | } |
||
8 | paul | 912 | else |
167 | Franz | 913 | { |
8 | paul | 914 | mx = sin(sc / 180 * M_PI) * (w/2) + (w/2); |
915 | my = cos(sc / 180 * M_PI) * (h/2) + (h/2); |
||
167 | Franz | 916 | } |
8 | paul | 917 | pts.resize(x+1); |
918 | pts.setPoint(x, mx, my); |
||
167 | Franz | 919 | } |
8 | paul | 920 | return pts; |
921 | } |
||
922 | |||
923 | QPointArray FlattenPath(FPointArray ina, QValueList<uint> &Segs) |
||
924 | { |
||
925 | QPointArray Bez(4); |
||
926 | QPointArray outa, cli; |
||
927 | Segs.clear(); |
||
928 | if (ina.size() > 3) |
||
167 | Franz | 929 | { |
930 | for (uint poi=0; poi<ina.size()-3; poi += 4) |
||
8 | paul | 931 | { |
167 | Franz | 932 | if (ina.point(poi).x() > 900000) |
8 | paul | 933 | { |
934 | outa.resize(outa.size()+1); |
||
935 | outa.setPoint(outa.size()-1, cli.point(cli.size()-1)); |
||
80 | Franz | 936 | Segs.append(outa.size()); |
8 | paul | 937 | continue; |
167 | Franz | 938 | } |
8 | paul | 939 | BezierPoints(&Bez, ina.pointQ(poi), ina.pointQ(poi+1), ina.pointQ(poi+3), ina.pointQ(poi+2)); |
940 | cli = Bez.cubicBezier(); |
||
941 | outa.putPoints(outa.size(), cli.size()-1, cli); |
||
167 | Franz | 942 | } |
8 | paul | 943 | outa.resize(outa.size()+1); |
944 | outa.setPoint(outa.size()-1, cli.point(cli.size()-1)); |
||
167 | Franz | 945 | } |
8 | paul | 946 | return outa; |
947 | } |
||
948 | |||
80 | Franz | 949 | double xy2Deg(double x, double y) |
8 | paul | 950 | { |
951 | return (atan2(y,x)*(180.0/M_PI)); |
||
952 | } |
||
953 | |||
954 | void BezierPoints(QPointArray *ar, QPoint n1, QPoint n2, QPoint n3, QPoint n4) |
||
955 | { |
||
956 | ar->setPoint(0, n1); |
||
957 | ar->setPoint(1, n2); |
||
958 | ar->setPoint(2, n3); |
||
959 | ar->setPoint(3, n4); |
||
960 | return; |
||
961 | } |
||
962 | |||
963 | void Level2Layer(ScribusDoc *doc, struct Layer *ll, int Level) |
||
964 | { |
||
965 | for (uint la2 = 0; la2 < doc->Layers.count(); ++la2) |
||
167 | Franz | 966 | { |
967 | if (doc->Layers[la2].Level == Level) |
||
8 | paul | 968 | { |
969 | ll->Sichtbar = doc->Layers[la2].Sichtbar; |
||
970 | ll->Drucken = doc->Layers[la2].Drucken; |
||
971 | ll->LNr = doc->Layers[la2].LNr; |
||
972 | break; |
||
973 | } |
||
167 | Franz | 974 | } |
8 | paul | 975 | } |
976 | |||
977 | QString ImageToTxt(QImage *im) |
||
978 | { |
||
979 | int h = im->height(); |
||
980 | int w = im->width(); |
||
981 | QString ImgStr = ""; |
||
982 | for( int yi=0; yi < h; ++yi ) |
||
167 | Franz | 983 | { |
8 | paul | 984 | QRgb * s = (QRgb*)(im->scanLine( yi )); |
985 | for( int xi=0; xi < w; ++xi ) |
||
167 | Franz | 986 | { |
8 | paul | 987 | QRgb r=*s++; |
988 | unsigned char u=qRed(r); |
||
989 | ImgStr += u; |
||
990 | u=qGreen(r); |
||
991 | ImgStr += u; |
||
992 | u=qBlue(r); |
||
993 | ImgStr += u; |
||
994 | } |
||
167 | Franz | 995 | } |
8 | paul | 996 | return ImgStr; |
997 | } |
||
998 | |||
999 | QString ImageToCMYK(QImage *im) |
||
1000 | { |
||
1001 | int h = im->height(); |
||
1002 | int w = im->width(); |
||
1003 | QString ImgStr = ""; |
||
1004 | for( int yi=0; yi < h; ++yi ) |
||
167 | Franz | 1005 | { |
8 | paul | 1006 | QRgb * s = (QRgb*)(im->scanLine( yi )); |
1007 | for( int xi=0; xi < w; ++xi ) |
||
167 | Franz | 1008 | { |
201 | Franz | 1009 | QRgb r=*s; |
8 | paul | 1010 | int c = 255 - qRed(r); |
1011 | int m = 255 - qGreen(r); |
||
1012 | int y = 255 - qBlue(r); |
||
1013 | int k = QMIN(QMIN(c, m), y); |
||
201 | Franz | 1014 | *s = qRgba(m - k, y - k, k, c - k); |
8 | paul | 1015 | ImgStr += c - k; |
1016 | ImgStr += m - k; |
||
1017 | ImgStr += y - k; |
||
1018 | ImgStr += k; |
||
201 | Franz | 1019 | s++; |
8 | paul | 1020 | } |
167 | Franz | 1021 | } |
8 | paul | 1022 | return ImgStr; |
1023 | } |
||
1024 | |||
1025 | QString ImageToCMYK_PS(QImage *im, int pl, bool pre) |
||
1026 | { |
||
1027 | int h = im->height(); |
||
1028 | int w = im->width(); |
||
1029 | QString ImgStr = ""; |
||
1030 | if (pre) |
||
167 | Franz | 1031 | { |
1032 | for( int yi=0; yi < h; ++yi ) |
||
8 | paul | 1033 | { |
1034 | QRgb * s = (QRgb*)(im->scanLine( yi )); |
||
1035 | for( int xi=0; xi < w; ++xi ) |
||
167 | Franz | 1036 | { |
8 | paul | 1037 | QRgb r=*s++; |
1038 | int c = qRed(r); |
||
1039 | int m = qGreen(r); |
||
1040 | int y = qBlue(r); |
||
1041 | int k = qAlpha(r); |
||
1042 | if (pl == -1) |
||
167 | Franz | 1043 | { |
8 | paul | 1044 | ImgStr += c; |
1045 | ImgStr += m; |
||
1046 | ImgStr += y; |
||
1047 | ImgStr += k; |
||
167 | Franz | 1048 | } |
8 | paul | 1049 | else |
167 | Franz | 1050 | { |
8 | paul | 1051 | if (pl == -2) |
1052 | ImgStr += QMIN(255, qRound(0.3 * c + 0.59 * m + 0.11 * y + k)); |
||
1053 | if (pl == 1) |
||
1054 | ImgStr += c; |
||
1055 | if (pl == 2) |
||
1056 | ImgStr += m; |
||
1057 | if (pl == 3) |
||
1058 | ImgStr += y; |
||
1059 | if (pl == 0) |
||
1060 | ImgStr += k; |
||
1061 | } |
||
1062 | } |
||
1063 | } |
||
167 | Franz | 1064 | } |
8 | paul | 1065 | else |
167 | Franz | 1066 | { |
1067 | for( int yi=0; yi < h; ++yi ) |
||
8 | paul | 1068 | { |
1069 | QRgb * s = (QRgb*)(im->scanLine( yi )); |
||
1070 | for( int xi=0; xi < w; ++xi ) |
||
167 | Franz | 1071 | { |
8 | paul | 1072 | QRgb r=*s++; |
1073 | int c = 255 - qRed(r); |
||
1074 | int m = 255 - qGreen(r); |
||
1075 | int y = 255 - qBlue(r); |
||
1076 | int k = QMIN(QMIN(c, m), y); |
||
1077 | if (pl == -1) |
||
167 | Franz | 1078 | { |
8 | paul | 1079 | ImgStr += c - k; |
1080 | ImgStr += m - k; |
||
1081 | ImgStr += y - k; |
||
1082 | ImgStr += k; |
||
167 | Franz | 1083 | } |
8 | paul | 1084 | else |
167 | Franz | 1085 | { |
8 | paul | 1086 | if (pl == -2) |
1087 | ImgStr += QMIN(255, qRound(0.3 * c + 0.59 * m + 0.11 * y + k)); |
||
1088 | if (pl == 1) |
||
1089 | ImgStr += c - k; |
||
1090 | if (pl == 2) |
||
1091 | ImgStr += m - k; |
||
1092 | if (pl == 3) |
||
1093 | ImgStr += y - k; |
||
1094 | if (pl == 0) |
||
1095 | ImgStr += k; |
||
1096 | } |
||
1097 | } |
||
1098 | } |
||
167 | Franz | 1099 | } |
8 | paul | 1100 | return ImgStr; |
1101 | } |
||
1102 | |||
1103 | QString MaskToTxt(QImage *im, bool PDF) |
||
1104 | { |
||
1105 | int h = im->height(); |
||
1106 | int w = im->width(); |
||
167 | Franz | 1107 | int w2; |
1108 | w2 = w / 8; |
||
1109 | if ((w % 8) != 0) |
||
1110 | w2++; |
||
8 | paul | 1111 | QString ImgStr = ""; |
1112 | for( int yi=0; yi < h; ++yi ) |
||
167 | Franz | 1113 | { |
8 | paul | 1114 | uchar * s = im->scanLine( yi ); |
1115 | for( int xi=0; xi < w2; ++xi ) |
||
167 | Franz | 1116 | { |
8 | paul | 1117 | unsigned char u = *(s+xi); |
167 | Franz | 1118 | ImgStr += PDF ? ~u : u; |
8 | paul | 1119 | } |
167 | Franz | 1120 | } |
8 | paul | 1121 | return ImgStr; |
1122 | } |
||
1123 | |||
203 | Franz | 1124 | QString MaskToTxt14(QImage *im) |
1125 | { |
||
1126 | int h = im->height(); |
||
1127 | int w = im->width(); |
||
1128 | QString ImgStr = ""; |
||
1129 | for( int yi=0; yi < h; ++yi ) |
||
1130 | { |
||
1131 | QRgb * s = (QRgb*)(im->scanLine( yi )); |
||
1132 | for( int xi=0; xi < w; ++xi ) |
||
1133 | { |
||
1134 | QRgb r=*s++; |
||
1135 | unsigned char u=qAlpha(r); |
||
1136 | ImgStr += u; |
||
1137 | } |
||
1138 | } |
||
1139 | return ImgStr; |
||
1140 | } |
||
1141 | |||
201 | Franz | 1142 | typedef struct my_error_mgr |
1143 | { |
||
1144 | struct jpeg_error_mgr pub; /* "public" fields */ |
||
1145 | jmp_buf setjmp_buffer; /* for return to caller */ |
||
1146 | } *my_error_ptr; |
||
1147 | |||
1148 | /* |
||
1149 | * Here's the routine that will replace the standard error_exit method: |
||
1150 | */ |
||
1151 | |||
1152 | static void my_error_exit (j_common_ptr cinfo) |
||
1153 | { |
||
1154 | my_error_ptr myerr = (my_error_ptr) cinfo->err; |
||
1155 | (*cinfo->err->output_message) (cinfo); |
||
1156 | longjmp (myerr->setjmp_buffer, 1); |
||
1157 | } |
||
1158 | |||
202 | Franz | 1159 | void Convert2JPG(QString fn, QImage *image, int Quality, bool isCMYK) |
201 | Franz | 1160 | { |
1161 | struct jpeg_compress_struct cinfo; |
||
1162 | struct my_error_mgr jerr; |
||
1163 | FILE *outfile; |
||
1164 | JSAMPROW row_pointer[1]; |
||
1165 | row_pointer[0] = 0; |
||
1166 | cinfo.err = jpeg_std_error (&jerr.pub); |
||
1167 | jerr.pub.error_exit = my_error_exit; |
||
1168 | outfile = NULL; |
||
1169 | if (setjmp (jerr.setjmp_buffer)) |
||
1170 | { |
||
1171 | jpeg_destroy_compress (&cinfo); |
||
1172 | if (outfile) |
||
1173 | fclose (outfile); |
||
1174 | return; |
||
1175 | } |
||
1176 | jpeg_create_compress (&cinfo); |
||
1177 | if ((outfile = fopen (fn, "wb")) == NULL) |
||
1178 | return; |
||
1179 | jpeg_stdio_dest (&cinfo, outfile); |
||
1180 | cinfo.image_width = image->width(); |
||
1181 | cinfo.image_height = image->height(); |
||
1182 | if (isCMYK) |
||
1183 | { |
||
1184 | cinfo.in_color_space = JCS_CMYK; |
||
1185 | cinfo.input_components = 4; |
||
1186 | } |
||
1187 | else |
||
1188 | { |
||
1189 | cinfo.in_color_space = JCS_RGB; |
||
1190 | cinfo.input_components = 3; |
||
1191 | } |
||
1192 | jpeg_set_defaults (&cinfo); |
||
202 | Franz | 1193 | int qual[] = { 95, 85, 75, 50, 25 }; // These are the JPEG Quality settings 100 means best, 0 .. don't discuss |
1194 | jpeg_set_quality (&cinfo, qual[Quality], true); |
||
201 | Franz | 1195 | jpeg_start_compress (&cinfo, TRUE); |
1196 | row_pointer[0] = new uchar[cinfo.image_width*cinfo.input_components]; |
||
1197 | int w = cinfo.image_width; |
||
1198 | while (cinfo.next_scanline < cinfo.image_height) |
||
1199 | { |
||
1200 | uchar *row = row_pointer[0]; |
||
1201 | if (isCMYK) |
||
1202 | { |
||
1203 | QRgb* rgba = (QRgb*)image->scanLine(cinfo.next_scanline); |
||
1204 | for (int i=0; i<w; ++i) |
||
1205 | { |
||
1206 | *row++ = qAlpha(*rgba); |
||
1207 | *row++ = qRed(*rgba); |
||
1208 | *row++ = qGreen(*rgba); |
||
1209 | *row++ = qBlue(*rgba); |
||
1210 | ++rgba; |
||
1211 | } |
||
1212 | } |
||
1213 | else |
||
1214 | { |
||
1215 | QRgb* rgb = (QRgb*)image->scanLine(cinfo.next_scanline); |
||
1216 | for (int i=0; i<w; i++) |
||
1217 | { |
||
1218 | *row++ = qRed(*rgb); |
||
1219 | *row++ = qGreen(*rgb); |
||
1220 | *row++ = qBlue(*rgb); |
||
1221 | ++rgb; |
||
1222 | } |
||
1223 | } |
||
1224 | jpeg_write_scanlines (&cinfo, row_pointer, 1); |
||
1225 | } |
||
1226 | jpeg_finish_compress (&cinfo); |
||
1227 | fclose (outfile); |
||
1228 | jpeg_destroy_compress (&cinfo); |
||
1229 | delete [] row_pointer[0]; |
||
1230 | } |
||
1231 | |||
8 | paul | 1232 | QString CompressStr(QString *in) |
1233 | { |
||
1234 | QString out = ""; |
||
1235 | #ifdef HAVE_LIBZ |
||
1236 | QByteArray bb(in->length()); |
||
1237 | for (uint ax = 0; ax < in->length(); ++ax) |
||
1238 | bb[ax] = uchar(QChar(in->at(ax))); |
||
1239 | uLong exlen = uint(bb.size() * 0.001 + 16) + bb.size(); |
||
1240 | QByteArray bc(exlen); |
||
1241 | compress2((Byte *)bc.data(), &exlen, (Byte *)bb.data(), uLong(bb.size()), 9); |
||
1242 | for (uint cl = 0; cl < exlen; ++cl) |
||
1243 | out += bc[cl]; |
||
1244 | #else |
||
1245 | out = *in; |
||
1246 | #endif |
||
1247 | return out; |
||
1248 | } |
||
1249 | |||
1250 | char *toHex( uchar u ) |
||
1251 | { |
||
1252 | static char hexVal[3]; |
||
1253 | int i = 1; |
||
1254 | while ( i >= 0 ) |
||
167 | Franz | 1255 | { |
1256 | ushort hex = (u & 0x000f); |
||
1257 | if ( hex < 0x0a ) |
||
8 | paul | 1258 | hexVal[i] = '0'+hex; |
167 | Franz | 1259 | else |
8 | paul | 1260 | hexVal[i] = 'A'+(hex-0x0a); |
167 | Franz | 1261 | u = u >> 4; |
8 | paul | 1262 | i--; |
167 | Franz | 1263 | } |
8 | paul | 1264 | hexVal[2] = '\0'; |
1265 | return hexVal; |
||
1266 | } |
||
1267 | |||
1268 | QString String2Hex(QString *in, bool lang) |
||
1269 | { |
||
1270 | int i = 0; |
||
1271 | QString out = ""; |
||
1272 | for( uint xi = 0; xi < in->length(); ++xi ) |
||
167 | Franz | 1273 | { |
8 | paul | 1274 | out += toHex(uchar(QChar(in->at(xi)))); |
1275 | ++i; |
||
1276 | if ((i>40) && (lang)) |
||
167 | Franz | 1277 | { |
8 | paul | 1278 | out += '\n'; |
1279 | i=0; |
||
1280 | } |
||
167 | Franz | 1281 | } |
8 | paul | 1282 | return out; |
1283 | } |
||
1284 | |||
1285 | QByteArray ComputeMD5Sum(QByteArray *in) |
||
1286 | { |
||
1287 | QByteArray MDsum(16); |
||
49 | paul | 1288 | md5_buffer (in->data(), in->size(), reinterpret_cast<void*>(MDsum.data())); |
8 | paul | 1289 | return MDsum; |
1290 | } |
||
1291 | |||
19 | Franz | 1292 | QString Path2Relative(QString Path) |
1293 | { |
||
1294 | QString Ndir = ""; |
||
1295 | QStringList Pdir = QStringList::split("/", QDir::currentDirPath()); |
||
1296 | QFileInfo Bfi = QFileInfo(Path); |
||
1297 | QStringList Bdir = QStringList::split("/", Bfi.dirPath(true)); |
||
1298 | bool ende = true; |
||
1299 | uint dcoun = 0; |
||
1300 | uint dcoun2 = 0; |
||
1301 | while (ende) |
||
167 | Franz | 1302 | { |
19 | Franz | 1303 | if (Pdir[dcoun] == Bdir[dcoun]) |
1304 | dcoun++; |
||
1305 | else |
||
1306 | break; |
||
1307 | if (dcoun > Pdir.count()) |
||
1308 | break; |
||
167 | Franz | 1309 | } |
19 | Franz | 1310 | dcoun2 = dcoun; |
1311 | for (uint ddx2 = dcoun; ddx2 < Pdir.count(); ddx2++) |
||
1312 | Ndir += "../"; |
||
1313 | for (uint ddx = dcoun2; ddx < Bdir.count(); ddx++) |
||
1314 | Ndir += Bdir[ddx]+"/"; |
||
1315 | Ndir += Bfi.fileName(); |
||
1316 | return Ndir; |
||
1317 | } |
||
1318 | |||
895 | fschmid | 1319 | void setBestEncoding(FT_Face face) |
8 | paul | 1320 | { |
1321 | FT_ULong charcode; |
||
895 | fschmid | 1322 | FT_UInt gindex; |
875 | fschmid | 1323 | bool foundEncoding = false; |
895 | fschmid | 1324 | int countUniCode = 0; |
1325 | int chmapUniCode = 0; |
||
1326 | int chmapCustom = 0; |
||
1327 | FT_CharMap defaultEncoding = face->charmap; |
||
391 | Franz | 1328 | for(int u = 0; u < face->num_charmaps; u++) |
1329 | { |
||
895 | fschmid | 1330 | if (face->charmaps[u]->encoding == FT_ENCODING_UNICODE ) |
391 | Franz | 1331 | { |
895 | fschmid | 1332 | FT_Set_Charmap(face, face->charmaps[u]); |
1333 | chmapUniCode = u; |
||
1334 | gindex = 0; |
||
1335 | charcode = FT_Get_First_Char( face, &gindex ); |
||
1336 | while ( gindex != 0 ) |
||
875 | fschmid | 1337 | { |
895 | fschmid | 1338 | countUniCode++; |
1339 | charcode = FT_Get_Next_Char( face, charcode, &gindex ); |
||
875 | fschmid | 1340 | } |
1341 | } |
||
895 | fschmid | 1342 | if (face->charmaps[u]->encoding == FT_ENCODING_ADOBE_CUSTOM) |
875 | fschmid | 1343 | { |
895 | fschmid | 1344 | chmapCustom = u; |
1345 | foundEncoding = true; |
||
875 | fschmid | 1346 | } |
1064 | cbradney | 1347 | else if (face->charmaps[u]->encoding == FT_ENCODING_MS_SYMBOL) |
1348 | { |
||
1349 | chmapCustom = u; |
||
1350 | foundEncoding = true; |
||
1351 | } |
||
875 | fschmid | 1352 | } |
895 | fschmid | 1353 | if (countUniCode > 255) |
1354 | FT_Set_Charmap(face, face->charmaps[chmapUniCode]); |
||
1355 | else if (foundEncoding) |
||
1356 | FT_Set_Charmap(face, face->charmaps[chmapCustom]); |
||
1357 | else |
||
1358 | FT_Set_Charmap(face, defaultEncoding); |
||
1359 | } |
||
1360 | |||
1361 | bool GlyNames(QMap<uint, QString> *GList, QString Dat) |
||
1362 | { |
||
1363 | bool error; |
||
1364 | char *buf[50]; |
||
1365 | FT_Library library; |
||
1366 | FT_Face face; |
||
1367 | FT_ULong charcode; |
||
1368 | FT_UInt gindex; |
||
1369 | error = FT_Init_FreeType(&library); |
||
1370 | error = FT_New_Face(library, Dat, 0, &face); |
||
1371 | setBestEncoding(face); |
||
77 | Franz | 1372 | gindex = 0; |
167 | Franz | 1373 | charcode = FT_Get_First_Char(face, &gindex ); |
1374 | while (gindex != 0) |
||
1375 | { |
||
8 | paul | 1376 | FT_Get_Glyph_Name(face, gindex, buf, 50); |
49 | paul | 1377 | GList->insert(charcode, QString(reinterpret_cast<char*>(buf))); |
167 | Franz | 1378 | charcode = FT_Get_Next_Char(face, charcode, &gindex ); |
1379 | } |
||
8 | paul | 1380 | FT_Done_FreeType( library ); |
1381 | return true; |
||
1382 | } |
||
1383 | |||
1384 | bool GlyIndex(QMap<uint, PDFlib::GlNamInd> *GListInd, QString Dat) |
||
1385 | { |
||
1386 | struct PDFlib::GlNamInd gln; |
||
1387 | bool error; |
||
1388 | char *buf[50]; |
||
1389 | FT_Library library; |
||
1390 | FT_Face face; |
||
1391 | FT_ULong charcode; |
||
167 | Franz | 1392 | FT_UInt gindex; |
1393 | uint counter1 = 32; |
||
1394 | uint counter2 = 0; |
||
8 | paul | 1395 | error = FT_Init_FreeType(&library); |
1396 | error = FT_New_Face(library, Dat, 0, &face); |
||
895 | fschmid | 1397 | setBestEncoding(face); |
77 | Franz | 1398 | gindex = 0; |
167 | Franz | 1399 | charcode = FT_Get_First_Char(face, &gindex ); |
1400 | while (gindex != 0) |
||
1401 | { |
||
8 | paul | 1402 | FT_Get_Glyph_Name(face, gindex, buf, 50); |
1403 | gln.Code = counter1 + counter2; |
||
49 | paul | 1404 | gln.Name = "/"+QString(reinterpret_cast<char*>(buf)); |
8 | paul | 1405 | GListInd->insert(charcode, gln); |
167 | Franz | 1406 | charcode = FT_Get_Next_Char(face, charcode, &gindex ); |
1407 | counter1++; |
||
1408 | if (counter1 > 255) |
||
1409 | { |
||
8 | paul | 1410 | counter1 = 32; |
1411 | counter2 += 0x100; |
||
1412 | } |
||
167 | Franz | 1413 | } |
8 | paul | 1414 | FT_Done_FreeType( library ); |
1415 | return true; |
||
1416 | } |
||
1417 | |||
1418 | FPoint firstP; |
||
1419 | bool FirstM; |
||
1420 | |||
1421 | int traceMoveto( FT_Vector *to, FPointArray *composite ) |
||
1422 | { |
||
1423 | double tox = ( to->x / 64.0 ); |
||
1424 | double toy = ( to->y / 64.0 ); |
||
1425 | if (!FirstM) |
||
167 | Franz | 1426 | { |
68 | Franz | 1427 | composite->addPoint(firstP); |
1428 | composite->addPoint(firstP); |
||
1429 | composite->setMarker(); |
||
167 | Franz | 1430 | } |
8 | paul | 1431 | else |
1432 | FirstM = false; |
||
68 | Franz | 1433 | composite->addPoint(FPoint(tox, toy)); |
1434 | composite->addPoint(FPoint(tox, toy)); |
||
8 | paul | 1435 | firstP = FPoint(tox, toy); |
1436 | return 0; |
||
1437 | } |
||
1438 | |||
1439 | int traceLineto( FT_Vector *to, FPointArray *composite ) |
||
1440 | { |
||
1441 | double tox = ( to->x / 64.0 ); |
||
1442 | double toy = ( to->y / 64.0 ); |
||
120 | Franz | 1443 | if (composite->size() > 4) |
167 | Franz | 1444 | { |
120 | Franz | 1445 | FPoint b1 = composite->point(composite->size()-4); |
1446 | FPoint b2 = composite->point(composite->size()-3); |
||
1447 | FPoint b3 = composite->point(composite->size()-2); |
||
1448 | FPoint b4 = composite->point(composite->size()-1); |
||
1449 | FPoint n1 = FPoint(tox, toy); |
||
1450 | FPoint n2 = FPoint(tox, toy); |
||
1451 | FPoint n3 = FPoint(tox, toy); |
||
1452 | FPoint n4 = FPoint(tox, toy); |
||
1453 | if ((b1 == n1) && (b2 == n2) && (b3 == n3) && (b4 == n4)) |
||
1454 | return 0; |
||
167 | Franz | 1455 | } |
68 | Franz | 1456 | composite->addPoint(FPoint(tox, toy)); |
1457 | composite->addPoint(FPoint(tox, toy)); |
||
1458 | composite->addPoint(FPoint(tox, toy)); |
||
1459 | composite->addPoint(FPoint(tox, toy)); |
||
8 | paul | 1460 | return 0; |
1461 | } |
||
1462 | |||
1463 | int traceQuadraticBezier( FT_Vector *control, FT_Vector *to, FPointArray *composite ) |
||
1464 | { |
||
1465 | double x1 = ( control->x / 64.0 ); |
||
1466 | double y1 = ( control->y / 64.0 ); |
||
1467 | double x2 = ( to->x / 64.0 ); |
||
1468 | double y2 = ( to->y / 64.0 ); |
||
120 | Franz | 1469 | if (composite->size() > 4) |
167 | Franz | 1470 | { |
120 | Franz | 1471 | FPoint b1 = composite->point(composite->size()-4); |
1472 | FPoint b2 = composite->point(composite->size()-3); |
||
1473 | FPoint b3 = composite->point(composite->size()-2); |
||
1474 | FPoint b4 = composite->point(composite->size()-1); |
||
1475 | FPoint n1 = FPoint(x2, y2); |
||
1476 | FPoint n2 = FPoint(x1, y1); |
||
1477 | FPoint n3 = FPoint(x2, y2); |
||
1478 | FPoint n4 = FPoint(x2, y2); |
||
1479 | if ((b1 == n1) && (b2 == n2) && (b3 == n3) && (b4 == n4)) |
||
1480 | return 0; |
||
167 | Franz | 1481 | } |
68 | Franz | 1482 | composite->addPoint(FPoint(x2, y2)); |
1483 | composite->addPoint(FPoint(x1, y1)); |
||
1484 | composite->addPoint(FPoint(x2, y2)); |
||
1485 | composite->addPoint(FPoint(x2, y2)); |
||
8 | paul | 1486 | return 0; |
167 | Franz | 1487 | } |
8 | paul | 1488 | |
1489 | int traceCubicBezier( FT_Vector *p, FT_Vector *q, FT_Vector *to, FPointArray *composite ) |
||
1490 | { |
||
1491 | double x1 = ( p->x / 64.0 ); |
||
1492 | double y1 = ( p->y / 64.0 ); |
||
1493 | double x2 = ( q->x / 64.0 ); |
||
1494 | double y2 = ( q->y / 64.0 ); |
||
1495 | double x3 = ( to->x / 64.0 ); |
||
1496 | double y3 = ( to->y / 64.0 ); |
||
120 | Franz | 1497 | if (composite->size() > 4) |
167 | Franz | 1498 | { |
120 | Franz | 1499 | FPoint b1 = composite->point(composite->size()-4); |
1500 | FPoint b2 = composite->point(composite->size()-3); |
||
1501 | FPoint b3 = composite->point(composite->size()-2); |
||
1502 | FPoint b4 = composite->point(composite->size()-1); |
||
1503 | FPoint n1 = FPoint(x3, y3); |
||
1504 | FPoint n2 = FPoint(x2, y2); |
||
1505 | FPoint n3 = FPoint(x3, y3); |
||
1506 | FPoint n4 = FPoint(x3, y3); |
||
1507 | if ((b1 == n1) && (b2 == n2) && (b3 == n3) && (b4 == n4)) |
||
1508 | return 0; |
||
167 | Franz | 1509 | } |
8 | paul | 1510 | composite->setPoint(composite->size()-1, FPoint(x1, y1)); |
68 | Franz | 1511 | composite->addPoint(FPoint(x3, y3)); |
1512 | composite->addPoint(FPoint(x2, y2)); |
||
1513 | composite->addPoint(FPoint(x3, y3)); |
||
1514 | composite->addPoint(FPoint(x3, y3)); |
||
8 | paul | 1515 | return 0; |
1516 | } |
||
1517 | |||
1518 | FT_Outline_Funcs OutlineMethods = |
||
1519 | { |
||
1520 | (FT_Outline_MoveTo_Func) traceMoveto, |
||
1521 | (FT_Outline_LineTo_Func) traceLineto, |
||
1522 | (FT_Outline_ConicTo_Func) traceQuadraticBezier, |
||
1523 | (FT_Outline_CubicTo_Func) traceCubicBezier, |
||
1524 | 0, |
||
1525 | |||
1526 | }; |
||
1527 | |||
220 | Franz | 1528 | FPointArray traceChar(FT_Face face, uint chr, int chs, double *x, double *y, bool *err) |
8 | paul | 1529 | { |
220 | Franz | 1530 | bool error = false; |
8 | paul | 1531 | FT_UInt glyphIndex; |
1532 | FPointArray pts, pts2; |
||
1533 | pts.resize(0); |
||
220 | Franz | 1534 | pts2.resize(0); |
8 | paul | 1535 | firstP = FPoint(0,0); |
1536 | FirstM = true; |
||
220 | Franz | 1537 | error = FT_Set_Char_Size( face, 0, chs*64, 72, 72 ); |
1538 | if (error) |
||
1539 | { |
||
1540 | *err = error; |
||
1541 | return pts2; |
||
1542 | } |
||
8 | paul | 1543 | glyphIndex = FT_Get_Char_Index(face, chr); |
220 | Franz | 1544 | if (glyphIndex == 0) |
1545 | { |
||
1546 | *err = true; |
||
1547 | return pts2; |
||
1548 | } |
||
1549 | error = FT_Load_Glyph( face, glyphIndex, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP ); |
||
1550 | if (error) |
||
1551 | { |
||
1552 | *err = error; |
||
1553 | return pts2; |
||
1554 | } |
||
1555 | error = FT_Outline_Decompose(&face->glyph->outline, &OutlineMethods, reinterpret_cast<void*>(&pts)); |
||
1556 | if (error) |
||
1557 | { |
||
1558 | *err = error; |
||
1559 | return pts2; |
||
1560 | } |
||
87 | Franz | 1561 | *x = face->glyph->metrics.horiBearingX / 64.0; |
1562 | *y = face->glyph->metrics.horiBearingY / 64.0; |
||
8 | paul | 1563 | QWMatrix ma; |
1564 | ma.scale(1, -1); |
||
1565 | pts.map(ma); |
||
1566 | pts.translate(0, chs); |
||
1567 | pts2.putPoints(0, pts.size()-2, pts, 0); |
||
1568 | return pts2; |
||
1569 | } |
||
90 | Franz | 1570 | |
95 | Franz | 1571 | FPoint GetMaxClipF(FPointArray Clip) |
1572 | { |
||
1573 | FPoint np, rp; |
||
1574 | double mx = 0; |
||
1575 | double my = 0; |
||
1576 | for (uint c = 0; c < Clip.size(); ++c) |
||
167 | Franz | 1577 | { |
95 | Franz | 1578 | np = Clip.point(c); |
1579 | if (np.x() > 900000) |
||
1580 | continue; |
||
1581 | if (np.x() > mx) |
||
1582 | mx = np.x(); |
||
1583 | if (np.y() > my) |
||
1584 | my = np.y(); |
||
167 | Franz | 1585 | } |
95 | Franz | 1586 | rp = FPoint(mx, my); |
1587 | return rp; |
||
1588 | } |
||
1589 | |||
92 | Franz | 1590 | QPixmap FontSample(QString da, int s, QString ts, QColor back) |
1591 | { |
||
1592 | FT_Face face; |
||
1593 | FT_Library library; |
||
95 | Franz | 1594 | double x, y, ymax; |
92 | Franz | 1595 | bool error; |
1596 | int pen_x; |
||
95 | Franz | 1597 | FPoint gp; |
92 | Franz | 1598 | error = FT_Init_FreeType( &library ); |
1599 | error = FT_New_Face( library, da, 0, &face ); |
||
895 | fschmid | 1600 | setBestEncoding(face); |
92 | Franz | 1601 | double uniEM = static_cast<double>(face->units_per_EM); |
95 | Franz | 1602 | int h = qRound(face->height / uniEM) * s + 1; |
1603 | double a = static_cast<double>(face->descender) / uniEM * s + 1; |
||
92 | Franz | 1604 | int w = qRound((face->bbox.xMax - face->bbox.xMin) / uniEM) * s * (ts.length()+1); |
1605 | QPixmap pm(w, h); |
||
1606 | pm.fill(); |
||
1607 | pen_x = 0; |
||
95 | Franz | 1608 | ymax = 0.0; |
92 | Franz | 1609 | ScPainter *p = new ScPainter(&pm, pm.width(), pm.height()); |
1610 | p->setFillMode(1); |
||
1611 | p->setLineWidth(0.0); |
||
1612 | p->setBrush(back); |
||
1613 | p->drawRect(0.0, 0.0, static_cast<double>(w), static_cast<double>(h)); |
||
1614 | p->setBrush(Qt::black); |
||
167 | Franz | 1615 | for (uint n = 0; n < ts.length(); ++n) |
1616 | { |
||
92 | Franz | 1617 | uint dv = ts[n].unicode(); |
221 | Franz | 1618 | error = false; |
220 | Franz | 1619 | FPointArray gly = traceChar(face, dv, s, &x, &y, &error); |
221 | Franz | 1620 | if (error) |
1621 | break; |
||
92 | Franz | 1622 | if (gly.size() > 3) |
167 | Franz | 1623 | { |
92 | Franz | 1624 | gly.translate(static_cast<double>(pen_x) / 64.0, a); |
95 | Franz | 1625 | gp = GetMaxClipF(gly); |
1626 | ymax = QMAX(ymax, gp.y()); |
||
92 | Franz | 1627 | p->setupPolygon(&gly); |
1628 | p->fillPath(); |
||
167 | Franz | 1629 | } |
92 | Franz | 1630 | pen_x += face->glyph->advance.x; |
167 | Franz | 1631 | } |
92 | Franz | 1632 | p->end(); |
95 | Franz | 1633 | pm.resize(QMIN(qRound(gp.x()), w), QMIN(qRound(ymax), h)); |
92 | Franz | 1634 | delete p; |
1635 | FT_Done_FreeType( library ); |
||
1636 | return pm; |
||
1637 | } |
||
1638 | |||
418 | Franz | 1639 | /** Same as FontSample() with \n strings support added. |
1640 | 09/26/2004 petr vanek |
||
1641 | */ |
||
1642 | QPixmap fontSamples(QString da, int s, QString ts, QColor back) |
||
1643 | { |
||
1644 | QStringList lines = QStringList::split("\n", ts); |
||
1645 | QPixmap ret(640, 480); |
||
1646 | QPixmap sample; |
||
1647 | QPainter *painter = new QPainter(&ret); |
||
1648 | int y = 0; |
||
1649 | int x = 0; |
||
1650 | ret.fill(back); |
||
1651 | for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ) { |
||
1652 | sample = FontSample(da, s, *it, back); |
||
1653 | painter->drawPixmap(0, y, sample, 0, 0); |
||
1654 | y = y + sample.height(); |
||
1655 | if (x < sample.width()) |
||
1656 | x = sample.width(); |
||
1657 | } // for |
||
1658 | delete(painter); |
||
1659 | QPixmap final(x, y); |
||
1660 | QPainter *fpainter = new QPainter(&final); |
||
1661 | fpainter->drawPixmap(0, 0, ret, 0, 0, x, y); |
||
1662 | delete(fpainter); |
||
1663 | return final; |
||
1664 | } |
||
1665 | |||
90 | Franz | 1666 | /*************************************************************************** |
1667 | begin : Wed Oct 29 2003 |
||
1668 | copyright : (C) 2003 The Scribus Team |
||
1669 | email : paul@all-the-johnsons.co.uk |
||
1670 | ***************************************************************************/ |
||
1671 | // check if the file exists, if it does, ask if they're sure |
||
1672 | // return true if they're sure, else return false; |
||
1673 | |||
1674 | bool overwrite(QWidget *parent, QString filename) |
||
1675 | { |
||
167 | Franz | 1676 | bool retval = true; |
1677 | QFileInfo fi(filename); |
||
1678 | if (fi.exists()) |
||
90 | Franz | 1679 | { |
167 | Franz | 1680 | int t = QMessageBox::warning(parent, QObject::tr("Warning"), |
1681 | QObject::tr("Do you really want to overwrite the File:\n%1 ?").arg(filename), |
||
1682 | QMessageBox::No, QMessageBox::Yes, QMessageBox::NoButton); |
||
1683 | if (t == QMessageBox::No) |
||
90 | Franz | 1684 | retval = false; |
1685 | } |
||
1686 | return retval; |
||
1687 | } |
||
124 | Franz | 1688 | |
1689 | void CopyPageItem(struct CLBuf *Buffer, PageItem *b) |
||
1690 | { |
||
1691 | uint a; |
||
1692 | Buffer->PType = b->PType; |
||
1693 | Buffer->Xpos = b->Xpos; |
||
1694 | Buffer->Ypos = b->Ypos; |
||
1695 | Buffer->Width = b->Width; |
||
1696 | Buffer->Height = b->Height; |
||
1697 | Buffer->RadRect = b->RadRect; |
||
1698 | Buffer->FrameType = b->FrameType; |
||
1699 | Buffer->ClipEdited = b->ClipEdited; |
||
1700 | Buffer->Pwidth = b->Pwidth; |
||
1701 | Buffer->Pcolor = b->Pcolor; |
||
1702 | Buffer->Pcolor2 = b->Pcolor2; |
||
1703 | Buffer->Shade = b->Shade; |
||
1704 | Buffer->Shade2 = b->Shade2; |
||
295 | Franz | 1705 | Buffer->GrColor = ""; |
1706 | Buffer->GrColor2 = ""; |
||
1707 | Buffer->GrShade = 100; |
||
1708 | Buffer->GrShade2 = 100; |
||
1709 | Buffer->fill_gradient = b->fill_gradient; |
||
124 | Franz | 1710 | Buffer->GrType = b->GrType; |
292 | Franz | 1711 | Buffer->GrStartX = b->GrStartX; |
1712 | Buffer->GrStartY = b->GrStartY; |
||
1713 | Buffer->GrEndX = b->GrEndX; |
||
1714 | Buffer->GrEndY = b->GrEndY; |
||
124 | Franz | 1715 | Buffer->TxtStroke = b->TxtStroke; |
1716 | Buffer->TxtFill = b->TxtFill; |
||
1717 | Buffer->ShTxtStroke = b->ShTxtStroke; |
||
1718 | Buffer->ShTxtFill = b->ShTxtFill; |
||
1719 | Buffer->TxtScale = b->TxtScale; |
||
1720 | Buffer->TxTStyle = b->TxTStyle; |
||
1721 | Buffer->Rot = b->Rot; |
||
1722 | Buffer->PLineArt = b->PLineArt; |
||
1723 | Buffer->PLineEnd = b->PLineEnd; |
||
1724 | Buffer->PLineJoin = b->PLineJoin; |
||
1725 | Buffer->LineSp = b->LineSp; |
||
1726 | Buffer->LocalScX = b->LocalScX; |
||
1727 | Buffer->LocalScY = b->LocalScY; |
||
1728 | Buffer->LocalX = b->LocalX; |
||
1729 | Buffer->LocalY = b->LocalY; |
||
1730 | Buffer->PicArt = b->PicArt; |
||
1731 | Buffer->flippedH = b->flippedH; |
||
1732 | Buffer->flippedV = b->flippedV; |
||
1733 | Buffer->BBoxX = b->BBoxX; |
||
1734 | Buffer->BBoxH = b->BBoxH; |
||
1735 | Buffer->isPrintable = b->isPrintable; |
||
1736 | Buffer->isBookmark = b->isBookmark; |
||
1737 | Buffer->BMnr = b->BMnr; |
||
1738 | Buffer->isAnnotation = b->isAnnotation; |
||
1739 | Buffer->AnType = b->AnType; |
||
1740 | Buffer->AnAction = b->AnAction; |
||
1741 | Buffer->An_E_act = b->An_E_act; |
||
1742 | Buffer->An_X_act = b->An_X_act; |
||
1743 | Buffer->An_D_act = b->An_D_act; |
||
1744 | Buffer->An_Fo_act = b->An_Fo_act; |
||
1745 | Buffer->An_Bl_act = b->An_Bl_act; |
||
1746 | Buffer->An_K_act = b->An_K_act; |
||
1747 | Buffer->An_F_act = b->An_F_act; |
||
1748 | Buffer->An_V_act = b->An_V_act; |
||
1749 | Buffer->An_C_act = b->An_C_act; |
||
1750 | Buffer->An_Extern = b->An_Extern; |
||
1751 | Buffer->AnZiel = b->AnZiel; |
||
1752 | Buffer->AnName = b->AnName; |
||
1753 | Buffer->AnActType = b->AnActType; |
||
1754 | Buffer->AnToolTip = b->AnToolTip; |
||
1755 | Buffer->AnBwid = b->AnBwid; |
||
1756 | Buffer->AnBsty = b->AnBsty; |
||
1757 | Buffer->AnFeed = b->AnFeed; |
||
1758 | Buffer->AnFlag = b->AnFlag; |
||
1759 | Buffer->AnFont = b->AnFont; |
||
1760 | Buffer->AnRollOver = b->AnRollOver; |
||
1761 | Buffer->AnDown = b->AnDown; |
||
1762 | Buffer->AnFormat = b->AnFormat; |
||
1763 | Buffer->AnVis = b->AnVis; |
||
1764 | Buffer->AnMaxChar = b->AnMaxChar; |
||
1765 | Buffer->AnChkStil = b->AnChkStil; |
||
1766 | Buffer->AnIsChk = b->AnIsChk; |
||
1767 | Buffer->AnAAact = b->AnAAact; |
||
1768 | Buffer->AnBColor = b->AnBColor; |
||
1769 | Buffer->AnHTML = b->AnHTML; |
||
1770 | Buffer->AnUseIcons = b->AnUseIcons; |
||
1771 | Buffer->AnIPlace = b->AnIPlace; |
||
1772 | Buffer->AnScaleW = b->AnScaleW; |
||
1773 | Buffer->Extra = b->Extra; |
||
1774 | Buffer->TExtra = b->TExtra; |
||
1775 | Buffer->BExtra = b->BExtra; |
||
1776 | Buffer->RExtra = b->RExtra; |
||
1777 | Buffer->Pfile = b->Pfile; |
||
1778 | Buffer->Pfile2 = b->Pfile2; |
||
1779 | Buffer->Pfile3 = b->Pfile3; |
||
1780 | QString Text = ""; |
||
1781 | if (b->Ptext.count() != 0) |
||
167 | Franz | 1782 | { |
1783 | for (a=0; a<b->Ptext.count(); ++a) |
||
124 | Franz | 1784 | { |
1785 | if( (b->Ptext.at(a)->ch == "\n") || (b->Ptext.at(a)->ch == "\r")) |
||
1786 | Text += QString(QChar(5))+"\t"; |
||
157 | Franz | 1787 | else if(b->Ptext.at(a)->ch == "\t") |
139 | Franz | 1788 | Text += QString(QChar(4))+"\t"; |
124 | Franz | 1789 | else |
1790 | Text += b->Ptext.at(a)->ch+"\t"; |
||
1791 | Text += b->Ptext.at(a)->cfont+"\t"; |
||
1792 | Text += QString::number(b->Ptext.at(a)->csize / 10.0)+"\t"; |
||
1793 | Text += b->Ptext.at(a)->ccolor+"\t"; |
||
1794 | Text += QString::number(b->Ptext.at(a)->cextra)+"\t"; |
||
1795 | Text += QString::number(b->Ptext.at(a)->cshade)+'\t'; |
||
1796 | Text += QString::number(b->Ptext.at(a)->cstyle)+'\t'; |
||
1797 | Text += QString::number(b->Ptext.at(a)->cab)+'\t'; |
||
1798 | Text += b->Ptext.at(a)->cstroke+"\t"; |
||
1799 | Text += QString::number(b->Ptext.at(a)->cshade2)+'\t'; |
||
1800 | Text += QString::number(b->Ptext.at(a)->cscale)+'\n'; |
||
1801 | } |
||
167 | Franz | 1802 | } |
124 | Franz | 1803 | Buffer->Ptext = Text; |
1804 | Buffer->Clip = b->Clip.copy(); |
||
1805 | Buffer->PoLine = b->PoLine.copy(); |
||
340 | Franz | 1806 | Buffer->ContourLine = b->ContourLine.copy(); |
1807 | Buffer->UseContour = b->UseContour; |
||
139 | Franz | 1808 | Buffer->TabValues = b->TabValues; |
1809 | Buffer->DashValues = b->DashValues; |
||
1810 | Buffer->DashOffset = b->DashOffset; |
||
124 | Franz | 1811 | Buffer->PoShow = b->PoShow; |
1812 | Buffer->BaseOffs = b->BaseOffs; |
||
1813 | Buffer->Textflow = b->Textflow; |
||
1814 | Buffer->Textflow2 = b->Textflow2; |
||
1815 | Buffer->Ausrich = b->Ausrich; |
||
1816 | Buffer->IFont = b->IFont; |
||
1817 | Buffer->ISize = b->ISize; |
||
1818 | Buffer->ExtraV = b->ExtraV; |
||
1819 | Buffer->Groups = b->Groups; |
||
1820 | Buffer->IProfile = b->IProfile; |
||
1821 | Buffer->IRender = b->IRender; |
||
1822 | Buffer->UseEmbedded = b->UseEmbedded; |
||
1823 | Buffer->EmProfile = b->EmProfile; |
||
1824 | Buffer->LayerNr = b->LayerNr; |
||
1825 | Buffer->ScaleType = b->ScaleType; |
||
1826 | Buffer->AspectRatio = b->AspectRatio; |
||
1827 | Buffer->Locked = b->Locked; |
||
205 | Franz | 1828 | Buffer->LockRes = b->LockRes; |
124 | Franz | 1829 | Buffer->Transparency = b->Transparency; |
1830 | Buffer->TranspStroke = b->TranspStroke; |
||
1831 | Buffer->Reverse = b->Reverse; |
||
1832 | Buffer->InvPict = b->InvPict; |
||
1833 | Buffer->NamedLStyle = b->NamedLStyle; |
||
1834 | Buffer->Language = b->Language; |
||
134 | Franz | 1835 | Buffer->Cols = b->Cols; |
135 | Franz | 1836 | Buffer->ColGap = b->ColGap; |
232 | Franz | 1837 | Buffer->isTableItem = b->isTableItem; |
1838 | Buffer->TopLine = b->TopLine; |
||
1839 | Buffer->LeftLine = b->LeftLine; |
||
1840 | Buffer->RightLine = b->RightLine; |
||
1841 | Buffer->BottomLine = b->BottomLine; |
||
234 | Franz | 1842 | if (b->isTableItem) |
1843 | { |
||
1844 | if (b->TopLink != 0) |
||
1845 | Buffer->TopLinkID = b->TopLink->ItemNr; |
||
1846 | else |
||
1847 | Buffer->TopLinkID = -1; |
||
1848 | if (b->LeftLink != 0) |
||
1849 | Buffer->LeftLinkID = b->LeftLink->ItemNr; |
||
1850 | else |
||
1851 | Buffer->LeftLinkID = -1; |
||
1852 | if (b->RightLink != 0) |
||
1853 | Buffer->RightLinkID = b->RightLink->ItemNr; |
||
1854 | else |
||
1855 | Buffer->RightLinkID = -1; |
||
1856 | if (b->BottomLink != 0) |
||
1857 | Buffer->BottomLinkID = b->BottomLink->ItemNr; |
||
1858 | else |
||
1859 | Buffer->BottomLinkID = -1; |
||
1860 | } |
||
124 | Franz | 1861 | } |
125 | Franz | 1862 | |
1863 | void WordAndPara(PageItem* b, int *w, int *p, int *c, int *wN, int *pN, int *cN) |
||
1864 | { |
||
1865 | QChar Dat = QChar(32); |
||
1866 | int para = 0; |
||
1867 | int ww = 0; |
||
1868 | int cc = 0; |
||
1869 | int paraN = 0; |
||
1870 | int wwN = 0; |
||
1871 | int ccN = 0; |
||
1872 | bool first = true; |
||
1873 | PageItem *nb = b; |
||
1874 | PageItem *nbl = b; |
||
1875 | while (nb != 0) |
||
167 | Franz | 1876 | { |
125 | Franz | 1877 | if (nb->BackBox != 0) |
1878 | nb = nb->BackBox; |
||
1879 | else |
||
1880 | break; |
||
167 | Franz | 1881 | } |
125 | Franz | 1882 | while (nb != 0) |
167 | Franz | 1883 | { |
1884 | for (uint a = 0; a < nb->Ptext.count(); ++a) |
||
125 | Franz | 1885 | { |
1886 | QChar b = nb->Ptext.at(a)->ch[0]; |
||
1887 | if (b == QChar(13)) |
||
167 | Franz | 1888 | { |
125 | Franz | 1889 | if (a >= nb->MaxChars) |
1890 | paraN++; |
||
1891 | else |
||
1892 | para++; |
||
167 | Franz | 1893 | } |
125 | Franz | 1894 | if ((!b.isLetterOrNumber()) && (Dat.isLetterOrNumber()) && (!first)) |
167 | Franz | 1895 | { |
125 | Franz | 1896 | if (a >= nb->MaxChars) |
1897 | wwN++; |
||
1898 | else |
||
1899 | ww++; |
||
167 | Franz | 1900 | } |
125 | Franz | 1901 | if (a >= nb->MaxChars) |
1902 | ccN++; |
||
1903 | else |
||
1904 | cc++; |
||
167 | Franz | 1905 | Dat = b; |
125 | Franz | 1906 | first = false; |
1907 | } |
||
1908 | nbl = nb; |
||
1909 | nb = nb->NextBox; |
||
167 | Franz | 1910 | } |
125 | Franz | 1911 | if (nbl->MaxChars < nbl->Ptext.count()) |
1912 | paraN++; |
||
1913 | else |
||
1914 | para++; |
||
1915 | if (Dat.isLetterOrNumber()) |
||
167 | Franz | 1916 | { |
125 | Franz | 1917 | if (nbl->MaxChars < nbl->Ptext.count()) |
1918 | wwN++; |
||
1919 | else |
||
1920 | ww++; |
||
167 | Franz | 1921 | } |
125 | Franz | 1922 | *w = ww; |
1923 | *p = para; |
||
1924 | *c = cc; |
||
1925 | *wN = wwN; |
||
1926 | *pN = paraN; |
||
1927 | *cN = ccN; |
||
1928 | } |
||
203 | Franz | 1929 | |
1930 | void ReOrderText(ScribusDoc *doc, ScribusView *view) |
||
1931 | { |
||
1932 | double savScale = doc->Scale; |
||
1933 | doc->Scale = 1.0; |
||
1934 | doc->RePos = true; |
||
1935 | QPixmap pgPix(10, 10); |
||
1936 | QRect rd = QRect(0,0,9,9); |
||
1937 | ScPainter *painter = new ScPainter(&pgPix, pgPix.width(), pgPix.height()); |
||
1938 | for (uint az=0; az<view->MasterPages.count(); az++) |
||
1939 | { |
||
1940 | for (uint azz=0; azz<view->MasterPages.at(az)->Items.count(); ++azz) |
||
1941 | { |
||
1942 | PageItem *ite = view->MasterPages.at(az)->Items.at(azz); |
||
313 | Franz | 1943 | if (ite->PType == 8) |
203 | Franz | 1944 | ite->DrawObj(painter, rd); |
1945 | } |
||
1946 | } |
||
1947 | for (uint az=0; az<view->Pages.count(); az++) |
||
1948 | { |
||
1949 | for (uint azz=0; azz<view->Pages.at(az)->Items.count(); ++azz) |
||
1950 | { |
||
1951 | PageItem *ite = view->Pages.at(az)->Items.at(azz); |
||
247 | Franz | 1952 | if ((ite->PType == 4) || (ite->PType == 8)) |
203 | Franz | 1953 | ite->DrawObj(painter, rd); |
1954 | } |
||
1955 | } |
||
1956 | doc->RePos = false; |
||
1957 | doc->Scale = savScale; |
||
1958 | delete painter; |
||
1959 | } |
||
447 | cbradney | 1960 | |
1961 | |||
1962 | /*! 10/06/2004 - pv |
||
1963 | \param QString s1 first string |
||
1964 | \param QString s2 second string |
||
1965 | \retval bool t/f related s1>s2 |
||
1966 | */ |
||
1967 | bool compareQStrings(QString s1, QString s2) |
||
1968 | { |
||
1969 | if (QString::localeAwareCompare(s1, s2) >= 0) |
||
1970 | return FALSE; |
||
1971 | return TRUE; |
||
1972 | } |
||
1973 | |||
1974 | /*! 10/06/2004 - pv |
||
1975 | Returns a sorted list of QStrings - sorted by locale specific |
||
1976 | rules! Uses compareQStrings() as rule. There is STL used! |
||
1977 | TODO: Maybe we can implement one cass for various sorting... |
||
1978 | \param QStringList aList unsorted string list |
||
1979 | \retval QStringList sorted string list |
||
1980 | */ |
||
1981 | QStringList sortQStringList(QStringList aList) |
||
1982 | { |
||
1983 | std::vector<QString> sortList; |
||
1984 | QStringList retList; |
||
1985 | QStringList::Iterator it; |
||
1986 | |||
1987 | for (it = aList.begin(); it != aList.end(); ++it) |
||
1988 | sortList.push_back(*it); |
||
1989 | std::sort(sortList.begin(), sortList.end(), compareQStrings); |
||
533 | fschmid | 1990 | for(uint i = 0; i < sortList.size(); i++) |
447 | cbradney | 1991 | retList.append(sortList[i]); |
1992 | return retList; |
||
1993 | } |