Rev 22431 | Rev 22434 | 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 | |||
17539 | jghali | 28 | #if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES) |
14170 | jghali | 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> |
||
19914 | craig | 41 | #include <QCryptographicHash> |
10223 | cbradney | 42 | #include <QDateTime> |
10004 | fschmid | 43 | #include <QDataStream> |
12080 | avox | 44 | #include <QDebug> |
10223 | cbradney | 45 | #include <QDir> |
12080 | avox | 46 | #include <QFileInfo> |
47 | #include <QImage> |
||
9803 | fschmid | 48 | #include <QList> |
11453 | fschmid | 49 | #include <QPainterPath> |
8501 | cbradney | 50 | #include <QPixmap> |
12080 | avox | 51 | #include <QRect> |
52 | #include <QRegExp> |
||
19671 | jghali | 53 | #include <QScopedPointer> |
12080 | avox | 54 | #include <QStack> |
55 | #include <QString> |
||
13839 | fschmid | 56 | #include <QTemporaryFile> |
10614 | cbradney | 57 | #include <QTextCodec> |
14043 | jghali | 58 | #include <QtXml> |
59 | #include <QUuid> |
||
3133 | fschmid | 60 | |
10601 | mrdocs | 61 | #include "cmsettings.h" |
4028 | cbradney | 62 | #include "commonstrings.h" |
3133 | fschmid | 63 | #include "pageitem.h" |
10601 | mrdocs | 64 | #include "pageitem_textframe.h" |
16258 | fschmid | 65 | #include "pageitem_group.h" |
17312 | fschmid | 66 | #include "pageitem_table.h" |
10212 | cbradney | 67 | #include "pdfoptions.h" |
68 | #include "prefscontext.h" |
||
69 | #include "prefsmanager.h" |
||
70 | #include "sccolor.h" |
||
71 | #include "sccolorengine.h" |
||
72 | #include "scfonts.h" |
||
21107 | craig | 73 | #include "text/textlayoutpainter.h" |
20103 | avox | 74 | #include "fonts/cff.h" |
75 | #include "fonts/sfnt.h" |
||
16736 | jghali | 76 | #include "scpage.h" |
5917 | jghali | 77 | #include "scpaths.h" |
10212 | cbradney | 78 | #include "scpattern.h" |
19115 | avox | 79 | |
5243 | cbradney | 80 | #include "scribuscore.h" |
3699 | cbradney | 81 | #include "scribusdoc.h" |
11599 | jghali | 82 | #include "scstreamfilter_flate.h" |
83 | #include "scstreamfilter_rc4.h" |
||
17312 | fschmid | 84 | #include "tableutils.h" |
3133 | fschmid | 85 | #include "util.h" |
11605 | jghali | 86 | #include "util_file.h" |
10212 | cbradney | 87 | #include "util_formats.h" |
10203 | cbradney | 88 | #include "util_math.h" |
12517 | fschmid | 89 | #include "util_ghostscript.h" |
21107 | craig | 90 | #include "text/boxes.h" |
16736 | jghali | 91 | |
13839 | fschmid | 92 | #ifdef HAVE_OSG |
14930 | fschmid | 93 | #include "third_party/prc/exportPRC.h" |
13839 | fschmid | 94 | #endif |
3133 | fschmid | 95 | |
16736 | jghali | 96 | #include "ui/bookmwin.h" |
97 | #include "ui/bookmarkpalette.h" |
||
98 | #include "ui/multiprogressdialog.h" |
||
99 | |||
3133 | fschmid | 100 | using namespace std; |
17312 | fschmid | 101 | using namespace TableUtils; |
3133 | fschmid | 102 | |
12096 | jghali | 103 | #if defined(_WIN32) |
104 | #undef GetObject |
||
105 | #endif |
||
3133 | fschmid | 106 | |
21107 | craig | 107 | static inline QByteArray FToStr(double c) |
108 | { |
||
109 | double v = c; |
||
110 | if (fabs(c) < 0.0000001) |
||
111 | v = 0.0; |
||
112 | return QByteArray::number(v, 'f', 5); |
||
113 | } |
||
6562 | fschmid | 114 | |
21107 | craig | 115 | class PdfPainter: public TextLayoutPainter |
116 | { |
||
117 | QByteArray m_glyphBuffer; |
||
118 | QByteArray m_pathBuffer; |
||
21942 | craig | 119 | // PageItem* m_item; |
21107 | craig | 120 | QMap<QString, PdfFont> m_UsedFontsP; |
121 | PDFLibCore *m_pdf; |
||
122 | uint m_PNr; |
||
123 | const ScPage* m_page; |
||
124 | |||
22098 | jghali | 125 | QByteArray m_prevFontName; |
126 | int m_prevFontSize; |
||
127 | |||
21107 | craig | 128 | QByteArray transformToStr(QTransform tr) |
129 | { |
||
130 | return FToStr(tr.m11()) + " " + FToStr(-tr.m12()) + " " + FToStr(-tr.m21()) + " " + FToStr(tr.m22()) + " " + FToStr(tr.dx()) + " " + FToStr(-tr.dy()); |
||
131 | } |
||
132 | |||
133 | public: |
||
134 | PdfPainter(PageItem *ite, PDFLibCore *pdf, uint num, const ScPage* pag) : |
||
135 | m_glyphBuffer(), |
||
136 | m_pathBuffer(), |
||
21942 | craig | 137 | // m_item(ite), |
21107 | craig | 138 | m_pdf(pdf), |
139 | m_PNr(num), |
||
22098 | jghali | 140 | m_page(pag), |
141 | m_prevFontSize(-1) |
||
21107 | craig | 142 | {} |
143 | |||
144 | ~PdfPainter() {} |
||
145 | |||
21563 | jghali | 146 | void drawGlyph(const GlyphCluster& gc) |
21107 | craig | 147 | { |
21563 | jghali | 148 | if (gc.isControlGlyphs() || gc.isEmpty()) |
21107 | craig | 149 | return; |
21563 | jghali | 150 | |
151 | double current_x = 0.0; |
||
152 | foreach (const GlyphLayout& gl, gc.glyphs()) { |
||
153 | PdfFont pdfFont = m_pdf->UsedFontsP[font().replacementName()]; |
||
154 | QByteArray StrokeColor; |
||
155 | QByteArray FillColor; |
||
21107 | craig | 156 | |
21563 | jghali | 157 | if (strokeColor().color != CommonStrings::None) |
158 | StrokeColor = m_pdf->putColor(strokeColor().color, strokeColor().shade, false); |
||
159 | if (fillColor().color != CommonStrings::None) |
||
160 | FillColor = m_pdf->putColor(fillColor().color, fillColor().shade, true); |
||
21107 | craig | 161 | |
21563 | jghali | 162 | QTransform transform = matrix(); |
163 | if (pdfFont.method == Use_XForm) |
||
164 | { |
||
165 | if (!FillColor.isEmpty()) |
||
166 | m_pathBuffer += FillColor; |
||
21107 | craig | 167 | |
21563 | jghali | 168 | m_pathBuffer += "q\n"; |
169 | m_pathBuffer += transformToStr(transform) + " cm\n"; |
||
170 | m_pathBuffer += FToStr(fontSize()) + " 0 0 " + FToStr(fontSize()) + " " + FToStr(x() + gl.xoffset + current_x) + " " + FToStr((y() - fontSize() + gl.yoffset) * -1) + " cm\n"; |
||
21107 | craig | 171 | |
21563 | jghali | 172 | if (gl.scaleV != 1.0) |
173 | m_pathBuffer += "1 0 0 1 0 " + FToStr(((fontSize() - fontSize() * gl.scaleV) / fontSize()) * -1) + " cm\n"; |
||
174 | m_pathBuffer += FToStr(qMax(gl.scaleH, 0.1)) + " 0 0 " + FToStr(qMax(gl.scaleV, 0.1)) + " 0 0 cm\n"; |
||
21107 | craig | 175 | |
21563 | jghali | 176 | if (!FillColor.isEmpty()) |
21894 | jghali | 177 | m_pathBuffer += pdfFont.name + "_gl" + Pdf::toPdf(gl.glyph) + " Do\n"; |
21563 | jghali | 178 | m_pathBuffer += "Q\n"; |
21107 | craig | 179 | } |
180 | else |
||
21563 | jghali | 181 | { |
182 | uint gid = gl.glyph; |
||
183 | uint fontNr = 65535; |
||
21107 | craig | 184 | |
185 | switch (pdfFont.encoding) |
||
186 | { |
||
21563 | jghali | 187 | case Encode_256: |
188 | gid = pdfFont.glyphmap[gid]; |
||
189 | fontNr = gid / 256; |
||
190 | gid = gid % 256; |
||
191 | break; |
||
21107 | craig | 192 | case Encode_224: |
21563 | jghali | 193 | fontNr = gid / 224; |
194 | gid = gid % 224 + 32; |
||
21107 | craig | 195 | break; |
21563 | jghali | 196 | case Encode_Subset: |
197 | gid = pdfFont.glyphmap[gid]; |
||
198 | break; |
||
21107 | craig | 199 | case Encode_IdentityH: |
200 | break; |
||
201 | } |
||
202 | |||
22098 | jghali | 203 | QByteArray pdfFontName = pdfFont.name; |
204 | if (fontNr != 65535) |
||
205 | { |
||
206 | pdfFontName += "S"; |
||
207 | pdfFontName += Pdf::toPdf(fontNr); |
||
208 | } |
||
21107 | craig | 209 | |
22099 | jghali | 210 | if ((pdfFontName != m_prevFontName) || (fontSize() != m_prevFontSize)) |
22098 | jghali | 211 | { |
212 | m_glyphBuffer += pdfFontName + " " + FToStr(fontSize()) + " Tf\n"; |
||
213 | m_prevFontName = pdfFontName; |
||
214 | m_prevFontSize = fontSize(); |
||
215 | } |
||
216 | |||
21563 | jghali | 217 | if (!StrokeColor.isEmpty()) |
218 | m_glyphBuffer += StrokeColor; |
||
21107 | craig | 219 | |
21563 | jghali | 220 | if (!FillColor.isEmpty()) |
221 | m_glyphBuffer += FillColor; |
||
21107 | craig | 222 | |
21563 | jghali | 223 | m_glyphBuffer += "0 Tr\n"; |
21107 | craig | 224 | |
21563 | jghali | 225 | transform.translate(x() + gl.xoffset + current_x , y() + gl.yoffset); |
226 | transform.scale(qMax(gl.scaleH, 0.1), qMax(gl.scaleV, 0.1)); |
||
227 | m_glyphBuffer += transformToStr(transform) + " Tm\n"; |
||
21107 | craig | 228 | |
21563 | jghali | 229 | if (pdfFont.method != Use_Type3 || !FillColor.isEmpty()) |
21107 | craig | 230 | { |
21563 | jghali | 231 | switch (pdfFont.encoding) |
21107 | craig | 232 | { |
21563 | jghali | 233 | case Encode_224: |
234 | case Encode_256: |
||
235 | m_glyphBuffer += Pdf::toHexString8(gid) + " Tj\n"; |
||
236 | break; |
||
237 | case Encode_IdentityH: |
||
238 | default: |
||
239 | m_glyphBuffer += Pdf::toHexString16(gid) + " Tj\n"; |
||
240 | break; |
||
21107 | craig | 241 | } |
242 | } |
||
243 | } |
||
21563 | jghali | 244 | current_x += gl.xadvance; |
21107 | craig | 245 | } |
21563 | jghali | 246 | } |
21107 | craig | 247 | |
21563 | jghali | 248 | void drawGlyphOutline(const GlyphCluster& gc, bool fill) |
249 | { |
||
250 | if (gc.isControlGlyphs() || gc.isEmpty()) |
||
251 | return; |
||
21107 | craig | 252 | |
21563 | jghali | 253 | double current_x = 0.0; |
254 | foreach (const GlyphLayout& gl, gc.glyphs()) { |
||
255 | PdfFont pdfFont = m_pdf->UsedFontsP[font().replacementName()]; |
||
256 | QByteArray StrokeColor; |
||
257 | QByteArray FillColor; |
||
258 | QTransform transform = matrix(); |
||
21107 | craig | 259 | |
21563 | jghali | 260 | if (strokeColor().color != CommonStrings::None) |
261 | StrokeColor = m_pdf->putColor(strokeColor().color, strokeColor().shade, false); |
||
262 | if (fill && fillColor().color != CommonStrings::None) |
||
263 | FillColor = m_pdf->putColor(fillColor().color, fillColor().shade, true); |
||
21107 | craig | 264 | |
21563 | jghali | 265 | if (pdfFont.method == Use_XForm) |
266 | { |
||
267 | if (!StrokeColor.isEmpty()) |
||
268 | { |
||
269 | m_pathBuffer += FToStr(strokeWidth() / fontSize()) + " w\n[] 0 d\n0 J\n0 j\n"; |
||
270 | m_pathBuffer += StrokeColor; |
||
271 | } |
||
21107 | craig | 272 | |
21563 | jghali | 273 | if (!FillColor.isEmpty()) |
274 | m_pathBuffer += FillColor; |
||
275 | |||
21107 | craig | 276 | m_pathBuffer += "q\n"; |
277 | m_pathBuffer += transformToStr(transform) + " cm\n"; |
||
21563 | jghali | 278 | m_pathBuffer += FToStr(fontSize()) + " 0 0 " + FToStr(fontSize()) + " " + FToStr(x() + gl.xoffset) + " " + FToStr((y() - fontSize() + gl.yoffset) * -1) + " cm\n"; |
21107 | craig | 279 | |
21563 | jghali | 280 | if (gc.scaleV() != 1.0) |
281 | m_pathBuffer += "1 0 0 1 0 " + FToStr(((fontSize() - fontSize() * (gc.scaleV())) / fontSize()) * -1) + " cm\n"; |
||
282 | |||
283 | m_pathBuffer += FToStr(qMax(gc.scaleH(), 0.1)) + " 0 0 " + FToStr(qMax(gc.scaleV(), 0.1)) + " 0 0 cm\n"; |
||
284 | |||
285 | if (!FillColor.isEmpty()) |
||
21894 | jghali | 286 | m_pathBuffer += pdfFont.name + "_gl" + Pdf::toPdf(gl.glyph) + " Do\n"; |
21563 | jghali | 287 | |
21107 | craig | 288 | FPointArray outline = font().glyphOutline(gl.glyph); |
289 | QTransform mat; |
||
290 | mat.scale(0.1, 0.1); |
||
291 | outline.map(mat); |
||
292 | bool nPath = true; |
||
293 | FPoint np; |
||
294 | if (outline.size() > 3) |
||
295 | { |
||
296 | for (int poi = 0; poi < outline.size() - 3; poi += 4) |
||
297 | { |
||
298 | if (outline.isMarker(poi)) |
||
299 | { |
||
300 | m_pathBuffer += "h\n"; |
||
301 | nPath = true; |
||
302 | continue; |
||
303 | } |
||
304 | |||
305 | if (nPath) |
||
306 | { |
||
307 | np = outline.point(poi); |
||
308 | m_pathBuffer += FToStr(np.x()) + " " + FToStr(-np.y()) + " m\n"; |
||
309 | nPath = false; |
||
310 | } |
||
311 | |||
312 | np = outline.point(poi + 1); |
||
313 | m_pathBuffer += FToStr(np.x()) + " " + FToStr(-np.y()) + " "; |
||
314 | np = outline.point(poi + 3); |
||
315 | m_pathBuffer += FToStr(np.x()) + " " + FToStr(-np.y()) + " "; |
||
316 | np = outline.point(poi + 2); |
||
317 | m_pathBuffer += FToStr(np.x()) + " " + FToStr(-np.y()) + " c\n"; |
||
318 | } |
||
319 | } |
||
320 | m_pathBuffer += "h s\n"; |
||
321 | m_pathBuffer += "Q\n"; |
||
322 | } |
||
323 | else |
||
324 | { |
||
21563 | jghali | 325 | if (!StrokeColor.isEmpty()) |
326 | m_pathBuffer += StrokeColor; |
||
21107 | craig | 327 | |
21563 | jghali | 328 | uint gid = gl.glyph; |
329 | uint fontNr = 65535; |
||
21107 | craig | 330 | switch (pdfFont.encoding) |
331 | { |
||
21563 | jghali | 332 | case Encode_256: |
333 | gid = pdfFont.glyphmap[gid]; |
||
334 | fontNr = gid / 256; |
||
335 | gid = gid % 256; |
||
336 | break; |
||
21107 | craig | 337 | case Encode_224: |
21563 | jghali | 338 | fontNr = gid / 224; |
339 | gid = gid % 224 + 32; |
||
21107 | craig | 340 | break; |
21563 | jghali | 341 | case Encode_Subset: |
342 | gid = pdfFont.glyphmap[gid]; |
||
343 | break; |
||
21107 | craig | 344 | case Encode_IdentityH: |
345 | break; |
||
346 | } |
||
21563 | jghali | 347 | |
22098 | jghali | 348 | QByteArray pdfFontName = pdfFont.name; |
349 | if (fontNr != 65535) |
||
350 | { |
||
351 | pdfFontName += "S"; |
||
352 | pdfFontName += Pdf::toPdf(fontNr); |
||
353 | } |
||
21563 | jghali | 354 | |
22099 | jghali | 355 | if ((pdfFontName != m_prevFontName) || (fontSize() != m_prevFontSize)) |
22098 | jghali | 356 | { |
357 | m_glyphBuffer += pdfFontName + " " + FToStr(fontSize()) + " Tf\n"; |
||
358 | m_prevFontName = pdfFontName; |
||
359 | m_prevFontSize = fontSize(); |
||
360 | } |
||
361 | |||
21563 | jghali | 362 | if (!StrokeColor.isEmpty()) |
363 | m_glyphBuffer += StrokeColor; |
||
364 | |||
365 | if (!FillColor.isEmpty()) |
||
366 | m_glyphBuffer += FillColor; |
||
367 | |||
368 | if (pdfFont.method == Use_Type3 && !StrokeColor.isEmpty()) |
||
369 | { |
||
370 | m_pathBuffer += "q\n"; |
||
371 | m_pathBuffer += FToStr(strokeWidth()) + " w\n[] 0 d\n0 J\n0 j\n"; |
||
372 | |||
373 | transform.scale(fontSize(), fontSize()); |
||
374 | transform.translate(x() + gl.xoffset + current_x, y() + gl.yoffset); |
||
375 | if (gc.scaleV() != 1.0) |
||
376 | transform.translate(0, ((fontSize() - fontSize() * gc.scaleV()) / fontSize()) * -1); |
||
377 | transform.scale(qMax(gc.scaleH(), 0.1), qMax(gc.scaleV(), 0.1)); |
||
378 | m_pathBuffer += transformToStr(transform) + " cm\n"; |
||
379 | |||
380 | /* paint outline */ |
||
381 | FPointArray outline = font().glyphOutline(gl.glyph); |
||
382 | QTransform mat; |
||
383 | mat.scale(0.1, 0.1); |
||
384 | outline.map(mat); |
||
385 | bool nPath = true; |
||
386 | FPoint np; |
||
387 | if (outline.size() > 3) |
||
388 | { |
||
389 | for (int poi = 0; poi < outline.size() - 3; poi += 4) |
||
390 | { |
||
391 | if (outline.isMarker(poi)) |
||
392 | { |
||
393 | m_pathBuffer += "h\n"; |
||
394 | nPath = true; |
||
395 | continue; |
||
396 | } |
||
397 | |||
398 | if (nPath) |
||
399 | { |
||
400 | np = outline.point(poi); |
||
401 | m_pathBuffer += FToStr(np.x()) + " " + FToStr(-np.y()) + " m\n"; |
||
402 | nPath = false; |
||
403 | } |
||
404 | |||
405 | np = outline.point(poi + 1); |
||
406 | m_pathBuffer += FToStr(np.x()) + " " + FToStr(-np.y()) + " "; |
||
407 | np = outline.point(poi + 3); |
||
408 | m_pathBuffer += FToStr(np.x()) + " " + FToStr(-np.y()) + " "; |
||
409 | np = outline.point(poi + 2); |
||
410 | m_pathBuffer += FToStr(np.x()) + " " + FToStr(-np.y()) + " c\n"; |
||
411 | } |
||
412 | } |
||
413 | m_pathBuffer += "h s\n"; |
||
414 | m_pathBuffer += "Q\n"; |
||
415 | } |
||
416 | else |
||
417 | { |
||
418 | m_glyphBuffer += FToStr(strokeWidth()) + " w "; |
||
419 | if (fill) |
||
420 | m_glyphBuffer += "2 Tr\n"; |
||
421 | else |
||
422 | m_glyphBuffer += "1 Tr\n"; |
||
423 | } |
||
424 | |||
425 | transform.translate(x() + gl.xoffset + current_x, y() + gl.yoffset); |
||
426 | transform.scale(qMax(gc.scaleH(), 0.1), qMax(gc.scaleV(), 0.1)); |
||
427 | m_glyphBuffer += transformToStr(transform) + " Tm\n"; |
||
428 | |||
429 | if (pdfFont.method != Use_Type3 || !FillColor.isEmpty()) |
||
430 | { |
||
431 | switch (pdfFont.encoding) |
||
432 | { |
||
433 | case Encode_224: |
||
434 | case Encode_256: |
||
435 | m_glyphBuffer += Pdf::toHexString8(gid) + " Tj\n"; |
||
436 | break; |
||
437 | case Encode_IdentityH: |
||
438 | default: |
||
439 | m_glyphBuffer += Pdf::toHexString16(gid) + " Tj\n"; |
||
440 | break; |
||
441 | } |
||
442 | } |
||
21107 | craig | 443 | } |
21563 | jghali | 444 | current_x += gl.xadvance; |
21107 | craig | 445 | } |
446 | } |
||
447 | |||
448 | void drawLine(QPointF start, QPointF end) |
||
449 | { |
||
450 | QTransform transform = matrix(); |
||
451 | transform.translate(x(), y()); |
||
452 | m_pathBuffer += "q\n"; |
||
453 | m_pathBuffer += transformToStr(transform) + " cm\n"; |
||
454 | m_pathBuffer += m_pdf->putColor(strokeColor().color, strokeColor().shade, false); |
||
455 | m_pathBuffer += FToStr(strokeWidth())+" w\n"; |
||
456 | m_pathBuffer += FToStr(start.x()) + " " + FToStr(-start.y()) + " m\n"; |
||
457 | m_pathBuffer += FToStr(end.x()) + " " + FToStr(-end.y()) + " l\n"; |
||
458 | m_pathBuffer += "S\n"; |
||
459 | m_pathBuffer += "Q\n"; |
||
460 | } |
||
461 | |||
462 | QByteArray getBuffer() |
||
463 | { |
||
464 | return "BT\n" + m_glyphBuffer + "ET\n" + m_pathBuffer; |
||
465 | } |
||
466 | |||
467 | void drawRect(QRectF rect) |
||
468 | { |
||
469 | QTransform transform = matrix(); |
||
470 | // transform.translate(x(), y()); |
||
471 | double rectX = x() + rect.x(); |
||
472 | double rectY = -y() - rect.y(); |
||
473 | m_glyphBuffer += "q\n"; |
||
474 | m_glyphBuffer += transformToStr(transform) + " cm\n"; |
||
475 | m_glyphBuffer += "n\n"; |
||
476 | m_glyphBuffer += m_pdf->putColor(fillColor().color, fillColor().shade, true); |
||
477 | m_glyphBuffer += m_pdf->putColor(strokeColor().color, strokeColor().shade, false); |
||
478 | m_glyphBuffer += FToStr(rectX) + " " + FToStr(rectY) + " m\n"; |
||
479 | m_glyphBuffer += FToStr(rectX + rect.width()) + " " + FToStr(rectY) + " l\n"; |
||
480 | m_glyphBuffer += FToStr(rectX + rect.width()) + " " + FToStr(rectY - rect.height()) + " l\n"; |
||
481 | m_glyphBuffer += FToStr(rectX) + " " + FToStr(rectY - rect.height()) + " l\n"; |
||
482 | m_glyphBuffer += "h\nf\n"; |
||
483 | m_glyphBuffer += "Q\n"; |
||
484 | } |
||
485 | |||
486 | void drawObject(PageItem* embedded) |
||
487 | { |
||
488 | m_glyphBuffer += "ET\n"+m_pathBuffer; |
||
489 | m_pathBuffer = ""; |
||
490 | |||
491 | m_pathBuffer += "q\n"; |
||
21301 | fschmid | 492 | m_pathBuffer += FToStr(scaleH()) + " 0 0 " + FToStr(scaleV()) + " " + FToStr(x() + embedded->gXpos) + " " + FToStr(-(y() + embedded->gYpos)) + " cm\n"; |
21107 | craig | 493 | |
494 | QByteArray output; |
||
495 | if (!m_pdf->PDF_ProcessItem(output, embedded, m_page, m_PNr, true)) |
||
496 | return; |
||
497 | m_pathBuffer += output; |
||
498 | m_pathBuffer += "Q\n"; |
||
499 | m_glyphBuffer += m_pathBuffer+"\n"; |
||
500 | m_pathBuffer = ""; |
||
501 | |||
22098 | jghali | 502 | m_prevFontName.clear(); |
503 | m_prevFontSize = -1; |
||
21107 | craig | 504 | m_glyphBuffer += "BT\n"; |
505 | } |
||
506 | }; |
||
507 | |||
10054 | craig | 508 | PDFLibCore::PDFLibCore(ScribusDoc & docu) |
4264 | craig | 509 | : QObject(&docu), |
4223 | craig | 510 | doc(docu), |
511 | ActPageP(0), |
||
14925 | cbradney | 512 | Options(doc.pdfOptions()), |
4223 | craig | 513 | Bvie(0), |
19114 | avox | 514 | ucs2Codec(0), |
20103 | avox | 515 | // ObjCounter(7), |
4223 | craig | 516 | ResNam("RE"), |
517 | ResCount(0), |
||
518 | NDnam("LI"), |
||
519 | NDnum(0), |
||
20103 | avox | 520 | // KeyGen(""), |
521 | // OwnerKey(""), |
||
522 | // UserKey(""), |
||
523 | // FileID(""), |
||
524 | // EncryKey(""), |
||
525 | // Encrypt(0), |
||
526 | // KeyLen(5), |
||
4223 | craig | 527 | colorsToUse(), |
528 | spotNam("Spot"), |
||
529 | spotCount(0), |
||
4225 | craig | 530 | progressDialog(0), |
4223 | craig | 531 | abortExport(false), |
20089 | jghali | 532 | usingGUI(ScCore->usingGUI()), |
533 | bleedDisplacementX(0), |
||
534 | bleedDisplacementY(0) |
||
3133 | fschmid | 535 | { |
20103 | avox | 536 | // KeyGen.resize(32); |
537 | // OwnerKey.resize(32); |
||
538 | // UserKey.resize(32); |
||
539 | // FileID.resize(16); |
||
540 | // EncryKey.resize(5); |
||
3133 | fschmid | 541 | Catalog.Outlines = 2; |
542 | Catalog.PageTree = 3; |
||
543 | Catalog.Dest = 4; |
||
544 | PageTree.Count = 0; |
||
545 | Outlines.First = 0; |
||
546 | Outlines.Last = 0; |
||
547 | Outlines.Count = 0; |
||
20103 | avox | 548 | pageData.ObjNum = 0; |
549 | pageData.Thumb = 0; |
||
550 | // int kg_array[] = {0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, |
||
551 | // 0x01, 0x08, 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80, 0x2f, 0x0c, 0xa9, 0xfe, |
||
552 | // 0x64, 0x53, 0x69, 0x7a}; |
||
553 | // for (int a = 0; a < 32; ++a) |
||
554 | // KeyGen[a] = kg_array[a]; |
||
4028 | cbradney | 555 | if (usingGUI) |
556 | { |
||
10508 | cbradney | 557 | progressDialog = new MultiProgressDialog( tr("Saving PDF"), CommonStrings::tr_Cancel, doc.scMW()); |
4224 | craig | 558 | Q_CHECK_PTR(progressDialog); |
559 | QStringList barNames, barTexts; |
||
560 | barNames << "EMP" << "EP" << "ECPI"; |
||
5370 | cbradney | 561 | barTexts << tr("Exporting Master Page:") << tr("Exporting Page:") << tr("Exporting Items on Current Page:"); |
9803 | fschmid | 562 | QList<bool> barsNumeric; |
5370 | cbradney | 563 | barsNumeric << true << true << false; |
564 | progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric); |
||
8559 | subik | 565 | connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested())); |
4028 | cbradney | 566 | } |
3133 | fschmid | 567 | } |
568 | |||
10054 | craig | 569 | PDFLibCore::~PDFLibCore() |
4224 | craig | 570 | { |
571 | delete progressDialog; |
||
572 | } |
||
573 | |||
4229 | craig | 574 | |
19115 | avox | 575 | bool PDFLibCore::PDF_IsPDFX() |
576 | { |
||
577 | if (Options.Version == PDFOptions::PDFVersion_X1a) |
||
578 | return true; |
||
579 | if (Options.Version == PDFOptions::PDFVersion_X3) |
||
580 | return true; |
||
581 | if (Options.Version == PDFOptions::PDFVersion_X4) |
||
582 | return true; |
||
583 | return false; |
||
584 | } |
||
585 | |||
586 | bool PDFLibCore::PDF_IsPDFX(PDFOptions::PDFVersion ver) |
||
587 | { |
||
588 | if (ver == PDFOptions::PDFVersion_X1a) |
||
589 | return true; |
||
590 | if (ver == PDFOptions::PDFVersion_X3) |
||
591 | return true; |
||
592 | if (ver == PDFOptions::PDFVersion_X4) |
||
593 | return true; |
||
594 | return false; |
||
595 | } |
||
596 | |||
10054 | craig | 597 | bool PDFLibCore::doExport(const QString& fn, const QString& nam, int Components, |
4264 | craig | 598 | const std::vector<int> & pageNs, const QMap<int,QPixmap> & thumbs) |
3133 | fschmid | 599 | { |
600 | QPixmap pm; |
||
11060 | jghali | 601 | bool ret = false, error = false; |
602 | int pc_exportpages=0; |
||
603 | int pc_exportmasterpages=0; |
||
4224 | craig | 604 | if (usingGUI) |
605 | progressDialog->show(); |
||
5387 | avox | 606 | QMap<QString, QMap<uint, FPointArray> > usedFonts; |
607 | usedFonts.clear(); |
||
608 | doc.getUsedFonts(usedFonts); |
||
19114 | avox | 609 | ucs2Codec = QTextCodec::codecForName("ISO-10646-UCS-2"); |
17758 | jghali | 610 | if (!ucs2Codec) |
19114 | avox | 611 | ucs2Codec = QTextCodec::codecForName("UTF-16"); |
612 | if (!ucs2Codec) |
||
13764 | jghali | 613 | { |
13791 | pierre | 614 | PDF_Error( tr("Qt build miss both \"UTF-16\" and \"ISO-10646-UCS-2\" text codecs, pdf export is not possible") ); |
13764 | jghali | 615 | return false; |
616 | } |
||
13955 | cbradney | 617 | if (PDF_Begin_Doc(fn, PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts, usedFonts, doc.scMW()->bookmarkPalette->BView)) |
3133 | fschmid | 618 | { |
619 | QMap<int, int> pageNsMpa; |
||
620 | for (uint a = 0; a < pageNs.size(); ++a) |
||
621 | { |
||
14653 | jghali | 622 | pageNsMpa.insert(doc.MasterNames[doc.DocPages.at(pageNs[a]-1)->MPageNam], 0); |
3133 | fschmid | 623 | } |
4028 | cbradney | 624 | if (usingGUI) |
3133 | fschmid | 625 | { |
4028 | cbradney | 626 | progressDialog->setOverallTotalSteps(pageNsMpa.count()+pageNs.size()); |
627 | progressDialog->setTotalSteps("EMP", pageNsMpa.count()); |
||
628 | progressDialog->setTotalSteps("EP", pageNs.size()); |
||
629 | progressDialog->setOverallProgress(0); |
||
630 | progressDialog->setProgress("EMP", 0); |
||
631 | progressDialog->setProgress("EP", 0); |
||
632 | } |
||
10018 | fschmid | 633 | for (int ap = 0; ap < doc.MasterPages.count() && !abortExport; ++ap) |
4028 | cbradney | 634 | { |
4264 | craig | 635 | if (doc.MasterItems.count() != 0) |
3133 | fschmid | 636 | { |
637 | if (pageNsMpa.contains(ap)) |
||
638 | { |
||
5243 | cbradney | 639 | qApp->processEvents(); |
11060 | jghali | 640 | if (!PDF_TemplatePage(doc.MasterPages.at(ap))) |
641 | error = abortExport = true; |
||
4028 | cbradney | 642 | ++pc_exportmasterpages; |
3133 | fschmid | 643 | } |
644 | } |
||
4546 | subik | 645 | if (usingGUI) |
646 | { |
||
4028 | cbradney | 647 | progressDialog->setProgress("EMP", pc_exportmasterpages); |
648 | progressDialog->setOverallProgress(pc_exportmasterpages+pc_exportpages); |
||
649 | } |
||
3133 | fschmid | 650 | } |
4028 | cbradney | 651 | for (uint a = 0; a < pageNs.size() && !abortExport; ++a) |
3133 | fschmid | 652 | { |
14925 | cbradney | 653 | if (doc.pdfOptions().Thumbnails) |
3133 | fschmid | 654 | pm = thumbs[pageNs[a]]; |
5243 | cbradney | 655 | qApp->processEvents(); |
4028 | cbradney | 656 | if (abortExport) break; |
11060 | jghali | 657 | |
14653 | jghali | 658 | PDF_Begin_Page(doc.DocPages.at(pageNs[a]-1), pm); |
5243 | cbradney | 659 | qApp->processEvents(); |
4028 | cbradney | 660 | if (abortExport) break; |
11060 | jghali | 661 | |
14925 | cbradney | 662 | if (!PDF_ProcessPage(doc.DocPages.at(pageNs[a]-1), pageNs[a]-1, doc.pdfOptions().doClip)) |
11060 | jghali | 663 | error = abortExport = true; |
5243 | cbradney | 664 | qApp->processEvents(); |
4028 | cbradney | 665 | if (abortExport) break; |
11060 | jghali | 666 | |
15444 | craig | 667 | PDF_End_Page(a); |
4028 | cbradney | 668 | pc_exportpages++; |
669 | if (usingGUI) |
||
670 | { |
||
671 | progressDialog->setProgress("EP", pc_exportpages); |
||
672 | progressDialog->setOverallProgress(pc_exportmasterpages+pc_exportpages); |
||
673 | } |
||
3133 | fschmid | 674 | } |
20681 | craig | 675 | ret = true;//Even when aborting we return true. Don't want that "couldnt write msg" |
4028 | cbradney | 676 | if (!abortExport) |
677 | { |
||
19115 | avox | 678 | if (PDF_IsPDFX(doc.pdfOptions().Version)) |
14925 | cbradney | 679 | ret = PDF_End_Doc(ScCore->PrinterProfiles[doc.pdfOptions().PrintProf], nam, Components); |
4028 | cbradney | 680 | else |
12387 | jghali | 681 | ret = PDF_End_Doc(); |
4028 | cbradney | 682 | } |
3133 | fschmid | 683 | else |
4028 | cbradney | 684 | closeAndCleanup(); |
3133 | fschmid | 685 | } |
4029 | cbradney | 686 | if (usingGUI) |
687 | progressDialog->close(); |
||
11060 | jghali | 688 | return (ret && !error); |
3133 | fschmid | 689 | } |
690 | |||
11060 | jghali | 691 | const QString& PDFLibCore::errorMessage(void) const |
692 | { |
||
693 | return ErrorMessage; |
||
694 | } |
||
695 | |||
11441 | jghali | 696 | bool PDFLibCore::exportAborted(void) const |
697 | { |
||
698 | return abortExport; |
||
699 | } |
||
700 | |||
20103 | avox | 701 | //#define StartObj(n) writer.startObj((n)) |
702 | #define PutDoc(s) writer.write(s) |
||
703 | //#define newObject() writer.newObject() |
||
3133 | fschmid | 704 | |
705 | |||
20103 | avox | 706 | //void PDFLibCore::StartObj(PdfId nr) |
707 | //{ |
||
708 | // for (int i=XRef.size(); i < nr; ++i) |
||
709 | // XRef.append(0); |
||
710 | // XRef[nr-1] = bytesWritten(); |
||
711 | // PutDoc(Pdf::toPdf(nr)+ " 0 obj\n"); |
||
712 | //} |
||
713 | |||
714 | //// Encode a string for inclusion in a |
||
715 | //// PDF (literal) . |
||
716 | //static QByteArray PDFEncode(const QString & in) |
||
717 | //{ |
||
718 | // QByteArray tmp(""); |
||
719 | // for (int d = 0; d < in.length(); ++d) |
||
720 | // { |
||
721 | // QChar cc(in.at(d)); |
||
722 | // if ((cc == '(') || (cc == ')') || (cc == '\\')) |
||
723 | // tmp += '\\'; |
||
724 | // else if ((cc == '\r') || (cc == '\n')) |
||
725 | // { |
||
726 | // tmp += (cc == '\r') ? "\\r" : "\\n"; |
||
727 | // continue; |
||
728 | // } |
||
729 | // tmp += cc; |
||
730 | // } |
||
731 | // return tmp; |
||
732 | //} |
||
733 | |||
734 | static QByteArray blendMode(int code) |
||
12080 | avox | 735 | { |
736 | switch (code) |
||
737 | { |
||
738 | case 0: |
||
739 | return("Normal"); |
||
740 | break; |
||
741 | case 1: |
||
742 | return("Darken"); |
||
743 | break; |
||
744 | case 2: |
||
745 | return("Lighten"); |
||
746 | break; |
||
747 | case 3: |
||
748 | return("Multiply"); |
||
749 | break; |
||
750 | case 4: |
||
751 | return("Screen"); |
||
752 | break; |
||
753 | case 5: |
||
754 | return("Overlay"); |
||
755 | break; |
||
756 | case 6: |
||
757 | return("HardLight"); |
||
758 | break; |
||
759 | case 7: |
||
760 | return("SoftLight"); |
||
761 | break; |
||
762 | case 8: |
||
763 | return("Difference"); |
||
764 | break; |
||
765 | case 9: |
||
766 | return("Exclusion"); |
||
767 | break; |
||
768 | case 10: |
||
769 | return("ColorDodge"); |
||
770 | break; |
||
771 | case 11: |
||
772 | return("ColorBurn"); |
||
773 | break; |
||
774 | case 12: |
||
775 | return("Hue"); |
||
776 | break; |
||
777 | case 13: |
||
778 | return("Saturation"); |
||
779 | break; |
||
780 | case 14: |
||
781 | return("Color"); |
||
782 | break; |
||
783 | case 15: |
||
784 | return("Luminosity"); |
||
785 | break; |
||
786 | default: |
||
787 | return ""; |
||
788 | } |
||
14043 | jghali | 789 | } |
20103 | avox | 790 | // |
791 | //QByteArray PDFLibCore::EncodeUTF16(const QString &in) |
||
792 | //{ |
||
793 | // QString tmp = in; |
||
794 | // QByteArray cres = ucs2Codec->fromUnicode( tmp ); |
||
795 | //#ifndef WORDS_BIGENDIAN |
||
796 | // // on little endian systems we need to swap bytes: |
||
797 | // uchar sw; |
||
798 | // for(int d = 0; d < cres.size()-1; d += 2) |
||
799 | // { |
||
800 | // sw = cres[d]; |
||
801 | // cres[d] = cres[d+1]; |
||
802 | // cres[d+1] = sw; |
||
803 | // } |
||
804 | //#endif |
||
805 | // return cres; |
||
806 | //} |
||
12080 | avox | 807 | |
20103 | avox | 808 | QByteArray PDFLibCore::EncStream(const QByteArray & in, PdfId ObjNum) |
19114 | avox | 809 | { |
810 | if (in.length() < 1) |
||
20103 | avox | 811 | return QByteArray(); |
19114 | avox | 812 | else if (!Options.Encrypt) |
813 | return in; |
||
20112 | jghali | 814 | else |
815 | return writer.encryptBytes(in, ObjNum); |
||
20103 | avox | 816 | // rc4_context_t rc4; |
817 | // QByteArray tmp(in); |
||
818 | // QByteArray us(tmp.length(), ' '); |
||
819 | // QByteArray ou(tmp.length(), ' '); |
||
820 | // for (int a = 0; a < tmp.length(); ++a) |
||
20112 | jghali | 821 | // us[a] = (tmp.at(a)); |
822 | // QByteArray step1 = writer.ComputeRC4Key(ObjNum); |
||
20103 | avox | 823 | // rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), qMin(KeyLen+5, 16)); |
824 | // rc4_encrypt(&rc4, reinterpret_cast<uchar*>(us.data()), reinterpret_cast<uchar*>(ou.data()), tmp.length()); |
||
825 | // QString uk = ""; |
||
826 | // for (int cl = 0; cl < tmp.length(); ++cl) |
||
827 | // uk += QChar(ou[cl]); |
||
828 | // return ou; |
||
19114 | avox | 829 | } |
830 | |||
20103 | avox | 831 | QByteArray PDFLibCore::EncString(const QByteArray & in, PdfId ObjNum) |
19114 | avox | 832 | { |
833 | if (in.length() < 1) |
||
834 | return "<>"; |
||
835 | if (!Options.Encrypt) |
||
836 | { |
||
20103 | avox | 837 | //tmp = "(" + PDFEncode(in) + ")"; |
20112 | jghali | 838 | return Pdf::toLiteralString(in); |
19114 | avox | 839 | } |
20112 | jghali | 840 | |
20103 | avox | 841 | // rc4_context_t rc4; |
842 | // QByteArray us(in.length(), ' '); |
||
843 | // QByteArray ou(in.length(), ' '); |
||
844 | // for (int a = 0; a < in.length(); ++a) |
||
845 | // us[a] = static_cast<uchar>(QChar(in.at(a)).cell()); |
||
846 | // QByteArray step1 = writer.ComputeRC4Key(ObjNum); |
||
847 | // rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), qMin(KeyLen+5, 16)); |
||
848 | // rc4_encrypt(&rc4, reinterpret_cast<uchar*>(us.data()), reinterpret_cast<uchar*>(ou.data()), in.length()); |
||
849 | // QString uk = ""; |
||
850 | // for (int cl = 0; cl < in.length(); ++cl) |
||
851 | // uk += QChar(ou[cl]); |
||
20112 | jghali | 852 | |
853 | return Pdf::toHexString(writer.encryptBytes(in, ObjNum)); |
||
19114 | avox | 854 | } |
855 | |||
20103 | avox | 856 | QByteArray PDFLibCore::EncStringUTF16(const QString & in, PdfId ObjNum) |
19114 | avox | 857 | { |
858 | if (in.length() < 1) |
||
859 | return "<>"; |
||
860 | if (!Options.Encrypt) |
||
861 | { |
||
20112 | jghali | 862 | QByteArray us = Pdf::toUTF16(in); |
20103 | avox | 863 | // QString uk = ""; |
864 | // for (int cl = 0; cl < us.size(); ++cl) |
||
865 | // uk += QChar(us[cl]); |
||
866 | return Pdf::toHexString(us); |
||
19114 | avox | 867 | } |
20103 | avox | 868 | // rc4_context_t rc4; |
20112 | jghali | 869 | QByteArray us = Pdf::toUTF16(in); |
20103 | avox | 870 | // QByteArray ou(us.size(), ' '); |
871 | // QByteArray step1 = writer.ComputeRC4Key(ObjNum); |
||
872 | // rc4_init(&rc4, reinterpret_cast<uchar*>(step1.data()), qMin(KeyLen+5, 16)); |
||
873 | // rc4_encrypt(&rc4, reinterpret_cast<uchar*>(us.data()), reinterpret_cast<uchar*>(ou.data()), ou.size()); |
||
874 | // QString uk = ""; |
||
875 | // for (int cl = 0; cl < ou.size(); ++cl) |
||
876 | // uk += QChar(ou[cl]); |
||
877 | QByteArray tmp = Pdf::toHexString(writer.encryptBytes(us, ObjNum)); |
||
19114 | avox | 878 | return tmp; |
879 | } |
||
880 | |||
20103 | avox | 881 | bool PDFLibCore::EncodeArrayToStream(const QByteArray& in, PdfId ObjNum) |
19114 | avox | 882 | { |
883 | if (in.size() < 1) |
||
884 | return true; |
||
885 | bool succeed = false; |
||
886 | if (Options.Encrypt) |
||
887 | { |
||
20103 | avox | 888 | ScStreamFilter* rc4Encode = writer.openStreamFilter(true, ObjNum); |
889 | if (rc4Encode->openFilter()) |
||
19114 | avox | 890 | { |
20103 | avox | 891 | succeed = rc4Encode->writeData(in.data(), in.size()); |
892 | succeed &= rc4Encode->closeFilter(); |
||
19114 | avox | 893 | } |
20112 | jghali | 894 | delete rc4Encode; |
19114 | avox | 895 | } |
896 | else |
||
20103 | avox | 897 | writer.write(in); |
898 | return (writer.getOutStream().status() == QDataStream::Ok); |
||
19114 | avox | 899 | } |
900 | |||
20103 | avox | 901 | int PDFLibCore::WriteImageToStream(ScImage& image, PdfId ObjNum, ColorSpaceEnum format, bool precal) |
11599 | jghali | 902 | { |
17758 | jghali | 903 | bool fromCmyk, succeed = false; |
11599 | jghali | 904 | int bytesWritten = 0; |
20103 | avox | 905 | |
20112 | jghali | 906 | ScStreamFilter* rc4Encode = writer.openStreamFilter(Options.Encrypt, ObjNum); |
907 | if (rc4Encode->openFilter()) |
||
908 | { |
||
909 | switch (format) |
||
910 | { |
||
911 | case ColorSpaceMonochrome : |
||
912 | fromCmyk = !Options.UseRGB && !Options.isGrayscale && !(doc.HasCMS && Options.UseProfiles2); |
||
913 | succeed = image.writeMonochromeDataToFilter(rc4Encode, fromCmyk); break; |
||
914 | case ColorSpaceGray : |
||
915 | succeed = image.writeGrayDataToFilter(rc4Encode, precal); break; |
||
916 | case ColorSpaceCMYK : |
||
917 | succeed = image.writeCMYKDataToFilter(rc4Encode); break; |
||
918 | default : |
||
919 | succeed = image.writeRGBDataToFilter(rc4Encode); break; |
||
920 | } |
||
921 | succeed &= rc4Encode->closeFilter(); |
||
922 | bytesWritten = rc4Encode->writtenToStream(); |
||
923 | delete rc4Encode; |
||
924 | } |
||
11599 | jghali | 925 | return (succeed ? bytesWritten : 0); |
926 | } |
||
927 | |||
20103 | avox | 928 | int PDFLibCore::WriteJPEGImageToStream(ScImage& image, const QString& fn, PdfId ObjNum, int quality, ColorSpaceEnum format, |
17758 | jghali | 929 | bool sameFile, bool precal) |
11599 | jghali | 930 | { |
931 | bool succeed = true; |
||
932 | int bytesWritten = 0; |
||
933 | QFileInfo fInfo(fn); |
||
934 | QString ext = fInfo.suffix().toLower(); |
||
935 | QString jpgFileName, tmpFile; |
||
936 | if (extensionIndicatesJPEG(ext) && sameFile) |
||
937 | jpgFileName = fn; |
||
11445 | jghali | 938 | else |
11599 | jghali | 939 | { |
21526 | craig | 940 | tmpFile = QDir::toNativeSeparators(ScPaths::tempFileDir() + "sc.jpg"); |
17758 | jghali | 941 | if (format == ColorSpaceGray && (!precal)) |
11599 | jghali | 942 | image.convertToGray(); |
17758 | jghali | 943 | if (image.convert2JPG(tmpFile, quality, format == ColorSpaceCMYK, format == ColorSpaceGray)) |
11599 | jghali | 944 | jpgFileName = tmpFile; |
945 | } |
||
946 | if (jpgFileName.isEmpty()) |
||
11792 | fschmid | 947 | return 0; |
11599 | jghali | 948 | if (Options.Encrypt) |
949 | { |
||
950 | succeed = false; |
||
20112 | jghali | 951 | ScStreamFilter* rc4Encode = writer.openStreamFilter(true, ObjNum); |
952 | if (rc4Encode->openFilter()) |
||
11599 | jghali | 953 | { |
20103 | avox | 954 | succeed = copyFileToFilter(jpgFileName, *rc4Encode); |
955 | succeed &= rc4Encode->closeFilter(); |
||
956 | bytesWritten = rc4Encode->writtenToStream(); |
||
11599 | jghali | 957 | } |
20112 | jghali | 958 | delete rc4Encode; |
11599 | jghali | 959 | } |
960 | else |
||
961 | { |
||
20103 | avox | 962 | succeed &= copyFileToStream(jpgFileName, writer.getOutStream()); |
11599 | jghali | 963 | QFileInfo jpgInfo(jpgFileName); |
964 | bytesWritten = jpgInfo.size(); |
||
965 | } |
||
966 | if (!tmpFile.isEmpty() && QFile::exists(tmpFile)) |
||
967 | QFile::remove(tmpFile); |
||
968 | return (succeed ? bytesWritten : 0); |
||
11445 | jghali | 969 | } |
970 | |||
20103 | avox | 971 | int PDFLibCore::WriteFlateImageToStream(ScImage& image, PdfId ObjNum, ColorSpaceEnum format, bool precal) |
11599 | jghali | 972 | { |
20112 | jghali | 973 | bool fromCmyk, succeed = false; |
974 | int bytesWritten = 0; |
||
975 | ScStreamFilter* rc4Encode = writer.openStreamFilter(Options.Encrypt, ObjNum); |
||
976 | ScFlateEncodeFilter flateEncode(rc4Encode); |
||
977 | if (flateEncode.openFilter()) |
||
978 | { |
||
979 | switch (format) |
||
980 | { |
||
981 | case ColorSpaceMonochrome : |
||
982 | fromCmyk = !Options.UseRGB && !Options.isGrayscale && !(doc.HasCMS && Options.UseProfiles2); |
||
983 | succeed = image.writeMonochromeDataToFilter(&flateEncode, fromCmyk); break; |
||
984 | case ColorSpaceGray : |
||
985 | succeed = image.writeGrayDataToFilter(&flateEncode, precal); break; |
||
986 | case ColorSpaceCMYK : |
||
987 | succeed = image.writeCMYKDataToFilter(&flateEncode); break; |
||
988 | default : |
||
989 | succeed = image.writeRGBDataToFilter(&flateEncode); break; |
||
990 | } |
||
991 | succeed &= flateEncode.closeFilter(); |
||
992 | bytesWritten = flateEncode.writtenToStream(); |
||
993 | } |
||
994 | delete rc4Encode; |
||
995 | return (succeed ? bytesWritten : 0); |
||
11599 | jghali | 996 | } |
997 | |||
3133 | fschmid | 998 | |
19114 | avox | 999 | |
20103 | avox | 1000 | bool PDFLibCore::PDF_Begin_Doc(const QString& fn, SCFonts &AllFonts, const QMap<QString, QMap<uint, FPointArray> >& DocFonts, BookMView* vi) |
19114 | avox | 1001 | { |
20112 | jghali | 1002 | if (!writer.open(fn)) |
1003 | return false; |
||
1004 | |||
6407 | fschmid | 1005 | inPattern = 0; |
3133 | fschmid | 1006 | Bvie = vi; |
1007 | BookMinUse = false; |
||
1008 | UsedFontsP.clear(); |
||
8454 | fschmid | 1009 | UsedFontsF.clear(); |
20112 | jghali | 1010 | |
1011 | writer.writeHeader(Options.Version); |
||
1012 | |||
20103 | avox | 1013 | // if (((Options.Version == PDFOptions::PDFVersion_15) || (Options.Version == PDFOptions::PDFVersion_X4)) && (Options.useLayers)) |
1014 | // ObjCounter = 10; |
||
1015 | // else |
||
1016 | // ObjCounter = 9; |
||
1017 | // switch (Options.Version) |
||
1018 | // { |
||
1019 | // case PDFOptions::PDFVersion_X1a: |
||
1020 | // case PDFOptions::PDFVersion_X3: |
||
1021 | // case PDFOptions::PDFVersion_13: |
||
1022 | // PutDoc("%PDF-1.3\n"); |
||
1023 | // break; |
||
1024 | // case PDFOptions::PDFVersion_14: |
||
1025 | // PutDoc("%PDF-1.4\n"); |
||
1026 | // break; |
||
1027 | // case PDFOptions::PDFVersion_X4: |
||
1028 | // case PDFOptions::PDFVersion_15: |
||
1029 | // PutDoc("%PDF-1.5\n"); |
||
1030 | // break; |
||
1031 | // } |
||
1032 | // if (PDF_IsPDFX()) |
||
1033 | // ObjCounter++; |
||
1034 | // PutDoc("%\xc7\xec\x8f\xa2\n"); |
||
1035 | |||
20112 | jghali | 1036 | PDF_Begin_Catalog(); |
1037 | PDF_Begin_MetadataAndEncrypt(); |
||
1038 | PDF_Begin_WriteUsedFonts(AllFonts, PDF_Begin_FindUsedFonts(AllFonts, DocFonts)); |
||
1039 | PDF_Begin_Colors(); |
||
1040 | PDF_Begin_Layers(); |
||
1041 | |||
1042 | return true; |
||
20103 | avox | 1043 | } |
1044 | |||
1045 | void PDFLibCore::PDF_Begin_Catalog() |
||
1046 | { |
||
20112 | jghali | 1047 | writer.startObj(writer.CatalogObj); |
22386 | jghali | 1048 | PutDoc("<<\n/Type /Catalog\n"); |
1049 | PutDoc("/Pages " + Pdf::toObjRef(writer.PagesObj) + "\n"); |
||
1050 | if (!PDF_IsPDFX()) |
||
1051 | { |
||
1052 | if (doc.useAcroFormFields()) |
||
1053 | { |
||
1054 | writer.AcroFormObj = writer.newObject(); |
||
1055 | PutDoc("/AcroForm " + Pdf::toObjRef(writer.AcroFormObj) + "\n"); |
||
1056 | } |
||
1057 | if (doc.useAnnotations()) |
||
1058 | { |
||
1059 | writer.DestsObj = writer.newObject(); |
||
1060 | PutDoc("/Dests " + Pdf::toObjRef(writer.DestsObj) + "\n"); |
||
1061 | } |
||
1062 | if (doc.JavaScripts.count() > 0) |
||
1063 | { |
||
1064 | writer.NamesObj = writer.newObject(); |
||
1065 | PutDoc("/Names " + Pdf::toObjRef(writer.NamesObj) + "\n"); |
||
1066 | } |
||
1067 | } |
||
1068 | if (Options.Bookmarks) |
||
1069 | { |
||
1070 | writer.OutlinesObj = writer.newObject(); |
||
1071 | PutDoc("/Outlines " + Pdf::toObjRef(writer.OutlinesObj) + "\n"); |
||
1072 | } |
||
1073 | if (Options.Articles) |
||
1074 | { |
||
1075 | writer.ThreadsObj = writer.newObject(); |
||
1076 | PutDoc("/Threads " + Pdf::toObjRef(writer.ThreadsObj) + "\n"); |
||
1077 | } |
||
19114 | avox | 1078 | if (((Options.Version == PDFOptions::PDFVersion_15) || (Options.Version == PDFOptions::PDFVersion_X4)) && (Options.useLayers)) |
20112 | jghali | 1079 | { |
1080 | writer.OCPropertiesObj = writer.newObject(); |
||
20103 | avox | 1081 | PutDoc("/OCProperties " + Pdf::toObjRef(writer.OCPropertiesObj) + "\n"); |
20112 | jghali | 1082 | } |
1083 | if (PDF_IsPDFX()) |
||
19114 | avox | 1084 | { |
20112 | jghali | 1085 | writer.OutputIntentObj = writer.newObject(); |
1086 | PutDoc("/OutputIntents [ " + Pdf::toObjRef(writer.OutputIntentObj) + " ]\n"); |
||
1087 | } |
||
1088 | if ((Options.Version == PDFOptions::PDFVersion_X4)) |
||
1089 | { |
||
1090 | writer.MetaDataObj = writer.newObject(); |
||
20103 | avox | 1091 | PutDoc("/Metadata "+ Pdf::toObjRef(writer.MetaDataObj) + "\n"); |
19114 | avox | 1092 | } |
1093 | PutDoc("/PageLayout "); |
||
1094 | switch (Options.PageLayout) |
||
1095 | { |
||
1096 | case PDFOptions::SinglePage: |
||
1097 | PutDoc("/SinglePage\n"); |
||
1098 | break; |
||
1099 | case PDFOptions::OneColumn: |
||
1100 | PutDoc("/OneColumn\n"); |
||
1101 | break; |
||
1102 | case PDFOptions::TwoColumnLeft: |
||
1103 | PutDoc("/TwoColumnLeft\n"); |
||
1104 | break; |
||
1105 | case PDFOptions::TwoColumnRight: |
||
1106 | PutDoc("/TwoColumnRight\n"); |
||
1107 | break; |
||
1108 | } |
||
1109 | if (Options.displayBookmarks) |
||
1110 | PutDoc("/PageMode /UseOutlines\n"); |
||
1111 | else if (Options.displayFullscreen) |
||
1112 | PutDoc("/PageMode /FullScreen\n"); |
||
1113 | else if (Options.displayThumbs) |
||
1114 | PutDoc("/PageMode /UseThumbs\n"); |
||
1115 | else if ((Options.Version == PDFOptions::PDFVersion_15) && (Options.displayLayers)) |
||
1116 | PutDoc("/PageMode /UseOC\n"); |
||
1117 | if (!Options.openAction.isEmpty()) |
||
1118 | { |
||
22389 | jghali | 1119 | writer.OpenActionObj = writer.newObject(); |
1120 | PutDoc("/OpenAction << /S /JavaScript /JS " + Pdf::toPdf(writer.OpenActionObj) + " 0 R >>\n"); |
||
19114 | avox | 1121 | } |
21942 | craig | 1122 | QDateTime dt = QDateTime::currentDateTimeUtc(); |
20112 | jghali | 1123 | Datum = Pdf::toDateString(dt); |
20103 | avox | 1124 | // "D:"; |
1125 | // tmp.sprintf("%4d", d.year()); |
||
1126 | // tmp.replace(QRegExp(" "), "0"); |
||
1127 | // Datum += tmp; |
||
1128 | // tmp.sprintf("%2d", d.month()); |
||
1129 | // tmp.replace(QRegExp(" "), "0"); |
||
1130 | // Datum += tmp; |
||
1131 | // tmp.sprintf("%2d", d.day()); |
||
1132 | // tmp.replace(QRegExp(" "), "0"); |
||
1133 | // Datum += tmp; |
||
1134 | // tmp = dt.time().toString(); |
||
1135 | // tmp.replace(QRegExp(":"), ""); |
||
1136 | // Datum += tmp; |
||
1137 | // Datum += "Z"; |
||
12429 | fschmid | 1138 | |
19114 | avox | 1139 | // only include XMP to PDF/X-4 at the moment, could easily be extended to include it to any PDF |
1140 | if (Options.Version == PDFOptions::PDFVersion_X4) |
||
1141 | generateXMP(dt.toString("yyyy-MM-ddThh:mm:ssZ")); |
||
1142 | |||
1143 | /* The following code makes the resulting PDF "Reader enabled" in Acrobat Reader 8 |
||
1144 | but sadly it doesn't work with newer version, because its based on a bug in AR 8 |
||
1145 | PutDoc("/Perms\n"); |
||
1146 | PutDoc("<<\n"); |
||
1147 | PutDoc("/UR3\n"); |
||
1148 | PutDoc("<<\n"); |
||
1149 | PutDoc("/M ("+Datum+")\n"); |
||
1150 | PutDoc("/Name (Scribus "+QString(VERSION)+")\n"); |
||
1151 | PutDoc("/Reference [\n"); |
||
1152 | PutDoc("<<\n"); |
||
1153 | PutDoc("/TransformParams\n"); |
||
1154 | PutDoc("<<\n"); |
||
1155 | PutDoc("/Type /TransformParams\n"); |
||
1156 | PutDoc("/V /2.2\n"); |
||
1157 | PutDoc("/Document [/FullSave]\n"); |
||
1158 | PutDoc("/Annots [/Create/Delete/Modify/Copy/Import/Export]\n"); |
||
1159 | PutDoc("/Form [/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate]\n"); |
||
1160 | PutDoc("/Signature [/Modify]\n"); |
||
1161 | PutDoc(">>\n"); |
||
1162 | PutDoc("/TransformMethod /UR3\n"); |
||
1163 | PutDoc("/Type /SigRef\n"); |
||
1164 | PutDoc(">>\n"); |
||
1165 | PutDoc("]\n"); |
||
1166 | PutDoc("/Type /Sig\n"); |
||
1167 | PutDoc(">>\n"); |
||
1168 | PutDoc(">>\n"); |
||
1169 | */ |
||
1170 | |||
1171 | PutDoc("/ViewerPreferences\n<<\n/PageDirection "); |
||
1172 | PutDoc( Options.Binding == 0 ? "/L2R\n" : "/R2L\n"); |
||
1173 | if (Options.hideToolBar) |
||
1174 | PutDoc("/HideToolbar true\n"); |
||
1175 | if (Options.hideMenuBar) |
||
1176 | PutDoc("/HideMenubar true\n"); |
||
1177 | if (Options.fitWindow) |
||
1178 | PutDoc("/FitWindow true\n"); |
||
20112 | jghali | 1179 | PutDoc(" >>\n>>"); |
1180 | writer.endObj(writer.CatalogObj); |
||
20103 | avox | 1181 | } |
1182 | |||
1183 | void PDFLibCore::PDF_Begin_MetadataAndEncrypt() |
||
1184 | { |
||
19114 | avox | 1185 | QString IDg(Datum); |
1186 | IDg += Options.fileName; |
||
1187 | IDg += "Scribus "+QString(VERSION); |
||
1188 | IDg += "Scribus PDF Library "+QString(VERSION); |
||
1189 | IDg += doc.documentInfo().title(); |
||
1190 | IDg += doc.documentInfo().author(); |
||
1191 | IDg += "/False"; |
||
20112 | jghali | 1192 | writer.setFileId(Pdf::toPdfDocEncoding(IDg)); |
19114 | avox | 1193 | if (Options.Encrypt) |
1194 | { |
||
20112 | jghali | 1195 | writer.setEncryption((Options.Version == PDFOptions::PDFVersion_14) || (Options.Version == PDFOptions::PDFVersion_15), Pdf::toPdfDocEncoding(Options.PassOwner), Pdf::toPdfDocEncoding(Options.PassUser), Options.Permissions); |
19114 | avox | 1196 | } |
20103 | avox | 1197 | writer.startObj(writer.InfoObj); |
20112 | jghali | 1198 | PutDoc("<<\n/Creator " + EncString(QByteArray("Scribus ") + VERSION, writer.InfoObj) + "\n"); |
20103 | avox | 1199 | PutDoc("/Producer " + EncString(QByteArray("Scribus PDF Library ") + VERSION, writer.InfoObj) + "\n"); |
19114 | avox | 1200 | QString docTitle = doc.documentInfo().title(); |
19115 | avox | 1201 | if ((PDF_IsPDFX()) && (docTitle.isEmpty())) |
20103 | avox | 1202 | PutDoc("/Title " + EncStringUTF16(doc.DocName, writer.InfoObj) + "\n"); |
19114 | avox | 1203 | else |
20103 | avox | 1204 | PutDoc("/Title " + EncStringUTF16(doc.documentInfo().title(), writer.InfoObj) + "\n"); |
1205 | PutDoc("/Author " + EncStringUTF16(doc.documentInfo().author(), writer.InfoObj) + "\n"); |
||
1206 | PutDoc("/Subject " + EncStringUTF16(doc.documentInfo().subject(), writer.InfoObj) + "\n"); |
||
1207 | PutDoc("/Keywords " + EncStringUTF16(doc.documentInfo().keywords(), writer.InfoObj) + "\n"); |
||
1208 | PutDoc("/CreationDate " + EncString(Datum, writer.InfoObj) + "\n"); |
||
1209 | PutDoc("/ModDate " + EncString(Datum, writer.InfoObj) + "\n"); |
||
19114 | avox | 1210 | if (Options.Version == PDFOptions::PDFVersion_X1a) |
1211 | { |
||
1212 | PutDoc("/GTS_PDFXVersion (PDF/X-1:2001)\n"); |
||
1213 | PutDoc("/GTS_PDFXConformance (PDF/X-1a:2001)\n"); |
||
1214 | } |
||
19115 | avox | 1215 | if (Options.Version == PDFOptions::PDFVersion_X3) |
1216 | PutDoc("/GTS_PDFXVersion (PDF/X-3:2002)\n"); |
||
19114 | avox | 1217 | if (Options.Version == PDFOptions::PDFVersion_X4) |
1218 | PutDoc("/GTS_PDFXVersion (PDF/X-4)\n"); |
||
20112 | jghali | 1219 | PutDoc("/Trapped /False\n>>"); |
1220 | writer.endObj(writer.InfoObj); |
||
20103 | avox | 1221 | } |
1222 | |||
1223 | QMap<QString, QMap<uint, FPointArray> > |
||
1224 | PDFLibCore::PDF_Begin_FindUsedFonts(SCFonts &AllFonts, const QMap<QString, QMap<uint, FPointArray> >& DocFonts) |
||
1225 | { |
||
5387 | avox | 1226 | QMap<QString, QMap<uint, FPointArray> > ReallyUsed; |
3133 | fschmid | 1227 | ReallyUsed.clear(); |
1228 | PageItem* pgit; |
||
20103 | avox | 1229 | QMap<int, QByteArray> ind2PDFabr; |
1230 | const QByteArray tmpf[] = {"/Courier", "/Courier-Bold", "/Courier-Oblique", "/Courier-BoldOblique", |
||
4017 | fschmid | 1231 | "/Helvetica", "/Helvetica-Bold", "/Helvetica-Oblique", "/Helvetica-BoldOblique", |
4546 | subik | 1232 | "/Times-Roman", "/Times-Bold", "/Times-Italic", "/Times-BoldItalic", |
4017 | fschmid | 1233 | "/ZapfDingbats", "/Symbol"}; |
1234 | size_t ar = sizeof(tmpf) / sizeof(*tmpf); |
||
1235 | for (uint ax = 0; ax < ar; ++ax) |
||
1236 | ind2PDFabr[ax] = tmpf[ax]; |
||
21709 | jghali | 1237 | |
1238 | QList<PageItem*> allItems = doc.FrameItems.values(); |
||
1239 | while (allItems.count() > 0) |
||
3133 | fschmid | 1240 | { |
21709 | jghali | 1241 | pgit = allItems.takeFirst(); |
1242 | if (pgit->isGroup() || pgit->isTable()) |
||
3133 | fschmid | 1243 | { |
22224 | jghali | 1244 | allItems = pgit->getChildren() + allItems; |
21709 | jghali | 1245 | continue; |
1246 | } |
||
1247 | if ((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) |
||
1248 | { |
||
1249 | if (pgit->isAnnotation()) |
||
17312 | fschmid | 1250 | { |
21709 | jghali | 1251 | int annotType = pgit->annotation().Type(); |
1252 | bool mustEmbed = ((annotType >= Annotation::Button) && (annotType <= Annotation::Listbox) && (annotType != Annotation::Checkbox)); |
||
1253 | if ((pgit->annotation().Type() == Annotation::Checkbox) || (pgit->annotation().Type() == Annotation::RadioButton)) |
||
1254 | StdFonts.insert("/ZapfDingbats", ""); |
||
1255 | if (pgit->itemText.length() > 0 || mustEmbed) |
||
17312 | fschmid | 1256 | { |
21709 | jghali | 1257 | if (Options.Version < PDFOptions::PDFVersion_14) |
1258 | StdFonts.insert(ind2PDFabr[pgit->annotation().Font()], ""); |
||
21744 | jghali | 1259 | QString replacementName = pgit->itemText.defaultStyle().charStyle().font().replacementName(); |
1260 | ReallyUsed.insert(replacementName, DocFonts[replacementName]); |
||
17312 | fschmid | 1261 | } |
1262 | } |
||
21709 | jghali | 1263 | uint start = pgit->isTextFrame() ? (uint) pgit->firstInFrame() : 0; |
1264 | uint stop = pgit->isTextFrame() ? (uint) pgit->lastInFrame() + 1 : (uint) pgit->itemText.length(); |
||
1265 | for (uint e = start; e < stop; ++e) |
||
8092 | fschmid | 1266 | { |
21709 | jghali | 1267 | QString replacementName = pgit->itemText.charStyle(e).font().replacementName(); |
1268 | ReallyUsed.insert(replacementName, DocFonts[replacementName]); |
||
8092 | fschmid | 1269 | } |
3133 | fschmid | 1270 | } |
1271 | } |
||
21709 | jghali | 1272 | |
1273 | allItems = doc.MasterItems; |
||
1274 | while (allItems.count() > 0) |
||
3133 | fschmid | 1275 | { |
21709 | jghali | 1276 | pgit = allItems.takeFirst(); |
1277 | if (pgit->isGroup() || pgit->isTable()) |
||
3133 | fschmid | 1278 | { |
22224 | jghali | 1279 | allItems = pgit->getChildren() + allItems; |
21709 | jghali | 1280 | continue; |
1281 | } |
||
1282 | if ((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) |
||
1283 | { |
||
1284 | if (pgit->isAnnotation()) |
||
17312 | fschmid | 1285 | { |
21709 | jghali | 1286 | int annotType = pgit->annotation().Type(); |
1287 | bool mustEmbed = ((annotType >= Annotation::Button) && (annotType <= Annotation::Listbox) && (annotType != Annotation::Checkbox)); |
||
1288 | if ((pgit->annotation().Type() == Annotation::Checkbox) || (pgit->annotation().Type() == Annotation::RadioButton)) |
||
1289 | StdFonts.insert("/ZapfDingbats", ""); |
||
1290 | if (pgit->itemText.length() > 0 || mustEmbed) |
||
17312 | fschmid | 1291 | { |
21709 | jghali | 1292 | if (Options.Version < PDFOptions::PDFVersion_14) |
1293 | StdFonts.insert(ind2PDFabr[pgit->annotation().Font()], ""); |
||
1294 | QString replacementName = pgit->itemText.defaultStyle().charStyle().font().replacementName(); |
||
1295 | ReallyUsed.insert(replacementName, DocFonts[replacementName]); |
||
17312 | fschmid | 1296 | } |
1297 | } |
||
21709 | jghali | 1298 | uint start = pgit->isTextFrame() ? (uint) pgit->firstInFrame() : 0; |
1299 | uint stop = pgit->isTextFrame() ? (uint) pgit->lastInFrame() + 1 : (uint) pgit->itemText.length(); |
||
1300 | for (uint e = start; e < stop; ++e) |
||
8092 | fschmid | 1301 | { |
21709 | jghali | 1302 | QString replacementName = pgit->itemText.charStyle(e).font().replacementName(); |
1303 | ReallyUsed.insert(replacementName, DocFonts[replacementName]); |
||
1304 | } |
||
1305 | } |
||
1306 | } |
||
1307 | |||
1308 | allItems = *(doc.Items); |
||
1309 | while (allItems.count() > 0) |
||
1310 | { |
||
1311 | pgit = allItems.takeFirst(); |
||
1312 | if (pgit->isGroup() || pgit->isTable()) |
||
1313 | { |
||
22224 | jghali | 1314 | allItems = pgit->getChildren() + allItems; |
21709 | jghali | 1315 | continue; |
1316 | } |
||
1317 | if ((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) |
||
1318 | { |
||
1319 | if (pgit->isAnnotation()) |
||
1320 | { |
||
1321 | int annotType = pgit->annotation().Type(); |
||
1322 | bool mustEmbed = ((annotType >= Annotation::Button) && (annotType <= Annotation::Listbox) && (annotType != Annotation::Checkbox)); |
||
1323 | if ((pgit->annotation().Type() == Annotation::Checkbox) || (pgit->annotation().Type() == Annotation::RadioButton)) |
||
1324 | StdFonts.insert("/ZapfDingbats", ""); |
||
1325 | if (pgit->itemText.length() > 0 || mustEmbed) |
||
12763 | fschmid | 1326 | { |
21709 | jghali | 1327 | if (Options.Version < PDFOptions::PDFVersion_14) |
1328 | StdFonts.insert(ind2PDFabr[pgit->annotation().Font()], ""); |
||
1329 | QString replacementName = pgit->itemText.defaultStyle().charStyle().font().replacementName(); |
||
21707 | jghali | 1330 | ReallyUsed.insert(replacementName, DocFonts[replacementName]); |
16953 | fschmid | 1331 | } |
8092 | fschmid | 1332 | } |
21709 | jghali | 1333 | uint start = pgit->isTextFrame() ? (uint) pgit->firstInFrame() : 0; |
1334 | uint stop = pgit->isTextFrame() ? (uint) pgit->lastInFrame() + 1 : (uint) pgit->itemText.length(); |
||
1335 | for (uint e = start; e < stop; ++e) |
||
1336 | { |
||
1337 | QString replacementName = pgit->itemText.charStyle(e).font().replacementName(); |
||
1338 | ReallyUsed.insert(replacementName, DocFonts[replacementName]); |
||
1339 | } |
||
3133 | fschmid | 1340 | } |
1341 | } |
||
21709 | jghali | 1342 | /* if (Options.docInfoMarks) |
3133 | fschmid | 1343 | { |
21709 | jghali | 1344 | StdFonts.insert("/Helvetica", ""); |
1345 | } */ |
||
1346 | QStringList patterns = doc.getPatternDependencyList(doc.getUsedPatterns()); |
||
1347 | for (int c = 0; c < patterns.count(); ++c) |
||
1348 | { |
||
1349 | ScPattern pa = doc.docPatterns[patterns[c]]; |
||
1350 | allItems = pa.items; |
||
1351 | while (allItems.count() > 0) |
||
3133 | fschmid | 1352 | { |
21709 | jghali | 1353 | pgit = allItems.takeFirst(); |
1354 | if (pgit->isGroup() || pgit->isTable()) |
||
17312 | fschmid | 1355 | { |
22224 | jghali | 1356 | allItems = pgit->getChildren() + allItems; |
21709 | jghali | 1357 | continue; |
17312 | fschmid | 1358 | } |
16953 | fschmid | 1359 | if ((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) |
8092 | fschmid | 1360 | { |
16953 | fschmid | 1361 | if (pgit->isAnnotation()) |
12763 | fschmid | 1362 | { |
17952 | fschmid | 1363 | if ((pgit->annotation().Type() == Annotation::Checkbox) || (pgit->annotation().Type() == Annotation::RadioButton)) |
16953 | fschmid | 1364 | StdFonts.insert("/ZapfDingbats", ""); |
21709 | jghali | 1365 | if (pgit->itemText.length() > 0) |
16953 | fschmid | 1366 | { |
1367 | if (Options.Version < PDFOptions::PDFVersion_14) |
||
1368 | StdFonts.insert(ind2PDFabr[pgit->annotation().Font()], ""); |
||
21707 | jghali | 1369 | QString replacementName = pgit->itemText.defaultStyle().charStyle().font().replacementName(); |
1370 | ReallyUsed.insert(replacementName, DocFonts[replacementName]); |
||
16953 | fschmid | 1371 | } |
12763 | fschmid | 1372 | } |
17751 | jghali | 1373 | uint start = pgit->isTextFrame() ? (uint) pgit->firstInFrame() : 0; |
1374 | uint stop = pgit->isTextFrame() ? (uint) pgit->lastInFrame() + 1 : (uint) pgit->itemText.length(); |
||
1375 | for (uint e = start; e < stop; ++e) |
||
16953 | fschmid | 1376 | { |
21707 | jghali | 1377 | QString replacementName = pgit->itemText.charStyle(e).font().replacementName(); |
1378 | ReallyUsed.insert(replacementName, DocFonts[replacementName]); |
||
16953 | fschmid | 1379 | } |
8092 | fschmid | 1380 | } |
3133 | fschmid | 1381 | } |
1382 | } |
||
20112 | jghali | 1383 | return ReallyUsed; |
20103 | avox | 1384 | } |
17628 | jghali | 1385 | |
20103 | avox | 1386 | static QByteArray sanitizeFontName(QString fn) |
1387 | { |
||
20112 | jghali | 1388 | return Pdf::toPdfDocEncoding(fn.replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )); |
20103 | avox | 1389 | } |
17628 | jghali | 1390 | |
20103 | avox | 1391 | static QList<Pdf::Resource> asColorSpace(QList<PdfICCD> iccCSlist) |
1392 | { |
||
20112 | jghali | 1393 | QList<Pdf::Resource> result; |
21951 | craig | 1394 | foreach (const Pdf::Resource& r, iccCSlist) |
20112 | jghali | 1395 | result.append(r); |
1396 | return result; |
||
20103 | avox | 1397 | } |
1398 | |||
1399 | static QList<Pdf::Resource> asColorSpace(QList<PdfSpotC> spotMapValues) |
||
1400 | { |
||
20112 | jghali | 1401 | QList<Pdf::Resource> result; |
21951 | craig | 1402 | foreach (const Pdf::Resource& r, spotMapValues) |
20112 | jghali | 1403 | result.append(r); |
1404 | return result; |
||
20103 | avox | 1405 | } |
1406 | |||
1407 | void PDFLibCore::PDF_WriteStandardFonts() |
||
1408 | { |
||
20112 | jghali | 1409 | int a = 0; |
1410 | QMap<QString, QString>::Iterator itStd; |
||
1411 | for (itStd = StdFonts.begin(); itStd != StdFonts.end(); ++itStd) |
||
1412 | { |
||
1413 | PdfId fontObject = writer.newObject(); |
||
1414 | writer.startObj(fontObject); |
||
1415 | PutDoc("<<\n/Type /Font\n/Subtype /Type1\n"); |
||
1416 | PutDoc("/Name /FoStd"+Pdf::toPdf(a)+"\n"); |
||
1417 | PutDoc("/BaseFont "+Pdf::toPdfDocEncoding(itStd.key())+"\n"); |
||
1418 | if (itStd.key() != "/ZapfDingbats") |
||
1419 | { |
||
1420 | PutDoc("/Encoding << \n"); |
||
1421 | PutDoc("/Differences [ \n"); |
||
1422 | PutDoc("24 /breve /caron /circumflex /dotaccent /hungarumlaut /ogonek /ring /tilde\n"); |
||
1423 | PutDoc("39 /quotesingle 96 /grave 128 /bullet /dagger /daggerdbl /ellipsis /emdash /endash /florin /fraction /guilsinglleft /guilsinglright\n"); |
||
1424 | PutDoc("/minus /perthousand /quotedblbase /quotedblleft /quotedblright /quoteleft /quoteright /quotesinglbase /trademark /fi /fl /Lslash /OE /Scaron\n"); |
||
21744 | jghali | 1425 | PutDoc("/Ydieresis /Zcaron /dotlessi /lslash /oe /scaron /zcaron 160 /Euro 164 /currency 166 /brokenbar 168 /dieresis /copyright /ordfeminine 172 /logicalnot\n"); |
20112 | jghali | 1426 | PutDoc("/.notdef /registered /macron /degree /plusminus /twosuperior /threesuperior /acute /mu 183 /periodcentered /cedilla /onesuperior /ordmasculine\n"); |
1427 | PutDoc("188 /onequarter /onehalf /threequarters 192 /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla /Egrave /Eacute /Ecircumflex\n"); |
||
1428 | PutDoc("/Edieresis /Igrave /Iacute /Icircumflex /Idieresis /Eth /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply /Oslash\n"); |
||
1429 | PutDoc("/Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn /germandbls /agrave /aacute /acircumflex /atilde /adieresis /aring /ae /ccedilla\n"); |
||
1430 | PutDoc("/egrave /eacute /ecircumflex /edieresis /igrave /iacute /icircumflex /idieresis /eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis\n"); |
||
1431 | PutDoc("/divide /oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn /ydieresis\n"); |
||
1432 | PutDoc("] >>\n"); |
||
1433 | } |
||
1434 | PutDoc(">>"); |
||
1435 | writer.endObj(fontObject); |
||
1436 | pageData.FObjects["FoStd"+Pdf::toPdf(a)] = fontObject; |
||
1437 | itStd.value() = "FoStd"+Pdf::toPdf(a); |
||
1438 | a++; |
||
1439 | } |
||
20103 | avox | 1440 | } |
1441 | |||
1442 | |||
1443 | PdfFont PDFLibCore::PDF_WriteType3Font(const QByteArray& name, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs) |
||
1444 | { |
||
20112 | jghali | 1445 | PdfFont result; |
1446 | result.name = Pdf::toName(name); |
||
1447 | result.method = Use_Type3; |
||
1448 | result.encoding = Encode_256; |
||
20103 | avox | 1449 | |
22008 | jghali | 1450 | // TrueType font rasterizers use non-zero winding file rule, |
1451 | // vs even-odd for current Postscript font rasterizers |
||
1452 | // Note: OTF CFF2 will also use non-zero winding rule, so |
||
1453 | // change code below when adding CCF2 support to Scribus |
||
1454 | // ref: https://www.microsoft.com/typography/OTSpec/cff2.htm |
||
1455 | bool useNonZeroRule = (face.type() == ScFace::TTF); |
||
1456 | |||
20112 | jghali | 1457 | uint SubFonts = 0; |
1458 | int glyphCount = 0; |
||
1459 | double minx = std::numeric_limits<double>::max(); |
||
1460 | double miny = std::numeric_limits<double>::max(); |
||
1461 | double maxx = -std::numeric_limits<double>::max(); |
||
1462 | double maxy = -std::numeric_limits<double>::max(); |
||
22142 | jghali | 1463 | |
20112 | jghali | 1464 | QList<uint> glyphWidths; |
1465 | QList<QByteArray> charProcs; |
||
22142 | jghali | 1466 | QStringList toUnicodeMaps; |
1467 | QList<int> toUnicodeMapsCount; |
||
1468 | QString toUnicodeMap = ""; |
||
1469 | int toUnicodeMapCounter = 0; |
||
20112 | jghali | 1470 | QByteArray encoding = "<< /Type /Encoding\n/Differences [ 0\n"; |
1471 | QByteArray fon; |
||
1472 | QMap<uint, uint> glyphMapping; |
||
22142 | jghali | 1473 | |
20112 | jghali | 1474 | ScFace::FaceEncoding gl; |
1475 | face.glyphNames(gl); |
||
22142 | jghali | 1476 | |
20112 | jghali | 1477 | QMap<uint,FPointArray>::ConstIterator ig; |
1478 | for (ig = RealGlyphs.cbegin(); ig != RealGlyphs.cend(); ++ig) |
||
1479 | { |
||
1480 | FPoint np, np1, np2; |
||
1481 | bool nPath = true; |
||
1482 | fon.resize(0); |
||
1483 | if (ig.value().size() > 3) |
||
1484 | { |
||
1485 | FPointArray gly = ig.value(); |
||
1486 | QTransform mat; |
||
1487 | mat.scale(100.0, -100.0); |
||
1488 | gly.map(mat); |
||
1489 | gly.translate(0, 1000); |
||
1490 | for (int poi = 0; poi < gly.size()-3; poi += 4) |
||
1491 | { |
||
1492 | if (gly.isMarker(poi)) |
||
1493 | { |
||
1494 | fon += "h\n"; |
||
1495 | nPath = true; |
||
1496 | continue; |
||
1497 | } |
||
1498 | if (nPath) |
||
1499 | { |
||
1500 | np = gly.point(poi); |
||
1501 | fon += FToStr(np.x())+" "+FToStr(np.y())+" m\n"; |
||
1502 | nPath = false; |
||
1503 | } |
||
1504 | np = gly.point(poi+1); |
||
1505 | np1 = gly.point(poi+3); |
||
1506 | np2 = gly.point(poi+2); |
||
1507 | fon += FToStr(np.x()) + " " + FToStr(np.y()) + " " + FToStr(np1.x()) + " " + FToStr(np1.y()) + " " + FToStr(np2.x()) + " " + FToStr(np2.y()) + " c\n"; |
||
1508 | } |
||
22008 | jghali | 1509 | fon += useNonZeroRule? "h f\n" : "h f*\n"; |
20112 | jghali | 1510 | np = getMinClipF(&gly); |
1511 | np1 = getMaxClipF(&gly); |
||
1512 | } |
||
1513 | else |
||
1514 | { |
||
20684 | jghali | 1515 | // 13654: make evince emit warning about "Syntax Error: No current point in closepath" |
1516 | // PDF specification is not quite clear about that, but a single "h" operator might not |
||
1517 | // be a valid way to make an empty path |
||
1518 | // fon = "h"; |
||
20112 | jghali | 1519 | np = FPoint(0, 0); |
1520 | np1 = FPoint(0, 0); |
||
1521 | } |
||
1522 | fon.prepend(Pdf::toPdf(qRound(np1.x())) + " 0 "+Pdf::toPdf(qRound(np.x()))+" "+Pdf::toPdf(qRound(np.y()))+" "+Pdf::toPdf(qRound(np1.x()))+ " "+Pdf::toPdf(qRound(np1.y()))+" d1\n"); |
||
1523 | minx = qMin(minx, np.x()); |
||
1524 | miny = qMin(miny, np.y()); |
||
1525 | maxx = qMax(maxx, np1.x()); |
||
1526 | maxy = qMax(maxy, np1.y()); |
||
1527 | glyphWidths.append(qRound(np1.x())); |
||
22142 | jghali | 1528 | |
20112 | jghali | 1529 | PdfId charProcObject = writer.newObject(); |
22143 | jghali | 1530 | const ScFace::GlyphEncoding& glEncoding = gl[ig.key()]; |
1531 | charProcs.append(Pdf::toName(glEncoding.glyphName)+" "+Pdf::toPdf(charProcObject)+" 0 R\n"); |
||
1532 | encoding += Pdf::toName(glEncoding.glyphName)+" "; |
||
20112 | jghali | 1533 | glyphMapping.insert(ig.key(), glyphCount + SubFonts * 256); |
1534 | writer.startObj(charProcObject); |
||
1535 | if (Options.Compress) |
||
1536 | fon = CompressArray(fon); |
||
1537 | PutDoc("<< /Length "+Pdf::toPdf(fon.length()+1)); |
||
1538 | if (Options.Compress) |
||
1539 | PutDoc("\n/Filter /FlateDecode"); |
||
1540 | PutDoc("\n>>\nstream\n"+EncStream(fon, charProcObject)+"\nendstream"); |
||
1541 | writer.endObj(charProcObject); |
||
22142 | jghali | 1542 | |
22143 | jghali | 1543 | QString tmp; |
22142 | jghali | 1544 | tmp.sprintf("%02X", glyphCount); |
22143 | jghali | 1545 | toUnicodeMap += "<" + Pdf::toAscii(tmp) + "> <" + Pdf::toAscii(glEncoding.toUnicode) + ">\n"; |
22142 | jghali | 1546 | toUnicodeMapCounter++; |
1547 | if (toUnicodeMapCounter == 100) |
||
1548 | { |
||
1549 | toUnicodeMaps.append(toUnicodeMap); |
||
1550 | toUnicodeMapsCount.append(toUnicodeMapCounter); |
||
1551 | toUnicodeMap = ""; |
||
1552 | toUnicodeMapCounter = 0; |
||
1553 | } |
||
1554 | |||
20112 | jghali | 1555 | glyphCount++; |
1556 | int glyphsLeft = RealGlyphs.count() - SubFonts * 256; |
||
1557 | if ((glyphCount > 255) || (glyphCount == glyphsLeft)) |
||
1558 | { |
||
1559 | PdfId fontWidths = writer.newObject(); |
||
1560 | writer.startObj(fontWidths); |
||
1561 | PutDoc("[ "); |
||
1562 | for (int ww = 0; ww < glyphWidths.count(); ++ww) |
||
1563 | { |
||
1564 | PutDoc(Pdf::toPdf(glyphWidths[ww])+" "); |
||
1565 | } |
||
1566 | PutDoc("]"); |
||
1567 | writer.endObj(fontWidths); |
||
1568 | PdfId fontCharProcs = writer.newObject(); |
||
1569 | writer.startObj(fontCharProcs); |
||
1570 | PutDoc("<<\n"); |
||
1571 | for (int ww = 0; ww < charProcs.count(); ++ww) |
||
1572 | { |
||
1573 | PutDoc(charProcs[ww]); |
||
1574 | } |
||
1575 | PutDoc(">>"); |
||
1576 | writer.endObj(fontCharProcs); |
||
1577 | PdfId fontEncoding = writer.newObject(); |
||
1578 | writer.startObj(fontEncoding); |
||
1579 | PutDoc(encoding); |
||
1580 | PutDoc("]\n"); |
||
1581 | PutDoc(">>"); |
||
1582 | writer.endObj(fontEncoding); |
||
22142 | jghali | 1583 | |
1584 | if (toUnicodeMapCounter != 0) |
||
1585 | { |
||
1586 | toUnicodeMaps.append(toUnicodeMap); |
||
1587 | toUnicodeMapsCount.append(toUnicodeMapCounter); |
||
1588 | } |
||
1589 | |||
1590 | QByteArray toUnicodeMapStream = ""; |
||
1591 | toUnicodeMapStream += "/CIDInit /ProcSet findresource begin\n"; |
||
1592 | toUnicodeMapStream += "12 dict begin\n"; |
||
1593 | toUnicodeMapStream += "begincmap\n"; |
||
1594 | toUnicodeMapStream += "/CIDSystemInfo <<\n"; |
||
1595 | toUnicodeMapStream += "/Registry (Adobe)\n"; |
||
1596 | toUnicodeMapStream += "/Ordering (UCS)\n"; |
||
1597 | toUnicodeMapStream += "/Supplement 0\n"; |
||
1598 | toUnicodeMapStream += ">> def\n"; |
||
1599 | toUnicodeMapStream += "/CMapName /Adobe-Identity-UCS def\n"; |
||
1600 | toUnicodeMapStream += "/CMapType 2 def\n"; |
||
1601 | toUnicodeMapStream += "1 begincodespacerange\n"; |
||
1602 | toUnicodeMapStream += "<0000> <FFFF>\n"; |
||
1603 | toUnicodeMapStream += "endcodespacerange\n"; |
||
1604 | for (int uniC = 0; uniC < toUnicodeMaps.count(); uniC++) |
||
1605 | { |
||
1606 | toUnicodeMapStream += Pdf::toPdf(toUnicodeMapsCount[uniC]); |
||
1607 | toUnicodeMapStream += " beginbfchar\n"; |
||
1608 | toUnicodeMapStream += toUnicodeMaps[uniC]; |
||
1609 | toUnicodeMapStream += "endbfchar\n"; |
||
1610 | } |
||
1611 | toUnicodeMapStream += "endcmap\n"; |
||
1612 | toUnicodeMapStream += "CMapName currentdict /CMap defineresource pop\n"; |
||
1613 | toUnicodeMapStream += "end\n"; |
||
1614 | toUnicodeMapStream += "end\n"; |
||
1615 | PdfId fontToUnicode = WritePDFStream(toUnicodeMapStream); |
||
1616 | |||
20112 | jghali | 1617 | PdfId font3Object = writer.newObject(); |
1618 | writer.startObj(font3Object); |
||
1619 | PutDoc("<<\n/Type /Font\n/Subtype /Type3\n"); |
||
1620 | PutDoc("/Name /"+name+"S"+Pdf::toPdf(SubFonts)+"\n"); |
||
1621 | PutDoc("/FirstChar 0\n"); |
||
1622 | PutDoc("/LastChar "+Pdf::toPdf(glyphCount-1)+"\n"); |
||
1623 | PutDoc("/Widths "+Pdf::toPdf(fontWidths)+" 0 R\n"); |
||
1624 | PutDoc("/CharProcs "+Pdf::toPdf(fontCharProcs)+" 0 R\n"); |
||
1625 | PutDoc("/FontBBox ["+Pdf::toPdf(qRound(minx))+" "+Pdf::toPdf(qRound(miny))+" "+Pdf::toPdf(qRound(maxx))+ " "+Pdf::toPdf(qRound(maxy))+"]\n"); |
||
1626 | PutDoc("/FontMatrix [0.001 0 0 0.001 0 0]\n"); |
||
1627 | PutDoc("/Encoding "+Pdf::toPdf(fontEncoding)+" 0 R\n"); |
||
22142 | jghali | 1628 | PutDoc("/ToUnicode " + Pdf::toPdf(fontToUnicode) + " 0 R\n"); |
20112 | jghali | 1629 | PutDoc(">>"); |
1630 | writer.endObj(font3Object); |
||
1631 | pageData.FObjects[name+"S"+Pdf::toPdf(SubFonts)] = font3Object; |
||
1632 | charProcs.clear(); |
||
1633 | glyphWidths.clear(); |
||
22142 | jghali | 1634 | toUnicodeMaps.clear(); |
1635 | toUnicodeMapsCount.clear(); |
||
1636 | toUnicodeMap.clear(); |
||
1637 | toUnicodeMapCounter = 0; |
||
20112 | jghali | 1638 | glyphCount = 0; |
1639 | ++SubFonts; |
||
1640 | minx = std::numeric_limits<double>::max(); |
||
1641 | miny = std::numeric_limits<double>::max(); |
||
1642 | maxx = -std::numeric_limits<double>::max(); |
||
1643 | maxy = -std::numeric_limits<double>::max(); |
||
1644 | encoding = "<< /Type /Encoding\n/Differences [ 0\n"; |
||
1645 | } |
||
1646 | } |
||
1647 | result.glyphmap = glyphMapping; |
||
1648 | return result; |
||
20103 | avox | 1649 | } |
1650 | |||
1651 | |||
1652 | PdfFont PDFLibCore::PDF_WriteGlyphsAsXForms(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs) |
||
1653 | { |
||
20112 | jghali | 1654 | PdfFont result; |
1655 | result.name = Pdf::toName(fontName); |
||
1656 | result.method = Use_XForm; |
||
1657 | result.encoding = Encode_224; |
||
20103 | avox | 1658 | |
22008 | jghali | 1659 | // TrueType font rasterizers use non-zero winding file rule, |
1660 | // vs even-odd for current Postscript font rasterizers |
||
1661 | // Note: OTF CFF2 will also use non-zero winding rule, so |
||
1662 | // change code below when adding CCF2 support to Scribus |
||
1663 | // ref: https://www.microsoft.com/typography/OTSpec/cff2.htm |
||
1664 | bool useNonZeroRule = (face.type() == ScFace::TTF); |
||
1665 | |||
20112 | jghali | 1666 | QByteArray fon; |
1667 | QMap<uint,FPointArray>::ConstIterator ig; |
||
1668 | for (ig = RealGlyphs.cbegin(); ig != RealGlyphs.cend(); ++ig) |
||
1669 | { |
||
1670 | FPoint np, np1, np2; |
||
1671 | bool nPath = true; |
||
1672 | fon.resize(0); |
||
1673 | if (ig.value().size() > 3) |
||
1674 | { |
||
1675 | FPointArray gly = ig.value(); |
||
1676 | QTransform mat; |
||
1677 | mat.scale(0.1, 0.1); |
||
1678 | gly.map(mat); |
||
1679 | for (int poi = 0; poi < gly.size()-3; poi += 4) |
||
1680 | { |
||
1681 | if (gly.isMarker(poi)) |
||
1682 | { |
||
1683 | fon += "h\n"; |
||
1684 | nPath = true; |
||
1685 | continue; |
||
1686 | } |
||
1687 | if (nPath) |
||
1688 | { |
||
1689 | np = gly.point(poi); |
||
1690 | fon += FToStr(np.x())+" "+FToStr(-np.y())+" m\n"; |
||
1691 | nPath = false; |
||
1692 | } |
||
1693 | np = gly.point(poi+1); |
||
1694 | np1 = gly.point(poi+3); |
||
1695 | np2 = gly.point(poi+2); |
||
1696 | fon += FToStr(np.x()) + " " + FToStr(-np.y()) + " " + |
||
1697 | FToStr(np1.x()) + " " + FToStr(-np1.y()) + " " + |
||
1698 | FToStr(np2.x()) + " " + FToStr(-np2.y()) + " c\n"; |
||
1699 | } |
||
22008 | jghali | 1700 | fon += useNonZeroRule? "h f\n" : "h f*\n"; |
20112 | jghali | 1701 | np = getMinClipF(&gly); |
1702 | np1 = getMaxClipF(&gly); |
||
1703 | } |
||
1704 | else |
||
1705 | { |
||
20684 | jghali | 1706 | // 13654: make evince emit warning about "Syntax Error: No current point in closepath" |
1707 | // PDF specification is not quite clear about that, but a single "h" operator might not |
||
1708 | // be a valid way to make an empty path |
||
1709 | fon = " " /*"h"*/; |
||
20112 | jghali | 1710 | np = FPoint(0, 0); |
1711 | np1 = FPoint(0, 0); |
||
1712 | } |
||
1713 | PdfId fontGlyphXForm = writer.newObject(); |
||
1714 | writer.startObj(fontGlyphXForm); |
||
1715 | PutDoc("<<\n/Type /XObject\n/Subtype /Form\n/FormType 1\n"); |
||
1716 | PutDoc("/BBox [ "+FToStr(np.x())+" "+FToStr(-np.y())+" "+FToStr(np1.x())+ " "+FToStr(-np1.y())+" ]\n"); |
||
1717 | PutDoc("/Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n"); |
||
1718 | PutDoc(">>\n"); |
||
1719 | if (Options.Compress) |
||
1720 | fon = CompressArray(fon); |
||
1721 | PutDoc("/Length "+Pdf::toPdf(fon.length()+1)); |
||
1722 | if (Options.Compress) |
||
1723 | PutDoc("\n/Filter /FlateDecode"); |
||
1724 | PutDoc(" >>\nstream\n"+EncStream(fon, fontGlyphXForm)+"\nendstream"); |
||
1725 | writer.endObj(fontGlyphXForm); |
||
21894 | jghali | 1726 | pageData.XObjects[fontName + "_gl" + Pdf::toPdf(ig.key())] = fontGlyphXForm; |
20112 | jghali | 1727 | } |
1728 | return result; |
||
20103 | avox | 1729 | } |
1730 | |||
1731 | PdfId PDFLibCore::PDF_EmbedFontObject(const QByteArray& font, const QByteArray& subtype) |
||
1732 | |||
1733 | { |
||
20112 | jghali | 1734 | PdfId embeddedFontObject = writer.newObject(); |
1735 | writer.startObj(embeddedFontObject); |
||
1736 | int len = font.length(); |
||
1737 | QByteArray ttf = (Options.Compress? CompressArray(font) : font); |
||
1738 | //qDebug() << QString("sfnt data: size=%1 compressed=%2").arg(len).arg(bb.length()); |
||
1739 | PutDoc("<<\n/Length " + Pdf::toPdf(ttf.length() + 1) + "\n"); |
||
1740 | PutDoc("/Length1 " + Pdf::toPdf(len) + "\n"); |
||
1741 | if (subtype.size() > 0) |
||
1742 | PutDoc("/Subtype " + subtype); |
||
1743 | if (Options.Compress) |
||
1744 | PutDoc("/Filter /FlateDecode\n"); |
||
1745 | PutDoc(">>\nstream\n"); |
||
1746 | EncodeArrayToStream(ttf, embeddedFontObject); |
||
1747 | PutDoc("\nendstream"); |
||
1748 | writer.endObj(embeddedFontObject); |
||
1749 | return embeddedFontObject; |
||
20103 | avox | 1750 | } |
1751 | |||
21775 | jghali | 1752 | QByteArray PDFLibCore::PDF_GenerateSubsetTag(const QByteArray& fontName, QList<uint> usedGlyphs) |
1753 | { |
||
1754 | uint hash, mod; |
||
1755 | QVector<uint> glyphVec = usedGlyphs.toVector(); |
||
1756 | |||
1757 | hash = qHashBits(fontName.constData(), fontName.size(), 0); |
||
1758 | hash = qHashBits(glyphVec.constData(), glyphVec.size() * sizeof(uint), hash); |
||
1759 | |||
1760 | QByteArray subsetTag(6, (char) 0); |
||
1761 | for (int i = 0; i < 6; ++i) |
||
1762 | { |
||
1763 | mod = hash % 26; |
||
1764 | subsetTag[i] = 'A' + mod; |
||
1765 | hash = (hash - mod) / 26; |
||
1766 | } |
||
1767 | |||
1768 | return subsetTag; |
||
1769 | } |
||
1770 | |||
20103 | avox | 1771 | PdfId PDFLibCore::PDF_WriteFontDescriptor(const QByteArray& fontName, ScFace& face, ScFace::FontFormat fformat, PdfId embeddedFontObject) |
1772 | { |
||
20112 | jghali | 1773 | PdfId fontDescriptor = writer.newObject(); |
1774 | writer.startObj(fontDescriptor); |
||
1775 | // TODO: think about QByteArray ScFace::getFontDescriptor() -- AV |
||
1776 | PutDoc("<<\n/Type /FontDescriptor\n"); |
||
1777 | PutDoc("/FontName " + Pdf::toName(fontName) + "\n"); |
||
1778 | PutDoc("/FontBBox [ " + Pdf::toAscii(face.pdfFontBBoxAsString()) + " ]\n"); |
||
1779 | PutDoc("/Flags "); |
||
1780 | //FIXME: isItalic() should be queried from ScFace, not from Qt -- AV |
||
1781 | //QFontInfo fo = QFontInfo(it.data()); |
||
1782 | int pfl = 0; |
||
1783 | if (face.isFixedPitch()) |
||
1784 | pfl = pfl ^ 1; |
||
1785 | //if (fo.italic()) |
||
1786 | if (face.italicAngleAsString() != "0") |
||
1787 | pfl = pfl ^ 64; |
||
1788 | // pfl = pfl ^ 4; |
||
1789 | pfl = pfl ^ 32; |
||
1790 | PutDoc(Pdf::toPdf(pfl)+"\n"); |
||
1791 | PutDoc("/Ascent " + Pdf::toAscii(face.pdfAscentAsString())+"\n"); |
||
1792 | PutDoc("/Descent " + Pdf::toAscii(face.pdfDescentAsString())+"\n"); |
||
1793 | PutDoc("/CapHeight " + Pdf::toAscii(face.pdfCapHeightAsString())+"\n"); |
||
1794 | PutDoc("/ItalicAngle " + Pdf::toAscii(face.italicAngleAsString())+"\n"); |
||
1795 | PutDoc("/StemV 1\n"); |
||
1796 | if (embeddedFontObject != 0) |
||
1797 | { |
||
1798 | if (fformat == ScFace::SFNT || fformat == ScFace::TTCF) |
||
1799 | { |
||
1800 | if (face.type() == ScFace::OTF) |
||
1801 | { |
||
1802 | PutDoc("/FontFile3 "+Pdf::toPdf(embeddedFontObject)+" 0 R\n"); |
||
1803 | } |
||
1804 | else |
||
1805 | { |
||
1806 | PutDoc("/FontFile2 "+Pdf::toPdf(embeddedFontObject)+" 0 R\n"); |
||
1807 | } |
||
1808 | } |
||
1809 | else if (fformat == ScFace::PFB) |
||
1810 | PutDoc("/FontFile "+Pdf::toPdf(embeddedFontObject)+" 0 R\n"); |
||
1811 | else if (fformat == ScFace::PFA) |
||
1812 | PutDoc("/FontFile "+Pdf::toPdf(embeddedFontObject)+" 0 R\n"); |
||
1813 | } |
||
1814 | PutDoc(">>"); |
||
1815 | writer.endObj(fontDescriptor); |
||
1816 | return fontDescriptor; |
||
20103 | avox | 1817 | } |
1818 | |||
1819 | PdfFont PDFLibCore::PDF_EncodeCidFont(const QByteArray& fontName, ScFace& face, const QByteArray& baseFont, PdfId fontDes, const ScFace::FaceEncoding& gl, const QMap<uint,uint> glyphmap ) |
||
1820 | { |
||
20112 | jghali | 1821 | PdfFont result; |
1822 | result.name = Pdf::toName(fontName); |
||
1823 | result.method = glyphmap.isEmpty()? Use_Embedded : Use_Subset; |
||
1824 | result.encoding = glyphmap.isEmpty()? Encode_IdentityH : Encode_Subset; |
||
1825 | result.glyphmap = glyphmap; |
||
1826 | |||
1827 | PdfId fontWidths2 = writer.newObject(); |
||
1828 | writer.startObj(fontWidths2); |
||
1829 | QList<QByteArray> toUnicodeMaps; |
||
1830 | QList<int> toUnicodeMapsCount; |
||
1831 | QByteArray toUnicodeMap = ""; |
||
1832 | int toUnicodeMapCounter = 0; |
||
1833 | |||
1834 | PutDoc("[ "); |
||
1835 | QList<uint> keys = gl.uniqueKeys(); |
||
1836 | QList<uint>::iterator git; |
||
1837 | bool seenNotDef = false; |
||
1838 | for (git = keys.begin(); git != keys.end(); ++git) |
||
1839 | { |
||
1840 | uint gid = result.encoding == Encode_Subset? glyphmap[*git] : *git; |
||
1841 | if (gid > 0 || !seenNotDef) |
||
1842 | { |
||
1843 | seenNotDef |= (gid == 0); |
||
1844 | PutDoc(Pdf::toPdf(gid)+" ["+Pdf::toPdf(static_cast<int>(face.glyphWidth(*git)* 1000))+"] " ); |
||
1845 | QString tmp, tmp2; |
||
1846 | tmp.sprintf("%04X", gid); |
||
22143 | jghali | 1847 | tmp2 = gl.value(*git).toUnicode; |
20112 | jghali | 1848 | toUnicodeMap += "<" + Pdf::toAscii(tmp)+ "> <" + Pdf::toAscii(tmp2) + ">\n"; |
1849 | toUnicodeMapCounter++; |
||
1850 | if (toUnicodeMapCounter == 100) |
||
1851 | { |
||
1852 | toUnicodeMaps.append(toUnicodeMap); |
||
1853 | toUnicodeMapsCount.append(toUnicodeMapCounter); |
||
1854 | toUnicodeMap = ""; |
||
1855 | toUnicodeMapCounter = 0; |
||
1856 | } |
||
1857 | } |
||
1858 | } |
||
1859 | PutDoc("]"); |
||
1860 | writer.endObj(fontWidths2); |
||
1861 | if (toUnicodeMapCounter != 0) |
||
1862 | { |
||
1863 | toUnicodeMaps.append(toUnicodeMap); |
||
1864 | toUnicodeMapsCount.append(toUnicodeMapCounter); |
||
1865 | } |
||
1866 | QByteArray toUnicodeMapStream = ""; |
||
1867 | toUnicodeMapStream += "/CIDInit /ProcSet findresource begin\n"; |
||
1868 | toUnicodeMapStream += "12 dict begin\n"; |
||
1869 | toUnicodeMapStream += "begincmap\n"; |
||
1870 | toUnicodeMapStream += "/CIDSystemInfo <<\n"; |
||
1871 | toUnicodeMapStream += "/Registry (Adobe)\n"; |
||
1872 | toUnicodeMapStream += "/Ordering (UCS)\n"; |
||
1873 | toUnicodeMapStream += "/Supplement 0\n"; |
||
1874 | toUnicodeMapStream += ">> def\n"; |
||
1875 | toUnicodeMapStream += "/CMapName /Adobe-Identity-UCS def\n"; |
||
1876 | toUnicodeMapStream += "/CMapType 2 def\n"; |
||
1877 | toUnicodeMapStream += "1 begincodespacerange\n"; |
||
1878 | toUnicodeMapStream += "<0000> <FFFF>\n"; |
||
1879 | toUnicodeMapStream += "endcodespacerange\n"; |
||
1880 | for (int uniC = 0; uniC < toUnicodeMaps.count(); uniC++) |
||
1881 | { |
||
1882 | toUnicodeMapStream += Pdf::toPdf(toUnicodeMapsCount[uniC]); |
||
1883 | toUnicodeMapStream += " beginbfchar\n"; |
||
1884 | toUnicodeMapStream += toUnicodeMaps[uniC]; |
||
1885 | toUnicodeMapStream += "endbfchar\n"; |
||
1886 | } |
||
1887 | toUnicodeMapStream += "endcmap\n"; |
||
1888 | toUnicodeMapStream += "CMapName currentdict /CMap defineresource pop\n"; |
||
1889 | toUnicodeMapStream += "end\n"; |
||
1890 | toUnicodeMapStream += "end\n"; |
||
1891 | PdfId fontToUnicode2 = WritePDFStream(toUnicodeMapStream); |
||
1892 | PdfId fontObject2 = writer.newObject(); |
||
1893 | writer.startObj(fontObject2); |
||
1894 | PutDoc("<<\n/Type /Font\n/Subtype /Type0\n"); |
||
1895 | PutDoc("/Name " + Pdf::toName(fontName) + "\n"); |
||
21759 | jghali | 1896 | PutDoc("/BaseFont "+ Pdf::toName(baseFont) +"\n"); |
20112 | jghali | 1897 | PutDoc("/Encoding /Identity-H\n"); |
1898 | PutDoc("/ToUnicode "+Pdf::toPdf(fontToUnicode2)+" 0 R\n"); |
||
1899 | PutDoc("/DescendantFonts ["); |
||
1900 | PutDoc("<</Type /Font"); |
||
1901 | if (face.type() == ScFace::OTF) |
||
1902 | PutDoc("/Subtype /CIDFontType0"); |
||
1903 | else |
||
1904 | PutDoc("/Subtype /CIDFontType2"); |
||
21759 | jghali | 1905 | PutDoc("/BaseFont " + Pdf::toName(baseFont)); |
20112 | jghali | 1906 | PutDoc("/FontDescriptor " + Pdf::toPdf(fontDes)+ " 0 R"); |
1907 | PutDoc("/CIDSystemInfo <</Ordering(Identity)/Registry(Adobe)/Supplement 0>>"); |
||
1908 | PutDoc("/DW 1000"); |
||
1909 | PutDoc("/W "+Pdf::toPdf(fontWidths2)+" 0 R"); |
||
1910 | PutDoc("/CIDToGIDMap /Identity"); |
||
1911 | PutDoc(">>"); // close CIDFont dictionary |
||
1912 | PutDoc("]\n"); // close DescendantFonts array |
||
1913 | PutDoc(">>"); |
||
1914 | writer.endObj(fontObject2); |
||
1915 | pageData.FObjects[fontName] = fontObject2; |
||
1916 | return result; |
||
20103 | avox | 1917 | } |
1918 | |||
1919 | |||
1920 | PdfFont PDFLibCore::PDF_EncodeSimpleFont(const QByteArray& fontName, ScFace& face, const QByteArray& baseFont, const QByteArray& subtype, bool isEmbedded, PdfId fontDes, const ScFace::FaceEncoding& gl) |
||
1921 | { |
||
20112 | jghali | 1922 | PdfFont result; |
1923 | result.name = Pdf::toName(fontName); |
||
1924 | result.method = isEmbedded? Use_Embedded : Use_System; |
||
1925 | result.encoding = Encode_224; |
||
1926 | |||
1927 | int nglyphs = 0; |
||
1928 | ScFace::FaceEncoding::ConstIterator gli; |
||
1929 | for (gli = gl.cbegin(); gli != gl.cend(); ++gli) |
||
1930 | { |
||
1931 | if (gli.key() > static_cast<uint>(nglyphs)) |
||
1932 | nglyphs = gli.key(); |
||
1933 | } |
||
1934 | ++nglyphs; |
||
1935 | // qDebug() << QString("pdflib: nglyphs %1 max %2").arg(nglyphs).arg(face.maxGlyph()); |
||
1936 | |||
1937 | uint Fcc = nglyphs / 224; |
||
1938 | if ((nglyphs % 224) != 0) |
||
1939 | Fcc += 1; |
||
1940 | for (uint Fc = 0; Fc < Fcc; ++Fc) |
||
1941 | { |
||
1942 | PdfId fontWidths2 = writer.newObject(); |
||
1943 | writer.startObj(fontWidths2); |
||
1944 | int chCount = 32; |
||
1945 | 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 "); |
||
1946 | for (int ww = 32; ww < 256; ++ww) |
||
1947 | { |
||
1948 | uint glyph = 224 * Fc + ww - 32; |
||
1949 | if (gl.contains(glyph)) |
||
1950 | PutDoc(Pdf::toPdf(static_cast<int>(face.glyphWidth(glyph)* 1000))+" "); |
||
1951 | else |
||
1952 | PutDoc("0 "); |
||
1953 | chCount++; |
||
1954 | if (signed(glyph) == nglyphs-1) |
||
1955 | break; |
||
1956 | } |
||
1957 | PutDoc("]"); |
||
1958 | writer.endObj(fontWidths2); |
||
1959 | PdfId fontEncoding2 = writer.newObject(); |
||
1960 | writer.startObj(fontEncoding2); |
||
1961 | QStringList toUnicodeMaps; |
||
1962 | QList<int> toUnicodeMapsCount; |
||
1963 | QString toUnicodeMap = ""; |
||
1964 | int toUnicodeMapCounter = 0; |
||
1965 | PutDoc("<< /Type /Encoding\n"); |
||
1966 | PutDoc("/Differences [ \n"); |
||
1967 | int crc = 0; |
||
1968 | bool startOfSeq = true; |
||
1969 | for (int ww2 = 32; ww2 < 256; ++ww2) |
||
1970 | { |
||
1971 | uint glyph = 224 * Fc + ww2 - 32; |
||
1972 | ScFace::FaceEncoding::ConstIterator glIt = gl.find(glyph); |
||
22143 | jghali | 1973 | if (glIt != gl.cend() && !glIt.value().glyphName.isEmpty()) |
20112 | jghali | 1974 | { |
22143 | jghali | 1975 | const ScFace::GlyphEncoding& glEncoding = glIt.value(); |
20112 | jghali | 1976 | if (startOfSeq) |
1977 | { |
||
1978 | PutDoc(Pdf::toPdf(ww2)+" "); |
||
1979 | startOfSeq = false; |
||
1980 | } |
||
22143 | jghali | 1981 | PutDoc(Pdf::toName(glEncoding.glyphName)+" "); |
20112 | jghali | 1982 | QString tmp, tmp2; |
1983 | tmp.sprintf("%02X", ww2); |
||
22143 | jghali | 1984 | tmp2 = glEncoding.toUnicode; |
20112 | jghali | 1985 | toUnicodeMap += "<" + Pdf::toAscii(tmp) + "> <" + Pdf::toAscii(tmp2) + ">\n"; |
1986 | //QString("<%1> <%2>\n").arg(tmp).arg((tmp2)); |
||
1987 | toUnicodeMapCounter++; |
||
1988 | if (toUnicodeMapCounter == 100) |
||
1989 | { |
||
1990 | toUnicodeMaps.append(toUnicodeMap); |
||
1991 | toUnicodeMapsCount.append(toUnicodeMapCounter); |
||
1992 | toUnicodeMap = ""; |
||
1993 | toUnicodeMapCounter = 0; |
||
1994 | } |
||
1995 | crc++; |
||
1996 | } |
||
1997 | else |
||
1998 | { |
||
1999 | startOfSeq = true; |
||
2000 | } |
||
2001 | if (signed(glyph) == nglyphs-1) |
||
2002 | break; |
||
2003 | if (crc > 8) |
||
2004 | { |
||
2005 | PutDoc("\n"); |
||
2006 | crc = 0; |
||
2007 | } |
||
2008 | } |
||
2009 | if (toUnicodeMapCounter != 0) |
||
2010 | { |
||
2011 | toUnicodeMaps.append(toUnicodeMap); |
||
2012 | toUnicodeMapsCount.append(toUnicodeMapCounter); |
||
2013 | } |
||
2014 | PutDoc("]\n"); |
||
2015 | PutDoc(">>"); |
||
2016 | writer.endObj(fontEncoding2); |
||
2017 | QByteArray toUnicodeMapStream = ""; |
||
2018 | toUnicodeMapStream += "/CIDInit /ProcSet findresource begin\n"; |
||
2019 | toUnicodeMapStream += "12 dict begin\n"; |
||
2020 | toUnicodeMapStream += "begincmap\n"; |
||
2021 | toUnicodeMapStream += "/CIDSystemInfo <<\n"; |
||
2022 | toUnicodeMapStream += "/Registry (Adobe)\n"; |
||
2023 | toUnicodeMapStream += "/Ordering (UCS)\n"; |
||
2024 | toUnicodeMapStream += "/Supplement 0\n"; |
||
2025 | toUnicodeMapStream += ">> def\n"; |
||
2026 | toUnicodeMapStream += "/CMapName /Adobe-Identity-UCS def\n"; |
||
2027 | toUnicodeMapStream += "/CMapType 2 def\n"; |
||
2028 | toUnicodeMapStream += "1 begincodespacerange\n"; |
||
2029 | toUnicodeMapStream += "<0000> <FFFF>\n"; |
||
2030 | toUnicodeMapStream += "endcodespacerange\n"; |
||
2031 | for (int uniC = 0; uniC < toUnicodeMaps.count(); uniC++) |
||
2032 | { |
||
2033 | toUnicodeMapStream += Pdf::toPdf(toUnicodeMapsCount[uniC]); |
||
2034 | toUnicodeMapStream += " beginbfchar\n"; |
||
2035 | toUnicodeMapStream += toUnicodeMaps[uniC]; |
||
2036 | toUnicodeMapStream += "endbfchar\n"; |
||
2037 | } |
||
2038 | toUnicodeMapStream += "endcmap\n"; |
||
2039 | toUnicodeMapStream += "CMapName currentdict /CMap defineresource pop\n"; |
||
2040 | toUnicodeMapStream += "end\n"; |
||
2041 | toUnicodeMapStream += "end\n"; |
||
2042 | PdfId fontToUnicode2 = WritePDFStream(toUnicodeMapStream); |
||
2043 | PdfId fontObject2 = writer.newObject(); |
||
2044 | writer.startObj(fontObject2); |
||
2045 | PutDoc("<<\n/Type /Font\n/Subtype "); |
||
2046 | PutDoc(subtype + "\n"); |
||
2047 | PutDoc("/Name "+Pdf::toName(fontName)+"S"+Pdf::toPdf(Fc)+"\n"); |
||
21759 | jghali | 2048 | PutDoc("/BaseFont "+ Pdf::toName(baseFont) + "\n"); |
20112 | jghali | 2049 | PutDoc("/FirstChar 0\n"); |
2050 | PutDoc("/LastChar "+Pdf::toPdf(chCount-1)+"\n"); |
||
2051 | PutDoc("/Widths "+Pdf::toPdf(fontWidths2)+" 0 R\n"); |
||
2052 | PutDoc("/Encoding "+Pdf::toPdf(fontEncoding2)+" 0 R\n"); |
||
2053 | PutDoc("/ToUnicode "+Pdf::toPdf(fontToUnicode2)+" 0 R\n"); |
||
2054 | PutDoc("/FontDescriptor "+Pdf::toPdf(fontDes)+" 0 R\n"); |
||
2055 | PutDoc(">>"); |
||
2056 | writer.endObj(fontObject2); |
||
2057 | pageData.FObjects[fontName + "S"+Pdf::toPdf(Fc)] = fontObject2; |
||
2058 | } // for(Fc) |
||
21744 | jghali | 2059 | |
2060 | return result; |
||
2061 | } |
||
2062 | |||
2063 | PdfFont PDFLibCore::PDF_EncodeFormFont(const QByteArray& fontName, ScFace& face, const QByteArray& baseFont, const QByteArray& subtype, PdfId fontDes) |
||
2064 | { |
||
2065 | PdfFont formFont; |
||
2066 | formFont.name = Pdf::toName(fontName) + "Form"; |
||
2067 | formFont.usage = Used_in_Forms; |
||
2068 | |||
20112 | jghali | 2069 | PdfId fontWidthsForm = writer.newObject(); |
2070 | writer.startObj(fontWidthsForm); |
||
2071 | 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 "); |
||
21563 | jghali | 2072 | for (uint ww = 32; ww < 256; ++ww) |
20112 | jghali | 2073 | { |
21744 | jghali | 2074 | int unicode = Pdf::fromPDFDocEncoding(ww); |
2075 | uint glyph = face.char2CMap(unicode); |
||
2076 | if (glyph > 0) |
||
20112 | jghali | 2077 | PutDoc(Pdf::toPdf(static_cast<int>(face.glyphWidth(glyph)* 1000))+" "); |
2078 | else |
||
2079 | PutDoc("0 "); |
||
2080 | } |
||
2081 | PutDoc("]"); |
||
2082 | writer.endObj(fontWidthsForm); |
||
21744 | jghali | 2083 | |
20112 | jghali | 2084 | PdfId fontObjectForm = writer.newObject(); |
2085 | writer.startObj(fontObjectForm); |
||
2086 | PutDoc("<<\n/Type /Font\n/Subtype "); |
||
2087 | PutDoc(subtype + "\n"); |
||
21759 | jghali | 2088 | PutDoc("/Name " + formFont.name + "\n"); |
2089 | PutDoc("/BaseFont "+ Pdf::toName(baseFont) +"\n"); |
||
20112 | jghali | 2090 | PutDoc("/Encoding << \n"); |
2091 | PutDoc("/Differences [ \n"); |
||
2092 | PutDoc("24 /breve /caron /circumflex /dotaccent /hungarumlaut /ogonek /ring /tilde\n"); |
||
2093 | PutDoc("39 /quotesingle 96 /grave 128 /bullet /dagger /daggerdbl /ellipsis /emdash /endash /florin /fraction /guilsinglleft /guilsinglright\n"); |
||
2094 | PutDoc("/minus /perthousand /quotedblbase /quotedblleft /quotedblright /quoteleft /quoteright /quotesinglbase /trademark /fi /fl /Lslash /OE /Scaron\n"); |
||
21744 | jghali | 2095 | PutDoc("/Ydieresis /Zcaron /dotlessi /lslash /oe /scaron /zcaron 160 /Euro 164 /currency 166 /brokenbar 168 /dieresis /copyright /ordfeminine 172 /logicalnot\n"); |
20112 | jghali | 2096 | PutDoc("/.notdef /registered /macron /degree /plusminus /twosuperior /threesuperior /acute /mu 183 /periodcentered /cedilla /onesuperior /ordmasculine\n"); |
2097 | PutDoc("188 /onequarter /onehalf /threequarters 192 /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla /Egrave /Eacute /Ecircumflex\n"); |
||
2098 | PutDoc("/Edieresis /Igrave /Iacute /Icircumflex /Idieresis /Eth /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply /Oslash\n"); |
||
2099 | PutDoc("/Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn /germandbls /agrave /aacute /acircumflex /atilde /adieresis /aring /ae /ccedilla\n"); |
||
2100 | PutDoc("/egrave /eacute /ecircumflex /edieresis /igrave /iacute /icircumflex /idieresis /eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis\n"); |
||
2101 | PutDoc("/divide /oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn /ydieresis\n"); |
||
2102 | PutDoc("] >>\n"); |
||
2103 | PutDoc("/FirstChar 0\n"); |
||
2104 | PutDoc("/LastChar 255\n"); |
||
2105 | PutDoc("/Widths "+Pdf::toPdf(fontWidthsForm)+" 0 R\n"); |
||
2106 | PutDoc("/FontDescriptor "+Pdf::toPdf(fontDes)+" 0 R\n"); |
||
2107 | PutDoc(">>"); |
||
2108 | writer.endObj(fontObjectForm); |
||
20103 | avox | 2109 | |
21744 | jghali | 2110 | pageData.FObjects[fontName + "Form"] = fontObjectForm; |
2111 | UsedFontsF.insert(face.replacementName(), formFont); |
||
2112 | |||
2113 | return formFont; |
||
20103 | avox | 2114 | } |
2115 | |||
21075 | craig | 2116 | /* |
20103 | avox | 2117 | static void dumpFont(QString name, QByteArray data) |
2118 | { |
||
20112 | jghali | 2119 | QFile file(name); |
20980 | craig | 2120 | if (file.open(QIODevice::WriteOnly)) |
2121 | { |
||
2122 | QDataStream out(&file); |
||
2123 | out.writeRawData(data.data(), data.length()); |
||
2124 | file.close(); |
||
2125 | } |
||
20103 | avox | 2126 | } |
2127 | |||
2128 | static void dumpCFF(QString name, cff::CFF font) |
||
2129 | { |
||
20112 | jghali | 2130 | QFile file(name); |
20980 | craig | 2131 | if (file.open(QIODevice::WriteOnly)) |
2132 | { |
||
2133 | QDataStream out(&file); |
||
2134 | font.dump(out); |
||
2135 | file.close(); |
||
2136 | } |
||
20103 | avox | 2137 | } |
21075 | craig | 2138 |