Rev 9 | Rev 45 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | paul | 1 | /*************************************************************************** |
2 | pslib.cpp - description |
||
3 | ------------------- |
||
4 | begin : Sat May 26 2001 |
||
5 | copyright : (C) 2001 by Franz Schmid |
||
6 | email : Franz.Schmid@altmuehlnet.de |
||
7 | ***************************************************************************/ |
||
8 | |||
9 | /*************************************************************************** |
||
10 | * * |
||
11 | * This program is free software; you can redistribute it and/or modify * |
||
12 | * it under the terms of the GNU General Public License as published by * |
||
13 | * the Free Software Foundation; either version 2 of the License, or * |
||
14 | * (at your option) any later version. * |
||
15 | * * |
||
16 | ***************************************************************************/ |
||
17 | #include <qfileinfo.h> |
||
18 | #include <qtextstream.h> |
||
19 | #include <qimage.h> |
||
20 | #include <qcolor.h> |
||
21 | #include <qcstring.h> |
||
22 | #include <qfontinfo.h> |
||
23 | #include <cstdlib> |
||
24 | #include <qregexp.h> |
||
25 | #include "config.h" |
||
26 | #include "pslib.h" |
||
27 | #include "scfonts.h" |
||
28 | #include <cmath> |
||
29 | |||
30 | extern bool loadText(QString nam, QString *Buffer); |
||
31 | extern QImage LoadPict(QString fn); |
||
32 | extern QString CompressStr(QString *in); |
||
33 | extern QString ImageToCMYK_PS(QImage *im, int pl, bool pre); |
||
34 | extern QString MaskToTxt(QImage *im, bool PDF = true); |
||
35 | extern char *toHex( uchar u ); |
||
36 | extern QString String2Hex(QString *in, bool lang = true); |
||
37 | #ifdef HAVE_CMS |
||
38 | extern bool CMSuse; |
||
39 | extern QImage LoadPictCol(QString fn, QString Prof, bool UseEmbedded, bool *realCMYK); |
||
40 | #endif |
||
41 | |||
42 | extern "C" void* Run(bool psart, SCFonts &AllFonts, QMap<QString,QFont> DocFonts, CListe DocColors, bool pdf); |
||
43 | |||
44 | void* Run(bool psart, SCFonts &AllFonts, QMap<QString,QFont> DocFonts, CListe DocColors, bool pdf) |
||
45 | { |
||
46 | PSLib *dia = new PSLib(psart, AllFonts, DocFonts, DocColors, pdf); |
||
47 | return dia; |
||
48 | } |
||
49 | |||
50 | PSLib::PSLib(bool psart, SCFonts &AllFonts, QMap<QString,QFont> DocFonts, CListe DocColors, bool pdf) |
||
51 | { |
||
52 | QString tmp, tmp2, tmp3, tmp4, CHset; |
||
53 | QStringList wt; |
||
54 | int IsoInUse = 0; |
||
55 | QString Epfad = PREL; |
||
56 | Seiten = 0; |
||
57 | User = ""; |
||
58 | Creator = "PSlib-0.3"; |
||
59 | Titel = ""; |
||
60 | FillColor = "0.0 0.0 0.0 0.0"; |
||
61 | StrokeColor = "0.0 0.0 0.0 0.0"; |
||
62 | if (psart) |
||
63 | { |
||
64 | Header = "%!PS-Adobe-3.0\n"; |
||
65 | } |
||
66 | else |
||
67 | { |
||
68 | Header = "%!PS-Adobe-3.0 EPSF-3.0\n"; |
||
69 | } |
||
70 | BBox = ""; |
||
71 | BBoxH = ""; |
||
72 | Art = psart; |
||
73 | isPDF = pdf; |
||
74 | UsedFonts.clear(); |
||
75 | Fonts = ""; |
||
76 | FontDesc = ""; |
||
77 | GraySc = false; |
||
78 | DoSep = false; |
||
79 | #ifdef HAVE_LIBZ |
||
80 | CompAvail = true; |
||
81 | #else |
||
82 | CompAvail = false; |
||
83 | #endif |
||
84 | GrayCalc = "/setcmykcolor {exch 0.11 mul add exch 0.59 mul add exch 0.3 mul add\n"; |
||
85 | GrayCalc += " dup 1 gt {pop 1} if 1 exch sub oldsetgray} bind def\n"; |
||
86 | GrayCalc += "/setrgbcolor {0.11 mul exch 0.59 mul add exch 0.3 mul add\n"; |
||
87 | GrayCalc += " oldsetgray} bind def\n"; |
||
88 | Farben = "%%CMYKCustomColor: "; |
||
89 | FNamen = "%%DocumentCustomColors: "; |
||
90 | CListe::Iterator itf; |
||
91 | int c, m, y, k; |
||
92 | bool erst = true; |
||
93 | for (itf = DocColors.begin(); itf != DocColors.end(); ++itf) |
||
94 | { |
||
95 | if ((itf.key() != "Cyan") && (itf.key() != "Magenta") && (itf.key() != "Yellow") && (itf.key() != "Black")) |
||
96 | { |
||
97 | DocColors[itf.key()].getCMYK(&c, &m, &y, &k); |
||
98 | if (!erst) |
||
99 | { |
||
100 | Farben += "%%+ "; |
||
101 | FNamen += "%%+ "; |
||
102 | } |
||
103 | Farben += ToStr(float(c) / 255) + " " + ToStr(float(m) / 255) + " "; |
||
104 | Farben += ToStr(float(y) / 255) + " " + ToStr(float(k) / 255) + " (" + itf.key() + ")\n"; |
||
105 | FNamen += "(" + itf.key() + ")\n"; |
||
106 | erst = false; |
||
107 | } |
||
108 | } |
||
109 | QMap<QString,QFont>::Iterator it; |
||
110 | int a = 0; |
||
111 | for (it = DocFonts.begin(); it != DocFonts.end(); ++it) |
||
112 | { |
||
113 | UsedFonts.insert(it.key(), "/Fo"+IToStr(a)); |
||
114 | CHset = AllFonts[it.key()]->FontEnc; |
||
115 | if ((CHset == "iso8859-1") || (CHset == "ascii-0") || (CHset == "iso8859-15")) |
||
116 | Fonts += "/"+AllFonts[it.key()]->RealName()+" /Fo"+IToStr(a)+" cf ef\n"; |
||
117 | if (CHset == "iso8859-2") |
||
118 | { |
||
119 | Fonts += "/"+AllFonts[it.key()]->RealName()+" /Fo"+IToStr(a)+" iso2f ef\n"; |
||
120 | IsoInUse = 2; |
||
121 | } |
||
122 | if (CHset == "iso8859-3") |
||
123 | { |
||
124 | Fonts += "/"+AllFonts[it.key()]->RealName()+" /Fo"+IToStr(a)+" iso3f ef\n"; |
||
125 | IsoInUse = 3; |
||
126 | } |
||
127 | if (CHset == "iso8859-4") |
||
128 | { |
||
129 | Fonts += "/"+AllFonts[it.key()]->RealName()+" /Fo"+IToStr(a)+" iso4f ef\n"; |
||
130 | IsoInUse = 4; |
||
131 | } |
||
132 | if (CHset == "iso8859-5") |
||
133 | { |
||
134 | Fonts += "/"+AllFonts[it.key()]->RealName()+" /Fo"+IToStr(a)+" iso5f ef\n"; |
||
135 | IsoInUse = 5; |
||
136 | } |
||
137 | if (CHset == "iso8859-7") |
||
138 | { |
||
139 | Fonts += "/"+AllFonts[it.key()]->RealName()+" /Fo"+IToStr(a)+" iso7f ef\n"; |
||
140 | IsoInUse = 7; |
||
141 | } |
||
142 | if (CHset == "iso8859-9") |
||
143 | { |
||
144 | Fonts += "/"+AllFonts[it.key()]->RealName()+" /Fo"+IToStr(a)+" iso9f ef\n"; |
||
145 | IsoInUse = 9; |
||
146 | } |
||
147 | if (CHset == "iso8859-10") |
||
148 | { |
||
149 | Fonts += "/"+AllFonts[it.key()]->RealName()+" /Fo"+IToStr(a)+" iso10f ef\n"; |
||
150 | IsoInUse = 10; |
||
151 | } |
||
152 | if (CHset == "iso8859-13") |
||
153 | { |
||
154 | Fonts += "/"+AllFonts[it.key()]->RealName()+" /Fo"+IToStr(a)+" iso13f ef\n"; |
||
155 | IsoInUse = 13; |
||
156 | } |
||
157 | if (CHset.startsWith("koi8")) |
||
158 | { |
||
159 | Fonts += "/"+AllFonts[it.key()]->RealName()+" /Fo"+IToStr(a)+" koi8f ef\n"; |
||
160 | IsoInUse = 99; |
||
161 | } |
||
162 | if (CHset == "adobe-fontspecific") |
||
163 | Fonts += "/Fo"+IToStr(a)+" /"+AllFonts[it.key()]->RealName()+" findfont definefont pop\n"; |
||
164 | if (AllFonts[it.key()]->EmbedPS) |
||
165 | { |
||
166 | QString tmp; |
||
167 | if(AllFonts[it.key()]->EmbedFont(tmp)) |
||
168 | { |
||
169 | GListe gl; |
||
170 | AllFonts[it.key()]->GlNames(&gl); |
||
171 | GlyphsOfFont.insert(it.key(), gl); |
||
172 | FontDesc += "%%BeginFont: " + AllFonts[it.key()]->RealName() + "\n"; |
||
173 | FontDesc += tmp + "\n%%EndFont\n"; |
||
174 | } |
||
175 | } |
||
176 | a++; |
||
177 | } |
||
178 | Prolog = "%%BeginProlog\n"; |
||
179 | Prolog += "/Scribusdict 100 dict def\n"; |
||
180 | Prolog += "Scribusdict begin\n"; |
||
181 | Prolog += "/sp {showpage} bind def\n"; |
||
182 | Prolog += "/oldsetgray /setgray load def\n"; |
||
183 | Prolog += "/cmyk {setcmykcolor} def\n"; |
||
184 | Prolog += "/m {moveto} bind def\n"; |
||
185 | Prolog += "/li {lineto} bind def\n"; |
||
186 | Prolog += "/cl {closepath} bind def\n"; |
||
187 | Prolog += "/gs {gsave} bind def\n"; |
||
188 | Prolog += "/gr {grestore} bind def\n"; |
||
189 | Prolog += "/tr {translate} bind def\n"; |
||
190 | Prolog += "/ro {rotate} bind def\n"; |
||
191 | Prolog += "/sh {show} bind def\n"; |
||
192 | Prolog += "/ftt {currentfont /FontType get 42 eq { 1000 } { 1 } ifelse div} bind def\n"; |
||
193 | Prolog += "/shg {setcmykcolor moveto glyphshow} def\n"; |
||
194 | Prolog += "/shm {setcmykcolor moveto\n"; |
||
195 | Prolog += " dup (\\55) eq\n"; |
||
196 | Prolog += " {pop /hyphen glyphshow}\n"; |
||
197 | Prolog += " {show}\n"; |
||
198 | Prolog += " ifelse} def\n"; |
||
199 | Prolog += "/sc {scale} bind def\n"; |
||
200 | Prolog += "/se {selectfont} bind def\n"; |
||
201 | Prolog += "/sf {setfont} bind def\n"; |
||
202 | Prolog += "/sw {setlinewidth} bind def\n"; |
||
203 | Prolog += "/srt {2 setlinecap currentfont dup /FontMatrix get\n"; |
||
204 | Prolog += " exch /FontInfo get dup /UnderlinePosition get ftt exch\n"; |
||
205 | Prolog += " /UnderlineThickness get ftt 3 -1 roll dtransform\n"; |
||
206 | Prolog += " setlinewidth 0 exch rmoveto stringwidth rlineto stroke} bind def\n"; |
||
207 | Prolog += "/srd {2 setlinecap currentfont dup /FontMatrix get\n"; |
||
208 | Prolog += " exch /FontInfo get dup /UnderlinePosition get ftt exch\n"; |
||
209 | Prolog += " /UnderlineThickness get ftt 3 -1 roll dtransform\n"; |
||
210 | Prolog += " setlinewidth pop stringwidth rlineto stroke} bind def\n"; |
||
211 | Prolog += "/f {findfont} bind def\n"; |
||
212 | Prolog += "/mf {makefont} bind def\n"; |
||
213 | Prolog += "/ss {scalefont setfont} bind def\n"; |
||
214 | Prolog += "/ci {newpath 0 0 1 0 360 arc} bind def\n"; |
||
215 | Prolog += "/fi {fill} bind def\n"; |
||
216 | Prolog += "/st {stroke} bind def\n"; |
||
217 | QString isoenc; |
||
218 | if (IsoInUse != 0) |
||
219 | { |
||
220 | switch (IsoInUse) |
||
221 | { |
||
222 | case 2: |
||
223 | Prolog += "/iso2f [\n"; |
||
224 | loadText(Epfad+"/lib/scribus/iso8859-2ps.enc", &isoenc); |
||
225 | Prolog += isoenc; |
||
226 | Prolog += "] def\n"; |
||
227 | break; |
||
228 | case 3: |
||
229 | Prolog += "/iso3f [\n"; |
||
230 | loadText(Epfad+"/lib/scribus/iso8859-3ps.enc", &isoenc); |
||
231 | Prolog += isoenc; |
||
232 | Prolog += "] def\n"; |
||
233 | break; |
||
234 | case 4: |
||
235 | Prolog += "/iso4f [\n"; |
||
236 | loadText(Epfad+"/lib/scribus/iso8859-4ps.enc", &isoenc); |
||
237 | Prolog += isoenc; |
||
238 | Prolog += "] def\n"; |
||
239 | break; |
||
240 | case 5: |
||
241 | Prolog += "/iso5f [\n"; |
||
242 | loadText(Epfad+"/lib/scribus/iso8859-5ps.enc", &isoenc); |
||
243 | Prolog += isoenc; |
||
244 | Prolog += "] def\n"; |
||
245 | break; |
||
246 | case 7: |
||
247 | Prolog += "/iso7f [\n"; |
||
248 | loadText(Epfad+"/lib/scribus/iso8859-7ps.enc", &isoenc); |
||
249 | Prolog += isoenc; |
||
250 | Prolog += "] def\n"; |
||
251 | break; |
||
252 | case 9: |
||
253 | Prolog += "/iso9f [\n"; |
||
254 | loadText(Epfad+"/lib/scribus/iso8859-9ps.enc", &isoenc); |
||
255 | Prolog += isoenc; |
||
256 | Prolog += "] def\n"; |
||
257 | break; |
||
258 | case 10: |
||
259 | Prolog += "/iso10f [\n"; |
||
260 | loadText(Epfad+"/lib/scribus/iso8859-10ps.enc", &isoenc); |
||
261 | Prolog += isoenc; |
||
262 | Prolog += "] def\n"; |
||
263 | break; |
||
264 | case 13: |
||
265 | Prolog += "/iso13f [\n"; |
||
266 | loadText(Epfad+"/lib/scribus/iso8859-13ps.enc", &isoenc); |
||
267 | Prolog += isoenc; |
||
268 | Prolog += "] def\n"; |
||
269 | break; |
||
270 | case 99: |
||
271 | Prolog += "/koi8f [\n"; |
||
272 | loadText(Epfad+"/lib/scribus/koi8ps.enc", &isoenc); |
||
273 | Prolog += isoenc; |
||
274 | Prolog += "] def\n"; |
||
275 | break; |
||
276 | } |
||
277 | } |
||
278 | Prolog += "/cf [\n"; |
||
279 | Prolog += " 16#2d /hyphen\n"; |
||
280 | Prolog += " 16#80 /Euro\n"; |
||
281 | Prolog += " 16#82 /quotesinglbase\n"; |
||
282 | Prolog += " 16#83 /florin\n"; |
||
283 | Prolog += " 16#84 /quotedblbase\n"; |
||
284 | Prolog += " 16#85 /ellipsis\n"; |
||
285 | Prolog += " 16#86 /dagger\n"; |
||
286 | Prolog += " 16#87 /daggerdbl\n"; |
||
287 | Prolog += " 16#88 /circumflex\n"; |
||
288 | Prolog += " 16#89 /perthousand\n"; |
||
289 | Prolog += " 16#8a /Scaron\n"; |
||
290 | Prolog += " 16#8b /guilsinglleft\n"; |
||
291 | Prolog += " 16#8c /OE\n"; |
||
292 | Prolog += " 16#8e /zcaron\n"; |
||
293 | Prolog += " 16#91 /quoteleft\n"; |
||
294 | Prolog += " 16#92 /quoteright\n"; |
||
295 | Prolog += " 16#93 /quotedblleft\n"; |
||
296 | Prolog += " 16#94 /quotedblright\n"; |
||
297 | Prolog += " 16#95 /bullet\n"; |
||
298 | Prolog += " 16#96 /endash\n"; |
||
299 | Prolog += " 16#97 /emdash\n"; |
||
300 | Prolog += " 16#98 /tilde\n"; |
||
301 | Prolog += " 16#99 /trademark\n"; |
||
302 | Prolog += " 16#9a /scaron\n"; |
||
303 | Prolog += " 16#9b /guilsinglright\n"; |
||
304 | Prolog += " 16#9c /oe\n"; |
||
305 | Prolog += " 16#9e /zcaron\n"; |
||
306 | Prolog += " 16#9f /Ydieresis\n"; |
||
307 | Prolog += "] def\n"; |
||
308 | Prolog += "/ski /ISOLatin1Encoding where{pop true}{false}ifelse def\n"; |
||
309 | Prolog += "/reencodesmalldict 12 dict def\n"; |
||
310 | Prolog += "/ef {\n"; |
||
311 | Prolog += " reencodesmalldict begin\n"; |
||
312 | Prolog += " /newcodesandnames exch def\n"; |
||
313 | Prolog += " /newfontname exch def\n"; |
||
314 | Prolog += " /basefontname exch def\n"; |
||
315 | Prolog += " /basefontdict basefontname findfont def\n"; |
||
316 | Prolog += " /newfont basefontdict maxlength dict def\n"; |
||
317 | Prolog += " basefontdict\n"; |
||
318 | Prolog += " {\n"; |
||
319 | Prolog += " exch dup /FID ne\n"; |
||
320 | Prolog += " {\n"; |
||
321 | Prolog += " dup /Encoding eq\n"; |
||
322 | Prolog += " {\n"; |
||
323 | Prolog += " ski\n"; |
||
324 | Prolog += " {\n"; |
||
325 | Prolog += " exch pop\n"; |
||
326 | Prolog += " ISOLatin1Encoding dup length array copy\n"; |
||
327 | Prolog += " }{\n"; |
||
328 | Prolog += " exch dup length array copy\n"; |
||
329 | Prolog += " }\n"; |
||
330 | Prolog += " ifelse\n"; |
||
331 | Prolog += " newfont 3 1 roll put\n"; |
||
332 | Prolog += " }{\n"; |
||
333 | Prolog += " exch newfont 3 1 roll put\n"; |
||
334 | Prolog += " }\n"; |
||
335 | Prolog += " ifelse\n"; |
||
336 | Prolog += " }{\n"; |
||
337 | Prolog += " pop pop\n"; |
||
338 | Prolog += " }\n"; |
||
339 | Prolog += " ifelse\n"; |
||
340 | Prolog += " } forall\n"; |
||
341 | Prolog += " newfont /FontName newfontname put\n"; |
||
342 | Prolog += " newcodesandnames aload pop\n"; |
||
343 | Prolog += " newcodesandnames length 2 idiv\n"; |
||
344 | Prolog += " {\n"; |
||
345 | Prolog += " newfont /Encoding get 3 1 roll put\n"; |
||
346 | Prolog += " } repeat\n"; |
||
347 | Prolog += " newfontname newfont definefont pop\n"; |
||
348 | Prolog += " end\n"; |
||
349 | Prolog += " } def\n"; |
||
350 | Prolog += "/bEPS {\n"; |
||
351 | Prolog += " /b4_Inc_state save def\n"; |
||
352 | Prolog += " /dict_count countdictstack def\n"; |
||
353 | Prolog += " /op_count count 1 sub def\n"; |
||
354 | Prolog += " userdict begin\n"; |
||
355 | Prolog += " /showpage { } def\n"; |
||
356 | Prolog += " 0 setgray 0 setlinecap\n"; |
||
357 | Prolog += " 1 setlinewidth 0 setlinejoin\n"; |
||
358 | Prolog += " 10 setmiterlimit [ ] 0 setdash newpath\n"; |
||
359 | Prolog += " /languagelevel where\n"; |
||
360 | Prolog += " {pop languagelevel\n"; |
||
361 | Prolog += " 1 ne\n"; |
||
362 | Prolog += " {false setstrokeadjust false setoverprint\n"; |
||
363 | Prolog += " } if } if } bind def\n"; |
||
364 | Prolog += "/eEPS { count op_count sub {pop} repeat\n"; |
||
365 | Prolog += " countdictstack dict_count sub {end} repeat\n"; |
||
366 | Prolog += " b4_Inc_state restore } bind def\n"; |
||
367 | Prolog += " end\n"; |
||
368 | Prolog += "%%EndProlog\n"; |
||
369 | } |
||
370 | PSLib::~PSLib() |
||
371 | { |
||
372 | } |
||
373 | |||
374 | void PSLib::PutSeite(QString c) |
||
375 | { |
||
376 | QTextStream t(&Spool); |
||
377 | t.writeRawBytes(c, c.length()); |
||
378 | } |
||
379 | |||
380 | void PSLib::PutDoc(QString c) |
||
381 | { |
||
382 | QTextStream t(&Spool); |
||
383 | t.writeRawBytes(c, c.length()); |
||
384 | } |
||
385 | |||
386 | QString PSLib::ToStr(float c) |
||
387 | { |
||
388 | QString cc; |
||
389 | return cc.setNum(c); |
||
390 | } |
||
391 | |||
392 | QString PSLib::IToStr(int c) |
||
393 | { |
||
394 | QString cc; |
||
395 | return cc.setNum(c); |
||
396 | } |
||
397 | |||
398 | void PSLib::PS_set_Info(QString art, QString was) |
||
399 | { |
||
400 | if (art == "Author") |
||
401 | User = was; |
||
402 | if (art == "Creator") |
||
403 | Creator = was; |
||
404 | if (art == "Title") |
||
405 | Titel = was; |
||
406 | } |
||
407 | |||
408 | bool PSLib::PS_set_file(QString fn) |
||
409 | { |
||
410 | Spool.setName(fn); |
||
411 | return Spool.open(IO_WriteOnly); |
||
412 | } |
||
413 | |||
414 | void PSLib::PS_begin_doc(int Ori, float breite, float hoehe, int numpage) |
||
415 | { |
||
416 | PutDoc(Header); |
||
417 | PutDoc("%%For: " + User + "\n"); |
||
418 | PutDoc("%%Title: " + Titel + "\n"); |
||
419 | PutDoc("%%Creator: " + Creator + "\n"); |
||
420 | PutDoc("%%Pages: " + IToStr(numpage) + "\n"); |
||
421 | BBox = "%%BoundingBox: 0 0 " + IToStr(qRound(breite)) + " " + IToStr(qRound(hoehe)) + "\n"; |
||
422 | BBoxH = "%%HiResBoundingBox: 0 0 " + ToStr(breite) + " " + ToStr(hoehe) + "\n"; |
||
423 | if (!Art) |
||
424 | { |
||
425 | PutDoc(BBox); |
||
426 | PutDoc(BBoxH); |
||
427 | } |
||
428 | PutDoc(FNamen); |
||
429 | PutDoc(Farben); |
||
430 | PutDoc("%%LanguageLevel: 3\n"); |
||
431 | PutDoc("%%EndComments\n"); |
||
432 | PutDoc(Prolog); |
||
433 | PutDoc("%%BeginSetup\n"); |
||
434 | PutDoc("/pdfmark where {pop} {userdict /pdfmark /cleartomark load put} ifelse\n"); |
||
435 | if (FontDesc != "") |
||
436 | { |
||
437 | PutDoc(FontDesc); |
||
438 | } |
||
439 | PutDoc("Scribusdict begin\n"); |
||
440 | PutDoc(Fonts); |
||
441 | if (GraySc) |
||
442 | PutDoc(GrayCalc); |
||
443 | PutDoc("%%EndSetup\n"); |
||
444 | if ((Art) && (Ori != 0)) |
||
445 | { |
||
446 | PutSeite("<< /PageSize [ "+ToStr(breite)+" "+ToStr(hoehe)+" ]\n"); |
||
447 | // if (Ori != 0) |
||
448 | PutSeite("/Orientation 3\n"); |
||
449 | PutSeite(">> setpagedevice\n"); |
||
450 | } |
||
451 | Prolog = ""; |
||
452 | FontDesc = ""; |
||
453 | } |
||
454 | |||
455 | QString PSLib::PSEncode(QString in) |
||
456 | { |
||
457 | QString tmp = ""; |
||
458 | QString cc; |
||
459 | for (uint d = 0; d < in.length(); ++d) |
||
460 | { |
||
461 | cc = in.at(d); |
||
462 | if ((cc == "(") || (cc == ")") || (cc == "\\")) |
||
463 | tmp += "\\"; |
||
464 | tmp += cc; |
||
465 | } |
||
466 | tmp = tmp.simplifyWhiteSpace().replace( QRegExp("\\s"), "" ); |
||
467 | return tmp; |
||
468 | } |
||
469 | |||
470 | void PSLib::PS_TemplateStart(QString Name, float breite, float hoehe) |
||
471 | { |
||
472 | PutDoc("/"+PSEncode(Name)+"\n<<\n"); |
||
473 | PutDoc("/FormType 1\n"); |
||
474 | PutDoc("/BBox [0 0 "+ToStr(breite)+" "+ToStr(hoehe)+"]\n"); |
||
475 | PutDoc("/Matrix [1 0 0 1 0 0]\n"); |
||
476 | PutDoc("/PaintProc\n{\n"); |
||
477 | } |
||
478 | |||
479 | void PSLib::PS_UseTemplate(QString Name) |
||
480 | { |
||
481 | PutDoc(PSEncode(Name)+" execform\n"); |
||
482 | } |
||
483 | |||
484 | void PSLib::PS_TemplateEnd() |
||
485 | { |
||
486 | PutDoc("pop } bind\n"); |
||
487 | PutDoc(">> def\n"); |
||
488 | } |
||
489 | |||
490 | void PSLib::PS_begin_page(float breite, float hoehe, struct Margs* Ma) |
||
491 | { |
||
492 | PDev = ToStr(Ma->Left) + " " + ToStr(Ma->Bottom) + " m\n"; |
||
493 | PDev += ToStr(breite - Ma->Right) + " " + ToStr(Ma->Bottom) + " li\n"; |
||
494 | PDev += ToStr(breite - Ma->Right) + " " + ToStr(hoehe - Ma->Top) + " li\n"; |
||
495 | PDev += ToStr(Ma->Left) + " " + ToStr(hoehe - Ma->Top) + " li cl clip newpath\n"; |
||
496 | Seiten++; |
||
497 | PutSeite("%%Page: " + IToStr(Seiten) + " " + IToStr(Seiten) + "\nsave\n" + PDev); |
||
498 | PutSeite("/DeviceCMYK setcolorspace\n"); |
||
499 | } |
||
500 | |||
501 | void PSLib::PS_end_page() |
||
502 | { |
||
503 | PutSeite("%%PageTrailer\nrestore\nsp\n"); |
||
504 | } |
||
505 | |||
506 | void PSLib::PS_curve(float x1, float y1, float x2, float y2, float x3, float y3) |
||
507 | { |
||
508 | PutSeite(ToStr(x1) + " " + ToStr(y1) + " " + ToStr(x2) + " " + ToStr(y2) + " " + ToStr(x3) + " " + ToStr(y3) + " curveto\n"); |
||
509 | } |
||
510 | |||
511 | void PSLib::PS_moveto(float x, float y) |
||
512 | { |
||
513 | PutSeite(ToStr(x) + " " + ToStr(y) + " m\n"); |
||
514 | } |
||
515 | |||
516 | void PSLib::PS_lineto(float x, float y) |
||
517 | { |
||
518 | PutSeite(ToStr(x) + " " + ToStr(y) + " li\n"); |
||
519 | } |
||
520 | |||
521 | void PSLib::PS_closepath() |
||
522 | { |
||
523 | PutSeite("cl\n"); |
||
524 | } |
||
525 | |||
526 | void PSLib::PS_translate(float x, float y) |
||
527 | { |
||
528 | PutSeite(ToStr(x) + " " + ToStr(y) + " tr\n"); |
||
529 | } |
||
530 | |||
531 | void PSLib::PS_scale(float x, float y) |
||
532 | { |
||
533 | PutSeite(ToStr(x) + " " + ToStr(y) + " sc\n"); |
||
534 | } |
||
535 | |||
536 | void PSLib::PS_rotate(float x) |
||
537 | { |
||
538 | PutSeite(ToStr(x) + " ro\n"); |
||
539 | } |
||
540 | |||
541 | void PSLib::PS_clip(bool mu) |
||
542 | { |
||
543 | if (mu) |
||
544 | PutSeite("eoclip newpath\n"); |
||
545 | else |
||
546 | PutSeite("clip newpath\n"); |
||
547 | } |
||
548 | |||
549 | void PSLib::PS_save() |
||
550 | { |
||
551 | PutSeite("gs\n"); |
||
552 | } |
||
553 | |||
554 | void PSLib::PS_restore() |
||
555 | { |
||
556 | PutSeite("gr\n"); |
||
557 | } |
||
558 | |||
559 | void PSLib::PS_setcmykcolor_fill(float c, float m, float y, float k) |
||
560 | { |
||
561 | FillColor = ToStr(c) + " " + ToStr(m) + " " + ToStr(y) + " " + ToStr(k); |
||
562 | } |
||
563 | |||
564 | void PSLib::PS_setcmykcolor_dummy() |
||
565 | { |
||
566 | PutSeite("0 0 0 0 cmyk\n"); |
||
567 | } |
||
568 | |||
569 | void PSLib::PS_setcmykcolor_stroke(float c, float m, float y, float k) |
||
570 | { |
||
571 | StrokeColor = ToStr(c) + " " + ToStr(m) + " " + ToStr(y) + " " + ToStr(k); |
||
572 | } |
||
573 | |||
574 | void PSLib::PS_setlinewidth(float w) |
||
575 | { |
||
576 | PutSeite(ToStr(w) + " sw\n"); |
||
577 | LineW = w; |
||
578 | } |
||
579 | |||
580 | void PSLib::PS_setdash(Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo) |
||
581 | { |
||
582 | QString Dt = ToStr(QMAX(LineW, 1)); |
||
583 | QString Da = ToStr(QMAX(3*LineW, 1)); |
||
584 | switch (st) |
||
585 | { |
||
586 | case Qt::SolidLine: |
||
587 | PutSeite("[] 0 setdash\n"); |
||
588 | break; |
||
589 | case Qt::DashLine: |
||
590 | PutSeite("["+Da+" "+Dt+"] 0 setdash\n"); |
||
591 | break; |
||
592 | case Qt::DotLine: |
||
593 | PutSeite("["+Dt+"] 0 setdash\n"); |
||
594 | break; |
||
595 | case Qt::DashDotLine: |
||
596 | PutSeite("["+Da+" "+Dt+" "+Dt+" "+Dt+"] 0 setdash\n"); |
||
597 | break; |
||
598 | case Qt::DashDotDotLine: |
||
599 | PutSeite("["+Da+" "+Dt+" "+Dt+" "+Dt+" "+Dt+" "+Dt+"] 0 setdash\n"); |
||
600 | break; |
||
601 | default: |
||
602 | PutSeite("[] 0 setdash\n"); |
||
603 | break; |
||
604 | } |
||
605 | switch (ca) |
||
606 | { |
||
607 | case Qt::FlatCap: |
||
608 | PutSeite("0 setlinecap\n"); |
||
609 | break; |
||
610 | case Qt::SquareCap: |
||
611 | PutSeite("2 setlinecap\n"); |
||
612 | break; |
||
613 | case Qt::RoundCap: |
||
614 | PutSeite("1 setlinecap\n"); |
||
615 | break; |
||
616 | default: |
||
617 | PutSeite("0 setlinecap\n"); |
||
618 | break; |
||
619 | } |
||
620 | switch (jo) |
||
621 | { |
||
622 | case Qt::MiterJoin: |
||
623 | PutSeite("0 setlinejoin\n"); |
||
624 | break; |
||
625 | case Qt::BevelJoin: |
||
626 | PutSeite("2 setlinejoin\n"); |
||
627 | break; |
||
628 | case Qt::RoundJoin: |
||
629 | PutSeite("1 setlinejoin\n"); |
||
630 | break; |
||
631 | default: |
||
632 | PutSeite("0 setlinejoin\n"); |
||
633 | break; |
||
634 | } |
||
635 | } |
||
636 | |||
637 | void PSLib::PS_selectfont(QString f, int s) |
||
638 | { |
||
639 | PutSeite(UsedFonts[f] + " " + IToStr(s) + " se\n"); |
||
640 | } |
||
641 | |||
642 | void PSLib::PS_fill(bool mu) |
||
643 | { |
||
644 | if (mu) |
||
645 | PutSeite(FillColor + " cmyk eofill\n"); |
||
646 | else |
||
647 | PutSeite(FillColor + " cmyk fi\n"); |
||
648 | } |
||
649 | |||
650 | void PSLib::PS_stroke() |
||
651 | { |
||
652 | PutSeite(StrokeColor + " cmyk st\n"); |
||
653 | } |
||
654 | |||
655 | void PSLib::PS_fill_stroke(bool mu) |
||
656 | { |
||
657 | PS_save(); |
||
658 | PS_fill(mu); |
||
659 | PS_restore(); |
||
660 | PS_stroke(); |
||
661 | } |
||
662 | |||
663 | void PSLib::PS_newpath() |
||
664 | { |
||
665 | PutSeite("newpath\n"); |
||
666 | } |
||
667 | |||
668 | void PSLib::PS_GradientCol1(float c, float m, float y, float k) |
||
669 | { |
||
670 | GrColor1 = ToStr(c) + " " + ToStr(m) + " " + ToStr(y) + " " + ToStr(k); |
||
671 | } |
||
672 | |||
673 | void PSLib::PS_GradientCol2(float c, float m, float y, float k) |
||
674 | { |
||
675 | GrColor2 = ToStr(c) + " " + ToStr(m) + " " + ToStr(y) + " " + ToStr(k); |
||
676 | } |
||
677 | |||
678 | void PSLib::PS_LinGradient(float w, float h, int item, int grad, bool mu) |
||
679 | { |
||
680 | if (item == 1) |
||
681 | PutSeite("-"+ToStr(w / 2.0)+" "+ToStr(-h / 2.0)+" tr\n"); |
||
682 | if (mu) |
||
683 | PutSeite("eoclip\n"); |
||
684 | else |
||
685 | PutSeite("clip\n"); |
||
686 | PutSeite("<<\n"); |
||
687 | PutSeite("/ShadingType 2\n"); |
||
688 | if (DoSep) |
||
689 | PutSeite("/ColorSpace /DeviceGray\n"); |
||
690 | else |
||
691 | PutSeite("/ColorSpace /DeviceCMYK\n"); |
||
692 | switch (grad) |
||
693 | { |
||
694 | case 1: |
||
695 | PutSeite("/Coords [0 "+ToStr(h / 2.0)+" "+ToStr(w)+" "+ToStr(h / 2.0)+"]\n"); |
||
696 | break; |
||
697 | case 2: |
||
698 | PutSeite("/Coords ["+ToStr(w / 2.0)+" 0 "+ToStr(w / 2.0)+" "+ToStr(h)+"]\n"); |
||
699 | break; |
||
700 | case 3: |
||
701 | PutSeite("/Coords [0 0 "+ToStr(w)+" "+ToStr(h)+"]\n"); |
||
702 | break; |
||
703 | case 4: |
||
704 | PutSeite("/Coords ["+ToStr(w)+" 0 0 "+ToStr(h)+"]\n"); |
||
705 | break; |
||
706 | } |
||
707 | PutSeite("/BBox [0 "+ToStr(h)+" "+ToStr(w)+" 0]\n"); |
||
708 | if (DoSep) |
||
709 | PutSeite("/Background [0]\n"); |
||
710 | else |
||
711 | PutSeite("/Background ["+FillColor+"]\n"); |
||
712 | PutSeite("/Extend [false false]\n"); |
||
713 | PutSeite("/Function\n"); |
||
714 | PutSeite("<<\n"); |
||
715 | PutSeite("/FunctionType 2\n"); |
||
716 | PutSeite("/Domain [0 1]\n"); |
||
717 | if (DoSep) |
||
718 | { |
||
719 | int pla = Plate - 1; |
||
720 | if (pla < 0) |
||
721 | pla = 3; |
||
722 | QStringList cols1 = QStringList::split(" ", GrColor2); |
||
723 | QStringList cols2 = QStringList::split(" ", GrColor1); |
||
724 | PutSeite("/C1 ["+ToStr(1-cols1[pla].toFloat())+"]\n"); |
||
725 | PutSeite("/C0 ["+ToStr(1-cols2[pla].toFloat())+"]\n"); |
||
726 | } |
||
727 | else |
||
728 | { |
||
729 | PutSeite("/C0 ["+GrColor1+"]\n"); |
||
730 | PutSeite("/C1 ["+GrColor2+"]\n"); |
||
731 | } |
||
732 | PutSeite("/N 1\n"); |
||
733 | PutSeite(">>\n"); |
||
734 | PutSeite(">>\n"); |
||
735 | PutSeite("shfill\n"); |
||
736 | } |
||
737 | |||
738 | void PSLib::PS_RadGradient(float w, float h, int item, bool mu) |
||
739 | { |
||
740 | float w2, h2, rad; |
||
741 | w2 = w / 2.0; |
||
742 | h2 = h / 2.0; |
||
743 | rad = QMIN(w, fabs(h)) / 2.0; |
||
744 | PutSeite("/cmtx matrix currentmatrix def\n"); |
||
745 | if (mu) |
||
746 | PutSeite("eoclip\n"); |
||
747 | else |
||
748 | PutSeite("clip\n"); |
||
749 | PutSeite("<<\n"); |
||
750 | PutSeite("/ShadingType 3\n"); |
||
751 | if (DoSep) |
||
752 | PutSeite("/ColorSpace /DeviceGray\n"); |
||
753 | else |
||
754 | PutSeite("/ColorSpace /DeviceCMYK\n"); |
||
755 | PutSeite("/Coords ["+ToStr(w2)+" "+ToStr(h2)+" 0 "+ToStr(w2)+" "+ToStr(h2)+" "+ToStr(rad)+"]\n"); |
||
756 | PutSeite("/BBox [0 "+ToStr(h)+" "+ToStr(w)+" 0]\n"); |
||
757 | if (DoSep) |
||
758 | PutSeite("/Background [0]\n"); |
||
759 | else |
||
760 | PutSeite("/Background ["+FillColor+"]\n"); |
||
761 | PutSeite("/Extend [true true]\n"); |
||
762 | PutSeite("/Function\n"); |
||
763 | PutSeite("<<\n"); |
||
764 | PutSeite("/FunctionType 2\n"); |
||
765 | PutSeite("/Domain [0 1]\n"); |
||
766 | if (DoSep) |
||
767 | { |
||
768 | int pla = Plate - 1; |
||
769 | if (pla < 0) |
||
770 | pla = 3; |
||
771 | QStringList cols1 = QStringList::split(" ", GrColor2); |
||
772 | QStringList cols2 = QStringList::split(" ", GrColor1); |
||
773 | PutSeite("/C0 ["+ToStr(1-cols1[pla].toFloat())+"]\n"); |
||
774 | PutSeite("/C1 ["+ToStr(1-cols2[pla].toFloat())+"]\n"); |
||
775 | } |
||
776 | else |
||
777 | { |
||
778 | PutSeite("/C0 ["+GrColor2+"]\n"); |
||
779 | PutSeite("/C1 ["+GrColor1+"]\n"); |
||
780 | } |
||
781 | PutSeite("/N 1\n"); |
||
782 | PutSeite(">>\n"); |
||
783 | PutSeite(">>\n"); |
||
784 | if (item == 1) |
||
785 | { |
||
786 | if (w > fabs(h)) |
||
787 | PutSeite("-"+ToStr(w2*(w2 / rad))+" "+ToStr(fabs(h2))+" tr\n"); |
||
788 | else |
||
789 | PutSeite("-"+ToStr(w2*(w2 / rad))+" "+ToStr(fabs(h2)*(fabs(h2) /rad))+" tr\n"); |
||
790 | } |
||
791 | else |
||
792 | { |
||
793 | if (w > fabs(h)) |
||
794 | PutSeite("-"+ToStr(w2*(w2 / rad)-w2)+" 0 tr\n"); |
||
795 | else |
||
796 | { |
||
797 | if (w < fabs(h)) |
||
798 | PutSeite("0 "+ToStr(fabs(h2)*(fabs(h2) /rad)-fabs(h2))+" tr\n"); |
||
799 | } |
||
800 | } |
||
801 | PutSeite(ToStr(w2 / rad)+" "+ToStr(fabs(h2) / rad)+" scale\n"); |
||
802 | PutSeite("shfill\n"); |
||
803 | PutSeite("cmtx setmatrix\n"); |
||
804 | } |
||
805 | |||
806 | void PSLib::PS_underline(QCString ch, float x, float y) |
||
807 | { |
||
808 | PS_moveto(x, y); |
||
809 | PutSeite("("+QString(ch)+") srt\n"); |
||
810 | } |
||
811 | |||
812 | void PSLib::PS_strikeout(QCString ch, float x, float y) |
||
813 | { |
||
814 | PS_moveto(x, y); |
||
815 | PutSeite("("+QString(ch)+") srd\n"); |
||
816 | } |
||
817 | |||
818 | void PSLib::PS_show_xy(QCString ch, float x, float y) |
||
819 | { |
||
820 | PutSeite("("+QString(ch)+") "+ToStr(x)+" "+ToStr(y)+" "+StrokeColor+" shm\n"); |
||
821 | } |
||
822 | |||
823 | void PSLib::PS_show_xyG(QString font, QString ch, float x, float y) |
||
824 | { |
||
825 | QString Name; |
||
826 | uint cc = ch[0].unicode(); |
||
827 | if (GlyphsOfFont[font].contains(cc)) |
||
828 | Name = GlyphsOfFont[font][cc]; |
||
829 | else |
||
830 | Name = ".notdef"; |
||
831 | PutSeite("/"+Name+" "+ToStr(x)+" "+ToStr(y)+" "+StrokeColor+" shg\n"); |
||
832 | } |
||
833 | |||
834 | void PSLib::PS_show(float x, float y) |
||
835 | { |
||
836 | PS_moveto(x, y); |
||
837 | PutSeite("/hyphen glyphshow\n"); |
||
838 | } |
||
839 | |||
20 | Franz | 840 | void PSLib::PS_ImageData(bool inver, QString fn, QString Name, QString Prof, bool UseEmbedded, bool UseProf) |
3 | paul | 841 | { |
842 | QString tmp; |
||
843 | QFileInfo fi = QFileInfo(fn); |
||
844 | QString ext = fi.extension(false).lower(); |
||
845 | if (ext == "eps") |
||
846 | { |
||
847 | if (loadText(fn, &tmp)) |
||
848 | { |
||
849 | PutSeite("currentfile 1 (%ENDEPSDATA) /SubFileDecode filter /ReusableStreamDecode filter\n"); |
||
850 | PutSeite("%%BeginDocument: " + fi.fileName() + "\n"); |
||
851 | PutSeite(tmp+"\n"); |
||
852 | PutSeite("%ENDEPSDATA\n"); |
||
853 | PutSeite("%%EndDocument\n"); |
||
854 | PutSeite("/"+PSEncode(Name)+"Bild exch def\n"); |
||
855 | } |
||
856 | return; |
||
857 | } |
||
858 | QString ImgStr = ""; |
||
859 | QImage image; |
||
860 | #ifdef HAVE_CMS |
||
861 | QImage image2; |
||
862 | bool cmy = false; |
||
863 | if ((CMSuse) && (UseProf)) |
||
864 | { |
||
865 | image = LoadPict(fn); |
||
866 | image = image.convertDepth(32); |
||
867 | image2 = LoadPictCol(fn, Prof, UseEmbedded, &cmy); |
||
20 | Franz | 868 | if (inver) |
869 | { |
||
870 | image.invertPixels(); |
||
871 | image2.invertPixels(); |
||
872 | } |
||
3 | paul | 873 | ImgStr = ImageToCMYK_PS(&image2, -1, cmy); |
874 | } |
||
875 | else |
||
876 | { |
||
877 | image = LoadPict(fn); |
||
20 | Franz | 878 | if (inver) |
879 | image.invertPixels(); |
||
3 | paul | 880 | ImgStr = ImageToCMYK_PS(&image, -1, false); |
881 | } |
||
882 | #else |
||
883 | image = LoadPict(fn); |
||
884 | image = image.convertDepth(32); |
||
20 | Franz | 885 | if (inver) |
886 | image.invertPixels(); |
||
3 | paul | 887 | ImgStr = ImageToCMYK_PS(&image, -1, false); |
888 | #endif |
||
889 | if (CompAvail) |
||
890 | { |
||
891 | PutSeite("currentfile /ASCIIHexDecode filter /FlateDecode filter /ReusableStreamDecode filter\n"); |
||
892 | ImgStr = CompressStr(&ImgStr); |
||
893 | } |
||
894 | else |
||
895 | PutSeite("currentfile /ASCIIHexDecode filter /ReusableStreamDecode filter\n"); |
||
896 | ImgStr = String2Hex(&ImgStr); |
||
897 | PutSeite(ImgStr); |
||
898 | PutSeite("\n>\n"); |
||
899 | PutSeite("/"+PSEncode(Name)+"Bild exch def\n"); |
||
900 | ImgStr = ""; |
||
901 | if (image.hasAlphaBuffer()) |
||
902 | { |
||
903 | QImage iMask = image.createAlphaMask(); |
||
904 | ImgStr = MaskToTxt(&iMask, false); |
||
905 | if (CompAvail) |
||
906 | { |
||
907 | PutSeite("currentfile /ASCIIHexDecode filter /FlateDecode filter /ReusableStreamDecode filter\n"); |
||
908 | ImgStr = CompressStr(&ImgStr); |
||
909 | } |
||
910 | else |
||
911 | PutSeite("currentfile /ASCIIHexDecode filter /ReusableStreamDecode filter\n"); |
||
912 | ImgStr = String2Hex(&ImgStr); |
||
913 | PutSeite(ImgStr); |
||
914 | PutSeite("\n>\n"); |
||
915 | PutSeite("/"+PSEncode(Name)+"Mask exch def\n"); |
||
916 | } |
||
917 | } |
||
918 | |||
20 | Franz | 919 | void PSLib::PS_image(bool inver, float x, float y, QString fn, float scalex, float scaley, QString Prof, bool UseEmbedded, bool UseProf, QString Name) |
3 | paul | 920 | { |
921 | QString tmp; |
||
922 | QFileInfo fi = QFileInfo(fn); |
||
923 | QString ext = fi.extension(false).lower(); |
||
924 | if (ext == "eps") |
||
925 | { |
||
926 | if (loadText(fn, &tmp)) |
||
927 | { |
||
928 | if (Name != "") |
||
929 | { |
||
930 | PutSeite("bEPS\n"); |
||
931 | PutSeite(ToStr(scalex) + " " + ToStr(scaley) + " sc\n"); |
||
932 | PutSeite(ToStr(x) + " " + ToStr(y) + " tr\n"); |
||
933 | PutSeite(PSEncode(Name)+"Bild cvx exec\n"); |
||
934 | PutSeite(PSEncode(Name)+"Bild resetfile\n"); |
||
935 | PutSeite("eEPS\n"); |
||
936 | } |
||
937 | else |
||
938 | { |
||
939 | PutSeite("bEPS\n"); |
||
940 | PutSeite(ToStr(scalex) + " " + ToStr(scaley) + " sc\n"); |
||
941 | PutSeite(ToStr(x) + " " + ToStr(y) + " tr\n"); |
||
942 | PutSeite("%%BeginDocument: " + fi.fileName() + "\n"); |
||
943 | PutSeite(tmp+"\n"); |
||
944 | PutSeite("%%EndDocument\n"); |
||
945 | PutSeite("eEPS\n"); |
||
946 | } |
||
947 | } |
||
948 | } |
||
949 | else |
||
950 | { |
||
951 | QString ImgStr = ""; |
||
952 | QImage image; |
||
953 | #ifdef HAVE_CMS |
||
954 | QImage image2; |
||
955 | bool cmy = false; |
||
956 | if ((CMSuse) && (UseProf)) |
||
957 | { |
||
958 | image = LoadPict(fn); |
||
959 | image = image.convertDepth(32); |
||
960 | image2 = LoadPictCol(fn, Prof, UseEmbedded, &cmy); |
||
961 | } |
||
962 | else |
||
963 | { |
||
964 | image = LoadPict(fn); |
||
965 | image = image.convertDepth(32); |
||
966 | } |
||
20 | Franz | 967 | if (inver) |
968 | { |
||
969 | image.invertPixels(); |
||
970 | image2.invertPixels(); |
||
971 | } |
||
3 | paul | 972 | #else |
973 | image = LoadPict(fn); |
||
974 | image = image.convertDepth(32); |
||
20 | Franz | 975 | if (inver) |
976 | image.invertPixels(); |
||
3 | paul | 977 | #endif |
978 | int w = image.width(); |
||
979 | int h = image.height(); |
||
980 | PutSeite(ToStr(x*scalex) + " " + ToStr(y*scaley) + " tr\n"); |
||
981 | PutSeite(ToStr(scalex*w) + " " + ToStr(scaley*h) + " sc\n"); |
||
982 | if ((!DoSep) && (!GraySc)) |
||
983 | PutSeite("/DeviceCMYK setcolorspace\n"); |
||
984 | else |
||
985 | PutSeite("/DeviceGray setcolorspace\n"); |
||
986 | if (image.hasAlphaBuffer()) |
||
987 | { |
||
988 | QImage iMask = image.createAlphaMask(); |
||
989 | #ifdef HAVE_CMS |
||
990 | if ((CMSuse) && (UseProf)) |
||
991 | { |
||
992 | if (DoSep) |
||
993 | ImgStr = ImageToCMYK_PS(&image2, Plate, cmy); |
||
994 | else |
||
995 | { |
||
996 | if (GraySc) |
||
997 | ImgStr = ImageToCMYK_PS(&image2, -2, cmy); |
||
998 | else |
||
999 | ImgStr = ImageToCMYK_PS(&image2, -1, cmy); |
||
1000 | } |
||
1001 | } |
||
1002 | else |
||
1003 | { |
||
1004 | if (DoSep) |
||
1005 | ImgStr = ImageToCMYK_PS(&image, Plate, false); |
||
1006 | else |
||
1007 | { |
||
1008 | if (GraySc) |
||
1009 | ImgStr = ImageToCMYK_PS(&image, -2, false); |
||
1010 | else |
||
1011 | ImgStr = ImageToCMYK_PS(&image, -1, false); |
||
1012 | } |
||
1013 | } |
||
1014 | #else |
||
1015 | if (DoSep) |
||
1016 | ImgStr = ImageToCMYK_PS(&image, Plate, false); |
||
1017 | else |
||
1018 | { |
||
1019 | if (GraySc) |
||
1020 | ImgStr = ImageToCMYK_PS(&image, -2, false); |
||
1021 | else |
||
1022 | ImgStr = ImageToCMYK_PS(&image, -1, false); |
||
1023 | } |
||
1024 | #endif |
||
1025 | if (Name == "") |
||
1026 | { |
||
1027 | if (CompAvail) |
||
1028 | { |
||
1029 | PutSeite("currentfile /ASCIIHexDecode filter /FlateDecode filter /ReusableStreamDecode filter\n"); |
||
1030 | ImgStr = CompressStr(&ImgStr); |
||
1031 | } |
||
1032 | else |
||
1033 | PutSeite("currentfile /ASCIIHexDecode filter /ReusableStreamDecode filter\n"); |
||
1034 | ImgStr = String2Hex(&ImgStr); |
||
1035 | PutSeite(ImgStr); |
||
1036 | ImgStr = ""; |
||
1037 | PutSeite("\n>\n"); |
||
1038 | PutSeite("/Bild exch def\n"); |
||
1039 | ImgStr = MaskToTxt(&iMask, false); |
||
1040 | if (CompAvail) |
||
1041 | { |
||
1042 | PutSeite("currentfile /ASCIIHexDecode filter /FlateDecode filter /ReusableStreamDecode filter\n"); |
||
1043 | ImgStr = CompressStr(&ImgStr); |
||
1044 | } |
||
1045 | else |
||
1046 | PutSeite("currentfile /ASCIIHexDecode filter /ReusableStreamDecode filter\n"); |
||
1047 | ImgStr = String2Hex(&ImgStr); |
||
1048 | PutSeite(ImgStr); |
||
1049 | PutSeite("\n>\n"); |
||
1050 | PutSeite("/Mask exch def\n"); |
||
1051 | } |
||
1052 | PutSeite("<<\n"); |
||
1053 | PutSeite(" /PaintType 1\n"); |
||
1054 | PutSeite(" /PatternType 1\n"); |
||
1055 | PutSeite(" /TilingType 3\n"); |
||
1056 | PutSeite(" /BBox [ 0 0 1 1 ]\n"); |
||
1057 | PutSeite(" /XStep 2\n"); |
||
1058 | PutSeite(" /YStep 2\n"); |
||
1059 | PutSeite(" /PaintProc {\n"); |
||
1060 | PutSeite(" pop\n"); |
||
1061 | PutSeite(" 1 1 1 1 setcmykcolor\n"); |
||
1062 | PutSeite(" <<\n"); |
||
1063 | PutSeite(" /ImageType 1\n"); |
||
1064 | PutSeite(" /Height " + IToStr(h) + "\n"); |
||
1065 | PutSeite(" /Width " + IToStr(w) + "\n"); |
||
1066 | PutSeite(" /ImageMatrix [" + IToStr(w) + " 0 0 " + IToStr(-h) + " 0 " + IToStr(h) +"]\n"); |
||
1067 | if (DoSep) |
||
1068 | PutSeite(" /Decode [1 0]\n"); |
||
1069 | else |
||
1070 | { |
||
1071 | if (GraySc) |
||
1072 | PutSeite(" /Decode [1 0]\n"); |
||
1073 | else |
||
1074 | PutSeite(" /Decode [0 1 0 1 0 1 0 1]\n"); |
||
1075 | } |
||
1076 | PutSeite(" /BitsPerComponent 8\n"); |
||
1077 | PutSeite(" /DataSource "+PSEncode(Name)+"Bild\n"); |
||
1078 | PutSeite(" >>\n"); |
||
1079 | PutSeite(" image\n"); |
||
1080 | PutSeite(" }\n"); |
||
1081 | PutSeite(">> matrix makepattern setpattern\n"); |
||
1082 | PutSeite("<< /ImageType 1\n"); |
||
1083 | PutSeite(" /Width " + IToStr(w) + "\n"); |
||
1084 | PutSeite(" /Height " + IToStr(h) + "\n"); |
||
1085 | PutSeite(" /BitsPerComponent 1\n"); |
||
1086 | PutSeite(" /Decode [1 0]\n"); |
||
1087 | PutSeite(" /ImageMatrix [" + IToStr(w) + " 0 0 " + IToStr(-h) + " 0 " + IToStr(h) + "]\n"); |
||
1088 | PutSeite(" /DataSource "+PSEncode(Name)+"Mask\n"); |
||
1089 | PutSeite(">>\n"); |
||
1090 | PutSeite("imagemask\n"); |
||
1091 | if (Name != "") |
||
1092 | { |
||
1093 | PutSeite(PSEncode(Name)+"Bild resetfile\n"); |
||
1094 | PutSeite(PSEncode(Name)+"Mask resetfile\n"); |
||
1095 | } |
||
1096 | } |
||
1097 | else |
||
1098 | { |
||
1099 | PutSeite("<< /ImageType 1\n"); |
||
1100 | PutSeite(" /Width " + IToStr(w) + "\n"); |
||
1101 | PutSeite(" /Height " + IToStr(h) + "\n"); |
||
1102 | PutSeite(" /BitsPerComponent 8\n"); |
||
1103 | if (DoSep) |
||
1104 | PutSeite(" /Decode [1 0]\n"); |
||
1105 | else |
||
1106 | { |
||
1107 | if (GraySc) |
||
1108 | PutSeite(" /Decode [1 0]\n"); |
||
1109 | else |
||
1110 | PutSeite(" /Decode [0 1 0 1 0 1 0 1]\n"); |
||
1111 | } |
||
1112 | PutSeite(" /ImageMatrix [" + IToStr(w) + " 0 0 " + IToStr(-h) + " 0 " + IToStr(h) + "]\n"); |
||
1113 | if (Name != "") |
||
1114 | { |
||
1115 | PutSeite(" /DataSource "+PSEncode(Name)+"Bild >>\n"); |
||
1116 | PutSeite("image\n"); |
||
1117 | PutSeite(PSEncode(Name)+"Bild resetfile\n"); |
||
1118 | } |
||
1119 | else |
||
1120 | { |
||
1121 | if (CompAvail) |
||
1122 | PutSeite(" /DataSource currentfile /ASCIIHexDecode filter /FlateDecode filter >>\n"); |
||
1123 | else |
||
1124 | PutSeite(" /DataSource currentfile /ASCIIHexDecode filter >>\n"); |
||
1125 | PutSeite("image\n"); |
||
1126 | #ifdef HAVE_CMS |
||
1127 | if ((CMSuse) && (UseProf)) |
||
1128 | { |
||
1129 | if (DoSep) |
||
1130 | ImgStr = ImageToCMYK_PS(&image2, Plate, cmy); |
||
1131 | else |
||
1132 | { |
||
1133 | if (GraySc) |
||
1134 | ImgStr = ImageToCMYK_PS(&image2, -2, cmy); |
||
1135 | else |
||
1136 | ImgStr = ImageToCMYK_PS(&image2, -1, cmy); |
||
1137 | } |
||
1138 | } |
||
1139 | else |
||
1140 | { |
||
1141 | if (DoSep) |
||
1142 | ImgStr = ImageToCMYK_PS(&image, Plate, false); |
||
1143 | else |
||
1144 | { |
||
1145 | if (GraySc) |
||
1146 | ImgStr = ImageToCMYK_PS(&image, -2, false); |
||
1147 | else |
||
1148 | ImgStr = ImageToCMYK_PS(&image, -1, false); |
||
1149 | } |
||
1150 | } |
||
1151 | #else |
||
1152 | if (DoSep) |
||
1153 | ImgStr = ImageToCMYK_PS(&image, Plate, false); |
||
1154 | else |
||
1155 | { |
||
1156 | if (GraySc) |
||
1157 | ImgStr = ImageToCMYK_PS(&image, -2, false); |
||
1158 | else |
||
1159 | ImgStr = ImageToCMYK_PS(&image, -1, false); |
||
1160 | } |
||
1161 | #endif |
||
1162 | if (CompAvail) |
||
1163 | ImgStr = CompressStr(&ImgStr); |
||
1164 | ImgStr = String2Hex(&ImgStr); |
||
1165 | PutSeite(ImgStr); |
||
1166 | PutSeite("\n>\n"); |
||
1167 | } |
||
1168 | } |
||
1169 | } |
||
1170 | } |
||
1171 | |||
1172 | void PSLib::PS_plate(int nr) |
||
1173 | { |
||
1174 | switch (nr) |
||
1175 | { |
||
1176 | case 0: |
||
1177 | PutSeite("%%PlateColor Black\n"); |
||
1178 | PutSeite("/setcmykcolor {exch pop exch pop exch pop 1 exch sub oldsetgray} bind def\n"); |
||
1179 | PutSeite("/setrgbcolor {pop pop pop 1 oldsetgray} bind def\n"); |
||
1180 | break; |
||
1181 | case 1: |
||
1182 | PutSeite("%%PlateColor Cyan\n"); |
||
1183 | PutSeite("/setcmykcolor {pop pop pop 1 exch sub oldsetgray} bind def\n"); |
||
1184 | PutSeite("/setrgbcolor {pop pop oldsetgray} bind def\n"); |
||
1185 | break; |
||
1186 | case 2: |
||
1187 | PutSeite("%%PlateColor Magenta\n"); |
||
1188 | PutSeite("/setcmykcolor {pop pop exch pop 1 exch sub oldsetgray} bind def\n"); |
||
1189 | PutSeite("/setrgbcolor {pop exch pop oldsetgray} bind def\n"); |
||
1190 | break; |
||
1191 | case 3: |
||
1192 | PutSeite("%%PlateColor Yellow\n"); |
||
1193 | PutSeite("/setcmykcolor {pop exch pop exch pop 1 exch sub oldsetgray} bind def\n"); |
||
1194 | PutSeite("/setrgbcolor {exch pop exch pop oldsetgray} bind def\n"); |
||
1195 | break; |
||
1196 | } |
||
1197 | Plate = nr; |
||
1198 | DoSep = true; |
||
1199 | } |
||
1200 | |||
1201 | void PSLib::PS_setGray() |
||
1202 | { |
||
1203 | GraySc = true; |
||
1204 | } |
||
1205 | |||
1206 | void PSLib::PDF_Bookmark(QString text, uint Seite) |
||
1207 | { |
||
1208 | PutSeite("[/Title ("+text+") /Page "+IToStr(Seite)+" /View [/Fit]\n"); |
||
1209 | PutSeite("/OUT pdfmark\n"); |
||
1210 | isPDF = true; |
||
1211 | } |
||
1212 | |||
1213 | void PSLib::PDF_Annotation(QString text, float x, float y, float b, float h) |
||
1214 | { |
||
1215 | PutSeite("[ /Rect [ "+ToStr(static_cast<int>(x))+" "+ToStr(static_cast<int>(y))+" "+ToStr(static_cast<int>(b))+" "+ToStr(static_cast<int>(h))+" ]\n"); |
||
1216 | PutSeite(" /Contents ("+text+")\n /Open false\n"); |
||
1217 | PutSeite("/ANN pdfmark\n"); |
||
1218 | isPDF = true; |
||
1219 | } |
||
1220 | |||
1221 | |||
1222 | void PSLib::PS_close() |
||
1223 | { |
||
1224 | PutDoc("%%Trailer\n"); |
||
1225 | PutDoc("end\n"); |
||
1226 | PutDoc("%%EOF\n"); |
||
1227 | Spool.close(); |
||
1228 | } |