Rev 18454 | Rev 18734 | 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 | */ |
||
3136 | fschmid | 7 | /*************************************************************************** |
8 | pslib.cpp - description |
||
9 | ------------------- |
||
10 | begin : Sat May 26 2001 |
||
11 | copyright : (C) 2001 by Franz Schmid |
||
12 | email : Franz.Schmid@altmuehlnet.de |
||
13 | ***************************************************************************/ |
||
14 | |||
15 | /*************************************************************************** |
||
16 | * * |
||
17 | * This program is free software; you can redistribute it and/or modify * |
||
18 | * it under the terms of the GNU General Public License as published by * |
||
19 | * the Free Software Foundation; either version 2 of the License, or * |
||
20 | * (at your option) any later version. * |
||
21 | * * |
||
22 | ***************************************************************************/ |
||
4037 | cbradney | 23 | |
24 | #include "pslib.h" |
||
25 | |||
16480 | craig | 26 | #include <cstdlib> |
27 | |||
10223 | cbradney | 28 | #include <QFileInfo> |
29 | #include <QImage> |
||
30 | #include <QColor> |
||
31 | #include <QFontInfo> |
||
9803 | fschmid | 32 | #include <QList> |
9967 | fschmid | 33 | #include <QByteArray> |
10223 | cbradney | 34 | #include <QRegExp> |
35 | #include <QBuffer> |
||
9922 | fschmid | 36 | #include <QStack> |
3136 | fschmid | 37 | |
10601 | mrdocs | 38 | #include "cmsettings.h" |
4037 | cbradney | 39 | #include "commonstrings.h" |
3136 | fschmid | 40 | #include "scconfig.h" |
41 | #include "pluginapi.h" |
||
13982 | jghali | 42 | #include "pageitem_latexframe.h" |
17023 | fschmid | 43 | #include "pageitem_pathtext.h" |
17304 | fschmid | 44 | #include "pageitem_table.h" |
3939 | cbradney | 45 | #include "prefsmanager.h" |
13467 | jghali | 46 | #include "scclocale.h" |
13982 | jghali | 47 | #include "sccolorengine.h" |
48 | #include "scfonts.h" |
||
49 | #include "scribusapp.h" |
||
3136 | fschmid | 50 | #include "scribusdoc.h" |
4037 | cbradney | 51 | #include "scribus.h" |
5243 | cbradney | 52 | #include "scribuscore.h" |
3934 | cbradney | 53 | #include "selection.h" |
13982 | jghali | 54 | #include "scpattern.h" |
55 | #include "scstreamfilter_ascii85.h" |
||
56 | #include "scstreamfilter_flate.h" |
||
17310 | fschmid | 57 | #include "tableutils.h" |
13982 | jghali | 58 | #include "ui/multiprogressdialog.h" |
3136 | fschmid | 59 | #include "util.h" |
10212 | cbradney | 60 | #include "util_formats.h" |
10203 | cbradney | 61 | #include "util_math.h" |
3136 | fschmid | 62 | |
17310 | fschmid | 63 | using namespace TableUtils; |
5184 | avox | 64 | |
6954 | fschmid | 65 | PSLib::PSLib(PrintOptions &options, bool psart, SCFonts &AllFonts, QMap<QString, QMap<uint, FPointArray> > DocFonts, ColorList DocColors, bool pdf, bool spot) |
3136 | fschmid | 66 | { |
6954 | fschmid | 67 | Options = options; |
11562 | jghali | 68 | optimization = OptimizeCompat; |
5243 | cbradney | 69 | usingGUI=ScCore->usingGUI(); |
4044 | cbradney | 70 | abortExport=false; |
3136 | fschmid | 71 | QString tmp, tmp2, tmp3, tmp4, CHset; |
72 | QStringList wt; |
||
73 | Seiten = 0; |
||
74 | User = ""; |
||
75 | Creator = "Scribus" + QString(VERSION); |
||
76 | Titel = ""; |
||
77 | FillColor = "0.0 0.0 0.0 0.0"; |
||
78 | StrokeColor = "0.0 0.0 0.0 0.0"; |
||
79 | Header = psart ? "%!PS-Adobe-3.0\n" : "%!PS-Adobe-3.0 EPSF-3.0\n"; |
||
80 | BBox = ""; |
||
81 | BBoxH = ""; |
||
15548 | fschmid | 82 | psExport = psart; |
3136 | fschmid | 83 | isPDF = pdf; |
84 | UsedFonts.clear(); |
||
85 | Fonts = ""; |
||
86 | FontDesc = ""; |
||
87 | GraySc = false; |
||
88 | DoSep = false; |
||
4046 | fschmid | 89 | abortExport = false; |
3136 | fschmid | 90 | useSpotColors = spot; |
91 | GrayCalc = "/setcmykcolor {exch 0.11 mul add exch 0.59 mul add exch 0.3 mul add\n"; |
||
92 | GrayCalc += " dup 1 gt {pop 1} if 1 exch sub oldsetgray} bind def\n"; |
||
93 | GrayCalc += "/setrgbcolor {0.11 mul exch 0.59 mul add exch 0.3 mul add\n"; |
||
94 | GrayCalc += " oldsetgray} bind def\n"; |
||
6748 | fschmid | 95 | Farben = ""; |
96 | FNamen = ""; |
||
9619 | jghali | 97 | CMYKColor cmykValues; |
3136 | fschmid | 98 | ColorList::Iterator itf; |
99 | int c, m, y, k; |
||
14033 | jghali | 100 | int spotCount = 1; |
3136 | fschmid | 101 | bool erst = true; |
102 | colorsToUse = DocColors; |
||
103 | spotMap.clear(); |
||
104 | colorDesc = ""; |
||
105 | for (itf = DocColors.begin(); itf != DocColors.end(); ++itf) |
||
106 | { |
||
14033 | jghali | 107 | if (((itf->isSpotColor()) || (itf->isRegistrationColor())) && (useSpotColors)) |
3136 | fschmid | 108 | { |
14033 | jghali | 109 | ScColorEngine::getCMYKValues(*itf, DocColors.document(), cmykValues); |
9619 | jghali | 110 | cmykValues.getValues(c, m, y, k); |
14033 | jghali | 111 | colorDesc += "/Spot"+QString::number(spotCount)+" { [ /Separation ("; |
3136 | fschmid | 112 | if (DocColors[itf.key()].isRegistrationColor()) |
113 | colorDesc += "All"; |
||
114 | else |
||
115 | colorDesc += itf.key(); |
||
116 | colorDesc += ")\n"; |
||
117 | colorDesc += "/DeviceCMYK\n{\ndup "+ToStr(static_cast<double>(c) / 255)+"\nmul exch dup "; |
||
118 | colorDesc += ToStr(static_cast<double>(m) / 255)+"\nmul exch dup "; |
||
119 | colorDesc += ToStr(static_cast<double>(y) / 255)+"\nmul exch "; |
||
120 | colorDesc += ToStr(static_cast<double>(k) / 255)+" mul }] setcolorspace setcolor} bind def\n"; |
||
14033 | jghali | 121 | spotMap.insert(itf.key(), "Spot"+QString::number(spotCount)); |
122 | ++spotCount; |
||
3136 | fschmid | 123 | } |
124 | if ((itf.key() != "Cyan") && (itf.key() != "Magenta") && (itf.key() != "Yellow") && (itf.key() != "Black") && DocColors[itf.key()].isSpotColor()) |
||
125 | { |
||
9619 | jghali | 126 | ScColorEngine::getCMYKValues(DocColors[itf.key()], DocColors.document(), cmykValues); |
127 | cmykValues.getValues(c, m, y, k); |
||
3136 | fschmid | 128 | if (!erst) |
129 | { |
||
130 | Farben += "%%+ "; |
||
131 | FNamen += "%%+ "; |
||
132 | } |
||
133 | Farben += ToStr(static_cast<double>(c) / 255) + " " + ToStr(static_cast<double>(m) / 255) + " "; |
||
134 | Farben += ToStr(static_cast<double>(y) / 255) + " " + ToStr(static_cast<double>(k) / 255) + " (" + itf.key() + ")\n"; |
||
135 | FNamen += "(" + itf.key() + ")\n"; |
||
136 | erst = false; |
||
137 | } |
||
138 | } |
||
13769 | jghali | 139 | QMap<QString, QString> psNameMap; |
5387 | avox | 140 | QMap<QString, QMap<uint, FPointArray> >::Iterator it; |
3136 | fschmid | 141 | int a = 0; |
142 | for (it = DocFonts.begin(); it != DocFonts.end(); ++it) |
||
143 | { |
||
13769 | jghali | 144 | // Subset all TTF Fonts until the bug in the TTF-Embedding Code is fixed |
145 | // Subset also font whose postscript name conflicts with an already used font |
||
146 | ScFace &face (AllFonts[it.key()]); |
||
147 | ScFace::FontType type = face.type(); |
||
148 | QString encodedName = face.psName().simplified().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" ); |
||
3136 | fschmid | 149 | |
13769 | jghali | 150 | if ((type == ScFace::TTF) || (face.isOTF()) || (face.subset()) || psNameMap.contains(encodedName)) |
3136 | fschmid | 151 | { |
10398 | cbradney | 152 | QMap<uint, FPointArray>& RealGlyphs(it.value()); |
13769 | jghali | 153 | // Handle possible PostScript name conflict in oft/ttf fonts |
154 | int psNameIndex = 1; |
||
155 | QString initialName = encodedName; |
||
156 | while (psNameMap.contains(encodedName)) |
||
157 | { |
||
158 | encodedName = QString("%1-%2").arg(initialName).arg(psNameIndex); |
||
159 | ++psNameIndex; |
||
160 | } |
||
161 | FontDesc += "/" + encodedName + " " + IToStr(RealGlyphs.count()+1) + " dict def\n"; |
||
162 | FontDesc += encodedName + " begin\n"; |
||
3136 | fschmid | 163 | QMap<uint,FPointArray>::Iterator ig; |
5390 | avox | 164 | for (ig = RealGlyphs.begin(); ig != RealGlyphs.end(); ++ig) |
3136 | fschmid | 165 | { |
166 | FontDesc += "/G"+IToStr(ig.key())+" { newpath\n"; |
||
167 | FPoint np, np1, np2; |
||
168 | bool nPath = true; |
||
10398 | cbradney | 169 | if (ig.value().size() > 3) |
3136 | fschmid | 170 | { |
18114 | jghali | 171 | for (int poi = 0; poi < ig.value().size()-3; poi += 4) |
3136 | fschmid | 172 | { |
10398 | cbradney | 173 | if (ig.value().point(poi).x() > 900000) |
3136 | fschmid | 174 | { |
175 | FontDesc += "cl\n"; |
||
176 | nPath = true; |
||
177 | continue; |
||
178 | } |
||
179 | if (nPath) |
||
180 | { |
||
10398 | cbradney | 181 | np = ig.value().point(poi); |
3136 | fschmid | 182 | FontDesc += ToStr(np.x()) + " " + ToStr(-np.y()) + " m\n"; |
183 | nPath = false; |
||
184 | } |
||
10398 | cbradney | 185 | np = ig.value().point(poi+1); |
186 | np1 = ig.value().point(poi+3); |
||
187 | np2 = ig.value().point(poi+2); |
||
3136 | fschmid | 188 | FontDesc += ToStr(np.x()) + " " + ToStr(-np.y()) + " " + |
189 | ToStr(np1.x()) + " " + ToStr(-np1.y()) + " " + |
||
190 | ToStr(np2.x()) + " " + ToStr(-np2.y()) + " cu\n"; |
||
191 | } |
||
192 | } |
||
193 | FontDesc += "cl\n} bind def\n"; |
||
194 | } |
||
195 | FontDesc += "end\n"; |
||
13769 | jghali | 196 | FontSubsetMap.insert(face.scName(), encodedName); |
3136 | fschmid | 197 | } |
198 | else |
||
199 | { |
||
200 | UsedFonts.insert(it.key(), "/Fo"+IToStr(a)); |
||
13769 | jghali | 201 | Fonts += "/Fo" + IToStr(a) + " /" + encodedName + " findfont definefont pop\n"; |
5980 | avox | 202 | if (AllFonts[it.key()].embedPs()) |
3136 | fschmid | 203 | { |
204 | QString tmp; |
||
13769 | jghali | 205 | if(face.EmbedFont(tmp)) |
3136 | fschmid | 206 | { |
13769 | jghali | 207 | FontDesc += "%%BeginFont: " + encodedName + "\n"; |
3136 | fschmid | 208 | FontDesc += tmp + "\n%%EndFont\n"; |
209 | } |
||
210 | } |
||
13769 | jghali | 211 | GlyphList gl; |
212 | face.glyphNames(gl); |
||
3136 | fschmid | 213 | GlyphsOfFont.insert(it.key(), gl); |
214 | a++; |
||
215 | } |
||
13769 | jghali | 216 | psNameMap.insert(encodedName, face.scName()); |
3136 | fschmid | 217 | } |
218 | Prolog = "%%BeginProlog\n"; |
||
219 | Prolog += "/Scribusdict 100 dict def\n"; |
||
220 | Prolog += "Scribusdict begin\n"; |
||
221 | Prolog += "/sp {showpage} bind def\n"; |
||
222 | Prolog += "/oldsetgray /setgray load def\n"; |
||
223 | Prolog += "/cmyk {setcmykcolor} def\n"; |
||
224 | Prolog += "/m {moveto} bind def\n"; |
||
225 | Prolog += "/l {lineto} bind def\n"; |
||
226 | Prolog += "/li {lineto} bind def\n"; |
||
227 | Prolog += "/cu {curveto} bind def\n"; |
||
228 | Prolog += "/cl {closepath} bind def\n"; |
||
229 | Prolog += "/gs {gsave} bind def\n"; |
||
230 | Prolog += "/gr {grestore} bind def\n"; |
||
231 | Prolog += "/tr {translate} bind def\n"; |
||
232 | Prolog += "/ro {rotate} bind def\n"; |
||
233 | Prolog += "/sh {show} bind def\n"; |
||
234 | Prolog += "/shg {setcmykcolor moveto glyphshow} def\n"; |
||
3555 | fschmid | 235 | Prolog += "/shgsp {moveto glyphshow} def\n"; |
3136 | fschmid | 236 | Prolog += "/sc {scale} bind def\n"; |
237 | Prolog += "/se {selectfont} bind def\n"; |
||
238 | Prolog += "/sf {setfont} bind def\n"; |
||
239 | Prolog += "/sw {setlinewidth} bind def\n"; |
||
240 | Prolog += "/f {findfont} bind def\n"; |
||
241 | Prolog += "/fi {fill} bind def\n"; |
||
242 | Prolog += "/st {stroke} bind def\n"; |
||
243 | Prolog += "/shgf {gs dup scale begin cvx exec fill end gr} bind def\n"; |
||
244 | Prolog += "/shgs {gs dup 1 exch div currentlinewidth mul sw dup scale\n"; |
||
245 | Prolog += " begin cvx exec st end gr} bind def\n"; |
||
246 | Prolog += "/bEPS {\n"; |
||
247 | Prolog += " /b4_Inc_state save def\n"; |
||
248 | Prolog += " /dict_count countdictstack def\n"; |
||
249 | Prolog += " /op_count count 1 sub def\n"; |
||
250 | Prolog += " userdict begin\n"; |
||
251 | Prolog += " /showpage { } def\n"; |
||
252 | Prolog += " 0 setgray 0 setlinecap\n"; |
||
253 | Prolog += " 1 setlinewidth 0 setlinejoin\n"; |
||
254 | Prolog += " 10 setmiterlimit [ ] 0 setdash newpath\n"; |
||
255 | Prolog += " /languagelevel where\n"; |
||
256 | Prolog += " {pop languagelevel\n"; |
||
257 | Prolog += " 1 ne\n"; |
||
258 | Prolog += " {false setstrokeadjust false setoverprint\n"; |
||
259 | Prolog += " } if } if } bind def\n"; |
||
260 | Prolog += "/eEPS { count op_count sub {pop} repeat\n"; |
||
261 | Prolog += " countdictstack dict_count sub {end} repeat\n"; |
||
262 | Prolog += " b4_Inc_state restore } bind def\n"; |
||
263 | Prolog += " end\n"; |
||
6954 | fschmid | 264 | if ((Options.cropMarks) || (Options.bleedMarks) || (Options.registrationMarks) || (Options.colorMarks)) |
265 | Prolog += "/rb { [ /Separation (All)\n/DeviceCMYK { dup 0 mul exch dup 0 mul exch dup 0 mul exch 1 mul }\n] setcolorspace setcolor} bind def\n"; |
||
3136 | fschmid | 266 | Prolog += "%%EndProlog\n"; |
267 | } |
||
268 | |||
11280 | jghali | 269 | void PSLib::PutStream(const QString& c) |
3136 | fschmid | 270 | { |
14033 | jghali | 271 | QByteArray utf8Array = c.toUtf8(); |
272 | spoolStream.writeRawData(utf8Array.data(), utf8Array.length()); |
||
3136 | fschmid | 273 | } |
274 | |||
11280 | jghali | 275 | void PSLib::PutStream(const QByteArray& array, bool hexEnc) |
5234 | fschmid | 276 | { |
277 | if(hexEnc) |
||
11107 | jghali | 278 | WriteASCII85Bytes(array); |
5234 | fschmid | 279 | else |
11534 | jghali | 280 | spoolStream.writeRawData(array.data(), array.size()); |
5234 | fschmid | 281 | } |
282 | |||
11280 | jghali | 283 | void PSLib::PutStream(const char* array, int length, bool hexEnc) |
5234 | fschmid | 284 | { |
285 | if(hexEnc) |
||
11107 | jghali | 286 | WriteASCII85Bytes((const unsigned char*) array, length); |
5234 | fschmid | 287 | else |
11534 | jghali | 288 | spoolStream.writeRawData(array, length); |
5234 | fschmid | 289 | } |
290 | |||
11568 | jghali | 291 | bool PSLib::PutImageToStream(ScImage& image, int plate) |
292 | { |
||
293 | bool writeSucceed = false; |
||
294 | ScASCII85EncodeFilter asciiEncode(&spoolStream); |
||
295 | ScFlateEncodeFilter flateEncode(&asciiEncode); |
||
296 | if (flateEncode.openFilter()) |
||
297 | { |
||
298 | writeSucceed = image.writePSImageToFilter(&flateEncode, plate); |
||
299 | writeSucceed &= flateEncode.closeFilter(); |
||
300 | } |
||
301 | return writeSucceed; |
||
302 | } |
||
303 | |||
304 | bool PSLib::PutImageToStream(ScImage& image, const QByteArray& mask, int plate) |
||
305 | { |
||
306 | bool writeSucceed = false; |
||
307 | ScASCII85EncodeFilter asciiEncode(&spoolStream); |
||
308 | ScFlateEncodeFilter flateEncode(&asciiEncode); |
||
309 | if (flateEncode.openFilter()) |
||
310 | { |
||
311 | writeSucceed = image.writePSImageToFilter(&flateEncode, mask, plate); |
||
312 | writeSucceed &= flateEncode.closeFilter(); |
||
313 | } |
||
314 | return writeSucceed; |
||
315 | } |
||
316 | |||
11551 | jghali | 317 | bool PSLib::PutImageDataToStream(const QByteArray& image) |
11107 | jghali | 318 | { |
11551 | jghali | 319 | bool writeSucceed = false; |
320 | ScASCII85EncodeFilter asciiEncode(&spoolStream); |
||
321 | ScFlateEncodeFilter flateEncode(&asciiEncode); |
||
322 | if (flateEncode.openFilter()) |
||
323 | { |
||
324 | writeSucceed = flateEncode.writeData(image, image.size()); |
||
325 | writeSucceed &= flateEncode.closeFilter(); |
||
326 | } |
||
327 | return writeSucceed; |
||
11107 | jghali | 328 | } |
329 | |||
11551 | jghali | 330 | bool PSLib::PutInterleavedImageMaskToStream(const QByteArray& image, const QByteArray& mask, bool gray) |
11107 | jghali | 331 | { |
11551 | jghali | 332 | int pending = 0; |
333 | unsigned char bytes[1505]; |
||
334 | const unsigned char* imageData = (const unsigned char*) image.constData(); |
||
335 | const unsigned char* maskData = (const unsigned char*) mask.constData(); |
||
336 | bool writeSuccess = true; |
||
11107 | jghali | 337 | |
11551 | jghali | 338 | int channels = gray ? 1 : 4; |
339 | int pixels = image.size() / channels; |
||
340 | assert((image.size() % channels) == 0); |
||
341 | assert( mask.size() >= pixels ); |
||
11440 | jghali | 342 | |
11551 | jghali | 343 | ScASCII85EncodeFilter asciiEncode(&spoolStream); |
344 | ScFlateEncodeFilter flateEncode(&asciiEncode); |
||
345 | if (!flateEncode.openFilter()) |
||
346 | return false; |
||
347 | |||
348 | for (int i = 0; i < pixels; ++i) |
||
11107 | jghali | 349 | { |
11551 | jghali | 350 | bytes[pending++] = maskData [i]; |
351 | bytes[pending++] = *imageData++; // cyan/black |
||
11562 | jghali | 352 | if (channels > 1) |
5234 | fschmid | 353 | { |
11551 | jghali | 354 | bytes[pending++] = *imageData++; // magenta |
355 | bytes[pending++] = *imageData++; // yellow |
||
356 | bytes[pending++] = *imageData++; // green |
||
357 | } |
||
358 | if (pending >= 1500) |
||
359 | { |
||
360 | writeSuccess &= flateEncode.writeData((const char* ) bytes, pending); |
||
11107 | jghali | 361 | pending = 0; |
5234 | fschmid | 362 | } |
363 | } |
||
11551 | jghali | 364 | // To close the stream |
365 | if (pending > 0) |
||
366 | writeSuccess &= flateEncode.writeData((const char* ) bytes, pending); |
||
367 | writeSuccess &= flateEncode.closeFilter(); |
||
368 | return writeSuccess; |
||
369 | } |
||
11107 | jghali | 370 | |
11551 | jghali | 371 | void PSLib::WriteASCII85Bytes(const QByteArray& array) |
372 | { |
||
373 | WriteASCII85Bytes((const unsigned char*) array.data(), array.size()); |
||
5234 | fschmid | 374 | } |
375 | |||
11551 | jghali | 376 | void PSLib::WriteASCII85Bytes(const unsigned char* array, int length) |
377 | { |
||
378 | ScASCII85EncodeFilter filter(&spoolStream); |
||
379 | filter.openFilter(); |
||
380 | filter.writeData((const char*) array, length); |
||
381 | filter.closeFilter(); |
||
382 | } |
||
383 | |||
3136 | fschmid | 384 | QString PSLib::ToStr(double c) |
385 | { |
||
386 | QString cc; |
||
387 | return cc.setNum(c); |
||
388 | } |
||
389 | |||
390 | QString PSLib::IToStr(int c) |
||
391 | { |
||
392 | QString cc; |
||
393 | return cc.setNum(c); |
||
394 | } |
||
395 | |||
11750 | jghali | 396 | QString PSLib::MatrixToStr(double m11, double m12, double m21, double m22, double x, double y) |
397 | { |
||
398 | QString cc("[%1 %2 %3 %4 %5 %6]"); |
||
399 | return cc.arg(m11).arg(m12).arg(m21).arg(m22).arg(x).arg(y); |
||
400 | } |
||
401 | |||
3136 | fschmid | 402 | void PSLib::PS_set_Info(QString art, QString was) |
403 | { |
||
404 | if (art == "Author") |
||
405 | User = was; |
||
406 | if (art == "Creator") |
||
407 | Creator = was; |
||
408 | if (art == "Title") |
||
409 | Titel = was; |
||
410 | } |
||
411 | |||
412 | bool PSLib::PS_set_file(QString fn) |
||
413 | { |
||
10553 | fschmid | 414 | Spool.setFileName(fn); |
9642 | avox | 415 | if (Spool.exists()) |
416 | Spool.remove(); |
||
8501 | cbradney | 417 | bool ret = Spool.open(QIODevice::WriteOnly); |
6388 | fschmid | 418 | spoolStream.setDevice(&Spool); |
419 | return ret; |
||
3136 | fschmid | 420 | } |
421 | |||
17401 | jghali | 422 | bool PSLib::PS_begin_doc(ScribusDoc *doc, double x, double y, double width, double height, int numpage, bool doDev, bool sep, bool farb, bool ic, bool gcr) |
3136 | fschmid | 423 | { |
6388 | fschmid | 424 | m_Doc = doc; |
11280 | jghali | 425 | PutStream(Header); |
426 | PutStream("%%For: " + User + "\n"); |
||
427 | PutStream("%%Title: " + Titel + "\n"); |
||
428 | PutStream("%%Creator: " + Creator + "\n"); |
||
429 | PutStream("%%Pages: " + IToStr(numpage) + "\n"); |
||
17401 | jghali | 430 | if(width < height || !psExport) |
15548 | fschmid | 431 | { |
17401 | jghali | 432 | BBox = "%%BoundingBox: " + IToStr(qRound(x)) + " " + IToStr(qRound(y)) + " " + IToStr(qRound(width)) + " " + IToStr(qRound(height)) + "\n"; |
433 | BBoxH = "%%HiResBoundingBox: " + ToStr(x) + " " + ToStr(y) + " " + ToStr(width) + " " + ToStr(height) + "\n"; |
||
15548 | fschmid | 434 | } |
435 | else |
||
14959 | fschmid | 436 | { |
437 | |||
17401 | jghali | 438 | BBox = "%%BoundingBox: " + IToStr(qRound(x)) + " " + IToStr(qRound(y)) + " " + IToStr(qRound(height)) + " " + IToStr(qRound(width)) + "\n"; |
439 | BBoxH = "%%HiResBoundingBox: " + ToStr(x) + " " + ToStr(y) + " " + ToStr(height) + " " + ToStr(width) + "\n"; |
||
15548 | fschmid | 440 | } |
8447 | fschmid | 441 | // if (!Art) |
442 | // { |
||
11280 | jghali | 443 | PutStream(BBox); |
444 | PutStream(BBoxH); |
||
8447 | fschmid | 445 | // } |
6748 | fschmid | 446 | if (!FNamen.isEmpty()) |
11280 | jghali | 447 | PutStream("%%DocumentCustomColors: "+FNamen); |
6748 | fschmid | 448 | if (!Farben.isEmpty()) |
11280 | jghali | 449 | PutStream("%%CMYKCustomColor: "+Farben); |
450 | PutStream("%%LanguageLevel: 3\n"); |
||
451 | PutStream("%%EndComments\n"); |
||
452 | PutStream(Prolog); |
||
453 | PutStream("%%BeginSetup\n"); |
||
12589 | fschmid | 454 | if (isPDF) |
455 | PutStream("/pdfmark where {pop} {userdict /pdfmark /cleartomark load put} ifelse\n"); |
||
3136 | fschmid | 456 | if (!FontDesc.isEmpty()) |
11280 | jghali | 457 | PutStream(FontDesc); |
3136 | fschmid | 458 | if ((!colorDesc.isEmpty()) && (!sep)) |
11280 | jghali | 459 | PutStream(colorDesc); |
460 | // PutStream("Scribusdict begin\n"); |
||
461 | PutStream(Fonts); |
||
3136 | fschmid | 462 | if (GraySc) |
11280 | jghali | 463 | PutStream(GrayCalc); |
13932 | fschmid | 464 | Optimization optim = optimization; |
465 | optimization = OptimizeSize; |
||
16052 | fschmid | 466 | QStringList patterns = m_Doc->getPatternDependencyList(m_Doc->getUsedPatterns()); |
8575 | jghali | 467 | for (int c = 0; c < patterns.count(); ++c) |
6388 | fschmid | 468 | { |
6400 | fschmid | 469 | ScPattern pa = m_Doc->docPatterns[patterns[c]]; |
9856 | fschmid | 470 | for (int em = 0; em < pa.items.count(); ++em) |
6388 | fschmid | 471 | { |
472 | PageItem* item = pa.items.at(em); |
||
13097 | subik | 473 | if ((item->asImageFrame()) && (item->PictureIsAvailable) && (!item->Pfile.isEmpty()) && (item->printEnabled()) && (!sep) && (farb)) |
11060 | jghali | 474 | { |
475 | if (!PS_ImageData(item, item->Pfile, item->itemName(), item->IProfile, item->UseEmbedded, ic)) |
||
476 | return false; |
||
477 | } |
||
6388 | fschmid | 478 | } |
13899 | jghali | 479 | uint patHash = qHash(patterns[c]); |
480 | PutStream("/Pattern"+QString::number(patHash)+" 8 dict def\n"); |
||
481 | PutStream("Pattern"+QString::number(patHash)+" begin\n"); |
||
11280 | jghali | 482 | PutStream("/PatternType 1 def\n"); |
483 | PutStream("/PaintType 1 def\n"); |
||
484 | PutStream("/TilingType 1 def\n"); |
||
485 | PutStream("/BBox [ 0 0 "+ToStr(pa.width)+" "+ToStr(pa.height)+"] def\n"); |
||
486 | PutStream("/XStep "+ToStr(pa.width)+" def\n"); |
||
487 | PutStream("/YStep "+ToStr(pa.height)+" def\n"); |
||
488 | PutStream("/PaintProc {\n"); |
||
6388 | fschmid | 489 | QIODevice *spStream = spoolStream.device(); |
490 | QByteArray buf; |
||
8619 | subik | 491 | // Qt4 QBuffer b(buf); |
492 | QBuffer b(&buf); |
||
8501 | cbradney | 493 | b.open( QIODevice::WriteOnly ); |
6388 | fschmid | 494 | spoolStream.setDevice(&b); |
17018 | fschmid | 495 | // PS_translate(pa.items.at(0)->gXpos, -pa.items.at(0)->gYpos); |
9856 | fschmid | 496 | for (int em = 0; em < pa.items.count(); ++em) |
6388 | fschmid | 497 | { |
498 | PageItem* item = pa.items.at(em); |
||
11287 | fschmid | 499 | PutStream("{\n"); |
6388 | fschmid | 500 | PS_save(); |
9111 | fschmid | 501 | PS_translate(item->gXpos, pa.height - item->gYpos); |
6388 | fschmid | 502 | ProcessItem(m_Doc, m_Doc->Pages->at(0), item, 0, sep, farb, ic, gcr, false, true, true); |
503 | PS_restore(); |
||
11287 | fschmid | 504 | PutStream("} exec\n"); |
6388 | fschmid | 505 | } |
506 | spoolStream.setDevice(spStream); |
||
11280 | jghali | 507 | PutStream(buf); |
508 | PutStream("} def\n"); |
||
509 | PutStream("end\n"); |
||
6388 | fschmid | 510 | } |
13932 | fschmid | 511 | optimization = optim; |
11280 | jghali | 512 | // PutStream("end\n"); |
513 | // PutStream("%%EndSetup\n"); |
||
3136 | fschmid | 514 | Prolog = ""; |
515 | FontDesc = ""; |
||
11060 | jghali | 516 | return true; |
3136 | fschmid | 517 | } |
518 | |||
519 | QString PSLib::PSEncode(QString in) |
||
520 | { |
||
3622 | avox | 521 | static QRegExp badchars("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"); |
3136 | fschmid | 522 | QString tmp = ""; |
10394 | cbradney | 523 | tmp = in.simplified().replace( badchars, "_" ); |
3136 | fschmid | 524 | return tmp; |
525 | } |
||
526 | |||
527 | void PSLib::PS_TemplateStart(QString Name) |
||
528 | { |
||
11280 | jghali | 529 | PutStream("/"+PSEncode(Name)+"\n{\n"); |
3136 | fschmid | 530 | } |
531 | |||
532 | void PSLib::PS_UseTemplate(QString Name) |
||
533 | { |
||
11280 | jghali | 534 | PutStream(PSEncode(Name)+"\n"); |
3136 | fschmid | 535 | } |
536 | |||
537 | void PSLib::PS_TemplateEnd() |
||
538 | { |
||
11280 | jghali | 539 | PutStream("} bind def\n"); |
3136 | fschmid | 540 | } |
541 | |||
16729 | fschmid | 542 | void PSLib::PS_begin_page(ScPage* pg, MarginStruct* Ma, bool Clipping) |
3136 | fschmid | 543 | { |
6954 | fschmid | 544 | double bleedRight = 0.0; |
545 | double bleedLeft = 0.0; |
||
546 | double markOffs = 0.0; |
||
547 | if ((Options.cropMarks) || (Options.bleedMarks) || (Options.registrationMarks) || (Options.colorMarks)) |
||
17401 | jghali | 548 | markOffs = Options.markLength + Options.markOffset; |
549 | if ((Options.registrationMarks) || (Options.colorMarks)) |
||
550 | markOffs = qMax(markOffs, Options.markOffset + 20.0); |
||
13816 | jghali | 551 | GetBleeds(pg, bleedLeft, bleedRight); |
6954 | fschmid | 552 | double maxBoxX = pg->width()+bleedLeft+bleedRight+markOffs*2.0; |
7225 | cbradney | 553 | double maxBoxY = pg->height()+Options.bleeds.Bottom+Options.bleeds.Top+markOffs*2.0; |
3136 | fschmid | 554 | Seiten++; |
11280 | jghali | 555 | PutStream("%%Page: " + IToStr(Seiten) + " " + IToStr(Seiten) + "\n"); |
556 | PutStream("%%PageOrientation: "); |
||
6748 | fschmid | 557 | // when creating EPS files determine the orientation from the bounding box |
15548 | fschmid | 558 | if (!psExport) |
6748 | fschmid | 559 | { |
560 | if ((pg->width() - Ma->Left - Ma->Right) <= (pg->height() - Ma->Bottom - Ma->Top)) |
||
11280 | jghali | 561 | PutStream("Portrait\n"); |
6748 | fschmid | 562 | else |
11280 | jghali | 563 | PutStream("Landscape\n"); |
6748 | fschmid | 564 | } |
565 | else |
||
566 | { |
||
13731 | cbradney | 567 | if (pg->orientation() == 0) |
14959 | fschmid | 568 | { |
11280 | jghali | 569 | PutStream("Portrait\n"); |
14959 | fschmid | 570 | PutStream("%%PageBoundingBox: 0 0 "+IToStr(qRound(maxBoxX))+" "+IToStr(qRound(maxBoxY))+"\n"); |
571 | PutStream("%%PageCropBox: "+ToStr(bleedLeft+markOffs)+" "+ToStr(Options.bleeds.Bottom+markOffs)+" "+ToStr(maxBoxX-bleedRight-markOffs*2.0)+" "+ToStr(maxBoxY-Options.bleeds.Top-markOffs*2.0)+"\n"); |
||
572 | } |
||
6748 | fschmid | 573 | else |
14959 | fschmid | 574 | { |
11280 | jghali | 575 | PutStream("Landscape\n"); |
14959 | fschmid | 576 | PutStream("%%PageBoundingBox: 0 0 "+IToStr(qRound(maxBoxY))+" "+IToStr(qRound(maxBoxX))+"\n"); |
577 | PutStream("%%PageCropBox: "+ToStr(bleedLeft+markOffs)+" "+ToStr(Options.bleeds.Bottom+markOffs)+" "+ToStr(maxBoxY-Options.bleeds.Top-markOffs*2.0)+" "+ToStr(maxBoxX-bleedRight-markOffs*2.0)+"\n"); |
||
578 | } |
||
6748 | fschmid | 579 | } |
11280 | jghali | 580 | PutStream("Scribusdict begin\n"); |
15548 | fschmid | 581 | if ((psExport) && (Options.setDevParam)) |
6954 | fschmid | 582 | { |
11280 | jghali | 583 | PutStream("<< /PageSize [ "+ToStr(maxBoxX)+" "+ToStr(maxBoxY)+" ]\n"); |
584 | PutStream(">> setpagedevice\n"); |
||
6954 | fschmid | 585 | } |
13709 | jghali | 586 | PutStream("save\n"); |
15548 | fschmid | 587 | if (pg->orientation() == 1 && psExport) |
14959 | fschmid | 588 | PutStream("90 rotate 0 "+IToStr(qRound(maxBoxY))+" neg translate\n"); |
13709 | jghali | 589 | PutStream("/DeviceCMYK setcolorspace\n"); |
11280 | jghali | 590 | PutStream(ToStr(bleedLeft+markOffs)+" "+ToStr(Options.bleeds.Bottom+markOffs)+" tr\n"); |
6954 | fschmid | 591 | ActPage = pg; |
592 | if (Clipping) |
||
593 | { |
||
594 | PDev = ToStr(Ma->Left) + " " + ToStr(Ma->Bottom) + " m\n"; |
||
595 | PDev += ToStr(pg->width() - Ma->Right) + " " + ToStr(Ma->Bottom) + " li\n"; |
||
596 | PDev += ToStr(pg->width() - Ma->Right) + " " + ToStr(pg->height() - Ma->Top) + " li\n"; |
||
597 | PDev += ToStr(Ma->Left) + " " + ToStr(pg->height() - Ma->Top) + " li cl clip newpath\n"; |
||
12899 | fschmid | 598 | PutStream(PDev); |
6954 | fschmid | 599 | } |
3136 | fschmid | 600 | } |
601 | |||
602 | void PSLib::PS_end_page() |
||
603 | { |
||
11280 | jghali | 604 | PutStream("%%PageTrailer\nrestore\n"); |
6954 | fschmid | 605 | double markOffs = 0.0; |
606 | if ((Options.cropMarks) || (Options.bleedMarks) || (Options.registrationMarks) || (Options.colorMarks)) |
||
17401 | jghali | 607 | markOffs = Options.markLength + Options.markOffset; |
608 | if ((Options.registrationMarks) || (Options.colorMarks)) |
||
609 | markOffs = qMax(markOffs, Options.markOffset + 20.0); |
||
610 | double markDelta = markOffs - (Options.markLength + Options.markOffset); |
||
13816 | jghali | 611 | double bleedRight, bleedLeft; |
612 | GetBleeds(ActPage, bleedLeft, bleedRight); |
||
6954 | fschmid | 613 | double maxBoxX = ActPage->width()+bleedLeft+bleedRight+markOffs*2.0; |
7225 | cbradney | 614 | double maxBoxY = ActPage->height()+Options.bleeds.Bottom+Options.bleeds.Top+markOffs*2.0; |
15595 | jghali | 615 | PutStream("gs\n"); |
15603 | jghali | 616 | if(ActPage->orientation() == 1 && psExport) |
15595 | jghali | 617 | PutStream("90 rotate 0 "+IToStr(qRound(maxBoxY))+" neg translate\n"); |
6954 | fschmid | 618 | if ((Options.cropMarks) || (Options.bleedMarks) || (Options.registrationMarks) || (Options.colorMarks)) |
619 | { |
||
11280 | jghali | 620 | PutStream("gs\n"); |
6954 | fschmid | 621 | PS_setlinewidth(0.5); |
11280 | jghali | 622 | PutStream("[] 0 setdash\n"); |
623 | PutStream("0 setlinecap\n"); |
||
624 | PutStream("0 setlinejoin\n"); |
||
625 | PutStream("1 rb\n"); |
||
6954 | fschmid | 626 | if (Options.cropMarks) |
627 | { |
||
628 | // Bottom Left |
||
17401 | jghali | 629 | PutStream(ToStr(markDelta)+" "+ToStr(markOffs+Options.bleeds.Bottom)+" m\n"); |
630 | PutStream(ToStr(markDelta+Options.markLength)+" "+ToStr(markOffs+Options.bleeds.Bottom)+" li\n"); |
||
11280 | jghali | 631 | PutStream("st\n"); |
17401 | jghali | 632 | PutStream(ToStr(markOffs+bleedLeft)+" "+ToStr(markDelta)+" m\n"); |
633 | PutStream(ToStr(markOffs+bleedLeft)+" "+ToStr(markDelta+Options.markLength)+" li\n"); |
||
11280 | jghali | 634 | PutStream("st\n"); |
6954 | fschmid | 635 | // Top Left |
17401 | jghali | 636 | PutStream(ToStr(markDelta)+" "+ToStr(maxBoxY-Options.bleeds.Top-markOffs)+" m\n"); |
637 | PutStream(ToStr(markDelta+Options.markLength)+" "+ToStr(maxBoxY-Options.bleeds.Top-markOffs)+" li\n"); |
||
11280 | jghali | 638 | PutStream("st\n"); |
17401 | jghali | 639 | PutStream(ToStr(markOffs+bleedLeft)+" "+ToStr(maxBoxY-markDelta)+" m\n"); |
640 | PutStream(ToStr(markOffs+bleedLeft)+" "+ToStr(maxBoxY-markDelta-Options.markLength) +" li\n"); |
||
11280 | jghali | 641 | PutStream("st\n"); |
6954 | fschmid | 642 | // Bottom Right |
17401 | jghali | 643 | PutStream(ToStr(maxBoxX-markDelta)+" "+ToStr(markOffs+Options.bleeds.Bottom)+" m\n"); |
644 | PutStream(ToStr(maxBoxX-markDelta-Options.markLength)+" "+ToStr(markOffs+Options.bleeds.Bottom)+" li\n"); |
||
11280 | jghali | 645 | PutStream("st\n"); |
17401 | jghali | 646 | PutStream(ToStr(maxBoxX-bleedRight-markOffs)+" "+ ToStr(markDelta)+" m\n"); |
647 | PutStream(ToStr(maxBoxX-bleedRight-markOffs)+" "+ ToStr(markDelta+Options.markLength) +" li\n"); |
||
11280 | jghali | 648 | PutStream("st\n"); |
6954 | fschmid | 649 | // Top Right |
17401 | jghali | 650 | PutStream(ToStr(maxBoxX-markDelta)+" "+ToStr(maxBoxY-Options.bleeds.Top-markOffs)+" m\n"); |
651 | PutStream(ToStr(maxBoxX-markDelta-Options.markLength)+" "+ToStr(maxBoxY-Options.bleeds.Top-markOffs)+" li\n"); |
||
11280 | jghali | 652 | PutStream("st\n"); |
17401 | jghali | 653 | PutStream(ToStr(maxBoxX-bleedRight-markOffs)+" "+ ToStr(maxBoxY-markDelta)+" m\n"); |
654 | PutStream(ToStr(maxBoxX-bleedRight-markOffs)+" "+ ToStr(maxBoxY-markDelta-Options.markLength) +" li\n"); |
||
11280 | jghali | 655 | PutStream("st\n"); |
6954 | fschmid | 656 | } |
657 | if (Options.bleedMarks) |
||
658 | { |
||
11280 | jghali | 659 | PutStream("gs\n"); |
660 | PutStream("[3 1 1 1] 0 setdash\n"); |
||
6954 | fschmid | 661 | // Bottom Left |
17401 | jghali | 662 | PutStream(ToStr(markDelta)+" "+ToStr(markOffs)+" m\n"); |
663 | PutStream(ToStr(markDelta+Options.markLength)+" "+ToStr(markOffs)+" li\n"); |
||
11280 | jghali | 664 | PutStream("st\n"); |
17401 | jghali | 665 | PutStream(ToStr(markOffs)+" "+ToStr(markDelta)+" m\n"); |
666 | PutStream(ToStr(markOffs)+" "+ToStr(markDelta+Options.markLength)+" li\n"); |
||
11280 | jghali | 667 | PutStream("st\n"); |
6954 | fschmid | 668 | // Top Left |
17401 | jghali | 669 | PutStream(ToStr(markDelta)+" "+ToStr(maxBoxY-markOffs)+" m\n"); |
670 | PutStream(ToStr(markDelta+Options.markLength)+" "+ToStr(maxBoxY-markOffs)+" li\n"); |
||
11280 | jghali | 671 | PutStream("st\n"); |
17401 | jghali | 672 | PutStream(ToStr(markOffs)+" "+ToStr(maxBoxY-markDelta)+" m\n"); |
673 | PutStream(ToStr(markOffs)+" "+ToStr(maxBoxY-markDelta-Options.markLength)+" li\n"); |
||
11280 | jghali | 674 | PutStream("st\n"); |
6954 | fschmid | 675 | // Bottom Right |
17401 | jghali | 676 | PutStream(ToStr(maxBoxX-markDelta)+" "+ToStr(markOffs)+" m\n"); |
677 | PutStream(ToStr(maxBoxX-markDelta-Options.markLength)+" "+ToStr(markOffs)+" li\n"); |
||
11280 | jghali | 678 | PutStream("st\n"); |
17401 | jghali | 679 | PutStream(ToStr(maxBoxX-markOffs)+" "+ToStr(markDelta)+" m\n"); |
680 | PutStream(ToStr(maxBoxX-markOffs)+" "+ToStr(markDelta+Options.markLength)+" li\n"); |
||
11280 | jghali | 681 | PutStream("st\n"); |
6954 | fschmid | 682 | // Top Right |
17401 | jghali | 683 | PutStream(ToStr(maxBoxX-markDelta)+" "+ToStr(maxBoxY-markOffs)+" m\n"); |
684 | PutStream(ToStr(maxBoxX-markDelta-Options.markLength)+" "+ToStr(maxBoxY-markOffs)+" li\n"); |
||
11280 | jghali | 685 | PutStream("st\n"); |
17401 | jghali | 686 | PutStream(ToStr(maxBoxX-markOffs)+" "+ToStr(maxBoxY-markDelta)+" m\n"); |
687 | PutStream(ToStr(maxBoxX-markOffs)+" "+ToStr(maxBoxY-markDelta-Options.markLength)+" li\n"); |
||
11280 | jghali | 688 | PutStream("st\n"); |
689 | PutStream("gr\n"); |
||
6954 | fschmid | 690 | } |
691 | if (Options.registrationMarks) |
||
692 | { |
||
17401 | jghali | 693 | double regDelta = markOffs - Options.markOffset; |
6954 | fschmid | 694 | QString regCross = "0 7 m\n14 7 li\n7 0 m\n7 14 li\n13 7 m\n13 10.31383 10.31383 13 7 13 cu\n3.68629 13 1 10.31383 1 7 cu\n1 3.68629 3.68629 1 7 1 cu\n"; |
695 | regCross += "10.31383 1 13 3.68629 13 7 cu\ncl\n10.5 7 m\n10.5 8.93307 8.93307 10.5 7 10.5 cu\n5.067 10.5 3.5 8.93307 3.5 7 cu\n"; |
||
696 | regCross += "3.5 5.067 5.067 3.5 7 3.5 cu\n8.93307 3.5 10.5 5.067 10.5 7 cu\ncl\nst\n"; |
||
11280 | jghali | 697 | PutStream("gs\n"); |
17401 | jghali | 698 | PutStream(ToStr(maxBoxX / 2.0 - 7.0)+" "+ToStr(regDelta - 17)+" tr\n"); |
11280 | jghali | 699 | PutStream(regCross); |
700 | PutStream("gr\n"); |
||
701 | PutStream("gs\n"); |
||
17401 | jghali | 702 | PutStream(ToStr(regDelta - 17)+" "+ToStr(maxBoxY / 2.0 - 7.0)+" tr\n"); |
11280 | jghali | 703 | PutStream(regCross); |
704 | PutStream("gr\n"); |
||
705 | PutStream("gs\n"); |
||
17401 | jghali | 706 | PutStream(ToStr(maxBoxX / 2.0 - 7.0)+" "+ToStr(maxBoxY - regDelta + 3.0)+" tr\n"); |
11280 | jghali | 707 | PutStream(regCross); |
708 | PutStream("gr\n"); |
||
709 | PutStream("gs\n"); |
||
17401 | jghali | 710 | PutStream(ToStr(maxBoxX - regDelta + 3.0)+" "+ToStr(maxBoxY / 2.0 - 7.0)+" tr\n"); |
11280 | jghali | 711 | PutStream(regCross); |
712 | PutStream("gr\n"); |
||
6954 | fschmid | 713 | } |
714 | if (Options.colorMarks) |
||
715 | { |
||
716 | double startX = markOffs+bleedLeft+6.0; |
||
17401 | jghali | 717 | double startY = maxBoxY - markOffs + Options.markOffset + 2.0; |
11280 | jghali | 718 | PutStream("0 0 0 1 cmyk\n"); |
6954 | fschmid | 719 | double col = 1.0; |
720 | for (int bl = 0; bl < 11; bl++) |
||
721 | { |
||
11280 | jghali | 722 | PutStream("0 0 0 "+ToStr(col)+" cmyk\n"); |
723 | PutStream(ToStr(startX+bl*14.0)+" "+ToStr(startY)+" 14 14 rectfill\n"); |
||
724 | PutStream("0 0 0 1 cmyk\n"); |
||
725 | PutStream(ToStr(startX+bl*14.0)+" "+ToStr(startY)+" 14 14 rectstroke\n"); |
||
6954 | fschmid | 726 | col -= 0.1; |
727 | } |
||
728 | startX = maxBoxX-bleedRight-markOffs-20.0; |
||
11280 | jghali | 729 | PutStream("0 0 0 0.5 cmyk\n"); |
730 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectfill\n"); |
||
731 | PutStream("0 0 0 1 cmyk\n"); |
||
732 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectstroke\n"); |
||
6954 | fschmid | 733 | startX -= 14.0; |
11280 | jghali | 734 | PutStream("0 0 0.5 0 cmyk\n"); |
735 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectfill\n"); |
||
736 | PutStream("0 0 0 1 cmyk\n"); |
||
737 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectstroke\n"); |
||
6954 | fschmid | 738 | startX -= 14.0; |
11280 | jghali | 739 | PutStream("0 0.5 0 0 cmyk\n"); |
740 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectfill\n"); |
||
741 | PutStream("0 0 0 1 cmyk\n"); |
||
742 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectstroke\n"); |
||
6954 | fschmid | 743 | startX -= 14.0; |
11280 | jghali | 744 | PutStream("0.5 0 0 0 cmyk\n"); |
745 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectfill\n"); |
||
746 | PutStream("0 0 0 1 cmyk\n"); |
||
747 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectstroke\n"); |
||
6954 | fschmid | 748 | startX -= 14.0; |
11280 | jghali | 749 | PutStream("1 1 0 0 cmyk\n"); |
750 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectfill\n"); |
||
751 | PutStream("0 0 0 1 cmyk\n"); |
||
752 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectstroke\n"); |
||
6954 | fschmid | 753 | startX -= 14.0; |
11280 | jghali | 754 | PutStream("1 0 1 0 cmyk\n"); |
755 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectfill\n"); |
||
756 | PutStream("0 0 0 1 cmyk\n"); |
||
757 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectstroke\n"); |
||
6954 | fschmid | 758 | startX -= 14.0; |
11280 | jghali | 759 | PutStream("0 1 1 0 cmyk\n"); |
760 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectfill\n"); |
||
761 | PutStream("0 0 0 1 cmyk\n"); |
||
762 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectstroke\n"); |
||
6954 | fschmid | 763 | startX -= 14.0; |
11280 | jghali | 764 | PutStream("0 0 0 1 cmyk\n"); |
765 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectfill\n"); |
||
766 | PutStream("0 0 0 1 cmyk\n"); |
||
767 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectstroke\n"); |
||
6954 | fschmid | 768 | startX -= 14.0; |
11280 | jghali | 769 | PutStream("0 0 1 0 cmyk\n"); |
770 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectfill\n"); |
||
771 | PutStream("0 0 0 1 cmyk\n"); |
||
772 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectstroke\n"); |
||
6954 | fschmid | 773 | startX -= 14.0; |
11280 | jghali | 774 | PutStream("0 1 0 0 cmyk\n"); |
775 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectfill\n"); |
||
776 | PutStream("0 0 0 1 cmyk\n"); |
||
777 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectstroke\n"); |
||
6954 | fschmid | 778 | startX -= 14.0; |
11280 | jghali | 779 | PutStream("1 0 0 0 cmyk\n"); |
780 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectfill\n"); |
||
781 | PutStream("0 0 0 1 cmyk\n"); |
||
782 | PutStream(ToStr(startX)+" "+ToStr(startY)+" 14 14 rectstroke\n"); |
||
6954 | fschmid | 783 | } |
11280 | jghali | 784 | PutStream("gr\n"); |
6954 | fschmid | 785 | } |
15595 | jghali | 786 | PutStream("gr\n"); |
11280 | jghali | 787 | PutStream("sp\n"); |
788 | PutStream("end\n"); |
||
3136 | fschmid | 789 | } |
790 | |||
791 | void PSLib::PS_curve(double x1, double y1, double x2, double y2, double x3, double y3) |
||
792 | { |
||
11280 | jghali | 793 | PutStream(ToStr(x1) + " " + ToStr(y1) + " " + ToStr(x2) + " " + ToStr(y2) + " " + ToStr(x3) + " " + ToStr(y3) + " cu\n"); |
3136 | fschmid | 794 | } |
795 | |||
796 | void PSLib::PS_moveto(double x, double y) |
||
797 | { |
||
11280 | jghali | 798 | PutStream(ToStr(x) + " " + ToStr(y) + " m\n"); |
3136 | fschmid | 799 | } |
800 | |||
801 | void PSLib::PS_lineto(double x, double y) |
||
802 | { |
||
11280 | jghali | 803 | PutStream(ToStr(x) + " " + ToStr(y) + " li\n"); |
3136 | fschmid | 804 | } |
805 | |||
806 | void PSLib::PS_closepath() |
||
807 | { |
||
11280 | jghali | 808 | PutStream("cl\n"); |
3136 | fschmid | 809 | } |
810 | |||
811 | void PSLib::PS_translate(double x, double y) |
||
812 | { |
||
11280 | jghali | 813 | PutStream(ToStr(x) + " " + ToStr(y) + " tr\n"); |
3136 | fschmid | 814 | } |
815 | |||
816 | void PSLib::PS_scale(double x, double y) |
||
817 | { |
||
11280 | jghali | 818 | PutStream(ToStr(x) + " " + ToStr(y) + " sc\n"); |
3136 | fschmid | 819 | } |
820 | |||
821 | void PSLib::PS_rotate(double x) |
||
822 | { |
||
11280 | jghali | 823 | PutStream(ToStr(x) + " ro\n"); |
3136 | fschmid | 824 | } |
825 | |||
826 | void PSLib::PS_clip(bool mu) |
||
827 | { |
||
11280 | jghali | 828 | PutStream( mu ? "eoclip newpath\n" : "clip newpath\n" ); |
3136 | fschmid | 829 | } |
830 | |||
831 | void PSLib::PS_save() |
||
832 | { |
||
11280 | jghali | 833 | PutStream("gs\n"); |
3136 | fschmid | 834 | } |
835 | |||
836 | void PSLib::PS_restore() |
||
837 | { |
||
11280 | jghali | 838 | PutStream("gr\n"); |
3136 | fschmid | 839 | } |
840 | |||
841 | void PSLib::PS_setcmykcolor_fill(double c, double m, double y, double k) |
||
842 | { |
||
843 | FillColor = ToStr(c) + " " + ToStr(m) + " " + ToStr(y) + " " + ToStr(k); |
||
844 | } |
||
845 | |||
846 | void PSLib::PS_setcmykcolor_dummy() |
||
847 | { |
||
11280 | jghali | 848 | PutStream("0 0 0 0 cmyk\n"); |
3136 | fschmid | 849 | } |
850 | |||
851 | void PSLib::PS_setcmykcolor_stroke(double c, double m, double y, double k) |
||
852 | { |
||
853 | StrokeColor = ToStr(c) + " " + ToStr(m) + " " + ToStr(y) + " " + ToStr(k); |
||
854 | } |
||
855 | |||
856 | void PSLib::PS_setlinewidth(double w) |
||
857 | { |
||
11280 | jghali | 858 | PutStream(ToStr(w) + " sw\n"); |
3136 | fschmid | 859 | LineW = w; |
860 | } |
||
861 | |||
12055 | jghali | 862 | void PSLib::PS_setdash(Qt::PenStyle st, double offset, QVector<double> dash) |
3136 | fschmid | 863 | { |
864 | if (dash.count() != 0) |
||
865 | { |
||
11280 | jghali | 866 | PutStream("[ "); |
12055 | jghali | 867 | QVector<double>::iterator it; |
3136 | fschmid | 868 | for ( it = dash.begin(); it != dash.end(); ++it ) |
869 | { |
||
11280 | jghali | 870 | PutStream(ToStr(*it)+" "); |
3136 | fschmid | 871 | } |
11280 | jghali | 872 | PutStream("] "+ToStr(offset)+" setdash\n"); |
3136 | fschmid | 873 | } |
874 | else |
||
11280 | jghali | 875 | PutStream("["+getDashString(st, LineW)+"] 0 setdash\n"); |
3136 | fschmid | 876 | } |
6954 | fschmid | 877 | |
3136 | fschmid | 878 | void PSLib::PS_setcapjoin(Qt::PenCapStyle ca, Qt::PenJoinStyle jo) |
879 | { |
||
880 | switch (ca) |
||
881 | { |
||
882 | case Qt::FlatCap: |
||
11280 | jghali | 883 | PutStream("0 setlinecap\n"); |
3136 | fschmid | 884 | break; |
885 | case Qt::SquareCap: |
||
11280 | jghali | 886 | PutStream("2 setlinecap\n"); |
3136 | fschmid | 887 | break; |
888 | case Qt::RoundCap: |
||
11280 | jghali | 889 | PutStream("1 setlinecap\n"); |
3136 | fschmid | 890 | break; |
891 | default: |
||
11280 | jghali | 892 | PutStream("0 setlinecap\n"); |
3136 | fschmid | 893 | break; |
894 | } |
||
895 | switch (jo) |
||
896 | { |
||
897 | case Qt::MiterJoin: |
||
11280 | jghali | 898 | PutStream("0 setlinejoin\n"); |
3136 | fschmid | 899 | break; |
900 | case Qt::BevelJoin: |
||
11280 | jghali | 901 | PutStream("2 setlinejoin\n"); |
3136 | fschmid | 902 | break; |
903 | case Qt::RoundJoin: |
||
11280 | jghali | 904 | PutStream("1 setlinejoin\n"); |
3136 | fschmid | 905 | break; |
906 | default: |
||
11280 | jghali | 907 | PutStream("0 setlinejoin\n"); |
3136 | fschmid | 908 | break; |
909 | } |
||
910 | } |
||
911 | |||
912 | void PSLib::PS_selectfont(QString f, double s) |
||
913 | { |
||
11280 | jghali | 914 | PutStream(UsedFonts[f] + " " + ToStr(s) + " se\n"); |
3136 | fschmid | 915 | } |
916 | |||
917 | void PSLib::PS_fill() |
||
918 | { |
||
4477 | fschmid | 919 | if (fillRule) |
11280 | jghali | 920 | PutStream(FillColor + " cmyk eofill\n"); |
4477 | fschmid | 921 | else |
11280 | jghali | 922 | PutStream(FillColor + " cmyk fill\n"); |
3136 | fschmid | 923 | } |
924 | |||
9920 | fschmid | 925 | void PSLib::PS_fillspot(QString color, double shade) |
3136 | fschmid | 926 | { |
4477 | fschmid | 927 | if (fillRule) |
11280 | jghali | 928 | PutStream(ToStr(shade / 100.0)+" "+spotMap[color]+" eofill\n"); |
4477 | fschmid | 929 | else |
11280 | jghali | 930 | PutStream(ToStr(shade / 100.0)+" "+spotMap[color]+" fill\n"); |
3136 | fschmid | 931 | } |
932 | |||
9920 | fschmid | 933 | void PSLib::PS_strokespot(QString color, double shade) |
3136 | fschmid | 934 | { |
11280 | jghali | 935 | PutStream(ToStr(shade / 100.0)+" "+spotMap[color]+" st\n"); |
3136 | fschmid | 936 | } |
937 | |||
938 | void PSLib::PS_stroke() |
||
939 | { |
||
11280 | jghali | 940 | PutStream(StrokeColor + " cmyk st\n"); |
3136 | fschmid | 941 | } |
942 | |||
943 | void PSLib::PS_fill_stroke() |
||
944 | { |
||
945 | PS_save(); |
||
946 | PS_fill(); |
||
947 | PS_restore(); |
||
948 | PS_stroke(); |
||
949 | } |
||
950 | |||
951 | void PSLib::PS_newpath() |
||
952 | { |
||
11280 | jghali | 953 | PutStream("newpath\n"); |
3136 | fschmid | 954 | } |
955 | |||
14324 | jghali | 956 | void PSLib::PS_show_xyG(QString font, uint glyph, double x, double y, QString colorName, double shade) |
3136 | fschmid | 957 | { |
14324 | jghali | 958 | QString glyphName; |
959 | glyphName = GlyphsOfFont[font].contains(glyph) ? GlyphsOfFont[font][glyph].second : QString(".notdef"); |
||
960 | |||
961 | QString colorString; |
||
962 | ScColor& color(colorsToUse[colorName]); |
||
963 | bool spot = false; |
||
964 | if (((color.isSpotColor()) || (color.isRegistrationColor())) && (useSpotColors)) |
||
965 | { |
||
966 | if (!DoSep) |
||
967 | { |
||
968 | colorString = ToStr(shade / 100.0)+" "+spotMap[colorName]; |
||
969 | spot = true; |
||
970 | } |
||
971 | else if ((colorName == currentSpot) || (color.isRegistrationColor())) |
||
972 | colorString = "0 0 0 "+ToStr(shade / 100.0); |
||
973 | else |
||
974 | colorString = "0 0 0 0"; |
||
975 | } |
||
976 | else |
||
977 | { |
||
978 | int c, m, y, k; |
||
979 | SetColor(color, shade, &c, &m, &y, &k, Options.doGCR); |
||
980 | if (!DoSep || (Plate == 0 || Plate == 1 || Plate == 2 || Plate == 3)) |
||
981 | colorString = ToStr(c / 255.0) + " " + ToStr(m / 255.0) + " " + ToStr(y / 255.0) + " " + ToStr(k / 255.0); |
||
982 | else |
||
983 | colorString = "0 0 0 0"; |
||
984 | } |
||
3555 | fschmid | 985 | if (spot) |
14324 | jghali | 986 | { |
987 | PutStream(colorString + "\n"); |
||
988 | PutStream("/"+glyphName+" "+ToStr(x)+" "+ToStr(y)+" shgsp\n"); |
||
989 | } |
||
3555 | fschmid | 990 | else |
14324 | jghali | 991 | PutStream("/"+glyphName+" "+ToStr(x)+" "+ToStr(y)+" "+colorString+" shg\n"); |
3136 | fschmid | 992 | } |
993 | |||
994 | void PSLib::PS_show(double x, double y) |
||
995 | { |
||
996 | PS_moveto(x, y); |
||
11280 | jghali | 997 | PutStream("/hyphen glyphshow\n"); |
3136 | fschmid | 998 | } |
999 | |||
1000 | void PSLib::PS_showSub(uint chr, QString font, double size, bool stroke) |
||
1001 | { |
||
11280 | jghali | 1002 | PutStream(" (G"+IToStr(chr)+") "+font+" "+ToStr(size / 10.0)+" "); |
1003 | PutStream(stroke ? "shgs\n" : "shgf\n"); |
||
3136 | fschmid | 1004 | } |
1005 | |||
11060 | jghali | 1006 | bool PSLib::PS_ImageData(PageItem *c, QString fn, QString Name, QString Prof, bool UseEmbedded, bool UseProf) |
3136 | fschmid | 1007 | { |
1008 | bool dummy; |
||
9535 | fschmid | 1009 | QByteArray tmp; |
3136 | fschmid | 1010 | QFileInfo fi = QFileInfo(fn); |
10553 | fschmid | 1011 | QString ext = fi.suffix().toLower(); |
6808 | fschmid | 1012 | if (ext.isEmpty()) |
1013 | ext = getImageType(fn); |
||
11331 | jghali | 1014 | if (extensionIndicatesEPS(ext) && (c->pixm.imgInfo.type != ImageType7)) |
3136 | fschmid | 1015 | { |
5234 | fschmid | 1016 | if (loadRawText(fn, tmp)) |
3136 | fschmid | 1017 | { |
11280 | jghali | 1018 | PutStream("currentfile 1 (%ENDEPSDATA) /SubFileDecode filter /ReusableStreamDecode filter\n"); |
1019 | PutStream("%%BeginDocument: " + fi.fileName() + "\n"); |
||
16956 | jghali | 1020 | if (getDouble(tmp.mid(0, 4), true) == 0xC5D0D3C6) |
3136 | fschmid | 1021 | { |
5234 | fschmid | 1022 | char* data = tmp.data(); |
16956 | jghali | 1023 | uint startPos = getDouble(tmp.mid(4, 4), false); |
1024 | uint length = getDouble(tmp.mid(8, 4), false); |
||
11280 | jghali | 1025 | PutStream(data+startPos, length, false); |
3136 | fschmid | 1026 | } |
1027 | else |
||
11280 | jghali | 1028 | PutStream(tmp, false); |
1029 | PutStream("\n%ENDEPSDATA\n"); |
||
1030 | PutStream("%%EndDocument\n"); |
||
1031 | PutStream("/"+PSEncode(Name)+"Bild exch def\n"); |
||
11060 | jghali | 1032 | return true; |
3136 | fschmid | 1033 | } |
11060 | jghali | 1034 | return false; |
3136 | fschmid | 1035 | } |
1036 | ScImage image; |
||
5234 | fschmid | 1037 | QByteArray imgArray; |
3136 | fschmid | 1038 | image.imgInfo.valid = false; |
1039 | image.imgInfo.clipPath = ""; |
||
1040 | image.imgInfo.PDSpathData.clear(); |
||
1041 | image.imgInfo.layerInfo.clear(); |
||
1042 | image.imgInfo.RequestProps = c->pixm.imgInfo.RequestProps; |
||
1043 | image.imgInfo.isRequest = c->pixm.imgInfo.isRequest; |
||
5959 | jghali | 1044 | CMSettings cms(c->doc(), Prof, c->IRender); |
14467 | jghali | 1045 | cms.allowColorManagement(UseProf); |
1046 | cms.setUseEmbeddedProfile(UseEmbedded); |
||
1047 | if (!image.loadPicture(fn, c->pixm.imgInfo.actualPageNumber, cms, ScImage::CMYKData, 300, &dummy)) |
||
11060 | jghali | 1048 | { |
1049 | PS_Error_ImageLoadFailure(fn); |
||
1050 | return false; |
||
1051 | } |
||
3136 | fschmid | 1052 | image.applyEffect(c->effectsInUse, colorsToUse, true); |
11389 | jghali | 1053 | QByteArray maskArray; |
13932 | fschmid | 1054 | if (c->pixm.imgInfo.type != ImageType7) |
11389 | jghali | 1055 | { |
13932 | fschmid | 1056 | bool alphaLoaded = image.getAlpha(fn, c->pixm.imgInfo.actualPageNumber, maskArray, false, true, 300); |
1057 | if (!alphaLoaded) |
||
1058 | { |
||
1059 | PS_Error_MaskLoadFailure(fn); |
||
1060 | return false; |
||
1061 | } |
||
11389 | jghali | 1062 | } |
11331 | jghali | 1063 | if ((maskArray.size() > 0) && (c->pixm.imgInfo.type != ImageType7)) |
3136 | fschmid | 1064 | { |
11551 | jghali | 1065 | PutStream("currentfile /ASCII85Decode filter /FlateDecode filter /ReusableStreamDecode filter\n"); |
11568 | jghali | 1066 | if (!PutImageToStream(image, maskArray, -1)) |
3136 | fschmid | 1067 | { |
11551 | jghali | 1068 | PS_Error_ImageDataWriteFailure(); |
1069 | return false; |
||
3136 | fschmid | 1070 | } |
11551 | jghali | 1071 | PutStream("/"+PSEncode(Name)+"Bild exch def\n"); |
1072 | } |
||
1073 | else |
||
1074 | { |
||
1075 | PutStream("currentfile /ASCII85Decode filter /FlateDecode filter /ReusableStreamDecode filter\n"); |
||
11568 | jghali | 1076 | if (!PutImageToStream(image, -1)) |
11317 | jghali | 1077 | { |
11551 | jghali | 1078 | PS_Error_ImageDataWriteFailure(); |
1079 | return false; |
||
11317 | jghali | 1080 | } |
11551 | jghali | 1081 | PutStream("/"+PSEncode(Name)+"Bild exch def\n"); |
1082 | imgArray.resize(0); |
||
3136 | fschmid | 1083 | } |
11060 | jghali | 1084 | return true; |
3136 | fschmid | 1085 | } |
1086 | |||
11060 | jghali | 1087 | bool PSLib::PS_image(PageItem *c, double x, double y, QString fn, double scalex, double scaley, QString Prof, bool UseEmbedded, bool UseProf, QString Name) |
3136 | fschmid | 1088 | { |
1089 | bool dummy; |
||
9535 | fschmid | 1090 | QByteArray tmp; |
3136 | fschmid | 1091 | QFileInfo fi = QFileInfo(fn); |
10553 | fschmid | 1092 | QString ext = fi.suffix().toLower(); |
6808 | fschmid | 1093 | if (ext.isEmpty()) |
1094 | ext = getImageType(fn); |
||
11331 | jghali | 1095 | if (extensionIndicatesEPS(ext) && (c->pixm.imgInfo.type != ImageType7)) |
3136 | fschmid | 1096 | { |
5234 | fschmid | 1097 | if (loadRawText(fn, tmp)) |
3136 | fschmid | 1098 | { |
11280 | jghali | 1099 | PutStream("bEPS\n"); |
13955 | cbradney | 1100 | PutStream(ToStr(PrefsManager::instance()->appPrefs.extToolPrefs.gs_Resolution / 72.0 * scalex) + " " + ToStr(PrefsManager::instance()->appPrefs.extToolPrefs.gs_Resolution / 72.0 * scaley) + " sc\n"); |
11280 | jghali | 1101 | PutStream(ToStr(-c->BBoxX+x * scalex) + " " + ToStr(y * scalex) + " tr\n"); |
14861 | fschmid | 1102 | int h = c->pixm.height(); |
1103 | PutStream("0 " + ToStr(h*scaley) + " tr\n"); |
||
1104 | PutStream(ToStr(-c->imageRotation()) + " ro\n"); |
||
1105 | PutStream("0 " + ToStr(-h*scaley) + " tr\n"); |
||
3136 | fschmid | 1106 | if (!Name.isEmpty()) |
1107 | { |
||
11280 | jghali | 1108 | PutStream(PSEncode(Name)+"Bild cvx exec\n"); |
1109 | PutStream(PSEncode(Name)+"Bild resetfile\n"); |
||
3136 | fschmid | 1110 | } |
1111 | else |
||
1112 | { |
||
11280 | jghali | 1113 | PutStream("%%BeginDocument: " + fi.fileName() + "\n"); |
16956 | jghali | 1114 | if (getDouble(tmp.mid(0, 4), true) == 0xC5D0D3C6) |
3136 | fschmid | 1115 | { |
5234 | fschmid | 1116 | char* data = tmp.data(); |
3136 | fschmid | 1117 | uint startPos = getDouble(tmp.mid(4, 4), false); |
1118 | uint length = getDouble(tmp.mid(8, 4), false); |
||
11280 | jghali | 1119 | PutStream(data+startPos, length, false); |
3136 | fschmid | 1120 | } |
1121 | else |
||
11280 | jghali | 1122 | PutStream(tmp); |
1123 | PutStream("\n%%EndDocument\n"); |
||
3136 | fschmid | 1124 | } |
11280 | jghali | 1125 | PutStream("eEPS\n"); |
11060 | jghali | 1126 | return true; |
3136 | fschmid | 1127 | } |
11060 | jghali | 1128 | return false; |
3136 | fschmid | 1129 | } |
1130 | else |
||
1131 | { |
||
1132 | ScImage image; |
||
5234 | fschmid | 1133 | QByteArray imgArray; |
3136 | fschmid | 1134 | image.imgInfo.valid = false; |
1135 | image.imgInfo.clipPath = ""; |
||
1136 | image.imgInfo.PDSpathData.clear(); |
||
1137 | image.imgInfo.layerInfo.clear(); |
||
1138 | image.imgInfo.RequestProps = c->pixm.imgInfo.RequestProps; |
||
1139 | image.imgInfo.isRequest = c->pixm.imgInfo.isRequest; |
||
5959 | jghali | 1140 | CMSettings cms(c->doc(), Prof, c->IRender); |
14467 | jghali | 1141 | cms.allowColorManagement(UseProf); |
1142 | cms.setUseEmbeddedProfile(UseEmbedded); |
||
12698 | fschmid | 1143 | int resolution = 300; |
1144 | if (c->asLatexFrame()) |
||
1145 | resolution = c->asLatexFrame()->realDpi(); |
||
1146 | else if (c->pixm.imgInfo.type == ImageType7) |
||
1147 | resolution = 72; |
||
1148 | // int resolution = (c->pixm.imgInfo.type == ImageType7) ? 72 : 300; |
||
14467 | jghali | 1149 | if ( !image.loadPicture(fn, c->pixm.imgInfo.actualPageNumber, cms, ScImage::CMYKData, resolution, &dummy) ) |
11060 | jghali | 1150 | { |
1151 | PS_Error_ImageLoadFailure(fn); |
||
1152 | return false; |
||
1153 | } |
||
3136 | fschmid | 1154 | image.applyEffect(c->effectsInUse, colorsToUse, true); |
1155 | int w = image.width(); |
||
1156 | int h = image.height(); |
||
11917 | fschmid | 1157 | PutStream(ToStr(x*scalex) + " " + ToStr(y*scaley) + " tr\n"); |
14861 | fschmid | 1158 | PutStream("0 " + ToStr(h*scaley) + " tr\n"); |
1159 | PutStream(ToStr(-c->imageRotation()) + " ro\n"); |
||
1160 | PutStream("0 " + ToStr(-h*scaley) + " tr\n"); |
||
12698 | fschmid | 1161 | if ((extensionIndicatesPDF(ext)) && (!c->asLatexFrame())) |
3136 | fschmid | 1162 | { |
13955 | cbradney | 1163 | scalex *= PrefsManager::instance()->appPrefs.extToolPrefs.gs_Resolution / 300.0; |
1164 | scaley *= PrefsManager::instance()->appPrefs.extToolPrefs.gs_Resolution / 300.0; |
||
3136 | fschmid | 1165 | } |
11917 | fschmid | 1166 | // PutStream(ToStr(x*scalex) + " " + ToStr(y*scaley) + " tr\n"); |
1167 | PutStream(ToStr(qRound(scalex*w)) + " " + ToStr(qRound(scaley*h)) + " sc\n"); |
||
1168 | PutStream(((!DoSep) && (!GraySc)) ? "/DeviceCMYK setcolorspace\n" : "/DeviceGray setcolorspace\n"); |
||
5234 | fschmid | 1169 | QByteArray maskArray; |
3136 | fschmid | 1170 | ScImage img2; |
6873 | fschmid | 1171 | img2.imgInfo.clipPath = ""; |
1172 | img2.imgInfo.PDSpathData.clear(); |
||
1173 | img2.imgInfo.layerInfo.clear(); |
||
1174 | img2.imgInfo.RequestProps = c->pixm.imgInfo.RequestProps; |
||
1175 | img2.imgInfo.isRequest = c->pixm.imgInfo.isRequest; |
||
11331 | jghali | 1176 | if (c->pixm.imgInfo.type != ImageType7) |
11389 | jghali | 1177 | { |
12698 | fschmid | 1178 | bool alphaLoaded = img2.getAlpha(fn, c->pixm.imgInfo.actualPageNumber, maskArray, false, true, resolution); |
11389 | jghali | 1179 | if (!alphaLoaded) |
1180 | { |
||
1181 | PS_Error_MaskLoadFailure(fn); |
||
1182 | return false; |
||
1183 | } |
||
1184 | } |
||
11331 | jghali | 1185 | if ((maskArray.size() > 0) && (c->pixm.imgInfo.type != ImageType7)) |
3136 | fschmid | 1186 | { |
11389 | jghali | 1187 | int plate = DoSep ? Plate : (GraySc ? -2 : -1); |
11551 | jghali | 1188 | // JG - Experimental code using Type3 image instead of patterns |
11317 | jghali | 1189 | PutStream("<< /ImageType 3\n"); |
1190 | PutStream(" /DataDict <<\n"); |
||
1191 | PutStream(" /ImageType 1\n"); |
||
1192 | PutStream(" /Width " + IToStr(w) + "\n"); |
||
1193 | PutStream(" /Height " + IToStr(h) + "\n"); |
||
1194 | PutStream(" /BitsPerComponent 8\n"); |
||
1195 | PutStream( (GraySc || DoSep) ? " /Decode [1 0]\n" : " /Decode [0 1 0 1 0 1 0 1]\n"); |
||
1196 | PutStream(" /ImageMatrix [" + IToStr(w) + " 0 0 " + IToStr(-h) + " 0 " + IToStr(h) + "]\n"); |
||
11551 | jghali | 1197 | if (Name.length() > 0) |
1198 | PutStream(" /DataSource "+PSEncode(Name)+"Bild\n"); |
||
1199 | else |
||
1200 | PutStream(" /DataSource currentfile /ASCII85Decode filter /FlateDecode filter\n"); |
||
11317 | jghali | 1201 | PutStream(" >>\n"); |
1202 | PutStream(" /MaskDict <<\n"); |
||
1203 | PutStream(" /ImageType 1\n"); |
||
1204 | PutStream(" /Width " + IToStr(w) + "\n"); |
||
1205 | PutStream(" /Height " + IToStr(h) + "\n"); |
||
11551 | jghali | 1206 | PutStream(" /BitsPerComponent 8\n"); |
11317 | jghali | 1207 | PutStream(" /Decode [1 0]\n"); |
1208 | PutStream(" /ImageMatrix [" + IToStr(w) + " 0 0 " + IToStr(-h) + " 0 " + IToStr(h) + "]\n"); |
||
1209 | PutStream(" >>\n"); |
||
11551 | jghali | 1210 | PutStream(" /InterleaveType 1\n"); |
11317 | jghali | 1211 | PutStream(">>\n"); |
11551 | jghali | 1212 | PutStream("image\n"); |
1213 | if (Name.isEmpty()) |
||
3136 | fschmid | 1214 | { |
11568 | jghali | 1215 | if (!PutImageToStream(image, maskArray, plate)) |
11551 | jghali | 1216 | { |
1217 | PS_Error_ImageDataWriteFailure(); |
||
1218 | return false; |
||
1219 | } |
||
1220 | } |
||
1221 | else |
||
1222 | { |
||
11280 | jghali | 1223 | PutStream(PSEncode(Name)+"Bild resetfile\n"); |
11551 | jghali | 1224 | //PutStream(PSEncode(Name)+"Mask resetfile\n"); |
3136 | fschmid | 1225 | } |
1226 | } |
||
1227 | else |
||
1228 | { |
||
11280 | jghali | 1229 | PutStream("<< /ImageType 1\n"); |
1230 | PutStream(" /Width " + IToStr(w) + "\n"); |
||
1231 | PutStream(" /Height " + IToStr(h) + "\n"); |
||
1232 | PutStream(" /BitsPerComponent 8\n"); |
||
3136 | fschmid | 1233 | if (DoSep) |
11280 | jghali | 1234 | PutStream(" /Decode [1 0]\n"); |
3136 | fschmid | 1235 | else |
11280 | jghali | 1236 | PutStream( GraySc ? " /Decode [1 0]\n" : " /Decode [0 1 0 1 0 1 0 1]\n"); |
11317 | jghali | 1237 | PutStream(" /ImageMatrix [" + IToStr(w) + " 0 0 " + IToStr(-h) + " 0 " + IToStr(h) + "]\n"); |
3136 | fschmid | 1238 | if (!Name.isEmpty()) |
1239 | { |
||
11280 | jghali | 1240 | PutStream(" /DataSource "+PSEncode(Name)+"Bild >>\n"); |
1241 | PutStream("image\n"); |
||
1242 | PutStream(PSEncode(Name)+"Bild resetfile\n"); |
||
3136 | fschmid | 1243 | } |
1244 | else |
||
1245 | { |
||
11389 | jghali | 1246 | int plate = DoSep ? Plate : (GraySc ? -2 : -1); |
11551 | jghali | 1247 | PutStream(" /DataSource currentfile /ASCII85Decode filter /FlateDecode filter >>\n"); |
1248 | PutStream("image\n"); |
||
11568 | jghali | 1249 | if (!PutImageToStream(image, plate)) |
11317 | jghali | 1250 | { |
11551 | jghali | 1251 | PS_Error_ImageDataWriteFailure(); |
1252 | return false; |
||
11317 | jghali | 1253 | } |
3136 | fschmid | 1254 | } |
1255 | } |
||
1256 | } |
||
11060 | jghali | 1257 | return true; |
3136 | fschmid | 1258 | } |
1259 | |||
1260 | |||
1261 | void PSLib::PS_plate(int nr, QString name) |
||
1262 | { |
||
1263 | switch (nr) |
||
1264 | { |
||
1265 | case 0: |
||
11280 | jghali | 1266 | PutStream("%%PlateColor Black\n"); |
1267 | PutStream("/setcmykcolor {exch pop exch pop exch pop 1 exch sub oldsetgray} bind def\n"); |
||
1268 | PutStream("/setrgbcolor {pop pop pop 1 oldsetgray} bind def\n"); |
||
3136 | fschmid | 1269 | break; |
1270 | case 1: |
||
11280 | jghali | 1271 | PutStream("%%PlateColor Cyan\n"); |
1272 | PutStream("/setcmykcolor {pop pop pop 1 exch sub oldsetgray} bind def\n"); |
||
1273 | PutStream("/setrgbcolor {pop pop oldsetgray} bind def\n"); |
||
3136 | fschmid | 1274 | break; |
1275 | case 2: |
||
11280 | jghali | 1276 | PutStream("%%PlateColor Magenta\n"); |
1277 | PutStream("/setcmykcolor {pop pop exch pop 1 exch sub oldsetgray} bind def\n"); |
||
1278 | PutStream("/setrgbcolor {pop exch pop oldsetgray} bind def\n"); |
||
3136 | fschmid | 1279 | break; |
1280 | case 3: |
||
11280 | jghali | 1281 | PutStream("%%PlateColor Yellow\n"); |
1282 | PutStream("/setcmykcolor {pop exch pop exch pop 1 exch sub oldsetgray} bind def\n"); |
||
1283 | PutStream("/setrgbcolor {exch pop exch pop oldsetgray} bind def\n"); |
||
3136 | fschmid | 1284 | break; |
1285 | default: |
||
11280 | jghali | 1286 | PutStream("%%PlateColor "+name+"\n"); |
1287 | PutStream("/setcmykcolor {exch 0.11 mul add exch 0.59 mul add exch 0.3 mul add dup 1 gt {pop 1} if 1 exch sub oldsetgray} bind def\n"); |
||
1288 | PutStream("/setrgbcolor {0.11 mul exch 0.59 mul add exch 0.3 mul add oldsetgray} bind def\n"); |
||
3136 | fschmid | 1289 | break; |
1290 | } |
||
1291 | Plate = nr; |
||
1292 | currentSpot = name; |
||
1293 | DoSep = true; |
||
1294 | } |
||
1295 | |||
1296 | void PSLib::PS_setGray() |
||
1297 | { |
||
1298 | GraySc = true; |
||
1299 | } |
||
1300 | |||
1301 | void PSLib::PDF_Bookmark(QString text, uint Seite) |
||
1302 | { |
||
11280 | jghali | 1303 | PutStream("[/Title ("+text+") /Page "+IToStr(Seite)+" /View [/Fit]\n"); |
1304 | PutStream("/OUT pdfmark\n"); |
||
3136 | fschmid | 1305 | } |
1306 | |||
12589 | fschmid | 1307 | void PSLib::PDF_Annotation(PageItem *item, QString text, double x, double y, double b, double h) |
3136 | fschmid | 1308 | { |
12589 | fschmid | 1309 | PutStream("[\n/Rect [ "+ToStr(x)+" "+ToStr(y) +" "+ToStr(b)+" "+ToStr(h)+" ]\n"); |
1310 | switch (item->annotation().Type()) |
||
1311 | { |
||
1312 | case 0: |
||
17911 | fschmid | 1313 | case Annotation::Text: |
12589 | fschmid | 1314 | PutStream("/Subtype /Text\n"); |
1315 | PutStream("/Contents ("+text+")\n/Open false\n"); |
||
1316 | break; |
||
1317 | case 1: |
||
17911 | fschmid | 1318 | case Annotation::Link: |
12589 | fschmid | 1319 | PutStream("/Subtype /Link\n"); |
17977 | fschmid | 1320 | if (item->annotation().ActionType() == Annotation::Action_GoTo) |
12589 | fschmid | 1321 | { |
1322 | PutStream("/Page " + QString::number(item->annotation().Ziel() + 1) + "\n"); |
||
1323 | PutStream("/View [ /XYZ " + item->annotation().Action() + "]\n"); |
||
1324 | } |
||
17977 | fschmid | 1325 | if (item->annotation().ActionType() == Annotation::Action_GoToR_FileRel) |
12589 | fschmid | 1326 | { |
1327 | QFileInfo fiBase(Spool.fileName()); |
||
1328 | QString baseDir = fiBase.absolutePath(); |
||
1329 | PutStream("/Action /GoToR\n"); |
||
1330 | PutStream("/File (" + Path2Relative(item->annotation().Extern(), baseDir) + ")\n"); |
||
1331 | PutStream("/Page " + QString::number(item->annotation().Ziel() + 1) + "\n"); |
||
1332 | PutStream("/View [ /XYZ " + item->annotation().Action() + "]\n"); |
||
1333 | } |
||
17977 | fschmid | 1334 | if (item->annotation().ActionType() == Annotation::Action_URI) |
12589 | fschmid | 1335 | { |
1336 | /* The PDFMark docs say that for URI actions should contain an entry /Subtype /URI |
||
1337 | but tests with Ghostscript shows that only /S /URI works. Don't know if that is |
||
1338 | an error in the docs or a bug in Ghostscript |
||
1339 | PutStream("/Action << /Subtype /URI /URI (" + item->annotation().Extern() + ") >>\n"); |
||
1340 | */ |
||
1341 | PutStream("/Action << /S /URI /URI (" + item->annotation().Extern() + ") >>\n"); |
||
1342 | } |
||
17977 | fschmid | 1343 | if (item->annotation().ActionType() == Annotation::Action_GoToR_FileAbs) |
12589 | fschmid | 1344 | { |
1345 | PutStream("/Action /GoToR\n"); |
||
1346 | PutStream("/File (" + item->annotation().Extern() + ")\n"); |
||
1347 | PutStream("/Page " + QString::number(item->annotation().Ziel() + 1) + "\n"); |
||
1348 | PutStream("/View [ /XYZ " + item->annotation().Action() + "]\n"); |
||
1349 | } |
||
1350 | break; |
||
1351 | default: |
||
1352 | break; |
||
1353 | } |
||
1354 | if ((item->annotation().Type() < 2) || (item->annotation().Type() > 9)) |
||
1355 | PutStream("/Border [ 0 0 0 ]\n"); |
||
1356 | PutStream("/Title (" + item->itemName().replace(".", "_" ) + ")\n"); |
||
11280 | jghali | 1357 | PutStream("/ANN pdfmark\n"); |
3136 | fschmid | 1358 | } |
1359 | |||
1360 | |||
1361 | void PSLib::PS_close() |
||
1362 | { |
||
11280 | jghali | 1363 | PutStream("%%Trailer\n"); |
1364 | // PutStream("end\n"); |
||
1365 | PutStream("%%EOF\n"); |
||
3136 | fschmid | 1366 | Spool.close(); |
1367 | } |
||
1368 | |||
1369 | void PSLib::PS_insert(QString i) |
||
1370 | { |
||
11280 | jghali | 1371 | PutStream(i); |
3136 | fschmid | 1372 | } |
1373 | |||
11060 | jghali | 1374 | void PSLib::PS_Error(const QString& message) |
1375 | { |
||
1376 | ErrorMessage = message; |
||
1377 | if (!ScCore->usingGUI()) |
||
13085 | jghali | 1378 | qDebug("%s", message.toLocal8Bit().data()); |
11060 | jghali | 1379 | } |
1380 | |||
11551 | jghali | 1381 | void PSLib::PS_Error_ImageDataWriteFailure(void) |
1382 | { |
||
1383 | PS_Error( tr("Failed to write data for an image")); |
||
1384 | } |
||
1385 | |||
11060 | jghali | 1386 | void PSLib::PS_Error_ImageLoadFailure(const QString& fileName) |
1387 | { |
||
1388 | PS_Error( tr("Failed to load an image : %1").arg(fileName) ); |
||
1389 | } |
||
1390 | |||
11389 | jghali | 1391 | void PSLib::PS_Error_MaskLoadFailure(const QString& fileName) |
1392 | { |
||
1393 | PS_Error( tr("Failed to load an image mask : %1").arg(fileName) ); |
||
1394 | } |
||
1395 | |||
11060 | jghali | 1396 | void PSLib::PS_Error_InsufficientMemory(void) |
1397 | { |
||
1398 | PS_Error( tr("Insufficient memory for processing an image")); |
||
1399 | } |
||
1400 | |||
6954 | fschmid | 1401 | int PSLib::CreatePS(ScribusDoc* Doc, PrintOptions &options) |
3136 | fschmid | 1402 | { |
11060 | jghali | 1403 | bool errorOccured = false; |
6954 | fschmid | 1404 | Options = options; |
1405 | std::vector<int> &pageNs = options.pageNumbers; |
||
1406 | bool sep = options.outputSeparations; |
||
1407 | QString SepNam = options.separationName; |
||
1408 | QStringList spots = options.allSeparations; |
||
1409 | bool farb = options.useColor; |
||
1410 | bool Hm = options.mirrorH; |
||
1411 | bool Vm = options.mirrorV; |
||
1412 | bool Ic = options.useICC; |
||
1413 | bool gcr = options.doGCR; |
||
1414 | bool doDev = options.setDevParam; |
||
1415 | bool doClip = options.doClip; |
||
3136 | fschmid | 1416 | int sepac; |
1417 | int pagemult; |
||
1418 | if ((sep) && (SepNam == QObject::tr("All"))) |
||
1419 | pagemult = spots.count(); |
||
1420 | else |
||
3230 | fschmid | 1421 | pagemult = 1; |
12055 | jghali | 1422 | QVector<double> dum; |
7978 | fschmid | 1423 | double gx = 0.0; |
1424 | double gy = 0.0; |
||
1425 | double gw = 0.0; |
||
1426 | double gh = 0.0;; |
||
15037 | cbradney | 1427 | PS_set_Info("Author", Doc->documentInfo().author()); |
1428 | PS_set_Info("Title", Doc->documentInfo().title()); |
||
3136 | fschmid | 1429 | if (!farb) |
1430 | PS_setGray(); |
||
6671 | fschmid | 1431 | applyICC = Ic; |
1432 | if ((Doc->HasCMS) && (ScCore->haveCMS()) && (applyICC)) |
||
14170 | jghali | 1433 | solidTransform = Doc->colorEngine.createTransform(Doc->DocInputCMYKProf, Format_CMYK_16, Doc->DocPrinterProf, Format_CMYK_16, Doc->IntentColors, 0); |
6671 | fschmid | 1434 | else |
1435 | applyICC = false; |
||
4037 | cbradney | 1436 | if (usingGUI) |
1437 | { |
||
1438 | QString title=QObject::tr("Exporting PostScript File"); |
||
15548 | fschmid | 1439 | if (psExport) |
4037 | cbradney | 1440 | title=QObject::tr("Printing File"); |
10508 | cbradney | 1441 | progressDialog=new MultiProgressDialog(title, CommonStrings::tr_Cancel, Doc->scMW()); |
4037 | cbradney | 1442 | if (progressDialog==0) |
1443 | usingGUI=false; |
||
1444 | else |
||
1445 | { |
||
1446 | QStringList barNames, barTexts; |
||
1447 | barNames << "EMP" << "EP"; |
||
5370 | cbradney | 1448 | barTexts << tr("Processing Master Page:") << tr("Exporting Page:"); |
9803 | fschmid | 1449 | QList<bool> barsNumeric; |
5370 | cbradney | 1450 | barsNumeric << true << true; |
1451 | progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric); |
||
4037 | cbradney | 1452 | progressDialog->setOverallTotalSteps(pageNs.size()+Doc->MasterPages.count()); |
1453 | progressDialog->setTotalSteps("EMP", Doc->MasterPages.count()); |
||
1454 | progressDialog->setTotalSteps("EP", pageNs.size()); |
||
1455 | progressDialog->setOverallProgress(0); |
||
1456 | progressDialog->setProgress("EMP", 0); |
||
1457 | progressDialog->setProgress("EP", 0); |
||
1458 | progressDialog->show(); |
||
8619 | subik | 1459 | connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested())); |
4037 | cbradney | 1460 | ScQApp->processEvents(); |
1461 | } |
||
1462 | } |
||
4847 | cbradney | 1463 | uint docSelectionCount=Doc->m_Selection->count(); |
15548 | fschmid | 1464 | if ((!psExport) && (docSelectionCount != 0)) |
3136 | fschmid | 1465 | { |
15071 | fschmid | 1466 | double minx = 999999.9; |
1467 | double miny = 999999.9; |
||
1468 | double maxx = -999999.9; |
||
1469 | double maxy = -999999.9; |
||
3934 | cbradney | 1470 | for (uint ep = 0; ep < docSelectionCount; ++ep) |
3394 | fschmid | 1471 | { |
4847 | cbradney | 1472 | PageItem* currItem = Doc->m_Selection->itemAt(ep); |
3394 | fschmid | 1473 | double lw = currItem->lineWidth() / 2.0; |
3934 | cbradney | 1474 | if (currItem->rotation() != 0) |
3394 | fschmid | 1475 | { |
1476 | FPointArray pb; |
||
1477 | pb.resize(0); |
||
3903 | cbradney | 1478 | pb.addPoint(FPoint(currItem->xPos()-lw, currItem->yPos()-lw)); |
3934 | cbradney | 1479 | pb.addPoint(FPoint(currItem->width()+lw*2.0, -lw, currItem->xPos()-lw, currItem->yPos()-lw, currItem->rotation(), 1.0, 1.0)); |
1480 | pb.addPoint(FPoint(currItem->width()+lw*2.0, currItem->height()+lw*2.0, currItem->xPos()-lw, currItem->yPos()-lw, currItem->rotation(), 1.0, 1.0)); |
||
1481 | pb.addPoint(FPoint(-lw, currItem->height()+lw*2.0, currItem->xPos()-lw, currItem->yPos()-lw, currItem->rotation(), 1.0, 1.0)); |
||
3394 | fschmid | 1482 | for (uint pc = 0; pc < 4; ++pc) |
1483 | { |
||
8562 | jghali | 1484 | minx = qMin(minx, pb.point(pc).x()); |
1485 | miny = qMin(miny, pb.point(pc).y()); |
||
1486 | maxx = qMax(maxx, pb.point(pc).x()); |
||
1487 | maxy = qMax(maxy, pb.point(pc).y()); |
||
3394 | fschmid | 1488 | } |
1489 | } |
||
1490 | else |
||
1491 | { |
||
8562 | jghali | 1492 | minx = qMin(minx, currItem->xPos()-lw); |
1493 | miny = qMin(miny, currItem->yPos()-lw); |
||
1494 | maxx = qMax(maxx, currItem->xPos()-lw + currItem->width()+lw*2.0); |
||
1495 | maxy = qMax(maxy, currItem->yPos()-lw + currItem->height()+lw*2.0); |
||
3394 | fschmid | 1496 | } |
1497 | } |
||
1498 | gx = minx; |
||
1499 | gy = miny; |
||
1500 | gw = maxx - minx; |
||
1501 | gh = maxy - miny; |
||
3136 | fschmid | 1502 | int pgNum = pageNs[0]-1; |
3724 | cbradney | 1503 | gx -= Doc->Pages->at(pgNum)->xOffset(); |
1504 | gy -= Doc->Pages->at(pgNum)->yOffset(); |
||
14991 | cbradney | 1505 | errorOccured = !PS_begin_doc(Doc, gx, Doc->pageHeight() - (gy+gh), gx + gw, Doc->pageHeight() - gy, 1*pagemult, false, sep, farb, Ic, gcr); |
3136 | fschmid | 1506 | } |
1507 | else |
||
4037 | cbradney | 1508 | { |
8450 | fschmid | 1509 | uint a; |
1510 | double maxWidth = 0.0; |
||
1511 | double maxHeight = 0.0; |
||
8467 | avox | 1512 | for (uint aa = 0; aa < pageNs.size(); ++aa) |
8450 | fschmid | 1513 | { |
1514 | a = pageNs[aa]-1; |
||
8562 | jghali | 1515 | maxWidth = qMax(Doc->Pages->at(a)->width(), maxWidth); |
1516 | maxHeight = qMax(Doc->Pages->at(a)->height(), maxHeight); |
||
8450 | fschmid | 1517 | } |
12342 | jghali | 1518 | errorOccured = !PS_begin_doc(Doc, 0.0, 0.0, maxWidth, maxHeight, pageNs.size()*pagemult, doDev, sep, farb, Ic, gcr); |
4037 | cbradney | 1519 | } |
10018 | fschmid | 1520 | int ap=0; |
11060 | jghali | 1521 | for (; ap < Doc->MasterPages.count() && !abortExport && !errorOccured; ++ap) |
3136 | fschmid | 1522 | { |
4037 | cbradney | 1523 | progressDialog->setOverallProgress(ap); |
1524 | progressDialog->setProgress("EMP", ap); |
||
1525 | ScQApp->processEvents(); |
||
3136 | fschmid | 1526 | if (Doc->MasterItems.count() != 0) |
1527 | { |
||
1528 | int Lnr = 0; |
||
10140 | jghali | 1529 | ScLayer ll; |
3136 | fschmid | 1530 | ll.isPrintable = false; |
13875 | jghali | 1531 | ll.ID = 0; |
11440 | jghali | 1532 | for (int lam = 0; lam < Doc->Layers.count() && !abortExport && !errorOccured; ++lam) |
3136 | fschmid | 1533 | { |
10140 | jghali | 1534 | Doc->Layers.levelToLayer(ll, Lnr); |
3136 | fschmid | 1535 | if (ll.isPrintable) |
1536 | { |
||
11440 | jghali | 1537 | for (int api = 0; api < Doc->MasterItems.count() && !abortExport; ++api) |
3136 | fschmid | 1538 | { |
1539 | QString tmps; |
||
1540 | PageItem *it = Doc->MasterItems.at(api); |
||
11440 | jghali | 1541 | if (usingGUI) |
1542 | ScQApp->processEvents(); |
||
13875 | jghali | 1543 | if ((it->LayerID != ll.ID) || (!it->printEnabled())) |
3136 | fschmid | 1544 | continue; |
13816 | jghali | 1545 | double bLeft, bRight, bBottom, bTop; |
1546 | GetBleeds(Doc->MasterPages.at(ap), bLeft, bRight, bBottom, bTop); |
||
1547 | double x = Doc->MasterPages.at(ap)->xOffset() - bLeft; |
||
1548 | double y = Doc->MasterPages.at(ap)->yOffset() - bTop; |
||
1549 | double w = Doc->MasterPages.at(ap)->width() + bLeft + bRight; |
||
1550 | double h1 = Doc->MasterPages.at(ap)->height()+ bBottom + bTop; |
||
7449 | fschmid | 1551 | double ilw = it->lineWidth(); |
1552 | double x2 = it->BoundingX - ilw / 2.0; |
||
1553 | double y2 = it->BoundingY - ilw / 2.0; |
||
13013 | fschmid | 1554 | double w2 = qMax(it->BoundingW + ilw, 1.0); |
1555 | double h2 = qMax(it->BoundingH + ilw, 1.0); |
||
8562 | jghali | 1556 | if (!( qMax( x, x2 ) <= qMin( x+w, x2+w2 ) && qMax( y, y2 ) <= qMin( y+h1, y2+h2 ))) |
3136 | fschmid | 1557 | continue; |
3200 | cbradney | 1558 | if ((it->OwnPage != static_cast<int>(Doc->MasterPages.at(ap)->pageNr())) && (it->OwnPage != -1)) |
3136 | fschmid | 1559 | continue; |
13097 | subik | 1560 | if ((optimization == OptimizeSize) && it->asImageFrame() && it->PictureIsAvailable && (!it->Pfile.isEmpty()) && it->printEnabled() && (!sep) && farb) |
11060 | jghali | 1561 | { |
1562 | errorOccured = !PS_ImageData(it, it->Pfile, it->itemName(), it->IProfile, it->UseEmbedded, Ic); |
||
1563 | if (errorOccured) break; |
||
1564 | } |
||
16943 | fschmid | 1565 | PS_TemplateStart(QString("mp_obj_%1_%2").arg(ap).arg(qHash(it))); |
3136 | fschmid | 1566 | ProcessItem(Doc, Doc->MasterPages.at(ap), it, ap+1, sep, farb, Ic, gcr, true); |
1567 | PS_TemplateEnd(); |
||
1568 | } |
||
1569 | } |
||
1570 | Lnr++; |
||
11060 | jghali | 1571 | if (errorOccured) break; |
3136 | fschmid | 1572 | } |
1573 | } |
||
11060 | jghali | 1574 | if (errorOccured) break; |
3136 | fschmid | 1575 | } |
1576 | sepac = 0; |
||
1577 | uint aa = 0; |
||
5781 | cbradney | 1578 | uint a; |
11280 | jghali | 1579 | PutStream("%%EndSetup\n"); |
11060 | jghali | 1580 | while (aa < pageNs.size() && !abortExport && !errorOccured) |
3136 | fschmid | 1581 | { |
4037 | cbradney | 1582 | progressDialog->setProgress("EP", aa); |
1583 | progressDialog->setOverallProgress(ap+aa); |
||
11440 | jghali | 1584 | if (usingGUI) |
1585 | ScQApp->processEvents(); |
||
3136 | fschmid | 1586 | a = pageNs[aa]-1; |
16729 | fschmid | 1587 | ScPage* page = Doc->Pages->at(a); |
15548 | fschmid | 1588 | if ((!psExport) && (Doc->m_Selection->count() != 0)) |
3136 | fschmid | 1589 | { |
7316 | jghali | 1590 | MarginStruct Ma; |
3136 | fschmid | 1591 | Ma.Left = gx; |
1592 | Ma.Top = gy; |
||
13873 | jghali | 1593 | Ma.Bottom = page->height() - (gy + gh); |
1594 | Ma.Right = page->width() - (gx + gw); |
||
1595 | PS_begin_page(page, &Ma, true); |
||
3136 | fschmid | 1596 | } |
1597 | else |
||
13873 | jghali | 1598 | PS_begin_page(page, &page->Margins, doClip); |
3136 | fschmid | 1599 | if (Hm) |
1600 | { |
||
13873 | jghali | 1601 | PS_translate(page->width(), 0); |
3136 | fschmid | 1602 | PS_scale(-1, 1); |
1603 | } |
||
1604 | if (Vm) |
||
1605 | { |
||
13873 | jghali | 1606 | PS_translate(0, page->height()); |
3136 | fschmid | 1607 | PS_scale(1, -1); |
1608 | } |
||
1609 | if (sep) |
||
1610 | { |
||
1611 | if (SepNam == QObject::tr("Black")) |
||
1612 | PS_plate(0); |
||
1613 | else if (SepNam == QObject::tr("Cyan")) |
||
1614 | PS_plate(1); |
||
1615 | else if (SepNam == QObject::tr("Magenta")) |
||
1616 | PS_plate(2); |
||
1617 | else if (SepNam == QObject::tr("Yellow")) |
||
1618 | PS_plate(3); |
||
1619 | else if (SepNam == QObject::tr("All")) |
||
1620 | PS_plate(sepac, spots[sepac]); |
||
1621 | else |
||
1622 | PS_plate(4, SepNam); |
||
1623 | } |
||
13873 | jghali | 1624 | ScLayer ll; |
1625 | ll.isPrintable = false; |
||
1626 | for (int lam = 0; lam < Doc->Layers.count() && !abortExport && !errorOccured; ++lam) |
||
3136 | fschmid | 1627 | { |
13873 | jghali | 1628 | Doc->Layers.levelToLayer(ll, lam); |
1629 | if (!ll.isPrintable) |
||
1630 | continue; |
||
1631 | if (!page->MPageNam.isEmpty() && !abortExport && !errorOccured) |
||
3136 | fschmid | 1632 | { |
13873 | jghali | 1633 | errorOccured |= !ProcessMasterPageLayer(Doc, page, ll, a, sep, farb, Ic, gcr); |
3136 | fschmid | 1634 | } |
13873 | jghali | 1635 | if (!abortExport && !errorOccured) |
1636 | { |
||
1637 | errorOccured |= !ProcessPageLayer(Doc, page, ll, a+1, sep, farb, Ic, gcr); |
||
1638 | } |
||
3136 | fschmid | 1639 | } |
11060 | jghali | 1640 | if (!abortExport && !errorOccured) |
4037 | cbradney | 1641 | PS_end_page(); |
3136 | fschmid | 1642 | if (sep) |
1643 | { |
||
1644 | if (SepNam != QObject::tr("All")) |
||
1645 | aa++; |
||
1646 | else |
||
1647 | { |
||
1648 | if (sepac == static_cast<int>(spots.count()-1)) |
||
1649 | { |
||
1650 | aa++; |
||
1651 | sepac = 0; |
||
1652 | } |
||
1653 | else |
||
1654 | sepac++; |
||
1655 | } |
||
1656 | } |
||
1657 | else |
||
1658 | aa++; |
||
1659 | } |
||
1660 | PS_close(); |
||
4037 | cbradney | 1661 | if (usingGUI) progressDialog->close(); |
11060 | jghali | 1662 | if (errorOccured) |
1663 | return 1; |
||
11066 | fschmid | 1664 | else if (abortExport) |
4037 | cbradney | 1665 | return 2; //CB Lets leave 1 for general error condition |
11060 | jghali | 1666 | return 0; |
3136 | fschmid | 1667 | } |
1668 | |||
16729 | fschmid | 1669 | bool PSLib::ProcessItem(ScribusDoc* Doc, ScPage* a, PageItem* c, uint PNr, bool sep, bool farb, bool ic, bool gcr, bool master, bool embedded, bool useTemplate) |
3136 | fschmid | 1670 | { |
9920 | fschmid | 1671 | double tsz; |
1672 | int h, s, v, k; |
||
5732 | avox | 1673 | int d; |
17023 | fschmid | 1674 | int savedOwnPage; |
4689 | mrdocs | 1675 | ScText *hl; |
12055 | jghali | 1676 | QVector<double> dum; |
11585 | jghali | 1677 | QChar chstr; |
1678 | QString tmps; |
||
4698 | cbradney | 1679 | if (c->printEnabled()) |
3136 | fschmid | 1680 | { |
4477 | fschmid | 1681 | fillRule = true; |
3136 | fschmid | 1682 | PS_save(); |
12342 | jghali | 1683 | if (c->doOverprint) |
5320 | fschmid | 1684 | { |
12342 | jghali | 1685 | PutStream("true setoverprint\n"); |
1686 | PutStream("true setoverprintmode\n"); |
||
5320 | fschmid | 1687 | } |
4546 | subik | 1688 | if (c->fillColor() != CommonStrings::None) |
3136 | fschmid | 1689 | { |
11333 | jghali | 1690 | SetColor(c->fillColor(), c->fillShade(), &h, &s, &v, &k, gcr); |
3136 | fschmid | 1691 | PS_setcmykcolor_fill(h / 255.0, s / 255.0, v / 255.0, k / 255.0); |
1692 | } |
||
4546 | subik | 1693 | if (c->lineColor() != CommonStrings::None) |
3136 | fschmid | 1694 | { |
11333 | jghali | 1695 | SetColor(c->lineColor(), c->lineShade(), &h, &s, &v, &k, gcr); |
3136 | fschmid | 1696 | PS_setcmykcolor_stroke(h / 255.0, s / 255.0, v / 255.0, k / 255.0); |
1697 | } |
||
4580 | cbradney | 1698 | PS_setlinewidth(c->lineWidth()); |
3136 | fschmid | 1699 | PS_setcapjoin(c->PLineEnd, c->PLineJoin); |
1700 | PS_setdash(c->PLineArt, c->DashOffset, c->DashValues); |
||
1701 | if (!embedded) |
||
1702 | { |
||
3903 | cbradney | 1703 | PS_translate(c->xPos() - a->xOffset(), a->height() - (c->yPos() - a->yOffset())); |
3136 | fschmid | 1704 | } |
3934 | cbradney | 1705 | if (c->rotation() != 0) |
1706 | PS_rotate(-c->rotation()); |
||
3136 | fschmid | 1707 | switch (c->itemType()) |
1708 | { |
||
1709 | case PageItem::ImageFrame: |
||
10321 | mrdocs | 1710 | case PageItem::LatexFrame: |
3136 | fschmid | 1711 | if (master) |
1712 | break; |
||
4546 | subik | 1713 | if ((c->fillColor() != CommonStrings::None) || (c->GrType != 0)) |
3136 | fschmid | 1714 | { |
1715 | SetClipPath(&c->PoLine); |
||
1716 | PS_closepath(); |
||
11562 | jghali | 1717 | if ((c->GrType != 0) && (master == false)) |
14230 | fschmid | 1718 | HandleGradientFillStroke(c, gcr, false); |
3136 | fschmid | 1719 | else |
1720 | putColor(c->fillColor(), c->fillShade(), true); |
||
1721 | PS_newpath(); |
||
1722 | } |
||
1723 | PS_save(); |
||
1724 | if (c->imageFlippedH()) |
||
1725 | { |
||
3934 | cbradney | 1726 | PS_translate(c->width(), 0); |
3136 | fschmid | 1727 | PS_scale(-1, 1); |
1728 | } |
||
1729 | if (c->imageFlippedV()) |
||
1730 | { |
||
3934 | cbradney | 1731 | PS_translate(0, -c->height()); |
3136 | fschmid | 1732 | PS_scale(1, -1); |
1733 | } |
||
17041 | fschmid | 1734 | if (c->imageClip.size() != 0) |
1735 | { |
||
1736 | SetClipPath(&c->imageClip); |
||
1737 | PS_closepath(); |
||
1738 | PS_clip(true); |
||
1739 | } |
||
1740 | SetClipPath(&c->PoLine); |
||
1741 | PS_closepath(); |
||
1742 | PS_clip(true); |
||
13097 | subik | 1743 | if ((c->PictureIsAvailable) && (!c->Pfile.isEmpty())) |
3136 | fschmid | 1744 | { |
11060 | jghali | 1745 | bool imageOk = false; |
3985 | cbradney | 1746 | PS_translate(0, -c->BBoxH*c->imageYScale()); |
11562 | jghali | 1747 | if ((optimization == OptimizeSize) && (((!a->pageName().isEmpty()) && !sep && farb) || useTemplate)) |
1748 | imageOk = PS_image(c, c->imageXOffset(), -c->imageYOffset(), c->Pfile, c->imageXScale(), c->imageYScale(), c->IProfile, c->UseEmbedded, ic, c->itemName()); |
||
3136 | fschmid | 1749 | else |
11562 | jghali | 1750 | imageOk = PS_image(c, c->imageXOffset(), -c->imageYOffset(), c->Pfile, c->imageXScale(), c->imageYScale(), c->IProfile, c->UseEmbedded, ic); |
11060 | jghali | 1751 | if (!imageOk) return false; |
3136 | fschmid | 1752 | } |
1753 | PS_restore(); |
||
17418 | fschmid | 1754 | if (((c->lineColor() != CommonStrings::None) || (!c->NamedLStyle.isEmpty()) || (!c->strokePattern().isEmpty()) || (c->GrTypeStroke > 0))) |
3136 | fschmid | 1755 | { |
13013 | fschmid | 1756 | if (c->NamedLStyle.isEmpty()) // && (c->lineWidth() != 0.0)) |
3136 | fschmid | 1757 | { |
14419 | fschmid | 1758 | if ((!c->strokePattern().isEmpty()) && (c->patternStrokePath)) |
1759 | { |
||
1760 | QPainterPath path = c->PoLine.toQPainterPath(false); |
||
1761 | HandleBrushPattern(c, path, a, PNr, sep, farb, ic, gcr, master); |
||
1762 | } |
||
14168 | fschmid | 1763 | else |
1764 | { |
||
14419 | fschmid | 1765 | PS_setlinewidth(c->lineWidth()); |
1766 | PS_setcapjoin(c->PLineEnd, c->PLineJoin); |
||
1767 | PS_setdash(c->PLineArt, c->DashOffset, c->DashValues); |
||
1768 | SetClipPath(&c->PoLine); |
||
1769 | PS_closepath(); |
||
1770 | if (!c->strokePattern().isEmpty()) |
||
1771 | HandleStrokePattern(c); |
||
1772 | else if (c->GrTypeStroke > 0) |
||
1773 | HandleGradientFillStroke(c, gcr); |
||
1774 | else |
||
1775 | { |
||
1776 | SetColor(c->lineColor(), c->lineShade(), &h, &s, &v, &k, gcr); |
||
1777 | PS_setcmykcolor_stroke(h / 255.0, s / 255.0, v / 255.0, k / 255.0); |
||
1778 | putColor(c->lineColor(), c->lineShade(), false); |
||
1779 | } |
||
14168 | fschmid | 1780 | } |
3136 | fschmid | 1781 | } |
1782 | else |
||
1783 | { |
||
1784 | multiLine ml = Doc->MLineStyles[c->NamedLStyle]; |
||
1785 | for (int it = ml.size()-1; it > -1; it--) |
||
1786 | { |
||
13013 | fschmid | 1787 | if (ml[it].Color != CommonStrings::None) // && (ml[it].Width != 0)) |
6568 | fschmid | 1788 | { |
11333 | jghali | 1789 | SetColor(ml[it].Color, ml[it].Shade, &h, &s, &v, &k, gcr); |
6568 | fschmid | 1790 | PS_setcmykcolor_stroke(h / 255.0, s / 255.0, v / 255.0, k / 255.0); |
1791 | PS_setlinewidth(ml[it].Width); |
||
1792 | PS_setcapjoin(static_cast<Qt::PenCapStyle>(ml[it].LineEnd), static_cast<Qt::PenJoinStyle>(ml[it].LineJoin)); |
||
1793 | PS_setdash(static_cast<Qt::PenStyle>(ml[it].Dash), 0, dum); |
||
1794 | SetClipPath(&c->PoLine); |
||
1795 | PS_closepath(); |
||
1796 | putColor(ml[it].Color, ml[it].Shade, false); |
||
1797 | } |
||
3136 | fschmid | 1798 | } |
1799 | } |
||
1800 | } |
||
1801 | break; |
||
1802 | case PageItem::TextFrame: |
||
1803 | if (master) |
||
1804 | break; |
||
12589 | fschmid | 1805 | if ((c->isBookmark || c->isAnnotation()) && (!isPDF)) |
1806 | break; |
||
3136 | fschmid | 1807 | if (c->isBookmark) |
1808 | { |
||
1809 | QString bm = ""; |
||
1810 | QString cc; |
||
5387 | avox | 1811 | for (int d = 0; d < c->itemText.length(); ++d) |
3136 | fschmid | 1812 | { |
5184 | avox | 1813 | if ((c->itemText.text(d) == QChar(13)) || (c->itemText.text(d) == QChar(10)) || (c->itemText.text(d) == QChar(28))) |
3136 | fschmid | 1814 | break; |
8575 | jghali | 1815 | bm += "\\"+cc.setNum(qMax(c->itemText.text(d).unicode(), (ushort) 32), 8); |
3136 | fschmid | 1816 | } |
3200 | cbradney | 1817 | PDF_Bookmark(bm, a->pageNr()+1); |
3136 | fschmid | 1818 | } |
4084 | cbradney | 1819 | if (c->isAnnotation()) |
3136 | fschmid | 1820 | { |
17911 | fschmid | 1821 | if ((c->annotation().Type() == 0) || (c->annotation().Type() == 1) || (c->annotation().Type() == Annotation::Text) || (c->annotation().Type() == Annotation::Link)) |
3136 | fschmid | 1822 | { |
12589 | fschmid | 1823 | QString bm = ""; |
1824 | QString cc; |
||
1825 | for (int d = 0; d < c->itemText.length(); ++d) |
||
1826 | { |
||
1827 | bm += "\\"+cc.setNum(qMax(c->itemText.text(d).unicode(), (ushort) 32), 8); |
||
1828 | } |
||
1829 | PDF_Annotation(c, bm, 0, 0, c->width(), -c->height()); |
||
3136 | fschmid | 1830 | } |
1831 | break; |
||
1832 | } |
||
4546 | subik | 1833 | if ((c->fillColor() != CommonStrings::None) || (c->GrType != 0)) |
3136 | fschmid | 1834 | { |
1835 | SetClipPath(&c->PoLine); |
||
1836 | PS_closepath(); |
||
11562 | jghali | 1837 | if ((c->GrType != 0) && (master == false)) |
14230 | fschmid | 1838 | HandleGradientFillStroke(c, gcr, false); |
3136 | fschmid | 1839 | else |
1840 | putColor(c->fillColor(), c->fillShade(), true); |
||
1841 | } |
||
1842 | if (c->imageFlippedH()) |
||
1843 | { |
||
3934 | cbradney | 1844 | PS_translate(c->width(), 0); |
3136 | fschmid | 1845 | PS_scale(-1, 1); |
1846 | } |
||
1847 | if (c->imageFlippedV()) |
||
1848 | { |
||
3934 | cbradney | 1849 | PS_translate(0, -c->height()); |
3136 | fschmid | 1850 | PS_scale(1, -1); |
1851 | } |
||
1852 | setTextSt(Doc, c, gcr, PNr-1, a, sep, farb, ic, master); |
||
17418 | fschmid | 1853 | if (((c->lineColor() != CommonStrings::None) || (!c->NamedLStyle.isEmpty()) || (!c->strokePattern(). |