summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2010-04-15 22:40:41 +0200
committerTor Andersson <tor@ghostscript.com>2010-04-15 22:40:41 +0200
commit80f493b34eb72dfad76d06a97545e64afff84f78 (patch)
treee048b299da91aba52b878eab6242780f9f896bfc
parentbd7e94651b00d884ffb0a5349182d99a87396a6d (diff)
downloadmupdf-80f493b34eb72dfad76d06a97545e64afff84f78.tar.xz
Make the glyph cache an input to fz_newdrawdevice so that it can be shared between pages.
-rw-r--r--apps/pdfapp.c7
-rw-r--r--apps/pdfapp.h1
-rw-r--r--apps/pdfdraw.c10
-rw-r--r--fitz/dev_draw.c5
-rw-r--r--fitz/fitz_draw.h96
-rw-r--r--fitz/fitz_res.h3
-rw-r--r--fitz/res_font.c5
7 files changed, 73 insertions, 54 deletions
diff --git a/apps/pdfapp.c b/apps/pdfapp.c
index 499502ca..e4aaa07b 100644
--- a/apps/pdfapp.c
+++ b/apps/pdfapp.c
@@ -56,6 +56,7 @@ void pdfapp_init(pdfapp_t *app)
app->scrw = 640;
app->scrh = 480;
app->zoom = 1.0;
+ app->cache = fz_newglyphcache(512, 512 * 512);
}
void pdfapp_open(pdfapp_t *app, char *filename)
@@ -133,6 +134,10 @@ void pdfapp_open(pdfapp_t *app, char *filename)
void pdfapp_close(pdfapp_t *app)
{
+ if (app->cache)
+ fz_freeglyphcache(app->cache);
+ app->cache = nil;
+
if (app->page)
pdf_droppage(app->page);
app->page = nil;
@@ -241,7 +246,7 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage)
fz_droppixmap(app->image);
app->image = fz_newpixmapwithrect(pdf_devicergb, bbox);
fz_clearpixmap(app->image, 0xFF);
- idev = fz_newdrawdevice(app->image);
+ idev = fz_newdrawdevice(app->cache, app->image);
fz_executedisplaylist(list, idev, ctm);
fz_freedevice(idev);
diff --git a/apps/pdfapp.h b/apps/pdfapp.h
index d243dea1..1c80ee4a 100644
--- a/apps/pdfapp.h
+++ b/apps/pdfapp.h
@@ -27,6 +27,7 @@ struct pdfapp_s
pdf_xref *xref;
pdf_outline *outline;
int pagecount;
+ fz_glyphcache *cache;
/* current view params */
float zoom;
diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c
index 14ec4afd..8f840bd0 100644
--- a/apps/pdfdraw.c
+++ b/apps/pdfdraw.c
@@ -50,6 +50,7 @@ struct benchmark
int maxpage;
};
+static fz_glyphcache *drawcache = nil;
static int drawmode = DRAWPNM;
static char *drawpattern = nil;
static pdf_page *drawpage = nil;
@@ -67,6 +68,11 @@ static void local_cleanup(void)
pdf_dropstore(xref->store);
xref->store = nil;
}
+ if (drawcache)
+ {
+ fz_freeglyphcache(drawcache);
+ drawcache = nil;
+ }
}
static void drawusage(void)
@@ -216,7 +222,7 @@ static void drawpnm(int pagenum, struct benchmark *loadtimes, struct benchmark *
if (drawbands > 1)
fprintf(stdout, "drawing band %d / %d\n", b + 1, drawbands);
- dev = fz_newdrawdevice(pix);
+ dev = fz_newdrawdevice(drawcache, pix);
drawpage->contents->rp = drawpage->contents->bp;
error = pdf_runcontentstream(dev, ctm, xref, drawpage->resources, drawpage->contents);
if (error)
@@ -454,6 +460,8 @@ int main(int argc, char **argv)
if (fz_optind == argc)
drawusage();
+ drawcache = fz_newglyphcache(512, 512*512);
+
setcleanup(local_cleanup);
state = NO_FILE_OPENED;
diff --git a/fitz/dev_draw.c b/fitz/dev_draw.c
index 0b4bb970..dff1f840 100644
--- a/fitz/dev_draw.c
+++ b/fitz/dev_draw.c
@@ -715,21 +715,20 @@ fz_drawfreeuser(void *user)
fz_drawdevice *dev = user;
if (dev->model)
fz_dropcolorspace(dev->model);
- fz_freeglyphcache(dev->cache);
fz_freegel(dev->gel);
fz_freeael(dev->ael);
fz_free(dev);
}
fz_device *
-fz_newdrawdevice(fz_pixmap *dest)
+fz_newdrawdevice(fz_glyphcache *cache, fz_pixmap *dest)
{
fz_drawdevice *ddev = fz_malloc(sizeof(fz_drawdevice));
if (dest->colorspace)
ddev->model = fz_keepcolorspace(dest->colorspace);
else
ddev->model = nil;
- ddev->cache = fz_newglyphcache(512, 512 * 512);
+ ddev->cache = cache;
ddev->gel = fz_newgel();
ddev->ael = fz_newael();
ddev->dest = dest;
diff --git a/fitz/fitz_draw.h b/fitz/fitz_draw.h
index 389c9387..247488b6 100644
--- a/fitz/fitz_draw.h
+++ b/fitz/fitz_draw.h
@@ -1,12 +1,6 @@
-
-#define FZ_BYTE unsigned char
-
-#define FZ_PSRC \
- unsigned char *src, int srcw, int srch
-#define FZ_PDST \
- unsigned char *dst0, int dstw
-#define FZ_PCTM \
- int u0, int v0, int fa, int fb, int fc, int fd, int w0, int h
+/*
+ * Draw device and the graphics library.
+ */
typedef struct fz_glyph_s fz_glyph;
typedef struct fz_glyphcache_s fz_glyphcache;
@@ -18,6 +12,12 @@ void fz_renderglyph(fz_glyphcache*, fz_glyph*, fz_font*, int, fz_matrix);
void fz_debugglyphcache(fz_glyphcache *);
void fz_freeglyphcache(fz_glyphcache *);
+fz_device *fz_newdrawdevice(fz_glyphcache *cache, fz_pixmap *dest);
+
+/*
+ * Scan converter
+ */
+
typedef struct fz_edge_s fz_edge;
typedef struct fz_gel_s fz_gel;
typedef struct fz_ael_s fz_ael;
@@ -67,50 +67,56 @@ void fz_dashpath(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness, floa
* Function pointers -- they can be replaced by cpu-optimized versions
*/
-extern void (*fz_duff_non)(FZ_BYTE*,int,int,FZ_BYTE*,int,int,int);
-extern void (*fz_duff_nimcn)(FZ_BYTE*,int,int,FZ_BYTE*,int,int,FZ_BYTE*,int,int,int);
-extern void (*fz_duff_nimon)(FZ_BYTE*,int,int,FZ_BYTE*,int,int,FZ_BYTE*,int,int,int);
-extern void (*fz_duff_1o1)(FZ_BYTE*,int,FZ_BYTE*,int,int,int);
-extern void (*fz_duff_4o4)(FZ_BYTE*,int,FZ_BYTE*,int,int,int);
-extern void (*fz_duff_1i1c1)(FZ_BYTE*,int,FZ_BYTE*,int,FZ_BYTE*,int,int,int);
-extern void (*fz_duff_4i1c4)(FZ_BYTE*,int,FZ_BYTE*,int,FZ_BYTE*,int,int,int);
-extern void (*fz_duff_1i1o1)(FZ_BYTE*,int,FZ_BYTE*,int,FZ_BYTE*,int,int,int);
-extern void (*fz_duff_4i1o4)(FZ_BYTE*,int,FZ_BYTE*,int,FZ_BYTE*,int,int,int);
+#define FZ_PSRC \
+ unsigned char *src, int srcw, int srch
+#define FZ_PDST \
+ unsigned char *dst0, int dstw
+#define FZ_PCTM \
+ int u0, int v0, int fa, int fb, int fc, int fd, int w0, int h
+
+extern void fz_accelerate(void);
+
+extern void (*fz_duff_non)(unsigned char*,int,int,unsigned char*,int,int,int);
+extern void (*fz_duff_nimcn)(unsigned char*,int,int,unsigned char*,int,int,unsigned char*,int,int,int);
+extern void (*fz_duff_nimon)(unsigned char*,int,int,unsigned char*,int,int,unsigned char*,int,int,int);
+extern void (*fz_duff_1o1)(unsigned char*,int,unsigned char*,int,int,int);
+extern void (*fz_duff_4o4)(unsigned char*,int,unsigned char*,int,int,int);
+extern void (*fz_duff_1i1c1)(unsigned char*,int,unsigned char*,int,unsigned char*,int,int,int);
+extern void (*fz_duff_4i1c4)(unsigned char*,int,unsigned char*,int,unsigned char*,int,int,int);
+extern void (*fz_duff_1i1o1)(unsigned char*,int,unsigned char*,int,unsigned char*,int,int,int);
+extern void (*fz_duff_4i1o4)(unsigned char*,int,unsigned char*,int,unsigned char*,int,int,int);
-extern void (*fz_path_1c1)(FZ_BYTE*,unsigned char,int,FZ_BYTE*);
-extern void (*fz_path_1o1)(FZ_BYTE*,unsigned char,int,FZ_BYTE*);
-extern void (*fz_path_w4i1o4)(FZ_BYTE*,FZ_BYTE*,unsigned char,int,FZ_BYTE*);
+extern void (*fz_path_1c1)(unsigned char*,unsigned char,int,unsigned char*);
+extern void (*fz_path_1o1)(unsigned char*,unsigned char,int,unsigned char*);
+extern void (*fz_path_w4i1o4)(unsigned char*,unsigned char*,unsigned char,int,unsigned char*);
-extern void (*fz_text_1c1)(FZ_BYTE*,int,FZ_BYTE*,int,int,int);
-extern void (*fz_text_1o1)(FZ_BYTE*,int,FZ_BYTE*,int,int,int);
-extern void (*fz_text_w4i1o4)(FZ_BYTE*,FZ_BYTE*,int,FZ_BYTE*,int,int,int);
+extern void (*fz_text_1c1)(unsigned char*,int,unsigned char*,int,int,int);
+extern void (*fz_text_1o1)(unsigned char*,int,unsigned char*,int,int,int);
+extern void (*fz_text_w4i1o4)(unsigned char*,unsigned char*,int,unsigned char*,int,int,int);
extern void (*fz_img_ncn)(FZ_PSRC, int sn, FZ_PDST, FZ_PCTM);
extern void (*fz_img_1c1)(FZ_PSRC, FZ_PDST, FZ_PCTM);
extern void (*fz_img_4c4)(FZ_PSRC, FZ_PDST, FZ_PCTM);
extern void (*fz_img_1o1)(FZ_PSRC, FZ_PDST, FZ_PCTM);
extern void (*fz_img_4o4)(FZ_PSRC, FZ_PDST, FZ_PCTM);
-extern void (*fz_img_w4i1o4)(FZ_BYTE*,FZ_PSRC,FZ_PDST,FZ_PCTM);
+extern void (*fz_img_w4i1o4)(unsigned char*,FZ_PSRC,FZ_PDST,FZ_PCTM);
extern void (*fz_decodetile)(fz_pixmap *pix, int skip, float *decode);
-extern void (*fz_loadtile1)(FZ_BYTE*, int sw, FZ_BYTE*, int dw, int w, int h, int pad);
-extern void (*fz_loadtile2)(FZ_BYTE*, int sw, FZ_BYTE*, int dw, int w, int h, int pad);
-extern void (*fz_loadtile4)(FZ_BYTE*, int sw, FZ_BYTE*, int dw, int w, int h, int pad);
-extern void (*fz_loadtile8)(FZ_BYTE*, int sw, FZ_BYTE*, int dw, int w, int h, int pad);
-extern void (*fz_loadtile16)(FZ_BYTE*, int sw, FZ_BYTE*, int dw, int w, int h, int pad);
-
-extern void (*fz_srown)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom, int n);
-extern void (*fz_srow1)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom);
-extern void (*fz_srow2)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom);
-extern void (*fz_srow4)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom);
-extern void (*fz_srow5)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom);
-
-extern void (*fz_scoln)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom, int n);
-extern void (*fz_scol1)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom);
-extern void (*fz_scol2)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom);
-extern void (*fz_scol4)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom);
-extern void (*fz_scol5)(FZ_BYTE *src, FZ_BYTE *dst, int w, int denom);
-
-#undef FZ_BYTE
+extern void (*fz_loadtile1)(unsigned char*, int sw, unsigned char*, int dw, int w, int h, int pad);
+extern void (*fz_loadtile2)(unsigned char*, int sw, unsigned char*, int dw, int w, int h, int pad);
+extern void (*fz_loadtile4)(unsigned char*, int sw, unsigned char*, int dw, int w, int h, int pad);
+extern void (*fz_loadtile8)(unsigned char*, int sw, unsigned char*, int dw, int w, int h, int pad);
+extern void (*fz_loadtile16)(unsigned char*, int sw, unsigned char*, int dw, int w, int h, int pad);
+
+extern void (*fz_srown)(unsigned char *src, unsigned char *dst, int w, int denom, int n);
+extern void (*fz_srow1)(unsigned char *src, unsigned char *dst, int w, int denom);
+extern void (*fz_srow2)(unsigned char *src, unsigned char *dst, int w, int denom);
+extern void (*fz_srow4)(unsigned char *src, unsigned char *dst, int w, int denom);
+extern void (*fz_srow5)(unsigned char *src, unsigned char *dst, int w, int denom);
+
+extern void (*fz_scoln)(unsigned char *src, unsigned char *dst, int w, int denom, int n);
+extern void (*fz_scol1)(unsigned char *src, unsigned char *dst, int w, int denom);
+extern void (*fz_scol2)(unsigned char *src, unsigned char *dst, int w, int denom);
+extern void (*fz_scol4)(unsigned char *src, unsigned char *dst, int w, int denom);
+extern void (*fz_scol5)(unsigned char *src, unsigned char *dst, int w, int denom);
-extern void fz_accelerate(void);
diff --git a/fitz/fitz_res.h b/fitz/fitz_res.h
index de30f601..6311500b 100644
--- a/fitz/fitz_res.h
+++ b/fitz/fitz_res.h
@@ -97,8 +97,6 @@ void fz_freedevice(fz_device *dev);
fz_device *fz_newtracedevice(void);
-fz_device *fz_newdrawdevice(fz_pixmap *dest);
-
/* Text extraction device */
typedef struct fz_textspan_s fz_textspan;
@@ -225,7 +223,6 @@ fz_path *fz_clonepath(fz_path *old);
fz_rect fz_boundpath(fz_path *path, fz_matrix ctm, int dostroke);
void fz_debugpath(fz_path *, int indent);
-void fz_printpath(fz_path *, int indent);
/*
* Text buffer.
diff --git a/fitz/res_font.c b/fitz/res_font.c
index b7cc6cda..22e380cc 100644
--- a/fitz/res_font.c
+++ b/fitz/res_font.c
@@ -361,6 +361,7 @@ fz_rendert3glyph(fz_glyph *glyph, fz_font *font, int gid, fz_matrix trm)
fz_buffer *contents;
fz_rect bbox;
fz_device *dev;
+ fz_glyphcache *cache;
glyph->x = 0;
glyph->y = 0;
@@ -388,12 +389,14 @@ fz_rendert3glyph(fz_glyph *glyph, fz_font *font, int gid, fz_matrix trm)
pixmap = fz_newpixmap(nil, bbox.x0, bbox.y0, bbox.x1 - bbox.x0, bbox.y1 - bbox.y0);
fz_clearpixmap(pixmap, 0x00);
- dev = fz_newdrawdevice(pixmap);
+ cache = fz_newglyphcache(512, 512*512);
+ dev = fz_newdrawdevice(cache, pixmap);
contents->rp = contents->bp;
error = font->t3runcontentstream(dev, ctm, font->t3xref, font->t3resources, contents);
if (error)
fz_catch(error, "cannot draw type3 glyph");
fz_freedevice(dev);
+ fz_freeglyphcache(cache);
glyph->x = pixmap->x;
glyph->y = pixmap->y;