Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pdf/xpdf/GDKSplashOutputDev.cc
blob: 4ef3bb35f984cb76d11e065674eb4dca74ac3155 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//========================================================================
//
// GDKSplashOutputDev.cc
//
// Copyright 2003 Glyph & Cog, LLC
// Copyright 2004 Red Hat, Inc. (GDK port)
//
//========================================================================

#include <aconf.h>

#ifdef USE_GCC_PRAGMAS
#pragma implementation
#endif

#include "gmem.h"
#include "SplashTypes.h"
#include "SplashBitmap.h"
#include "Object.h"
#include "GfxState.h"
#include "TextOutputDev.h"
#include "GDKSplashOutputDev.h"

//------------------------------------------------------------------------
// Constants and macros
//------------------------------------------------------------------------

#define xoutRound(x) ((int)(x + 0.5))

//------------------------------------------------------------------------
// GDKSplashOutputDev
//------------------------------------------------------------------------

static SplashColor makeSplashColor(int r, int g, int b)
{
  SplashColor c;
  c.rgb8 = splashMakeRGB8 (r, g, b);
  return c;
}

GDKSplashOutputDev::GDKSplashOutputDev(GdkScreen *screen,
                                       void (*redrawCbkA)(void *data),
                                       void *redrawCbkDataA):
  SplashOutputDev(splashModeRGB8, gFalse, makeSplashColor (255,255,255)),
  incrementalUpdate (1)
{
  redrawCbk = redrawCbkA;
  redrawCbkData = redrawCbkDataA;

  // create text object
  text = new TextPage(gFalse);
}

GDKSplashOutputDev::~GDKSplashOutputDev() {
  delete text;
}

void GDKSplashOutputDev::drawChar(GfxState *state, double x, double y,
                                  double dx, double dy,
                                  double originX, double originY,
                                  CharCode code, Unicode *u, int uLen) {
  text->addChar(state, x, y, dx, dy, code, u, uLen);
  SplashOutputDev::drawChar(state, x, y, dx, dy, originX, originY,
			    code, u, uLen);
}

GBool GDKSplashOutputDev::beginType3Char(GfxState *state, double x, double y,
				       double dx, double dy,
				       CharCode code, Unicode *u, int uLen) {
  text->addChar(state, x, y, dx, dy, code, u, uLen);
  return SplashOutputDev::beginType3Char(state, x, y, dx, dy, code, u, uLen);
}

void GDKSplashOutputDev::clear() {
  startDoc(NULL);
  startPage(0, NULL);
}

void GDKSplashOutputDev::startPage(int pageNum, GfxState *state) {
  SplashOutputDev::startPage(pageNum, state);
  text->startPage(state);
}

void GDKSplashOutputDev::endPage() {
  SplashOutputDev::endPage();
  if (!incrementalUpdate) {
    (*redrawCbk)(redrawCbkData);
  }
  text->coalesce(gTrue);
}

void GDKSplashOutputDev::dump() {
  if (incrementalUpdate) {
    (*redrawCbk)(redrawCbkData);
  }
}

void GDKSplashOutputDev::updateFont(GfxState *state) {
  SplashOutputDev::updateFont(state);
  text->updateFont(state);
}

void GDKSplashOutputDev::redraw(int srcX, int srcY,
                                GdkDrawable *drawable,
                                int destX, int destY,
                                int width, int height) {
  SplashColorPtr dataPtr;
  GdkGC *gc;
  guchar *gdk_buf;
  int gdk_rowstride;
  int bw, x, y, r, g, b;

  gdk_rowstride = width * 3;
  
  /* better to draw nothing than crash on a huge image */
  gdk_buf = (guchar*) g_try_malloc (height * gdk_rowstride);
  if (gdk_buf == NULL)
    return;
  
  bw = getBitmap()->getWidth();
  dataPtr = getBitmap()->getDataPtr();
  
  for (y = 0; y < height; ++y)
    {
      SplashRGB8 *p;
      SplashRGB8 rgb;
      guchar *gdk_p;
      
      p = dataPtr.rgb8 + (y + srcY) * bw + srcX;
      gdk_p = gdk_buf + y * gdk_rowstride;
      for (x = 0; x < width; ++x)
        {
          rgb = *p++;
          r = splashRGB8R(rgb);
          g = splashRGB8G(rgb);
          b = splashRGB8B(rgb);

          *gdk_p++ = r;
          *gdk_p++ = g;
          *gdk_p++ = b;
        }
    }
  
  gc = gdk_gc_new (drawable);
  
  gdk_draw_rgb_image (drawable, gc,
                      destX, destY,
                      width, height,
                      GDK_RGB_DITHER_NORMAL,
                      gdk_buf,
                      gdk_rowstride);

  g_object_unref (gc);

  g_free (gdk_buf);
}

GBool GDKSplashOutputDev::findText(Unicode *s, int len,
                                   GBool startAtTop, GBool stopAtBottom,
                                   GBool startAtLast, GBool stopAtLast,
                                   int *xMin, int *yMin,
                                   int *xMax, int *yMax) {
  double xMin1, yMin1, xMax1, yMax1;
  
  xMin1 = (double)*xMin;
  yMin1 = (double)*yMin;
  xMax1 = (double)*xMax;
  yMax1 = (double)*yMax;
  if (text->findText(s, len, startAtTop, stopAtBottom,
		     startAtLast, stopAtLast,
		     &xMin1, &yMin1, &xMax1, &yMax1)) {
    *xMin = xoutRound(xMin1);
    *xMax = xoutRound(xMax1);
    *yMin = xoutRound(yMin1);
    *yMax = xoutRound(yMax1);
    return gTrue;
  }
  return gFalse;
}

GString *GDKSplashOutputDev::getText(int xMin, int yMin, int xMax, int yMax) {
  return text->getText((double)xMin, (double)yMin,
		       (double)xMax, (double)yMax);
}