6 < int nDigits, n1, n2, n3;
8 > int maxCode, n1, n2, n3;
10 < nDigits = nBits / 4;
12 > maxCode = (nBits == 8) ? 0xff : (nBits == 16) ? 0xffff : 0xffffffff;
14 < if (!(n1 == 2 + nDigits && tok1[0] == '<' && tok1[n1 - 1] == '>' &&
16 > if (!(tok1[0] == '<' && tok1[n1 - 1] == '>' &&
18 < error(-1, "Illegal entry in bfchar block in ToUnicode CMap");
20 > error(-1, "Illegal entry in bfchar block in ToUnicode CMap.");
22 > if (code1 > maxCode) {
23 > error(-1, "Invalid entry in bfchar block in ToUnicode CMap");
26 < if (!(n1 == 2 + nDigits && tok1[0] == '<' && tok1[n1 - 1] == '>' &&
27 < n2 == 2 + nDigits && tok2[0] == '<' && tok2[n2 - 1] == '>')) {
29 > if (!(tok1[0] == '<' && tok1[n1 - 1] == '>' &&
30 > tok2[0] == '<' && tok2[n2 - 1] == '>')) {
32 > if (code1 > maxCode || code2 > maxCode) {
33 > error(-1, "Invalid entry in bfrange block in ToUnicode CMap");
39 > startPage(0, NULL, 0,0,0,0);
41 > if(!n || n>16) n=16;
43 < out->startPage(pageNum, state);
46 > out->startPage(pageNum, state, cropBox->x1,cropBox->y1,cropBox->x2,cropBox->y2);
48 > out->startPage(pageNum, state, 0,0,0,0);
55 < if (n == 1 && *p == ' ') {
56 < dx += state->getWordSpace();
58 > if (n == 1 && (*p == ' ' || *p == 0)) {
59 > double w=state->getWordSpace();
61 > w=state->getFontSize()/3; // workaround for zero word space
64 < colorSpace = GfxColorSpace::parse(&obj1);
66 > colorSpace = GfxColorSpace::parse(&obj1, csMode);
68 > } else if (csMode == streamCSDeviceRGBX) {
69 > colorSpace = new GfxDeviceRGBXColorSpace();
71 > GfxState*old_state = state;
73 > // restore graphics state
74 > while(state != old_state)
77 > CharCodeToUnicode* Gfx8BitFont::getCTU() {
82 > CharCodeToUnicode* GfxCIDFont::getCTU() {
87 > virtual CharCodeToUnicode* getCTU() = 0;
89 > virtual CharCodeToUnicode* getCTU();
91 < char *getCharName(int code) { return enc[code]; }
93 > char *getCharName(int code) { return code>=256?0:enc[code]; }
95 > virtual CharCodeToUnicode* getCTU();
99 < GfxColorSpace *GfxColorSpace::parse(Object *csObj) {
101 > GfxColorSpace *GfxColorSpace::parse(Object *csObj, StreamColorSpaceMode csMode) {
103 < cs = new GfxDeviceRGBColorSpace();
105 > if(csMode == streamCSDeviceRGBX)
106 > cs = new GfxDeviceRGBXColorSpace();
108 > cs = new GfxDeviceRGBColorSpace();
110 < cs = new GfxDeviceRGBColorSpace();
112 > if(csMode == streamCSDeviceRGBX)
113 > cs = new GfxDeviceRGBColorSpace();
115 > cs = new GfxDeviceRGBColorSpace();
117 > // GfxDeviceRGBXColorSpace
118 > //------------------------------------------------------------------------
120 > GfxDeviceRGBXColorSpace::GfxDeviceRGBXColorSpace() {
123 > GfxColorSpace *GfxDeviceRGBXColorSpace::copy() {
124 > return new GfxDeviceRGBXColorSpace();
127 > //------------------------------------------------------------------------
129 > /*void GfxDeviceCMYKColorSpace::getRGB(GfxColor *color, GfxRGB *rgb) {
130 > unsigned char r,g,b;
131 > float c = color->c[0];
132 > float m = color->c[1];
133 > float y = color->c[2];
134 > float k = color->c[3];
135 > convert_cmyk2rgb(c,m,y,k, &r,&g,&b);
142 > int maxPixelForAlloc;
144 > maxPixelForAlloc = (1 << (bits>8?bits:8));
146 < lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
148 > lookup[k] = (GfxColorComp *)gmallocn(maxPixelForAlloc + 1,
150 < lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
152 > lookup[k] = (GfxColorComp *)gmallocn(maxPixelForAlloc + 1,
154 < lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
156 > lookup[k] = (GfxColorComp *)gmallocn(maxPixelForAlloc + 1,
163 < static GfxColorSpace *parse(Object *csObj);
165 > static GfxColorSpace *parse(Object *csObj, StreamColorSpaceMode csMode = streamCSNone);
167 > // GfxDeviceRGBXColorSpace
168 > //------------------------------------------------------------------------
170 > class GfxDeviceRGBXColorSpace: public GfxDeviceRGBColorSpace {
173 > GfxDeviceRGBXColorSpace();
174 > virtual GfxColorSpace *copy();
175 > virtual int getNComps() { return 4; }
179 > //------------------------------------------------------------------------
183 > char* cfgFileName = fileName->getCString();
184 > char* pos1 = strrchr(cfgFileName, '/');
185 > char* pos2 = strrchr(cfgFileName, '\\');
186 > char* p = pos1>pos2?pos1:pos2;
187 > int pos = p ? p-cfgFileName : -1;
188 > GString*path = new GString(new GString(cfgFileName), 0, (pos < 0 ? strlen(cfgFileName): pos));
192 > path->append('\\');
195 > path->append('\\');
201 > this->path = new GString();
205 > static char is_absolute(char*filename)
207 > int l = strlen(filename);
208 > if(filename[0] == '/' || filename[0] == '\\')
210 > if(l>2 && filename[1]==':' && (filename[2]=='\\' || filename[2]=='/'))
215 > static GString* qualify_filename(GString*path, GString*filename)
217 > GString*fullpath = 0;
218 > char*prefix = "/usr/local/share/xpdf/";
220 > if (!is_absolute(filename->getCString())) {
221 > /* relative path */
222 > fullpath = path->copy();
223 > fullpath->append(filename);
224 > } else if (!strncmp(filename->getCString(), prefix, strlen(prefix))) {
225 > /* xpdf default path */
226 > char*s = strchr(filename->getCString()+strlen(prefix), '/');
228 > fullpath = path->copy();
229 > fullpath->append(s+1);
231 > fullpath = filename->copy();
234 > /* absolute path */
235 > fullpath = filename->copy();
237 > //printf("%s -%s-> %s\n", filename->getCString(), path->getCString(), fullpath->getCString());
242 < name = (GString *)tokens->get(1);
244 > name = qualify_filename(this->path, (GString *)tokens->get(1));
246 < error(-1, "Couldn't open 'nameToUnicode' file '%s'",
247 < name->getCString());
249 > error(-1, "Couldn't open 'nameToUnicode' file '%s' using path '%s'",
250 > name->getCString(), path->getCString());
254 < cidToUnicodes->add(collection->copy(), name->copy());
257 > cidToUnicodes->add(collection->copy(), qualify_filename(this->path, name));
259 < unicodeToUnicodes->add(font->copy(), file->copy());
262 > unicodeToUnicodes->add(font->copy(), qualify_filename(this->path, file));
264 < unicodeMaps->add(encodingName->copy(), name->copy());
267 > unicodeMaps->add(encodingName->copy(), qualify_filename(this->path, name));
269 < list->append(dir->copy());
272 > list->append(qualify_filename(this->path, dir));
277 < toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
280 > dir = (GString *)tokens->get(1);
282 > toUnicodeDirs->append(qualify_filename(this->path, dir));
286 < param->t1.fileName = ((GString *)tokens->get(2))->copy();
288 > file = (GString *)tokens->get(2);
289 > param->t1.fileName = qualify_filename(this->path, file);
291 < param->tt.fileName = ((GString *)tokens->get(2))->copy();
293 > file = (GString *)tokens->get(2);
294 > param->tt.fileName = qualify_filename(this->path, file);
298 > virtual ~GlobalParams();
300 < DisplayFontParam *getDisplayFont(GString *fontName);
301 < DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
303 > virtual DisplayFontParam *getDisplayFont(GString *fontName);
304 > virtual DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
306 < void parseFile(GString *fileName, FILE *f);
308 > public: void parseFile(GString *fileName, FILE *f); private:
310 > //----- config file base path
316 < i = (numInputSyms + numNewSyms) >> 1;
323 > while (i < numInputSyms + numNewSyms) {
327 > if (huff && symCodeLen == 0) {
330 > if (huff && symCodeLen == 0) {
334 > Guint num_components = 0;
336 < readUWord(&dummy) &&
338 > readUWord(&num_components) &&
340 > if(*csMode == streamCSDeviceRGB && num_components == 4) {
341 > *csMode = streamCSDeviceRGBX;
344 > static int illegalChars = 0;
347 > error(0, "Illegal characters in hex string (%d)", illegalChars);
350 < error(getPos(), "Illegal digit in hex char in name");
353 > //error(getPos(), "Illegal digit in hex char in name");
356 < error(getPos(), "Illegal character <%02x> in hex string", c);
360 > //error(getPos(), "Illegal character <%02x> in hex string", c);
363 < error(getPos(), "Illegal character '>'");
366 > //error(getPos(), "Illegal character '>'");
368 < error(getPos(), "Illegal character '%c'", c);
370 > //error(getPos(), "Illegal character '%c'", c);
377 < error(-1, "Illegal annotation destination");
379 > error(-1, "Illegal annotation destination %d", destObj->getType());
383 < error(-1, "Illegal annotation destination");
385 > error(-1, "Illegal annotation destination %d", destObj->getType());
387 > #include "Object.h"
389 < virtual void startPage(int pageNum, GfxState *state) {}
391 > virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {}
396 > this->ascender = face->ascender;
397 > this->descender = face->descender;
400 > int SplashFTFont::getNumChars()
402 > SplashFTFontFile* ff = (SplashFTFontFile *)fontFile;
403 > return ff->face->num_glyphs;
407 > this->last_advance = -1;
410 < if (FT_Load_Glyph(ff->face, gid, FT_LOAD_NO_BITMAP)) {
413 > if ((error=FT_Load_Glyph(ff->face, gid, FT_LOAD_NO_BITMAP|FT_LOAD_NO_HINTING))) {
414 > fprintf(stderr, "Truetype wasn't able to load glyph %d, error %d\n", gid, error);
416 > this->last_advance = glyph->advance.x/65536.0;
419 < FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline,
421 > error = FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline,
424 > fprintf(stderr, "Truetype wasn't able to read glyph %d, error %d\n", gid, error);
427 > // return the number of characters in this font
428 > virtual int getNumChars();
440 > // return the number of characters in this font
441 > virtual int getNumChars() = 0;
446 > double last_advance; //set after getGlyphPath()
449 < # include <unistd.h>
452 > #include <unistd.h>
454 > #include <unistd.h>
456 < void SplashOutputDev::startPage(int pageNum, GfxState *state) {
458 > void SplashOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
460 < memset(softMask->getDataPtr(), 0,
461 < softMask->getRowSize() * softMask->getHeight());
463 > memset(softMask->getDataPtr(), 0x00, softMask->getRowSize()*softMask->getHeight());
465 > if (tx<softMask->getWidth() && ty<softMask->getHeight())
467 < virtual void startPage(int pageNum, GfxState *state);
469 > virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
471 > void doUpdateFont(GfxState *state);
473 > SplashPath *convertPath(GfxState *state, GfxPath *path);
475 < SplashPath *convertPath(GfxState *state, GfxPath *path);
476 < void doUpdateFont(GfxState *state);
481 < for (; xx + 7 <= xx0; xx += 8) {
483 > for (; xx + 7 < xx0; xx += 8) {
489 < for (; xx + 7 <= xx0; xx += 8) {
491 > for (; xx + 7 < xx0; xx += 8) {
498 > extern "C" int unlink(char *filename);
502 > streamCSDeviceCMYK,
505 < void TextOutputDev::startPage(int pageNum, GfxState *state) {
507 > void TextOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
509 > friend class XMLOutputDev;
511 < virtual void startPage(int pageNum, GfxState *state);
513 > virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
515 > static char* getTempDir()
518 > char*dir = getenv("TMP");
519 > if(!dir) dir = getenv("TEMP");
520 > if(!dir) dir = getenv("tmp");
521 > if(!dir) dir = getenv("temp");
522 > if(!dir) dir = "C:\\";
524 > char* dir = "/tmp/";
529 > char* mktmpname(char*ptr) {
530 > static char tmpbuf[128];
531 > char*dir = getTempDir();
532 > int l = strlen(dir);
536 > if(l && dir[l-1]!='/' && dir[l-1]!='\\') {
544 > // used to be mktemp. This does remove the warnings, but
545 > // It's not exactly an improvement.
546 > #ifdef HAVE_LRAND48
547 > sprintf(ptr, "%s%s%08x%08x",dir,sep,(unsigned int)lrand48(),(unsigned int)lrand48());
550 > sprintf(ptr, "%s%s%08x%08x",dir,sep,rand(),rand());
552 > static int count = 1;
553 > sprintf(ptr, "%s%s%08x%04x%04x",dir,sep,time(0),(unsigned int)tmpbuf^((unsigned int)tmpbuf)>>16,count);
562 < sprintf(buf, "%d", t + i);
564 > sprintf(buf, "%08x-%08x", t + i, GetCurrentThreadId());
571 > fprintf(stderr, "Couldn't create temporary file\n");
573 < if (!(s = tmpnam(NULL))) {
575 > if (!(s = mktmpname(NULL))) {
577 < if (!(s = tmpnam(NULL))) {
579 > if (!(s = mktmpname(NULL))) {
581 < if (!(s = tmpnam(NULL))) {
583 > if (!(s = mktmpname(NULL))) {
585 > /* create a temporary filename */
586 > char* mktmpname(char*ptr);