~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/poppler/poppler/PreScanOutputDev.cc

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//========================================================================
 
2
//
 
3
// PreScanOutputDev.cc
 
4
//
 
5
// Copyright 2005 Glyph & Cog, LLC
 
6
//
 
7
//========================================================================
 
8
 
 
9
//========================================================================
 
10
//
 
11
// Modified under the Poppler project - http://poppler.freedesktop.org
 
12
//
 
13
// All changes made under the Poppler project to this file are licensed
 
14
// under GPL version 2 or later
 
15
//
 
16
// Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
 
17
// Copyright (C) 2010 Albert Astals Cid <aacid@kde.org>
 
18
// Copyright (C) 2011 William Bader <williambader@hotmail.com>
 
19
//
 
20
// To see a description of the changes please see the Changelog file that
 
21
// came with your tarball or type make ChangeLog if you are building from git
 
22
//
 
23
//========================================================================
 
24
 
 
25
#ifdef USE_GCC_PRAGMAS
 
26
#pragma implementation
 
27
#endif
 
28
 
 
29
#include <math.h>
 
30
#include "GlobalParams.h"
 
31
#include "GfxFont.h"
 
32
#include "Link.h"
 
33
#include "PreScanOutputDev.h"
 
34
 
 
35
//------------------------------------------------------------------------
 
36
// PreScanOutputDev
 
37
//------------------------------------------------------------------------
 
38
 
 
39
PreScanOutputDev::PreScanOutputDev() {
 
40
  level = globalParams->getPSLevel();
 
41
  clearStats();
 
42
}
 
43
 
 
44
PreScanOutputDev::~PreScanOutputDev() {
 
45
}
 
46
 
 
47
void PreScanOutputDev::startPage(int /*pageNum*/, GfxState * /*state*/) {
 
48
}
 
49
 
 
50
void PreScanOutputDev::endPage() {
 
51
}
 
52
 
 
53
void PreScanOutputDev::stroke(GfxState *state) {
 
54
  double *dash;
 
55
  int dashLen;
 
56
  double dashStart;
 
57
 
 
58
  check(state->getStrokeColorSpace(), state->getStrokeColor(),
 
59
        state->getStrokeOpacity(), state->getBlendMode());
 
60
  state->getLineDash(&dash, &dashLen, &dashStart);
 
61
  if (dashLen != 0) {
 
62
    gdi = gFalse;
 
63
  }
 
64
}
 
65
 
 
66
void PreScanOutputDev::fill(GfxState *state) {
 
67
  check(state->getFillColorSpace(), state->getFillColor(),
 
68
        state->getFillOpacity(), state->getBlendMode());
 
69
}
 
70
 
 
71
void PreScanOutputDev::eoFill(GfxState *state) {
 
72
  check(state->getFillColorSpace(), state->getFillColor(),
 
73
        state->getFillOpacity(), state->getBlendMode());
 
74
}
 
75
 
 
76
void PreScanOutputDev::clip(GfxState * /*state*/) {
 
77
  //~ check for a rectangle "near" the edge of the page;
 
78
  //~   else set gdi to false
 
79
}
 
80
 
 
81
void PreScanOutputDev::eoClip(GfxState * /*state*/) {
 
82
  //~ see clip()
 
83
}
 
84
 
 
85
void PreScanOutputDev::beginStringOp(GfxState *state) {
 
86
  int render;
 
87
  GfxFont *font;
 
88
  double m11, m12, m21, m22;
 
89
  Ref embRef;
 
90
  DisplayFontParam *dfp;
 
91
  GBool simpleTTF;
 
92
 
 
93
  render = state->getRender();
 
94
  if (!(render & 1)) {
 
95
    check(state->getFillColorSpace(), state->getFillColor(),
 
96
          state->getFillOpacity(), state->getBlendMode());
 
97
  }
 
98
  if ((render & 3) == 1 || (render & 3) == 2) {
 
99
    check(state->getStrokeColorSpace(), state->getStrokeColor(),
 
100
          state->getStrokeOpacity(), state->getBlendMode());
 
101
  }
 
102
 
 
103
  font = state->getFont();
 
104
  state->getFontTransMat(&m11, &m12, &m21, &m22);
 
105
  simpleTTF = fabs(m11 + m22) < 0.01 &&
 
106
              m11 > 0 &&
 
107
              fabs(m12) < 0.01 &&
 
108
              fabs(m21) < 0.01 &&
 
109
              fabs(state->getHorizScaling() - 1) < 0.001 &&
 
110
              (font->getType() == fontTrueType ||
 
111
               font->getType() == fontTrueTypeOT) &&
 
112
              (font->getEmbeddedFontID(&embRef) ||
 
113
               font->getExtFontFile() ||
 
114
               (font->getName() &&
 
115
                (dfp = globalParams->getDisplayFont(font)) &&
 
116
                dfp->kind == displayFontTT));
 
117
  if (simpleTTF) {
 
118
    //~ need to create a FoFiTrueType object, and check for a Unicode cmap
 
119
  }
 
120
  if (state->getRender() != 0 || !simpleTTF) {
 
121
    gdi = gFalse;
 
122
  }
 
123
}
 
124
 
 
125
void PreScanOutputDev::endStringOp(GfxState * /*state*/) {
 
126
}
 
127
 
 
128
GBool PreScanOutputDev::beginType3Char(GfxState * /*state*/, double /*x*/, double /*y*/,
 
129
                                       double /*dx*/, double /*dy*/,
 
130
                                       CharCode /*code*/, Unicode * /*u*/, int /*uLen*/) {
 
131
  // return false so all Type 3 chars get rendered (no caching)
 
132
  return gFalse;
 
133
}
 
134
 
 
135
void PreScanOutputDev::endType3Char(GfxState * /*state*/) {
 
136
}
 
137
 
 
138
void PreScanOutputDev::drawImageMask(GfxState *state, Object * /*ref*/, Stream *str,
 
139
                                     int width, int height, GBool /*invert*/,
 
140
                                     GBool /*interpolate*/, GBool inlineImg) {
 
141
  int i, j;
 
142
 
 
143
  check(state->getFillColorSpace(), state->getFillColor(),
 
144
        state->getFillOpacity(), state->getBlendMode());
 
145
  gdi = gFalse;
 
146
  if ((level == psLevel1 || level == psLevel1Sep) &&
 
147
      state->getFillColorSpace()->getMode() == csPattern) {
 
148
    level1PSBug = gTrue;
 
149
  }
 
150
 
 
151
  if (inlineImg) {
 
152
    str->reset();
 
153
    j = height * ((width + 7) / 8);
 
154
    for (i = 0; i < j; ++i)
 
155
      str->getChar();
 
156
    str->close();
 
157
  }
 
158
}
 
159
 
 
160
void PreScanOutputDev::drawImage(GfxState *state, Object * /*ref*/, Stream *str,
 
161
                                 int width, int height,
 
162
                                 GfxImageColorMap *colorMap,
 
163
                                 GBool /*interpolate*/, int * /*maskColors*/, GBool inlineImg) {
 
164
  GfxColorSpace *colorSpace;
 
165
  int i, j;
 
166
 
 
167
  colorSpace = colorMap->getColorSpace();
 
168
  if (colorSpace->getMode() == csIndexed) {
 
169
    colorSpace = ((GfxIndexedColorSpace *)colorSpace)->getBase();
 
170
  }
 
171
  if (colorSpace->getMode() != csDeviceGray &&
 
172
      colorSpace->getMode() != csCalGray) {
 
173
    gray = gFalse;
 
174
  }
 
175
  mono = gFalse;
 
176
  if (state->getBlendMode() != gfxBlendNormal) {
 
177
    transparency = gTrue;
 
178
  }
 
179
  gdi = gFalse;
 
180
 
 
181
  if (inlineImg) {
 
182
    str->reset();
 
183
    j = height * ((width * colorMap->getNumPixelComps() *
 
184
                   colorMap->getBits() + 7) / 8);
 
185
    for (i = 0; i < j; ++i)
 
186
      str->getChar();
 
187
    str->close();
 
188
  }
 
189
}
 
190
 
 
191
void PreScanOutputDev::drawMaskedImage(GfxState *state, Object * /*ref*/,
 
192
                                       Stream * /*str*/,
 
193
                                       int /*width*/, int /*height*/,
 
194
                                       GfxImageColorMap *colorMap,
 
195
                                       GBool /*interpolate*/,
 
196
                                       Stream * /*maskStr*/,
 
197
                                       int /*maskWidth*/, int /*maskHeight*/,
 
198
                                       GBool /*maskInvert*/, GBool /*maskInterpolate*/) {
 
199
  GfxColorSpace *colorSpace;
 
200
 
 
201
  colorSpace = colorMap->getColorSpace();
 
202
  if (colorSpace->getMode() == csIndexed) {
 
203
    colorSpace = ((GfxIndexedColorSpace *)colorSpace)->getBase();
 
204
  }
 
205
  if (colorSpace->getMode() != csDeviceGray &&
 
206
      colorSpace->getMode() != csCalGray) {
 
207
    gray = gFalse;
 
208
  }
 
209
  mono = gFalse;
 
210
  if (state->getBlendMode() != gfxBlendNormal) {
 
211
    transparency = gTrue;
 
212
  }
 
213
  gdi = gFalse;
 
214
}
 
215
 
 
216
void PreScanOutputDev::drawSoftMaskedImage(GfxState * /*state*/, Object * /*ref*/,
 
217
                                           Stream * /*str*/,
 
218
                                           int /*width*/, int /*height*/,
 
219
                                           GfxImageColorMap *colorMap,
 
220
                                           GBool /*interpolate*/,
 
221
                                           Stream * /*maskStr*/,
 
222
                                           int /*maskWidth*/, int /*maskHeight*/,
 
223
                                           GfxImageColorMap * /*maskColorMap*/,
 
224
                                           GBool /*maskInterpolate*/) {
 
225
  GfxColorSpace *colorSpace;
 
226
 
 
227
  colorSpace = colorMap->getColorSpace();
 
228
  if (colorSpace->getMode() == csIndexed) {
 
229
    colorSpace = ((GfxIndexedColorSpace *)colorSpace)->getBase();
 
230
  }
 
231
  if (colorSpace->getMode() != csDeviceGray &&
 
232
      colorSpace->getMode() != csCalGray) {
 
233
    gray = gFalse;
 
234
  }
 
235
  mono = gFalse;
 
236
  transparency = gTrue;
 
237
  gdi = gFalse;
 
238
}
 
239
 
 
240
void PreScanOutputDev::beginTransparencyGroup(
 
241
                           GfxState * /*state*/, double * /*bbox*/,
 
242
                           GfxColorSpace * /*blendingColorSpace*/,
 
243
                           GBool /*isolated*/, GBool /*knockout*/,
 
244
                           GBool /*forSoftMask*/) {
 
245
  gdi = gFalse;
 
246
}
 
247
 
 
248
void PreScanOutputDev::paintTransparencyGroup(GfxState *state, double * /*bbox*/)
 
249
{
 
250
  check(state->getFillColorSpace(), state->getFillColor(),
 
251
        state->getFillOpacity(), state->getBlendMode());
 
252
}
 
253
 
 
254
void PreScanOutputDev::setSoftMask(GfxState * /*state*/, double * /*bbox*/, GBool /*alpha*/,
 
255
                           Function * /*transferFunc*/, GfxColor * /*backdropColor*/)
 
256
{
 
257
  transparency = gTrue;
 
258
}
 
259
 
 
260
void PreScanOutputDev::check(GfxColorSpace *colorSpace, GfxColor *color,
 
261
                             double opacity, GfxBlendMode blendMode) {
 
262
  GfxRGB rgb;
 
263
 
 
264
  if (colorSpace->getMode() == csPattern) {
 
265
    mono = gFalse;
 
266
    gray = gFalse;
 
267
    gdi = gFalse;
 
268
  } else {
 
269
    colorSpace->getRGB(color, &rgb);
 
270
    if (rgb.r != rgb.g || rgb.g != rgb.b || rgb.b != rgb.r) {
 
271
      mono = gFalse;
 
272
      gray = gFalse;
 
273
    } else if (!((rgb.r == 0 && rgb.g == 0 && rgb.b == 0) ||
 
274
                 (rgb.r == gfxColorComp1 &&
 
275
                  rgb.g == gfxColorComp1 &&
 
276
                  rgb.b == gfxColorComp1))) {
 
277
      mono = gFalse;
 
278
    }
 
279
  }
 
280
  if (opacity != 1 || blendMode != gfxBlendNormal) {
 
281
    transparency = gTrue;
 
282
  }
 
283
}
 
284
 
 
285
void PreScanOutputDev::clearStats() {
 
286
  mono = gTrue;
 
287
  gray = gTrue;
 
288
  transparency = gFalse;
 
289
  gdi = gTrue;
 
290
  level1PSBug = gFalse;
 
291
}