1 //========================================================================
3 // GDKSplashOutputDev.cc
5 // Copyright 2003 Glyph & Cog, LLC
6 // Copyright 2004 Red Hat, Inc. (GDK port)
8 //========================================================================
12 #ifdef USE_GCC_PRAGMAS
13 #pragma implementation
17 #include "SplashTypes.h"
18 #include "SplashBitmap.h"
21 #include "TextOutputDev.h"
22 #include "GDKSplashOutputDev.h"
24 //------------------------------------------------------------------------
25 // Constants and macros
26 //------------------------------------------------------------------------
28 #define xoutRound(x) ((int)(x + 0.5))
30 //------------------------------------------------------------------------
32 //------------------------------------------------------------------------
34 static SplashColor makeSplashColor(int r, int g, int b)
37 c.rgb8 = splashMakeRGB8 (r, g, b);
41 GDKSplashOutputDev::GDKSplashOutputDev(GdkScreen *screen,
42 void (*redrawCbkA)(void *data),
43 void *redrawCbkDataA):
44 SplashOutputDev(splashModeRGB8, gFalse, makeSplashColor (255,255,255)),
47 redrawCbk = redrawCbkA;
48 redrawCbkData = redrawCbkDataA;
51 text = new TextPage(gFalse);
54 GDKSplashOutputDev::~GDKSplashOutputDev() {
58 void GDKSplashOutputDev::drawChar(GfxState *state, double x, double y,
60 double originX, double originY,
61 CharCode code, Unicode *u, int uLen) {
62 text->addChar(state, x, y, dx, dy, code, u, uLen);
63 SplashOutputDev::drawChar(state, x, y, dx, dy, originX, originY,
67 GBool GDKSplashOutputDev::beginType3Char(GfxState *state, double x, double y,
69 CharCode code, Unicode *u, int uLen) {
70 text->addChar(state, x, y, dx, dy, code, u, uLen);
71 return SplashOutputDev::beginType3Char(state, x, y, dx, dy, code, u, uLen);
74 void GDKSplashOutputDev::clear() {
79 void GDKSplashOutputDev::startPage(int pageNum, GfxState *state) {
80 SplashOutputDev::startPage(pageNum, state);
81 text->startPage(state);
84 void GDKSplashOutputDev::endPage() {
85 SplashOutputDev::endPage();
86 if (!incrementalUpdate) {
87 (*redrawCbk)(redrawCbkData);
89 text->coalesce(gTrue);
92 void GDKSplashOutputDev::dump() {
93 if (incrementalUpdate) {
94 (*redrawCbk)(redrawCbkData);
98 void GDKSplashOutputDev::updateFont(GfxState *state) {
99 SplashOutputDev::updateFont(state);
100 text->updateFont(state);
103 void GDKSplashOutputDev::redraw(int srcX, int srcY,
104 GdkDrawable *drawable,
105 int destX, int destY,
106 int width, int height) {
107 SplashColorPtr dataPtr;
111 int bw, x, y, r, g, b;
113 gdk_rowstride = width * 3;
115 /* better to draw nothing than crash on a huge image */
116 gdk_buf = (guchar*) g_try_malloc (height * gdk_rowstride);
120 bw = getBitmap()->getWidth();
121 dataPtr = getBitmap()->getDataPtr();
123 for (y = 0; y < height; ++y)
129 p = dataPtr.rgb8 + (y + srcY) * bw + srcX;
130 gdk_p = gdk_buf + y * gdk_rowstride;
131 for (x = 0; x < width; ++x)
134 r = splashRGB8R(rgb);
135 g = splashRGB8G(rgb);
136 b = splashRGB8B(rgb);
144 gc = gdk_gc_new (drawable);
146 gdk_draw_rgb_image (drawable, gc,
149 GDK_RGB_DITHER_NORMAL,
158 GBool GDKSplashOutputDev::findText(Unicode *s, int len,
159 GBool startAtTop, GBool stopAtBottom,
160 GBool startAtLast, GBool stopAtLast,
161 int *xMin, int *yMin,
162 int *xMax, int *yMax) {
163 double xMin1, yMin1, xMax1, yMax1;
165 xMin1 = (double)*xMin;
166 yMin1 = (double)*yMin;
167 xMax1 = (double)*xMax;
168 yMax1 = (double)*yMax;
169 if (text->findText(s, len, startAtTop, stopAtBottom,
170 startAtLast, stopAtLast,
171 &xMin1, &yMin1, &xMax1, &yMax1)) {
172 *xMin = xoutRound(xMin1);
173 *xMax = xoutRound(xMax1);
174 *yMin = xoutRound(yMin1);
175 *yMax = xoutRound(yMax1);
181 GString *GDKSplashOutputDev::getText(int xMin, int yMin, int xMax, int yMax) {
182 return text->getText((double)xMin, (double)yMin,
183 (double)xMax, (double)yMax);