Rev 20 | Rev 68 | 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"); |
||
45 | Franz | 444 | /* if ((Art) && (Ori != 0)) |
3 | paul | 445 | { |
446 | PutSeite("<< /PageSize [ "+ToStr(breite)+" "+ToStr(hoehe)+" ]\n"); |
||
447 | PutSeite("/Orientation 3\n"); |
||
448 | PutSeite(">> setpagedevice\n"); |
||
45 | Franz | 449 | } */ |
3 | paul | 450 | Prolog = ""; |
451 | FontDesc = ""; |
||
452 | } |
||
453 | |||
454 | QString PSLib::PSEncode(QString in) |
||
455 | { |
||
456 | QString tmp = ""; |
||
457 | QString cc; |
||
458 | for (uint d = 0; d < in.length(); ++d) |
||
459 | { |
||
460 | cc = in.at(d); |
||
461 | if ((cc == "(") || (cc == ")") || (cc == "\\")) |
||
462 | tmp += "\\"; |
||
463 | tmp += cc; |
||
464 | } |
||
465 | tmp = tmp.simplifyWhiteSpace().replace( QRegExp("\\s"), "" ); |
||
466 | return tmp; |
||
467 | } |
||
468 | |||
469 | void PSLib::PS_TemplateStart(QString Name, float breite, float hoehe) |
||
470 | { |
||
471 | PutDoc("/"+PSEncode(Name)+"\n<<\n"); |
||
472 | PutDoc("/FormType 1\n"); |
||
473 | PutDoc("/BBox [0 0 "+ToStr(breite)+" "+ToStr(hoehe)+"]\n"); |
||
474 | PutDoc("/Matrix [1 0 0 1 0 0]\n"); |
||
475 | PutDoc("/PaintProc\n{\n"); |
||
476 | } |
||
477 | |||
478 | void PSLib::PS_UseTemplate(QString Name) |
||
479 | { |
||
480 | PutDoc(PSEncode(Name)+" execform\n"); |
||
481 | } |
||
482 | |||
483 | void PSLib::PS_TemplateEnd() |
||
484 | { |
||
485 | PutDoc("pop } bind\n"); |
||
486 | PutDoc(">> def\n"); |
||
487 | } |
||
488 | |||
489 | void PSLib::PS_begin_page(float breite, float hoehe, struct Margs* Ma) |
||
490 | { |
||
491 | PDev = ToStr(Ma->Left) + " " + ToStr(Ma->Bottom) + " m\n"; |
||
492 | PDev += ToStr(breite - Ma->Right) + " " + ToStr(Ma->Bottom) + " li\n"; |
||
493 | PDev += ToStr(breite - Ma->Right) + " " + ToStr(hoehe - Ma->Top) + " li\n"; |
||
494 | PDev += ToStr(Ma->Left) + " " + ToStr(hoehe - Ma->Top) + " li cl clip newpath\n"; |
||
495 | Seiten++; |
||
496 | PutSeite("%%Page: " + IToStr(Seiten) + " " + IToStr(Seiten) + "\nsave\n" + PDev); |
||
497 | PutSeite("/DeviceCMYK setcolorspace\n"); |
||
498 | } |
||
499 | |||
500 | void PSLib::PS_end_page() |
||
501 | { |
||
502 | PutSeite("%%PageTrailer\nrestore\nsp\n"); |
||
503 | } |
||
504 | |||
505 | void PSLib::PS_curve(float x1, float y1, float x2, float y2, float x3, float y3) |
||
506 | { |
||
507 | PutSeite(ToStr(x1) + " " + ToStr(y1) + " " + ToStr(x2) + " " + ToStr(y2) + " " + ToStr(x3) + " " + ToStr(y3) + " curveto\n"); |
||
508 | } |
||
509 | |||
510 | void PSLib::PS_moveto(float x, float y) |
||
511 | { |
||
512 | PutSeite(ToStr(x) + " " + ToStr(y) + " m\n"); |
||
513 | } |
||
514 | |||
515 | void PSLib::PS_lineto(float x, float y) |
||
516 | { |
||
517 | PutSeite(ToStr(x) + " " + ToStr(y) + " li\n"); |
||
518 | } |
||
519 | |||
520 | void PSLib::PS_closepath() |
||
521 | { |
||
522 | PutSeite("cl\n"); |
||
523 | } |
||
524 | |||
525 | void PSLib::PS_translate(float x, float y) |
||
526 | { |
||
527 | PutSeite(ToStr(x) + " " + ToStr(y) + " tr\n"); |
||
528 | } |
||
529 | |||
530 | void PSLib::PS_scale(float x, float y) |
||
531 | { |
||
532 | PutSeite(ToStr(x) + " " + ToStr(y) + " sc\n"); |
||
533 | } |
||
534 | |||
535 | void PSLib::PS_rotate(float x) |
||
536 | { |
||
537 | PutSeite(ToStr(x) + " ro\n"); |
||
538 | } |
||
539 | |||
540 | void PSLib::PS_clip(bool mu) |
||
541 | { |
||
542 | if (mu) |
||
543 | PutSeite("eoclip newpath\n"); |
||
544 | else |
||
545 | PutSeite("clip newpath\n"); |
||
546 | } |
||
547 | |||
548 | void PSLib::PS_save() |
||
549 | { |
||
550 | PutSeite("gs\n"); |
||
551 | } |
||
552 | |||
553 | void PSLib::PS_restore() |
||
554 | { |
||
555 | PutSeite("gr\n"); |
||
556 | } |
||
557 | |||
558 | void PSLib::PS_setcmykcolor_fill(float c, float m, float y, float k) |
||
559 | { |
||
560 | FillColor = ToStr(c) + " " + ToStr(m) + " " + ToStr(y) + " " + ToStr(k); |
||
561 | } |
||
562 | |||
563 | void PSLib::PS_setcmykcolor_dummy() |
||
564 | { |
||
565 | PutSeite("0 0 0 0 cmyk\n"); |
||
566 | } |
||
567 | |||
568 | void PSLib::PS_setcmykcolor_stroke(float c, float m, float y, float k) |
||
569 | { |
||
570 | StrokeColor = ToStr(c) + " " + ToStr(m) + " " + ToStr(y) + " " + ToStr(k); |
||
571 | } |
||
572 | |||
573 | void PSLib::PS_setlinewidth(float w) |
||
574 | { |
||
575 | PutSeite(ToStr(w) + " sw\n"); |
||
576 | LineW = w; |
||
577 | } |
||
578 | |||
579 | void PSLib::PS_setdash(Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo) |
||
580 | { |
||
581 | QString Dt = ToStr(QMAX(LineW, 1)); |
||
582 | QString Da = ToStr(QMAX(3*LineW, 1)); |
||
583 | switch (st) |
||
584 | { |
||
585 | case Qt::SolidLine: |
||
586 | PutSeite("[] 0 setdash\n"); |
||
587 | break; |
||
588 | case Qt::DashLine: |
||
589 | PutSeite("["+Da+" "+Dt+"] 0 setdash\n"); |
||
590 | break; |
||
591 | case Qt::DotLine: |
||
592 | PutSeite("["+Dt+"] 0 setdash\n"); |
||
593 | break; |
||
594 | case Qt::DashDotLine: |
||
595 | PutSeite("["+Da+" "+Dt+" "+Dt+" "+Dt+"] 0 setdash\n"); |
||
596 | break; |
||
597 | case Qt::DashDotDotLine: |
||
598 | PutSeite("["+Da+" "+Dt+" "+Dt+" "+Dt+" "+Dt+" "+Dt+"] 0 setdash\n"); |
||
599 | break; |
||
600 | default: |
||
601 | PutSeite("[] 0 setdash\n"); |
||
602 | break; |
||
603 | } |
||
604 | switch (ca) |
||
605 | { |
||
606 | case Qt::FlatCap: |
||
607 | PutSeite("0 setlinecap\n"); |
||
608 | break; |
||
609 | case Qt::SquareCap: |
||
610 | PutSeite("2 setlinecap\n"); |
||
611 | break; |
||
612 | case Qt::RoundCap: |
||
613 | PutSeite("1 setlinecap\n"); |
||
614 | break; |
||
615 | default: |
||
616 | PutSeite("0 setlinecap\n"); |
||
617 | break; |
||
618 | } |
||
619 | switch (jo) |
||
620 | { |
||
621 | case Qt::MiterJoin: |
||
622 | PutSeite("0 setlinejoin\n"); |
||
623 | break; |
||
624 | case Qt::BevelJoin: |
||
625 | PutSeite("2 setlinejoin\n"); |
||
626 | break; |
||
627 | case Qt::RoundJoin: |
||
628 | PutSeite("1 setlinejoin\n"); |
||
629 | break; |
||
630 | default: |
||
631 | PutSeite("0 setlinejoin\n"); |
||
632 | break; |
||
633 | } |
||
634 | } |
||
635 | |||
636 | void PSLib::PS_selectfont(QString f, int s) |
||
637 | { |
||
638 | PutSeite(UsedFonts[f] + " " + IToStr(s) + " se\n"); |
||
639 | } |
||
640 | |||
641 | void PSLib::PS_fill(bool mu) |
||
642 | { |
||
643 | if (mu) |
||
644 | PutSeite(FillColor + " cmyk eofill\n"); |
||
645 | else |
||
646 | PutSeite(FillColor + " cmyk fi\n"); |
||
647 | } |
||
648 | |||
649 | void PSLib::PS_stroke() |
||
650 | { |
||
651 | PutSeite(StrokeColor + " cmyk st\n"); |
||
652 | } |
||
653 | |||
654 | void PSLib::PS_fill_stroke(bool mu) |
||
655 | { |
||
656 | PS_save(); |
||
657 | PS_fill(mu); |
||
658 | PS_restore(); |
||
659 | PS_stroke(); |
||
660 | } |
||
661 | |||
662 | void PSLib::PS_newpath() |
||
663 | { |
||
664 | PutSeite("newpath\n"); |
||
665 | } |
||
666 | |||
667 | void PSLib::PS_GradientCol1(float c, float m, float y, float k) |
||
668 | { |
||
669 | GrColor1 = ToStr(c) + " " + ToStr(m) + " " + ToStr(y) + " " + ToStr(k); |
||
670 | } |
||
671 | |||
672 | void PSLib::PS_GradientCol2(float c, float m, float y, float k) |
||
673 | { |
||
674 | GrColor2 = ToStr(c) + " " + ToStr(m) + " " + ToStr(y) + " " + ToStr(k); |
||
675 | } |
||
676 | |||
677 | void PSLib::PS_LinGradient(float w, float h, int item, int grad, bool mu) |
||
678 | { |
||
679 | if (item == 1) |
||
680 | PutSeite("-"+ToStr(w / 2.0)+" "+ToStr(-h / 2.0)+" tr\n"); |
||
681 | if (mu) |
||
682 | PutSeite("eoclip\n"); |
||
683 | else |
||
684 | PutSeite("clip\n"); |
||
685 | PutSeite("<<\n"); |
||
686 | PutSeite("/ShadingType 2\n"); |
||
687 | if (DoSep) |
||
688 | PutSeite("/ColorSpace /DeviceGray\n"); |
||
689 | else |
||
690 | PutSeite("/ColorSpace /DeviceCMYK\n"); |
||
691 | switch (grad) |
||
692 | { |
||
693 | case 1: |
||
694 | PutSeite("/Coords [0 "+ToStr(h / 2.0)+" "+ToStr(w)+" "+ToStr(h / 2.0)+"]\n"); |
||
695 | break; |
||
696 | case 2: |
||
697 | PutSeite("/Coords ["+ToStr(w / 2.0)+" 0 "+ToStr(w / 2.0)+" "+ToStr(h)+"]\n"); |
||
698 | break; |
||
699 | case 3: |
||
700 | PutSeite("/Coords [0 0 "+ToStr(w)+" "+ToStr(h)+"]\n"); |
||
701 | break; |
||
702 | case 4: |
||
703 | PutSeite("/Coords ["+ToStr(w)+" 0 0 "+ToStr(h)+"]\n"); |
||
704 | break; |
||
705 | } |
||
706 | PutSeite("/BBox [0 "+ToStr(h)+" "+ToStr(w)+" 0]\n"); |
||
707 | if (DoSep) |
||
708 | PutSeite("/Background [0]\n"); |
||
709 | else |
||
710 | PutSeite("/Background ["+FillColor+"]\n"); |
||
711 | PutSeite("/Extend [false false]\n"); |
||
712 | PutSeite("/Function\n"); |
||
713 | PutSeite("<<\n"); |
||
714 | PutSeite("/FunctionType 2\n"); |
||
715 | PutSeite("/Domain [0 1]\n"); |
||
716 | if (DoSep) |
||
717 | { |
||
718 | int pla = Plate - 1; |
||
719 | if (pla < 0) |
||
720 | pla = 3; |
||
721 | QStringList cols1 = QStringList::split(" ", GrColor2); |
||
722 | QStringList cols2 = QStringList::split(" ", GrColor1); |
||
723 | PutSeite("/C1 ["+ToStr(1-cols1[pla].toFloat())+"]\n"); |
||
724 | PutSeite("/C0 ["+ToStr(1-cols2[pla].toFloat())+"]\n"); |
||
725 | } |
||
726 | else |
||
727 | { |
||
728 | PutSeite("/C0 ["+GrColor1+"]\n"); |
||
729 | PutSeite("/C1 ["+GrColor2+"]\n"); |
||
730 | } |
||
731 | PutSeite("/N 1\n"); |
||
732 | PutSeite(">>\n"); |
||
733 | PutSeite(">>\n"); |
||
734 | PutSeite("shfill\n"); |
||
735 | } |
||
736 | |||
737 | void PSLib::PS_RadGradient(float w, float h, int item, bool mu) |
||
738 | { |
||
739 | float w2, h2, rad; |
||
740 | w2 = w / 2.0; |
||
741 | h2 = h / 2.0; |
||
742 | rad = QMIN(w, fabs(h)) / 2.0; |
||
743 | PutSeite("/cmtx matrix currentmatrix def\n"); |
||
744 | if (mu) |
||
745 | PutSeite("eoclip\n"); |
||
746 | else |
||
747 | PutSeite("clip\n"); |
||
748 | PutSeite("<<\n"); |
||
749 | PutSeite("/ShadingType 3\n"); |
||
750 | if (DoSep) |
||
751 | PutSeite("/ColorSpace /DeviceGray\n"); |
||
752 | else |
||
753 | PutSeite("/ColorSpace /DeviceCMYK\n"); |
||
754 | PutSeite("/Coords ["+ToStr(w2)+" "+ToStr(h2)+" 0 "+ToStr(w2)+" "+ToStr(h2)+" "+ToStr(rad)+"]\n"); |
||
755 | PutSeite("/BBox [0 "+ToStr(h)+" "+ToStr(w)+" 0]\n"); |
||
756 | if (DoSep) |
||
757 | PutSeite("/Background [0]\n"); |
||
758 | else |
||
759 | PutSeite("/Background ["+FillColor+"]\n"); |
||
760 | PutSeite("/Extend [true true]\n"); |
||
761 | PutSeite("/Function\n"); |
||
762 | PutSeite("<<\n"); |
||
763 | PutSeite("/FunctionType 2\n"); |
||
764 | PutSeite("/Domain [0 1]\n"); |
||
765 | if (DoSep) |
||
766 | { |
||
767 | int pla = Plate - 1; |
||
768 | if (pla < 0) |
||
769 | pla = 3; |
||
770 | QStringList cols1 = QStringList::split(" ", GrColor2); |
||
771 | QStringList cols2 = QStringList::split(" ", GrColor1); |
||
772 | PutSeite("/C0 ["+ToStr(1-cols1[pla].toFloat())+"]\n"); |
||
773 | PutSeite("/C1 ["+ToStr(1-cols2[pla].toFloat())+"]\n"); |
||
774 | } |
||
775 | else |
||
776 | { |
||
777 | PutSeite("/C0 ["+GrColor2+"]\n"); |
||
778 | PutSeite("/C1 ["+GrColor1+"]\n"); |
||
779 | } |
||
780 | PutSeite("/N 1\n"); |
||
781 | PutSeite(">>\n"); |
||
782 | PutSeite(">>\n"); |
||
783 | if (item == 1) |
||
784 | { |
||
785 | if (w > fabs(h)) |
||
786 | PutSeite("-"+ToStr(w2*(w2 / rad))+" "+ToStr(fabs(h2))+" tr\n"); |
||
787 | else |
||
788 | PutSeite("-"+ToStr(w2*(w2 / rad))+" "+ToStr(fabs(h2)*(fabs(h2) /rad))+" tr\n"); |
||
789 | } |
||
790 | else |
||
791 | { |
||
792 | if (w > fabs(h)) |
||
793 | PutSeite("-"+ToStr(w2*(w2 / rad)-w2)+" 0 tr\n"); |
||
794 | else |
||
795 | { |
||
796 | if (w < fabs(h)) |
||
797 | PutSeite("0 "+ToStr(fabs(h2)*(fabs(h2) /rad)-fabs(h2))+" tr\n"); |
||
798 | } |
||
799 | } |
||
800 | PutSeite(ToStr(w2 / rad)+" "+ToStr(fabs(h2) / rad)+" scale\n"); |
||
801 | PutSeite("shfill\n"); |
||
802 | PutSeite("cmtx setmatrix\n"); |
||
803 | } |
||
804 | |||
805 | void PSLib::PS_underline(QCString ch, float x, float y) |
||
806 | { |
||
807 | PS_moveto(x, y); |
||
808 | PutSeite("("+QString(ch)+") srt\n"); |
||
809 | } |
||
810 | |||
811 | void PSLib::PS_strikeout(QCString ch, float x, float y) |
||
812 | { |
||
813 | PS_moveto(x, y); |
||
814 | PutSeite("("+QString(ch)+") srd\n"); |
||
815 | } |
||
816 | |||
817 | void PSLib::PS_show_xy(QCString ch, float x, float y) |
||
818 | { |
||
819 | PutSeite("("+QString(ch)+") "+ToStr(x)+" "+ToStr(y)+" "+StrokeColor+" shm\n"); |
||
820 | } |
||
821 | |||
822 | void PSLib::PS_show_xyG(QString font, QString ch, float x, float y) |
||
823 | { |
||
824 | QString Name; |
||
825 | uint cc = ch[0].unicode(); |
||
826 | if (GlyphsOfFont[font].contains(cc)) |
||
827 | Name = GlyphsOfFont[font][cc]; |
||
828 | else |
||
829 | Name = ".notdef"; |
||
830 | PutSeite("/"+Name+" "+ToStr(x)+" "+ToStr(y)+" "+StrokeColor+" shg\n"); |
||
831 | } |
||
832 | |||
833 | void PSLib::PS_show(float x, float y) |
||
834 | { |
||
835 | PS_moveto(x, y); |
||
836 | PutSeite("/hyphen glyphshow\n"); |
||
837 | } |
||
838 | |||
20 | Franz | 839 | void PSLib::PS_ImageData(bool inver, QString fn, QString Name, QString Prof, bool UseEmbedded, bool UseProf) |
3 | paul | 840 | { |
841 | QString tmp; |
||
842 | QFileInfo fi = QFileInfo(fn); |
||
843 | QString ext = fi.extension(false).lower(); |
||
844 | if (ext == "eps") |
||
845 | { |
||
846 | if (loadText(fn, &tmp)) |
||
847 | { |
||
848 | PutSeite("currentfile 1 (%ENDEPSDATA) /SubFileDecode filter /ReusableStreamDecode filter\n"); |
||
849 | PutSeite("%%BeginDocument: " + fi.fileName() + "\n"); |
||
850 | PutSeite(tmp+"\n"); |
||
851 | PutSeite("%ENDEPSDATA\n"); |
||
852 | PutSeite("%%EndDocument\n"); |
||
853 | PutSeite("/"+PSEncode(Name)+"Bild exch def\n"); |
||
854 | } |
||
855 | return; |
||
856 | } |
||
857 | QString ImgStr = ""; |
||
858 | QImage image; |
||
859 | #ifdef HAVE_CMS |
||
860 | QImage image2; |
||
861 | bool cmy = false; |
||
862 | if ((CMSuse) && (UseProf)) |
||
863 | { |
||
864 | image = LoadPict(fn); |
||
865 | image = image.convertDepth(32); |
||
866 | image2 = LoadPictCol(fn, Prof, UseEmbedded, &cmy); |
||
20 | Franz | 867 | if (inver) |
868 | { |
||
869 | image.invertPixels(); |
||
870 | image2.invertPixels(); |
||
871 | } |
||
3 | paul | 872 | ImgStr = ImageToCMYK_PS(&image2, -1, cmy); |
873 | } |
||
874 | else |
||
875 | { |
||
876 | image = LoadPict(fn); |
||
20 | Franz | 877 | if (inver) |
878 | image.invertPixels(); |
||
3 | paul | 879 | ImgStr = ImageToCMYK_PS(&image, -1, false); |
880 | } |
||
881 | #else |
||
882 | image = LoadPict(fn); |
||
883 | image = image.convertDepth(32); |
||
20 | Franz | 884 | if (inver) |
885 | image.invertPixels(); |
||
3 | paul | 886 | ImgStr = ImageToCMYK_PS(&image, -1, false); |
887 | #endif |
||
888 | if (CompAvail) |
||
889 | { |
||
890 | PutSeite("currentfile /ASCIIHexDecode filter /FlateDecode filter /ReusableStreamDecode filter\n"); |
||
891 | ImgStr = CompressStr(&ImgStr); |
||
892 | } |
||
893 | else |
||
894 | PutSeite("currentfile /ASCIIHexDecode filter /ReusableStreamDecode filter\n"); |
||
895 | ImgStr = String2Hex(&ImgStr); |
||
896 | PutSeite(ImgStr); |
||
897 | PutSeite("\n>\n"); |
||
898 | PutSeite("/"+PSEncode(Name)+"Bild exch def\n"); |
||
899 | ImgStr = ""; |
||
900 | if (image.hasAlphaBuffer()) |
||
901 | { |
||
902 | QImage iMask = image.createAlphaMask(); |
||
903 | ImgStr = MaskToTxt(&iMask, false); |
||
904 | if (CompAvail) |
||
905 | { |
||
906 | PutSeite("currentfile /ASCIIHexDecode filter /FlateDecode filter /ReusableStreamDecode filter\n"); |
||
907 | ImgStr = CompressStr(&ImgStr); |
||
908 | } |
||
909 | else |
||
910 | PutSeite("currentfile /ASCIIHexDecode filter /ReusableStreamDecode filter\n"); |
||
911 | ImgStr = String2Hex(&ImgStr); |
||
912 | PutSeite(ImgStr); |
||
913 | PutSeite("\n>\n"); |
||
914 | PutSeite("/"+PSEncode(Name)+"Mask exch def\n"); |
||
915 | } |
||
916 | } |
||
917 | |||
20 | Franz | 918 | 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 | 919 | { |
920 | QString tmp; |
||
921 | QFileInfo fi = QFileInfo(fn); |
||
922 | QString ext = fi.extension(false).lower(); |
||
923 | if (ext == "eps") |
||
924 | { |
||
925 | if (loadText(fn, &tmp)) |
||
926 | { |
||
927 | if (Name != "") |
||
928 | { |
||
929 | PutSeite("bEPS\n"); |
||
930 | PutSeite(ToStr(scalex) + " " + ToStr(scaley) + " sc\n"); |
||
931 | PutSeite(ToStr(x) + " " + ToStr(y) + " tr\n"); |
||
932 | PutSeite(PSEncode(Name)+"Bild cvx exec\n"); |
||
933 | PutSeite(PSEncode(Name)+"Bild resetfile\n"); |
||
934 | PutSeite("eEPS\n"); |
||
935 | } |
||
936 | else |
||
937 | { |
||
938 | PutSeite("bEPS\n"); |
||
939 | PutSeite(ToStr(scalex) + " " + ToStr(scaley) + " sc\n"); |
||
940 | PutSeite(ToStr(x) + " " + ToStr(y) + " tr\n"); |
||
941 | PutSeite("%%BeginDocument: " + fi.fileName() + "\n"); |
||
942 | PutSeite(tmp+"\n"); |
||
943 | PutSeite("%%EndDocument\n"); |
||
944 | PutSeite("eEPS\n"); |
||
945 | } |
||
946 | } |
||
947 | } |
||
948 | else |
||
949 | { |
||
950 | QString ImgStr = ""; |
||
951 | QImage image; |
||
952 | #ifdef HAVE_CMS |
||
953 | QImage image2; |
||
954 | bool cmy = false; |
||
955 | if ((CMSuse) && (UseProf)) |
||
956 | { |
||
957 | image = LoadPict(fn); |
||
958 | image = image.convertDepth(32); |
||
959 | image2 = LoadPictCol(fn, Prof, UseEmbedded, &cmy); |
||
960 | } |
||
961 | else |
||
962 | { |
||
963 | image = LoadPict(fn); |
||
964 | image = image.convertDepth(32); |
||
965 | } |
||
20 | Franz | 966 | if (inver) |
967 | { |
||
968 | image.invertPixels(); |
||
969 | image2.invertPixels(); |
||
970 | } |
||
3 | paul | 971 | #else |
972 | image = LoadPict(fn); |
||
973 | image = image.convertDepth(32); |
||
20 | Franz | 974 | if (inver) |
975 | image.invertPixels(); |
||
3 | paul | 976 | #endif |
977 | int w = image.width(); |
||
978 | int h = image.height(); |
||
979 | PutSeite(ToStr(x*scalex) + " " + ToStr(y*scaley) + " tr\n"); |
||
980 | PutSeite(ToStr(scalex*w) + " " + ToStr(scaley*h) + " sc\n"); |
||
981 | if ((!DoSep) && (!GraySc)) |
||
982 | PutSeite("/DeviceCMYK setcolorspace\n"); |
||
983 | else |
||
984 | PutSeite("/DeviceGray setcolorspace\n"); |
||
985 | if (image.hasAlphaBuffer()) |
||
986 | { |
||
987 | QImage iMask = image.createAlphaMask(); |
||
988 | #ifdef HAVE_CMS |
||
989 | if ((CMSuse) && (UseProf)) |
||
990 | { |
||
991 | if (DoSep) |
||
992 | ImgStr = ImageToCMYK_PS(&image2, Plate, cmy); |
||
993 | else |
||
994 | { |
||
995 | if (GraySc) |
||
996 | ImgStr = ImageToCMYK_PS(&image2, -2, cmy); |
||
997 | else |
||
998 | ImgStr = ImageToCMYK_PS(&image2, -1, cmy); |
||
999 | } |
||
1000 | } |
||
1001 | else |
||
1002 | { |
||
1003 | if (DoSep) |
||
1004 | ImgStr = ImageToCMYK_PS(&image, Plate, false); |
||
1005 | else |
||
1006 | { |
||
1007 | if (GraySc) |
||
1008 | ImgStr = ImageToCMYK_PS(&image, -2, false); |
||
1009 | else |
||
1010 | ImgStr = ImageToCMYK_PS(&image, -1, false); |
||
1011 | } |
||
1012 | } |
||
1013 | #else |
||
1014 | if (DoSep) |
||
1015 | ImgStr = ImageToCMYK_PS(&image, Plate, false); |
||
1016 | else |
||
1017 | { |
||
1018 | if (GraySc) |
||
1019 | ImgStr = ImageToCMYK_PS(&image, -2, false); |
||
1020 | else |
||
1021 | ImgStr = ImageToCMYK_PS(&image, -1, false); |
||
1022 | } |
||
1023 | #endif |
||
1024 | if (Name == "") |
||
1025 | { |
||
1026 | if (CompAvail) |
||
1027 | { |
||
1028 | PutSeite("currentfile /ASCIIHexDecode filter /FlateDecode filter /ReusableStreamDecode filter\n"); |
||
1029 | ImgStr = CompressStr(&ImgStr); |
||
1030 | } |
||
1031 | else |
||
1032 | PutSeite("currentfile /ASCIIHexDecode filter /ReusableStreamDecode filter\n"); |
||
1033 | ImgStr = String2Hex(&ImgStr); |
||
1034 | PutSeite(ImgStr); |
||
1035 | ImgStr = ""; |
||
1036 | PutSeite("\n>\n"); |
||
1037 | PutSeite("/Bild exch def\n"); |
||
1038 | ImgStr = MaskToTxt(&iMask, false); |
||
1039 | if (CompAvail) |
||
1040 | { |
||
1041 | PutSeite("currentfile /ASCIIHexDecode filter /FlateDecode filter /ReusableStreamDecode filter\n"); |
||
1042 | ImgStr = CompressStr(&ImgStr); |
||
1043 | } |
||
1044 | else |
||
1045 | PutSeite("currentfile /ASCIIHexDecode filter /ReusableStreamDecode filter\n"); |
||
1046 | ImgStr = String2Hex(&ImgStr); |
||
1047 | PutSeite(ImgStr); |
||
1048 | PutSeite("\n>\n"); |
||
1049 | PutSeite("/Mask exch def\n"); |
||
1050 | } |
||
1051 | PutSeite("<<\n"); |
||
1052 | PutSeite(" /PaintType 1\n"); |
||
1053 | PutSeite(" /PatternType 1\n"); |
||
1054 | PutSeite(" /TilingType 3\n"); |
||
1055 | PutSeite(" /BBox [ 0 0 1 1 ]\n"); |
||
1056 | PutSeite(" /XStep 2\n"); |
||
1057 | PutSeite(" /YStep 2\n"); |
||
1058 | PutSeite(" /PaintProc {\n"); |
||
1059 | PutSeite(" pop\n"); |
||
1060 | PutSeite(" 1 1 1 1 setcmykcolor\n"); |
||
1061 | PutSeite(" <<\n"); |
||
1062 | PutSeite(" /ImageType 1\n"); |
||
1063 | PutSeite(" /Height " + IToStr(h) + "\n"); |
||
1064 | PutSeite(" /Width " + IToStr(w) + "\n"); |
||
1065 | PutSeite(" /ImageMatrix [" + IToStr(w) + " 0 0 " + IToStr(-h) + " 0 " + IToStr(h) +"]\n"); |
||
1066 | if (DoSep) |
||
1067 | PutSeite(" /Decode [1 0]\n"); |
||
1068 | else |
||
1069 | { |
||
1070 | if (GraySc) |
||
1071 | PutSeite(" /Decode [1 0]\n"); |
||
1072 | else |
||
1073 | PutSeite(" /Decode [0 1 0 1 0 1 0 1]\n"); |
||
1074 | } |
||
1075 | PutSeite(" /BitsPerComponent 8\n"); |
||
1076 | PutSeite(" /DataSource "+PSEncode(Name)+"Bild\n"); |
||
1077 | PutSeite(" >>\n"); |
||
1078 | PutSeite(" image\n"); |
||
1079 | PutSeite(" }\n"); |
||
1080 | PutSeite(">> matrix makepattern setpattern\n"); |
||
1081 | PutSeite("<< /ImageType 1\n"); |
||
1082 | PutSeite(" /Width " + IToStr(w) + "\n"); |
||
1083 | PutSeite(" /Height " + IToStr(h) + "\n"); |
||
1084 | PutSeite(" /BitsPerComponent 1\n"); |
||
1085 | PutSeite(" /Decode [1 0]\n"); |
||
1086 | PutSeite(" /ImageMatrix [" + IToStr(w) + " 0 0 " + IToStr(-h) + " 0 " + IToStr(h) + "]\n"); |
||
1087 | PutSeite(" /DataSource "+PSEncode(Name)+"Mask\n"); |
||
1088 | PutSeite(">>\n"); |
||
1089 | PutSeite("imagemask\n"); |
||
1090 | if (Name != "") |
||
1091 | { |
||
1092 | PutSeite(PSEncode(Name)+"Bild resetfile\n"); |
||
1093 | PutSeite(PSEncode(Name)+"Mask resetfile\n"); |
||
1094 | } |
||
1095 | } |
||
1096 | else |
||
1097 | { |
||
1098 | PutSeite("<< /ImageType 1\n"); |
||
1099 | PutSeite(" /Width " + IToStr(w) + "\n"); |
||
1100 | PutSeite(" /Height " + IToStr(h) + "\n"); |
||
1101 | PutSeite(" /BitsPerComponent 8\n"); |
||
1102 | if (DoSep) |
||
1103 | PutSeite(" /Decode [1 0]\n"); |
||
1104 | else |
||
1105 | { |
||
1106 | if (GraySc) |
||
1107 | PutSeite(" /Decode [1 0]\n"); |
||
1108 | else |
||
1109 | PutSeite(" /Decode [0 1 0 1 0 1 0 1]\n"); |
||
1110 | } |
||
1111 | PutSeite(" /ImageMatrix [" + IToStr(w) + " 0 0 " + IToStr(-h) + " 0 " + IToStr(h) + "]\n"); |
||
1112 | if (Name != "") |
||
1113 | { |
||
1114 | PutSeite(" /DataSource "+PSEncode(Name)+"Bild >>\n"); |
||
1115 | PutSeite("image\n"); |
||
1116 | PutSeite(PSEncode(Name)+"Bild resetfile\n"); |
||
1117 | } |
||
1118 | else |
||
1119 | { |
||
1120 | if (CompAvail) |
||
1121 | PutSeite(" /DataSource currentfile /ASCIIHexDecode filter /FlateDecode filter >>\n"); |
||
1122 | else |
||
1123 | PutSeite(" /DataSource currentfile /ASCIIHexDecode filter >>\n"); |
||
1124 | PutSeite("image\n"); |
||
1125 | #ifdef HAVE_CMS |
||
1126 | if ((CMSuse) && (UseProf)) |
||
1127 | { |
||
1128 | if (DoSep) |
||
1129 | ImgStr = ImageToCMYK_PS(&image2, Plate, cmy); |
||
1130 | else |
||
1131 | { |
||
1132 | if (GraySc) |
||
1133 | ImgStr = ImageToCMYK_PS(&image2, -2, cmy); |
||
1134 | else |
||
1135 | ImgStr = ImageToCMYK_PS(&image2, -1, cmy); |
||
1136 | } |
||
1137 | } |
||
1138 | else |
||
1139 | { |
||
1140 | if (DoSep) |
||
1141 | ImgStr = ImageToCMYK_PS(&image, Plate, false); |
||
1142 | else |
||
1143 | { |
||
1144 | if (GraySc) |
||
1145 | ImgStr = ImageToCMYK_PS(&image, -2, false); |
||
1146 | else |
||
1147 | ImgStr = ImageToCMYK_PS(&image, -1, false); |
||
1148 | } |
||
1149 | } |
||
1150 | #else |
||
1151 | if (DoSep) |
||
1152 | ImgStr = ImageToCMYK_PS(&image, Plate, false); |
||
1153 | else |
||
1154 | { |
||
1155 | if (GraySc) |
||
1156 | ImgStr = ImageToCMYK_PS(&image, -2, false); |
||
1157 | else |
||
1158 | ImgStr = ImageToCMYK_PS(&image, -1, false); |
||
1159 | } |
||
1160 | #endif |
||
1161 | if (CompAvail) |
||
1162 | ImgStr = CompressStr(&ImgStr); |
||
1163 | ImgStr = String2Hex(&ImgStr); |
||
1164 | PutSeite(ImgStr); |
||
1165 | PutSeite("\n>\n"); |
||
1166 | } |
||
1167 | } |
||
1168 | } |
||
1169 | } |
||
1170 | |||
1171 | void PSLib::PS_plate(int nr) |
||
1172 | { |
||
1173 | switch (nr) |
||
1174 | { |
||
1175 | case 0: |
||
1176 | PutSeite("%%PlateColor Black\n"); |
||
1177 | PutSeite("/setcmykcolor {exch pop exch pop exch pop 1 exch sub oldsetgray} bind def\n"); |
||
1178 | PutSeite("/setrgbcolor {pop pop pop 1 oldsetgray} bind def\n"); |
||
1179 | break; |
||
1180 | case 1: |
||
1181 | PutSeite("%%PlateColor Cyan\n"); |
||
1182 | PutSeite("/setcmykcolor {pop pop pop 1 exch sub oldsetgray} bind def\n"); |
||
1183 | PutSeite("/setrgbcolor {pop pop oldsetgray} bind def\n"); |
||
1184 | break; |
||
1185 | case 2: |
||
1186 | PutSeite("%%PlateColor Magenta\n"); |
||
1187 | PutSeite("/setcmykcolor {pop pop exch pop 1 exch sub oldsetgray} bind def\n"); |
||
1188 | PutSeite("/setrgbcolor {pop exch pop oldsetgray} bind def\n"); |
||
1189 | break; |
||
1190 | case 3: |
||
1191 | PutSeite("%%PlateColor Yellow\n"); |
||
1192 | PutSeite("/setcmykcolor {pop exch pop exch pop 1 exch sub oldsetgray} bind def\n"); |
||
1193 | PutSeite("/setrgbcolor {exch pop exch pop oldsetgray} bind def\n"); |
||
1194 | break; |
||
1195 | } |
||
1196 | Plate = nr; |
||
1197 | DoSep = true; |
||
1198 | } |
||
1199 | |||
1200 | void PSLib::PS_setGray() |
||
1201 | { |
||
1202 | GraySc = true; |
||
1203 | } |
||
1204 | |||
1205 | void PSLib::PDF_Bookmark(QString text, uint Seite) |
||
1206 | { |
||
1207 | PutSeite("[/Title ("+text+") /Page "+IToStr(Seite)+" /View [/Fit]\n"); |
||
1208 | PutSeite("/OUT pdfmark\n"); |
||
1209 | isPDF = true; |
||
1210 | } |
||
1211 | |||
1212 | void PSLib::PDF_Annotation(QString text, float x, float y, float b, float h) |
||
1213 | { |
||
1214 | PutSeite("[ /Rect [ "+ToStr(static_cast<int>(x))+" "+ToStr(static_cast<int>(y))+" "+ToStr(static_cast<int>(b))+" "+ToStr(static_cast<int>(h))+" ]\n"); |
||
1215 | PutSeite(" /Contents ("+text+")\n /Open false\n"); |
||
1216 | PutSeite("/ANN pdfmark\n"); |
||
1217 | isPDF = true; |
||
1218 | } |
||
1219 | |||
1220 | |||
1221 | void PSLib::PS_close() |
||
1222 | { |
||
1223 | PutDoc("%%Trailer\n"); |
||
1224 | PutDoc("end\n"); |
||
1225 | PutDoc("%%EOF\n"); |
||
1226 | Spool.close(); |
||
1227 | } |