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