diff options
-rw-r--r-- | apps/pdfapp.c | 8 | ||||
-rw-r--r-- | apps/pdfapp.h | 1 | ||||
-rw-r--r-- | apps/pdfclean.c | 1 | ||||
-rw-r--r-- | apps/pdfdraw.c | 7 | ||||
-rw-r--r-- | apps/xpsdraw.c | 6 | ||||
-rw-r--r-- | draw/draw_device.c | 16 | ||||
-rw-r--r-- | draw/draw_glyph.c | 33 | ||||
-rw-r--r-- | fitz/base_context.c | 10 | ||||
-rw-r--r-- | fitz/fitz.h | 33 | ||||
-rw-r--r-- | fitz/res_font.c | 5 | ||||
-rw-r--r-- | ios/main.m | 7 | ||||
-rw-r--r-- | scripts/cmapdump.c | 4 |
12 files changed, 63 insertions, 68 deletions
diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 053d120d..5f7e79dc 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -196,8 +196,6 @@ void pdfapp_open(pdfapp_t *app, char *filename, int fd, int reload) else pdfapp_open_pdf(app, filename, fd); - app->cache = fz_new_glyph_cache(app->ctx); - if (app->pageno < 1) app->pageno = 1; if (app->pageno > app->pagecount) @@ -236,10 +234,6 @@ void pdfapp_close(pdfapp_t *app) fz_free(app->ctx, app->doctitle); app->doctitle = NULL; - if (app->cache) - fz_free_glyph_cache(app->ctx, app->cache); - app->cache = NULL; - if (app->image) fz_drop_pixmap(app->ctx, app->image); app->image = NULL; @@ -425,7 +419,7 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage, int repai #endif app->image = fz_new_pixmap_with_rect(app->ctx, colorspace, bbox); fz_clear_pixmap_with_color(app->image, 255); - idev = fz_new_draw_device(app->ctx, app->cache, app->image); + idev = fz_new_draw_device(app->ctx, app->image); fz_execute_display_list(app->page_list, idev, ctm, bbox, NULL); fz_free_device(idev); } diff --git a/apps/pdfapp.h b/apps/pdfapp.h index 22b6ad0d..84d00979 100644 --- a/apps/pdfapp.h +++ b/apps/pdfapp.h @@ -35,7 +35,6 @@ struct pdfapp_s xps_document *xps; int pagecount; - fz_glyph_cache *cache; /* current view params */ int resolution; diff --git a/apps/pdfclean.c b/apps/pdfclean.c index ed149268..583da83f 100644 --- a/apps/pdfclean.c +++ b/apps/pdfclean.c @@ -834,7 +834,6 @@ int main(int argc, char **argv) fz_free(xref->ctx, renumbermap); pdf_free_xref(xref); - fz_flush_warnings(ctx); fz_free_context(ctx); return 0; } diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c index ed10baa1..b0ed7707 100644 --- a/apps/pdfdraw.c +++ b/apps/pdfdraw.c @@ -27,7 +27,6 @@ static float gamma_value = 1; static int invert = 0; static fz_colorspace *colorspace; -static fz_glyph_cache *glyphcache; static char *filename; static struct { @@ -217,7 +216,7 @@ static void drawpage(pdf_xref *xref, int pagenum) else fz_clear_pixmap_with_color(pix, 255); - dev = fz_new_draw_device(ctx, glyphcache, pix); + dev = fz_new_draw_device(ctx, pix); if (list) fz_execute_display_list(list, dev, ctm, bbox, NULL); else @@ -440,8 +439,6 @@ int main(int argc, char **argv) fz_try(ctx) { - glyphcache = fz_new_glyph_cache(ctx); - while (fz_optind < argc) { filename = argv[fz_optind++]; @@ -489,8 +486,6 @@ int main(int argc, char **argv) printf("slowest page %d: %dms\n", timing.maxpage, timing.max); } - fz_free_glyph_cache(ctx, glyphcache); - fz_flush_warnings(ctx); fz_free_context(ctx); return 0; } diff --git a/apps/xpsdraw.c b/apps/xpsdraw.c index 04c43053..8509605c 100644 --- a/apps/xpsdraw.c +++ b/apps/xpsdraw.c @@ -19,7 +19,6 @@ int savealpha = 0; int uselist = 1; fz_colorspace *colorspace; -fz_glyph_cache *glyphcache; char *filename; fz_context *ctx; @@ -164,7 +163,7 @@ static void drawpage(xps_document *doc, int pagenum) else fz_clear_pixmap_with_color(pix, 255); - dev = fz_new_draw_device(doc->ctx, glyphcache, pix); + dev = fz_new_draw_device(doc->ctx, pix); if (list) fz_execute_display_list(list, dev, ctm, bbox, NULL); else @@ -327,8 +326,6 @@ int main(int argc, char **argv) exit(1); } - glyphcache = fz_new_glyph_cache(ctx); - colorspace = fz_device_rgb; if (grayscale) colorspace = fz_device_gray; @@ -388,7 +385,6 @@ int main(int argc, char **argv) printf("slowest page %d: %dms\n", timing.maxpage, timing.max); } - fz_free_glyph_cache(ctx, glyphcache); fz_free_context(ctx); return 0; diff --git a/draw/draw_device.c b/draw/draw_device.c index 07a2bb82..9a238b73 100644 --- a/draw/draw_device.c +++ b/draw/draw_device.c @@ -36,7 +36,6 @@ struct fz_draw_state_s { struct fz_draw_device_s { - fz_glyph_cache *cache; fz_gel *gel; fz_context *ctx; int flags; @@ -494,7 +493,7 @@ fz_draw_fill_text(fz_device *devp, fz_text *text, fz_matrix ctm, trm.e = QUANT(trm.e - floorf(trm.e), HSUBPIX); trm.f = QUANT(trm.f - floorf(trm.f), VSUBPIX); - glyph = fz_render_glyph(dev->ctx, dev->cache, text->font, gid, trm, model); + glyph = fz_render_glyph(dev->ctx, text->font, gid, trm, model); if (glyph) { if (glyph->n == 1) @@ -553,7 +552,7 @@ fz_draw_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke, fz_ trm.e = QUANT(trm.e - floorf(trm.e), HSUBPIX); trm.f = QUANT(trm.f - floorf(trm.f), VSUBPIX); - glyph = fz_render_stroked_glyph(dev->ctx, dev->cache, text->font, gid, trm, ctm, stroke); + glyph = fz_render_stroked_glyph(dev->ctx, text->font, gid, trm, ctm, stroke); if (glyph) { draw_glyph(colorbv, state->dest, glyph, x, y, state->scissor); @@ -645,7 +644,7 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, fz_matrix ctm, int accumulate) trm.e = QUANT(trm.e - floorf(trm.e), HSUBPIX); trm.f = QUANT(trm.f - floorf(trm.f), VSUBPIX); - glyph = fz_render_glyph(dev->ctx, dev->cache, text->font, gid, trm, model); + glyph = fz_render_glyph(dev->ctx, text->font, gid, trm, model); if (glyph) { draw_glyph(NULL, mask, glyph, x, y, bbox); @@ -711,7 +710,7 @@ fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke trm.e = QUANT(trm.e - floorf(trm.e), HSUBPIX); trm.f = QUANT(trm.f - floorf(trm.f), VSUBPIX); - glyph = fz_render_stroked_glyph(dev->ctx, dev->cache, text->font, gid, trm, ctm, stroke); + glyph = fz_render_stroked_glyph(dev->ctx, text->font, gid, trm, ctm, stroke); if (glyph) { draw_glyph(NULL, mask, glyph, x, y, bbox); @@ -1543,7 +1542,7 @@ fz_draw_free_user(fz_device *devp) } fz_device * -fz_new_draw_device(fz_context *ctx, fz_glyph_cache *cache, fz_pixmap *dest) +fz_new_draw_device(fz_context *ctx, fz_pixmap *dest) { fz_device *dev = NULL; fz_draw_device *ddev = fz_malloc_struct(ctx, fz_draw_device); @@ -1553,7 +1552,6 @@ fz_new_draw_device(fz_context *ctx, fz_glyph_cache *cache, fz_pixmap *dest) fz_var(dev); fz_try(ctx) { - ddev->cache = cache; ddev->gel = fz_new_gel(ctx); ddev->flags = 0; ddev->ctx = ctx; @@ -1609,9 +1607,9 @@ fz_new_draw_device(fz_context *ctx, fz_glyph_cache *cache, fz_pixmap *dest) } fz_device * -fz_new_draw_device_type3(fz_context *ctx, fz_glyph_cache *cache, fz_pixmap *dest) +fz_new_draw_device_type3(fz_context *ctx, fz_pixmap *dest) { - fz_device *dev = fz_new_draw_device(ctx, cache, dest); + fz_device *dev = fz_new_draw_device(ctx, dest); fz_draw_device *ddev = dev->user; ddev->flags |= FZ_DRAWDEV_FLAGS_TYPE3; return dev; diff --git a/draw/draw_glyph.c b/draw/draw_glyph.c index 6b83af74..ebda003e 100644 --- a/draw/draw_glyph.c +++ b/draw/draw_glyph.c @@ -21,8 +21,8 @@ struct fz_glyph_key_s unsigned char e, f; }; -fz_glyph_cache * -fz_new_glyph_cache(fz_context *ctx) +void +fz_new_glyph_cache_context(fz_context *ctx) { fz_glyph_cache *cache; @@ -38,12 +38,13 @@ fz_new_glyph_cache(fz_context *ctx) } cache->total = 0; - return cache; + ctx->glyph_cache = cache; } static void -fz_evict_glyph_cache(fz_context *ctx, fz_glyph_cache *cache) +fz_evict_glyph_cache(fz_context *ctx) { + fz_glyph_cache *cache = ctx->glyph_cache; fz_glyph_key *key; fz_pixmap *pixmap; int i; @@ -64,31 +65,37 @@ fz_evict_glyph_cache(fz_context *ctx, fz_glyph_cache *cache) } void -fz_free_glyph_cache(fz_context *ctx, fz_glyph_cache *cache) +fz_free_glyph_cache_context(fz_context *ctx) { - if (!cache) + if (!ctx->glyph_cache) return; - fz_evict_glyph_cache(ctx, cache); - fz_free_hash(cache->hash); - fz_free(ctx, cache); + fz_evict_glyph_cache(ctx); + fz_free_hash(ctx->glyph_cache->hash); + fz_free(ctx, ctx->glyph_cache); + ctx->glyph_cache = NULL; } fz_pixmap * -fz_render_stroked_glyph(fz_context *ctx, fz_glyph_cache *cache, fz_font *font, int gid, fz_matrix trm, fz_matrix ctm, fz_stroke_state *stroke) +fz_render_stroked_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, fz_matrix ctm, fz_stroke_state *stroke) { if (font->ft_face) return fz_render_ft_stroked_glyph(ctx, font, gid, trm, ctm, stroke); - return fz_render_glyph(ctx, cache, font, gid, trm, NULL); + return fz_render_glyph(ctx, font, gid, trm, NULL); } fz_pixmap * -fz_render_glyph(fz_context *ctx, fz_glyph_cache *cache, fz_font *font, int gid, fz_matrix ctm, fz_colorspace *model) +fz_render_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix ctm, fz_colorspace *model) { + fz_glyph_cache *cache; fz_glyph_key key; fz_pixmap *val; float size = fz_matrix_expansion(ctm); + if (!ctx->glyph_cache) + fz_new_glyph_cache_context(ctx); + cache = ctx->glyph_cache; + if (size > MAX_FONT_SIZE) { /* TODO: this case should be handled by rendering glyph as a path fill */ @@ -132,7 +139,7 @@ fz_render_glyph(fz_context *ctx, fz_glyph_cache *cache, fz_font *font, int gid, if (val->w < MAX_GLYPH_SIZE && val->h < MAX_GLYPH_SIZE) { if (cache->total + val->w * val->h > MAX_CACHE_SIZE) - fz_evict_glyph_cache(ctx, cache); + fz_evict_glyph_cache(ctx); fz_try(ctx) { fz_hash_insert(cache->hash, &key, val); diff --git a/fitz/base_context.c b/fitz/base_context.c index 218ce407..f77d3987 100644 --- a/fitz/base_context.c +++ b/fitz/base_context.c @@ -15,15 +15,21 @@ fz_free_context(fz_context *ctx) return; /* Other finalisation calls go here (in reverse order) */ + fz_free_glyph_cache_context(ctx); fz_free_store_context(ctx); fz_free_aa_context(ctx); fz_free_font_context(ctx); + if (ctx->warn) + { + fz_flush_warnings(ctx); + fz_free(ctx, ctx->warn); + } + if (ctx->error) { assert(ctx->error->top == -1); fz_free(ctx, ctx->error); - fz_free(ctx, ctx->warn); } /* Free the context itself */ @@ -46,6 +52,8 @@ fz_new_context(fz_alloc_context *alloc, unsigned int max_store) memset(ctx, 0, sizeof *ctx); ctx->alloc = alloc; + ctx->glyph_cache = NULL; + ctx->error = fz_malloc_no_throw(ctx, sizeof(fz_error_context)); if (!ctx->error) goto cleanup; diff --git a/fitz/fitz.h b/fitz/fitz.h index 9d6eb368..7bb12397 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -111,6 +111,7 @@ typedef struct fz_warn_context_s fz_warn_context; typedef struct fz_font_context_s fz_font_context; typedef struct fz_aa_context_s fz_aa_context; typedef struct fz_store_s fz_store; +typedef struct fz_glyph_cache_s fz_glyph_cache; typedef struct fz_context_s fz_context; struct fz_alloc_context_s @@ -365,6 +366,7 @@ struct fz_context_s fz_font_context *font; fz_aa_context *aa; fz_store *store; + fz_glyph_cache *glyph_cache; }; fz_context *fz_new_context(fz_alloc_context *alloc, unsigned int max_store); @@ -1138,6 +1140,19 @@ fz_rect fz_bound_path(fz_path *path, fz_stroke_state *stroke, fz_matrix ctm); void fz_debug_path(fz_path *, int indent); /* + * Glyph cache + */ + +void fz_new_glyph_cache_context(fz_context *ctx); +void fz_free_glyph_cache_context(fz_context *ctx); + +fz_pixmap *fz_render_ft_glyph(fz_context *ctx, fz_font *font, int cid, fz_matrix trm); +fz_pixmap *fz_render_t3_glyph(fz_context *ctx, fz_font *font, int cid, fz_matrix trm, fz_colorspace *model); +fz_pixmap *fz_render_ft_stroked_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, fz_matrix ctm, fz_stroke_state *state); +fz_pixmap *fz_render_glyph(fz_context *ctx, fz_font*, int, fz_matrix, fz_colorspace *model); +fz_pixmap *fz_render_stroked_glyph(fz_context *ctx, fz_font*, int, fz_matrix, fz_matrix, fz_stroke_state *stroke); + +/* * Text buffer. * * The trm field contains the a, b, c and d coefficients. @@ -1219,20 +1234,6 @@ fz_rect fz_bound_shade(fz_shade *shade, fz_matrix ctm); void fz_paint_shade(fz_context *ctx, fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox); /* - * Glyph cache - */ - -typedef struct fz_glyph_cache_s fz_glyph_cache; - -fz_glyph_cache *fz_new_glyph_cache(fz_context *ctx); -fz_pixmap *fz_render_ft_glyph(fz_context *ctx, fz_font *font, int cid, fz_matrix trm); -fz_pixmap *fz_render_t3_glyph(fz_context *ctx, fz_font *font, int cid, fz_matrix trm, fz_colorspace *model); -fz_pixmap *fz_render_ft_stroked_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, fz_matrix ctm, fz_stroke_state *state); -fz_pixmap *fz_render_glyph(fz_context *ctx, fz_glyph_cache*, fz_font*, int, fz_matrix, fz_colorspace *model); -fz_pixmap *fz_render_stroked_glyph(fz_context *ctx, fz_glyph_cache*, fz_font*, int, fz_matrix, fz_matrix, fz_stroke_state *stroke); -void fz_free_glyph_cache(fz_context *ctx, fz_glyph_cache *); - -/* * Scan converter */ @@ -1334,8 +1335,8 @@ void fz_free_device(fz_device *dev); fz_device *fz_new_trace_device(fz_context *ctx); fz_device *fz_new_bbox_device(fz_context *ctx, fz_bbox *bboxp); -fz_device *fz_new_draw_device(fz_context *ctx, fz_glyph_cache *cache, fz_pixmap *dest); -fz_device *fz_new_draw_device_type3(fz_context *ctx, fz_glyph_cache *cache, fz_pixmap *dest); +fz_device *fz_new_draw_device(fz_context *ctx, fz_pixmap *dest); +fz_device *fz_new_draw_device_type3(fz_context *ctx, fz_pixmap *dest); /* * Text extraction device diff --git a/fitz/res_font.c b/fitz/res_font.c index 79faa004..a851e3c7 100644 --- a/fitz/res_font.c +++ b/fitz/res_font.c @@ -623,7 +623,6 @@ fz_render_t3_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, fz_co fz_buffer *contents; fz_bbox bbox; fz_device *dev; - fz_glyph_cache *cache; fz_pixmap *glyph; fz_pixmap *result; @@ -666,12 +665,10 @@ fz_render_t3_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, fz_co glyph = fz_new_pixmap_with_rect(ctx, model ? model : fz_device_gray, bbox); fz_clear_pixmap(glyph); - cache = fz_new_glyph_cache(ctx); - dev = fz_new_draw_device_type3(ctx, cache, glyph); + dev = fz_new_draw_device_type3(ctx, glyph); font->t3run(font->t3xref, font->t3resources, contents, dev, ctm); /* RJW: "cannot draw type3 glyph" */ fz_free_device(dev); - fz_free_glyph_cache(ctx, cache); if (!model) { @@ -16,7 +16,6 @@ #define SEARCH_W (width - GAP - 170) static dispatch_queue_t queue; -static fz_glyph_cache *glyphcache = NULL; static float screenScale = 1; static fz_context *ctx = NULL; @@ -219,7 +218,7 @@ static UIImage *renderPage(struct document *doc, int number, CGSize screenSize) pix = fz_new_pixmap_with_rect(ctx, fz_device_rgb, bbox); fz_clear_pixmap_with_color(pix, 255); - dev = fz_new_draw_device(ctx, glyphcache, pix); + dev = fz_new_draw_device(ctx, pix); draw_page(doc, number, dev, ctm, NULL); fz_free_device(dev); @@ -256,7 +255,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize, pix = fz_new_pixmap_with_rect(ctx, fz_device_rgb, bbox); fz_clear_pixmap_with_color(pix, 255); - dev = fz_new_draw_device(ctx, glyphcache, pix); + dev = fz_new_draw_device(ctx, pix); draw_page(doc, number, dev, ctm, NULL); fz_free_device(dev); @@ -1388,8 +1387,6 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize, // use at most 128M for resource cache ctx = fz_new_context(NULL, 128<<20); - glyphcache = fz_new_glyph_cache(ctx); - screenScale = [[UIScreen mainScreen] scale]; library = [[MuLibraryController alloc] initWithStyle: UITableViewStylePlain]; diff --git a/scripts/cmapdump.c b/scripts/cmapdump.c index dc5d93e6..99983992 100644 --- a/scripts/cmapdump.c +++ b/scripts/cmapdump.c @@ -197,3 +197,7 @@ int fz_store_scavenge(fz_context *ctx, unsigned int size, int *phase) { return 0; } + +void fz_free_glyph_cache_context(fz_context *ctx) +{ +} |