X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpdf%2FGFXOutputDev.cc;h=d3a9e4e0786d1360abbb7b74a12c5809cad1f207;hb=35f52bc6c36d116f9916b60e3dde4cce3501a41c;hp=f6a361d079302e2fa04c59783d05a1ce2da5076b;hpb=41a32828cd45f872e07ed621a3929d24de1b161a;p=swftools.git diff --git a/lib/pdf/GFXOutputDev.cc b/lib/pdf/GFXOutputDev.cc index f6a361d..d3a9e4e 100644 --- a/lib/pdf/GFXOutputDev.cc +++ b/lib/pdf/GFXOutputDev.cc @@ -69,6 +69,10 @@ #include "../devices/ops.h" #include "../devices/arts.h" #include "../devices/render.h" + +#include "../art/libart.h" +#include "../devices/artsutils.c" + #include "../png.h" #include "fonts.h" @@ -76,7 +80,7 @@ typedef struct _fontfile { - char*filename; + const char*filename; int used; } fontfile_t; @@ -89,8 +93,8 @@ static int fontnum = 0; static char* lastfontdir = 0; struct fontentry { - char*pdffont; - char*filename; + const char*pdffont; + const char*filename; char*afm; int afmlen; char*pfb; @@ -115,7 +119,7 @@ struct fontentry { static int verbose = 0; static int dbgindent = 0; -static void dbg(char*format, ...) +static void dbg(const char*format, ...) { char buf[1024]; int l; @@ -148,7 +152,7 @@ typedef struct _feature } feature_t; feature_t*featurewarnings = 0; -void GFXOutputDev::showfeature(char*feature,char fully, char warn) +void GFXOutputDev::showfeature(const char*feature,char fully, char warn) { feature_t*f = featurewarnings; while(f) { @@ -170,11 +174,11 @@ void GFXOutputDev::showfeature(char*feature,char fully, char warn) msg(" File contains %s",feature); } } -void GFXOutputDev::warnfeature(char*feature,char fully) +void GFXOutputDev::warnfeature(const char*feature,char fully) { showfeature(feature,fully,1); } -void GFXOutputDev::infofeature(char*feature) +void GFXOutputDev::infofeature(const char*feature) { showfeature(feature,0,0); } @@ -191,7 +195,7 @@ GFXOutputState::GFXOutputState() { GBool GFXOutputDev::interpretType3Chars() { - return gTrue; + return this->do_interpretType3Chars; } typedef struct _drawnchar @@ -269,6 +273,7 @@ GFXOutputDev::GFXOutputDev(parameter_t*p) this->pagepos = 0; this->config_use_fontconfig=1; this->config_break_on_warning=0; + this->do_interpretType3Chars = gTrue; this->parameters = p; @@ -276,14 +281,23 @@ GFXOutputDev::GFXOutputDev(parameter_t*p) /* configure device */ while(p) { - if(!strcmp(p->name,"fontconfig")) { - this->config_use_fontconfig = atoi(p->value); - } else if(!strcmp(p->name,"breakonwarning")) { - this->config_break_on_warning = atoi(p->value); - } + setParameter(p->name, p->value); p = p->next; } }; + +void GFXOutputDev::setParameter(char*key, char*value) +{ + if(!strcmp(key,"rawtext")) { + this->do_interpretType3Chars = atoi(value)^1; + } else if(!strcmp(key,"breakonwarning")) { + this->config_break_on_warning = atoi(value); + } else if(!strcmp(key,"fontconfig")) { + this->config_use_fontconfig = atoi(value); + } else { + msg(" Ignored parameter: %s=%s", key, value); + } +} void GFXOutputDev::setDevice(gfxdevice_t*dev) { @@ -462,7 +476,7 @@ static char* gfxstate2str(GfxState *state) return mybuf; } -static void dumpFontInfo(char*loglevel, GfxFont*font); +static void dumpFontInfo(const char*loglevel, GfxFont*font); static int lastdumps[1024]; static int lastdumppos = 0; /* nr = 0 unknown @@ -485,11 +499,11 @@ static void showFontError(GfxFont*font, int nr) else if(nr == 1) msg(" The following font caused problems (substituting):"); else if(nr == 2) - msg(" The following Type 3 Font will be rendered as bitmap:"); + msg(" The following Type 3 Font will be rendered as graphics:"); dumpFontInfo("", font); } -static void dumpFontInfo(char*loglevel, GfxFont*font) +static void dumpFontInfo(const char*loglevel, GfxFont*font) { char* id = getFontID(font); char* name = getFontName(font); @@ -651,7 +665,9 @@ GBool GFXOutputDev::useShadedFills() return gFalse; } -void GFXOutputDev::strokeGfxline(GfxState *state, gfxline_t*line) +#define STROKE_FILL 1 +#define STROKE_CLIP 2 +void GFXOutputDev::strokeGfxline(GfxState *state, gfxline_t*line, int flags) { int lineCap = state->getLineCap(); // 0=butt, 1=round 2=square int lineJoin = state->getLineJoin(); // 0=miter, 1=round 2=bevel @@ -719,9 +735,23 @@ void GFXOutputDev::strokeGfxline(GfxState *state, gfxline_t*line) ); dump_outline(line); } - - //swfoutput_drawgfxline(output, line, width, &col, capType, joinType, miterLimit); - device->stroke(device, line, width, &col, capType, joinType, miterLimit); + + if(flags&STROKE_FILL) { + ArtSVP* svp = gfxstrokeToSVP(line, width, capType, joinType, miterLimit); + gfxline_t*gfxline = SVPtogfxline(svp); + if(flags&STROKE_CLIP) { + device->startclip(device, gfxline); + states[statepos].clipping++; + } else { + device->fill(device, gfxline, &col); + } + free(gfxline); + art_svp_free(svp); + } else { + if(flags&STROKE_CLIP) + msg(" Stroke&clip not supported at the same time"); + device->stroke(device, line, width, &col, capType, joinType, miterLimit); + } if(line2) gfxline_free(line2); @@ -784,6 +814,13 @@ void GFXOutputDev::eoClip(GfxState *state) states[statepos].clipping++; gfxline_free(line); } +void GFXOutputDev::clipToStrokePath(GfxState *state) +{ + GfxPath * path = state->getPath(); + gfxline_t*line= gfxPath_to_gfxline(state, path, 0, user_movex + clipmovex, user_movey + clipmovey); + strokeGfxline(state, line, STROKE_FILL|STROKE_CLIP); + gfxline_free(line); +} void GFXOutputDev::endframe() { @@ -831,7 +868,7 @@ GBool GFXOutputDev::useDrawChar() return gTrue; } -char*renderModeDesc[]= {"fill", "stroke", "fill+stroke", "invisible", +const char*renderModeDesc[]= {"fill", "stroke", "fill+stroke", "invisible", "clip+fill", "stroke+clip", "fill+stroke+clip", "clip"}; #define RENDER_FILL 0 @@ -869,7 +906,9 @@ char* makeStringPrintable(char*str) int getGfxCharID(gfxfont_t*font, int charnr, char *charname, int u) { - char*uniname = 0; + const char*uniname = 0; + if(!font) + return charnr; if(u>0) { int t; /* find out char name from unicode index @@ -924,6 +963,14 @@ int getGfxCharID(gfxfont_t*font, int charnr, char *charname, int u) msg(" Char [%d,%s,>%d<] maps to %d\n", charnr, charname, u, font->unicode2glyph[u]); return font->unicode2glyph[u]; } + /* try to use the unicode|0xe000 (needed for some WingDings fonts) + FIXME: do this only if we know the font is wingdings? + */ + u |= 0xe000; + if(u>=0 && umax_unicode && font->unicode2glyph[u]>=0) { + msg(" Char [%d,%s,>%d<] maps to %d\n", charnr, charname, u, font->unicode2glyph[u]); + return font->unicode2glyph[u]; + } if(charnr>=0 && charnrnum_glyphs) { msg(" Char [>%d<,%s,%d] maps to %d\n", charnr, charname, u, charnr); @@ -980,7 +1027,7 @@ void GFXOutputDev::drawChar(GfxState *state, double x, double y, Gushort *CIDToGIDMap = 0; GfxFont*font = state->getFont(); - if(font->getType() == fontType3) { + if(font->getType() == fontType3 && do_interpretType3Chars) { /* type 3 chars are passed as graphics */ msg(" type3 char at %f/%f", x, y); return; @@ -992,6 +1039,13 @@ void GFXOutputDev::drawChar(GfxState *state, double x, double y, if(uLen) u = _u[0]; +/* char*fontname = getFontName(font); + if(u<256 && strstr(fontname, "ingdings")) { + // symbols are at 0xe000 in the unicode table + u |= 0xe000; + } + free(fontname);*/ + if(font->isCIDFont()) { GfxCIDFont*cfont = (GfxCIDFont*)font; @@ -1040,6 +1094,22 @@ void GFXOutputDev::drawChar(GfxState *state, double x, double y, m.tx += user_movex + clipmovex; m.ty += user_movey + clipmovey; + if((!name || strcmp(name, "space")) && charid!=32 && u!=32) + { + gfxline_t*l = current_gfxfont->glyphs[charid].line; + double x,y; + char ok = 0; + while(l) { + if((l->type == gfx_lineTo || l->type == gfx_splineTo) && l->x!=x && l->y!=y) { + ok = 1; + } + l = l->next; + } + if(!ok) { + msg(" Drawing empty character charid=%d", charid); + } + } + if(render == RENDER_FILL) { device->drawchar(device, current_gfxfont, charid, &col, &m); } else { @@ -1082,11 +1152,11 @@ void GFXOutputDev::endString(GfxState *state) current_text_stroke = 0; } else if((render&3) == RENDER_FILLSTROKE) { fillGfxLine(state, current_text_stroke); - strokeGfxline(state, current_text_stroke); + strokeGfxline(state, current_text_stroke,0); gfxline_free(current_text_stroke); current_text_stroke = 0; } else if((render&3) == RENDER_STROKE) { - strokeGfxline(state, current_text_stroke); + strokeGfxline(state, current_text_stroke,0); gfxline_free(current_text_stroke); current_text_stroke = 0; } @@ -1126,14 +1196,14 @@ GBool GFXOutputDev::beginType3Char(GfxState *state, double x, double y, double d msg(" beginType3Char %d, %08x, %d", code, *u, uLen); type3active = 1; - int t; - + /*int t; + gfxcolor_t col={255,0,0,0}; gfxmatrix_t m = {1,0,0, 0,1,0}; for(t=0;tdrawchar(device, 0, u[t], &col, &m); - } + }*/ /* the character itself is going to be passed using the draw functions */ return gFalse; /* gTrue= is_in_cache? */ @@ -1263,7 +1333,7 @@ void GFXOutputDev::processLink(Link *link, Catalog *catalog) LinkAction*action=link->getAction(); char buf[128]; char*s = 0; - char*type = "-?-"; + const char*type = "-?-"; char*named = 0; int page = -1; msg(" drawlink action=%d\n", action->getKind()); @@ -1462,7 +1532,7 @@ char* writeOutStdFont(fontentry* f) return strdup(namebuf2); } -char* GFXOutputDev::searchFont(char*name) +char* GFXOutputDev::searchFont(const char*name) { int i; char*filename=0; @@ -1771,7 +1841,7 @@ char* GFXOutputDev::searchForSuitableFont(GfxFont*gfxFont) char* GFXOutputDev::substituteFont(GfxFont*gfxFont, char* oldname) { - char*fontname = 0, *filename = 0; + const char*fontname = 0, *filename = 0; msg(" substituteFont(%s)", oldname); if(!(fontname = searchForSuitableFont(gfxFont))) { @@ -2431,7 +2501,7 @@ void GFXOutputDev::stroke(GfxState *state) GfxPath * path = state->getPath(); gfxline_t*line= gfxPath_to_gfxline(state, path, 0, user_movex + clipmovex, user_movey + clipmovey); - strokeGfxline(state, line); + strokeGfxline(state, line, 0); gfxline_free(line); } @@ -2458,7 +2528,7 @@ void GFXOutputDev::eoFill(GfxState *state) } -static char* dirseparator() +static const char* dirseparator() { #ifdef WIN32 return "\\"; @@ -2467,7 +2537,7 @@ static char* dirseparator() #endif } -void addGlobalFont(char*filename) +void addGlobalFont(const char*filename) { fontfile_t f; memset(&f, 0, sizeof(fontfile_t)); @@ -2480,10 +2550,10 @@ void addGlobalFont(char*filename) } } -void addGlobalLanguageDir(char*dir) +void addGlobalLanguageDir(const char*dir) { if(!globalParams) - globalParams = new GlobalParams(""); + globalParams = new GlobalParams((char*)""); msg(" Adding %s to language pack directories", dir); @@ -2503,7 +2573,7 @@ void addGlobalLanguageDir(char*dir) fclose(fi); } -void addGlobalFontDir(char*dirname) +void addGlobalFontDir(const char*dirname) { #ifdef HAVE_DIRENT_H msg(" Adding %s to font directories", dirname); @@ -2655,7 +2725,7 @@ void GFXOutputDev::beginTransparencyGroup(GfxState *state, double *bbox, GBool isolated, GBool knockout, GBool forSoftMask) { - char*colormodename = ""; + const char*colormodename = ""; BBox rect = mkBBox(state, bbox, this->width, this->height); if(blendingColorSpace) { @@ -2703,9 +2773,9 @@ void GFXOutputDev::endTransparencyGroup(GfxState *state) void GFXOutputDev::paintTransparencyGroup(GfxState *state, double *bbox) { - char*blendmodes[] = {"normal","multiply","screen","overlay","darken", "lighten", - "colordodge","colorburn","hardlight","softlight","difference", - "exclusion","hue","saturation","color","luminosity"}; + const char*blendmodes[] = {"normal","multiply","screen","overlay","darken", "lighten", + "colordodge","colorburn","hardlight","softlight","difference", + "exclusion","hue","saturation","color","luminosity"}; dbg("paintTransparencyGroup blend=%s softmaskon=%d", blendmodes[state->getBlendMode()], states[statepos].softmask); msg(" paintTransparencyGroup blend=%s softmaskon=%d", blendmodes[state->getBlendMode()], states[statepos].softmask); @@ -2792,6 +2862,8 @@ void GFXOutputDev::clearSoftMask(GfxState *state) #endif int width = (int)bbox.xmax,height = (int)bbox.ymax; + if(width<=0 || height<=0) + return; gfxdevice_t belowrender; gfxdevice_render_init(&belowrender);