1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
|
/*
* This file is part of the KDE libraries
* Copyright (c) 2001 Michael Goffioul <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
**/
#include "lpdtools.h"
#include "driver.h"
#include "kmprinter.h"
#include <tqfile.h>
#include <klocale.h>
static const char *pt_pagesize[] = {
"ledger", I18N_NOOP("Ledger"),
"legal", I18N_NOOP("US Legal"),
"letter", I18N_NOOP("US Letter"),
"a4", I18N_NOOP("A4"),
"a3", I18N_NOOP("A3"),
"b4", I18N_NOOP("B4"),
"b5", I18N_NOOP("B5"),
0
};
static int pt_nup[] = { 1, 2, 4, 8, -1 };
static const char *pt_bool[] = {
"YES", I18N_NOOP("Enabled"),
"NO", I18N_NOOP("Disabled"),
0
};
void setupBooleanOption(DrBooleanOption *opt)
{
int i(0);
while (pt_bool[i])
{
DrBase *ch = new DrBase();
ch->setName(pt_bool[i++]);
ch->set("text",pt_bool[i++]);
opt->addChoice(ch);
}
}
TQString nextWord(const TQString& s, int& pos)
{
int p1(pos), p2(0);
while (s[p1].isSpace() && p1 < (int)s.length()) p1++;
if (s[p1] == '{')
{
p1++;
p2 = s.find('}',p1);
}
else
{
p2 = p1;
while (!s[p2].isSpace() && p2 < (int)s.length()) p2++;
}
pos = (p2+1);
return s.mid(p1,p2-p1);
}
//************************************************************************************************
bool PrintcapEntry::readLine(const TQString& line)
{
QStringList l = TQStringList::split(':',line,false);
if (l.count() > 0)
{
m_name = l[0];
int p(-1);
// discard aliases
if ((p=m_name.find('|')) != -1)
m_name = m_name.left(p);
m_args.clear();
for (uint i=1; i<l.count(); i++)
{
int p = l[i].find('=');
if (p == -1) p = 2;
QString key = l[i].left(p);
QString value = l[i].right(l[i].length()-(l[i][p] == '=' ? p+1 : p));
m_args[key] = value;
}
return true;
}
return false;
}
void PrintcapEntry::writeEntry(TQTextStream& t)
{
if (m_comment.isEmpty()) t << "# Entry for printer " << m_name << endl;
else t << m_comment << endl;
t << m_name << ":";
for (TQMap<TQString,TQString>::ConstIterator it=m_args.begin(); it!=m_args.end(); ++it)
{
t << "\\\n\t:" << it.key();
if (!it.data().isEmpty())
t << ((*it)[0] == '#' ? "" : "=") << *it;
t << ":";
}
t << endl << endl;
}
TQString PrintcapEntry::comment(int index)
{
QString w;
if (m_comment.startsWith("##PRINTTOOL3##"))
{
int p(0);
for (int i=0;i<index;i++)
w = nextWord(m_comment,p);
}
return w;
}
KMPrinter* PrintcapEntry::createPrinter()
{
KMPrinter *printer = new KMPrinter();
printer->setName(m_name);
printer->setPrinterName(m_name);
printer->setInstanceName(TQString::null);
printer->setState(KMPrinter::Idle);
printer->setType(KMPrinter::Printer);
return printer;
}
//************************************************************************************************
TQStringList splitPrinttoolLine(const TQString& line)
{
QStringList l;
int p = line.find(':');
if (p != -1)
{
l.append(line.left(p));
p = line.find('{',p);
if (p == -1)
l.append(line.right(line.length()-l[0].length()-1).stripWhiteSpace());
else
{
while (p != -1)
{
int q = line.find('}',p);
if (q != -1)
{
l.append(line.mid(p+1,q-p-1));
p = line.find('{',q);
}
else break;
}
}
}
return l;
}
bool PrinttoolEntry::readEntry(TQTextStream& t)
{
QString line;
QStringList args;
m_resolutions.setAutoDelete(true);
m_depths.setAutoDelete(true);
m_resolutions.clear();
m_depths.clear();
while (!t.eof())
{
line = getPrintcapLine(t);
if (line.isEmpty())
break;
if (line == "EndEntry")
return !m_name.isEmpty();
QStringList l = splitPrinttoolLine(line);
if (l.count() > 1)
{
if (l[0] == "StartEntry") m_name = l[1];
else if (l[0] == "GSDriver") m_gsdriver = l[1];
else if (l[0] == "About") m_about = l[1];
else if (l[0] == "Description") m_description = l[1];
else if (l[0] == "Resolution" && l.count() > 2)
{
Resolution *resol = new Resolution;
bool ok(false);
resol->xdpi = l[1].toInt(&ok);
if (ok) resol->ydpi = l[2].toInt(&ok);
if (l.count() > 3)
resol->comment = l[3];
if (ok) m_resolutions.append(resol);
else delete resol;
}
else if (l[0] == "BitsPerPixel" && l.count() > 1)
{
BitsPerPixel *dpth = new BitsPerPixel;
dpth->bpp = l[1];
if (l.count() > 2)
dpth->comment = l[2];
m_depths.append(dpth);
}
}
}
return false;
}
DrMain* PrinttoolEntry::createDriver()
{
// create driver
DrMain *dr = new DrMain();
dr->setName(m_name);
dr->set("description",m_description);
dr->set("text",m_description);
dr->set("drtype","printtool");
DrGroup *gr(0);
DrListOption *lopt(0);
DrStringOption *sopt(0);
DrBooleanOption *bopt(0);
DrBase *ch(0);
if (m_gsdriver != "TEXT")
{
// create GS group
gr = new DrGroup();
gr->set("text",i18n("GhostScript settings"));
dr->addGroup(gr);
// Pseudo option to have access to GS driver
lopt = new DrListOption();
lopt->setName("GSDEVICE");
lopt->set("text",i18n("Driver"));
lopt->set("default",m_gsdriver);
gr->addOption(lopt);
ch = new DrBase();
ch->setName(m_gsdriver);
ch->set("text",m_gsdriver);
lopt->addChoice(ch);
lopt->setValueText(m_gsdriver);
// Resolutions
if (m_resolutions.count() > 0)
{
lopt = new DrListOption();
lopt->setName("RESOLUTION");
lopt->set("text",i18n("Resolution"));
gr->addOption(lopt);
TQPtrListIterator<Resolution> it(m_resolutions);
for (int i=0;it.current();++it,i++)
{
ch = new DrBase;
ch->setName(TQString::fromLatin1("%1x%2").arg(it.current()->xdpi).arg(it.current()->ydpi));
if (it.current()->comment.isEmpty())
ch->set("text",TQString::fromLatin1("%1x%2 DPI").arg(it.current()->xdpi).arg(it.current()->ydpi));
else
ch->set("text",TQString::fromLatin1("%2x%3 DPI (%1)").arg(it.current()->comment).arg(it.current()->xdpi).arg(it.current()->ydpi));
lopt->addChoice(ch);
}
QString defval = lopt->choices()->first()->name();
lopt->set("default",defval);
lopt->setValueText(defval);
}
// BitsPerPixels
if (m_depths.count() > 0)
{
lopt = new DrListOption();
lopt->setName("COLOR");
lopt->set("text",i18n("Color depth"));
gr->addOption(lopt);
TQPtrListIterator<BitsPerPixel> it(m_depths);
for (int i=0;it.current();++it,i++)
{
ch = new DrBase;
if (m_gsdriver != "uniprint")
ch->setName(TQString::fromLatin1("-dBitsPerPixel=%1").arg(it.current()->bpp));
else
ch->setName(it.current()->bpp);
if (it.current()->comment.isEmpty())
ch->set("text",it.current()->bpp);
else
ch->set("text",TQString::fromLatin1("%1 - %2").arg(it.current()->bpp).arg(it.current()->comment));
lopt->addChoice(ch);
}
QString defval = lopt->choices()->first()->name();
lopt->set("default",defval);
lopt->setValueText(defval);
}
// additional GS options
sopt = new DrStringOption;
sopt->setName("EXTRA_GS_OPTIONS");
sopt->set("text",i18n("Additional GS options"));
gr->addOption(sopt);
}
// General group
gr = new DrGroup();
gr->set("text",i18n("General"));
dr->addGroup(gr);
// Page size
lopt = new DrListOption();
lopt->setName("PAPERSIZE");
lopt->set("text",i18n("Page size"));
lopt->set("default","letter");
gr->addOption(lopt);
int i(0);
while (pt_pagesize[i])
{
ch = new DrBase();
ch->setName(pt_pagesize[i++]);
ch->set("text",i18n(pt_pagesize[i++]));
lopt->addChoice(ch);
}
lopt->setValueText("letter");
// Nup
lopt = new DrListOption();
lopt->setName("NUP");
lopt->set("text",i18n("Pages per sheet"));
lopt->set("default","1");
gr->addOption(lopt);
i = 0;
while (pt_nup[i] != -1)
{
ch = new DrBase();
ch->setName(TQString::number(pt_nup[i++]));
ch->set("text",ch->name());
lopt->addChoice(ch);
}
lopt->setValueText("1");
// Margins
sopt = new DrStringOption();
sopt->setName("RTLFTMAR");
sopt->set("text",i18n("Left/right margin (1/72 in)"));
sopt->setValueText("18");
gr->addOption(sopt);
sopt = new DrStringOption();
sopt->setName("TOPBOTMAR");
sopt->set("text",i18n("Top/bottom margin (1/72 in)"));
sopt->setValueText("18");
gr->addOption(sopt);
// Text group
gr = new DrGroup();
gr->set("text",i18n("Text options"));
dr->addGroup(gr);
// Send EOF
bopt = new DrBooleanOption();
bopt->setName("TEXT_SEND_EOF");
bopt->set("text",i18n("Send EOF after job to eject page"));
gr->addOption(bopt);
setupBooleanOption(bopt);
bopt->setValueText("NO");
// Fix stair-stepping
bopt = new DrBooleanOption();
bopt->setName("CRLFTRANS");
bopt->set("text",i18n("Fix stair-stepping text"));
gr->addOption(bopt);
setupBooleanOption(bopt);
bopt->choices()->first()->setName("1");
bopt->choices()->last()->setName("0");
bopt->setValueText("0");
if (m_gsdriver != "POSTSCRIPT")
{
// Fast text printing
bopt = new DrBooleanOption();
bopt->setName("ASCII_TO_PS");
bopt->set("text",i18n("Fast text printing (non-PS printers only)"));
gr->addOption(bopt);
setupBooleanOption(bopt);
bopt->choices()->first()->setName("NO");
bopt->choices()->last()->setName("YES");
bopt->setValueText("NO");
}
return dr;
}
//************************************************************************************************
TQString getPrintcapLine(TQTextStream& t, TQString *lastcomment)
{
QString line, buffer, comm;
while (!t.eof())
{
buffer = t.readLine().stripWhiteSpace();
if (buffer.isEmpty() || buffer[0] == '#')
{
comm = buffer;
continue;
}
line.append(buffer);
if (line.right(1) == "\\")
{
line.truncate(line.length()-1);
line = line.stripWhiteSpace();
}
else break;
}
if (lastcomment)
*lastcomment = comm;
return line;
}
|