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(splashModeRGB8Packed, 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 && redrawCbk) {
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) {
110 gdk_rowstride = getBitmap()->getRowSize();
111 gc = gdk_gc_new (drawable);
113 gdk_draw_rgb_image (drawable, gc,
116 GDK_RGB_DITHER_NORMAL,
117 getBitmap()->getDataPtr().rgb8p + srcY * gdk_rowstride + srcX * 3,
123 void GDKSplashOutputDev::drawToPixbuf(GdkPixbuf *pixbuf, int pageNum) {
127 GBool GDKSplashOutputDev::findText(Unicode *s, int len,
128 GBool startAtTop, GBool stopAtBottom,
129 GBool startAtLast, GBool stopAtLast,
130 int *xMin, int *yMin,
131 int *xMax, int *yMax) {
132 double xMin1, yMin1, xMax1, yMax1;
134 xMin1 = (double)*xMin;
135 yMin1 = (double)*yMin;
136 xMax1 = (double)*xMax;
137 yMax1 = (double)*yMax;
138 if (text->findText(s, len, startAtTop, stopAtBottom,
139 startAtLast, stopAtLast,
140 &xMin1, &yMin1, &xMax1, &yMax1)) {
141 *xMin = xoutRound(xMin1);
142 *xMax = xoutRound(xMax1);
143 *yMin = xoutRound(yMin1);
144 *yMax = xoutRound(yMax1);
150 GString *GDKSplashOutputDev::getText(int xMin, int yMin, int xMax, int yMax) {
151 return text->getText((double)xMin, (double)yMin,
152 (double)xMax, (double)yMax);