filters

XPixmapOutputDev.cpp
1//========================================================================
2//
3// XPixmapOutputDev.cpp
4//
5// Copyright 2002 Glyph & Cog, LLC
6//
7//========================================================================
8
9#include <aconf.h>
10
11#ifdef USE_GCC_PRAGMAS
12#pragma implementation
13#endif
14
15#include "Object.h"
16#include "GfxState.h"
17#include "XPixmapOutputDev.h"
18
19//------------------------------------------------------------------------
20
21#define xoutRound(x) ((int)(x + 0.5))
22
23//------------------------------------------------------------------------
24
25XPixmapOutputDev::XPixmapOutputDev(Display *displayA, int screenNumA,
26 Visual *visualA, Colormap colormapA,
27 GBool reverseVideoA, Gulong paperColorA,
28 GBool installCmapA, int rgbCubeSizeA,
29 GBool incrementalUpdateA,
30 void (*redrawCbkA)(void *data),
31 void *redrawCbkDataA):
32 XOutputDev(displayA, screenNumA, visualA, colormapA,
33 reverseVideoA, paperColorA, installCmapA, rgbCubeSizeA)
34{
35 incrementalUpdate = incrementalUpdateA;
36 redrawCbk = redrawCbkA;
37 redrawCbkData = redrawCbkDataA;
38}
39
40XPixmapOutputDev::~XPixmapOutputDev() {
41 if (getPixmapWidth() > 0) {
42 XFreePixmap(getDisplay(), getPixmap());
43 }
44}
45
46void XPixmapOutputDev::clear() {
47 startDoc(NULL);
48 startPage(0, NULL);
49}
50
51void XPixmapOutputDev::startPage(int pageNum, GfxState *state) {
52 int oldPixmapW, oldPixmapH, newPixmapW, newPixmapH;
53
54 // resize the off-screen pixmap (if needed)
55 oldPixmapW = getPixmapWidth();
56 oldPixmapH = getPixmapHeight();
57 newPixmapW = xoutRound(state ? state->getPageWidth() : 1);
58 newPixmapH = xoutRound(state ? state->getPageHeight() : 1);
59 if (oldPixmapW == 0 ||
60 newPixmapW != oldPixmapW || newPixmapH != oldPixmapH) {
61 if (oldPixmapW > 0) {
62 XFreePixmap(getDisplay(), getPixmap());
63 }
64 setPixmap(XCreatePixmap(getDisplay(), win, newPixmapW, newPixmapH,
65 getDepth()),
66 newPixmapW, newPixmapH);
67 }
68
69 XOutputDev::startPage(pageNum, state);
70}
71
72void XPixmapOutputDev::endPage() {
73 if (!incrementalUpdate) {
74 (*redrawCbk)(redrawCbkData);
75 }
76 XOutputDev::endPage();
77}
78
79void XPixmapOutputDev::dump() {
80 if (incrementalUpdate) {
81 (*redrawCbk)(redrawCbkData);
82 }
83 XOutputDev::dump();
84}