virtual void drawImage(GfxState *state, Object *ref, Stream *str,
int width, int height, GfxImageColorMap *colorMap,
int *maskColors, GBool inlineImg);
+ virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
+ int width, int height,
+ GfxImageColorMap *colorMap,
+ Stream *maskStr, int maskWidth, int maskHeight,
+ GBool maskInvert);
+ virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
+ int width, int height,
+ GfxImageColorMap *colorMap,
+ Stream *maskStr,
+ int maskWidth, int maskHeight,
+ GfxImageColorMap *maskColorMap);
virtual GBool beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen);
virtual void endType3Char(GfxState *state);
private:
void drawGeneralImage(GfxState *state, Object *ref, Stream *str,
int width, int height, GfxImageColorMap*colorMap, GBool invert,
- GBool inlineImg, int mask, int *maskColors);
- int SWFOutputDev::setGfxFont(char*id, char*filename, double quality);
+ GBool inlineImg, int mask, int *maskColors,
+ Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert, GfxImageColorMap*maskColorMap);
+ int SWFOutputDev::setGfxFont(char*id, char*name, char*filename, double quality);
void strokeGfxline(GfxState *state, gfxline_t*line);
void clipToGfxLine(GfxState *state, gfxline_t*line);
void fillGfxLine(GfxState *state, gfxline_t*line);
static char*getFontID(GfxFont*font)
{
+ Ref*ref = font->getID();
GString*gstr = font->getName();
- char* fontname = gstr==0?0:gstr->getCString();
- if(fontname==0) {
- char buf[32];
- Ref*r=font->getID();
- sprintf(buf, "UFONT%d", r->num);
- return strdup(buf);
+ char* fname = gstr==0?0:gstr->getCString();
+ char buf[128];
+ if(fname==0) {
+ sprintf(buf, "font-%d-%d", ref->num, ref->gen);
+ } else {
+ sprintf(buf, "%s-%d-%d", fname, ref->num, ref->gen);
}
- return strdup(fontname);
+ return strdup(buf);
}
static char*getFontName(GfxFont*font)
{
- char*fontid = getFontID(font);
+ char*fontid;
+ GString*gstr = font->getName();
+ char* fname = gstr==0?0:gstr->getCString();
+ if(fname==0) {
+ char buf[32];
+ Ref*r=font->getID();
+ sprintf(buf, "UFONT%d", r->num);
+ fontid = strdup(buf);
+ }
+ fontid = strdup(fname);
+
char*fontname= 0;
char* plus = strchr(fontid, '+');
if(plus && plus < &fontid[strlen(fontid)-1]) {
col.r = colToByte(rgb.r);
col.g = colToByte(rgb.g);
col.b = colToByte(rgb.b);
- col.a = (unsigned char)(rgb.r*255);
+ col.a = (unsigned char)(opaq*255);
return col;
}
int getGfxCharID(gfxfont_t*font, int charnr, char *charname, int u)
{
- int t;
+ char*uniname = 0;
+ if(u>0) {
+ int t;
+ /* find out char name from unicode index
+ TODO: should be precomputed
+ */
+ for(t=0;t<sizeof(nameToUnicodeTab)/sizeof(nameToUnicodeTab[0]);t++) {
+ if(nameToUnicodeTab[t].u == u) {
+ uniname = nameToUnicodeTab[t].name;
+ break;
+ }
+ }
+ }
+
if(charname) {
+ int t;
for(t=0;t<font->num_glyphs;t++) {
if(font->glyphs[t].name && !strcmp(font->glyphs[t].name,charname)) {
msg("<debug> Char [%d,>%s<,%d] maps to %d\n", charnr, charname, u, t);
}
}
+ if(uniname) {
+ int t;
+ for(t=0;t<font->num_glyphs;t++) {
+ if(font->glyphs[t].name && !strcmp(font->glyphs[t].name,uniname)) {
+ msg("<debug> Char [%d,%s,>%d(%s)<] maps to %d\n", charnr, charname, u, uniname, t);
+ return t;
+ }
+ }
+ /* if we didn't find the character, maybe
+ we can find the capitalized version */
+ for(t=0;t<font->num_glyphs;t++) {
+ if(font->glyphs[t].name && !strcasecmp(font->glyphs[t].name,uniname)) {
+ msg("<debug> Char [%d,%s,>>%d(%s)<<] maps to %d\n", charnr, charname, u, uniname, t);
+ return t;
+ }
+ }
+ }
+
/* try to use the unicode id */
if(u>=0 && u<font->max_unicode && font->unicode2glyph[u]>=0) {
msg("<debug> Char [%d,%s,>%d<] maps to %d\n", charnr, charname, u, font->unicode2glyph[u]);
return font->unicode2glyph[u];
}
- /* we don't need to "draw" space characters, so don't overdo the search
- for a matching glyph */
- if(charname && !strcasecmp(charname, "space"))
- return -1;
-
if(charnr>=0 && charnr<font->num_glyphs) {
msg("<debug> Char [>%d<,%s,%d] maps to %d\n", charnr, charname, u, charnr);
return charnr;
Unicode u=0;
char*name=0;
- if(_u && uLen) {
- u = *_u;
- if (u) {
- int t;
- /* find out char name from unicode index
- TODO: should be precomputed
- */
- for(t=0;t<sizeof(nameToUnicodeTab)/sizeof(nameToUnicodeTab[0]);t++) {
- if(nameToUnicodeTab[t].u == u) {
- name = nameToUnicodeTab[t].name;
- break;
- }
- }
- }
- }
-
if(font->isCIDFont()) {
GfxCIDFont*cfont = (GfxCIDFont*)font;
Gfx8BitFont*font8;
font8 = (Gfx8BitFont*)font;
char**enc=font8->getEncoding();
- if(enc && enc[c] && strcasecmp(enc[c], "space")) {
- name = enc[c];
- }
+ name = enc[c];
}
if (CIDToGIDMap) {
msg("<debug> drawChar(%f, %f, c='%c' (%d), GID=%d, u=%d <%d>) CID=%d name=\"%s\" render=%d\n", x, y, (c&127)>=32?c:'?', c, CIDToGIDMap[c], u, uLen, font->isCIDFont(), FIXNULL(name), render);
if(uLen<=1) {
charid = getGfxCharID(current_gfxfont, c, name, u);
} else {
- charid = getGfxCharID(current_gfxfont, c, 0, -1);
+ charid = getGfxCharID(current_gfxfont, c, name, -1);
+
if(charid < 0) {
/* multiple unicodes- should usually map to a ligature.
if the ligature doesn't exist, we need to draw
return;
}
}
-
if(charid<0) {
- if(!name || strcasecmp(name, "space")) {
- msg("<warning> 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);
- }
+ msg("<warning> 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);
return;
}
break;
}
}
- if(lpage>=0) {
- char buf[80];
- sprintf(buf, "page%d", t);
- output->drawlink(output, points, buf);
- } else {
- msg("<warning> Invalid link to page %d", page);
+ if(lpage<0) {
+ lpage = page;
}
+ char buf[80];
+ sprintf(buf, "page%d", lpage);
+ output->drawlink(output, points, buf);
}
else if(url)
{
this->xref = xref;
}
-int SWFOutputDev::setGfxFont(char*id, char*filename, double maxSize)
+int SWFOutputDev::setGfxFont(char*id, char*name, char*filename, double maxSize)
{
gfxfont_t*font = 0;
fontlist_t*last=0,*l = this->fontlist;
if (!gfxFont) {
return;
}
+
char * fontid = getFontID(gfxFont);
+ char * fontname = getFontName(gfxFont);
+
double maxSize = 1.0;
if(this->info) {
/* second, see if this is a font which was used before-
if so, we are done */
- if(setGfxFont(fontid, 0, 0)) {
+ if(setGfxFont(fontid, fontname, 0, 0)) {
free(fontid);
+ free(fontname);
return;
}
/* if(swfoutput_queryfont(&output, fontid))
showFontError(gfxFont, 2);
}
free(fontid);
+ free(fontname);
return;
}
if(!fileName) showFontError(gfxFont,0);
else del = 1;
} else {
- char * fontname = getFontName(gfxFont);
fileName = searchFont(fontname);
if(!fileName) showFontError(gfxFont,0);
- free(fontname);
}
if(!fileName) {
char * fontname = getFontName(gfxFont);
if(!fileName) {
msg("<error> Couldn't set font %s\n", fontid);
free(fontid);
+ free(fontname);
return;
}
//swfoutput_setfont(&output, fontid, fileName);
- if(!setGfxFont(fontid, 0, 0)) {
- setGfxFont(fontid, fileName, maxSize);
+ if(!setGfxFont(fontid, fontname, 0, 0)) {
+ setGfxFont(fontid, fontname, fileName, maxSize);
}
if(fileName && del)
unlinkfont(fileName);
+
if(fileName)
free(fileName);
free(fontid);
+ free(fontname);
msg("<verbose> |");
}
void SWFOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str,
int width, int height, GfxImageColorMap*colorMap, GBool invert,
- GBool inlineImg, int mask, int*maskColors)
+ GBool inlineImg, int mask, int*maskColors,
+ Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert, GfxImageColorMap*maskColorMap)
{
- FILE *fi;
- int c;
- char fileName[128];
double x1,y1,x2,y2,x3,y3,x4,y4;
ImageStream *imgStr;
Guchar pixBuf[4];
GfxRGB rgb;
int ncomps = 1;
int bits = 1;
+ unsigned char* maskbitmap = 0;
if(colorMap) {
ncomps = colorMap->getNumPixelComps();
bits = colorMap->getBits();
}
+
+ if(maskStr) {
+ int x,y;
+ unsigned char buf[8];
+ maskbitmap = (unsigned char*)malloc(maskHeight*maskWidth);
+ if(maskColorMap) {
+ ImageStream*imgMaskStr = new ImageStream(maskStr, maskWidth, maskColorMap->getNumPixelComps(), maskColorMap->getBits());
+ imgMaskStr->reset();
+ unsigned char pal[256];
+ int n = 1 << colorMap->getBits();
+ int t;
+ for(t=0;t<n;t++) {
+ GfxGray gray;
+ pixBuf[0] = t;
+ maskColorMap->getGray(pixBuf, &gray);
+ pal[t] = colToByte(gray);
+ }
+ for (y = 0; y < maskHeight; y++) {
+ for (x = 0; x < maskWidth; x++) {
+ imgMaskStr->getPixel(buf);
+ maskbitmap[y*maskWidth+x] = pal[buf[0]];
+ }
+ }
+ delete imgMaskStr;
+ } else {
+ ImageStream*imgMaskStr = new ImageStream(maskStr, maskWidth, 1, 1);
+ imgMaskStr->reset();
+ for (y = 0; y < maskHeight; y++) {
+ for (x = 0; x < maskWidth; x++) {
+ imgMaskStr->getPixel(buf);
+ buf[0]^=maskInvert;
+ maskbitmap[y*maskWidth+x] = (buf[0]^1)*255;
+ }
+ }
+ delete imgMaskStr;
+ }
+ }
+
imgStr = new ImageStream(str, width, ncomps,bits);
imgStr->reset();
imgStr->getPixel(buf);
}
delete imgStr;
+ if(maskbitmap)
+ free(maskbitmap);
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; 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;
if(!pbminfo && !(str->getKind()==strDCT)) {
if(!type3active) {
free(pic2);
free(pic);
delete imgStr;
+ if(maskbitmap) free(maskbitmap);
return;
- }
+ }
int x,y;
pic[width*y+x].g = (unsigned char)(colToByte(rgb.g));
pic[width*y+x].b = (unsigned char)(colToByte(rgb.b));
pic[width*y+x].a = 255;//(U8)(rgb.a * 255 + 0.5);
+ if(maskbitmap) {
+ pic[width*y+x].a = maskbitmap[(y*maskHeight/height)*maskWidth+(x*maskWidth/width)];
+ }
}
}
if(str->getKind()==strDCT)
drawimagelossless(output, pic, width, height, x1,y1,x2,y2,x3,y3,x4,y4);
delete pic;
delete imgStr;
+ if(maskbitmap) free(maskbitmap);
return;
} else {
gfxcolor_t*pic=new gfxcolor_t[width*height];
gfxcolor_t pal[256];
+ int n = 1 << colorMap->getBits();
int t;
for(t=0;t<256;t++) {
pixBuf[0] = t;
colorMap->getRGB(pixBuf, &rgb);
- /*if(maskColors && *maskColors==t) {
+
+ {/*if(maskColors && *maskColors==t) {
msg("<notice> Color %d is transparent", t);
if (imgData->maskColors) {
*alpha = 0;
pal[t].b = 0;
pal[t].a = 0;
}
- } else*/ {
- pal[t].r = (unsigned char)(rgb.r * 255 + 0.5);
- pal[t].g = (unsigned char)(rgb.g * 255 + 0.5);
- pal[t].b = (unsigned char)(rgb.b * 255 + 0.5);
+ } else {*/
+ pal[t].r = (unsigned char)(colToByte(rgb.r));
+ pal[t].g = (unsigned char)(colToByte(rgb.g));
+ pal[t].b = (unsigned char)(colToByte(rgb.b));
pal[t].a = 255;//(U8)(rgb.b * 255 + 0.5);
}
}
for (x = 0; x < width; ++x) {
imgStr->getPixel(pixBuf);
pic[width*y+x] = pal[pixBuf[0]];
+ if(maskbitmap) {
+ pic[width*y+x].a = maskbitmap[(y*maskHeight/height)*maskWidth+(x*maskWidth/width)];
+ }
}
}
drawimagelossless(output, pic, width, height, x1,y1,x2,y2,x3,y3,x4,y4);
delete pic;
delete imgStr;
+ if(maskbitmap) free(maskbitmap);
return;
}
}
if(states[statepos].textRender & 4) //clipped
return;
msg("<verbose> drawImageMask %dx%d, invert=%d inline=%d", width, height, invert, inlineImg);
- drawGeneralImage(state,ref,str,width,height,0,invert,inlineImg,1, 0);
+ drawGeneralImage(state,ref,str,width,height,0,invert,inlineImg,1, 0, 0,0,0,0, 0);
}
void SWFOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
if(states[statepos].textRender & 4) //clipped
return;
- msg("<verbose> drawImage %dx%d, %s %s, inline=%d", width, height,
+ msg("<verbose> drawImage %dx%d, %s, %s, inline=%d", width, height,
colorMap?"colorMap":"no colorMap",
maskColors?"maskColors":"no maskColors",
inlineImg);
if(colorMap)
msg("<verbose> colorMap pixcomps:%d bits:%d mode:%d\n", colorMap->getNumPixelComps(),
colorMap->getBits(),colorMap->getColorSpace()->getMode());
- drawGeneralImage(state,ref,str,width,height,colorMap,0,inlineImg,0,maskColors);
+ drawGeneralImage(state,ref,str,width,height,colorMap,0,inlineImg,0,maskColors, 0,0,0,0, 0);
+}
+
+void SWFOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
+ int width, int height,
+ GfxImageColorMap *colorMap,
+ Stream *maskStr, int maskWidth, int maskHeight,
+ GBool maskInvert)
+{
+ if(states[statepos].textRender & 4) //clipped
+ return;
+
+ msg("<verbose> drawMaskedImage %dx%d, %s, %dx%d mask", width, height,
+ colorMap?"colorMap":"no colorMap",
+ maskWidth, maskHeight);
+ if(colorMap)
+ msg("<verbose> colorMap pixcomps:%d bits:%d mode:%d\n", colorMap->getNumPixelComps(),
+ colorMap->getBits(),colorMap->getColorSpace()->getMode());
+ drawGeneralImage(state,ref,str,width,height,colorMap,0,0,0,0, maskStr, maskWidth, maskHeight, maskInvert, 0);
+}
+
+void SWFOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
+ int width, int height,
+ GfxImageColorMap *colorMap,
+ Stream *maskStr,
+ int maskWidth, int maskHeight,
+ GfxImageColorMap *maskColorMap)
+{
+ if(states[statepos].textRender & 4) //clipped
+ return;
+
+ msg("<verbose> drawSoftMaskedImage %dx%d, %s, %dx%d mask", width, height,
+ colorMap?"colorMap":"no colorMap",
+ maskWidth, maskHeight);
+ if(colorMap)
+ msg("<verbose> colorMap pixcomps:%d bits:%d mode:%d\n", colorMap->getNumPixelComps(),
+ colorMap->getBits(),colorMap->getColorSpace()->getMode());
+ drawGeneralImage(state,ref,str,width,height,colorMap,0,0,0,0, maskStr, maskWidth, maskHeight, 0, maskColorMap);
}
//SWFOutputDev*output = 0;
storeDeviceParameter("ppmsubpixels", buf);
} else if(!strcmp(name, "forceType0Fonts")) {
forceType0Fonts = atoi(value);
- } else if(!strcmp(name, "fontdir")) {
+ } else if(!strncmp(name, "fontdir", strlen("fontdir"))) {
pdfswf_addfontdir(value);
- } else if(!strcmp(name, "languagedir")) {
+ } else if(!strncmp(name, "languagedir", strlen("languagedir"))) {
pdfswf_addlanguagedir(value);
} else if(!strcmp(name, "fontconfig")) {
config_use_fontconfig = atoi(value);
int l;
FILE*fi = 0;
- char* config_file = (char*)malloc(strlen(dir) + 1 + sizeof("add-to-xpdfrc"));
+ char* config_file = (char*)malloc(strlen(dir) + 1 + sizeof("add-to-xpdfrc") + 1);
strcpy(config_file, dir);
strcat(config_file, dirseparator());
strcat(config_file, "add-to-xpdfrc");