Rev 5362 | Rev 5372 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4430 | cbradney | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
3133 | fschmid | 7 | /*************************************************************************** |
8 | pdflib.cpp - description |
||
9 | ------------------- |
||
10 | begin : Sat Jan 19 2002 |
||
11 | copyright : (C) 2002 by Franz Schmid |
||
12 | email : Franz.Schmid@altmuehlnet.de |
||
13 | ***************************************************************************/ |
||
14 | |||
15 | /*************************************************************************** |
||
16 | * * |
||
17 | * This program is free software; you can redistribute it and/or modify * |
||
18 | * it under the terms of the GNU General Public License as published by * |
||
19 | * the Free Software Foundation; either version 2 of the License, or * |
||
20 | * (at your option) any later version. * |
||
21 | * * |
||
22 | ***************************************************************************/ |
||
23 | |||
24 | #include "pdflib.h" |
||
25 | #include "pdflib.moc" |
||
26 | |||
27 | #include "scconfig.h" |
||
28 | |||
4229 | craig | 29 | #include <string> |
3133 | fschmid | 30 | #include <qstring.h> |
31 | #include <qrect.h> |
||
32 | #include <qimage.h> |
||
33 | #include <qregexp.h> |
||
34 | #include <qdatetime.h> |
||
35 | #include <qfileinfo.h> |
||
36 | #include <qtextstream.h> |
||
37 | #include <qdir.h> |
||
38 | #include <cstdlib> |
||
39 | #include <cmath> |
||
40 | #ifdef HAVE_UNISTD_H |
||
41 | #include <unistd.h> |
||
42 | #endif |
||
43 | #include "rc4.h" |
||
44 | |||
4028 | cbradney | 45 | #include "commonstrings.h" |
3670 | cbradney | 46 | #include "page.h" |
3133 | fschmid | 47 | #include "pageitem.h" |
48 | #include "bookmwin.h" |
||
49 | #include "scribus.h" |
||
5243 | cbradney | 50 | #include "scribuscore.h" |
3699 | cbradney | 51 | #include "scribusdoc.h" |
4028 | cbradney | 52 | #include "multiprogressdialog.h" |
3133 | fschmid | 53 | #include "bookpalette.h" |
54 | #include "scfontmetrics.h" |
||
55 | #include "util.h" |
||
56 | #include "prefsmanager.h" |
||
3252 | craig | 57 | #include "prefscontext.h" |
3133 | fschmid | 58 | #include "pdfoptions.h" |
4007 | fschmid | 59 | #include "sccolor.h" |
3133 | fschmid | 60 | |
5184 | avox | 61 | #include "text/nlsconfig.h" |
62 | |||
3133 | fschmid | 63 | using namespace std; |
64 | |||
65 | #ifdef HAVE_CMS |
||
66 | extern bool CMSuse; |
||
67 | #endif |
||
68 | #ifdef HAVE_TIFF |
||
69 | #include <tiffio.h> |
||
70 | #endif |
||
71 | |||
4264 | craig | 72 | PDFlib::PDFlib(ScribusDoc & docu) |
73 | : QObject(&docu), |
||
4223 | craig | 74 | doc(docu), |
75 | ActPageP(0), |
||
4264 | craig | 76 | Options(doc.PDF_Options), |
4223 | craig | 77 | Bvie(0), |
78 | ObjCounter(7), |
||
79 | ResNam("RE"), |
||
80 | ResCount(0), |
||
81 | NDnam("LI"), |
||
82 | NDnum(0), |
||
83 | KeyGen(32), |
||
84 | OwnerKey(32), |
||
85 | UserKey(32), |
||
86 | FileID(16), |
||
87 | EncryKey(5), |
||
88 | Encrypt(0), |
||
89 | KeyLen(5), |
||
90 | colorsToUse(), |
||
91 | spotNam("Spot"), |
||
92 | spotCount(0), |
||
4225 | craig | 93 | progressDialog(0), |
4223 | craig | 94 | abortExport(false), |
5243 | cbradney | 95 | usingGUI(ScCore->usingGUI()) |
3133 | fschmid | 96 | { |
97 | Catalog.Outlines = 2; |
||
98 | Catalog.PageTree = 3; |
||
99 | Catalog.Dest = 4; |
||
100 | PageTree.Count = 0; |
||
101 | Outlines.First = 0; |
||
102 | Outlines.Last = 0; |
||
103 | Outlines.Count = 0; |
||
104 | Seite.ObjNum = 0; |
||
105 | Seite.Thumb = 0; |
||
106 | #ifdef HAVE_LIBZ |
||
107 | CompAvail = true; |
||
108 | #else |
||
109 | CompAvail = false; |
||
110 | #endif |
||
111 | int kg_array[] = {0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, |
||
112 | 0x01, 0x08, 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80, 0x2f, 0x0c, 0xa9, 0xfe, |
||
113 | 0x64, 0x53, 0x69, 0x7a}; |
||
114 | for (int a = 0; a < 32; ++a) |
||
115 | KeyGen[a] = kg_array[a]; |
||
4028 | cbradney | 116 | if (usingGUI) |
117 | { |
||
4223 | craig | 118 | progressDialog = new MultiProgressDialog(tr("Saving PDF"), CommonStrings::tr_Cancel, ScMW, "pdfexportprogress"); |
4224 | craig | 119 | Q_CHECK_PTR(progressDialog); |
120 | QStringList barNames, barTexts; |
||
121 | barNames << "EMP" << "EP" << "ECPI"; |
||
5370 | cbradney | 122 | barTexts << tr("Exporting Master Page:") << tr("Exporting Page:") << tr("Exporting Items on Current Page:"); |
123 | QValueList<bool> barsNumeric; |
||
124 | barsNumeric << true << true << false; |
||
125 | progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric); |
||
4224 | craig | 126 | connect(progressDialog->buttonCancel, SIGNAL(clicked()), this, SLOT(cancelRequested())); |
4028 | cbradney | 127 | } |
3133 | fschmid | 128 | } |
129 | |||
4224 | craig | 130 | PDFlib::~PDFlib() |
131 | { |
||
132 | delete progressDialog; |
||
133 | } |
||
134 | |||
4229 | craig | 135 | static inline QString FToStr(double c) |
136 | { |
||
137 | return QString::number(c, 'f', 5); |
||
138 | }; |
||
139 | |||
4264 | craig | 140 | bool PDFlib::doExport(const QString& fn, const QString& nam, int Components, |
141 | const std::vector<int> & pageNs, const QMap<int,QPixmap> & thumbs) |
||
3133 | fschmid | 142 | { |
143 | QPixmap pm; |
||
144 | bool ret = false; |
||
4028 | cbradney | 145 | int pc_exportpages=0; |
146 | int pc_exportmasterpages=0; |
||
4224 | craig | 147 | if (usingGUI) |
148 | progressDialog->show(); |
||
4264 | craig | 149 | if (PDF_Begin_Doc(fn, PrefsManager::instance()->appPrefs.AvailFonts, doc.UsedFonts, ScMW->bookmarkPalette->BView)) |
3133 | fschmid | 150 | { |
151 | QMap<int, int> pageNsMpa; |
||
152 | for (uint a = 0; a < pageNs.size(); ++a) |
||
153 | { |
||
4264 | craig | 154 | pageNsMpa.insert(doc.MasterNames[doc.Pages->at(pageNs[a]-1)->MPageNam], 0); |
3133 | fschmid | 155 | } |
4028 | cbradney | 156 | if (usingGUI) |
3133 | fschmid | 157 | { |
4028 | cbradney | 158 | progressDialog->setOverallTotalSteps(pageNsMpa.count()+pageNs.size()); |
159 | progressDialog->setTotalSteps("EMP", pageNsMpa.count()); |
||
160 | progressDialog->setTotalSteps("EP", pageNs.size()); |
||
161 | progressDialog->setOverallProgress(0); |
||
162 | progressDialog->setProgress("EMP", 0); |
||
163 | progressDialog->setProgress("EP", 0); |
||
164 | } |
||
4264 | craig | 165 | for (uint ap = 0; ap < doc.MasterPages.count() && !abortExport; ++ap) |
4028 | cbradney | 166 | { |
4264 | craig | 167 | if (doc.MasterItems.count() != 0) |
3133 | fschmid | 168 | { |
169 | if (pageNsMpa.contains(ap)) |
||
170 | { |
||
5243 | cbradney | 171 | qApp->processEvents(); |
4264 | craig | 172 | PDF_TemplatePage(doc.MasterPages.at(ap)); |
4028 | cbradney | 173 | ++pc_exportmasterpages; |
3133 | fschmid | 174 | } |
175 | } |
||
4546 | subik | 176 | |
177 | if (usingGUI) |
||
178 | { |
||
4028 | cbradney | 179 | progressDialog->setProgress("EMP", pc_exportmasterpages); |
180 | progressDialog->setOverallProgress(pc_exportmasterpages+pc_exportpages); |
||
181 | } |
||
3133 | fschmid | 182 | } |
4028 | cbradney | 183 | for (uint a = 0; a < pageNs.size() && !abortExport; ++a) |
3133 | fschmid | 184 | { |
4264 | craig | 185 | if (doc.PDF_Options.Thumbnails) |
3133 | fschmid | 186 | pm = thumbs[pageNs[a]]; |
5243 | cbradney | 187 | qApp->processEvents(); |
4028 | cbradney | 188 | if (abortExport) break; |
4264 | craig | 189 | PDF_Begin_Page(doc.Pages->at(pageNs[a]-1), pm); |
5243 | cbradney | 190 | qApp->processEvents(); |
4028 | cbradney | 191 | if (abortExport) break; |
4649 | fschmid | 192 | PDF_ProcessPage(doc.Pages->at(pageNs[a]-1), pageNs[a]-1, doc.PDF_Options.doClip); |
5243 | cbradney | 193 | qApp->processEvents(); |
4028 | cbradney | 194 | if (abortExport) break; |
3133 | fschmid | 195 | PDF_End_Page(); |
4028 | cbradney | 196 | pc_exportpages++; |
197 | if (usingGUI) |
||
198 | { |
||
199 | progressDialog->setProgress("EP", pc_exportpages); |
||
200 | progressDialog->setOverallProgress(pc_exportmasterpages+pc_exportpages); |
||
201 | } |
||
3133 | fschmid | 202 | } |
4028 | cbradney | 203 | ret = true;//Even when aborting we return true. Dont want that "couldnt write msg" |
204 | if (!abortExport) |
||
205 | { |
||
4264 | craig | 206 | if (doc.PDF_Options.Version == PDFOptions::PDFVersion_X3) |
5243 | cbradney | 207 | PDF_End_Doc(ScCore->PrinterProfiles[doc.PDF_Options.PrintProf], nam, Components); |
4028 | cbradney | 208 | else |
209 | PDF_End_Doc(); |
||
210 | } |
||
3133 | fschmid | 211 | else |
4028 | cbradney | 212 | closeAndCleanup(); |
3133 | fschmid | 213 | } |
4029 | cbradney | 214 | if (usingGUI) |
215 | progressDialog->close(); |
||
3133 | fschmid | 216 | return ret; |
217 | } |
||
218 | |||
219 | void PDFlib::StartObj(int nr) |
||
220 | { |
||
4229 | craig | 221 | XRef.append(bytesWritten()); |
222 | PutDoc(QString::number(nr)+ " 0 obj\n"); |
||
3133 | fschmid | 223 | } |
224 | |||
4229 | craig | 225 | // Encode a string for inclusion in a |
226 | // PDF (literal) . |
||
227 | QString PDFlib::PDFEncode(const QString & in) |
||
3133 | fschmid | 228 | { |
4229 | craig | 229 | QString tmp(""); |
3133 | fschmid | 230 | for (uint d = 0; d < in.length(); ++d) |
231 | { |
||
4229 | craig | 232 | QChar cc(in.at(d)); |
4230 | craig | 233 | if ((cc == '(') || (cc == ')') || (cc == '\\')) |
234 | tmp += '\\'; |
||
3133 | fschmid | 235 | tmp += cc; |
236 | } |
||
237 | return tmp; |
||
238 | } |
||
239 | |||
4229 | craig | 240 | QString PDFlib::EncStream(const QString & in, int ObjNum) |
3133 | fschmid | 241 | { |
4229 | craig | 242 | if (in.length() < 1) |
243 | return QString(""); |
||
4264 | craig | 244 | else if (!Options.Encrypt) |
4229 | craig | 245 | return in; |
246 | rc4_context_t rc4; |
||
3133 | fschmid | 247 | int dlen = 0; |
4229 | craig | 248 | QString tmp(in); |
249 | QByteArray us(tmp.length()); |
||
250 | QByteArray ou(tmp.length()); |
||
251 | for (uint a = 0; a < tmp.length(); ++a) |
||
252 | us[a] = uchar(QChar(tmp.at(a))); |
||
253 | QByteArray data(10); |
||
254 | if (KeyLen > 5) |
||
255 | data.resize(21); |
||
256 | for (int cd = 0; cd < KeyLen; ++cd) |
||
3133 | fschmid | 257 | { |
4229 | craig | 258 | data[cd] = EncryKey[cd]; |
259 | dlen++; |
||
3133 | fschmid | 260 | } |
4229 | craig | 261 | data[dlen++] = ObjNum; |
262 | data[dlen++] = ObjNum >> 8; |
||
263 | data[dlen++] = ObjNum >> 16; |
||
264 | data[dlen++] = 0; |
||
265 | data[dlen++] = 0; |
||
266 | QByteArray step1(16); |
||
267 | step1 = ComputeMD5Sum(&data); |
||
268 | rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), QMIN(KeyLen+5, 16)); |
||
269 | rc4_encrypt(&rc4, reinterpret_cast<uchar*>(us.data()), reinterpret_cast<uchar*>(ou.data()), tmp.length()); |
||
270 | QString uk = ""; |
||
271 | for (uint cl = 0; cl < tmp.length(); ++cl) |
||
272 | uk += QChar(ou[cl]); |
||
273 | return uk; |
||
3133 | fschmid | 274 | } |
275 | |||
5234 | fschmid | 276 | QByteArray PDFlib::EncStreamArray(const QByteArray & in, int ObjNum) |
277 | { |
||
278 | if (in.size() < 1) |
||
279 | return QByteArray(); |
||
280 | else if (!Options.Encrypt) |
||
281 | return in; |
||
282 | rc4_context_t rc4; |
||
283 | int dlen = 0; |
||
284 | QByteArray out(in.size()); |
||
285 | QByteArray data(10); |
||
286 | if (KeyLen > 5) |
||
287 | data.resize(21); |
||
288 | for (int cd = 0; cd < KeyLen; ++cd) |
||
289 | { |
||
290 | data[cd] = EncryKey[cd]; |
||
291 | dlen++; |
||
292 | } |
||
293 | data[dlen++] = ObjNum; |
||
294 | data[dlen++] = ObjNum >> 8; |
||
295 | data[dlen++] = ObjNum >> 16; |
||
296 | data[dlen++] = 0; |
||
297 | data[dlen++] = 0; |
||
298 | QByteArray step1(16); |
||
299 | step1 = ComputeMD5Sum(&data); |
||
300 | rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), QMIN(KeyLen+5, 16)); |
||
301 | rc4_encrypt(&rc4, reinterpret_cast<uchar*>(in.data()), reinterpret_cast<uchar*>(out.data()), in.size()); |
||
302 | return out; |
||
303 | } |
||
304 | |||
4229 | craig | 305 | QString PDFlib::EncString(const QString & in, int ObjNum) |
3133 | fschmid | 306 | { |
4264 | craig | 307 | if (!Options.Encrypt) |
4229 | craig | 308 | return in; |
309 | rc4_context_t rc4; |
||
3133 | fschmid | 310 | QString tmp; |
311 | int dlen = 0; |
||
4229 | craig | 312 | if (in.length() < 3) |
313 | return "<>"; |
||
314 | tmp = in.mid(1, in.length()-2); |
||
315 | QByteArray us(tmp.length()); |
||
316 | QByteArray ou(tmp.length()); |
||
317 | for (uint a = 0; a < tmp.length(); ++a) |
||
318 | us[a] = static_cast<uchar>(QChar(tmp.at(a))); |
||
319 | QByteArray data(10); |
||
320 | if (KeyLen > 5) |
||
321 | data.resize(21); |
||
322 | for (int cd = 0; cd < KeyLen; ++cd) |
||
3133 | fschmid | 323 | { |
4229 | craig | 324 | data[cd] = EncryKey[cd]; |
325 | dlen++; |
||
3133 | fschmid | 326 | } |
4229 | craig | 327 | data[dlen++] = ObjNum; |
328 | data[dlen++] = ObjNum >> 8; |
||
329 | data[dlen++] = ObjNum >> 16; |
||
330 | data[dlen++] = 0; |
||
331 | data[dlen++] = 0; |
||
332 | QByteArray step1(16); |
||
333 | step1 = ComputeMD5Sum(&data); |
||
334 | rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), QMIN(KeyLen+5, 16)); |
||
335 | rc4_encrypt(&rc4, reinterpret_cast<uchar*>(us.data()), reinterpret_cast<uchar*>(ou.data()), tmp.length()); |
||
336 | QString uk = ""; |
||
337 | for (uint cl = 0; cl < tmp.length(); ++cl) |
||
338 | uk += QChar(ou[cl]); |
||
339 | tmp = "<"+String2Hex(&uk, false)+">"; |
||
3133 | fschmid | 340 | return tmp; |
341 | } |
||
342 | |||
4229 | craig | 343 | QString PDFlib::FitKey(const QString & pass) |
3133 | fschmid | 344 | { |
4229 | craig | 345 | QString pw(pass); |
3133 | fschmid | 346 | if (pw.length() < 32) |
347 | { |
||
348 | uint l = pw.length(); |
||
349 | for (uint a = 0; a < 32 - l; ++a) |
||
350 | pw += QChar(KeyGen[a]); |
||
351 | } |
||
352 | else |
||
353 | pw = pw.left(32); |
||
354 | return pw; |
||
355 | } |
||
356 | |||
4229 | craig | 357 | void PDFlib::CalcOwnerKey(const QString & Owner, const QString & User) |
3133 | fschmid | 358 | { |
4229 | craig | 359 | rc4_context_t rc4; |
360 | QString pw(FitKey(User)); |
||
361 | QString pw2(FitKey(Owner.isEmpty() ? User : Owner)); |
||
3133 | fschmid | 362 | QByteArray step1(16); |
363 | step1 = ComputeMD5(pw2); |
||
364 | if (KeyLen > 5) |
||
365 | { |
||
366 | for (int kl = 0; kl < 50; ++kl) |
||
367 | step1 = ComputeMD5Sum(&step1); |
||
368 | } |
||
369 | QByteArray us(32); |
||
370 | QByteArray enk(16); |
||
371 | if (KeyLen > 5) |
||
372 | { |
||
373 | for (uint a2 = 0; a2 < 32; ++a2) |
||
374 | OwnerKey[a2] = static_cast<uchar>(QChar(pw.at(a2))); |
||
375 | for (int rl = 0; rl < 20; rl++) |
||
376 | { |
||
4229 | craig | 377 | for (int j = 0; j < 16; j ++) |
378 | enk[j] = step1[j] ^ rl; |
||
3133 | fschmid | 379 | rc4_init(&rc4, reinterpret_cast<uchar*>(enk.data()), 16); |
4229 | craig | 380 | rc4_encrypt(&rc4, reinterpret_cast<uchar*>(OwnerKey.data()), |
3133 | fschmid | 381 | reinterpret_cast<uchar*>(OwnerKey.data()), 32); |
382 | } |
||
383 | } |
||
384 | else |
||
385 | { |
||
386 | for (uint a = 0; a < 32; ++a) |
||
387 | us[a] = static_cast<uchar>(QChar(pw.at(a))); |
||
388 | rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), 5); |
||
4546 | subik | 389 | rc4_encrypt(&rc4, reinterpret_cast<uchar*>(us.data()), |
3133 | fschmid | 390 | reinterpret_cast<uchar*>(OwnerKey.data()), 32); |
391 | } |
||
392 | } |
||
393 | |||
4229 | craig | 394 | void PDFlib::CalcUserKey(const QString & User, int Permission) |
3133 | fschmid | 395 | { |
396 | rc4_context_t rc4; |
||
4229 | craig | 397 | QString pw(FitKey(User)); |
3133 | fschmid | 398 | QByteArray step1(16); |
399 | QByteArray perm(4); |
||
400 | uint perm_value = static_cast<uint>(Permission); |
||
401 | perm[0] = perm_value; |
||
402 | perm[1] = perm_value >> 8; |
||
403 | perm[2] = perm_value >> 16; |
||
404 | perm[3] = perm_value >> 24; |
||
405 | for (uint a = 0; a < 32; ++a) |
||
406 | pw += QChar(OwnerKey[a]); |
||
407 | for (uint a1 = 0; a1 < 4; ++a1) |
||
408 | pw += QChar(perm[a1]); |
||
409 | for (uint a3 = 0; a3 < 16; ++a3) |
||
410 | pw += QChar(FileID[a3]); |
||
411 | step1 = ComputeMD5(pw); |
||
412 | if (KeyLen > 5) |
||
413 | { |
||
414 | for (int kl = 0; kl < 50; ++kl) |
||
415 | step1 = ComputeMD5Sum(&step1); |
||
416 | EncryKey.resize(16); |
||
417 | } |
||
418 | for (int a2 = 0; a2 < KeyLen; ++a2) |
||
419 | EncryKey[a2] = step1[a2]; |
||
420 | if (KeyLen > 5) |
||
421 | { |
||
4229 | craig | 422 | QString pr2(""); |
3133 | fschmid | 423 | for (int kl3 = 0; kl3 < 32; ++kl3) |
424 | pr2 += QChar(KeyGen[kl3]); |
||
425 | for (uint a4 = 0; a4 < 16; ++a4) |
||
426 | pr2 += QChar(FileID[a4]); |
||
427 | step1 = ComputeMD5(pr2); |
||
428 | QByteArray enk(16); |
||
429 | for (uint a3 = 0; a3 < 16; ++a3) |
||
430 | UserKey[a3] = step1[a3]; |
||
431 | for (int rl = 0; rl < 20; rl++) |
||
432 | { |
||
4229 | craig | 433 | for (int j = 0; j < 16; j ++) |
434 | enk[j] = EncryKey[j] ^ rl; |
||
3133 | fschmid | 435 | rc4_init(&rc4, reinterpret_cast<uchar*>(enk.data()), 16); |
4229 | craig | 436 | rc4_encrypt(&rc4, reinterpret_cast<uchar*>(UserKey.data()), reinterpret_cast<uchar*>(UserKey.data()), 16); |
3133 | fschmid | 437 | } |
438 | } |
||
439 | else |
||
440 | { |
||
441 | rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), 5); |
||
4229 | craig | 442 | rc4_encrypt(&rc4, reinterpret_cast<uchar*>(KeyGen.data()), reinterpret_cast<uchar*>(UserKey.data()), 32); |
3133 | fschmid | 443 | } |
444 | } |
||
445 | |||
3829 | cbradney | 446 | QByteArray PDFlib::ComputeMD5(const QString& in) |
3133 | fschmid | 447 | { |
3829 | cbradney | 448 | uint inlen=in.length(); |
449 | QByteArray TBytes(inlen); |
||
450 | for (uint a = 0; a < inlen; ++a) |
||
3133 | fschmid | 451 | TBytes[a] = static_cast<uchar>(QChar(in.at(a))); |
452 | return ComputeMD5Sum(&TBytes); |
||
453 | } |
||
454 | |||
4264 | craig | 455 | bool PDFlib::PDF_Begin_Doc(const QString& fn, SCFonts &AllFonts, QMap<QString,int> DocFonts, BookMView* vi) |
3133 | fschmid | 456 | { |
4229 | craig | 457 | Spool.setName(fn); |
3133 | fschmid | 458 | if (!Spool.open(IO_WriteOnly)) |
459 | return false; |
||
4229 | craig | 460 | outStream.setDevice(&Spool); |
3133 | fschmid | 461 | QString tmp; |
462 | QString ok = ""; |
||
463 | QString uk = ""; |
||
464 | QFileInfo fd; |
||
465 | QString fext; |
||
466 | int a; |
||
467 | Bvie = vi; |
||
468 | BookMinUse = false; |
||
469 | UsedFontsP.clear(); |
||
4264 | craig | 470 | if ((Options.Version == 15) && (Options.useLayers)) |
3133 | fschmid | 471 | ObjCounter = 10; |
472 | else |
||
473 | ObjCounter = 9; |
||
4264 | craig | 474 | switch (Options.Version) |
3133 | fschmid | 475 | { |
476 | case 12: |
||
477 | case 13: |
||
4229 | craig | 478 | PutDoc("%PDF-1.3\n"); |
3133 | fschmid | 479 | break; |
480 | case 14: |
||
481 | PutDoc("%PDF-1.4\n"); |
||
482 | break; |
||
483 | case 15: |
||
484 | PutDoc("%PDF-1.5\n"); |
||
485 | break; |
||
486 | } |
||
4264 | craig | 487 | if (Options.Version == 12) |
3133 | fschmid | 488 | ObjCounter++; |
4229 | craig | 489 | PutDoc("%\xc7\xec\x8f\xa2\n"); |
3133 | fschmid | 490 | StartObj(1); |
491 | PutDoc("<<\n/Type /Catalog\n/Outlines 3 0 R\n/Pages 4 0 R\n/Dests 5 0 R\n/AcroForm 6 0 R\n/Names 7 0 R\n/Threads 8 0 R\n"); |
||
4264 | craig | 492 | if ((Options.Version == 15) && (Options.useLayers)) |
3133 | fschmid | 493 | PutDoc("/OCProperties 9 0 R\n"); |
4264 | craig | 494 | if (Options.Version == 12) |
4229 | craig | 495 | PutDoc("/OutputIntents [ "+QString::number(ObjCounter-1)+" 0 R ]\n"); |
4197 | fschmid | 496 | PutDoc("/PageLayout "); |
4264 | craig | 497 | switch (Options.PageLayout) |
3133 | fschmid | 498 | { |
4197 | fschmid | 499 | case PDFOptions::SinglePage: |
500 | PutDoc("/SinglePage\n"); |
||
501 | break; |
||
502 | case PDFOptions::OneColumn: |
||
503 | PutDoc("/OneColumn\n"); |
||
504 | break; |
||
505 | case PDFOptions::TwoColumnLeft: |
||
506 | PutDoc("/TwoColumnLeft\n"); |
||
507 | break; |
||
508 | case PDFOptions::TwoColumnRight: |
||
509 | PutDoc("/TwoColumnRight\n"); |
||
510 | break; |
||
511 | } |
||
4264 | craig | 512 | if (Options.displayBookmarks) |
4197 | fschmid | 513 | PutDoc("/PageMode /UseOutlines\n"); |
4264 | craig | 514 | else if (Options.displayFullscreen) |
4197 | fschmid | 515 | PutDoc("/PageMode /FullScreen\n"); |
4264 | craig | 516 | else if (Options.displayThumbs) |
4197 | fschmid | 517 | PutDoc("/PageMode /UseThumbs\n"); |
4264 | craig | 518 | else if ((Options.Version == 15) && (Options.displayLayers)) |
4197 | fschmid | 519 | PutDoc("/PageMode /UseOC\n"); |
4264 | craig | 520 | if (!Options.openAction.isEmpty()) |
4197 | fschmid | 521 | { |
4264 | craig | 522 | PutDoc("/OpenAction << /S /JavaScript /JS (this."+Options.openAction+"\\(\\)) >>\n"); |
3133 | fschmid | 523 | } |
524 | PutDoc("/ViewerPreferences\n<<\n/PageDirection "); |
||
4264 | craig | 525 | PutDoc( Options.Binding == 0 ? "/L2R\n" : "/R2L\n"); |
526 | if (Options.hideToolBar) |
||
4201 | fschmid | 527 | PutDoc("/HideToolbar true\n"); |
4264 | craig | 528 | if (Options.hideMenuBar) |
4201 | fschmid | 529 | PutDoc("/HideMenubar true\n"); |
4264 | craig | 530 | if (Options.fitWindow) |
4201 | fschmid | 531 | PutDoc("/FitWindow true\n"); |
3133 | fschmid | 532 | PutDoc(" >>\n>>\nendobj\n"); |
3829 | cbradney | 533 | QString IDg(Datum); |
4264 | craig | 534 | IDg += Options.Datei; |
3133 | fschmid | 535 | IDg += "Scribus "+QString(VERSION); |
536 | IDg += "Libpdf for Scribus "+QString(VERSION); |
||
4264 | craig | 537 | IDg += doc.documentInfo.getTitle(); |
538 | IDg += doc.documentInfo.getAuthor(); |
||
3133 | fschmid | 539 | IDg += "/False"; |
540 | FileID = ComputeMD5(IDg); |
||
4264 | craig | 541 | if (Options.Encrypt) |
3133 | fschmid | 542 | { |
4264 | craig | 543 | KeyLen = Options.Version == 14 ? 16 : 5; |
544 | CalcOwnerKey(Options.PassOwner, Options.PassUser); |
||
545 | CalcUserKey(Options.PassUser, Options.Permissions); |
||
3133 | fschmid | 546 | for (uint cl2 = 0; cl2 < 32; ++cl2) |
547 | ok += QChar(OwnerKey[cl2]); |
||
548 | if (KeyLen > 5) |
||
549 | { |
||
550 | for (uint cl3 = 0; cl3 < 16; ++cl3) |
||
551 | uk += QChar(UserKey[cl3]); |
||
552 | for (uint cl3r = 0; cl3r < 16; ++cl3r) |
||
553 | uk += QChar(KeyGen[cl3r]); |
||
554 | } |
||
555 | else |
||
556 | { |
||
557 | for (uint cl = 0; cl < 32; ++cl) |
||
558 | uk += QChar(UserKey[cl]); |
||
559 | } |
||
560 | } |
||
561 | QDate d = QDate::currentDate(); |
||
562 | Datum = "D:"; |
||
563 | tmp.sprintf("%4d", d.year()); |
||
564 | tmp.replace(QRegExp(" "), "0"); |
||
565 | Datum += tmp; |
||
566 | tmp.sprintf("%2d", d.month()); |
||
567 | tmp.replace(QRegExp(" "), "0"); |
||
568 | Datum += tmp; |
||
569 | tmp.sprintf("%2d", d.day()); |
||
570 | tmp.replace(QRegExp(" "), "0"); |
||
571 | Datum += tmp; |
||
4229 | craig | 572 | tmp = QTime::currentTime().toString(); |
3133 | fschmid | 573 | tmp.replace(QRegExp(":"), ""); |
574 | Datum += tmp; |
||
575 | StartObj(2); |
||
576 | PutDoc("<<\n/Creator "+EncString("(Scribus "+QString(VERSION)+")",2)+"\n"); |
||
577 | PutDoc("/Producer "+EncString("(Libpdf for Scribus "+QString(VERSION)+")",2)+"\n"); |
||
4718 | fschmid | 578 | QString docTitle = doc.documentInfo.getTitle(); |
579 | if ((Options.Version == 12) && (docTitle.isEmpty())) |
||
580 | PutDoc("/Title "+EncString("("+doc.DocName+")",2)+"\n"); |
||
581 | else |
||
582 | PutDoc("/Title "+EncString("("+doc.documentInfo.getTitle()+")",2)+"\n"); |
||
4264 | craig | 583 | PutDoc("/Author "+EncString("("+doc.documentInfo.getAuthor()+")",2)+"\n"); |
584 | PutDoc("/Keywords "+EncString("("+doc.documentInfo.getKeywords()+")",2)+"\n"); |
||
3133 | fschmid | 585 | PutDoc("/CreationDate "+EncString("("+Datum+")",2)+"\n"); |
586 | PutDoc("/ModDate "+EncString("("+Datum+")",2)+"\n"); |
||
4264 | craig | 587 | if (Options.Version == 12) |
3133 | fschmid | 588 | PutDoc("/GTS_PDFXVersion (PDF/X-3:2002)\n"); |
589 | PutDoc("/Trapped /False\n>>\nendobj\n"); |
||
4229 | craig | 590 | for (int t = 0; t < 6; ++t) |
591 | XRef.append(bytesWritten()); |
||
4264 | craig | 592 | if ((Options.Version == 15) && (Options.useLayers)) |
4229 | craig | 593 | XRef.append(bytesWritten()); |
4264 | craig | 594 | if (Options.Version == 12) |
4229 | craig | 595 | XRef.append(bytesWritten()); |
4264 | craig | 596 | if (Options.Encrypt) |
3133 | fschmid | 597 | { |
598 | StartObj(ObjCounter); |
||
599 | Encrypt = ObjCounter; |
||
600 | ObjCounter++; |
||
601 | PutDoc("<<\n/Filter /Standard\n"); |
||
602 | PutDoc( KeyLen > 5 ? "/R 3\n/V 2\n/Length 128\n" : "/R 2\n/V 1\n"); |
||
603 | PutDoc("/O <"+String2Hex(&ok)+">\n"); |
||
604 | PutDoc("/U <"+String2Hex(&uk)+">\n"); |
||
4264 | craig | 605 | PutDoc("/P "+QString::number(Options.Permissions)+"\n>>\nendobj\n"); |
3133 | fschmid | 606 | } |
607 | RealFonts = DocFonts; |
||
3544 | avox | 608 | QMap<QString,int> ReallyUsed; |
3133 | fschmid | 609 | ReallyUsed.clear(); |
610 | PageItem* pgit; |
||
4017 | fschmid | 611 | QMap<int, QString> ind2PDFabr; |
4546 | subik | 612 | const QString tmpf[] = {"/Courier", "/Courier-Bold", "/Courier-Oblique", "/Courier-BoldOblique", |
4017 | fschmid | 613 | "/Helvetica", "/Helvetica-Bold", "/Helvetica-Oblique", "/Helvetica-BoldOblique", |
4546 | subik | 614 | "/Times-Roman", "/Times-Bold", "/Times-Italic", "/Times-BoldItalic", |
4017 | fschmid | 615 | "/ZapfDingbats", "/Symbol"}; |
616 | size_t ar = sizeof(tmpf) / sizeof(*tmpf); |
||
617 | for (uint ax = 0; ax < ar; ++ax) |
||
618 | ind2PDFabr[ax] = tmpf[ax]; |
||
4264 | craig | 619 | for (uint c = 0; c < doc.FrameItems.count(); ++c) |
3133 | fschmid | 620 | { |
4264 | craig | 621 | pgit = doc.FrameItems.at(c); |
3133 | fschmid | 622 | if ((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) |
623 | { |
||
4084 | cbradney | 624 | if (pgit->isAnnotation()) |
625 | StdFonts.insert(ind2PDFabr[pgit->annotation().Font()], ""); |
||
5292 | fschmid | 626 | for (uint e = 0; e < static_cast<uint>(pgit->itemText.length()); ++e) |
3133 | fschmid | 627 | { |
5184 | avox | 628 | ReallyUsed.insert(pgit->itemText.charStyle(e).cfont->scName(), DocFonts[pgit->itemText.charStyle(e).cfont->scName()]); |
3133 | fschmid | 629 | } |
630 | } |
||
631 | } |
||
4264 | craig | 632 | for (uint c = 0; c < doc.MasterItems.count(); ++c) |
3133 | fschmid | 633 | { |
4264 | craig | 634 | pgit = doc.MasterItems.at(c); |
3133 | fschmid | 635 | if ((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) |
636 | { |
||
4084 | cbradney | 637 | if (pgit->isAnnotation()) |
638 | StdFonts.insert(ind2PDFabr[pgit->annotation().Font()], ""); |
||
5292 | fschmid | 639 | for (uint e = 0; e < static_cast<uint>(pgit->itemText.length()); ++e) |
3133 | fschmid | 640 | { |
5184 | avox | 641 | ReallyUsed.insert(pgit->itemText.charStyle(e).cfont->scName(), DocFonts[pgit->itemText.charStyle(e).cfont->scName()]); |
3133 | fschmid | 642 | } |
643 | } |
||
644 | } |
||
4264 | craig | 645 | for (uint d = 0; d < doc.Items->count(); ++d) |
3133 | fschmid | 646 | { |
4264 | craig | 647 | pgit = doc.Items->at(d); |
3133 | fschmid | 648 | if ((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) |
649 | { |
||
4084 | cbradney | 650 | if (pgit->isAnnotation()) |
651 | StdFonts.insert(ind2PDFabr[pgit->annotation().Font()], ""); |
||
5292 | fschmid | 652 | for (uint e = 0; e < static_cast<uint>(pgit->itemText.length()); ++e) |
3133 | fschmid | 653 | { |
5184 | avox | 654 | ReallyUsed.insert(pgit->itemText.charStyle(e).cfont->scName(), DocFonts[pgit->itemText.charStyle(e).cfont->scName()]); |
3133 | fschmid | 655 | } |
656 | } |
||
657 | } |
||
4017 | fschmid | 658 | a = 0; |
659 | QMap<QString, QString>::Iterator itStd; |
||
660 | for (itStd = StdFonts.begin(); itStd != StdFonts.end(); ++itStd) |
||
661 | { |
||
662 | StartObj(ObjCounter); |
||
663 | PutDoc("<<\n/Type /Font\n/Subtype /Type1\n"); |
||
664 | PutDoc("/BaseFont "+itStd.key()+"\n"); |
||
665 | PutDoc(">>\nendobj\n"); |
||
4229 | craig | 666 | Seite.FObjects["FoStd"+QString::number(a)] = ObjCounter; |
667 | itStd.data() = "FoStd"+QString::number(a); |
||
4017 | fschmid | 668 | ObjCounter++; |
669 | a++; |
||
670 | } |
||
3544 | avox | 671 | QMap<QString,int>::Iterator it; |
3133 | fschmid | 672 | a = 0; |
673 | for (it = ReallyUsed.begin(); it != ReallyUsed.end(); ++it) |
||
674 | { |
||
675 | Foi::FontFormat fformat = AllFonts[it.key()]->formatCode; |
||
4264 | craig | 676 | if ((AllFonts[it.key()]->isOTF) || (!AllFonts[it.key()]->HasNames) || (AllFonts[it.key()]->Subset) || (Options.SubsetList.contains(it.key()))) |
3133 | fschmid | 677 | { |
3829 | cbradney | 678 | QString fon(""); |
3133 | fschmid | 679 | QMap<uint,FPointArray>::Iterator ig; |
680 | for (ig = AllFonts[it.key()]->RealGlyphs.begin(); ig != AllFonts[it.key()]->RealGlyphs.end(); ++ig) |
||
681 | { |
||
682 | FPoint np, np1, np2; |
||
683 | bool nPath = true; |
||
684 | if (ig.data().size() > 3) |
||
685 | { |
||
686 | FPointArray gly = ig.data().copy(); |
||
687 | QWMatrix mat; |
||
688 | mat.scale(0.1, 0.1); |
||
689 | gly.map(mat); |
||
690 | for (uint poi = 0; poi < gly.size()-3; poi += 4) |
||
691 | { |
||
692 | if (gly.point(poi).x() > 900000) |
||
693 | { |
||
694 | fon += "h\n"; |
||
695 | nPath = true; |
||
696 | continue; |
||
697 | } |
||
698 | if (nPath) |
||
699 | { |
||
700 | np = gly.point(poi); |
||
701 | fon += FToStr(np.x())+" "+FToStr(-np.y())+" m\n"; |
||
702 | nPath = false; |
||
703 | } |
||
704 | np = gly.point(poi+1); |
||
705 | np1 = gly.point(poi+3); |
||
706 | np2 = gly.point(poi+2); |
||
707 | fon += FToStr(np.x()) + " " + FToStr(-np.y()) + " " + |
||
708 | FToStr(np1.x()) + " " + FToStr(-np1.y()) + " " + |
||
709 | FToStr(np2.x()) + " " + FToStr(-np2.y()) + " c\n"; |
||
710 | } |
||
711 | fon += "h f*\n"; |
||
712 | StartObj(ObjCounter); |
||
713 | ObjCounter++; |
||
714 | np = getMinClipF(&gly); |
||
715 | np1 = getMaxClipF(&gly); |
||
716 | PutDoc("<<\n/Type /XObject\n/Subtype /Form\n/FormType 1\n"); |
||
717 | PutDoc("/BBox [ "+FToStr(np.x())+" "+FToStr(-np.y())+" "+FToStr(np1.x())+ " "+FToStr(-np1.y())+" ]\n"); |
||
718 | PutDoc("/Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n"); |
||
719 | PutDoc(">>\n"); |
||
4264 | craig | 720 | if ((Options.Compress) && (CompAvail)) |
3133 | fschmid | 721 | fon = CompressStr(&fon); |
4229 | craig | 722 | PutDoc("/Length "+QString::number(fon.length()+1)); |
4264 | craig | 723 | if ((Options.Compress) && (CompAvail)) |
3133 | fschmid | 724 | PutDoc("\n/Filter /FlateDecode"); |
4229 | craig | 725 | PutDoc(" >>\nstream\n"+EncStream(fon, ObjCounter-1)+"\nendstream\nendobj\n"); |
726 | Seite.XObjects[AllFonts[it.key()]->RealName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )+QString::number(ig.key())] = ObjCounter-1; |
||
3133 | fschmid | 727 | fon = ""; |
728 | } |
||
729 | } |
||
730 | AllFonts[it.key()]->RealGlyphs.clear(); |
||
731 | } |
||
732 | else |
||
733 | { |
||
4229 | craig | 734 | UsedFontsP.insert(it.key(), "/Fo"+QString::number(a)); |
4264 | craig | 735 | if ((fformat == Foi::PFB) && (Options.EmbedList.contains(it.key()))) |
3133 | fschmid | 736 | { |
3829 | cbradney | 737 | QString fon(""); |
3133 | fschmid | 738 | StartObj(ObjCounter); |
739 | QByteArray bb; |
||
740 | AllFonts[it.key()]->RawData(bb); |
||
741 | uint posi; |
||
742 | for (posi = 6; posi < bb.size(); ++posi) |
||
743 | { |
||
744 | if ((bb[posi] == static_cast<char>(0x80)) && (static_cast<int>(bb[posi+1]) == 2)) |
||
745 | break; |
||
746 | fon += QChar(bb[posi]); |
||
747 | } |
||
748 | int len1 = fon.length(); |
||
749 | uint ulen; |
||
750 | ulen = bb[posi+2] & 0xff; |
||
751 | ulen |= (bb[posi+3] << 8) & 0xff00; |
||
752 | ulen |= (bb[posi+4] << 16) & 0xff0000; |
||
753 | ulen |= (bb[posi+5] << 24) & 0xff000000; |
||
754 | if (ulen > bb.size()) |
||
755 | ulen = bb.size()-7; |
||
756 | posi += 6; |
||
757 | for (uint j = 0; j < ulen; ++j) |
||
758 | fon += QChar(bb[posi++]); |
||
759 | posi += 6; |
||
760 | int len2 = fon.length()-len1; |
||
761 | for (uint j = posi; j < bb.size(); ++j) |
||
762 | { |
||
763 | if ((bb[j] == static_cast<char>(0x80)) && (static_cast<int>(bb[j+1]) == 3)) |
||
764 | break; |
||
765 | if (bb[j] == '\r') |
||
766 | fon += "\n"; |
||
767 | else |
||
768 | fon += QChar(bb[j]); |
||
769 | } |
||
770 | int len3 = fon.length()-len2-len1; |
||
4264 | craig | 771 | if ((Options.Compress) && (CompAvail)) |
3133 | fschmid | 772 | fon = CompressStr(&fon); |
4229 | craig | 773 | PutDoc("<<\n/Length "+QString::number(fon.length()+1)+"\n"); |
774 | PutDoc("/Length1 "+QString::number(len1)+"\n"); |
||
775 | PutDoc("/Length2 "+QString::number(len2)+"\n"); |
||
776 | PutDoc("/Length3 "+QString::number(len3)+"\n"); |
||
4264 | craig | 777 | if ((Options.Compress) && (CompAvail)) |
3133 | fschmid | 778 | PutDoc("/Filter /FlateDecode\n"); |
4229 | craig | 779 | PutDoc(">>\nstream\n"+EncStream(fon,ObjCounter)+"\nendstream\nendobj\n"); |
3133 | fschmid | 780 | ObjCounter++; |
781 | } |
||
4264 | craig | 782 | if ((fformat == Foi::PFA) && (Options.EmbedList.contains(it.key()))) |
3133 | fschmid | 783 | { |
3829 | cbradney | 784 | QString fon(""); |
785 | QString fon2(""); |
||
786 | QString tm(""); |
||
3133 | fschmid | 787 | uint value; |
788 | bool ok = true; |
||
789 | StartObj(ObjCounter); |
||
790 | AllFonts[it.key()]->EmbedFont(fon); |
||
791 | int len1 = fon.find("eexec")+5; |
||
792 | fon2 = fon.left(len1)+"\n"; |
||
793 | int len2 = fon.find("0000000000000000000000000"); |
||
794 | if (len2 == -1) |
||
795 | len2 = fon.length()+1; |
||
796 | int count = 0; |
||
797 | for (int xx = len1; xx < len2-1; ++xx) |
||
798 | { |
||
799 | tm = fon.at(xx); |
||
800 | if ((tm == QChar(13)) || (tm == QChar(10))) |
||
801 | continue; |
||
802 | xx++; |
||
803 | count++; |
||
804 | tm += fon.at(xx); |
||
805 | value = tm.toUInt(&ok, 16); |
||
806 | fon2 += QChar(value); |
||
807 | } |
||
808 | fon2 += fon.mid(len2); |
||
4264 | craig | 809 | if ((Options.Compress) && (CompAvail)) |
3133 | fschmid | 810 | fon2 = CompressStr(&fon2); |
4229 | craig | 811 | PutDoc("<<\n/Length "+QString::number(fon2.length()+1)+"\n"); |
812 | PutDoc("/Length1 "+QString::number(len1+1)+"\n"); |
||
813 | PutDoc("/Length2 "+QString::number(count)+"\n"); |
||
814 | PutDoc(static_cast<int>(fon.length()-len2) == -1 ? QString("/Length3 0\n") : "/Length3 "+QString::number(fon.length()-len2)+"\n"); |
||
4264 | craig | 815 | if ((Options.Compress) && (CompAvail)) |
3133 | fschmid | 816 | PutDoc("/Filter /FlateDecode\n"); |
4229 | craig | 817 | PutDoc(">>\nstream\n"+EncStream(fon2, ObjCounter)+"\nendstream\nendobj\n"); |
3133 | fschmid | 818 | ObjCounter++; |
819 | } |
||
4264 | craig | 820 | if ((fformat == Foi::SFNT || fformat == Foi::TTCF) && (Options.EmbedList.contains(it.key()))) |
3133 | fschmid | 821 | { |
3829 | cbradney | 822 | QString fon(""); |
3133 | fschmid | 823 | StartObj(ObjCounter); |
824 | QByteArray bb; |
||
825 | AllFonts[it.key()]->RawData(bb); |
||
826 | //AV: += and append() dont't work because they stop at '\0' :-( |
||
827 | for (unsigned int i=0; i < bb.size(); i++) |
||
828 | fon += QChar(bb[i]); |
||
829 | int len = fon.length(); |
||
4264 | craig | 830 | if ((Options.Compress) && (CompAvail)) |
3133 | fschmid | 831 | fon = CompressStr(&fon); |
832 | //qDebug(QString("sfnt data: size=%1 before=%2 compressed=%3").arg(bb.size()).arg(len).arg(fon.length())); |
||
4229 | craig | 833 | PutDoc("<<\n/Length "+QString::number(fon.length()+1)+"\n"); |
834 | PutDoc("/Length1 "+QString::number(len)+"\n"); |
||
4264 | craig | 835 | if ((Options.Compress) && (CompAvail)) |
3133 | fschmid | 836 | PutDoc("/Filter /FlateDecode\n"); |
4229 | craig | 837 | PutDoc(">>\nstream\n"+EncStream(fon, ObjCounter)+"\nendstream\nendobj\n"); |
3133 | fschmid | 838 | ObjCounter++; |
839 | } |
||
840 | StartObj(ObjCounter); |
||
841 | PutDoc("<<\n/Type /FontDescriptor\n"); |
||
3440 | fschmid | 842 | PutDoc("/FontName /"+AllFonts[it.key()]->RealName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )+"\n"); |
3133 | fschmid | 843 | PutDoc("/FontBBox [ "+AllFonts[it.key()]->FontBBox+" ]\n"); |
844 | PutDoc("/Flags "); |
||
3544 | avox | 845 | //FIXME: isItalic() should be queried from Foi, not from Qt -- AV |
846 | //QFontInfo fo = QFontInfo(it.data()); |
||
3133 | fschmid | 847 | int pfl = 0; |
848 | if (AllFonts[it.key()]->IsFixedPitch) |
||
849 | pfl = pfl ^ 1; |
||
3544 | avox | 850 | //if (fo.italic()) |
851 | if (AllFonts[it.key()]->ItalicAngle != "0") |
||
3133 | fschmid | 852 | pfl = pfl ^ 64; |
853 | // pfl = pfl ^ 4; |
||
854 | pfl = pfl ^ 32; |
||
4229 | craig | 855 | PutDoc(QString::number(pfl)+"\n"); |
3133 | fschmid | 856 | PutDoc("/Ascent "+AllFonts[it.key()]->Ascent+"\n"); |
857 | PutDoc("/Descent "+AllFonts[it.key()]->Descender+"\n"); |
||
858 | PutDoc("/CapHeight "+AllFonts[it.key()]->CapHeight+"\n"); |
||
859 | PutDoc("/ItalicAngle "+AllFonts[it.key()]->ItalicAngle+"\n"); |
||
860 | PutDoc("/StemV "+AllFonts[it.key()]->StdVW+"\n"); |
||
4264 | craig | 861 | if ((fformat == Foi::SFNT || fformat == Foi::TTCF) && (Options.EmbedList.contains(it.key()))) |
4229 | craig | 862 | PutDoc("/FontFile2 "+QString::number(ObjCounter-1)+" 0 R\n"); |
4264 | craig | 863 | if ((fformat == Foi::PFB) && (Options.EmbedList.contains(it.key()))) |
4229 | craig | 864 | PutDoc("/FontFile "+QString::number(ObjCounter-1)+" 0 R\n"); |
4264 | craig | 865 | if ((fformat == Foi::PFA) && (Options.EmbedList.contains(it.key()))) |
4229 | craig | 866 | PutDoc("/FontFile "+QString::number(ObjCounter-1)+" 0 R\n"); |
3133 | fschmid | 867 | PutDoc(">>\nendobj\n"); |
868 | ObjCounter++; |
||
4546 | subik | 869 | /* if (!FT_Has_PS_Glyph_Names(AllFonts[it.key()]) |
3133 | fschmid | 870 | { |
871 | StartObj(ObjCounter); |
||
872 | int chCount = 31; |
||
873 | PutDoc("[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 "); |
||
874 | for (int ww = 31; ww < 256; ++ww) |
||
875 | { |
||
4229 | craig | 876 | PutDoc(QString::number(static_cast<int>(AllFonts[it.key()]->CharWidth[itg.key()]* |
3133 | fschmid | 877 | 1000))+" "); |
878 | if (itg == gl.end()) |
||
879 | break; |
||
880 | ++itg; |
||
881 | chCount++; |
||
882 | } |
||
883 | PutDoc("]\nendobj\n"); |
||
884 | ObjCounter++; |
||
885 | // put widths object |
||
886 | // encoding dictionary w/ base encoding w/o differences |
||
887 | StartObj(ObjCounter); |
||
888 | PutDoc("<<\n/Type /Font\n/Subtype "); |
||
889 | PutDoc((fformat == Foi::SFNT || fformat == Foi::TTCF) ? "/TrueType\n" : "/Type1\n"); |
||
4229 | craig | 890 | PutDoc("/Name /Fo"+QString::number(a)+"\n"); |
3304 | fschmid | 891 | PutDoc("/BaseFont /"+AllFonts[it.key()]->RealName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "" )+"\n"); |
3133 | fschmid | 892 | //cf. widths: |
893 | PutDoc("/FirstChar 0\n"); |
||
4229 | craig | 894 | PutDoc("/LastChar "+QString::number(chCount-1)+"\n"); |
895 | PutDoc("/Widths "+QString::number(ObjCounter-1)+" 0 R\n"); |
||
896 | PutDoc("/FontDescriptor "+QString::number(ObjCounter-2)+" 0 R\n"); |
||
3133 | fschmid | 897 | PutDoc(">>\nendobj\n"); |
4229 | craig | 898 | Seite.FObjects["Fo"+QString::number(a)] = ObjCounter; |
3133 | fschmid | 899 | ObjCounter++; |
900 | } |
||
901 | else */ |
||
902 | // { |
||
903 | GListeInd gl; |
||
904 | GlyIndex(AllFonts[it.key()], &gl); |
||
905 | GlyphsIdxOfFont.insert(it.key(), gl); |
||
906 | uint FontDes = ObjCounter - 1; |
||
907 | GListeInd::Iterator itg; |
||
908 | itg = gl.begin(); |
||
909 | GListeInd::Iterator itg2; |
||
910 | itg2 = gl.begin(); |
||
911 | uint Fcc = gl.count() / 224; |
||
912 | if ((gl.count() % 224) != 0) |
||
913 | Fcc += 1; |
||
914 | for (uint Fc = 0; Fc < Fcc; ++Fc) |
||
915 | { |
||
916 | StartObj(ObjCounter); |
||
917 | int chCount = 31; |
||
918 | PutDoc("[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 "); |
||
919 | for (int ww = 31; ww < 256; ++ww) |
||
920 | { |
||
4229 | craig | 921 | PutDoc(QString::number(static_cast<int>(AllFonts[it.key()]->CharWidth[itg.key()]* 1000))+" "); |
3133 | fschmid | 922 | if (itg == gl.end()) |
923 | break; |
||
924 | ++itg; |
||
925 | chCount++; |
||
926 | } |
||
927 | PutDoc("]\nendobj\n"); |
||
928 | ObjCounter++; |
||
929 | StartObj(ObjCounter); |
||
930 | ObjCounter++; |
||
931 | PutDoc("<< /Type /Encoding\n"); |
||
932 | // PutDoc("/BaseEncoding /" + AllFonts[it.key()]->FontEnc + "\n"); |
||
933 | PutDoc("/Differences [ 32\n"); |
||
934 | int crc = 0; |
||
935 | for (int ww2 = 32; ww2 < 256; ++ww2) |
||
936 | { |
||
937 | PutDoc(itg2.data().Name+" "); |
||
938 | if (itg2 == gl.end()) |
||
939 | break; |
||
940 | ++itg2; |
||
941 | crc++; |
||
942 | if (crc > 8) |
||
943 | { |
||
944 | PutDoc("\n"); |
||
945 | crc = 0; |
||
946 | } |
||
947 | } |
||
948 | PutDoc("]\n"); |
||
4546 | subik | 949 | |
3133 | fschmid | 950 | PutDoc(">>\nendobj\n"); |
951 | StartObj(ObjCounter); |
||
952 | PutDoc("<<\n/Type /Font\n/Subtype "); |
||
953 | PutDoc((fformat == Foi::SFNT || fformat == Foi::TTCF) ? "/TrueType\n" : "/Type1\n"); |
||
4229 | craig | 954 | PutDoc("/Name /Fo"+QString::number(a)+"S"+QString::number(Fc)+"\n"); |
3440 | fschmid | 955 | PutDoc("/BaseFont /"+AllFonts[it.key()]->RealName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )+"\n"); |
3133 | fschmid | 956 | PutDoc("/FirstChar 0\n"); |
4229 | craig | 957 | PutDoc("/LastChar "+QString::number(chCount-1)+"\n"); |
958 | PutDoc("/Widths "+QString::number(ObjCounter-2)+" 0 R\n"); |
||
959 | PutDoc("/Encoding "+QString::number(ObjCounter-1)+" 0 R\n"); |
||
960 | PutDoc("/FontDescriptor "+QString::number(FontDes)+" 0 R\n"); |
||
3133 | fschmid | 961 | PutDoc(">>\nendobj\n"); |
4229 | craig | 962 | Seite.FObjects["Fo"+QString::number(a)+"S"+QString::number(Fc)] = ObjCounter; |
3133 | fschmid | 963 | ObjCounter++; |
964 | } // for(Fc) |
||
965 | // } // FT_Has_PS_Glyph_Names |
||
966 | } |
||
967 | a++; |
||
968 | } |
||
4264 | craig | 969 | if (Options.UseLPI) |
3133 | fschmid | 970 | { |
971 | StartObj(ObjCounter); |
||
972 | PutDoc("<<\n/Type /Halftone\n/HalftoneType 5\n"); |
||
4264 | craig | 973 | QMap<QString,LPIData>::const_iterator itlp; |
974 | for (itlp = Options.LPISettings.constBegin(); itlp != Options.LPISettings.constEnd(); ++itlp) |
||
3133 | fschmid | 975 | { |
976 | PutDoc("/"+itlp.key()+"\n<<\n/Type /Halftone\n/HalftoneType 1\n/Frequency "); |
||
4229 | craig | 977 | PutDoc(QString::number(itlp.data().Frequency)+"\n/Angle "+QString::number(itlp.data().Angle)+"\n/SpotFunction "); |
3829 | cbradney | 978 | QString func (""); |
3133 | fschmid | 979 | switch (itlp.data().SpotFunc) |
980 | { |
||
981 | case 0: |
||
982 | func = "/SimpleDot"; |
||
983 | break; |
||
984 | case 1: |
||
985 | func = "/Line"; |
||
986 | break; |
||
987 | case 2: |
||
988 | func = "/Round"; |
||
989 | break; |
||
990 | case 3: |
||
991 | func = "/Ellipse"; |
||
992 | break; |
||
993 | default: |
||
994 | func = "/SimpleDot"; |
||
995 | break; |
||
996 | } |
||
997 | PutDoc(func+"\n>>\n"); |
||
998 | } |
||
999 | PutDoc("/Default\n<<\n/Type /Halftone\n/HalftoneType 1\n/Frequency 50\n/Angle 45\n/SpotFunction /Round\n>>\n"); |
||
1000 | PutDoc(">>\nendobj\n"); |
||
1001 | ObjCounter++; |
||
1002 | StartObj(ObjCounter); |
||
4229 | craig | 1003 | HTName = ResNam+QString::number(ResCount); |
3133 | fschmid | 1004 | Transpar[HTName] = ObjCounter; |
4229 | craig | 1005 | PutDoc("<< /Type /ExtGState\n/HT "+QString::number(ObjCounter-1)+" 0 R\n>>\nendobj\n"); |
3133 | fschmid | 1006 | ResCount++; |
1007 | ObjCounter++; |
||
1008 | } |
||
1009 | #ifdef HAVE_CMS |
||
4264 | craig | 1010 | if ((CMSuse) && (Options.UseProfiles)) |
3133 | fschmid | 1011 | { |
1012 | StartObj(ObjCounter); |
||
1013 | ObjCounter++; |
||
1014 | QString dataP; |
||
1015 | struct ICCD dataD; |
||
5243 | cbradney | 1016 | loadText(ScCore->InputProfiles[Options.SolidProf], &dataP); |
3133 | fschmid | 1017 | PutDoc("<<\n"); |
4264 | craig | 1018 | if ((Options.Compress) && (CompAvail)) |
3133 | fschmid | 1019 | { |
1020 | PutDoc("/Filter /FlateDecode\n"); |
||
1021 | dataP = CompressStr(&dataP); |
||
1022 | } |
||
4229 | craig | 1023 | PutDoc("/Length "+QString::number(dataP.length()+1)+"\n"); |
4264 | craig | 1024 | PutDoc("/N "+QString::number(Options.SComp)+"\n"); |
4229 | craig | 1025 | PutDoc(">>\nstream\n"+EncStream(dataP, ObjCounter-1)+"\nendstream\nendobj\n"); |
3133 | fschmid | 1026 | StartObj(ObjCounter); |
4229 | craig | 1027 | dataD.ResName = ResNam+QString::number(ResCount); |
1028 | dataD.ICCArray = "[ /ICCBased "+QString::number(ObjCounter-1)+" 0 R ]"; |
||
3133 | fschmid | 1029 | dataD.ResNum = ObjCounter; |
4264 | craig | 1030 | ICCProfiles[Options.SolidProf] = dataD; |
4229 | craig | 1031 | PutDoc("[ /ICCBased "+QString::number(ObjCounter-1)+" 0 R ]\n"); |
3133 | fschmid | 1032 | PutDoc("endobj\n"); |
1033 | ResCount++; |
||
1034 | ObjCounter++; |
||
1035 | } |
||
1036 | #endif |
||
4264 | craig | 1037 | if (((Options.isGrayscale == false) && (Options.UseRGB == false)) && (Options.UseSpotColors)) |
3133 | fschmid | 1038 | { |
4264 | craig | 1039 | doc.getUsedColors(colorsToUse); |
3133 | fschmid | 1040 | ColorList::Iterator itf; |
1041 | for (itf = colorsToUse.begin(); itf != colorsToUse.end(); ++itf) |
||
1042 | { |
||
1043 | if ((colorsToUse[itf.key()].isSpotColor()) || (colorsToUse[itf.key()].isRegistrationColor())) |
||
1044 | { |
||
1045 | int cc, cm, cy, ck; |
||
1046 | struct SpotC spotD; |
||
1047 | colorsToUse[itf.key()].getCMYK(&cc, &cm, &cy, &ck); |
||
1048 | QString colorDesc = "{\ndup "+FToStr(static_cast<double>(cc) / 255)+"\nmul exch dup "; |
||
1049 | colorDesc += FToStr(static_cast<double>(cm) / 255)+"\nmul exch dup "; |
||
1050 | colorDesc += FToStr(static_cast<double>(cy) / 255)+"\nmul exch "; |
||
1051 | colorDesc += FToStr(static_cast<double>(ck) / 255)+" mul }"; |
||
1052 | StartObj(ObjCounter); |
||
1053 | ObjCounter++; |
||
1054 | PutDoc("<<\n/FunctionType 4\n"); |
||
1055 | PutDoc("/Domain [0.0 1.0]\n"); |
||
1056 | PutDoc("/Range [0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0]\n"); |
||
4229 | craig | 1057 | PutDoc("/Length "+QString::number(colorDesc.length()+1)+"\n"); |
1058 | PutDoc(">>\nstream\n"+EncStream(colorDesc, ObjCounter-1)+"\nendstream\nendobj\n"); |
||
3133 | fschmid | 1059 | StartObj(ObjCounter); |
1060 | PutDoc("[ /Separation /"); |
||
1061 | if (colorsToUse[itf.key()].isRegistrationColor()) |
||
1062 | PutDoc("All"); |
||
1063 | else |
||
3440 | fschmid | 1064 | PutDoc(itf.key().simplifyWhiteSpace().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" ).replace("#", "_")); |
4229 | craig | 1065 | PutDoc(" /DeviceCMYK "+QString::number(ObjCounter-1)+" 0 R ]\nendobj\n"); |
1066 | spotD.ResName = spotNam+QString::number(spotCount); |
||
3133 | fschmid | 1067 | spotD.ResNum = ObjCounter; |
1068 | spotMap.insert(itf.key(), spotD); |
||
1069 | spotCount++; |
||
1070 | ObjCounter++; |
||
1071 | } |
||
1072 | } |
||
1073 | } |
||
4264 | craig | 1074 | if ((Options.Version == 15) && (Options.useLayers)) |
3133 | fschmid | 1075 | { |
1076 | struct Layer ll; |
||
1077 | struct OCGInfo ocg; |
||
1078 | ll.isPrintable = false; |
||
1079 | ll.LNr = 0; |
||
1080 | int Lnr = 0; |
||
3829 | cbradney | 1081 | QString ocgNam("oc"); |
4264 | craig | 1082 | uint docLayersCount=doc.Layers.count(); |
3829 | cbradney | 1083 | for (uint la = 0; la < docLayersCount; ++la) |
3133 | fschmid | 1084 | { |
3829 | cbradney | 1085 | QString tmp(""); |
4264 | craig | 1086 | Level2Layer(&doc, &ll, Lnr); |
3133 | fschmid | 1087 | ocg.Name = ocgNam+tmp.setNum(ll.LNr); |
1088 | ocg.ObjNum = ObjCounter; |
||
1089 | ocg.visible = ll.isViewable; |
||
1090 | OCGEntries.insert(ll.Name, ocg); |
||
1091 | StartObj(ObjCounter); |
||
1092 | ObjCounter++; |
||
1093 | PutDoc("<<\n"); |
||
1094 | PutDoc("/Type /OCG\n"); |
||
1095 | PutDoc("/Name ("+ll.Name+")\n"); |
||
1096 | PutDoc(">>\nendobj\n"); |
||
1097 | Lnr++; |
||
1098 | } |
||
1099 | } |
||
1100 | return true; |
||
1101 | } |
||
1102 | |||
4241 | craig | 1103 | void PDFlib::PDF_TemplatePage(const Page* pag, bool ) |
3133 | fschmid | 1104 | { |
1105 | QString tmp; |
||
1106 | ActPageP = pag; |
||
1107 | PageItem* ite; |
||
1108 | QPtrList<PageItem> PItems; |
||
1109 | int Lnr = 0; |
||
1110 | struct Layer ll; |
||
1111 | ll.isPrintable = false; |
||
1112 | ll.LNr = 0; |
||
1113 | Inhalt = ""; |
||
1114 | Seite.AObjects.clear(); |
||
4264 | craig | 1115 | for (uint la = 0; la < doc.Layers.count(); ++la) |
3133 | fschmid | 1116 | { |
4264 | craig | 1117 | Level2Layer(&doc, &ll, Lnr); |
1118 | PItems = doc.MasterItems; |
||
3133 | fschmid | 1119 | if (ll.isPrintable) |
1120 | { |
||
4264 | craig | 1121 | if ((Options.Version == 15) && (Options.useLayers)) |
3133 | fschmid | 1122 | PutPage("/OC /"+OCGEntries[ll.Name].Name+" BDC\n"); |
1123 | for (uint a = 0; a < PItems.count(); ++a) |
||
1124 | { |
||
1125 | Inhalt = ""; |
||
1126 | ite =PItems.at(a); |
||
1127 | if (ite->LayerNr != ll.LNr) |
||
1128 | continue; |
||
4726 | fschmid | 1129 | double x = pag->xOffset(); |
1130 | double y = pag->yOffset(); |
||
1131 | double w = pag->width(); |
||
1132 | double h1 = pag->height(); |
||
4580 | cbradney | 1133 | double ilw=ite->lineWidth(); |
4726 | fschmid | 1134 | double x2 = ite->BoundingX - ilw / 2.0; |
1135 | double y2 = ite->BoundingY - ilw / 2.0; |
||
1136 | double w2 = ite->BoundingW + ilw; |
||
1137 | double h2 = ite->BoundingH + ilw; |
||
1138 | if (!( QMAX( x, x2 ) <= QMIN( x+w, x2+w2 ) && QMAX( y, y2 ) <= QMIN( y+h1, y2+h2 ))) |
||
3133 | fschmid | 1139 | continue; |
1140 | if (ite->ChangedMasterItem) |
||
1141 | continue; |
||
3200 | cbradney | 1142 | if ((!pag->PageNam.isEmpty()) && (ite->OwnPage != static_cast<int>(pag->pageNr())) && (ite->OwnPage != -1)) |
3133 | fschmid | 1143 | continue; |
1144 | PutPage("q\n"); |
||
5320 | fschmid | 1145 | if ((ite->doOverprint) && (!Options.doOverprint) && (!Options.UseRGB)) |
1146 | { |
||
1147 | StartObj(ObjCounter); |
||
1148 | QString ShName = ResNam+QString::number(ResCount); |
||
1149 | Transpar[ShName] = ObjCounter; |
||
1150 | ResCount++; |
||
1151 | ObjCounter++; |
||
1152 | PutDoc("<< /Type /ExtGState\n"); |
||
1153 | PutDoc("/OP true\n"); |
||
1154 | PutDoc("/op true\n"); |
||
1155 | PutDoc("/OPM 1\n"); |
||
1156 | PutDoc(">>\nendobj\n"); |
||
1157 | PutPage("/"+ShName+" gs\n"); |
||
1158 | } |
||
4264 | craig | 1159 | if (((ite->fillTransparency() != 0) || (ite->lineTransparency() != 0)) && (Options.Version >= 14)) |
3133 | fschmid | 1160 | PutPage(PDF_Transparenz(ite)); |
4679 | fschmid | 1161 | /* Bookmarks on Master Pages do not make any sense */ |
1162 | // if ((ite->isBookmark) && (Options.Bookmarks)) |
||
1163 | // PDF_Bookmark(ite, pag->height() - (ite->yPos() - pag->yOffset())); |
||
4698 | cbradney | 1164 | if (!ite->printEnabled() || ((ite->itemType() == PageItem::TextFrame) && (!pag->PageNam.isEmpty()))) |
3133 | fschmid | 1165 | { |
1166 | PutPage("Q\n"); |
||
1167 | continue; |
||
1168 | } |
||
4546 | subik | 1169 | if (ite->fillColor() != CommonStrings::None) |
3133 | fschmid | 1170 | PutPage(putColor(ite->fillColor(), ite->fillShade(), true)); |
4546 | subik | 1171 | if (ite->lineColor() != CommonStrings::None) |
3133 | fschmid | 1172 | PutPage(putColor(ite->lineColor(), ite->lineShade(), false)); |
4580 | cbradney | 1173 | Inhalt += FToStr(fabs(ite->lineWidth()))+" w\n"; |
3133 | fschmid | 1174 | if (ite->DashValues.count() != 0) |
1175 | { |
||
1176 | PutPage("[ "); |
||
1177 | QValueList<double>::iterator it; |
||
1178 | for ( it = ite->DashValues.begin(); it != ite->DashValues.end(); ++it ) |
||
1179 | { |
||
1180 | int da = static_cast<int>(*it); |
||
1181 | if (da != 0) |
||
4229 | craig | 1182 | PutPage(QString::number(da)+" "); |
3133 | fschmid | 1183 | } |
4229 | craig | 1184 | PutPage("] "+QString::number(static_cast<int>(ite->DashOffset))+" d\n"); |
3133 | fschmid | 1185 | } |
1186 | else |
||
1187 | { |
||
4580 | cbradney | 1188 | QString Dt = FToStr(QMAX(2*fabs(ite->lineWidth()), 1)); |
1189 | QString Da = FToStr(QMAX(6*fabs(ite->lineWidth()), 1)); |
||
3133 | fschmid | 1190 | switch (ite->PLineArt) |
1191 | { |
||
1192 | case Qt::SolidLine: |
||
1193 | PutPage("[] 0 d\n"); |
||
1194 | break; |
||
1195 | case Qt::DashLine: |
||
1196 | PutPage("["+Da+" "+Dt+"] 0 d\n"); |
||
1197 | break; |
||
1198 | case Qt::DotLine: |
||
1199 | PutPage("["+Dt+"] 0 d\n"); |
||
1200 | break; |
||
1201 | case Qt::DashDotLine: |
||
1202 | PutPage("["+Da+" "+Dt+" "+Dt+" "+Dt+"] 0 d\n"); |
||
1203 | break; |
||
1204 | case Qt::DashDotDotLine: |
||
1205 | PutPage("["+Da+" "+Dt+" "+Dt+" "+Dt+" "+Dt+" "+Dt+"] 0 d\n"); |
||
1206 | break; |
||
1207 | default: |
||
1208 | PutPage("[] 0 d\n"); |
||
1209 | break; |
||
1210 | } |
||
1211 | } |
||
1212 | switch (ite->PLineEnd) |
||
1213 | { |
||
1214 | case Qt::FlatCap: |
||
1215 | PutPage("0 J\n"); |
||
1216 | break; |
||
1217 | case Qt::SquareCap: |
||
1218 | PutPage("2 J\n"); |
||
1219 | break; |
||
1220 | case Qt::RoundCap: |
||
1221 | PutPage("1 J\n"); |
||
1222 | break; |
||
1223 | default: |
||
1224 | PutPage("0 J\n"); |
||
1225 | break; |
||
1226 | } |
||
1227 | switch (ite->PLineJoin) |
||
1228 | { |
||
1229 | case Qt::MiterJoin: |
||
1230 | PutPage("0 j\n"); |
||
1231 | break; |
||
1232 | case Qt::BevelJoin: |
||
1233 | PutPage("2 j\n"); |
||
1234 | break; |
||
1235 | case Qt::RoundJoin: |
||
1236 | PutPage("1 j\n"); |
||
1237 | break; |
||
1238 | default: |
||
1239 | PutPage("0 j\n"); |
||
1240 | break; |
||
1241 | } |
||
3903 | cbradney | 1242 | PutPage("1 0 0 1 "+FToStr(ite->xPos() - pag->xOffset())+" "+FToStr(pag->height() - (ite->yPos() - pag->yOffset()))+" cm\n"); |
3934 | cbradney | 1243 | if (ite->rotation() != 0) |
3133 | fschmid | 1244 | { |
3934 | cbradney | 1245 | double sr = sin(-ite->rotation()* M_PI / 180.0); |
1246 | double cr = cos(-ite->rotation()* M_PI / 180.0); |
||
3133 | fschmid | 1247 | if ((cr * cr) < 0.000001) |
1248 | cr = 0; |
||
1249 | if ((sr * sr) < 0.000001) |
||
1250 | sr = 0; |
||
1251 | PutPage(FToStr(cr)+" "+FToStr(sr)+" "+FToStr(-sr)+" "+FToStr(cr)+" 0 0 cm\n"); |
||
1252 | } |
||
1253 | switch (ite->itemType()) |
||
1254 | { |
||
1255 | case PageItem::ImageFrame: |
||
4546 | subik | 1256 | if ((ite->fillColor() != CommonStrings::None) || (ite->GrType != 0)) |
3133 | fschmid | 1257 | { |
1258 | if (ite->GrType != 0) |
||
1259 | PutPage(PDF_Gradient(ite)); |
||
1260 | else |
||
1261 | { |
||
1262 | PutPage(SetClipPath(ite)); |
||
1263 | PutPage("h\nf*\n"); |
||
1264 | } |
||
1265 | } |
||
1266 | PutPage("q\n"); |
||
1267 | if (ite->imageClip.size() != 0) |
||
4744 | fschmid | 1268 | { |
3133 | fschmid | 1269 | PutPage(SetClipPathImage(ite)); |
4744 | fschmid | 1270 | PutPage("h\nW*\nn\n"); |
1271 | } |
||
1272 | PutPage(SetClipPath(ite)); |
||
3133 | fschmid | 1273 | PutPage("h\nW*\nn\n"); |
1274 | if (ite->imageFlippedH()) |
||
3934 | cbradney | 1275 | PutPage("-1 0 0 1 "+FToStr(ite->width())+" 0 cm\n"); |
3133 | fschmid | 1276 | if (ite->imageFlippedV()) |
3934 | cbradney | 1277 | PutPage("1 0 0 -1 0 "+FToStr(-ite->height())+" cm\n"); |
3133 | fschmid | 1278 | if ((ite->PicAvail) && (!ite->Pfile.isEmpty())) |
3985 | cbradney | 1279 | PutPage(PDF_Image(ite, ite->Pfile, ite->imageXScale(), ite->imageYScale(), ite->imageXOffset(), -ite->imageYOffset(), false, ite->IProfile, ite->UseEmbedded, ite->IRender)); |
3133 | fschmid | 1280 | PutPage("Q\n"); |
4546 | subik | 1281 | if (((ite->lineColor() != CommonStrings::None) || (!ite->NamedLStyle.isEmpty())) && (!ite->isTableItem)) |
3133 | fschmid | 1282 | { |
4580 | cbradney | 1283 | if ((ite->NamedLStyle.isEmpty()) && (ite->lineWidth() != 0.0)) |
3133 | fschmid | 1284 | { |
1285 | PutPage(SetClipPath(ite)); |
||
1286 | PutPage("h\nS\n"); |
||
1287 | } |
||
1288 | else |
||
1289 | { |
||
4264 | craig | 1290 | multiLine ml = doc.MLineStyles[ite->NamedLStyle]; |
3133 | fschmid | 1291 | for (int it = ml.size()-1; it > -1; it--) |
1292 | { |
||
1293 | PutPage(setStrokeMulti(&ml[it])); |
||
1294 | PutPage(SetClipPath(ite)); |
||
1295 | PutPage("h\nS\n"); |
||
1296 | } |
||
1297 | } |
||
1298 | } |
||
1299 | break; |
||
1300 | case PageItem::TextFrame: |
||
1301 | break; |
||
1302 | case PageItem::Line: |
||
1303 | if (ite->NamedLStyle.isEmpty()) |
||
1304 | { |
||
1305 | PutPage("0 0 m\n"); |
||
3934 | cbradney | 1306 | PutPage(FToStr(ite->width())+" 0 l\n"); |
3133 | fschmid | 1307 | PutPage("S\n"); |
1308 | } |
||
1309 | else |
||
1310 | { |
||
4264 | craig | 1311 | multiLine ml = doc.MLineStyles[ite->NamedLStyle]; |
3133 | fschmid | 1312 | for (int it = ml.size()-1; it > -1; it--) |
1313 | { |
||
1314 | PutPage(setStrokeMulti(&ml[it])); |
||
1315 | PutPage("0 0 m\n"); |
||
3934 | cbradney | 1316 | PutPage(FToStr(ite->width())+" 0 l\n"); |
3133 | fschmid | 1317 | PutPage("S\n"); |
1318 | } |
||
1319 | } |
||
4061 | craig | 1320 | if (ite->startArrowIndex() != 0) |
3133 | fschmid | 1321 | { |
1322 | QWMatrix arrowTrans; |
||
4264 | craig | 1323 | FPointArray arrow = (*doc.arrowStyles.at(ite->startArrowIndex()-1)).points.copy(); |
3133 | fschmid | 1324 | arrowTrans.translate(0, 0); |
4580 | cbradney | 1325 | arrowTrans.scale(ite->lineWidth(), ite->lineWidth()); |
3133 | fschmid | 1326 | arrowTrans.scale(-1,1); |
1327 | arrow.map(arrowTrans); |
||
4264 | craig | 1328 | if ((ite->lineTransparency() != 0) && (Options.Version >= 14)) |
3133 | fschmid | 1329 | { |
1330 | StartObj(ObjCounter); |
||
4229 | craig | 1331 | QString ShName = ResNam+QString::number(ResCount); |
3133 | fschmid | 1332 | Transpar[ShName] = ObjCounter; |
1333 | ResCount++; |
||
1334 | ObjCounter++; |
||
1335 | PutDoc("<< /Type /ExtGState\n"); |
||
1336 | PutDoc("/CA "+FToStr(1.0 - ite->lineTransparency())+"\n"); |
||
1337 | PutDoc("/ca "+FToStr(1.0 - ite->lineTransparency())+"\n"); |
||
1338 | PutDoc("/SMask /None\n/AIS false\n/OPM 1\n"); |
||
1339 | PutDoc("/BM /Normal\n>>\nendobj\n"); |
||
1340 | PutPage("/"+ShName+" gs\n"); |
||
1341 | } |
||
4016 | fschmid | 1342 | PutPage(putColor(ite->lineColor(), ite->lineShade(), true)); |
3133 | fschmid | 1343 | PutPage(SetClipPathArray(&arrow)); |
1344 | PutPage("h\nf*\n"); |
||
1345 | } |
||
4061 | craig | 1346 | if (ite->endArrowIndex() != 0) |
3133 | fschmid | 1347 | { |
1348 | QWMatrix arrowTrans; |
||
4264 | craig | 1349 | FPointArray arrow = (*doc.arrowStyles.at(ite->endArrowIndex()-1)).points.copy(); |
3934 | cbradney | 1350 | arrowTrans.translate(ite->width(), 0); |
4580 | cbradney | 1351 | arrowTrans.scale(ite->lineWidth(), ite->lineWidth()); |
3133 | fschmid | 1352 | arrow.map(arrowTrans); |
4264 | craig | 1353 | if ((ite->lineTransparency() != 0) && (Options.Version >= 14)) |
3133 | fschmid | 1354 | { |
1355 | StartObj(ObjCounter); |
||
4229 | craig | 1356 | QString ShName = ResNam+QString::number(ResCount); |
3133 | fschmid | 1357 | Transpar[ShName] = ObjCounter; |
1358 | ResCount++; |
||
1359 | ObjCounter++; |
||
1360 | PutDoc("<< /Type /ExtGState\n"); |
||
1361 | PutDoc("/CA "+FToStr(1.0 - ite->lineTransparency())+"\n"); |
||
1362 | PutDoc("/ca "+FToStr(1.0 - ite->lineTransparency())+"\n"); |
||
1363 | PutDoc("/SMask /None\n/AIS false\n/OPM 1\n"); |
||
1364 | PutDoc("/BM /Normal\n>>\nendobj\n"); |
||
1365 | PutPage("/"+ShName+" gs\n"); |
||
1366 | } |
||
4016 | fschmid | 1367 | PutPage(putColor(ite->lineColor(), ite->lineShade(), true)); |
3133 | fschmid | 1368 | PutPage(SetClipPathArray(&arrow)); |
1369 | PutPage("h\nf*\n"); |
||
1370 | } |
||
1371 | break; |
||
3232 | cbradney | 1372 | case PageItem::ItemType1: |
1373 | case PageItem::ItemType3: |
||
3133 | fschmid | 1374 | case PageItem::Polygon: |
1375 | if (ite->GrType != 0) |
||
1376 | PutPage(PDF_Gradient(ite)); |
||
1377 | else |
||
1378 | { |
||
4546 | subik | 1379 | if (ite->fillColor() != CommonStrings::None) |
3133 | fschmid | 1380 | { |
1381 | PutPage(SetClipPath(ite)); |
||
1382 | PutPage("h\nf*\n"); |
||
1383 | } |
||
1384 | } |
||
4546 | subik | 1385 | if ((ite->lineColor() != CommonStrings::None) || (!ite->NamedLStyle.isEmpty())) |
3133 | fschmid | 1386 | { |
4580 | cbradney | 1387 | if ((ite->NamedLStyle.isEmpty()) && (ite->lineWidth() != 0.0)) |
3133 | fschmid | 1388 | { |
1389 | PutPage(SetClipPath(ite)); |
||
1390 | PutPage("h\nS\n"); |
||
1391 | } |
||
1392 | else |
||
1393 | { |
||
4264 | craig | 1394 | multiLine ml = doc.MLineStyles[ite->NamedLStyle]; |
3133 | fschmid | 1395 | for (int it = ml.size()-1; it > -1; it--) |
1396 | { |
||
1397 | PutPage(setStrokeMulti(&ml[it])); |
||
1398 | PutPage(SetClipPath(ite)); |
||
1399 | PutPage("h\nS\n"); |
||
1400 | } |
||
1401 | } |
||
1402 | } |
||
1403 | break; |
||
1404 | case PageItem::PolyLine: |
||
4658 | fschmid | 1405 | if (ite->PoLine.size() > 4) // && ((ite->PoLine.point(0) != ite->PoLine.point(1)) || (ite->PoLine.point(2) != ite->PoLine.point(3)))) |
3133 | fschmid | 1406 | { |
1407 | if (ite->GrType != 0) |
||
1408 | PutPage(PDF_Gradient(ite)); |
||
1409 | else |
||
1410 | { |
||
4546 | subik | 1411 | if (ite->fillColor() != CommonStrings::None) |
3133 | fschmid | 1412 | { |
1413 | PutPage(SetClipPath(ite)); |
||
1414 | PutPage("h\nf*\n"); |
||
1415 | } |
||
1416 | } |
||
1417 | } |
||
4546 | subik | 1418 | if ((ite->lineColor() != CommonStrings::None) || (!ite->NamedLStyle.isEmpty())) |
3133 | fschmid | 1419 | { |
4580 | cbradney | 1420 | if ((ite->NamedLStyle.isEmpty()) && (ite->lineWidth() != 0.0)) |
3133 | fschmid | 1421 | { |
1422 | PutPage(SetClipPath(ite, false)); |
||
1423 | PutPage("S\n"); |
||
1424 | } |
||
1425 | else |
||
1426 | { |
||
4264 | craig | 1427 | multiLine ml = doc.MLineStyles[ite->NamedLStyle]; |
3133 | fschmid | 1428 | for (int it = ml.size()-1; it > -1; it--) |
1429 | { |
||
1430 | PutPage(setStrokeMulti(&ml[it])); |
||
1431 | PutPage(SetClipPath(ite, false)); |
||
1432 | PutPage("S\n"); |
||
1433 | } |
||
1434 | } |
||
1435 | } |
||
4061 | craig | 1436 | if (ite->startArrowIndex() != 0) |
3133 | fschmid | 1437 | { |
1438 | FPoint Start = ite->PoLine.point(0); |
||
1439 | for (uint xx = 1; xx < ite->PoLine.size(); xx += 2) |
||
1440 | { |
||
1441 | FPoint Vector = ite->PoLine.point(xx); |
||
1442 | if ((Start.x() != Vector.x()) || (Start.y() != Vector.y())) |
||
1443 | { |
||
1444 | double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI); |
||
1445 | QWMatrix arrowTrans; |
||
4264 | craig | 1446 | FPointArray arrow = (*doc.arrowStyles.at(ite->startArrowIndex()-1)).points.copy(); |
3133 | fschmid | 1447 | arrowTrans.translate(Start.x(), Start.y()); |
1448 | arrowTrans.rotate(r); |
||
4580 | cbradney | 1449 | arrowTrans.scale(ite->lineWidth(), ite->lineWidth()); |
3133 | fschmid | 1450 | arrow.map(arrowTrans); |
4264 | craig | 1451 | if ((ite->lineTransparency() != 0) && (Options.Version >= 14)) |
3133 | fschmid | 1452 | { |
1453 | StartObj(ObjCounter); |
||
4229 | craig | 1454 | QString ShName = ResNam+QString::number(ResCount); |
3133 | fschmid | 1455 | Transpar[ShName] = ObjCounter; |
1456 | ResCount++; |
||
1457 | ObjCounter++; |
||
1458 | PutDoc("<< /Type /ExtGState\n"); |
||
1459 | PutDoc("/CA "+FToStr(1.0 - ite->lineTransparency())+"\n"); |
||
1460 | PutDoc("/ca "+FToStr(1.0 - ite->lineTransparency())+"\n"); |
||
1461 | PutDoc("/SMask /None\n/AIS false\n/OPM 1\n"); |
||
1462 | PutDoc("/BM /Normal\n>>\nendobj\n"); |
||
1463 | PutPage("/"+ShName+" gs\n"); |
||
1464 | } |
||
4016 | fschmid | 1465 | PutPage(putColor(ite->lineColor(), ite->lineShade(), true)); |
3133 | fschmid | 1466 | PutPage(SetClipPathArray(&arrow)); |
1467 | PutPage("h\nf*\n"); |
||
1468 | break; |
||
1469 | } |
||
1470 | } |
||
1471 | } |
||
4061 | craig | 1472 | if (ite->endArrowIndex() != 0) |
3133 | fschmid | 1473 | { |
1474 | FPoint End = ite->PoLine.point(ite->PoLine.size()-2); |
||
1475 | for (uint xx = ite->PoLine.size()-1; xx > 0; xx -= 2) |
||
1476 | { |
||
1477 | FPoint Vector = ite->PoLine.point(xx); |
||
1478 | if ((End.x() != Vector.x()) || (End.y() != Vector.y())) |
||
1479 | { |
||
1480 | double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI); |
||
1481 | QWMatrix arrowTrans; |
||
4264 | craig | 1482 | FPointArray arrow = (*doc.arrowStyles.at(ite->endArrowIndex()-1)).points.copy(); |
3133 | fschmid | 1483 | arrowTrans.translate(End.x(), End.y()); |
1484 | arrowTrans.rotate(r); |
||
4580 | cbradney | 1485 | arrowTrans.scale(ite->lineWidth(), ite->lineWidth()); |
3133 | fschmid | 1486 | arrow.map(arrowTrans); |
4264 | craig | 1487 | if ((ite->lineTransparency() != 0) && (Options.Version >= 14)) |
3133 | fschmid | 1488 | { |
1489 | StartObj(ObjCounter); |
||
4229 | craig | 1490 | QString ShName = ResNam+QString::number(ResCount); |
3133 | fschmid | 1491 | Transpar[ShName] = ObjCounter; |
1492 | ResCount++; |
||
1493 | ObjCounter++; |
||
1494 | PutDoc("<< /Type /ExtGState\n"); |
||
1495 | PutDoc("/CA "+FToStr(1.0 - ite->lineTransparency())+"\n"); |
||
1496 | PutDoc("/ca "+FToStr(1.0 - ite->lineTransparency())+"\n"); |
||
1497 | PutDoc("/SMask /None\n/AIS false\n/OPM 1\n"); |
||
1498 | PutDoc("/BM /Normal\n>>\nendobj\n"); |
||
1499 | PutPage("/"+ShName+" gs\n"); |
||
1500 | } |
||
4016 | fschmid | 1501 | PutPage(putColor(ite->lineColor(), ite->lineShade(), true)); |
3133 | fschmid | 1502 | PutPage(SetClipPathArray(&arrow)); |
1503 | PutPage("h\nf*\n"); |
||
1504 | break; |
||
1505 | } |
||
1506 | } |
||
1507 | } |
||
1508 | break; |
||
1509 | case PageItem::PathText: |
||
1510 | if (ite->PoShow) |
||
1511 | { |
||
1512 | if (ite->PoLine.size() > 3) |
||
1513 | { |
||
1514 | PutPage("q\n"); |
||
4546 | subik | 1515 | if ((ite->lineColor() != CommonStrings::None) || (!ite->NamedLStyle.isEmpty())) |
3133 | fschmid | 1516 | { |
4580 | cbradney | 1517 | if ((ite->NamedLStyle.isEmpty()) && (ite->lineWidth() != 0.0)) |
3133 | fschmid | 1518 | { |
1519 | PutPage(SetClipPath(ite, false)); |
||
1520 | PutPage("S\n"); |
||
1521 | } |
||
1522 | else |
||
1523 | { |
||
4264 | craig | 1524 | multiLine ml = doc.MLineStyles[ite->NamedLStyle]; |
4546 | subik | 1525 | for (int it = ml.size()-1; |
3133 | fschmid | 1526 | it > -1; it--) |
1527 | { |
||
1528 | PutPage(setStrokeMulti(&ml[it])); |
||
1529 | PutPage(SetClipPath(ite, false)); |
||
1530 | PutPage("S\n"); |
||
1531 | } |
||
1532 | } |
||
1533 | } |
||
1534 | PutPage("Q\n"); |
||
1535 | } |
||
1536 | } |
||
3200 | cbradney | 1537 | PutPage(setTextSt(ite, pag->pageNr(), pag)); |
3133 | fschmid | 1538 | break; |
1539 | } |
||
1540 | PutPage("Q\n"); |
||
1541 | StartObj(ObjCounter); |
||
1542 | ObjCounter++; |
||
1543 | PutDoc("<<\n/Type /XObject\n/Subtype /Form\n/FormType 1\n"); |
||
3200 | cbradney | 1544 | PutDoc("/BBox [ 0 0 "+FToStr(ActPageP->width())+" "+FToStr(ActPageP->height())+" ]\n"); |
3133 | fschmid | 1545 | PutDoc("/Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n"); |
1546 | if (Seite.ImgObjects.count() != 0) |
||
1547 | { |
||
1548 | PutDoc("/XObject <<\n"); |
||
1549 | QMap<QString,int>::Iterator it; |
||
1550 | for (it = Seite.ImgObjects.begin(); it != Seite.ImgObjects.end(); ++it) |
||
4229 | craig | 1551 | PutDoc("/"+it.key()+" "+QString::number(it.data())+" 0 R\n"); |
3133 | fschmid | 1552 | PutDoc(">>\n"); |
1553 | } |
||
1554 | if (Seite.FObjects.count() != 0) |
||
1555 | { |
||
1556 | PutDoc("/Font << \n"); |
||
1557 | QMap<QString,int>::Iterator it2; |
||
1558 | for (it2 = Seite.FObjects.begin(); it2 != Seite.FObjects.end(); ++it2) |
||
4229 | craig | 1559 | PutDoc("/"+it2.key()+" "+QString::number(it2.data())+" 0 R\n"); |
3133 | fschmid | 1560 | PutDoc(">>\n"); |
1561 | } |
||
1562 | if (Shadings.count() != 0) |
||
1563 | { |
||
1564 | PutDoc("/Shading << \n"); |
||
1565 | QMap<QString,int>::Iterator it3; |
||
1566 | for (it3 = Shadings.begin(); it3 != Shadings.end(); ++it3) |
||
4229 | craig | 1567 | PutDoc("/"+it3.key()+" "+QString::number(it3.data())+" 0 R\n"); |
3133 | fschmid | 1568 | PutDoc(">>\n"); |
1569 | } |
||
1570 | if (Transpar.count() != 0) |
||
1571 | { |
||
1572 | PutDoc("/ExtGState << \n"); |
||
1573 | QMap<QString,int>::Iterator it3t; |
||
1574 | for (it3t = Transpar.begin(); it3t != Transpar.end(); ++it3t) |
||
4229 | craig | 1575 | PutDoc("/"+it3t.key()+" "+QString::number(it3t.data())+" 0 R\n"); |
3133 | fschmid | 1576 | PutDoc(">>\n"); |
1577 | } |
||
1578 | if ((ICCProfiles.count() != 0) || (spotMap.count() != 0)) |
||
1579 | { |
||
1580 | PutDoc("/ColorSpace << \n"); |
||
1581 | QMap<QString,ICCD>::Iterator it3c; |
||
1582 | if (ICCProfiles.count() != 0) |
||
1583 | { |
||
1584 | for (it3c = ICCProfiles.begin(); it3c != ICCProfiles.end(); ++it3c) |
||
4229 | craig | 1585 | PutDoc("/"+it3c.data().ResName+" "+QString::number(it3c.data().ResNum)+" 0 R\n"); |
3133 | fschmid | 1586 | } |
1587 | QMap<QString,SpotC>::Iterator it3sc; |
||
1588 | if (spotMap.count() != 0) |
||
1589 | { |
||
1590 | for (it3sc = spotMap.begin(); it3sc != spotMap.end(); ++it3sc) |
||
4229 | craig | 1591 | PutDoc("/"+it3sc.data().ResName+" "+QString::number(it3sc.data().ResNum)+" 0 R\n"); |
3133 | fschmid | 1592 | } |
1593 | PutDoc(">>\n"); |
||
1594 | } |
||
1595 | PutDoc(">>\n"); |
||
4264 | craig | 1596 | if ((Options.Compress) && (CompAvail)) |
3133 | fschmid | 1597 | Inhalt = CompressStr(&Inhalt); |
4229 | craig | 1598 | PutDoc("/Length "+QString::number(Inhalt.length()+1)); |
4264 | craig | 1599 | if ((Options.Compress) && (CompAvail)) |
3133 | fschmid | 1600 | PutDoc("\n/Filter /FlateDecode"); |
4229 | craig | 1601 | PutDoc(" >>\nstream\n"+EncStream(Inhalt, ObjCounter-1)+"\nendstream\nendobj\n"); |
1602 | QString name = pag->PageNam.simplifyWhiteSpace().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" ) + QString::number(ite->ItemNr); |
||
3133 | fschmid | 1603 | Seite.XObjects[name] = ObjCounter-1; |
1604 | } |
||
4264 | craig | 1605 | if ((Options.Version == 15) && (Options.useLayers)) |
3133 | fschmid | 1606 | PutPage("EMC\n"); |
1607 | } |
||
1608 | Lnr++; |
||
1609 | } |
||
1610 | } |
||
1611 | |||
4241 | craig | 1612 | void PDFlib::PDF_Begin_Page(const Page* pag, QPixmap pm) |
3133 | fschmid | 1613 | { |
1614 | QString tmp; |
||
1615 | ActPageP = pag; |
||
1616 | Inhalt = ""; |
||
1617 | Seite.AObjects.clear(); |
||
4264 | craig | 1618 | if (Options.Thumbnails) |
3133 | fschmid | 1619 | { |
1620 | ScImage img = pm.convertToImage(); |
||
5234 | fschmid | 1621 | QByteArray array = img.ImageToArray(); |
4264 | craig | 1622 | if ((Options.Compress) && (CompAvail)) |
5234 | fschmid | 1623 | array = CompressArray(&array); |
3133 | fschmid | 1624 | StartObj(ObjCounter); |
4229 | craig | 1625 | PutDoc("<<\n/Width "+QString::number(img.width())+"\n"); |
1626 | PutDoc("/Height "+QString::number(img.height())+"\n"); |
||
3133 | fschmid | 1627 | PutDoc("/ColorSpace /DeviceRGB\n/BitsPerComponent 8\n"); |
5234 | fschmid | 1628 | |
1629 | PutDoc("/Length "+QString::number(array.size()+1)+"\n"); |
||
4264 | craig | 1630 | if ((Options.Compress) && (CompAvail)) |
3133 | fschmid | 1631 | PutDoc("/Filter /FlateDecode\n"); |
5234 | fschmid | 1632 | PutDoc(">>\nstream\n"); |
1633 | PutDoc(EncStreamArray(array, ObjCounter)); |
||
1634 | PutDoc("\nendstream\nendobj\n"); |
||
3133 | fschmid | 1635 | Seite.Thumb = ObjCounter; |
1636 | ObjCounter++; |
||
1637 | } |
||
1638 | } |
||
1639 | |||
1640 | void PDFlib::PDF_End_Page() |
||
1641 | { |
||
3200 | cbradney | 1642 | uint PgNr = ActPageP->pageNr(); |
3133 | fschmid | 1643 | Seite.ObjNum = ObjCounter; |
4084 | cbradney | 1644 | WritePDFStream(Inhalt); |
3133 | fschmid | 1645 | StartObj(ObjCounter); |
1646 | PutDoc("<<\n/Type /Page\n/Parent 4 0 R\n"); |
||
3200 | cbradney | 1647 | PutDoc("/MediaBox [0 0 "+FToStr(ActPageP->width())+" "+FToStr(ActPageP->height())+"]\n"); |
4264 | craig | 1648 | PutDoc("/TrimBox ["+FToStr(Options.BleedLeft)+" "+FToStr(Options.BleedBottom)+ |
1649 | " "+FToStr(ActPageP->width()-Options.BleedRight)+" "+FToStr(ActPageP->height()-Options.BleedTop)+"]\n"); |
||
1650 | PutDoc("/Rotate "+QString::number(Options.RotateDeg)+"\n"); |
||
4229 | craig | 1651 | PutDoc("/Contents "+QString::number(Seite.ObjNum)+" 0 R\n"); |
4264 | craig | 1652 | if (Options.Thumbnails) |
4229 | craig | 1653 | PutDoc("/Thumb "+QString::number(Seite.Thumb)+" 0 R\n"); |
3133 | fschmid | 1654 | if (Seite.AObjects.count() != 0) |
1655 | { |
||
1656 | PutDoc("/Annots [ "); |
||
1657 | for (uint b = 0; b < Seite.AObjects.count(); ++b) |
||
4229 | craig | 1658 | PutDoc(QString::number(Seite.AObjects[b])+" 0 R "); |
3133 | fschmid | 1659 | PutDoc("]\n"); |
1660 | } |
||
4264 | craig | 1661 | if (Options.PresentMode) |
3133 | fschmid | 1662 | { |
4932 | fschmid | 1663 | if (Options.PresentVals[PgNr].pageViewDuration > 0) |
1664 | PutDoc("/Dur "+QString::number(Options.PresentVals[PgNr].pageViewDuration)+"\n"); |
||
4264 | craig | 1665 | if (Options.PresentVals[PgNr].effectType != 0) |
3133 | fschmid | 1666 | { |
1667 | PutDoc("/Trans << /Type /Trans\n"); |
||
4264 | craig | 1668 | PutDoc("/D "+QString::number(Options.PresentVals[PgNr].pageEffectDuration)+"\n"); |
1669 | switch (Options.PresentVals[PgNr].effectType) |
||
3133 | fschmid | 1670 | { |
1671 | case 1: |
||
1672 | PutDoc("/S /Blinds\n"); |
||
4264 | craig | 1673 | PutDoc(Options.PresentVals[PgNr].Dm == 0 ? "/Dm /H\n" : "/Dm /V\n"); |
3133 | fschmid | 1674 | break; |
1675 | case 2: |
||
1676 | PutDoc("/S /Box\n"); |
||
4264 | craig | 1677 | PutDoc(Options.PresentVals[PgNr].M == 0 ? "/M /I\n" : "/M /O\n"); |
3133 | fschmid | 1678 | break; |
1679 | case 3: |
||
1680 | PutDoc("/S /Dissolve\n"); |
||
1681 | break; |
||
1682 | case 4: |
||
1683 | PutDoc("/S /Glitter\n"); |
||
1684 | PutDoc("/Di "); |
||
4264 | craig | 1685 | switch (Options.PresentVals[PgNr].Di) |
3133 | fschmid | 1686 | { |
1687 | case 0: |
||
1688 | PutDoc("0"); |
||
1689 | break; |
||
1690 | case 1: |
||
1691 | PutDoc("270"); |
||
1692 | break; |
||
1693 | case 4: |
||
1694 | PutDoc("315"); |
||
1695 | break; |
||
1696 | default: |
||
1697 | PutDoc("0"); |
||
1698 | break; |
||
1699 | } |
||
1700 | PutDoc("\n"); |
||
1701 | break; |
||
1702 | case 5: |
||
1703 | PutDoc("/S /Split\n"); |
||
4264 | craig | 1704 | PutDoc(Options.PresentVals[PgNr].Dm == 0 ? "/Dm /H\n" : "/Dm /V\n"); |
1705 | PutDoc(Options.PresentVals[PgNr].M == 0 ? "/M /I\n" : "/M /O\n"); |
||
3133 | fschmid | 1706 | break; |
1707 | case 6: |
||
1708 | PutDoc("/S /Wipe\n"); |
||
1709 | PutDoc("/Di "); |
||
4264 | craig | 1710 | switch (Options.PresentVals[PgNr].Di) |
3133 | fschmid | 1711 | { |
1712 | case 0: |
||
1713 | PutDoc("0"); |
||
1714 | break; |
||
1715 | case 1: |
||
1716 | PutDoc("270"); |
||
1717 | break; |
||
1718 | case 2: |
||
1719 | PutDoc("90"); |
||
1720 | break; |
||
1721 | case 3: |
||
1722 | PutDoc("180"); |
||
1723 | break; |
||
1724 | default: |
||
1725 | PutDoc("0"); |
||
1726 | break; |
||
1727 | } |
||
1728 | PutDoc("\n"); |
||
1729 | break; |
||
1730 | } |
||
1731 | PutDoc(">>\n"); |
||
1732 | } |
||
1733 | } |
||
1734 | PutDoc(">>\nendobj\n"); |
||
1735 | PageTree.Count++; |
||
1736 | PageTree.Kids.append(ObjCounter); |
||
1737 | ObjCounter++; |
||
1738 | } |
||
1739 | |||
4241 | craig | 1740 | void PDFlib::PDF_ProcessPage(const Page* pag, uint PNr, bool clip) |
3133 | fschmid | 1741 | { |
1742 | QString tmp; |
||
1743 | ActPageP = pag; |
||
1744 | PageItem* ite; |
||
1745 | QPtrList<PageItem> PItems; |
||
1746 | int Lnr = 0; |
||
1747 | struct Layer ll; |
||
1748 | ll.isPrintable = false; |
||
1749 | ll.LNr = 0; |
||
4264 | craig | 1750 | if (Options.UseLPI) |
3133 | fschmid | 1751 | PutPage("/"+HTName+" gs\n"); |
4264 | craig | 1752 | if ( (Options.MirrorH) && (!pag->MPageNam.isEmpty()) ) |
3200 | cbradney | 1753 | PutPage("-1 0 0 1 "+FToStr(ActPageP->width() |