Rev 16732 | Rev 16744 | 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 | /*************************************************************************** |
14043 | jghali | 8 | pdflib_core.cpp - description |
9 | ------------------- |
||
10 | begin : Sat Jan 19 2002 |
||
11 | copyright : (C) 2002 by Franz Schmid |
||
12 | email : Franz.Schmid@altmuehlnet.de |
||
3133 | fschmid | 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 | |||
10054 | craig | 24 | #include "pdflib_core.h" |
3133 | fschmid | 25 | |
26 | #include "scconfig.h" |
||
27 | |||
14170 | jghali | 28 | #if defined(_MSC_VER) |
29 | #define _USE_MATH_DEFINES |
||
30 | #endif |
||
12080 | avox | 31 | #include <cmath> |
32 | #include <cstdlib> |
||
4229 | craig | 33 | #include <string> |
12080 | avox | 34 | #ifdef HAVE_UNISTD_H |
35 | #include <unistd.h> |
||
36 | #endif |
||
37 | |||
38 | #include "rc4.h" |
||
39 | |||
40 | #include <QByteArray> |
||
10223 | cbradney | 41 | #include <QDateTime> |
10004 | fschmid | 42 | #include <QDataStream> |
12080 | avox | 43 | #include <QDebug> |
10223 | cbradney | 44 | #include <QDir> |
12080 | avox | 45 | #include <QFileInfo> |
46 | #include <QImage> |
||
9803 | fschmid | 47 | #include <QList> |
11453 | fschmid | 48 | #include <QPainterPath> |
8501 | cbradney | 49 | #include <QPixmap> |
12080 | avox | 50 | #include <QRect> |
51 | #include <QRegExp> |
||
52 | #include <QStack> |
||
53 | #include <QString> |
||
13839 | fschmid | 54 | #include <QTemporaryFile> |
10614 | cbradney | 55 | #include <QTextCodec> |
14043 | jghali | 56 | #include <QtXml> |
57 | #include <QUuid> |
||
3133 | fschmid | 58 | |
10601 | mrdocs | 59 | #include "cmsettings.h" |
4028 | cbradney | 60 | #include "commonstrings.h" |
3133 | fschmid | 61 | #include "pageitem.h" |
10601 | mrdocs | 62 | #include "pageitem_textframe.h" |
16258 | fschmid | 63 | #include "pageitem_group.h" |
10212 | cbradney | 64 | #include "pdfoptions.h" |
65 | #include "prefscontext.h" |
||
66 | #include "prefsmanager.h" |
||
67 | #include "sccolor.h" |
||
68 | #include "sccolorengine.h" |
||
69 | #include "scfonts.h" |
||
16736 | jghali | 70 | #include "scpage.h" |
5917 | jghali | 71 | #include "scpaths.h" |
10212 | cbradney | 72 | #include "scpattern.h" |
3133 | fschmid | 73 | #include "scribus.h" |
5243 | cbradney | 74 | #include "scribuscore.h" |
3699 | cbradney | 75 | #include "scribusdoc.h" |
11599 | jghali | 76 | #include "scstreamfilter_flate.h" |
77 | #include "scstreamfilter_rc4.h" |
||
10212 | cbradney | 78 | #include "text/nlsconfig.h" |
3133 | fschmid | 79 | #include "util.h" |
11605 | jghali | 80 | #include "util_file.h" |
10212 | cbradney | 81 | #include "util_formats.h" |
10203 | cbradney | 82 | #include "util_math.h" |
12517 | fschmid | 83 | #include "util_ghostscript.h" |
16736 | jghali | 84 | |
13839 | fschmid | 85 | #ifdef HAVE_OSG |
14930 | fschmid | 86 | #include "third_party/prc/exportPRC.h" |
13839 | fschmid | 87 | #endif |
3133 | fschmid | 88 | |
16736 | jghali | 89 | #include "ui/bookmwin.h" |
90 | #include "ui/bookmarkpalette.h" |
||
91 | #include "ui/multiprogressdialog.h" |
||
92 | |||
3133 | fschmid | 93 | using namespace std; |
94 | |||
12096 | jghali | 95 | #if defined(_WIN32) |
96 | #undef GetObject |
||
97 | #endif |
||
3133 | fschmid | 98 | |
6562 | fschmid | 99 | |
10054 | craig | 100 | PDFLibCore::PDFLibCore(ScribusDoc & docu) |
4264 | craig | 101 | : QObject(&docu), |
4223 | craig | 102 | doc(docu), |
103 | ActPageP(0), |
||
14925 | cbradney | 104 | Options(doc.pdfOptions()), |
4223 | craig | 105 | Bvie(0), |
13764 | jghali | 106 | ucs2Codec(0), |
4223 | craig | 107 | ObjCounter(7), |
108 | ResNam("RE"), |
||
109 | ResCount(0), |
||
110 | NDnam("LI"), |
||
111 | NDnum(0), |
||
10553 | fschmid | 112 | KeyGen(""), |
113 | OwnerKey(""), |
||
114 | UserKey(""), |
||
115 | FileID(""), |
||
116 | EncryKey(""), |
||
4223 | craig | 117 | Encrypt(0), |
118 | KeyLen(5), |
||
119 | colorsToUse(), |
||
120 | spotNam("Spot"), |
||
121 | spotCount(0), |
||
4225 | craig | 122 | progressDialog(0), |
4223 | craig | 123 | abortExport(false), |
5243 | cbradney | 124 | usingGUI(ScCore->usingGUI()) |
3133 | fschmid | 125 | { |
10553 | fschmid | 126 | KeyGen.resize(32); |
127 | OwnerKey.resize(32); |
||
128 | UserKey.resize(32); |
||
129 | FileID.resize(16); |
||
130 | EncryKey.resize(5); |
||
3133 | fschmid | 131 | Catalog.Outlines = 2; |
132 | Catalog.PageTree = 3; |
||
133 | Catalog.Dest = 4; |
||
134 | PageTree.Count = 0; |
||
135 | Outlines.First = 0; |
||
136 | Outlines.Last = 0; |
||
137 | Outlines.Count = 0; |
||
138 | Seite.ObjNum = 0; |
||
139 | Seite.Thumb = 0; |
||
140 | int kg_array[] = {0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, |
||
141 | 0x01, 0x08, 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80, 0x2f, 0x0c, 0xa9, 0xfe, |
||
142 | 0x64, 0x53, 0x69, 0x7a}; |
||
143 | for (int a = 0; a < 32; ++a) |
||
144 | KeyGen[a] = kg_array[a]; |
||
4028 | cbradney | 145 | if (usingGUI) |
146 | { |
||
10508 | cbradney | 147 | progressDialog = new MultiProgressDialog( tr("Saving PDF"), CommonStrings::tr_Cancel, doc.scMW()); |
4224 | craig | 148 | Q_CHECK_PTR(progressDialog); |
149 | QStringList barNames, barTexts; |
||
150 | barNames << "EMP" << "EP" << "ECPI"; |
||
5370 | cbradney | 151 | barTexts << tr("Exporting Master Page:") << tr("Exporting Page:") << tr("Exporting Items on Current Page:"); |
9803 | fschmid | 152 | QList<bool> barsNumeric; |
5370 | cbradney | 153 | barsNumeric << true << true << false; |
154 | progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric); |
||
8559 | subik | 155 | connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested())); |
4028 | cbradney | 156 | } |
3133 | fschmid | 157 | } |
158 | |||
10054 | craig | 159 | PDFLibCore::~PDFLibCore() |
4224 | craig | 160 | { |
161 | delete progressDialog; |
||
162 | } |
||
163 | |||
4229 | craig | 164 | static inline QString FToStr(double c) |
165 | { |
||
15283 | fschmid | 166 | double v = c; |
167 | if (fabs(c) < 0.0000001) |
||
168 | v = 0.0; |
||
169 | return QString::number(v, 'f', 5); |
||
4229 | craig | 170 | }; |
171 | |||
10054 | craig | 172 | bool PDFLibCore::doExport(const QString& fn, const QString& nam, int Components, |
4264 | craig | 173 | const std::vector<int> & pageNs, const QMap<int,QPixmap> & thumbs) |
3133 | fschmid | 174 | { |
175 | QPixmap pm; |
||
11060 | jghali | 176 | bool ret = false, error = false; |
177 | int pc_exportpages=0; |
||
178 | int pc_exportmasterpages=0; |
||
4224 | craig | 179 | if (usingGUI) |
180 | progressDialog->show(); |
||
5387 | avox | 181 | QMap<QString, QMap<uint, FPointArray> > usedFonts; |
182 | usedFonts.clear(); |
||
183 | doc.getUsedFonts(usedFonts); |
||
13764 | jghali | 184 | ucs2Codec = QTextCodec::codecForName("ISO-10646-UCS-2"); |
13791 | pierre | 185 | if(!ucs2Codec) |
186 | ucs2Codec = QTextCodec::codecForName("UTF-16"); |
||
13764 | jghali | 187 | if (!ucs2Codec) |
188 | { |
||
13791 | pierre | 189 | PDF_Error( tr("Qt build miss both \"UTF-16\" and \"ISO-10646-UCS-2\" text codecs, pdf export is not possible") ); |
13764 | jghali | 190 | return false; |
191 | } |
||
13955 | cbradney | 192 | if (PDF_Begin_Doc(fn, PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts, usedFonts, doc.scMW()->bookmarkPalette->BView)) |
3133 | fschmid | 193 | { |
194 | QMap<int, int> pageNsMpa; |
||
195 | for (uint a = 0; a < pageNs.size(); ++a) |
||
196 | { |
||
14653 | jghali | 197 | pageNsMpa.insert(doc.MasterNames[doc.DocPages.at(pageNs[a]-1)->MPageNam], 0); |
3133 | fschmid | 198 | } |
4028 | cbradney | 199 | if (usingGUI) |
3133 | fschmid | 200 | { |
4028 | cbradney | 201 | progressDialog->setOverallTotalSteps(pageNsMpa.count()+pageNs.size()); |
202 | progressDialog->setTotalSteps("EMP", pageNsMpa.count()); |
||
203 | progressDialog->setTotalSteps("EP", pageNs.size()); |
||
204 | progressDialog->setOverallProgress(0); |
||
205 | progressDialog->setProgress("EMP", 0); |
||
206 | progressDialog->setProgress("EP", 0); |
||
207 | } |
||
10018 | fschmid | 208 | for (int ap = 0; ap < doc.MasterPages.count() && !abortExport; ++ap) |
4028 | cbradney | 209 | { |
4264 | craig | 210 | if (doc.MasterItems.count() != 0) |
3133 | fschmid | 211 | { |
212 | if (pageNsMpa.contains(ap)) |
||
213 | { |
||
5243 | cbradney | 214 | qApp->processEvents(); |
11060 | jghali | 215 | if (!PDF_TemplatePage(doc.MasterPages.at(ap))) |
216 | error = abortExport = true; |
||
4028 | cbradney | 217 | ++pc_exportmasterpages; |
3133 | fschmid | 218 | } |
219 | } |
||
4546 | subik | 220 | if (usingGUI) |
221 | { |
||
4028 | cbradney | 222 | progressDialog->setProgress("EMP", pc_exportmasterpages); |
223 | progressDialog->setOverallProgress(pc_exportmasterpages+pc_exportpages); |
||
224 | } |
||
3133 | fschmid | 225 | } |
4028 | cbradney | 226 | for (uint a = 0; a < pageNs.size() && !abortExport; ++a) |
3133 | fschmid | 227 | { |
14925 | cbradney | 228 | if (doc.pdfOptions().Thumbnails) |
3133 | fschmid | 229 | pm = thumbs[pageNs[a]]; |
5243 | cbradney | 230 | qApp->processEvents(); |
4028 | cbradney | 231 | if (abortExport) break; |
11060 | jghali | 232 | |
14653 | jghali | 233 | PDF_Begin_Page(doc.DocPages.at(pageNs[a]-1), pm); |
5243 | cbradney | 234 | qApp->processEvents(); |
4028 | cbradney | 235 | if (abortExport) break; |
11060 | jghali | 236 | |
14925 | cbradney | 237 | if (!PDF_ProcessPage(doc.DocPages.at(pageNs[a]-1), pageNs[a]-1, doc.pdfOptions().doClip)) |
11060 | jghali | 238 | error = abortExport = true; |
5243 | cbradney | 239 | qApp->processEvents(); |
4028 | cbradney | 240 | if (abortExport) break; |
11060 | jghali | 241 | |
15444 | craig | 242 | PDF_End_Page(a); |
4028 | cbradney | 243 | pc_exportpages++; |
244 | if (usingGUI) |
||
245 | { |
||
246 | progressDialog->setProgress("EP", pc_exportpages); |
||
247 | progressDialog->setOverallProgress(pc_exportmasterpages+pc_exportpages); |
||
248 | } |
||
3133 | fschmid | 249 | } |
4028 | cbradney | 250 | ret = true;//Even when aborting we return true. Dont want that "couldnt write msg" |
251 | if (!abortExport) |
||
252 | { |
||
14925 | cbradney | 253 | if ((doc.pdfOptions().Version == PDFOptions::PDFVersion_X3) || (doc.pdfOptions().Version == PDFOptions::PDFVersion_X1a) || (doc.pdfOptions().Version == PDFOptions::PDFVersion_X4)) |
254 | ret = PDF_End_Doc(ScCore->PrinterProfiles[doc.pdfOptions().PrintProf], nam, Components); |
||
4028 | cbradney | 255 | else |
12387 | jghali | 256 | ret = PDF_End_Doc(); |
4028 | cbradney | 257 | } |
3133 | fschmid | 258 | else |
4028 | cbradney | 259 | closeAndCleanup(); |
3133 | fschmid | 260 | } |
4029 | cbradney | 261 | if (usingGUI) |
262 | progressDialog->close(); |
||
11060 | jghali | 263 | return (ret && !error); |
3133 | fschmid | 264 | } |
265 | |||
11060 | jghali | 266 | const QString& PDFLibCore::errorMessage(void) const |
267 | { |
||
268 | return ErrorMessage; |
||
269 | } |
||
270 | |||
11441 | jghali | 271 | bool PDFLibCore::exportAborted(void) const |
272 | { |
||
273 | return abortExport; |
||
274 | } |
||
275 | |||
10054 | craig | 276 | void PDFLibCore::StartObj(int nr) |
3133 | fschmid | 277 | { |
12080 | avox | 278 | for (int i=XRef.size(); i < nr; ++i) |
279 | XRef.append(0); |
||
280 | XRef[nr-1] = bytesWritten(); |
||
4229 | craig | 281 | PutDoc(QString::number(nr)+ " 0 obj\n"); |
3133 | fschmid | 282 | } |
283 | |||
4229 | craig | 284 | // Encode a string for inclusion in a |
285 | // PDF (literal) . |
||
12080 | avox | 286 | static QString PDFEncode(const QString & in) |
3133 | fschmid | 287 | { |
4229 | craig | 288 | QString tmp(""); |
8559 | subik | 289 | for (int d = 0; d < in.length(); ++d) |
3133 | fschmid | 290 | { |
4229 | craig | 291 | QChar cc(in.at(d)); |
4230 | craig | 292 | if ((cc == '(') || (cc == ')') || (cc == '\\')) |
293 | tmp += '\\'; |
||
3133 | fschmid | 294 | tmp += cc; |
295 | } |
||
296 | return tmp; |
||
297 | } |
||
298 | |||
12080 | avox | 299 | static QString blendMode(int code) |
300 | { |
||
301 | switch (code) |
||
302 | { |
||
303 | case 0: |
||
304 | return("Normal"); |
||
305 | break; |
||
306 | case 1: |
||
307 | return("Darken"); |
||
308 | break; |
||
309 | case 2: |
||
310 | return("Lighten"); |
||
311 | break; |
||
312 | case 3: |
||
313 | return("Multiply"); |
||
314 | break; |
||
315 | case 4: |
||
316 | return("Screen"); |
||
317 | break; |
||
318 | case 5: |
||
319 | return("Overlay"); |
||
320 | break; |
||
321 | case 6: |
||
322 | return("HardLight"); |
||
323 | break; |
||
324 | case 7: |
||
325 | return("SoftLight"); |
||
326 | break; |
||
327 | case 8: |
||
328 | return("Difference"); |
||
329 | break; |
||
330 | case 9: |
||
331 | return("Exclusion"); |
||
332 | break; |
||
333 | case 10: |
||
334 | return("ColorDodge"); |
||
335 | break; |
||
336 | case 11: |
||
337 | return("ColorBurn"); |
||
338 | break; |
||
339 | case 12: |
||
340 | return("Hue"); |
||
341 | break; |
||
342 | case 13: |
||
343 | return("Saturation"); |
||
344 | break; |
||
345 | case 14: |
||
346 | return("Color"); |
||
347 | break; |
||
348 | case 15: |
||
349 | return("Luminosity"); |
||
350 | break; |
||
351 | default: |
||
352 | return ""; |
||
353 | } |
||
14043 | jghali | 354 | } |
12080 | avox | 355 | |
10054 | craig | 356 | QByteArray PDFLibCore::EncodeUTF16(const QString &in) |
7328 | fschmid | 357 | { |
14900 | fschmid | 358 | // QString tmp(""); |
359 | // for (int d = 0; d < in.length(); ++d) |
||
360 | // { |
||
361 | // QChar cc(in.at(d)); |
||
362 | // if ((cc == '(') || (cc == ')') || (cc == '\\')) |
||
363 | // tmp += '\\'; |
||
364 | // tmp += cc; |
||
365 | // } |
||
366 | QString tmp = in; |
||
13764 | jghali | 367 | QByteArray cres = ucs2Codec->fromUnicode( tmp ); |
11455 | avox | 368 | #ifndef WORDS_BIGENDIAN |
369 | // on little endian systems we ned to swap bytes: |
||
7334 | fschmid | 370 | uchar sw; |
8559 | subik | 371 | for(int d = 0; d < cres.size()-1; d += 2) |
7334 | fschmid | 372 | { |
373 | sw = cres[d]; |
||
374 | cres[d] = cres[d+1]; |
||
375 | cres[d+1] = sw; |
||
376 | } |
||
11455 | avox | 377 | #endif |
7334 | fschmid | 378 | return cres; |
7328 | fschmid | 379 | } |
380 | |||
10054 | craig | 381 | QString PDFLibCore::EncStream(const QString & in, int ObjNum) |
3133 | fschmid | 382 | { |
4229 | craig | 383 | if (in.length() < 1) |
384 | return QString(""); |
||
4264 | craig | 385 | else if (!Options.Encrypt) |
4229 | craig | 386 | return in; |
387 | rc4_context_t rc4; |
||
388 | QString tmp(in); |
||
10553 | fschmid | 389 | QByteArray us(tmp.length(), ' '); |
390 | QByteArray ou(tmp.length(), ' '); |
||
8559 | subik | 391 | for (int a = 0; a < tmp.length(); ++a) |
8576 | jghali | 392 | us[a] = QChar(tmp.at(a)).cell(); |
11599 | jghali | 393 | QByteArray step1 = ComputeRC4Key(ObjNum); |
8562 | jghali | 394 | rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), qMin(KeyLen+5, 16)); |
4229 | craig | 395 | rc4_encrypt(&rc4, reinterpret_cast<uchar*>(us.data()), reinterpret_cast<uchar*>(ou.data()), tmp.length()); |
396 | QString uk = ""; |
||
8559 | subik | 397 | for (int cl = 0; cl < tmp.length(); ++cl) |
4229 | craig | 398 | uk += QChar(ou[cl]); |
399 | return uk; |
||
3133 | fschmid | 400 | } |
401 | |||
10054 | craig | 402 | QString PDFLibCore::EncString(const QString & in, int ObjNum) |
3133 | fschmid | 403 | { |
4264 | craig | 404 | if (!Options.Encrypt) |
4229 | craig | 405 | return in; |
406 | rc4_context_t rc4; |
||
3133 | fschmid | 407 | QString tmp; |
4229 | craig | 408 | if (in.length() < 3) |
409 | return "<>"; |
||
410 | tmp = in.mid(1, in.length()-2); |
||
10553 | fschmid | 411 | QByteArray us(tmp.length(), ' '); |
412 | QByteArray ou(tmp.length(), ' '); |
||
8559 | subik | 413 | for (int a = 0; a < tmp.length(); ++a) |
8576 | jghali | 414 | us[a] = static_cast<uchar>(QChar(tmp.at(a)).cell()); |
11599 | jghali | 415 | QByteArray step1 = ComputeRC4Key(ObjNum); |
8562 | jghali | 416 | rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), qMin(KeyLen+5, 16)); |
4229 | craig | 417 | rc4_encrypt(&rc4, reinterpret_cast<uchar*>(us.data()), reinterpret_cast<uchar*>(ou.data()), tmp.length()); |
418 | QString uk = ""; |
||
8559 | subik | 419 | for (int cl = 0; cl < tmp.length(); ++cl) |
4229 | craig | 420 | uk += QChar(ou[cl]); |
421 | tmp = "<"+String2Hex(&uk, false)+">"; |
||
3133 | fschmid | 422 | return tmp; |
423 | } |
||
424 | |||
10054 | craig | 425 | QString PDFLibCore::EncStringUTF16(const QString & in, int ObjNum) |
7328 | fschmid | 426 | { |
7355 | fschmid | 427 | if (in.length() < 3) |
428 | return "<>"; |
||
7328 | fschmid | 429 | if (!Options.Encrypt) |
430 | { |
||
431 | QString tmp = in.mid(1, in.length()-2); |
||
432 | QByteArray us = EncodeUTF16(tmp); |
||
433 | QString uk = ""; |
||
8559 | subik | 434 | for (int cl = 0; cl < us.size(); ++cl) |
7328 | fschmid | 435 | uk += QChar(us[cl]); |
436 | return "<"+String2Hex(&uk, false)+">"; |
||
437 | } |
||
438 | rc4_context_t rc4; |
||
11599 | jghali | 439 | QString tmp = in.mid(1, in.length()-2); |
7328 | fschmid | 440 | QByteArray us = EncodeUTF16(tmp); |
10553 | fschmid | 441 | QByteArray ou(us.size(), ' '); |
11599 | jghali | 442 | QByteArray step1 = ComputeRC4Key(ObjNum); |
8562 | jghali | 443 | rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), qMin(KeyLen+5, 16)); |
7328 | fschmid | 444 | rc4_encrypt(&rc4, reinterpret_cast<uchar*>(us.data()), reinterpret_cast<uchar*>(ou.data()), ou.size()); |
445 | QString uk = ""; |
||
8559 | subik | 446 | for (int cl = 0; cl < ou.size(); ++cl) |
7328 | fschmid | 447 | uk += QChar(ou[cl]); |
448 | tmp = "<"+String2Hex(&uk, false)+">"; |
||
449 | return tmp; |
||
450 | } |
||
451 | |||
11445 | jghali | 452 | bool PDFLibCore::EncodeArrayToStream(const QByteArray& in, int ObjNum) |
453 | { |
||
454 | if (in.size() < 1) |
||
455 | return true; |
||
11599 | jghali | 456 | bool succeed = false; |
11445 | jghali | 457 | if (Options.Encrypt) |
458 | { |
||
11599 | jghali | 459 | QByteArray step1 = ComputeRC4Key(ObjNum); |
460 | ScRC4EncodeFilter rc4Encode(&outStream, step1.data(), qMin(KeyLen+5, 16)); |
||
461 | if (rc4Encode.openFilter()) |
||
11445 | jghali | 462 | { |
11599 | jghali | 463 | succeed = rc4Encode.writeData(in.data(), in.size()); |
464 | succeed &= rc4Encode.closeFilter(); |
||
11445 | jghali | 465 | } |
11599 | jghali | 466 | } |
467 | else |
||
468 | outStream.writeRawData(in, in.size()); |
||
469 | return (outStream.status() == QDataStream::Ok); |
||
470 | } |
||
11445 | jghali | 471 | |
12732 | fschmid | 472 | int PDFLibCore::WriteImageToStream(ScImage& image, int ObjNum, bool cmyk, bool gray, bool precal) |
11599 | jghali | 473 | { |
474 | bool succeed = false; |
||
475 | int bytesWritten = 0; |
||
476 | if (Options.Encrypt) |
||
477 | { |
||
478 | QByteArray step1 = ComputeRC4Key(ObjNum); |
||
479 | ScRC4EncodeFilter rc4Encode(&outStream, step1.data(), qMin(KeyLen+5, 16)); |
||
480 | if (rc4Encode.openFilter()) |
||
11445 | jghali | 481 | { |
11599 | jghali | 482 | if (gray) |
12732 | fschmid | 483 | succeed = image.writeGrayDataToFilter(&rc4Encode, precal); |
11599 | jghali | 484 | else if (cmyk) |
485 | succeed = image.writeCMYKDataToFilter(&rc4Encode); |
||
486 | else |
||
487 | succeed = image.writeRGBDataToFilter(&rc4Encode); |
||
488 | succeed &= rc4Encode.closeFilter(); |
||
489 | bytesWritten = rc4Encode.writtenToStream(); |
||
11445 | jghali | 490 | } |
14043 | jghali | 491 | } |
11599 | jghali | 492 | else |
493 | { |
||
494 | ScNullEncodeFilter nullEncode(&outStream); |
||
495 | if (nullEncode.openFilter()) |
||
11445 | jghali | 496 | { |
11599 | jghali | 497 | if (gray) |
12732 | fschmid | 498 | succeed = image.writeGrayDataToFilter(&nullEncode, precal); |
11599 | jghali | 499 | else if (cmyk) |
500 | succeed = image.writeCMYKDataToFilter(&nullEncode); |
||
501 | else |
||
502 | succeed = image.writeRGBDataToFilter(&nullEncode); |
||
503 | succeed &= nullEncode.closeFilter(); |
||
504 | bytesWritten = nullEncode.writtenToStream(); |
||
11445 | jghali | 505 | } |
506 | } |
||
11599 | jghali | 507 | return (succeed ? bytesWritten : 0); |
508 | } |
||
509 | |||
14444 | fschmid | 510 | int PDFLibCore::WriteJPEGImageToStream(ScImage& image, const QString& fn, int ObjNum, int quality, bool cmyk, |
12732 | fschmid | 511 | bool gray, bool sameFile, bool precal) |
11599 | jghali | 512 | { |
513 | bool succeed = true; |
||
514 | int bytesWritten = 0; |
||
515 | QFileInfo fInfo(fn); |
||
516 | QString ext = fInfo.suffix().toLower(); |
||
517 | QString jpgFileName, tmpFile; |
||
518 | if (extensionIndicatesJPEG(ext) && sameFile) |
||
519 | jpgFileName = fn; |
||
11445 | jghali | 520 | else |
11599 | jghali | 521 | { |
16577 | craig | 522 | tmpFile = QDir::toNativeSeparators(ScPaths::getTempFileDir() + "sc.jpg"); |
12732 | fschmid | 523 | if ((gray) && (!precal)) |
11599 | jghali | 524 | image.convertToGray(); |
14467 | jghali | 525 | if (image.convert2JPG(tmpFile, quality, cmyk, gray)) |
11599 | jghali | 526 | jpgFileName = tmpFile; |
527 | } |
||
528 | if (jpgFileName.isEmpty()) |
||
11792 | fschmid | 529 | return 0; |
11599 | jghali | 530 | if (Options.Encrypt) |
531 | { |
||
532 | succeed = false; |
||
533 | QByteArray step1 = ComputeRC4Key(ObjNum); |
||
534 | ScRC4EncodeFilter rc4Encode(&outStream, step1.data(), qMin(KeyLen+5, 16)); |
||
535 | if (rc4Encode.openFilter()) |
||
536 | { |
||
537 | succeed = copyFileToFilter(jpgFileName, rc4Encode); |
||
538 | succeed &= rc4Encode.closeFilter(); |
||
539 | bytesWritten = rc4Encode.writtenToStream(); |
||
540 | } |
||
541 | } |
||
542 | else |
||
543 | { |
||
544 | succeed &= copyFileToStream(jpgFileName, outStream); |
||
545 | QFileInfo jpgInfo(jpgFileName); |
||
546 | bytesWritten = jpgInfo.size(); |
||
547 | } |
||
548 | if (!tmpFile.isEmpty() && QFile::exists(tmpFile)) |
||
549 | QFile::remove(tmpFile); |
||
550 | return (succeed ? bytesWritten : 0); |
||
11445 | jghali | 551 | } |
552 | |||
12732 | fschmid | 553 | int PDFLibCore::WriteFlateImageToStream(ScImage& image, int ObjNum, bool cmyk, bool gray, bool precal) |
11599 | jghali | 554 | { |
555 | bool succeed = false; |
||
556 | int bytesWritten = 0; |
||
557 | if (Options.Encrypt) |
||
558 | { |
||
559 | QByteArray step1 = ComputeRC4Key(ObjNum); |
||
560 | ScRC4EncodeFilter rc4Encode(&outStream, step1.data(), qMin(KeyLen+5, 16)); |
||
561 | ScFlateEncodeFilter flateEncode(&rc4Encode); |
||
562 | if (flateEncode.openFilter()) |
||
563 | { |
||
564 | if (gray) |
||
12732 | fschmid | 565 | succeed = image.writeGrayDataToFilter(&flateEncode, precal); |
11599 | jghali | 566 | else if (cmyk) |
567 | succeed = image.writeCMYKDataToFilter(&flateEncode); |
||
568 | else |
||
569 | succeed = image.writeRGBDataToFilter(&flateEncode); |
||
570 | succeed &= flateEncode.closeFilter(); |
||
571 | bytesWritten = flateEncode.writtenToStream(); |
||
572 | } |
||
14043 | jghali | 573 | } |
11599 | jghali | 574 | else |
575 | { |
||
576 | ScFlateEncodeFilter flateEncode(&outStream); |
||
577 | if (flateEncode.openFilter()) |
||
578 | { |
||
579 | if (gray) |
||
12732 | fschmid | 580 | succeed = image.writeGrayDataToFilter(&flateEncode, precal); |
11599 | jghali | 581 | else if (cmyk) |
582 | succeed = image.writeCMYKDataToFilter(&flateEncode); |
||
583 | else |
||
584 | succeed = image.writeRGBDataToFilter(&flateEncode); |
||
585 | succeed &= flateEncode.closeFilter(); |
||
586 | bytesWritten = flateEncode.writtenToStream(); |
||
587 | } |
||
588 | } |
||
11792 | fschmid | 589 | return (succeed ? bytesWritten : 0); |
11599 | jghali | 590 | } |
591 | |||
10054 | craig | 592 | QString PDFLibCore::FitKey(const QString & pass) |
3133 | fschmid | 593 | { |
4229 | craig | 594 | QString pw(pass); |
3133 | fschmid | 595 | if (pw.length() < 32) |
596 | { |
||
597 | uint l = pw.length(); |
||
598 | for (uint a = 0; a < 32 - l; ++a) |
||
599 | pw += QChar(KeyGen[a]); |
||
600 | } |
||
601 | else |
||
602 | pw = pw.left(32); |
||
603 | return pw; |
||
604 | } |
||
605 | |||
10054 | craig | 606 | void PDFLibCore::CalcOwnerKey(const QString & Owner, const QString & User) |
3133 | fschmid | 607 | { |
4229 | craig | 608 | rc4_context_t rc4; |
609 | QString pw(FitKey(User)); |
||
610 | QString pw2(FitKey(Owner.isEmpty() ? User : Owner)); |
||
10553 | fschmid | 611 | QByteArray step1(16, ' '); |
3133 | fschmid | 612 | step1 = ComputeMD5(pw2); |
613 | if (KeyLen > 5) |
||
614 | { |
||
615 | for (int kl = 0; kl < 50; ++kl) |
||
616 | step1 = ComputeMD5Sum(&step1); |
||
617 | } |
||
10553 | fschmid | 618 | QByteArray us(32, ' '); |
619 | QByteArray enk(16, ' '); |
||
3133 | fschmid | 620 | if (KeyLen > 5) |
621 | { |
||
622 | for (uint a2 = 0; a2 < 32; ++a2) |
||
8576 | jghali | 623 | OwnerKey[a2] = QChar(pw.at(a2)).cell(); |
3133 | fschmid | 624 | for (int rl = 0; rl < 20; rl++) |
625 | { |
||
4229 | craig | 626 | for (int j = 0; j < 16; j ++) |
627 | enk[j] = step1[j] ^ rl; |
||
3133 | fschmid | 628 | rc4_init(&rc4, reinterpret_cast<uchar*>(enk.data()), 16); |
4229 | craig | 629 | rc4_encrypt(&rc4, reinterpret_cast<uchar*>(OwnerKey.data()), |
3133 | fschmid | 630 | reinterpret_cast<uchar*>(OwnerKey.data()), 32); |
631 | } |
||
632 | } |
||
633 | else |
||
634 | { |
||
635 | for (uint a = 0; a < 32; ++a) |
||
8576 | jghali | 636 | us[a] = static_cast<uchar>(QChar(pw.at(a)).cell()); |
3133 | fschmid | 637 | rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), 5); |
4546 | subik | 638 | rc4_encrypt(&rc4, reinterpret_cast<uchar*>(us.data()), |
3133 | fschmid | 639 | reinterpret_cast<uchar*>(OwnerKey.data()), 32); |
640 | } |
||
641 | } |
||
642 | |||
10054 | craig | 643 | void PDFLibCore::CalcUserKey(const QString & User, int Permission) |
3133 | fschmid | 644 | { |
645 | rc4_context_t rc4; |
||
4229 | craig | 646 | QString pw(FitKey(User)); |
10553 | fschmid | 647 | QByteArray step1(16, ' '); |
648 | QByteArray perm(4, ' '); |
||
3133 | fschmid | 649 | uint perm_value = static_cast<uint>(Permission); |
650 | perm[0] = perm_value; |
||
651 | perm[1] = perm_value >> 8; |
||
652 | perm[2] = perm_value >> 16; |
||
653 | perm[3] = perm_value >> 24; |
||
654 | for (uint a = 0; a < 32; ++a) |
||
655 | pw += QChar(OwnerKey[a]); |
||
656 | for (uint a1 = 0; a1 < 4; ++a1) |
||
657 | pw += QChar(perm[a1]); |
||
658 | for (uint a3 = 0; a3 < 16; ++a3) |
||
659 | pw += QChar(FileID[a3]); |
||
660 | step1 = ComputeMD5(pw); |
||
661 | if (KeyLen > 5) |
||
662 | { |
||
663 | for (int kl = 0; kl < 50; ++kl) |
||
664 | step1 = ComputeMD5Sum(&step1); |
||
665 | EncryKey.resize(16); |
||
666 | } |
||
667 | for (int a2 = 0; a2 < KeyLen; ++a2) |
||
668 | EncryKey[a2] = step1[a2]; |
||
669 | if (KeyLen > 5) |
||
670 | { |
||
4229 | craig | 671 | QString pr2(""); |
3133 | fschmid | 672 | for (int kl3 = 0; kl3 < 32; ++kl3) |
673 | pr2 += QChar(KeyGen[kl3]); |
||
674 | for (uint a4 = 0; a4 < 16; ++a4) |
||
675 | pr2 += QChar(FileID[a4]); |
||
676 | step1 = ComputeMD5(pr2); |
||
10553 | fschmid | 677 | QByteArray enk(16, ' '); |
3133 | fschmid | 678 | for (uint a3 = 0; a3 < 16; ++a3) |
679 | UserKey[a3] = step1[a3]; |
||
680 | for (int rl = 0; rl < 20; rl++) |
||
681 | { |
||
4229 | craig | 682 | for (int j = 0; j < 16; j ++) |
683 | enk[j] = EncryKey[j] ^ rl; |
||
3133 | fschmid | 684 | rc4_init(&rc4, reinterpret_cast<uchar*>(enk.data()), 16); |
4229 | craig | 685 | rc4_encrypt(&rc4, reinterpret_cast<uchar*>(UserKey.data()), reinterpret_cast<uchar*>(UserKey.data()), 16); |
3133 | fschmid | 686 | } |
687 | } |
||
688 | else |
||
689 | { |
||
690 | rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), 5); |
||
4229 | craig | 691 | rc4_encrypt(&rc4, reinterpret_cast<uchar*>(KeyGen.data()), reinterpret_cast<uchar*>(UserKey.data()), 32); |
3133 | fschmid | 692 | } |
693 | } |
||
694 | |||
10054 | craig | 695 | QByteArray PDFLibCore::ComputeMD5(const QString& in) |
3133 | fschmid | 696 | { |
3829 | cbradney | 697 | uint inlen=in.length(); |
10553 | fschmid | 698 | QByteArray TBytes(inlen, ' '); |
3829 | cbradney | 699 | for (uint a = 0; a < inlen; ++a) |
8576 | jghali | 700 | TBytes[a] = static_cast<uchar>(QChar(in.at(a)).cell()); |
3133 | fschmid | 701 | return ComputeMD5Sum(&TBytes); |
702 | } |
||
703 | |||
11599 | jghali | 704 | QByteArray PDFLibCore::ComputeRC4Key(int ObjNum) |
705 | { |
||
706 | int dlen = 0; |
||
707 | QByteArray data(10, ' '); |
||
708 | if (KeyLen > 5) |
||
709 | data.resize(21); |
||
710 | for (int cd = 0; cd < KeyLen; ++cd) |
||
711 | { |
||
712 | data[cd] = EncryKey[cd]; |
||
713 | dlen++; |
||
714 | } |
||
715 | data[dlen++] = ObjNum; |
||
716 | data[dlen++] = ObjNum >> 8; |
||
717 | data[dlen++] = ObjNum >> 16; |
||
718 | data[dlen++] = 0; |
||
719 | data[dlen++] = 0; |
||
720 | QByteArray rc4Key(16, ' '); |
||
721 | rc4Key = ComputeMD5Sum(&data); |
||
722 | rc4Key.resize(qMin(KeyLen+5, 16)); |
||
723 | return rc4Key; |
||
724 | } |
||
725 | |||
10054 | craig | 726 | bool PDFLibCore::PDF_Begin_Doc(const QString& fn, SCFonts &AllFonts, QMap<QString, QMap<uint, FPointArray> > DocFonts, BookMView* vi) |
3133 | fschmid | 727 | { |
10553 | fschmid | 728 | Spool.setFileName(fn); |
8501 | cbradney | 729 | if (!Spool.open(QIODevice::WriteOnly)) |
3133 | fschmid | 730 | return false; |
4229 | craig | 731 | outStream.setDevice(&Spool); |
3133 | fschmid | 732 | QString tmp; |
733 | QString ok = ""; |
||
734 | QString uk = ""; |
||
735 | QFileInfo fd; |
||
736 | QString fext; |
||
737 | int a; |
||
6407 | fschmid | 738 | inPattern = 0; |
3133 | fschmid | 739 | Bvie = vi; |
740 | BookMinUse = false; |
||
741 | UsedFontsP.clear(); |
||
8454 | fschmid | 742 | UsedFontsF.clear(); |
14043 | jghali | 743 | if (((Options.Version == PDFOptions::PDFVersion_15) || (Options.Version == PDFOptions::PDFVersion_X4)) && (Options.useLayers)) |
3133 | fschmid | 744 | ObjCounter = 10; |
745 | else |
||
746 | ObjCounter = 9; |
||
4264 | craig | 747 | switch (Options.Version) |
3133 | fschmid | 748 | { |
14043 | jghali | 749 | case PDFOptions::PDFVersion_X1a: |
12884 | jghali | 750 | case PDFOptions::PDFVersion_X3: |
751 | case PDFOptions::PDFVersion_13: |
||
4229 | craig | 752 | PutDoc("%PDF-1.3\n"); |
3133 | fschmid | 753 | break; |
12884 | jghali | 754 | case PDFOptions::PDFVersion_14: |
3133 | fschmid | 755 | PutDoc("%PDF-1.4\n"); |
756 | break; |
||
14043 | jghali | 757 | case PDFOptions::PDFVersion_X4: |
12884 | jghali | 758 | case PDFOptions::PDFVersion_15: |
3133 | fschmid | 759 | PutDoc("%PDF-1.5\n"); |
760 | break; |
||
761 | } |
||
14043 | jghali | 762 | if ((Options.Version == PDFOptions::PDFVersion_X3) || (Options.Version == PDFOptions::PDFVersion_X1a) || (Options.Version == PDFOptions::PDFVersion_X4)) |
3133 | fschmid | 763 | ObjCounter++; |
4229 | craig | 764 | PutDoc("%\xc7\xec\x8f\xa2\n"); |
3133 | fschmid | 765 | StartObj(1); |
766 | 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"); |
||
14043 | jghali | 767 | if (((Options.Version == PDFOptions::PDFVersion_15) || (Options.Version == PDFOptions::PDFVersion_X4)) && (Options.useLayers)) |
3133 | fschmid | 768 | PutDoc("/OCProperties 9 0 R\n"); |
14043 | jghali | 769 | if ((Options.Version == PDFOptions::PDFVersion_X3) || (Options.Version == PDFOptions::PDFVersion_X1a) || (Options.Version == PDFOptions::PDFVersion_X4)) |
4229 | craig | 770 | PutDoc("/OutputIntents [ "+QString::number(ObjCounter-1)+" 0 R ]\n"); |
14043 | jghali | 771 | if ((Options.Version == PDFOptions::PDFVersion_X4)) |
772 | { |
||
773 | ObjCounter++; |
||
774 | PutDoc("/Metadata "+QString::number(ObjCounter-1)+" 0 R\n"); |
||
775 | } |
||
4197 | fschmid | 776 | PutDoc("/PageLayout "); |
4264 | craig | 777 | switch (Options.PageLayout) |
3133 | fschmid | 778 | { |
4197 | fschmid | 779 | case PDFOptions::SinglePage: |
780 | PutDoc("/SinglePage\n"); |
||
781 | break; |
||
782 | case PDFOptions::OneColumn: |
||
783 | PutDoc("/OneColumn\n"); |
||
784 | break; |
||
785 | case PDFOptions::TwoColumnLeft: |
||
786 | PutDoc("/TwoColumnLeft\n"); |
||
787 | break; |
||
788 | case PDFOptions::TwoColumnRight: |
||
789 | PutDoc("/TwoColumnRight\n"); |
||
790 | break; |
||
791 | } |
||
4264 | craig | 792 | if (Options.displayBookmarks) |
4197 | fschmid | 793 | PutDoc("/PageMode /UseOutlines\n"); |
4264 | craig | 794 | else if (Options.displayFullscreen) |
4197 | fschmid | 795 | PutDoc("/PageMode /FullScreen\n"); |
4264 | craig | 796 | else if (Options.displayThumbs) |
4197 | fschmid | 797 | PutDoc("/PageMode /UseThumbs\n"); |
12884 | jghali | 798 | else if ((Options.Version == PDFOptions::PDFVersion_15) && (Options.displayLayers)) |
4197 | fschmid | 799 | PutDoc("/PageMode /UseOC\n"); |
4264 | craig | 800 | if (!Options.openAction.isEmpty()) |
4197 | fschmid | 801 | { |
4264 | craig | 802 | PutDoc("/OpenAction << /S /JavaScript /JS (this."+Options.openAction+"\\(\\)) >>\n"); |
3133 | fschmid | 803 | } |
14043 | jghali | 804 | QDateTime dt = QDateTime::currentDateTime().toUTC(); |
805 | QDate d = dt.date(); |
||
11593 | fschmid | 806 | Datum = "D:"; |
807 | tmp.sprintf("%4d", d.year()); |
||
808 | tmp.replace(QRegExp(" "), "0"); |
||
809 | Datum += tmp; |
||
810 | tmp.sprintf("%2d", d.month()); |
||
811 | tmp.replace(QRegExp(" "), "0"); |
||
812 | Datum += tmp; |
||
813 | tmp.sprintf("%2d", d.day()); |
||
814 | tmp.replace(QRegExp(" "), "0"); |
||
815 | Datum += tmp; |
||
14043 | jghali | 816 | tmp = dt.time().toString(); |
11593 | fschmid | 817 | tmp.replace(QRegExp(":"), ""); |
818 | Datum += tmp; |
||
14043 | jghali | 819 | Datum += "Z"; |
12429 | fschmid | 820 | |
14043 | jghali | 821 | // only include XMP to PDF/X-4 at the moment, could easily be extended to include it to any PDF |
822 | if (Options.Version == PDFOptions::PDFVersion_X4) |
||
823 | generateXMP(dt.toString("yyyy-MM-ddThh:mm:ssZ")); |
||
824 | |||
12429 | fschmid | 825 | /* The following code makes the resulting PDF "Reader enabled" in Acrobat Reader 8 |
826 | but sadly it doesn't work with newer version, because its based on a bug in AR 8 |
||
827 | PutDoc("/Perms\n"); |
||
828 | PutDoc("<<\n"); |
||
829 | PutDoc("/UR3\n"); |
||
830 | PutDoc("<<\n"); |
||
831 | PutDoc("/M ("+Datum+")\n"); |
||
832 | PutDoc("/Name (Scribus "+QString(VERSION)+")\n"); |
||
833 | PutDoc("/Reference [\n"); |
||
834 | PutDoc("<<\n"); |
||
835 | PutDoc("/TransformParams\n"); |
||
836 | PutDoc("<<\n"); |
||
837 | PutDoc("/Type /TransformParams\n"); |
||
838 | PutDoc("/V /2.2\n"); |
||
839 | PutDoc("/Document [/FullSave]\n"); |
||
840 | PutDoc("/Annots [/Create/Delete/Modify/Copy/Import/Export]\n"); |
||
841 | PutDoc("/Form [/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate]\n"); |
||
842 | PutDoc("/Signature [/Modify]\n"); |
||
843 | PutDoc(">>\n"); |
||
844 | PutDoc("/TransformMethod /UR3\n"); |
||
845 | PutDoc("/Type /SigRef\n"); |
||
846 | PutDoc(">>\n"); |
||
847 | PutDoc("]\n"); |
||
848 | PutDoc("/Type /Sig\n"); |
||
849 | PutDoc(">>\n"); |
||
850 | PutDoc(">>\n"); |
||
851 | */ |
||
852 | |||
853 | PutDoc("/ViewerPreferences\n<<\n/PageDirection "); |
||
854 | PutDoc( Options.Binding == 0 ? "/L2R\n" : "/R2L\n"); |
||
855 | if (Options.hideToolBar) |
||
856 | PutDoc("/HideToolbar true\n"); |
||
857 | if (Options.hideMenuBar) |
||
858 | PutDoc("/HideMenubar true\n"); |
||
859 | if (Options.fitWindow) |
||
860 | PutDoc("/FitWindow true\n"); |
||
861 | PutDoc(" >>\n>>\nendobj\n"); |
||
3829 | cbradney | 862 | QString IDg(Datum); |
11948 | jghali | 863 | IDg += Options.fileName; |
3133 | fschmid | 864 | IDg += "Scribus "+QString(VERSION); |
6878 | fschmid | 865 | IDg += "Scribus PDF Library "+QString(VERSION); |
15037 | cbradney | 866 | IDg += doc.documentInfo().title(); |
867 | IDg += doc.documentInfo().author(); |
||
3133 | fschmid | 868 | IDg += "/False"; |
869 | FileID = ComputeMD5(IDg); |
||
4264 | craig | 870 | if (Options.Encrypt) |
3133 | fschmid | 871 | { |
12884 | jghali | 872 | if ((Options.Version == PDFOptions::PDFVersion_14) || (Options.Version == PDFOptions::PDFVersion_15)) |
6166 | fschmid | 873 | KeyLen = 16; |
874 | else |
||
875 | KeyLen = 5; |
||
4264 | craig | 876 | CalcOwnerKey(Options.PassOwner, Options.PassUser); |
877 | CalcUserKey(Options.PassUser, Options.Permissions); |
||
3133 | fschmid | 878 | for (uint cl2 = 0; cl2 < 32; ++cl2) |
879 | ok += QChar(OwnerKey[cl2]); |
||
880 | if (KeyLen > 5) |
||
881 | { |
||
882 | for (uint cl3 = 0; cl3 < 16; ++cl3) |
||
883 | uk += QChar(UserKey[cl3]); |
||
884 | for (uint cl3r = 0; cl3r < 16; ++cl3r) |
||
885 | uk += QChar(KeyGen[cl3r]); |
||
886 | } |
||
887 | else |
||
888 | { |
||
889 | for (uint cl = 0; cl < 32; ++cl) |
||
890 | uk += QChar(UserKey[cl]); |
||
891 | } |
||
892 | } |
||
893 | StartObj(2); |
||
894 | PutDoc("<<\n/Creator "+EncString("(Scribus "+QString(VERSION)+")",2)+"\n"); |
||
6890 | fschmid | 895 | PutDoc("/Producer "+EncString("(Scribus PDF Library "+QString(VERSION)+")",2)+"\n"); |
15037 | cbradney | 896 | QString docTitle = doc.documentInfo().title(); |
14043 | jghali | 897 | if (((Options.Version == PDFOptions::PDFVersion_X3) || (Options.Version == PDFOptions::PDFVersion_X1a) || (Options.Version == PDFOptions::PDFVersion_X4)) && (docTitle.isEmpty())) |
7328 | fschmid | 898 | PutDoc("/Title "+EncStringUTF16("("+doc.DocName+")",2)+"\n"); |
4718 | fschmid | 899 | else |
15037 | cbradney | 900 | PutDoc("/Title "+EncStringUTF16("("+doc.documentInfo().title()+")",2)+"\n"); |
901 | PutDoc("/Author "+EncStringUTF16("("+doc.documentInfo().author()+")",2)+"\n"); |
||
902 | PutDoc("/Subject "+EncStringUTF16("("+doc.documentInfo().subject()+")",2)+"\n"); |
||
903 | PutDoc("/Keywords "+EncStringUTF16("("+doc.documentInfo().keywords()+")",2)+"\n"); |
||
3133 | fschmid | 904 | PutDoc("/CreationDate "+EncString("("+Datum+")",2)+"\n"); |
905 | PutDoc("/ModDate "+EncString("("+Datum+")",2)+"\n"); |
||
12884 | jghali | 906 | if (Options.Version == PDFOptions::PDFVersion_X3) |
3133 | fschmid | 907 | PutDoc("/GTS_PDFXVersion (PDF/X-3:2002)\n"); |
14043 | jghali | 908 | if (Options.Version == PDFOptions::PDFVersion_X1a) |
909 | { |
||
910 | PutDoc("/GTS_PDFXVersion (PDF/X-1:2001)\n"); |
||
911 | PutDoc("/GTS_PDFXConformance (PDF/X-1a:2001)\n"); |
||
912 | } |
||
913 | if (Options.Version == PDFOptions::PDFVersion_X4) |
||
914 | PutDoc("/GTS_PDFXVersion (PDF/X-4)\n"); |
||
3133 | fschmid | 915 | PutDoc("/Trapped /False\n>>\nendobj\n"); |
4229 | craig | 916 | for (int t = 0; t < 6; ++t) |
917 | XRef.append(bytesWritten()); |
||
14043 | jghali | 918 | if (((Options.Version == PDFOptions::PDFVersion_15) || (Options.Version == PDFOptions::PDFVersion_X4)) && (Options.useLayers)) |
4229 | craig | 919 | XRef.append(bytesWritten()); |
14043 | jghali | 920 | if ((Options.Version == PDFOptions::PDFVersion_X3) || (Options.Version == PDFOptions::PDFVersion_X1a) || (Options.Version == PDFOptions::PDFVersion_X4)) |
4229 | craig | 921 | XRef.append(bytesWritten()); |
14043 | jghali | 922 | if (Options.Version == PDFOptions::PDFVersion_X4) |
923 | XRef.append(bytesWritten()); |
||
4264 | craig | 924 | if (Options.Encrypt) |
3133 | fschmid | 925 | { |
12080 | avox | 926 | Encrypt = newObject(); |
927 | StartObj(Encrypt); |
||
3133 | fschmid | 928 | PutDoc("<<\n/Filter /Standard\n"); |
929 | PutDoc( KeyLen > 5 ? "/R 3\n/V 2\n/Length 128\n" : "/R 2\n/V 1\n"); |
||
930 | PutDoc("/O <"+String2Hex(&ok)+">\n"); |
||
931 | PutDoc("/U <"+String2Hex(&uk)+">\n"); |
||
4264 | craig | 932 | PutDoc("/P "+QString::number(Options.Permissions)+"\n>>\nendobj\n"); |
3133 | fschmid | 933 | } |
5387 | avox | 934 | QMap<QString, QMap<uint, FPointArray> > ReallyUsed; |
3133 | fschmid | 935 | ReallyUsed.clear(); |
936 | PageItem* pgit; |
||
4017 | fschmid | 937 | QMap<int, QString> ind2PDFabr; |
4546 | subik | 938 | const QString tmpf[] = {"/Courier", "/Courier-Bold", "/Courier-Oblique", "/Courier-BoldOblique", |
4017 | fschmid | 939 | "/Helvetica", "/Helvetica-Bold", "/Helvetica-Oblique", "/Helvetica-BoldOblique", |
4546 | subik | 940 | "/Times-Roman", "/Times-Bold", "/Times-Italic", "/Times-BoldItalic", |
4017 | fschmid | 941 | "/ZapfDingbats", "/Symbol"}; |
942 | size_t ar = sizeof(tmpf) / sizeof(*tmpf); |
||
943 | for (uint ax = 0; ax < ar; ++ax) |
||
944 | ind2PDFabr[ax] = tmpf[ax]; |
||
9856 | fschmid | 945 | for (int c = 0; c < doc.FrameItems.count(); ++c) |
3133 | fschmid | 946 | { |
4264 | craig | 947 | pgit = doc.FrameItems.at(c); |
3133 | fschmid | 948 | if ((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) |
949 | { |
||
4084 | cbradney | 950 | if (pgit->isAnnotation()) |
8092 | fschmid | 951 | { |
14594 | jghali | 952 | int annotType = pgit->annotation().Type(); |
953 | bool mustEmbed = ((annotType >= 2) && (annotType <= 6) && (annotType != 4)); |
||
8351 | fschmid | 954 | if (pgit->annotation().Type() == 4) |
955 | StdFonts.insert("/ZapfDingbats", ""); |
||
14594 | jghali | 956 | if (pgit->itemText.length() > 0 || mustEmbed) |
12763 | fschmid | 957 | { |
12900 | fschmid | 958 | if (Options.Version < PDFOptions::PDFVersion_14) |
959 | StdFonts.insert(ind2PDFabr[pgit->annotation().Font()], ""); |
||
12763 | fschmid | 960 | ReallyUsed.insert(pgit->itemText.defaultStyle().charStyle().font().replacementName(), DocFonts[pgit->itemText.defaultStyle().charStyle().font().replacementName()]); |
961 | } |
||
8092 | fschmid | 962 | } |
5292 | fschmid | 963 | for (uint e = 0; e < static_cast<uint>(pgit->itemText.length()); ++e) |
3133 | fschmid | 964 | { |
7210 | avox | 965 | ReallyUsed.insert(pgit->itemText.charStyle(e).font().replacementName(), DocFonts[pgit->itemText.charStyle(e).font().replacementName()]); |
3133 | fschmid | 966 | } |
967 | } |
||
968 | } |
||
9856 | fschmid | 969 | for (int c = 0; c < doc.MasterItems.count(); ++c) |
3133 | fschmid | 970 | { |
4264 | craig | 971 | pgit = doc.MasterItems.at(c); |
3133 | fschmid | 972 | if ((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) |
973 | { |
||
4084 | cbradney | 974 | if (pgit->isAnnotation()) |
8092 | fschmid | 975 | { |
14594 | jghali | 976 | int annotType = pgit->annotation().Type(); |
977 | bool mustEmbed = ((annotType >= 2) && (annotType <= 6) && (annotType != 4)); |
||
8351 | fschmid | 978 | if (pgit->annotation().Type() == 4) |
979 | StdFonts.insert("/ZapfDingbats", ""); |
||
14594 | jghali | 980 | if (pgit->itemText.length() > 0 || mustEmbed) |
12763 | fschmid | 981 | { |
12900 | fschmid | 982 | if (Options.Version < PDFOptions::PDFVersion_14) |
983 | StdFonts.insert(ind2PDFabr[pgit->annotation().Font()], ""); |
||
12763 | fschmid | 984 | ReallyUsed.insert(pgit->itemText.defaultStyle().charStyle().font().replacementName(), DocFonts[pgit->itemText.defaultStyle().charStyle().font().replacementName()]); |
985 | } |
||
8092 | fschmid | 986 | } |
5292 | fschmid | 987 | for (uint e = 0; e < static_cast<uint>(pgit->itemText.length()); ++e) |
3133 | fschmid | 988 | { |
7210 | avox | 989 | ReallyUsed.insert(pgit->itemText.charStyle(e).font().replacementName(), DocFonts[pgit->itemText.charStyle(e).font().replacementName()]); |
3133 | fschmid | 990 | } |
991 | } |
||
992 | } |
||
9856 | fschmid | 993 | for (int d = 0; d < doc.Items->count(); ++d) |
3133 | fschmid | 994 | { |
4264 | craig | 995 | pgit = doc.Items->at(d); |
3133 | fschmid | 996 | if ((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) |
997 | { |
||
4084 | cbradney | 998 | if (pgit->isAnnotation()) |
8092 | fschmid | 999 | { |
14594 | jghali | 1000 | int annotType = pgit->annotation().Type(); |
1001 | bool mustEmbed = ((annotType >= 2) && (annotType <= 6) && (annotType != 4)); |
||
8351 | fschmid | 1002 | if (pgit->annotation().Type() == 4) |
1003 | StdFonts.insert("/ZapfDingbats", ""); |
||
14594 | jghali | 1004 | if (pgit->itemText.length() > 0 || mustEmbed) |
12763 | fschmid | 1005 | { |
12900 | fschmid | 1006 | if (Options.Version < PDFOptions::PDFVersion_14) |
1007 | StdFonts.insert(ind2PDFabr[pgit->annotation().Font()], ""); |
||
12763 | fschmid | 1008 | ReallyUsed.insert(pgit->itemText.defaultStyle().charStyle().font().replacementName(), DocFonts[pgit->itemText.defaultStyle().charStyle().font().replacementName()]); |
1009 | } |
||
8092 | fschmid | 1010 | } |
5292 | fschmid | 1011 | for (uint e = 0; e < static_cast<uint>(pgit->itemText.length()); ++e) |
3133 | fschmid | 1012 | { |
7210 | avox | 1013 | ReallyUsed.insert(pgit->itemText.charStyle(e).font().replacementName(), DocFonts[pgit->itemText.charStyle(e).font().replacementName()]); |
3133 | fschmid | 1014 | } |
1015 | } |
||
1016 | } |
||
11453 | fschmid | 1017 | /* if (Options.docInfoMarks) |
6943 | fschmid | 1018 | { |
1019 | StdFonts.insert("/Helvetica", ""); |
||
11453 | fschmid | 1020 | } */ |
16052 | fschmid | 1021 | QStringList patterns = doc.getPatternDependencyList(doc.getUsedPatterns()); |
8559 | subik | 1022 | for (int c = 0; c < patterns.count(); ++c) |
6407 | fschmid | 1023 | { |
1024 | ScPattern pa = doc.docPatterns[patterns[c]]; |
||
9856 | fschmid | 1025 | for (int o = 0; o < pa.items.count(); o++) |
6407 | fschmid | 1026 | { |
1027 | pgit = pa.items.at(o); |
||
1028 | if ((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) |
||
1029 | { |
||
1030 | if (pgit->isAnnotation()) |
||
8351 | fschmid | 1031 | { |
1032 | if (pgit->annotation().Type() == 4) |
||
1033 | StdFonts.insert("/ZapfDingbats", ""); |
||
12763 | fschmid | 1034 | if (pgit->itemText.length() > 0) |
1035 | { |
||
12900 | fschmid | 1036 | if (Options.Version < PDFOptions::PDFVersion_14) |
1037 | StdFonts.insert(ind2PDFabr[pgit->annotation().Font()], ""); |
||
12763 | fschmid | 1038 | ReallyUsed.insert(pgit->itemText.defaultStyle().charStyle().font().replacementName(), DocFonts[pgit->itemText.defaultStyle().charStyle().font().replacementName()]); |
1039 | } |
||
8351 | fschmid | 1040 | } |
6407 | fschmid | 1041 | for (uint e = 0; e < static_cast<uint>(pgit->itemText.length()); ++e) |
1042 | { |
||
7210 | avox | 1043 | ReallyUsed.insert(pgit->itemText.charStyle(e).font().replacementName(), DocFonts[pgit->itemText.charStyle(e).font().replacementName()]); |
6407 | fschmid | 1044 | } |
1045 | } |
||
1046 | } |
||
1047 | } |
||
4017 | fschmid | 1048 | a = 0; |
1049 | QMap<QString, QString>::Iterator itStd; |
||
1050 | for (itStd = StdFonts.begin(); itStd != StdFonts.end(); ++itStd) |
||
1051 | { |
||
12080 | avox | 1052 | uint fontObject = newObject(); |
1053 | StartObj(fontObject); |
||
4017 | fschmid | 1054 | PutDoc("<<\n/Type /Font\n/Subtype /Type1\n"); |
8392 | fschmid | 1055 | PutDoc("/Name /FoStd"+QString::number(a)+"\n"); |
4017 | fschmid | 1056 | PutDoc("/BaseFont "+itStd.key()+"\n"); |
8432 | fschmid | 1057 | if (itStd.key() != "/ZapfDingbats") |
1058 | { |
||
1059 | PutDoc("/Encoding << \n"); |
||
1060 | PutDoc("/Differences [ \n"); |
||
1061 | PutDoc("24 /breve /caron /circumflex /dotaccent /hungarumlaut /ogonek /ring /tilde\n"); |
||
1062 | PutDoc("39 /quotesingle 96 /grave 128 /bullet /dagger /daggerdbl /ellipsis /emdash /endash /florin /fraction /guilsinglleft /guilsinglright\n"); |
||
1063 | PutDoc("/minus /perthousand /quotedblbase /quotedblleft /quotedblright /quoteleft /quoteright /quotesinglbase /trademark /fi /fl /Lslash /OE /Scaron\n"); |
||
1064 | PutDoc("/Ydieresis /Zcaron /dotlessi /lslash /oe /scaron /zcaron 164 /currency 166 /brokenbar 168 /dieresis /copyright /ordfeminine 172 /logicalnot\n"); |
||
1065 | PutDoc("/.notdef /registered /macron /degree /plusminus /twosuperior /threesuperior /acute /mu 183 /periodcentered /cedilla /onesuperior /ordmasculine\n"); |
||
1066 | PutDoc("188 /onequarter /onehalf /threequarters 192 /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla /Egrave /Eacute /Ecircumflex\n"); |
||
1067 | PutDoc("/Edieresis /Igrave /Iacute /Icircumflex /Idieresis /Eth /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply /Oslash\n"); |
||
1068 | PutDoc("/Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn /germandbls /agrave /aacute /acircumflex /atilde /adieresis /aring /ae /ccedilla\n"); |
||
1069 | PutDoc("/egrave /eacute /ecircumflex /edieresis /igrave /iacute /icircumflex /idieresis /eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis\n"); |
||
1070 | PutDoc("/divide /oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn /ydieresis\n"); |
||
1071 | PutDoc("] >>\n"); |
||
1072 | } |
||
4017 | fschmid | 1073 | PutDoc(">>\nendobj\n"); |
12080 | avox | 1074 | Seite.FObjects["FoStd"+QString::number(a)] = fontObject; |
10469 | cbradney | 1075 | itStd.value() = "FoStd"+QString::number(a); |
4017 | fschmid | 1076 | a++; |
1077 | } |
||
5387 | avox | 1078 | QMap<QString,QMap<uint, FPointArray> >::Iterator it; |
3133 | fschmid | 1079 | a = 0; |
1080 | for (it = ReallyUsed.begin(); it != ReallyUsed.end(); ++it) |
||
1081 | { |
||
16336 | jghali | 1082 | ScFace& face(AllFonts[it.key()]); |
1083 | ScFace::FontFormat fformat = face.format(); |
||
1084 | if ((!face.hasNames()) || (Options.SubsetList.contains(it.key()))) |
||
3133 | fschmid | 1085 | { |
16336 | jghali | 1086 | if (face.hasNames()) |
3133 | fschmid | 1087 | { |
8469 | fschmid | 1088 | UsedFontsP.insert(it.key(), "/Fo"+QString::number(a)); |
1089 | uint SubFonts = 0; |
||
8559 | subik | 1090 | int glyphCount = 0; |
15071 | fschmid | 1091 | double minx = 999999.9; |
1092 | double miny = 999999.9; |
||
1093 | double maxx = -999999.9; |
||
1094 | double maxy = -999999.9; |
||
9803 | fschmid | 1095 | QList<uint> glyphWidths; |
8469 | fschmid | 1096 | QStringList charProcs; |
1097 | QString encoding = "<< /Type /Encoding\n/Differences [ 0\n"; |
||
1098 | QString fon(""); |
||
1099 | QMap<uint, uint> glyphMapping; |
||
1100 | QMap<uint,std::pair<QChar,QString> > gl; |
||
16336 | jghali | 1101 | face.glyphNames(gl); |
10469 | cbradney | 1102 | QMap<uint,FPointArray>& RealGlyphs(it.value()); |
8469 | fschmid | 1103 | QMap<uint,FPointArray>::Iterator ig; |
1104 | for (ig = RealGlyphs.begin(); ig != RealGlyphs.end(); ++ig) |
||
3133 | fschmid | 1105 | { |
8469 | fschmid | 1106 | FPoint np, np1, np2; |
1107 | bool nPath = true; |
||
1108 | fon = ""; |
||
10469 | cbradney | 1109 | if (ig.value().size() > 3) |
3133 | fschmid | 1110 | { |
10469 | cbradney | 1111 | FPointArray gly = ig.value(); |
13951 | fschmid | 1112 | QTransform mat; |
8469 | fschmid | 1113 | mat.scale(100.0, -100.0); |
1114 | gly.map(mat); |
||
1115 | gly.translate(0, 1000); |
||
1116 | for (uint poi = 0; poi < gly.size()-3; poi += 4) |
||
3133 | fschmid | 1117 | { |
8469 | fschmid | 1118 | if (gly.point(poi).x() > 900000) |
1119 | { |
||
1120 | fon += "h\n"; |
||
1121 | nPath = true; |
||
1122 | continue; |
||
1123 | } |
||
1124 | if (nPath) |
||
1125 | { |
||
1126 | np = gly.point(poi); |
||
1127 | fon += FToStr(np.x())+" "+FToStr(np.y())+" m\n"; |
||
1128 | nPath = false; |
||
1129 | } |
||
1130 | np = gly.point(poi+1); |
||
1131 | np1 = gly.point(poi+3); |
||
1132 | np2 = gly.point(poi+2); |
||
1133 | fon += FToStr(np.x()) + " " + FToStr(np.y()) + " " + FToStr(np1.x()) + " " + FToStr(np1.y()) + " " + FToStr(np2.x()) + " " + FToStr(np2.y()) + " c\n"; |
||
3133 | fschmid | 1134 | } |
8469 | fschmid | 1135 | fon += "h f*\n"; |
1136 | np = getMinClipF(&gly); |
||
1137 | np1 = getMaxClipF(&gly); |
||
1138 | } |
||
1139 | else |
||
1140 | { |
||
1141 | fon = "h"; |
||
1142 | np = FPoint(0, 0); |
||
1143 | np1 = FPoint(0, 0); |
||
1144 | } |
||
1145 | fon.prepend(QString::number(qRound(np1.x())) + " 0 "+QString::number(qRound(np.x()))+" "+QString::number(qRound(np.y()))+" "+QString::number(qRound(np1.x()))+ " "+QString::number(qRound(np1.y()))+" d1\n"); |
||
8562 | jghali | 1146 | minx = qMin(minx, np.x()); |
1147 | miny = qMin(miny, np.y()); |
||
1148 | maxx = qMax(maxx, np1.x()); |
||
1149 | maxy = qMax(maxy, np1.y()); |
||
8469 | fschmid | 1150 | glyphWidths.append(qRound(np1.x())); |
12080 | avox | 1151 | uint charProcObject = newObject(); |
1152 | charProcs.append("/"+gl[ig.key()].second+" "+QString::number(charProcObject)+" 0 R\n"); |
||
8469 | fschmid | 1153 | encoding += "/"+gl[ig.key()].second+" "; |
1154 | glyphMapping.insert(ig.key(), glyphCount + SubFonts * 256); |
||
12080 | avox | 1155 | StartObj(charProcObject); |
11317 | jghali | 1156 | if (Options.Compress) |
8469 | fschmid | 1157 | fon = CompressStr(&fon); |
1158 | PutDoc("<< /Length "+QString::number(fon.length()+1)); |
||
11317 | jghali | 1159 | if (Options.Compress) |
8469 | fschmid | 1160 | PutDoc("\n/Filter /FlateDecode"); |
12080 | avox | 1161 | PutDoc("\n>>\nstream\n"+EncStream(fon, charProcObject)+"\nendstream\nendobj\n"); |
8469 | fschmid | 1162 | glyphCount++; |
13522 | jghali | 1163 | int glyphsLeft = RealGlyphs.count() - SubFonts * 256; |
1164 | if ((glyphCount > 255) || (glyphCount == glyphsLeft)) |
||
8469 | fschmid | 1165 | { |
12080 | avox | 1166 | uint fontWidths = newObject(); |
1167 | StartObj(fontWidths); |
||
8469 | fschmid | 1168 | PutDoc("[ "); |
8559 | subik | 1169 | for (int ww = 0; ww < glyphWidths.count(); ++ww) |
3133 | fschmid | 1170 | { |
8469 | fschmid | 1171 | PutDoc(QString::number(qRound(glyphWidths[ww]))+" "); |
3133 | fschmid | 1172 | } |
8469 | fschmid | 1173 | PutDoc("]\nendobj\n"); |
12080 | avox | 1174 | uint fontCharProcs = newObject(); |
1175 | StartObj(fontCharProcs); |
||
8469 | fschmid | 1176 | PutDoc("<<\n"); |
8559 | subik | 1177 | for (int ww = 0; ww < charProcs.count(); ++ww) |
8469 | fschmid | 1178 | { |
1179 | PutDoc(charProcs[ww]); |
||
1180 | } |
||
1181 | PutDoc(">>\nendobj\n"); |
||
12080 | avox | 1182 | uint fontEncoding = newObject(); |
1183 | StartObj(fontEncoding); |
||
8469 | fschmid | 1184 | PutDoc(encoding); |
1185 | PutDoc("]\n"); |
||
1186 | PutDoc(">>\nendobj\n"); |
||
12080 | avox | 1187 | uint font3Object = newObject(); |
1188 | StartObj(font3Object); |
||
8469 | fschmid | 1189 | PutDoc("<<\n/Type /Font\n/Subtype /Type3\n"); |
1190 | PutDoc("/Name /Fo"+QString::number(a)+"S"+QString::number(SubFonts)+"\n"); |
||
1191 | PutDoc("/FirstChar 0\n"); |
||
1192 | PutDoc("/LastChar "+QString::number(glyphCount-1)+"\n"); |
||
12080 | avox | 1193 | PutDoc("/Widths "+QString::number(fontWidths)+" 0 R\n"); |
1194 | PutDoc("/CharProcs "+QString::number(fontCharProcs)+" 0 R\n"); |
||
8469 | fschmid | 1195 | PutDoc("/FontBBox ["+QString::number(qRound(minx))+" "+QString::number(qRound(miny))+" "+QString::number(qRound(maxx))+ " "+QString::number(qRound(maxy))+"]\n"); |
1196 | PutDoc("/FontMatrix [0.001 0 0 0.001 0 0]\n"); |
||
12080 | avox | 1197 | PutDoc("/Encoding "+QString::number(fontEncoding)+" 0 R\n"); |
8469 | fschmid | 1198 | PutDoc(">>\nendobj\n"); |
12080 | avox | 1199 | Seite.FObjects["Fo"+QString::number(a)+"S"+QString::number(SubFonts)] = font3Object; |
8469 | fschmid | 1200 | charProcs.clear(); |
1201 | glyphWidths.clear(); |
||
1202 | // glyphMapping.clear(); |
||
1203 | glyphCount = 0; |
||
13522 | jghali | 1204 | ++SubFonts; |
15071 | fschmid | 1205 | minx = 999999.9; |
1206 | miny = 999999.9; |
||
1207 | maxx = -999999.9; |
||
1208 | maxy = -999999.9; |
||
8469 | fschmid | 1209 | encoding = "<< /Type /Encoding\n/Differences [ 0\n"; |
3133 | fschmid | 1210 | } |
1211 | } |
||
8469 | fschmid | 1212 | Type3Fonts.insert("/Fo"+QString::number(a), glyphMapping); |
1213 | } |
||
1214 | else |
||
1215 | { |
||
1216 | QString fon(""); |
||
10469 | cbradney | 1217 | QMap<uint,FPointArray>& RealGlyphs(it.value()); |
8469 | fschmid | 1218 | QMap<uint,FPointArray>::Iterator ig; |
1219 | for (ig = RealGlyphs.begin(); ig != RealGlyphs.end(); ++ig) |
||
5606 | fschmid | 1220 | { |
8469 | fschmid | 1221 | FPoint np, np1, np2; |
1222 | bool nPath = true; |
||
1223 | fon = ""; |
||
10469 | cbradney | 1224 | if (ig.value().size() > 3) |
8469 | fschmid | 1225 | { |
10469 | cbradney | 1226 | FPointArray gly = ig.value(); |
13951 | fschmid | 1227 | QTransform mat; |
8469 | fschmid | 1228 | mat.scale(0.1, 0.1); |
1229 | gly.map(mat); |
||
1230 | for (uint poi = 0; poi < gly.size()-3; poi += 4) |
||
1231 | { |
||
1232 | if (gly.point(poi).x() > 900000) |
||
1233 | { |
||
1234 | fon += "h\n"; |
||
1235 | nPath = true; |
||
1236 | continue; |
||
1237 | } |
||
1238 | if (nPath) |
||
1239 | { |
||
1240 | np = gly.point(poi); |
||
1241 | fon += FToStr(np.x())+" "+FToStr(-np.y())+" m\n"; |
||
1242 | nPath = false; |
||
1243 | } |
||
1244 | np = gly.point(poi+1); |
||
1245 | np1 = gly.point(poi+3); |
||
1246 | np2 = gly.point(poi+2); |
||
1247 | fon += FToStr(np.x()) + " " + FToStr(-np.y()) + " " + |
||
1248 | FToStr(np1.x()) + " " + FToStr(-np1.y()) + " " + |
||
1249 | FToStr(np2.x()) + " " + FToStr(-np2.y()) + " c\n"; |
||
1250 | } |
||
1251 | fon += "h f*\n"; |
||
1252 | np = getMinClipF(&gly); |
||
1253 | np1 = getMaxClipF(&gly); |
||
1254 | } |
||
1255 | else |
||
1256 | { |
||
1257 | fon = "h"; |
||
1258 | np = FPoint(0, 0); |
||
1259 | np1 = FPoint(0, 0); |
||
1260 | } |
||
12080 | avox | 1261 | uint fontGlyphXForm = newObject(); |
1262 | StartObj(fontGlyphXForm); |
||
8469 | fschmid | 1263 | PutDoc("<<\n/Type /XObject\n/Subtype /Form\n/FormType 1\n"); |
1264 | PutDoc("/BBox [ "+FToStr(np.x())+" "+FToStr(-np.y())+" "+FToStr(np1.x())+ " "+FToStr(-np1.y())+" ]\n"); |
||
1265 | PutDoc("/Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n"); |
||
1266 | PutDoc(">>\n"); |
||
11317 | jghali | 1267 | if (Options.Compress) |
8469 | fschmid | 1268 | fon = CompressStr(&fon); |
1269 | PutDoc("/Length "+QString::number(fon.length()+1)); |
||
11317 | jghali | 1270 | if (Options.Compress) |
8469 | fschmid | 1271 | PutDoc("\n/Filter /FlateDecode"); |
12080 | avox | 1272 | PutDoc(" >>\nstream\n"+EncStream(fon, fontGlyphXForm)+"\nendstream\nendobj\n"); |
1273 | Seite.XObjects[AllFonts[it.key()].psName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )+QString::number(ig.key())] = fontGlyphXForm; |
||
5606 | fschmid | 1274 | } |
3133 | fschmid | 1275 | } |
1276 | } |
||
1277 | else |
||
1278 | { |
||
4229 | craig | 1279 | UsedFontsP.insert(it.key(), "/Fo"+QString::number(a)); |
12080 | avox | 1280 | uint embeddedFontObject = 0; |
5980 | avox | 1281 | if ((fformat == ScFace::PFB) && (Options.EmbedList.contains(it.key()))) |
3133 | fschmid | 1282 | { |
3829 | cbradney | 1283 | QString fon(""); |
12080 | avox | 1284 | embeddedFontObject = newObject(); |
1285 | StartObj(embeddedFontObject); |
||
3133 | fschmid | 1286 | QByteArray bb; |
5980 | avox | 1287 | AllFonts[it.key()].RawData(bb); |
8559 | subik | 1288 | int posi; |
3133 | fschmid | 1289 | for (posi = 6; posi < bb.size(); ++posi) |
1290 | { |
||
1291 | if ((bb[posi] == static_cast<char>(0x80)) && (static_cast<int>(bb[posi+1]) == 2)) |
||
1292 | break; |
||
1293 | fon += QChar(bb[posi]); |
||
1294 | } |
||
1295 | int len1 = fon.length(); |
||
8559 | subik | 1296 | int ulen; |
3133 | fschmid | 1297 | ulen = bb[posi+2] & 0xff; |
1298 | ulen |= (bb[posi+3] << 8) & 0xff00; |
||
1299 | ulen |= (bb[posi+4] << 16) & 0xff0000; |
||
1300 | ulen |= (bb[posi+5] << 24) & 0xff000000; |
||
1301 | if (ulen > bb.size()) |
||
1302 | ulen = bb.size()-7; |
||
1303 | posi += 6; |
||
8559 | subik | 1304 | for (int j = 0; j < ulen; ++j) |
3133 | fschmid | 1305 | fon += QChar(bb[posi++]); |
1306 | posi += 6; |
||
1307 | int len2 = fon.length()-len1; |
||
8559 | subik | 1308 | for (int j = posi; j < bb.size(); ++j) |
3133 | fschmid | 1309 | { |
1310 | if ((bb[j] == static_cast<char>(0x80)) && (static_cast<int>(bb[j+1]) == 3)) |
||
1311 | break; |
||
1312 | if (bb[j] == '\r') |
||
1313 | fon += "\n"; |
||
1314 | else |
||
1315 | fon += QChar(bb[j]); |
||
1316 | } |
||
1317 | int len3 = fon.length()-len2-len1; |
||
11317 | jghali | 1318 | if (Options.Compress) |
3133 | fschmid | 1319 | fon = CompressStr(&fon); |
4229 | craig | 1320 | PutDoc("<<\n/Length "+QString::number(fon.length()+1)+"\n"); |
1321 | PutDoc("/Length1 "+QString::number(len1)+"\n"); |
||
1322 | PutDoc("/Length2 "+QString::number(len2)+"\n"); |
||
1323 | PutDoc("/Length3 "+QString::number(len3)+"\n"); |
||
11317 | jghali | 1324 | if (Options.Compress) |
3133 | fschmid | 1325 | PutDoc("/Filter /FlateDecode\n"); |
12080 | avox | 1326 | PutDoc(">>\nstream\n"+EncStream(fon,embeddedFontObject)+"\nendstream\nendobj\n"); |
3133 | fschmid | 1327 | } |
5980 | avox | 1328 | if ((fformat == ScFace::PFA) && (Options.EmbedList.contains(it.key()))) |
3133 | fschmid | 1329 | { |
3829 | cbradney | 1330 | QString fon(""); |
1331 | QString fon2(""); |
||
1332 | QString tm(""); |
||
3133 | fschmid | 1333 | uint value; |
1334 | bool ok = true; |
||
12080 | avox | 1335 | embeddedFontObject = newObject(); |
1336 | StartObj(embeddedFontObject); |
||
5980 | avox | 1337 | AllFonts[it.key()].EmbedFont(fon); |
10469 | cbradney | 1338 | int len1 = fon.indexOf("eexec")+5; |
3133 | fschmid | 1339 | fon2 = fon.left(len1)+"\n"; |
10469 | cbradney | 1340 | int len2 = fon.indexOf("0000000000000000000000000"); |
3133 | fschmid | 1341 | if (len2 == -1) |
1342 | len2 = fon.length()+1; |
||
1343 | int count = 0; |
||
1344 | for (int xx = len1; xx < len2-1; ++xx) |
||
1345 | { |
||
1346 | tm = fon.at(xx); |
||
1347 | if ((tm == QChar(13)) || (tm == QChar(10))) |
||
1348 | continue; |
||
1349 | xx++; |
||
1350 | count++; |
||
1351 | tm += fon.at(xx); |
||
1352 | value = tm.toUInt(&ok, 16); |
||
1353 | fon2 += QChar(value); |
||
1354 | } |
||
1355 | fon2 += fon.mid(len2); |
||
11317 | jghali | 1356 | if (Options.Compress) |
3133 | fschmid | 1357 | fon2 = CompressStr(&fon2); |
4229 | craig | 1358 | PutDoc("<<\n/Length "+QString::number(fon2.length()+1)+"\n"); |
1359 | PutDoc("/Length1 "+QString::number(len1+1)+"\n"); |
||
1360 | PutDoc("/Length2 "+QString::number(count)+"\n"); |
||
1361 | PutDoc(static_cast<int>(fon.length()-len2) == -1 ? QString("/Length3 0\n") : "/Length3 "+QString::number(fon.length()-len2)+"\n"); |
||
11317 | jghali | 1362 | if (Options.Compress) |
3133 | fschmid | 1363 | PutDoc("/Filter /FlateDecode\n"); |
12080 | avox | 1364 | PutDoc(">>\nstream\n"+EncStream(fon2, embeddedFontObject)+"\nendstream\nendobj\n"); |
3133 | fschmid | 1365 | } |
5980 | avox | 1366 | if ((fformat == ScFace::SFNT || fformat == ScFace::TTCF) && (Options.EmbedList.contains(it.key()))) |
3133 | fschmid | 1367 | { |
3829 | cbradney | 1368 | QString fon(""); |
12080 | avox | 1369 | embeddedFontObject = newObject(); |
1370 | StartObj(embeddedFontObject); |
||
3133 | fschmid | 1371 | QByteArray bb; |
5980 | avox | 1372 | AllFonts[it.key()].RawData(bb); |
3133 | fschmid | 1373 | //AV: += and append() dont't work because they stop at '\0' :-( |
8559 | subik | 1374 | for (int i=0; i < bb.size(); i++) |
3133 | fschmid | 1375 | fon += QChar(bb[i]); |
1376 | int len = fon.length(); |
||
11317 | jghali | 1377 | if (Options.Compress) |
3133 | fschmid | 1378 | fon = CompressStr(&fon); |
13085 | jghali | 1379 | //qDebug() << QString("sfnt data: size=%1 before=%2 compressed=%3").arg(bb.size()).arg(len).arg(fon.length()); |
4229 | craig | 1380 | PutDoc("<<\n/Length "+QString::number(fon.length()+1)+"\n"); |
1381 | PutDoc("/Length1 "+QString::number(len)+"\n"); |
||
11317 | jghali | 1382 | if (Options.Compress) |
3133 | fschmid | 1383 | PutDoc("/Filter /FlateDecode\n"); |
12080 | avox | 1384 | PutDoc(">>\nstream\n"+EncStream(fon, embeddedFontObject)+"\nendstream\nendobj\n"); |
3133 | fschmid | 1385 | } |
12080 | avox | 1386 | uint fontDescriptor = newObject(); |
1387 | StartObj(fontDescriptor); |
||
5387 | avox | 1388 | // TODO: think about QByteArray ScFace::getFontDescriptor() -- AV |
3133 | fschmid | 1389 | PutDoc("<<\n/Type /FontDescriptor\n"); |
5980 | avox | 1390 | PutDoc("/FontName /"+AllFonts[it.key()].psName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )+"\n"); |
15364 | jghali | 1391 | PutDoc("/FontBBox [ "+AllFonts[it.key()].fontBBoxAsString()+" ]\n"); |
3133 | fschmid | 1392 | PutDoc("/Flags "); |
5980 | avox | 1393 | //FIXME: isItalic() should be queried from ScFace, not from Qt -- AV |
3544 | avox | 1394 | //QFontInfo fo = QFontInfo(it.data()); |
3133 | fschmid | 1395 | int pfl = 0; |
5980 | avox | 1396 | if (AllFonts[it.key()].isFixedPitch()) |
3133 | fschmid | 1397 | pfl = pfl ^ 1; |
3544 | avox | 1398 | //if (fo.italic()) |
15364 | jghali | 1399 | if (AllFonts[it.key()].italicAngleAsString() != "0") |
3133 | fschmid | 1400 | pfl = pfl ^ 64; |
1401 | // pfl = pfl ^ 4; |
||
1402 | pfl = pfl ^ 32; |
||
4229 | craig | 1403 | PutDoc(QString::number(pfl)+"\n"); |
6213 | fschmid | 1404 | PutDoc("/Ascent "+AllFonts[it.key()].ascentAsString()+"\n"); |
1405 | PutDoc("/Descent "+AllFonts[it.key()].descentAsString()+"\n"); |
||
1406 | PutDoc("/CapHeight "+AllFonts[it.key()].capHeightAsString()+"\n"); |
||
15364 | jghali | 1407 | PutDoc("/ItalicAngle "+AllFonts[it.key()].italicAngleAsString()+"\n"); |
6213 | fschmid | 1408 | // PutDoc("/Ascent "+QString::number(static_cast<int>(AllFonts[it.key()].ascent()))+"\n"); |
1409 | // PutDoc("/Descent "+QString::number(static_cast<int>(AllFonts[it.key()].descent()))+"\n"); |
||
1410 | // PutDoc("/CapHeight "+QString::number(static_cast<int>(AllFonts[it.key()].capHeight()))+"\n"); |
||
1411 | // PutDoc("/ItalicAngle "+AllFonts[it.key()].italicAngle()+"\n"); |
||
1412 | // PutDoc("/StemV "+ AllFonts[it.key()].stemV() + "\n"); |
||
1413 | PutDoc("/StemV 1\n"); |
||
5980 | avox | 1414 | if ((fformat == ScFace::SFNT || fformat == ScFace::TTCF) && (Options.EmbedList.contains(it.key()))) |
12080 | avox | 1415 | PutDoc("/FontFile2 "+QString::number(embeddedFontObject)+" 0 R\n"); |
5980 | avox | 1416 | if ((fformat == ScFace::PFB) && (Options.EmbedList.contains(it.key()))) |
12080 | avox | 1417 | PutDoc("/FontFile "+QString::number(embeddedFontObject)+" 0 R\n"); |
5980 | avox | 1418 | if ((fformat == ScFace::PFA) && (Options.EmbedList.contains(it.key()))) |
12080 | avox | 1419 | PutDoc("/FontFile "+QString::number(embeddedFontObject)+" 0 R\n"); |
3133 | fschmid | 1420 | PutDoc(">>\nendobj\n"); |
4546 | subik | 1421 | /* if (!FT_Has_PS_Glyph_Names(AllFonts[it.key()]) |
3133 | fschmid | 1422 | { |
1423 | StartObj(ObjCounter); |
||
1424 | int chCount = 31; |
||
1425 | 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 "); |
||
1426 | for (int ww = 31; ww < 256; ++ww) |
||
1427 | { |
||
4229 | craig | 1428 | PutDoc(QString::number(static_cast<int>(AllFonts[it.key()]->CharWidth[itg.key()]* |
3133 | fschmid | 1429 | 1000))+" "); |
1430 | if (itg == gl.end()) |
||
1431 | break; |
||
1432 | ++itg; |
||
1433 | chCount++; |
||
1434 | } |
||
1435 | PutDoc("]\nendobj\n"); |
||
1436 | ObjCounter++; |
||
1437 | // put widths object |
||
1438 | // encoding dictionary w/ base encoding w/o differences |
||
1439 | StartObj(ObjCounter); |
||
1440 | PutDoc("<<\n/Type /Font\n/Subtype "); |
||
5980 | avox | 1441 | PutDoc((fformat == ScFace::SFNT || fformat == ScFace::TTCF) ? "/TrueType\n" : "/Type1\n"); |
4229 | craig | 1442 | PutDoc("/Name /Fo"+QString::number(a)+"\n"); |
5980 | avox | 1443 | PutDoc("/BaseFont /"+AllFonts[it.key()]->psName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "" )+"\n"); |
3133 | fschmid | 1444 | //cf. widths: |
1445 | PutDoc("/FirstChar 0\n"); |
||
4229 | craig | 1446 | PutDoc("/LastChar "+QString::number(chCount-1)+"\n"); |
1447 | PutDoc("/Widths "+QString::number(ObjCounter-1)+" 0 R\n"); |
||
1448 | PutDoc("/FontDescriptor "+QString::number(ObjCounter-2)+" 0 R\n"); |
||
3133 | fschmid | 1449 | PutDoc(">>\nendobj\n"); |
4229 | craig | 1450 | Seite.FObjects["Fo"+QString::number(a)] = ObjCounter; |
3133 | fschmid | 1451 | ObjCounter++; |
1452 | } |
||
1453 | else */ |
||
1454 | // { |
||
6301 | avox | 1455 | QMap<uint,std::pair<QChar,QString> > gl; |
1456 | AllFonts[it.key()].glyphNames(gl); |
||
1457 | int nglyphs = 0; |
||
1458 | QMap<uint,std::pair<QChar,QString> >::Iterator gli; |
||
8092 | fschmid | 1459 | for (gli = gl.begin(); gli != gl.end(); ++gli) |
1460 | { |
||
7328 | fschmid | 1461 | if (gli.key() > static_cast<uint>(nglyphs)) |
6301 | avox | 1462 | nglyphs = gli.key(); |
1463 | } |
||
1464 | ++nglyphs; |
||
13085 | jghali | 1465 | // qDebug() << QString("pdflib: nglyphs %1 max %2").arg(nglyphs).arg(AllFonts[it.key()].maxGlyph()); |
12080 | avox | 1466 | uint FontDes = fontDescriptor; |
14043 | jghali | 1467 | if (Options.Version == PDFOptions::PDFVersion_X4 && (fformat == ScFace::SFNT || fformat == ScFace::TTCF)) |
3133 | fschmid | 1468 | { |
12080 | avox | 1469 | uint fontWidths2 = newObject(); |
1470 | StartObj(fontWidths2); |
||
8147 | fschmid | 1471 | QStringList toUnicodeMaps; |
9803 | fschmid | 1472 | QList<int> toUnicodeMapsCount; |
8136 | fschmid | 1473 | QString toUnicodeMap = ""; |
1474 | int toUnicodeMapCounter = 0; |
||
14043 | jghali | 1475 | |
1476 | PutDoc("[ "); |
||
1477 | QList<uint> keys = gl.uniqueKeys(); |
||
1478 | QList<uint>::iterator git; |
||
1479 | for (git = keys.begin(); git != keys.end(); ++git) |
||
3133 | fschmid | 1480 | { |
14043 | jghali | 1481 | PutDoc(QString::number(*git)+" ["+QString::number(static_cast<int>(AllFonts[it.key()].glyphWidth(*git)* 1000))+"] " ); |
1482 | QString tmp, tmp2; |
||
1483 | tmp.sprintf("%02X", *git); |
||
1484 | tmp2.sprintf("%04X", gl.value(*git).first.unicode()); |
||
1485 | toUnicodeMap += QString("<%1> <%2>\n").arg(tmp).arg((tmp2)); |
||
1486 | toUnicodeMapCounter++; |
||
1487 | if (toUnicodeMapCounter == 100) |
||
6213 | fschmid | 1488 | { |
14043 | jghali | 1489 | toUnicodeMaps.append(toUnicodeMap); |
1490 | toUnicodeMapsCount.append(toUnicodeMapCounter); |
||
1491 | toUnicodeMap = ""; |
||
1492 | toUnicodeMapCounter = 0; |
||
6213 | fschmid | 1493 | } |
3133 | fschmid | 1494 | } |
14043 | jghali | 1495 | PutDoc("]\nendobj\n"); |
8147 | fschmid | 1496 | if (toUnicodeMapCounter != 0) |
1497 | { |
||
1498 | toUnicodeMaps.append(toUnicodeMap); |
||
1499 | toUnicodeMapsCount.append(toUnicodeMapCounter); |
||
1500 | } |
||
8136 | fschmid | 1501 | QString toUnicodeMapStream = ""; |
1502 | toUnicodeMapStream += "/CIDInit /ProcSet findresource begin\n"; |
||
1503 | toUnicodeMapStream += "12 dict begin\n"; |
||
1504 | toUnicodeMapStream += "begincmap\n"; |
||
1505 | toUnicodeMapStream += "/CIDSystemInfo <<\n"; |
||
1506 | toUnicodeMapStream += "/Registry (Adobe)\n"; |
||
1507 | toUnicodeMapStream += "/Ordering (UCS)\n"; |
||
1508 | toUnicodeMapStream += "/Supplement 0\n"; |
||
1509 | toUnicodeMapStream += ">> def\n"; |
||
1510 | toUnicodeMapStream += "/CMapName /Adobe-Identity-UCS def\n"; |
||
1511 | toUnicodeMapStream += "/CMapType 2 def\n"; |
||
1512 | toUnicodeMapStream += "1 begincodespacerange\n"; |
||
8147 | fschmid | 1513 | toUnicodeMapStream += "<0000> <FFFF>\n"; |
8136 | fschmid | 1514 | toUnicodeMapStream += "endcodespacerange\n"; |
8559 | subik | 1515 | for (int uniC = 0; uniC < toUnicodeMaps.count(); uniC++) |
8147 | fschmid | 1516 | { |
1517 | toUnicodeMapStream += QString("%1 beginbfchar\n").arg(toUnicodeMapsCount[uniC]); |
||
1518 | toUnicodeMapStream += toUnicodeMaps[uniC]; |
||
1519 | toUnicodeMapStream += "endbfchar\n"; |
||
1520 | } |
||
8136 | fschmid | 1521 | toUnicodeMapStream += "endcmap\n"; |
1522 | toUnicodeMapStream += "CMapName currentdict /CMap defineresource pop\n"; |
||
1523 | toUnicodeMapStream += "end\n"; |
||
1524 | toUnicodeMapStream += "end\n"; |
||
12906 | jghali | 1525 | uint fontToUnicode2 = WritePDFStream(toUnicodeMapStream); |
12080 | avox | 1526 | uint fontObject2 = newObject(); |
1527 | StartObj(fontObject2); |
||
14043 | jghali | 1528 | PutDoc("<<\n/Type /Font\n/Subtype /Type0\n"); |
1529 | PutDoc("/Name /Fo"+QString::number(a)+"\n"); |
||
1530 | PutDoc("/BaseFont /"+AllFonts[it.key()].psName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )+"\n"); |
||
1531 | PutDoc("/Encoding /Identity-H\n"); |
||
1532 | PutDoc("/ToUnicode "+QString::number(fontToUnicode2)+" 0 R\n"); |
||
1533 | PutDoc("/DescendantFonts ["); |
||
1534 | PutDoc("<</Type /Font"); |
||
1535 | PutDoc("/Subtype /CIDFontType2"); |
||
1536 | PutDoc("/BaseFont /"+AllFonts[it.key()].psName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )); |
||
1537 | PutDoc("/FontDescriptor "+QString::number(FontDes)+" 0 R"); |
||
1538 | PutDoc("/CIDSystemInfo <</Ordering(Identity)/Registry(Adobe)/Supplement 0>>"); |
||
1539 | PutDoc("/DW 1000"); |
||
1540 | PutDoc("/W "+QString::number(fontWidths2)+" 0 R"); |
||
1541 | PutDoc("/CIDToGIDMap /Identity"); |
||
1542 | PutDoc(">>"); // close CIDFont dictionary |
||
1543 | PutDoc("]\n"); // close DescendantFonts array |
||
1544 | PutDoc(">>\nendobj\n"); |
||
1545 | Seite.FObjects["Fo"+QString::number(a)] = fontObject2; |
||
1546 | } |
||
1547 | else |
||
1548 | { |
||
1549 | uint Fcc = nglyphs / 224; |
||
1550 | if ((nglyphs % 224) != 0) |
||
1551 | Fcc += 1; |
||
1552 | for (uint Fc = 0; Fc < Fcc; ++Fc) |
||
1553 | { |
||
1554 | uint fontWidths2 = newObject(); |
||
1555 | StartObj(fontWidths2); |
||
1556 | int chCount = 32; |
||
1557 | 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 0 "); |
||
1558 | for (int ww = 32; ww < 256; ++ww) |
||
1559 | { |
||
1560 | uint glyph = 224 * Fc + ww - 32; |
||
1561 | if (gl.contains(glyph)) |
||
1562 | PutDoc(QString::number(static_cast<int>(AllFonts[it.key()].glyphWidth(glyph)* 1000))+" "); |
||
1563 | else |
||
1564 | PutDoc("0 "); |
||
1565 | chCount++; |
||
1566 | if (signed(glyph) == nglyphs-1) |
||
1567 | break; |
||
1568 | } |
||
1569 | PutDoc("]\nendobj\n"); |
||
1570 | uint fontEncoding2 = newObject(); |
||
1571 | StartObj(fontEncoding2); |
||
1572 | QStringList toUnicodeMaps; |
||
1573 | QList<int> toUnicodeMapsCount; |
||
1574 | QString toUnicodeMap = ""; |
||
1575 | int toUnicodeMapCounter = 0; |
||
1576 | PutDoc("<< /Type /Encoding\n"); |
||
1577 | PutDoc("/Differences [ \n"); |
||
1578 | int crc = 0; |
||
1579 | bool startOfSeq = true; |
||
1580 | for (int ww2 = 32; ww2 < 256; ++ww2) |
||
1581 | { |
||
1582 | uint glyph = 224 * Fc + ww2 - 32; |
||
1583 | QMap<uint,std::pair<QChar,QString> >::Iterator glIt = gl.find(glyph); |
||
1584 | if (glIt != gl.end() && !glIt.value().second.isEmpty()) |
||
1585 | { |
||
1586 | if (startOfSeq) |
||
1587 | { |
||
1588 | PutDoc(QString::number(ww2)+" "); |
||
1589 | startOfSeq = false; |
||
1590 | } |
||
1591 | PutDoc("/"+glIt.value().second+" "); |
||
1592 | QString tmp, tmp2; |
||
1593 | tmp.sprintf("%02X", ww2); |
||
1594 | tmp2.sprintf("%04X", glIt.value().first.unicode()); |
||
1595 | toUnicodeMap += QString("<%1> <%2>\n").arg(tmp).arg((tmp2)); |
||
1596 | toUnicodeMapCounter++; |
||
1597 | if (toUnicodeMapCounter == 100) |
||
1598 | { |
||
1599 | toUnicodeMaps.append(toUnicodeMap); |
||
1600 | toUnicodeMapsCount.append(toUnicodeMapCounter); |
||
1601 | toUnicodeMap = ""; |
||
1602 | toUnicodeMapCounter = 0; |
||
1603 | } |
||
1604 | crc++; |
||
1605 | } |
||
1606 | else |
||
1607 | { |
||
1608 | startOfSeq = true; |
||
1609 | } |
||
1610 | if (signed(glyph) == nglyphs-1) |
||
1611 | break; |
||
1612 | if (crc > 8) |
||
1613 | { |
||
1614 | PutDoc("\n"); |
||
1615 | crc = 0; |
||
1616 | } |
||
1617 | } |
||
1618 | if (toUnicodeMapCounter != 0) |
||
1619 | { |
||
1620 | toUnicodeMaps.append(toUnicodeMap); |
||
1621 | toUnicodeMapsCount.append(toUnicodeMapCounter); |
||
1622 | } |
||
1623 | PutDoc("]\n"); |
||
1624 | PutDoc(">>\nendobj\n"); |
||
1625 | QString toUnicodeMapStream = ""; |
||
1626 | toUnicodeMapStream += "/CIDInit /ProcSet findresource begin\n"; |
||
1627 | toUnicodeMapStream += "12 dict begin\n"; |
||
1628 | toUnicodeMapStream += "begincmap\n"; |
||
1629 | toUnicodeMapStream += "/CIDSystemInfo <<\n"; |
||
1630 | toUnicodeMapStream += "/Registry (Adobe)\n"; |
||
1631 | toUnicodeMapStream += "/Ordering (UCS)\n"; |
||
1632 | toUnicodeMapStream += "/Supplement 0\n"; |
||
1633 | toUnicodeMapStream += ">> def\n"; |
||
1634 | toUnicodeMapStream += "/CMapName /Adobe-Identity-UCS def\n"; |
||
1635 | toUnicodeMapStream += "/CMapType 2 def\n"; |
||
1636 | toUnicodeMapStream += "1 begincodespacerange\n"; |
||
1637 | toUnicodeMapStream += "<0000> <FFFF>\n"; |
||
1638 | toUnicodeMapStream += "endcodespacerange\n"; |
||
1639 | for (int uniC = 0; uniC < toUnicodeMaps.count(); uniC++) |
||
1640 | { |
||
1641 | toUnicodeMapStream += QString("%1 beginbfchar\n").arg(toUnicodeMapsCount[uniC]); |
||
1642 | toUnicodeMapStream += toUnicodeMaps[uniC]; |
||
1643 | toUnicodeMapStream += "endbfchar\n"; |
||
1644 | } |
||
1645 | toUnicodeMapStream += "endcmap\n"; |
||
1646 | toUnicodeMapStream += "CMapName currentdict /CMap defineresource pop\n"; |
||
1647 | toUnicodeMapStream += "end\n"; |
||
1648 | toUnicodeMapStream += "end\n"; |
||
1649 | uint fontToUnicode2 = WritePDFStream(toUnicodeMapStream); |
||
1650 | uint fontObject2 = newObject(); |
||
1651 | StartObj(fontObject2); |
||
1652 | PutDoc("<<\n/Type /Font\n/Subtype "); |
||
1653 | PutDoc((fformat == ScFace::SFNT || fformat == ScFace::TTCF) ? "/TrueType\n" : "/Type1\n"); |
||
1654 | PutDoc("/Name /Fo"+QString::number(a)+"S"+QString::number(Fc)+"\n"); |
||
1655 | PutDoc("/BaseFont /"+AllFonts[it.key()].psName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )+"\n"); |
||
1656 | PutDoc("/FirstChar 0\n"); |
||
1657 | PutDoc("/LastChar "+QString::number(chCount-1)+"\n"); |
||
1658 | PutDoc("/Widths "+QString::number(fontWidths2)+" 0 R\n"); |
||
1659 | PutDoc("/Encoding "+QString::number(fontEncoding2)+" 0 R\n"); |
||
1660 | PutDoc("/ToUnicode "+QString::number(fontToUnicode2)+" 0 R\n"); |
||
1661 | PutDoc("/FontDescriptor "+QString::number(FontDes)+" 0 R\n"); |
||
1662 | PutDoc(">>\nendobj\n"); |
||
1663 | Seite.FObjects["Fo"+QString::number(a)+"S"+QString::number(Fc)] = fontObject2; |
||
1664 | } // for(Fc) |
||
1665 | uint fontWidthsForm = newObject(); |
||
1666 | StartObj(fontWidthsForm); |
||
1667 | 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 0 "); |
||
1668 | for (int ww = 32; ww < 256; ++ww) |
||
1669 | { |
||
1670 | uint glyph = AllFonts[it.key()].char2CMap(QChar(ww)); |
||
1671 | if (gl.contains(glyph)) |
||
1672 | PutDoc(QString::number(static_cast<int>(AllFonts[it.key()].glyphWidth(glyph)* 1000))+" "); |
||
1673 | else |
||
1674 | PutDoc("0 "); |
||
1675 | } |
||
1676 | PutDoc("]\nendobj\n"); |
||
1677 | uint fontObjectForm = newObject(); |
||
1678 | StartObj(fontObjectForm); |
||
3133 | fschmid | 1679 | PutDoc("<<\n/Type /Font\n/Subtype "); |
5980 | avox | 1680 | PutDoc((fformat == ScFace::SFNT || fformat == ScFace::TTCF) ? "/TrueType\n" : "/Type1\n"); |
14043 | jghali | 1681 | // if (fformat == ScFace::SFNT || fformat == ScFace::TTCF) |
1682 | // { |
||
1683 | // PutDoc("/TrueType\n"); |
||
1684 | PutDoc("/Name /Fo"+QString::number(a)+"Form"+"\n"); |
||
1685 | Seite.FObjects["Fo"+QString::number(a)+"Form"] = fontObjectForm; |
||
1686 | UsedFontsF.insert(it.key(), "/Fo"+QString::number(a)+"Form"); |
||
1687 | /* } |
||
1688 | else |
||
1689 | { |
||
1690 | PutDoc("/Type1\n"); |
||
1691 | PutDoc("/Name /"+AllFonts[it.key()].psName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )+"\n"); |
||
1692 | Seite.FObjects[AllFonts[it.key()].psName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )] = ObjCounter; |
||
1693 | UsedFontsF.insert(it.key(), "/"+AllFonts[it.key()].psName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )); |
||
1694 | } */ |
||
5980 | avox | 1695 | PutDoc("/BaseFont /"+AllFonts[it.key()].psName().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )+"\n"); |
14043 | jghali | 1696 | PutDoc("/Encoding << \n"); |
1697 | PutDoc("/Differences [ \n"); |
||
1698 | PutDoc("24 /breve /caron /circumflex /dotaccent /hungarumlaut /ogonek /ring /tilde\n"); |
||
1699 | PutDoc("39 /quotesingle 96 /grave 128 /bullet /dagger /daggerdbl /ellipsis /emdash /endash /florin /fraction /guilsinglleft /guilsinglright\n"); |
||
1700 | PutDoc("/minus /perthousand /quotedblbase /quotedblleft /quotedblright /quoteleft /quoteright /quotesinglbase /trademark /fi /fl /Lslash /OE /Scaron\n"); |
||
1701 | PutDoc("/Ydieresis /Zcaron /dotlessi /lslash /oe /scaron /zcaron 164 /currency 166 /brokenbar 168 /dieresis /copyright /ordfeminine 172 /logicalnot\n"); |
||
1702 | PutDoc("/.notdef /registered /macron /degree /plusminus /twosuperior /threesuperior /acute /mu 183 /periodcentered /cedilla /onesuperior /ordmasculine\n"); |
||
1703 | PutDoc("188 /onequarter /onehalf /threequarters 192 /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla /Egrave /Eacute /Ecircumflex\n"); |
||
1704 | PutDoc("/Edieresis /Igrave /Iacute /Icircumflex /Idieresis /Eth /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply /Oslash\n"); |
||
1705 | PutDoc("/Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn /germandbls /agrave /aacute /acircumflex /atilde /adieresis /aring /ae /ccedilla\n"); |
||
1706 | PutDoc("/egrave /eacute /ecircumflex /edieresis /igrave /iacute /icircumflex /idieresis /eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis\n"); |
||
1707 | PutDoc("/divide /oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn /ydieresis\n"); |
||
1708 | PutDoc("] >>\n"); |
||
3133 | fschmid | 1709 | PutDoc("/FirstChar 0\n"); |
14043 | jghali | 1710 | PutDoc("/LastChar 255\n"); |
1711 | PutDoc("/Widths "+QString::number(fontWidthsForm)+" 0 R\n"); |
||
4229 | craig | 1712 | PutDoc("/FontDescriptor "+QString::number(FontDes)+" 0 R\n"); |
3133 | fschmid | 1713 | PutDoc(">>\nendobj\n"); |
14043 | jghali | 1714 | // } // FT_Has_PS_Glyph_Names |
8101 | fschmid | 1715 | } |
14043 | jghali | 1716 | |
3133 | fschmid | 1717 | } |
1718 | a++; |
||
1719 | } |
||
4264 | craig | 1720 | if (Options.UseLPI) |
3133 | fschmid | 1721 | { |
12080 | avox | 1722 | uint halftones = newObject(); |
1723 | StartObj(halftones); |
||
3133 | fschmid | 1724 | PutDoc("<<\n/Type /Halftone\n/HalftoneType 5\n"); |
4264 | craig | 1725 | QMap<QString,LPIData>::const_iterator itlp; |
1726 | for (itlp = Options.LPISettings.constBegin(); itlp != Options.LPISettings.constEnd(); ++itlp) |
||
3133 | fschmid | 1727 | { |
1728 | PutDoc("/"+itlp.key()+"\n<<\n/Type /Halftone\n/HalftoneType 1\n/Frequency "); |
||
10469 | cbradney | 1729 | PutDoc(QString::number(itlp.value().Frequency)+"\n/Angle "+QString::number(itlp.value().Angle)+"\n/SpotFunction "); |
3829 | cbradney | 1730 | QString func (""); |
10469 | cbradney | 1731 | switch (itlp.value().SpotFunc) |
3133 | fschmid | 1732 | { |
1733 | case 0: |
||
1734 | func = "/SimpleDot"; |
||
1735 | break; |
||
1736 | case 1: |
||
1737 | func = "/Line"; |
||
1738 | break; |
||
1739 | case 2: |
||
1740 | func = "/Round"; |
||
1741 | break; |
||
1742 | case 3: |
||
1743 | func = "/Ellipse"; |
||
1744 | break; |
||
1745 | default: |
||
1746 | func = "/SimpleDot"; |
||
1747 | break; |
||
1748 | } |
||
1749 | PutDoc(func+"\n>>\n"); |
||
1750 | } |
||
1751 | PutDoc("/Default\n<<\n/Type /Halftone\n/HalftoneType 1\n/Frequency 50\n/Angle 45\n/SpotFunction /Round\n>>\n"); |
||
1752 | PutDoc(">>\nendobj\n"); |
||
4229 | craig | 1753 | HTName = ResNam+QString::number(ResCount); |
12080 | avox | 1754 | Transpar[HTName] = writeGState("/HT "+QString::number(halftones)+" 0 R\n"); |
3133 | fschmid | 1755 | ResCount++; |
1756 | } |
||
14043 | jghali | 1757 | if ((doc.HasCMS) && (Options.UseProfiles) && (Options.Version != PDFOptions::PDFVersion_X1a )) |
3133 | fschmid | 1758 | { |
12080 | avox | 1759 | uint iccProfileObject = newObject(); |
1760 | StartObj(iccProfileObject); |
||
7144 | jghali | 1761 | QByteArray dataP; |
3133 | fschmid | 1762 | struct ICCD dataD; |
7144 | jghali | 1763 | loadRawBytes(ScCore->InputProfiles[Options.SolidProf], dataP); |
3133 | fschmid | 1764 | PutDoc("<<\n"); |
11317 | jghali | 1765 | if (Options.Compress) |
3133 | fschmid | 1766 | { |
11317 | jghali | 1767 | QByteArray compData = CompressArray(dataP); |
1768 | if (compData.size() > 0) |
||
1769 | { |
||
1770 | PutDoc("/Filter /FlateDecode\n"); |
||
1771 | dataP = compData; |
||
1772 | } |
||
3133 | fschmid | 1773 | } |
7144 | jghali | 1774 | PutDoc("/Length "+QString::number(dataP.size()+1)+"\n"); |
4264 | craig | 1775 | PutDoc("/N "+QString::number(Options.SComp)+"\n"); |
7144 | jghali | 1776 | PutDoc(">>\nstream\n"); |
12080 | avox | 1777 | EncodeArrayToStream(dataP, iccProfileObject); |
7144 | jghali | 1778 | PutDoc("\nendstream\nendobj\n"); |
12080 | avox | 1779 | uint iccColorspace = newObject(); |
1780 | StartObj(iccColorspace); |
||
4229 | craig | 1781 | dataD.ResName = ResNam+QString::number(ResCount); |
12080 | avox | 1782 | dataD.ICCArray = "[ /ICCBased "+QString::number(iccProfileObject)+" 0 R ]"; |
1783 | dataD.ResNum = iccColorspace; |
||
12732 | fschmid | 1784 | dataD.components = Options.SComp; |
4264 | craig | 1785 | ICCProfiles[Options.SolidProf] = dataD; |
12080 | avox | 1786 | PutDoc("[ /ICCBased "+QString::number(iccProfileObject)+" 0 R ]\n"); |
3133 | fschmid | 1787 | PutDoc("endobj\n"); |
1788 | ResCount++; |
||
1789 | } |
||
4264 | craig | 1790 | if (((Options.isGrayscale == false) && (Options.UseRGB == false)) && (Options.UseSpotColors)) |
3133 | fschmid | 1791 | { |
4264 | craig | 1792 | doc.getUsedColors(colorsToUse); |
3133 | fschmid | 1793 | ColorList::Iterator itf; |
1794 | for (itf = colorsToUse.begin(); itf != colorsToUse.end(); ++itf) |
||
1795 | { |
||
1796 | if ((colorsToUse[itf.key()].isSpotColor()) || (colorsToUse[itf.key()].isRegistrationColor())) |
||
1797 | { |
||
9619 | jghali | 1798 | CMYKColor cmykValues; |
3133 | fschmid | 1799 | int cc, cm, cy, ck; |
1800 | struct SpotC spotD; |
||
9619 | jghali | 1801 | ScColorEngine::getCMYKValues(colorsToUse[itf.key()], &doc, cmykValues); |
1802 | cmykValues.getValues(cc, cm, cy, ck); |
||
3133 | fschmid | 1803 | QString colorDesc = "{\ndup "+FToStr(static_cast<double>(cc) / 255)+"\nmul exch dup "; |