diff options
author | Tor Andersson <tor@ghostscript.com> | 2010-04-06 00:37:45 +0200 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2010-04-06 00:37:45 +0200 |
commit | fc0c17314f40e758e19de549be5b506f93cea2b9 (patch) | |
tree | 9eb0a4e8f7a53d6406d1d4bd8a63eeec3cc99362 | |
parent | b761cb01c5ac977efed3a60f896f4bdc9cd744f0 (diff) | |
download | mupdf-fc0c17314f40e758e19de549be5b506f93cea2b9.tar.xz |
Support rendering alpha mask only with the device colorspace set to NULL. Use this to render type 3 fonts.
-rw-r--r-- | apps/pdfapp.c | 4 | ||||
-rw-r--r-- | apps/pdfdraw.c | 6 | ||||
-rw-r--r-- | fitz/dev_draw.c | 136 | ||||
-rw-r--r-- | fitz/fitz_res.h | 2 | ||||
-rw-r--r-- | fitz/res_font.c | 6 | ||||
-rw-r--r-- | mupdf/mupdf.h | 2 | ||||
-rw-r--r-- | mupdf/pdf_interpret.c | 12 |
7 files changed, 94 insertions, 74 deletions
diff --git a/apps/pdfapp.c b/apps/pdfapp.c index e677c76e..0b39f134 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -265,12 +265,12 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage) tdev = fz_newtextdevice(app->text); app->page->contents->rp = app->page->contents->bp; - error = pdf_runcontentstream(idev, ctm, 0, app->xref, app->page->resources, app->page->contents); + error = pdf_runcontentstream(idev, ctm, app->xref, app->page->resources, app->page->contents); if (error) pdfapp_error(app, error); app->page->contents->rp = app->page->contents->bp; - error = pdf_runcontentstream(tdev, ctm, 0, app->xref, app->page->resources, app->page->contents); + error = pdf_runcontentstream(tdev, ctm, app->xref, app->page->resources, app->page->contents); if (error) pdfapp_error(app, error); diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c index 2855227a..2e8c8472 100644 --- a/apps/pdfdraw.c +++ b/apps/pdfdraw.c @@ -229,11 +229,11 @@ static void drawpnm(int pagenum, struct benchmark *loadtimes, struct benchmark * // dev = fz_newtracedevice(); // drawpage->contents->rp = drawpage->contents->bp; -// pdf_runcontentstream(dev, ctm, 0, xref, drawpage->resources, drawpage->contents); +// pdf_runcontentstream(dev, ctm, xref, drawpage->resources, drawpage->contents); dev = fz_newdrawdevice(pix); drawpage->contents->rp = drawpage->contents->bp; - error = pdf_runcontentstream(dev, ctm, 0, xref, drawpage->resources, drawpage->contents); + error = pdf_runcontentstream(dev, ctm, xref, drawpage->resources, drawpage->contents); if (error) die(error); fz_freedrawdevice(dev); @@ -322,7 +322,7 @@ static void drawtxt(int pagenum) dev = fz_newtextdevice(text); drawpage->contents->rp = drawpage->contents->bp; - error = pdf_runcontentstream(dev, ctm, 0, xref, drawpage->resources, drawpage->contents); + error = pdf_runcontentstream(dev, ctm, xref, drawpage->resources, drawpage->contents); if (error) die(error); diff --git a/fitz/dev_draw.c b/fitz/dev_draw.c index 45575bbb..b8223ce4 100644 --- a/fitz/dev_draw.c +++ b/fitz/dev_draw.c @@ -109,20 +109,6 @@ void fz_drawfillpath(void *user, fz_path *path, fz_colorspace *colorspace, float float flatness = 0.3 / expansion; fz_irect bbox; fz_irect clip; - unsigned char argb[7]; - float rgb[3]; - - if (flatness < 0.1) - flatness = 0.1; - - fz_convertcolor(colorspace, color, dev->model, rgb); - argb[0] = alpha * 255; - argb[1] = rgb[0] * alpha * 255; - argb[2] = rgb[1] * alpha * 255; - argb[3] = rgb[2] * alpha * 255; - argb[4] = rgb[0] * 255; - argb[5] = rgb[1] * 255; - argb[6] = rgb[2] * 255; clip.x0 = dev->dest->x; clip.y0 = dev->dest->y; @@ -138,7 +124,24 @@ void fz_drawfillpath(void *user, fz_path *path, fz_colorspace *colorspace, float if (fz_isemptyrect(bbox)) return; - fz_scanconvert(dev->gel, dev->ael, path->winding == FZ_EVENODD, bbox, dev->dest, argb, 1); + if (dev->model) + { + unsigned char argb[7]; + float rgb[3]; + fz_convertcolor(colorspace, color, dev->model, rgb); + argb[0] = alpha * 255; + argb[1] = rgb[0] * alpha * 255; + argb[2] = rgb[1] * alpha * 255; + argb[3] = rgb[2] * alpha * 255; + argb[4] = rgb[0] * 255; + argb[5] = rgb[1] * 255; + argb[6] = rgb[2] * 255; + fz_scanconvert(dev->gel, dev->ael, path->winding == FZ_EVENODD, bbox, dev->dest, argb, 1); + } + else + { + fz_scanconvert(dev->gel, dev->ael, path->winding == FZ_EVENODD, bbox, dev->dest, nil, 1); + } } void fz_drawstrokepath(void *user, fz_path *path, fz_colorspace *colorspace, float *color, float alpha) @@ -149,21 +152,10 @@ void fz_drawstrokepath(void *user, fz_path *path, fz_colorspace *colorspace, flo float linewidth = path->linewidth; fz_irect bbox; fz_irect clip; - unsigned char argb[7]; - float rgb[3]; if (linewidth * expansion < 0.1) linewidth = 1.0 / expansion; - fz_convertcolor(colorspace, color, dev->model, rgb); - argb[0] = alpha * 255; - argb[1] = rgb[0] * alpha * 255; - argb[2] = rgb[1] * alpha * 255; - argb[3] = rgb[2] * alpha * 255; - argb[4] = rgb[0] * 255; - argb[5] = rgb[1] * 255; - argb[6] = rgb[2] * 255; - clip.x0 = dev->dest->x; clip.y0 = dev->dest->y; clip.x1 = dev->dest->x + dev->dest->w; @@ -181,7 +173,24 @@ void fz_drawstrokepath(void *user, fz_path *path, fz_colorspace *colorspace, flo if (fz_isemptyrect(bbox)) return; - fz_scanconvert(dev->gel, dev->ael, 0, bbox, dev->dest, argb, 1); + if (dev->model) + { + unsigned char argb[7]; + float rgb[3]; + fz_convertcolor(colorspace, color, dev->model, rgb); + argb[0] = alpha * 255; + argb[1] = rgb[0] * alpha * 255; + argb[2] = rgb[1] * alpha * 255; + argb[3] = rgb[2] * alpha * 255; + argb[4] = rgb[0] * 255; + argb[5] = rgb[1] * 255; + argb[6] = rgb[2] * 255; + fz_scanconvert(dev->gel, dev->ael, 0, bbox, dev->dest, argb, 1); + } + else + { + fz_scanconvert(dev->gel, dev->ael, 0, bbox, dev->dest, nil, 1); + } } void fz_drawclippath(void *user, fz_path *path) @@ -217,7 +226,7 @@ void fz_drawclippath(void *user, fz_path *path) memset(dest->samples, 0, dest->w * dest->h * dest->n); if (!fz_isemptyrect(bbox)) - fz_scanconvert(dev->gel, dev->ael, path->winding == FZ_EVENODD, bbox, mask, NULL, 1); + fz_scanconvert(dev->gel, dev->ael, path->winding == FZ_EVENODD, bbox, mask, nil, 1); dev->clipstack[dev->cliptop].mask = mask; dev->clipstack[dev->cliptop].dest = dev->dest; @@ -261,30 +270,36 @@ static void drawglyph(unsigned char *argb, fz_pixmap *dst, fz_glyph *src, int xo if (dst->colorspace) fz_text_w4i1o4(argb, sp, src->w, dp, dst->w * 4, w, h); else - { - printf("drawing glyph to alpha mask\n"); fz_text_1o1(sp, src->w, dp, dst->w, w, h); - } } void fz_drawfilltext(void *user, fz_text *text, fz_colorspace *colorspace, float *color, float alpha) { fz_drawdevice *dev = user; - unsigned char argb[7]; - float rgb[3]; fz_irect clip; fz_matrix tm, trm; fz_glyph glyph; int i, x, y, gid; + unsigned char tmp[7]; + unsigned char *argb; - fz_convertcolor(colorspace, color, dev->model, rgb); - argb[0] = alpha * 255; - argb[1] = rgb[0] * alpha * 255; - argb[2] = rgb[1] * alpha * 255; - argb[3] = rgb[2] * alpha * 255; - argb[4] = rgb[0] * 255; - argb[5] = rgb[1] * 255; - argb[6] = rgb[2] * 255; + if (dev->model) + { + float rgb[3]; + fz_convertcolor(colorspace, color, dev->model, rgb); + tmp[0] = alpha * 255; + tmp[1] = rgb[0] * alpha * 255; + tmp[2] = rgb[1] * alpha * 255; + tmp[3] = rgb[2] * alpha * 255; + tmp[4] = rgb[0] * 255; + tmp[5] = rgb[1] * 255; + tmp[6] = rgb[2] * 255; + argb = tmp; + } + else + { + argb = nil; + } clip.x0 = dev->dest->x; clip.y0 = dev->dest->y; @@ -368,6 +383,12 @@ void fz_drawdrawshade(void *user, fz_shade *shade, fz_matrix ctm) if (fz_isemptyrect(clip)) return; + if (!dev->model) + { + fz_warn("cannot render shading directly to an alpha mask"); + return; + } + temp = fz_newpixmapwithrect(dev->model, clip); if (shade->usebackground) @@ -448,6 +469,12 @@ void fz_drawdrawimage(void *user, fz_pixmap *image, fz_matrix ctm) if (image->w == 0 || image->h == 0) return; + if (!dev->model) + { + fz_warn("cannot render image directly to an alpha mask"); + return; + } + calcimagescale(ctm, image->w, image->h, &dx, &dy); if (dx != 1 || dy != 1) @@ -456,7 +483,7 @@ void fz_drawdrawimage(void *user, fz_pixmap *image, fz_matrix ctm) image = temp; } - if (image->colorspace && image->colorspace != dev->model) + if (image->colorspace != dev->model) { temp = fz_newpixmap(dev->model, image->x, image->y, image->w, image->h); fz_convertpixmap(image->colorspace, image, dev->model, temp); @@ -509,17 +536,6 @@ void fz_drawfillimagemask(void *user, fz_pixmap *image, fz_matrix ctm, fz_colors int u0, v0; int x0, y0; int w, h; - unsigned char argb[7]; - float rgb[3]; - - fz_convertcolor(colorspace, color, dev->model, rgb); - argb[0] = alpha * 255; - argb[1] = rgb[0] * alpha * 255; - argb[2] = rgb[1] * alpha * 255; - argb[3] = rgb[2] * alpha * 255; - argb[4] = rgb[0] * 255; - argb[5] = rgb[1] * 255; - argb[6] = rgb[2] * 255; bounds.x0 = 0; bounds.y0 = 0; @@ -572,11 +588,25 @@ void fz_drawfillimagemask(void *user, fz_pixmap *image, fz_matrix ctm, fz_colors #define PDST(p) p->samples + ((y0-p->y) * p->w + (x0-p->x)) * p->n, p->w * p->n if (dev->dest->colorspace) + { + unsigned char argb[7]; + float rgb[3]; + fz_convertcolor(colorspace, color, dev->model, rgb); + argb[0] = alpha * 255; + argb[1] = rgb[0] * alpha * 255; + argb[2] = rgb[1] * alpha * 255; + argb[3] = rgb[2] * alpha * 255; + argb[4] = rgb[0] * 255; + argb[5] = rgb[1] * 255; + argb[6] = rgb[2] * 255; fz_img_w4i1o4(argb, image->samples, image->w, image->h, PDST(dev->dest), u0, v0, fa, fb, fc, fd, w, h); + } else + { fz_img_1o1(image->samples, image->w, image->h, PDST(dev->dest), u0, v0, fa, fb, fc, fd, w, h); + } } void fz_drawclipimagemask(void *user, fz_pixmap *image, fz_matrix ctm) diff --git a/fitz/fitz_res.h b/fitz/fitz_res.h index 1ca21aeb..35416fda 100644 --- a/fitz/fitz_res.h +++ b/fitz/fitz_res.h @@ -253,7 +253,7 @@ struct fz_font_s fz_buffer **t3procs; /* has 256 entries if used */ float *t3widths; /* has 256 entries if used */ void *t3xref; /* a pdf_xref for the callback */ - fz_error (*t3runcontentstream)(fz_device *dev, fz_matrix ctm, int maskonly, + fz_error (*t3runcontentstream)(fz_device *dev, fz_matrix ctm, void *xref, fz_obj *resources, fz_buffer *contents); fz_rect bbox; diff --git a/fitz/res_font.c b/fitz/res_font.c index 0c314b32..817bc3eb 100644 --- a/fitz/res_font.c +++ b/fitz/res_font.c @@ -368,8 +368,6 @@ fz_rendert3glyph(fz_glyph *glyph, fz_font *font, int gid, fz_matrix trm) glyph->h = 0; glyph->samples = nil; - printf("render t3 glyph %d\n", gid); - /* TODO: make it reentrant */ static fz_pixmap *pixmap = nil; if (pixmap) @@ -392,13 +390,11 @@ fz_rendert3glyph(fz_glyph *glyph, fz_font *font, int gid, fz_matrix trm) dev = fz_newdrawdevice(pixmap); contents->rp = contents->bp; - error = font->t3runcontentstream(dev, ctm, 1, font->t3xref, font->t3resources, contents); + error = font->t3runcontentstream(dev, ctm, font->t3xref, font->t3resources, contents); if (error) fz_catch(error, "cannot draw type3 glyph"); fz_freedrawdevice(dev); - fz_debugpixmap(pixmap, "g"); - glyph->x = pixmap->x; glyph->y = pixmap->y; glyph->w = pixmap->w; diff --git a/mupdf/mupdf.h b/mupdf/mupdf.h index 47fef1dc..883c24fe 100644 --- a/mupdf/mupdf.h +++ b/mupdf/mupdf.h @@ -695,6 +695,6 @@ void pdf_showshade(pdf_csi*, fz_shade *shd); void pdf_gsave(pdf_csi *csi); void pdf_grestore(pdf_csi *csi); fz_error pdf_runcsibuffer(pdf_csi *csi, pdf_xref *xref, fz_obj *rdb, fz_buffer *contents); -fz_error pdf_runcontentstream(fz_device *dev, fz_matrix ctm, int maskonly, pdf_xref *xref, fz_obj *resources, fz_buffer *contents); +fz_error pdf_runcontentstream(fz_device *dev, fz_matrix ctm, pdf_xref *xref, fz_obj *resources, fz_buffer *contents); #endif diff --git a/mupdf/pdf_interpret.c b/mupdf/pdf_interpret.c index 6feb79b7..ad7590ad 100644 --- a/mupdf/pdf_interpret.c +++ b/mupdf/pdf_interpret.c @@ -2,7 +2,7 @@ #include "mupdf.h" static pdf_csi * -pdf_newcsi(fz_device *dev, int maskonly, fz_matrix ctm) +pdf_newcsi(fz_device *dev, fz_matrix ctm) { pdf_csi *csi; @@ -17,12 +17,6 @@ pdf_newcsi(fz_device *dev, int maskonly, fz_matrix ctm) csi->path = fz_newpath(); csi->text = nil; - if (maskonly) - { - csi->gstate[0].fill.kind = PDF_MNONE; - csi->gstate[0].stroke.kind = PDF_MNONE; - } - csi->clip = 0; csi->clipevenodd = 0; @@ -1374,10 +1368,10 @@ pdf_runcsibuffer(pdf_csi *csi, pdf_xref *xref, fz_obj *rdb, fz_buffer *contents) } fz_error -pdf_runcontentstream(fz_device *dev, fz_matrix ctm, int maskonly, +pdf_runcontentstream(fz_device *dev, fz_matrix ctm, pdf_xref *xref, fz_obj *resources, fz_buffer *contents) { - pdf_csi *csi = pdf_newcsi(dev, maskonly, ctm); + pdf_csi *csi = pdf_newcsi(dev, ctm); fz_error error = pdf_runcsibuffer(csi, xref, resources, contents); pdf_freecsi(csi); if (error) |