X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fxpdf%2FGFXOutputDev.cc;h=45a0a923f8b074eef30a8baac72f0f5d4746835d;hb=2b39e1bd64223659303afb113da273eb8499db6e;hp=7eed5902638d10bea8dc7e5b8e8c5655b5adc7df;hpb=1279e7201aaf80eca58ad982ec11de68c85631af;p=swftools.git diff --git a/lib/xpdf/GFXOutputDev.cc b/lib/xpdf/GFXOutputDev.cc index 7eed590..45a0a92 100644 --- a/lib/xpdf/GFXOutputDev.cc +++ b/lib/xpdf/GFXOutputDev.cc @@ -170,6 +170,8 @@ GFXOutputDev::GFXOutputDev(parameter_t*p) this->type3Warning = 0; this->user_movex = 0; this->user_movey = 0; + this->clipmovex = 0; + this->clipmovey = 0; this->user_clipx1 = 0; this->user_clipy1 = 0; this->user_clipx2 = 0; @@ -185,14 +187,14 @@ GFXOutputDev::GFXOutputDev(parameter_t*p) this->forceType0Fonts=1; this->config_use_fontconfig=1; + this->parameters = p; + /* configure device */ while(p) { if(!strcmp(p->name,"forceType0Fonts")) { this->forceType0Fonts = atoi(p->value); } else if(!strcmp(p->name,"fontconfig")) { this->config_use_fontconfig = atoi(p->value); - } else { - msg(" Ignored Paramter %s=%s", p->name, p->value); } p = p->next; } @@ -200,7 +202,16 @@ GFXOutputDev::GFXOutputDev(parameter_t*p) void GFXOutputDev::setDevice(gfxdevice_t*dev) { + parameter_t*p = this->parameters; + + /* TODO: get rid of this */ this->device = dev; + if(this->device) { + while(p) { + this->device->setparameter(this->device, p->name, p->value); + p = p->next; + } + } } void GFXOutputDev::setMove(int x,int y) @@ -244,8 +255,9 @@ static char*getFontName(GfxFont*font) Ref*r=font->getID(); sprintf(buf, "UFONT%d", r->num); fontid = strdup(buf); + } else { + fontid = strdup(fname); } - fontid = strdup(fname); char*fontname= 0; char* plus = strchr(fontid, '+'); @@ -546,7 +558,7 @@ gfxline_t* gfxPath_to_gfxline(GfxState*state, GfxPath*path, int closed, int user void GFXOutputDev::stroke(GfxState *state) { GfxPath * path = state->getPath(); - gfxline_t*line= gfxPath_to_gfxline(state, path, 0, user_movex, user_movey); + gfxline_t*line= gfxPath_to_gfxline(state, path, 0, user_movex + clipmovex, user_movey + clipmovey); strokeGfxline(state, line); gfxline_free(line); } @@ -647,17 +659,18 @@ gfxcolor_t getFillColor(GfxState * state) void GFXOutputDev::fillGfxLine(GfxState *state, gfxline_t*line) { gfxcolor_t col = getFillColor(state); - + if(getLogLevel() >= LOGLEVEL_TRACE) { msg(" fill %02x%02x%02x%02x\n", col.r, col.g, col.b, col.a); dump_outline(line); } + device->fill(device, line, &col); } void GFXOutputDev::fill(GfxState *state) { GfxPath * path = state->getPath(); - gfxline_t*line= gfxPath_to_gfxline(state, path, 1, user_movex, user_movey); + gfxline_t*line= gfxPath_to_gfxline(state, path, 1, user_movex + clipmovex, user_movey + clipmovey); fillGfxLine(state, line); gfxline_free(line); } @@ -666,7 +679,7 @@ void GFXOutputDev::eoFill(GfxState *state) GfxPath * path = state->getPath(); gfxcolor_t col = getFillColor(state); - gfxline_t*line= gfxPath_to_gfxline(state, path, 1, user_movex, user_movey); + gfxline_t*line= gfxPath_to_gfxline(state, path, 1, user_movex + clipmovex, user_movey + clipmovey); if(getLogLevel() >= LOGLEVEL_TRACE) { msg(" eofill\n"); @@ -680,7 +693,7 @@ void GFXOutputDev::eoFill(GfxState *state) void GFXOutputDev::clip(GfxState *state) { GfxPath * path = state->getPath(); - gfxline_t*line = gfxPath_to_gfxline(state, path, 1, user_movex, user_movey); + gfxline_t*line = gfxPath_to_gfxline(state, path, 1, user_movex + clipmovex, user_movey + clipmovey); clipToGfxLine(state, line); gfxline_free(line); } @@ -698,7 +711,7 @@ void GFXOutputDev::clipToGfxLine(GfxState *state, gfxline_t*line) void GFXOutputDev::eoClip(GfxState *state) { GfxPath * path = state->getPath(); - gfxline_t*line = gfxPath_to_gfxline(state, path, 1, user_movex, user_movey); + gfxline_t*line = gfxPath_to_gfxline(state, path, 1, user_movex + clipmovex, user_movey + clipmovey); if(getLogLevel() >= LOGLEVEL_TRACE) { msg(" eoclip\n"); @@ -743,7 +756,6 @@ GFXOutputDev::~GFXOutputDev() fontlist_t*next = l->next; l->next = 0; gfxfont_free(l->font); - free(l->id);l->id=0; free(l->filename);l->filename=0; free(l); l = next; @@ -952,7 +964,7 @@ void GFXOutputDev::drawChar(GfxState *state, double x, double y, if the ligature doesn't exist, we need to draw the characters one-by-one. */ int t; - msg(" ligature %d missing in font %s\n", c, current_font_id); + msg(" ligature %d missing in font %s\n", c, current_gfxfont->id); for(t=0;t Didn't find character '%s' (c=%d,u=%d) in current charset (%s, %d characters)", - FIXNULL(name),c, u, FIXNULL((char*)current_font_id), current_gfxfont->num_glyphs); + FIXNULL(name),c, u, FIXNULL((char*)current_gfxfont->id), current_gfxfont->num_glyphs); return; } gfxmatrix_t m = this->current_font_matrix; state->transform(x, y, &m.tx, &m.ty); - m.tx += user_movex; - m.ty += user_movey; + m.tx += user_movex + clipmovex; + m.ty += user_movey + clipmovey; if(render == RENDER_FILL) { - device->drawchar(device, current_font_id, charid, &col, &m); + device->drawchar(device, current_gfxfont, charid, &col, &m); } else { msg(" Drawing glyph %d as shape", charid); if(!textmodeinfo) { @@ -1075,6 +1087,11 @@ void GFXOutputDev::endType3Char(GfxState *state) void GFXOutputDev::startFrame(int width, int height) { + if(outer_clip_box) { + device->endclip(device); + outer_clip_box = 0; + } + device->startpage(device, width, height); } @@ -1104,23 +1121,21 @@ void GFXOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, doubl if(x2clipmovex = -(int)x1; + this->clipmovey = -(int)y1; + /* apply user clip box */ if(user_clipx1|user_clipy1|user_clipx2|user_clipy2) { /*if(user_clipx1 > x1)*/ x1 = user_clipx1; /*if(user_clipx2 < x2)*/ x2 = user_clipx2; /*if(user_clipy1 > y1)*/ y1 = user_clipy1; /*if(user_clipy2 < y2)*/ y2 = user_clipy2; + msg(" Using user clip box %f/%f/%f/%f",x1,y1,x2,y2); } //msg(" Bounding box is (%f,%f)-(%f,%f) [shifted by %d/%d]", x1,y1,x2,y2, user_movex, user_movey); - if(outer_clip_box) { - device->endclip(device); - outer_clip_box = 0; - } - - msg(" processing PDF page %d (%dx%d:%d:%d) (move:%d:%d)", pageNum, (int)x2-(int)x1,(int)y2-(int)y1, (int)x1, (int)y1, user_movex, user_movey); + msg(" processing PDF page %d (%dx%d:%d:%d) (move:%d:%d)", pageNum, (int)x2-(int)x1,(int)y2-(int)y1, (int)x1, (int)y1, user_movex + clipmovex, user_movey + clipmovey); if(rot!=0) msg(" page is rotated %d degrees\n", rot); @@ -1144,28 +1159,28 @@ void GFXOutputDev::drawLink(Link *link, Catalog *catalog) link->getRect(&x1, &y1, &x2, &y2); cvtUserToDev(x1, y1, &x, &y); points[0].type = gfx_moveTo; - points[0].x = points[4].x = x + user_movex; - points[0].y = points[4].y = y + user_movey; + points[0].x = points[4].x = x + user_movex + clipmovex; + points[0].y = points[4].y = y + user_movey + clipmovey; points[0].next = &points[1]; cvtUserToDev(x2, y1, &x, &y); points[1].type = gfx_lineTo; - points[1].x = x + user_movex; - points[1].y = y + user_movey; + points[1].x = x + user_movex + clipmovex; + points[1].y = y + user_movey + clipmovey; points[1].next = &points[2]; cvtUserToDev(x2, y2, &x, &y); points[2].type = gfx_lineTo; - points[2].x = x + user_movex; - points[2].y = y + user_movey; + points[2].x = x + user_movex + clipmovex; + points[2].y = y + user_movey + clipmovey; points[2].next = &points[3]; cvtUserToDev(x1, y2, &x, &y); points[3].type = gfx_lineTo; - points[3].x = x + user_movex; - points[3].y = y + user_movey; + points[3].x = x + user_movex + clipmovex; + points[3].y = y + user_movey + clipmovey; points[3].next = &points[4]; cvtUserToDev(x1, y1, &x, &y); points[4].type = gfx_lineTo; - points[4].x = x + user_movex; - points[4].y = y + user_movey; + points[4].x = x + user_movex + clipmovex; + points[4].y = y + user_movey + clipmovey; points[4].next = 0; msg(" drawlink %.2f/%.2f %.2f/%.2f %.2f/%.2f %.2f/%.2f\n", @@ -1204,9 +1219,17 @@ void GFXOutputDev::drawLink(Link *link, Catalog *catalog) case actionGoToR: { type = "GoToR"; LinkGoToR*l = (LinkGoToR*)action; - GString*g = l->getNamedDest(); - if(g) + GString*g = l->getFileName(); + if(g) s = strdup(g->getCString()); + if(!s) { + /* if the GoToR link has no filename, then + try to find a refernce in the *local* + file */ + GString*g = l->getNamedDest(); + if(g) + s = strdup(g->getCString()); + } } break; case actionNamed: { @@ -1401,7 +1424,7 @@ void GFXOutputDev::updateStrokeColor(GfxState *state) void FoFiWrite(void *stream, char *data, int len) { - fwrite(data, len, 1, (FILE*)stream); + int ret = fwrite(data, len, 1, (FILE*)stream); } char*GFXOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font) @@ -1683,14 +1706,16 @@ int GFXOutputDev::setGfxFont(char*id, char*name, char*filename, double maxSize) gfxfont_t*font = 0; fontlist_t*last=0,*l = this->fontlist; + if(!id) + msg(" Internal Error: FontID is null"); + /* TODO: should this be part of the state? */ while(l) { last = l; - if(!strcmp(l->id, id)) { - current_font_id = l->id; + if(!strcmp(l->font->id, id)) { current_gfxfont = l->font; font = l->font; - device->addfont(device, id, current_gfxfont); + device->addfont(device, current_gfxfont); return 1; } l = l->next; @@ -1704,22 +1729,24 @@ int GFXOutputDev::setGfxFont(char*id, char*name, char*filename, double maxSize) double quality = (1024 * 0.05) / maxSize; msg(" Loading %s...", filename); - font = gfxfont_load(filename, quality); - msg(" Font %s loaded successfully", filename); + font = gfxfont_load(id, filename, quality); + if(!font) { + msg(" Couldn't load Font %s (%s)", filename, id); + return 0; + } + msg(" Font %s (%s) loaded successfully", filename, id); l = new fontlist_t; l->font = font; l->filename = strdup(filename); - l->id = strdup(id); l->next = 0; - current_font_id = l->id; current_gfxfont = l->font; if(last) { last->next = l; } else { this->fontlist = l; } - device->addfont(device, id, current_gfxfont); + device->addfont(device, current_gfxfont); return 1; } @@ -2033,10 +2060,10 @@ void GFXOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str, return; } - state->transform(0, 1, &x1, &y1); x1 += user_movex; y1 += user_movey; - state->transform(0, 0, &x2, &y2); x2 += user_movex; y2 += user_movey; - state->transform(1, 0, &x3, &y3); x3 += user_movex; y3 += user_movey; - state->transform(1, 1, &x4, &y4); x4 += user_movex; y4 += user_movey; + state->transform(0, 1, &x1, &y1); x1 += user_movex + clipmovex; y1 += user_movey + clipmovey; + state->transform(0, 0, &x2, &y2); x2 += user_movex + clipmovex; y2 += user_movey + clipmovey; + state->transform(1, 0, &x3, &y3); x3 += user_movex + clipmovex; y3 += user_movey + clipmovey; + state->transform(1, 1, &x4, &y4); x4 += user_movex + clipmovex; y4 += user_movey + clipmovey; if(!pbminfo && !(str->getKind()==strDCT)) { @@ -2209,8 +2236,6 @@ void GFXOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, GBool invert, GBool inlineImg) { - if(states[statepos].textRender & 4) //clipped - return; msg(" drawImageMask %dx%d, invert=%d inline=%d", width, height, invert, inlineImg); drawGeneralImage(state,ref,str,width,height,0,invert,inlineImg,1, 0, 0,0,0,0, 0); } @@ -2219,9 +2244,6 @@ void GFXOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, int *maskColors, GBool inlineImg) { - if(states[statepos].textRender & 4) //clipped - return; - msg(" drawImage %dx%d, %s, %s, inline=%d", width, height, colorMap?"colorMap":"no colorMap", maskColors?"maskColors":"no maskColors", @@ -2238,9 +2260,6 @@ void GFXOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str, Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert) { - if(states[statepos].textRender & 4) //clipped - return; - msg(" drawMaskedImage %dx%d, %s, %dx%d mask", width, height, colorMap?"colorMap":"no colorMap", maskWidth, maskHeight); @@ -2257,9 +2276,6 @@ void GFXOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str int maskWidth, int maskHeight, GfxImageColorMap *maskColorMap) { - if(states[statepos].textRender & 4) //clipped - return; - msg(" drawSoftMaskedImage %dx%d, %s, %dx%d mask", width, height, colorMap?"colorMap":"no colorMap", maskWidth, maskHeight);