]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/GDKSplashOutputDev.cc
pdf/splash/SplashBitmap.cc (SplashBitmap, ~SplashBitmap, writePNMFile):
[evince.git] / pdf / xpdf / GDKSplashOutputDev.cc
1 //========================================================================
2 //
3 // GDKSplashOutputDev.cc
4 //
5 // Copyright 2003 Glyph & Cog, LLC
6 // Copyright 2004 Red Hat, Inc. (GDK port)
7 //
8 //========================================================================
9
10 #include <aconf.h>
11
12 #ifdef USE_GCC_PRAGMAS
13 #pragma implementation
14 #endif
15
16 #include "gmem.h"
17 #include "SplashTypes.h"
18 #include "SplashBitmap.h"
19 #include "Object.h"
20 #include "GfxState.h"
21 #include "TextOutputDev.h"
22 #include "GDKSplashOutputDev.h"
23
24 //------------------------------------------------------------------------
25 // Constants and macros
26 //------------------------------------------------------------------------
27
28 #define xoutRound(x) ((int)(x + 0.5))
29
30 //------------------------------------------------------------------------
31 // GDKSplashOutputDev
32 //------------------------------------------------------------------------
33
34 static SplashColor makeSplashColor(int r, int g, int b)
35 {
36   SplashColor c;
37   c.rgb8 = splashMakeRGB8 (r, g, b);
38   return c;
39 }
40
41 GDKSplashOutputDev::GDKSplashOutputDev(GdkScreen *screen,
42                                        void (*redrawCbkA)(void *data),
43                                        void *redrawCbkDataA):
44   SplashOutputDev(splashModeRGB8Packed, gFalse, makeSplashColor (255,255,255)),
45   incrementalUpdate (1)
46 {
47   redrawCbk = redrawCbkA;
48   redrawCbkData = redrawCbkDataA;
49
50   // create text object
51   text = new TextPage(gFalse);
52 }
53
54 GDKSplashOutputDev::~GDKSplashOutputDev() {
55   delete text;
56 }
57
58 void GDKSplashOutputDev::drawChar(GfxState *state, double x, double y,
59                                   double dx, double dy,
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,
64                             code, u, uLen);
65 }
66
67 GBool GDKSplashOutputDev::beginType3Char(GfxState *state, double x, double y,
68                                        double dx, double dy,
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);
72 }
73
74 void GDKSplashOutputDev::clear() {
75   startDoc(NULL);
76   startPage(0, NULL);
77 }
78
79 void GDKSplashOutputDev::startPage(int pageNum, GfxState *state) {
80   SplashOutputDev::startPage(pageNum, state);
81   text->startPage(state);
82 }
83
84 void GDKSplashOutputDev::endPage() {
85   SplashOutputDev::endPage();
86   if (!incrementalUpdate) {
87     (*redrawCbk)(redrawCbkData);
88   }
89   text->coalesce(gTrue);
90 }
91
92 void GDKSplashOutputDev::dump() {
93   if (incrementalUpdate && redrawCbk) {
94     (*redrawCbk)(redrawCbkData);
95   }
96 }
97
98 void GDKSplashOutputDev::updateFont(GfxState *state) {
99   SplashOutputDev::updateFont(state);
100   text->updateFont(state);
101 }
102
103 void GDKSplashOutputDev::redraw(int srcX, int srcY,
104                                 GdkDrawable *drawable,
105                                 int destX, int destY,
106                                 int width, int height) {
107   GdkGC *gc;
108   int gdk_rowstride;
109
110   gdk_rowstride = getBitmap()->getRowSize();
111   gc = gdk_gc_new (drawable);
112   
113   gdk_draw_rgb_image (drawable, gc,
114                       destX, destY,
115                       width, height,
116                       GDK_RGB_DITHER_NORMAL,
117                       getBitmap()->getDataPtr().rgb8p + srcY * gdk_rowstride + srcX,
118                       gdk_rowstride);
119
120   g_object_unref (gc);
121 }
122
123 void GDKSplashOutputDev::drawToPixbuf(GdkPixbuf *pixbuf, int pageNum) {
124         
125 }
126
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;
133   
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);
145     return gTrue;
146   }
147   return gFalse;
148 }
149
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);
153 }