Tizen 2.1 base
[platform/upstream/cups-filters.git] / filter / pdftoopvp / oprs / OPVPWrapper.cxx
1 /*
2   OPVPWrapper.cc
3 */
4
5
6 #include <config.h>
7 #include <stdio.h>
8 #include "OPRS.h"
9 #include "OPVPWrapper.h"
10 #include "OPVPWrapper_0_2.h"
11 #include <string.h>
12 #include <dlfcn.h>
13
14 OPVPWrapper::OPVPWrapper(void *opvpHandleA, opvp_int_t *opvpErrorNoA,
15   opvp_api_procs_t *procsA, opvp_dc_t printerContextA)
16 {
17     procs = procsA;
18     opvpHandle = opvpHandleA;
19     opvpErrorNo = opvpErrorNoA;
20     printerContext = printerContextA;
21     version[0] = 1;
22     version[1] = 0;
23     supportClosePrinter = (procs->opvpClosePrinter != 0);
24     supportStartJob = (procs->opvpStartJob != 0);
25     supportEndJob = (procs->opvpEndJob != 0);
26     supportAbortJob = (procs->opvpAbortJob != 0);
27     supportStartDoc = (procs->opvpStartDoc != 0);
28     supportEndDoc = (procs->opvpEndDoc != 0);
29     supportStartPage = (procs->opvpStartPage != 0);
30     supportEndPage = (procs->opvpEndPage != 0);
31     supportResetCTM = (procs->opvpResetCTM != 0);
32     supportSetCTM = (procs->opvpSetCTM != 0);
33     supportGetCTM = (procs->opvpGetCTM != 0);
34     supportInitGS = (procs->opvpInitGS != 0);
35     supportSaveGS = (procs->opvpSaveGS != 0);
36     supportRestoreGS = (procs->opvpRestoreGS != 0);
37     supportQueryColorSpace = (procs->opvpQueryColorSpace != 0);
38     supportSetColorSpace = (procs->opvpSetColorSpace != 0);
39     supportGetColorSpace = (procs->opvpGetColorSpace != 0);
40     supportSetFillMode = (procs->opvpSetFillMode != 0);
41     supportGetFillMode = (procs->opvpGetFillMode != 0);
42     supportSetAlphaConstant = (procs->opvpSetAlphaConstant != 0);
43     supportGetAlphaConstant = (procs->opvpGetAlphaConstant != 0);
44     supportSetLineWidth = (procs->opvpSetLineWidth != 0);
45     supportGetLineWidth = (procs->opvpGetLineWidth != 0);
46     supportSetLineDash = (procs->opvpSetLineDash != 0);
47     supportGetLineDash = (procs->opvpGetLineDash != 0);
48     supportSetLineDashOffset = (procs->opvpSetLineDashOffset != 0);
49     supportGetLineDashOffset = (procs->opvpGetLineDashOffset != 0);
50     supportSetLineStyle = (procs->opvpSetLineStyle != 0);
51     supportGetLineStyle = (procs->opvpGetLineStyle != 0);
52     supportSetLineCap = (procs->opvpSetLineCap != 0);
53     supportGetLineCap = (procs->opvpGetLineCap != 0);
54     supportSetLineJoin = (procs->opvpSetLineJoin != 0);
55     supportGetLineJoin = (procs->opvpGetLineJoin != 0);
56     supportSetMiterLimit = (procs->opvpSetMiterLimit != 0);
57     supportGetMiterLimit = (procs->opvpGetMiterLimit != 0);
58     supportSetPaintMode = (procs->opvpSetPaintMode != 0);
59     supportGetPaintMode = (procs->opvpGetPaintMode != 0);
60     supportSetStrokeColor = (procs->opvpSetStrokeColor != 0);
61     supportSetFillColor = (procs->opvpSetFillColor != 0);
62     supportSetBgColor = (procs->opvpSetBgColor != 0);
63     supportNewPath = (procs->opvpNewPath != 0);
64     supportEndPath = (procs->opvpEndPath != 0);
65     supportStrokePath = (procs->opvpStrokePath != 0);
66     supportFillPath = (procs->opvpFillPath != 0);
67     supportStrokeFillPath = (procs->opvpStrokeFillPath != 0);
68     supportSetClipPath = (procs->opvpSetClipPath != 0);
69     supportSetCurrentPoint = (procs->opvpSetCurrentPoint != 0);
70     supportLinePath = (procs->opvpLinePath != 0);
71     supportPolygonPath = (procs->opvpPolygonPath != 0);
72     supportRectanglePath = (procs->opvpRectanglePath != 0);
73     supportRoundRectanglePath = (procs->opvpRoundRectanglePath != 0);
74     supportBezierPath = (procs->opvpBezierPath != 0);
75     supportArcPath = (procs->opvpArcPath != 0);
76     supportDrawImage = (procs->opvpDrawImage != 0);
77     supportStartDrawImage = (procs->opvpStartDrawImage != 0);
78     supportTransferDrawImage = (procs->opvpTransferDrawImage != 0);
79     supportEndDrawImage = (procs->opvpEndDrawImage != 0);
80     supportStartScanline = (procs->opvpStartScanline != 0);
81     supportScanline = (procs->opvpScanline != 0);
82     supportEndScanline = (procs->opvpEndScanline != 0);
83     supportStartRaster = (procs->opvpStartRaster != 0);
84     supportTransferRasterData = (procs->opvpTransferRasterData != 0);
85     supportSkipRaster = (procs->opvpSkipRaster != 0);
86     supportEndRaster = (procs->opvpEndRaster != 0);
87     supportStartStream = (procs->opvpStartStream != 0);
88     supportTransferStreamData = (procs->opvpTransferStreamData != 0);
89     supportEndStream = (procs->opvpEndStream != 0);
90     supportQueryDeviceCapability = (procs->opvpQueryDeviceCapability != 0);
91     supportQueryDeviceInfo = (procs->opvpQueryDeviceInfo != 0);
92     supportResetClipPath = (procs->opvpResetClipPath != 0);
93 }
94
95 OPVPWrapper::~OPVPWrapper()
96 {
97     unloadDriver(opvpHandle);
98     opvpHandle = 0;
99 }
100
101 opvp_result_t OPVPWrapper::ClosePrinter()
102 {
103     if (!supportClosePrinter) {
104         *opvpErrorNo = OPVP_NOTSUPPORTED;
105         return -1;
106     }
107     return procs->opvpClosePrinter(printerContext);
108 }
109
110 opvp_result_t OPVPWrapper::StartJob(const opvp_char_t *jobInfo)
111 {
112     if (!supportStartJob) {
113         *opvpErrorNo = OPVP_NOTSUPPORTED;
114         return -1;
115     }
116     return procs->opvpStartJob(printerContext,jobInfo);
117 }
118
119 opvp_result_t OPVPWrapper::EndJob()
120 {
121     if (!supportEndJob) {
122         *opvpErrorNo = OPVP_NOTSUPPORTED;
123         return -1;
124     }
125     return procs->opvpEndJob(printerContext);
126 }
127
128 opvp_result_t OPVPWrapper::AbortJob()
129 {
130     if (!supportAbortJob) {
131         *opvpErrorNo = OPVP_NOTSUPPORTED;
132         return -1;
133     }
134     return procs->opvpAbortJob(printerContext);
135 }
136
137 opvp_result_t OPVPWrapper::StartDoc(const opvp_char_t *docInfo)
138 {
139     if (!supportStartDoc) {
140         *opvpErrorNo = OPVP_NOTSUPPORTED;
141         return -1;
142     }
143     return procs->opvpStartDoc(printerContext,docInfo);
144 }
145
146 opvp_result_t OPVPWrapper::EndDoc()
147 {
148     if (!supportEndDoc) {
149         *opvpErrorNo = OPVP_NOTSUPPORTED;
150         return -1;
151     }
152     return procs->opvpEndDoc(printerContext);
153 }
154
155 opvp_result_t OPVPWrapper::StartPage(const opvp_char_t *pageInfo)
156 {
157     if (!supportStartPage) {
158         *opvpErrorNo = OPVP_NOTSUPPORTED;
159         return -1;
160     }
161     return procs->opvpStartPage(printerContext,pageInfo);
162 }
163
164 opvp_result_t OPVPWrapper::EndPage()
165 {
166     if (!supportEndPage) {
167         *opvpErrorNo = OPVP_NOTSUPPORTED;
168         return -1;
169     }
170     return procs->opvpEndPage(printerContext);
171 }
172
173 opvp_result_t OPVPWrapper::QueryDeviceCapability(opvp_flag_t queryflag,
174   opvp_int_t *buflen, opvp_byte_t *infoBuf)
175 {
176     if (!supportQueryDeviceCapability) {
177         *opvpErrorNo = OPVP_NOTSUPPORTED;
178         return -1;
179     }
180     return procs->opvpQueryDeviceCapability(printerContext,queryflag,
181       buflen,infoBuf);
182 }
183
184 opvp_result_t OPVPWrapper::QueryDeviceInfo(opvp_flag_t queryflag,
185   opvp_int_t *buflen, opvp_byte_t *infoBuf)
186 {
187     if (!supportQueryDeviceInfo) {
188         *opvpErrorNo = OPVP_NOTSUPPORTED;
189         return -1;
190     }
191     return procs->opvpQueryDeviceInfo(printerContext,queryflag,
192       buflen,infoBuf);
193 }
194
195 opvp_result_t OPVPWrapper::ResetCTM()
196 {
197     if (!supportResetCTM) {
198         *opvpErrorNo = OPVP_NOTSUPPORTED;
199         return -1;
200     }
201     return procs->opvpResetCTM(printerContext);
202 }
203
204 opvp_result_t OPVPWrapper::SetCTM(const opvp_ctm_t *pCTM)
205 {
206     if (!supportSetCTM) {
207         *opvpErrorNo = OPVP_NOTSUPPORTED;
208         return -1;
209     }
210     return procs->opvpSetCTM(printerContext,pCTM);
211 }
212
213 opvp_result_t OPVPWrapper::GetCTM(opvp_ctm_t *pCTM)
214 {
215     if (!supportGetCTM) {
216         *opvpErrorNo = OPVP_NOTSUPPORTED;
217         return -1;
218     }
219     return procs->opvpGetCTM(printerContext,pCTM);
220 }
221
222 opvp_result_t OPVPWrapper::InitGS()
223 {
224     if (!supportInitGS) {
225         *opvpErrorNo = OPVP_NOTSUPPORTED;
226         return -1;
227     }
228     return procs->opvpInitGS(printerContext);
229 }
230
231 opvp_result_t OPVPWrapper::SaveGS()
232 {
233     if (!supportSaveGS) {
234         *opvpErrorNo = OPVP_NOTSUPPORTED;
235         return -1;
236     }
237     return procs->opvpSaveGS(printerContext);
238 }
239
240 opvp_result_t OPVPWrapper::RestoreGS()
241 {
242     if (!supportRestoreGS) {
243         *opvpErrorNo = OPVP_NOTSUPPORTED;
244         return -1;
245     }
246     return procs->opvpRestoreGS(printerContext);
247 }
248
249 opvp_result_t OPVPWrapper::QueryColorSpace(opvp_int_t *pnum,
250   opvp_cspace_t *pcspace)
251 {
252     if (!supportQueryColorSpace) {
253         *opvpErrorNo = OPVP_NOTSUPPORTED;
254         return -1;
255     }
256     return procs->opvpQueryColorSpace(printerContext,pnum,pcspace);
257 }
258
259 opvp_result_t OPVPWrapper::SetColorSpace(opvp_cspace_t cspace)
260 {
261     if (!supportSetColorSpace) {
262         *opvpErrorNo = OPVP_NOTSUPPORTED;
263         return -1;
264     }
265     return procs->opvpSetColorSpace(printerContext,cspace);
266 }
267
268 opvp_result_t OPVPWrapper::GetColorSpace(opvp_cspace_t *pcspace)
269 {
270     if (!supportGetColorSpace) {
271         *opvpErrorNo = OPVP_NOTSUPPORTED;
272         return -1;
273     }
274     return procs->opvpGetColorSpace(printerContext,pcspace);
275 }
276
277 opvp_result_t OPVPWrapper::SetFillMode(opvp_fillmode_t fillmode)
278 {
279     if (!supportSetFillMode) {
280         *opvpErrorNo = OPVP_NOTSUPPORTED;
281         return -1;
282     }
283     return procs->opvpSetFillMode(printerContext,fillmode);
284 }
285
286 opvp_result_t OPVPWrapper::GetFillMode(opvp_fillmode_t *pfillmode)
287 {
288     if (!supportGetFillMode) {
289         *opvpErrorNo = OPVP_NOTSUPPORTED;
290         return -1;
291     }
292     return procs->opvpGetFillMode(printerContext,pfillmode);
293 }
294
295 opvp_result_t OPVPWrapper::SetAlphaConstant(opvp_float_t alpha)
296 {
297     if (!supportSetAlphaConstant) {
298         *opvpErrorNo = OPVP_NOTSUPPORTED;
299         return -1;
300     }
301     return procs->opvpSetAlphaConstant(printerContext,alpha);
302 }
303
304 opvp_result_t OPVPWrapper::GetAlphaConstant(opvp_float_t *palpha)
305 {
306     if (!supportGetAlphaConstant) {
307         *opvpErrorNo = OPVP_NOTSUPPORTED;
308         return -1;
309     }
310     return procs->opvpGetAlphaConstant(printerContext,palpha);
311 }
312
313 opvp_result_t OPVPWrapper::SetLineWidth(opvp_fix_t width)
314 {
315     if (!supportSetLineWidth) {
316         *opvpErrorNo = OPVP_NOTSUPPORTED;
317         return -1;
318     }
319     return procs->opvpSetLineWidth(printerContext,width);
320 }
321
322 opvp_result_t OPVPWrapper::GetLineWidth(opvp_fix_t *pwidth)
323 {
324     if (!supportGetLineWidth) {
325         *opvpErrorNo = OPVP_NOTSUPPORTED;
326         return -1;
327     }
328     return procs->opvpGetLineWidth(printerContext,pwidth);
329 }
330
331 opvp_result_t OPVPWrapper::SetLineDash(opvp_int_t num,
332   const opvp_fix_t *pdash)
333 {
334     if (!supportSetLineDash) {
335         *opvpErrorNo = OPVP_NOTSUPPORTED;
336         return -1;
337     }
338     return procs->opvpSetLineDash(printerContext,num,pdash);
339 }
340
341 opvp_result_t OPVPWrapper::GetLineDash(opvp_int_t *pnum, opvp_fix_t *pdash)
342 {
343     if (!supportGetLineDash) {
344         *opvpErrorNo = OPVP_NOTSUPPORTED;
345         return -1;
346     }
347     return procs->opvpGetLineDash(printerContext,pnum,pdash);
348 }
349
350 opvp_result_t OPVPWrapper::SetLineDashOffset(opvp_fix_t offset)
351 {
352     if (!supportSetLineDashOffset) {
353         *opvpErrorNo = OPVP_NOTSUPPORTED;
354         return -1;
355     }
356     return procs->opvpSetLineDashOffset(printerContext,offset);
357 }
358
359 opvp_result_t OPVPWrapper::GetLineDashOffset(opvp_fix_t *poffset)
360 {
361     if (!supportGetLineDashOffset) {
362         *opvpErrorNo = OPVP_NOTSUPPORTED;
363         return -1;
364     }
365     return procs->opvpGetLineDashOffset(printerContext,poffset);
366 }
367
368 opvp_result_t OPVPWrapper::SetLineStyle(opvp_linestyle_t linestyle)
369 {
370     if (!supportSetLineStyle) {
371         *opvpErrorNo = OPVP_NOTSUPPORTED;
372         return -1;
373     }
374     return procs->opvpSetLineStyle(printerContext,linestyle);
375 }
376
377 opvp_result_t OPVPWrapper::GetLineStyle(opvp_linestyle_t *plinestyle)
378 {
379     if (!supportGetLineStyle) {
380         *opvpErrorNo = OPVP_NOTSUPPORTED;
381         return -1;
382     }
383     return procs->opvpGetLineStyle(printerContext,plinestyle);
384 }
385
386 opvp_result_t OPVPWrapper::SetLineCap(opvp_linecap_t linecap)
387 {
388     if (!supportSetLineCap) {
389         *opvpErrorNo = OPVP_NOTSUPPORTED;
390         return -1;
391     }
392     return procs->opvpSetLineCap(printerContext,linecap);
393 }
394
395 opvp_result_t OPVPWrapper::GetLineCap(opvp_linecap_t *plinecap)
396 {
397     if (!supportGetLineCap) {
398         *opvpErrorNo = OPVP_NOTSUPPORTED;
399         return -1;
400     }
401     return procs->opvpGetLineCap(printerContext,plinecap);
402 }
403
404 opvp_result_t OPVPWrapper::SetLineJoin(opvp_linejoin_t linejoin)
405 {
406     if (!supportSetLineJoin) {
407         *opvpErrorNo = OPVP_NOTSUPPORTED;
408         return -1;
409     }
410     return procs->opvpSetLineJoin(printerContext,linejoin);
411 }
412
413 opvp_result_t OPVPWrapper::GetLineJoin(opvp_linejoin_t *plinejoin)
414 {
415     if (!supportGetLineJoin) {
416         *opvpErrorNo = OPVP_NOTSUPPORTED;
417         return -1;
418     }
419     return procs->opvpGetLineJoin(printerContext,plinejoin);
420 }
421
422 opvp_result_t OPVPWrapper::SetMiterLimit(opvp_fix_t miterlimit)
423 {
424     if (!supportSetMiterLimit) {
425         *opvpErrorNo = OPVP_NOTSUPPORTED;
426         return -1;
427     }
428     return procs->opvpSetMiterLimit(printerContext,miterlimit);
429 }
430
431 opvp_result_t OPVPWrapper::GetMiterLimit(opvp_fix_t *pmiterlimit)
432 {
433     if (!supportGetMiterLimit) {
434         *opvpErrorNo = OPVP_NOTSUPPORTED;
435         return -1;
436     }
437     return procs->opvpGetMiterLimit(printerContext,pmiterlimit);
438 }
439
440 opvp_result_t OPVPWrapper::SetPaintMode(opvp_paintmode_t paintmode)
441 {
442     if (!supportSetPaintMode) {
443         *opvpErrorNo = OPVP_NOTSUPPORTED;
444         return -1;
445     }
446     return procs->opvpSetPaintMode(printerContext,paintmode);
447 }
448
449 opvp_result_t OPVPWrapper::GetPaintMode(opvp_paintmode_t *ppaintmode)
450 {
451     if (!supportGetPaintMode) {
452         *opvpErrorNo = OPVP_NOTSUPPORTED;
453         return -1;
454     }
455     return procs->opvpGetPaintMode(printerContext,ppaintmode);
456 }
457
458 opvp_result_t OPVPWrapper::SetStrokeColor(const opvp_brush_t *brush)
459 {
460     if (!supportSetStrokeColor) {
461         *opvpErrorNo = OPVP_NOTSUPPORTED;
462         return -1;
463     }
464     return procs->opvpSetStrokeColor(printerContext,brush);
465 }
466
467 opvp_result_t OPVPWrapper::SetFillColor(const opvp_brush_t *brush)
468 {
469     if (!supportSetFillColor) {
470         *opvpErrorNo = OPVP_NOTSUPPORTED;
471         return -1;
472     }
473     return procs->opvpSetFillColor(printerContext,brush);
474 }
475
476 opvp_result_t OPVPWrapper::SetBgColor(const opvp_brush_t *brush)
477 {
478     if (!supportSetBgColor) {
479         *opvpErrorNo = OPVP_NOTSUPPORTED;
480         return -1;
481     }
482     return procs->opvpSetBgColor(printerContext,brush);
483 }
484
485 opvp_result_t OPVPWrapper::NewPath()
486 {
487     if (!supportNewPath) {
488         *opvpErrorNo = OPVP_NOTSUPPORTED;
489         return -1;
490     }
491     return procs->opvpNewPath(printerContext);
492 }
493
494 opvp_result_t OPVPWrapper::EndPath()
495 {
496     if (!supportEndPath) {
497         *opvpErrorNo = OPVP_NOTSUPPORTED;
498         return -1;
499     }
500     return procs->opvpEndPath(printerContext);
501 }
502
503 opvp_result_t OPVPWrapper::StrokePath()
504 {
505     if (!supportStrokePath) {
506         *opvpErrorNo = OPVP_NOTSUPPORTED;
507         return -1;
508     }
509     return procs->opvpStrokePath(printerContext);
510 }
511
512 opvp_result_t OPVPWrapper::FillPath()
513 {
514     if (!supportFillPath) {
515         *opvpErrorNo = OPVP_NOTSUPPORTED;
516         return -1;
517     }
518     return procs->opvpFillPath(printerContext);
519 }
520
521 opvp_result_t OPVPWrapper::StrokeFillPath()
522 {
523     if (!supportStrokeFillPath) {
524         *opvpErrorNo = OPVP_NOTSUPPORTED;
525         return -1;
526     }
527     return procs->opvpStrokeFillPath(printerContext);
528 }
529
530 opvp_result_t OPVPWrapper::SetClipPath(opvp_cliprule_t clipRule)
531 {
532     if (!supportSetClipPath) {
533         *opvpErrorNo = OPVP_NOTSUPPORTED;
534         return -1;
535     }
536     return procs->opvpSetClipPath(printerContext,clipRule);
537 }
538
539 opvp_result_t OPVPWrapper::SetCurrentPoint(opvp_fix_t x, opvp_fix_t y)
540 {
541     if (!supportSetCurrentPoint) {
542         *opvpErrorNo = OPVP_NOTSUPPORTED;
543         return -1;
544     }
545     return procs->opvpSetCurrentPoint(printerContext,x,y);
546 }
547
548 opvp_result_t OPVPWrapper::LinePath(opvp_pathmode_t flag,
549   opvp_int_t npoints, const opvp_point_t *points)
550 {
551     if (!supportLinePath) {
552         *opvpErrorNo = OPVP_NOTSUPPORTED;
553         return -1;
554     }
555     return procs->opvpLinePath(printerContext,flag,npoints,points);
556 }
557
558 opvp_result_t OPVPWrapper::PolygonPath(opvp_int_t npolygons,
559   const opvp_int_t *nvertexes, const opvp_point_t *points)
560 {
561     if (!supportPolygonPath) {
562         *opvpErrorNo = OPVP_NOTSUPPORTED;
563         return -1;
564     }
565     return procs->opvpPolygonPath(printerContext,npolygons,nvertexes,points);
566 }
567
568 opvp_result_t OPVPWrapper::RectanglePath(opvp_int_t nrectangles,
569   const opvp_rectangle_t *rectangles)
570 {
571     if (!supportRectanglePath) {
572         *opvpErrorNo = OPVP_NOTSUPPORTED;
573         return -1;
574     }
575     return procs->opvpRectanglePath(printerContext,nrectangles,rectangles);
576 }
577
578 opvp_result_t OPVPWrapper::RoundRectanglePath(opvp_int_t nrectangles,
579   const opvp_roundrectangle_t *rectangles)
580 {
581     if (!supportRoundRectanglePath) {
582         *opvpErrorNo = OPVP_NOTSUPPORTED;
583         return -1;
584     }
585     return procs->opvpRoundRectanglePath(printerContext,nrectangles,rectangles);
586 }
587
588 opvp_result_t OPVPWrapper::BezierPath(opvp_int_t npoints,
589   const opvp_point_t *points)
590 {
591     if (!supportBezierPath) {
592         *opvpErrorNo = OPVP_NOTSUPPORTED;
593         return -1;
594     }
595     return procs->opvpBezierPath(printerContext,npoints,points);
596 }
597
598 opvp_result_t OPVPWrapper::ArcPath(opvp_arcmode_t kind,
599   opvp_arcdir_t dir, opvp_fix_t bbx0,
600   opvp_fix_t bby0, opvp_fix_t bbx1, opvp_fix_t bby1, opvp_fix_t x0,
601   opvp_fix_t y0, opvp_fix_t x1, opvp_fix_t y1)
602 {
603     if (!supportArcPath) {
604         *opvpErrorNo = OPVP_NOTSUPPORTED;
605         return -1;
606     }
607     return procs->opvpArcPath(printerContext,kind,dir,bbx0,bby0,
608        bbx1,bby1,x0,y0,x1,y1);
609 }
610
611 opvp_result_t OPVPWrapper::DrawImage(
612   opvp_int_t sourceWidth, opvp_int_t sourceHeight, opvp_int_t sourcePitch,
613   opvp_imageformat_t imageFormat, opvp_int_t destinationWidth,
614   opvp_int_t destinationHeight, const void *imagedata)
615 {
616     if (!supportDrawImage) {
617       int result;
618
619       if ((result = StartDrawImage(sourceWidth,sourceHeight,sourcePitch,
620         imageFormat,destinationWidth,destinationHeight)) < 0) {
621         return result;
622       }
623       if ((result = TransferDrawImage(sourcePitch*sourceHeight,
624         imagedata)) < 0) {
625         return result;
626       }
627       return EndDrawImage();
628     }
629     return procs->opvpDrawImage(printerContext,sourceWidth, sourceHeight,
630       sourcePitch, imageFormat, destinationWidth, destinationHeight,
631       imagedata);
632 }
633
634 opvp_result_t OPVPWrapper::StartDrawImage(
635   opvp_int_t sourceWidth, opvp_int_t sourceHeight, opvp_int_t sourcePitch,
636   opvp_imageformat_t imageFormat, opvp_int_t destinationWidth,
637   opvp_int_t destinationHeight)
638 {
639     if (!supportStartDrawImage) {
640         *opvpErrorNo = OPVP_NOTSUPPORTED;
641         return -1;
642     }
643     return procs->opvpStartDrawImage(printerContext,sourceWidth,
644       sourceHeight,sourcePitch,imageFormat,
645       destinationWidth,destinationHeight);
646 }
647
648 opvp_result_t OPVPWrapper::TransferDrawImage(opvp_int_t count,
649   const void *imagedata)
650 {
651     if (!supportTransferDrawImage) {
652         *opvpErrorNo = OPVP_NOTSUPPORTED;
653         return -1;
654     }
655     return procs->opvpTransferDrawImage(printerContext,count,imagedata);
656 }
657
658 opvp_result_t OPVPWrapper::EndDrawImage()
659 {
660     if (!supportEndDrawImage) {
661         *opvpErrorNo = OPVP_NOTSUPPORTED;
662         return -1;
663     }
664     return procs->opvpEndDrawImage(printerContext);
665 }
666
667 opvp_result_t OPVPWrapper::StartScanline(opvp_int_t yposition)
668 {
669     if (!supportStartScanline) {
670         *opvpErrorNo = OPVP_NOTSUPPORTED;
671         return -1;
672     }
673     return procs->opvpStartScanline(printerContext,yposition);
674 }
675
676 opvp_result_t OPVPWrapper::Scanline(opvp_int_t nscanpairs,
677   const opvp_int_t *scanpairs)
678 {
679     if (!supportScanline) {
680         *opvpErrorNo = OPVP_NOTSUPPORTED;
681         return -1;
682     }
683     return procs->opvpScanline(printerContext,nscanpairs,scanpairs);
684 }
685
686 opvp_result_t OPVPWrapper::EndScanline()
687 {
688     if (!supportEndScanline) {
689         *opvpErrorNo = OPVP_NOTSUPPORTED;
690         return -1;
691     }
692     return procs->opvpEndScanline(printerContext);
693 }
694
695 opvp_result_t OPVPWrapper::StartRaster(
696   opvp_int_t rasterWidth)
697 {
698     if (!supportStartRaster) {
699         *opvpErrorNo = OPVP_NOTSUPPORTED;
700         return -1;
701     }
702     return procs->opvpStartRaster(printerContext,rasterWidth);
703 }
704
705 opvp_result_t OPVPWrapper::TransferRasterData(opvp_int_t count,
706   const opvp_byte_t *data)
707 {
708     if (!supportTransferRasterData) {
709         *opvpErrorNo = OPVP_NOTSUPPORTED;
710         return -1;
711     }
712     return procs->opvpTransferRasterData(printerContext,count,
713       data);
714 }
715
716 opvp_result_t OPVPWrapper::SkipRaster(opvp_int_t count)
717 {
718     if (!supportSkipRaster) {
719         *opvpErrorNo = OPVP_NOTSUPPORTED;
720         return -1;
721     }
722     return procs->opvpSkipRaster(printerContext,count);
723 }
724
725 opvp_result_t OPVPWrapper::EndRaster()
726 {
727     if (!supportEndRaster) {
728         *opvpErrorNo = OPVP_NOTSUPPORTED;
729         return -1;
730     }
731     return procs->opvpEndRaster(printerContext);
732 }
733
734 opvp_result_t OPVPWrapper::StartStream()
735 {
736     if (!supportStartStream) {
737         *opvpErrorNo = OPVP_NOTSUPPORTED;
738         return -1;
739     }
740     return procs->opvpStartStream(printerContext);
741 }
742
743 opvp_result_t OPVPWrapper::TransferStreamData(opvp_int_t count,
744   const void *data)
745 {
746     if (!supportTransferStreamData) {
747         *opvpErrorNo = OPVP_NOTSUPPORTED;
748         return -1;
749     }
750     return procs->opvpTransferStreamData(printerContext,count,data);
751 }
752
753 opvp_result_t OPVPWrapper::EndStream()
754 {
755     if (!supportEndStream) {
756         *opvpErrorNo = OPVP_NOTSUPPORTED;
757         return -1;
758     }
759     return procs->opvpEndStream(printerContext);
760 }
761
762 opvp_result_t OPVPWrapper::ResetClipPath()
763 {
764     if (!supportResetClipPath) {
765         *opvpErrorNo = OPVP_NOTSUPPORTED;
766         return -1;
767     }
768     return procs->opvpResetClipPath(printerContext);
769 }
770
771 char *OPVPWrapper::allocString(char **destin, unsigned int size)
772 {
773     if (!destin) return 0;
774
775     if (*destin != 0) delete[] *destin;
776     if (size > 0) {
777         *destin = new char[size];
778     }
779
780     return *destin;
781 }
782
783 char **OPVPWrapper::genDynamicLibName(const char *name)
784 {
785     static char *buff[5] = {0,0,0,0,0};
786
787     allocString(&(buff[0]), strlen(name)+1);
788     strcpy(buff[0], name);
789     allocString(&(buff[1]), strlen(name)+3+1);
790     strcpy(buff[1], name);
791     strcat(buff[1], ".so");
792     allocString(&(buff[2]), strlen(name)+4+1);
793     strcpy(buff[2], name);
794     strcat(buff[2], ".dll");
795     allocString(&(buff[3]), strlen(name)+6+1);
796     strcpy(buff[3], "lib");
797     strcat(buff[3], name);
798     strcat(buff[3], ".so");
799     buff[4] = 0;
800
801     return buff;
802 }
803
804 OPVPWrapper *OPVPWrapper::loadDriver(const char *driverName,
805   int outputFD, const char *printerModel)
806 {
807     char **list = 0;
808     int  i;
809     void *h;
810     int nApiEntry;
811     int (*opvpOpenPrinter)(opvp_int_t outputFD,
812       const opvp_char_t * printerModel, const opvp_int_t version[2],
813       opvp_api_procs_t **apiEntry) = 0;
814     int (*opvpOpenPrinter_0_2)(int outputFD, char* printerModel,
815       int *nApiEntry, OPVP_api_procs **apiEntry) = 0;
816     opvp_api_procs_t *opvpProcs;
817     OPVP_api_procs *opvpProcs_0_2;
818     opvp_dc_t opvpContext;
819     int opvpContext_0_2 = 0;
820     opvp_int_t *opvpErrorNo = 0;
821     int *opvpErrorNo_0_2 = 0;
822     void *handle = 0;
823     OPVPWrapper *opvp = 0;
824
825     list = genDynamicLibName(driverName);
826
827     if (list) {
828         i = 0;
829         while (list[i]) {
830             if ((h = dlopen(list[i],RTLD_NOW))) {
831                 opvpOpenPrinter = (int (*)(opvp_int_t,
832                   const opvp_char_t *, const opvp_int_t[2],
833                   opvp_api_procs_t **))dlsym(h,"opvpOpenPrinter");
834                 opvpErrorNo = (opvp_int_t *)dlsym(h,"opvpErrorNo");
835                 if (opvpOpenPrinter && opvpErrorNo) {
836                     handle = h;
837                     break;
838                 }
839                 opvpOpenPrinter = 0;
840                 opvpErrorNo = 0;
841                 /* try version 0.2 driver */
842                 opvpOpenPrinter_0_2 = (int (*)(int, char*, int *,
843                   OPVP_api_procs **))dlsym(h,"OpenPrinter");
844                 opvpErrorNo_0_2 = (int *)dlsym(h,"errorno");
845                 if (opvpOpenPrinter_0_2 && opvpErrorNo_0_2) {
846                     handle = h;
847                     break;
848                 }
849                 opvpOpenPrinter_0_2 = 0;
850                 opvpErrorNo_0_2 = 0;
851             }
852             i++;
853         }
854         for (i = 0;list[i] != 0;i++) {
855             delete[] (list[i]);
856             list[i] = 0;
857         }
858     }
859     if (handle == 0) {
860       OPRS::error("Loading vector printer driver (%s) fail\n",driverName);
861       return 0;
862     }
863     if (opvpOpenPrinter != 0) {
864         opvp_int_t apiVersion[2];
865
866         /* require version 1.0 */
867         apiVersion[0] = 1;
868         apiVersion[1] = 0;
869         if ((opvpContext = (*opvpOpenPrinter)(outputFD,
870              (const opvp_char_t *)printerModel,apiVersion,&opvpProcs)) < 0) {
871             OPRS::error("OpenPrinter fail\n",driverName);
872             unloadDriver(handle);
873             return 0;
874         }
875         opvp = new OPVPWrapper(handle, opvpErrorNo, opvpProcs, opvpContext);
876     } else if (opvpOpenPrinter_0_2) {
877         if ((opvpContext_0_2 = (*opvpOpenPrinter_0_2)(outputFD,
878              (char *)printerModel,&nApiEntry,&opvpProcs_0_2)) < 0) {
879             OPRS::error("OpenPrinter fail\n",driverName);
880             unloadDriver(handle);
881             return 0;
882         }
883         opvp = (OPVPWrapper *)new OPVPWrapper_0_2(handle, opvpErrorNo_0_2,
884           opvpProcs_0_2, opvpContext_0_2);
885     }
886     return opvp;
887 }
888
889 /*
890  * unload vector-driver
891  */
892 int OPVPWrapper::unloadDriver(void *opvpHandleA)
893 {
894     if (opvpHandleA != 0) {
895         dlclose(opvpHandleA);
896     }
897     return 0;
898 }
899
900 opvp_int_t OPVPWrapper::getErrorNo()
901 {
902     return *opvpErrorNo;
903 }
904