1 //========================================================================
3 // GDKSplashOutputDev.cc
5 // Copyright 2003 Glyph & Cog, LLC
6 // Copyright 2004 Red Hat, Inc. (GDK port)
8 //========================================================================
10 #ifdef USE_GCC_PRAGMAS
11 #pragma implementation
15 #include <splash/SplashTypes.h>
16 #include <splash/SplashBitmap.h>
19 #include <TextOutputDev.h>
20 #include <GDKSplashOutputDev.h>
22 //------------------------------------------------------------------------
23 // Constants and macros
24 //------------------------------------------------------------------------
26 #define xoutRound(x) ((int)(x + 0.5))
28 //------------------------------------------------------------------------
30 //------------------------------------------------------------------------
32 static SplashColor makeSplashColor(int r, int g, int b)
35 c.rgb8 = splashMakeRGB8 (r, g, b);
39 GDKSplashOutputDev::GDKSplashOutputDev(GdkScreen *screen,
40 void (*redrawCbkA)(void *data),
41 void *redrawCbkDataA):
42 SplashOutputDev(splashModeRGB8Packed, gFalse, makeSplashColor (255,255,255)),
45 redrawCbk = redrawCbkA;
46 redrawCbkData = redrawCbkDataA;
49 text = new TextPage(gFalse);
52 GDKSplashOutputDev::~GDKSplashOutputDev() {
56 void GDKSplashOutputDev::drawChar(GfxState *state, double x, double y,
58 double originX, double originY,
59 CharCode code, Unicode *u, int uLen) {
60 text->addChar(state, x, y, dx, dy, code, u, uLen);
61 SplashOutputDev::drawChar(state, x, y, dx, dy, originX, originY,
65 GBool GDKSplashOutputDev::beginType3Char(GfxState *state, double x, double y,
67 CharCode code, Unicode *u, int uLen) {
68 text->addChar(state, x, y, dx, dy, code, u, uLen);
69 return SplashOutputDev::beginType3Char(state, x, y, dx, dy, code, u, uLen);
72 void GDKSplashOutputDev::clear() {
77 void GDKSplashOutputDev::startPage(int pageNum, GfxState *state) {
78 SplashOutputDev::startPage(pageNum, state);
79 text->startPage(state);
82 void GDKSplashOutputDev::endPage() {
83 SplashOutputDev::endPage();
84 if (!incrementalUpdate) {
85 (*redrawCbk)(redrawCbkData);
87 text->coalesce(gTrue);
90 void GDKSplashOutputDev::dump() {
91 if (incrementalUpdate && redrawCbk) {
92 (*redrawCbk)(redrawCbkData);
96 void GDKSplashOutputDev::updateFont(GfxState *state) {
97 SplashOutputDev::updateFont(state);
98 text->updateFont(state);
101 void GDKSplashOutputDev::redraw(int srcX, int srcY,
102 GdkDrawable *drawable,
103 int destX, int destY,
104 int width, int height) {
108 gdk_rowstride = getBitmap()->getRowSize();
109 gc = gdk_gc_new (drawable);
111 gdk_draw_rgb_image (drawable, gc,
114 GDK_RGB_DITHER_NORMAL,
115 getBitmap()->getDataPtr().rgb8p + srcY * gdk_rowstride + srcX * 3,
121 void GDKSplashOutputDev::drawToPixbuf(GdkPixbuf *pixbuf, int pageNum) {
125 GBool GDKSplashOutputDev::findText(Unicode *s, int len,
126 GBool startAtTop, GBool stopAtBottom,
127 GBool startAtLast, GBool stopAtLast,
128 int *xMin, int *yMin,
129 int *xMax, int *yMax) {
130 double xMin1, yMin1, xMax1, yMax1;
132 xMin1 = (double)*xMin;
133 yMin1 = (double)*yMin;
134 xMax1 = (double)*xMax;
135 yMax1 = (double)*yMax;
136 if (text->findText(s, len, startAtTop, stopAtBottom,
137 startAtLast, stopAtLast,
138 &xMin1, &yMin1, &xMax1, &yMax1)) {
139 *xMin = xoutRound(xMin1);
140 *xMax = xoutRound(xMax1);
141 *yMin = xoutRound(yMin1);
142 *yMax = xoutRound(yMax1);
148 GooString *GDKSplashOutputDev::getText(int xMin, int yMin, int xMax, int yMax) {
149 return text->getText((double)xMin, (double)yMin,
150 (double)xMax, (double)yMax);