diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2011-04-05 02:30:25 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2011-04-05 02:30:25 +0200 |
commit | 68f9077504d387a396efd0af6b8ee4147c3451f3 (patch) | |
tree | 085d376176b4fffa9ec59db7997a2bae7c62caa1 /fitz | |
parent | 61226c48df68fba170637f3b5ee654854d01c6ea (diff) | |
download | mupdf-68f9077504d387a396efd0af6b8ee4147c3451f3.tar.xz |
Add wrapper functions around device calls.
They test for NULL and make the code look nicer.
Diffstat (limited to 'fitz')
-rw-r--r-- | fitz/dev_draw.c | 12 | ||||
-rw-r--r-- | fitz/dev_null.c | 193 | ||||
-rw-r--r-- | fitz/fitz.h | 29 |
3 files changed, 173 insertions, 61 deletions
diff --git a/fitz/dev_draw.c b/fitz/dev_draw.c index e5078f49..05f96f28 100644 --- a/fitz/dev_draw.c +++ b/fitz/dev_draw.c @@ -45,7 +45,7 @@ fz_draw_fill_path(void *user, fz_path *path, int even_odd, fz_matrix ctm, int i; fz_reset_gel(dev->gel, dev->scissor); - fz_fill_path(dev->gel, path, ctm, flatness); + fz_flatten_fill_path(dev->gel, path, ctm, flatness); fz_sort_gel(dev->gel); bbox = fz_bound_gel(dev->gel); @@ -81,9 +81,9 @@ fz_draw_stroke_path(void *user, fz_path *path, fz_stroke_state *stroke, fz_matri fz_reset_gel(dev->gel, dev->scissor); if (stroke->dash_len > 0) - fz_dash_path(dev->gel, path, stroke, ctm, flatness, linewidth); + fz_flatten_dash_path(dev->gel, path, stroke, ctm, flatness, linewidth); else - fz_stroke_path(dev->gel, path, stroke, ctm, flatness, linewidth); + fz_flatten_stroke_path(dev->gel, path, stroke, ctm, flatness, linewidth); fz_sort_gel(dev->gel); bbox = fz_bound_gel(dev->gel); @@ -117,7 +117,7 @@ fz_draw_clip_path(void *user, fz_path *path, int even_odd, fz_matrix ctm) } fz_reset_gel(dev->gel, dev->scissor); - fz_fill_path(dev->gel, path, ctm, flatness); + fz_flatten_fill_path(dev->gel, path, ctm, flatness); fz_sort_gel(dev->gel); bbox = fz_bound_gel(dev->gel); @@ -171,9 +171,9 @@ fz_draw_clip_stroke_path(void *user, fz_path *path, fz_stroke_state *stroke, fz_ fz_reset_gel(dev->gel, dev->scissor); if (stroke->dash_len > 0) - fz_dash_path(dev->gel, path, stroke, ctm, flatness, linewidth); + fz_flatten_dash_path(dev->gel, path, stroke, ctm, flatness, linewidth); else - fz_stroke_path(dev->gel, path, stroke, ctm, flatness, linewidth); + fz_flatten_stroke_path(dev->gel, path, stroke, ctm, flatness, linewidth); fz_sort_gel(dev->gel); bbox = fz_bound_gel(dev->gel); diff --git a/fitz/dev_null.c b/fitz/dev_null.c index dcb43292..d351c0a0 100644 --- a/fitz/dev_null.c +++ b/fitz/dev_null.c @@ -1,71 +1,164 @@ #include "fitz.h" -static void fz_null_free_user(void *user) {} -static void fz_null_fill_path(void *user, fz_path *path, int even_odd, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha) {} -static void fz_null_stroke_path(void *user, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha) {} -static void fz_null_clip_path(void *user, fz_path *path, int even_odd, fz_matrix ctm) {} -static void fz_null_clip_stroke_path(void *user, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm) {} -static void fz_null_fill_text(void *user, fz_text *text, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha) {} -static void fz_null_stroke_text(void *user, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha) {} -static void fz_null_clip_text(void *user, fz_text *text, fz_matrix ctm, int accumulate) {} -static void fz_null_clip_stroke_text(void *user, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm) {} -static void fz_null_ignore_text(void *user, fz_text *text, fz_matrix ctm) {} -static void fz_null_pop_clip(void *user) {} -static void fz_null_fill_shade(void *user, fz_shade *shade, fz_matrix ctm, float alpha) {} -static void fz_null_fill_image(void *user, fz_pixmap *image, fz_matrix ctm, float alpha) {} -static void fz_null_fill_image_mask(void *user, fz_pixmap *image, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha) {} -static void fz_null_clip_image_mask(void *user, fz_pixmap *image, fz_matrix ctm) {} -static void fz_null_begin_mask(void *user, fz_rect r, int luminosity, fz_colorspace *colorspace, float *bc) {} -static void fz_null_end_mask(void *user) {} -static void fz_null_begin_group(void *user, fz_rect r, int isolated, int knockout, fz_blendmode blendmode, float alpha) {} -static void fz_null_end_group(void *user) {} -static void fz_null_begin_tile(void *user, fz_rect area, fz_rect view, float xstep, float ystep, fz_matrix ctm) {} -static void fz_null_end_tile(void *user) {} - fz_device * fz_new_device(void *user) { fz_device *dev = fz_malloc(sizeof(fz_device)); memset(dev, 0, sizeof(fz_device)); - dev->hints = 0; - dev->user = user; - dev->free_user = fz_null_free_user; + return dev; +} - dev->fill_path = fz_null_fill_path; - dev->stroke_path = fz_null_stroke_path; - dev->clip_path = fz_null_clip_path; - dev->clip_stroke_path = fz_null_clip_stroke_path; +void +fz_free_device(fz_device *dev) +{ + if (dev->free_user) + dev->free_user(dev->user); + fz_free(dev); +} - dev->fill_text = fz_null_fill_text; - dev->stroke_text = fz_null_stroke_text; - dev->clip_text = fz_null_clip_text; - dev->clip_stroke_text = fz_null_clip_stroke_text; - dev->ignore_text = fz_null_ignore_text; +void +fz_fill_path(fz_device *dev, fz_path *path, int even_odd, fz_matrix ctm, + fz_colorspace *colorspace, float *color, float alpha) +{ + if (dev->fill_path) + dev->fill_path(dev->user, path, even_odd, ctm, colorspace, color, alpha); +} - dev->fill_shade = fz_null_fill_shade; - dev->fill_image = fz_null_fill_image; - dev->fill_image_mask = fz_null_fill_image_mask; - dev->clip_image_mask = fz_null_clip_image_mask; +void +fz_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm, + fz_colorspace *colorspace, float *color, float alpha) +{ + if (dev->stroke_path) + dev->stroke_path(dev->user, path, stroke, ctm, colorspace, color, alpha); +} - dev->pop_clip = fz_null_pop_clip; +void +fz_clip_path(fz_device *dev, fz_path *path, int even_odd, fz_matrix ctm) +{ + if (dev->clip_path) + dev->clip_path(dev->user, path, even_odd, ctm); +} - dev->begin_mask = fz_null_begin_mask; - dev->end_mask = fz_null_end_mask; - dev->begin_group = fz_null_begin_group; - dev->end_group = fz_null_end_group; +void +fz_clip_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm) +{ + if (dev->clip_stroke_path) + dev->clip_stroke_path(dev->user, path, stroke, ctm); +} - dev->begin_tile = fz_null_begin_tile; - dev->end_tile = fz_null_end_tile; +void +fz_fill_text(fz_device *dev, fz_text *text, fz_matrix ctm, + fz_colorspace *colorspace, float *color, float alpha) +{ + if (dev->fill_text) + dev->fill_text(dev->user, text, ctm, colorspace, color, alpha); +} - return dev; +void +fz_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm, + fz_colorspace *colorspace, float *color, float alpha) +{ + if (dev->stroke_text) + dev->stroke_text(dev->user, text, stroke, ctm, colorspace, color, alpha); } void -fz_free_device(fz_device *dev) +fz_clip_text(fz_device *dev, fz_text *text, fz_matrix ctm, int accumulate) { - if (dev->free_user) - dev->free_user(dev->user); - fz_free(dev); + if (dev->clip_text) + dev->clip_text(dev->user, text, ctm, accumulate); +} + +void +fz_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm) +{ + if (dev->clip_stroke_text) + dev->clip_stroke_text(dev->user, text, stroke, ctm); +} + +void +fz_ignore_text(fz_device *dev, fz_text *text, fz_matrix ctm) +{ + if (dev->ignore_text) + dev->ignore_text(dev->user, text, ctm); +} + +void +fz_pop_clip(fz_device *dev) +{ + if (dev->pop_clip) + dev->pop_clip(dev->user); +} + +void +fz_fill_shade(fz_device *dev, fz_shade *shade, fz_matrix ctm, float alpha) +{ + if (dev->fill_shade) + dev->fill_shade(dev->user, shade, ctm, alpha); +} + +void +fz_fill_image(fz_device *dev, fz_pixmap *image, fz_matrix ctm, float alpha) +{ + if (dev->fill_image) + dev->fill_image(dev->user, image, ctm, alpha); +} + +void +fz_fill_image_mask(fz_device *dev, fz_pixmap *image, fz_matrix ctm, + fz_colorspace *colorspace, float *color, float alpha) +{ + if (dev->fill_image_mask) + dev->fill_image_mask(dev->user, image, ctm, colorspace, color, alpha); +} + +void +fz_clip_image_mask(fz_device *dev, fz_pixmap *image, fz_matrix ctm) +{ + if (dev->clip_image_mask) + dev->clip_image_mask(dev->user, image, ctm); +} + +void +fz_begin_mask(fz_device *dev, fz_rect area, int luminosity, fz_colorspace *colorspace, float *bc) +{ + if (dev->begin_mask) + dev->begin_mask(dev->user, area, luminosity, colorspace, bc); +} + +void +fz_end_mask(fz_device *dev) +{ + if (dev->end_mask) + dev->end_mask(dev->user); +} + +void +fz_begin_group(fz_device *dev, fz_rect area, int isolated, int knockout, fz_blendmode blendmode, float alpha) +{ + if (dev->begin_group) + dev->begin_group(dev->user, area, isolated, knockout, blendmode, alpha); +} + +void +fz_end_group(fz_device *dev) +{ + if (dev->end_group) + dev->end_group(dev->user); +} + +void +fz_begin_tile(fz_device *dev, fz_rect area, fz_rect view, float xstep, float ystep, fz_matrix ctm) +{ + if (dev->begin_tile) + dev->begin_tile(dev->user, area, view, xstep, ystep, ctm); +} + +void +fz_end_tile(fz_device *dev) +{ + if (dev->end_tile) + dev->end_tile(dev->user); } diff --git a/fitz/fitz.h b/fitz/fitz.h index c765da87..f0f3ecdb 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -978,9 +978,9 @@ void fz_free_ael(fz_ael *ael); fz_error fz_scan_convert(fz_gel *gel, fz_ael *ael, int eofill, fz_bbox clip, fz_pixmap *pix, unsigned char *colorbv); -void fz_fill_path(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness); -void fz_stroke_path(fz_gel *gel, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm, float flatness, float linewidth); -void fz_dash_path(fz_gel *gel, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm, float flatness, float linewidth); +void fz_flatten_fill_path(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness); +void fz_flatten_stroke_path(fz_gel *gel, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm, float flatness, float linewidth); +void fz_flatten_dash_path(fz_gel *gel, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm, float flatness, float linewidth); /* * The device interface. @@ -1028,13 +1028,32 @@ struct fz_device_s void (*end_tile)(void *); }; +void fz_fill_path(fz_device *dev, fz_path *path, int even_odd, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha); +void fz_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha); +void fz_clip_path(fz_device *dev, fz_path *path, int even_odd, fz_matrix ctm); +void fz_clip_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm); +void fz_fill_text(fz_device *dev, fz_text *text, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha); +void fz_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha); +void fz_clip_text(fz_device *dev, fz_text *text, fz_matrix ctm, int accumulate); +void fz_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm); +void fz_ignore_text(fz_device *dev, fz_text *text, fz_matrix ctm); +void fz_pop_clip(fz_device *dev); +void fz_fill_shade(fz_device *dev, fz_shade *shade, fz_matrix ctm, float alpha); +void fz_fill_image(fz_device *dev, fz_pixmap *image, fz_matrix ctm, float alpha); +void fz_fill_image_mask(fz_device *dev, fz_pixmap *image, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha); +void fz_clip_image_mask(fz_device *dev, fz_pixmap *image, fz_matrix ctm); +void fz_begin_mask(fz_device *dev, fz_rect area, int luminosity, fz_colorspace *colorspace, float *bc); +void fz_end_mask(fz_device *dev); +void fz_begin_group(fz_device *dev, fz_rect area, int isolated, int knockout, fz_blendmode blendmode, float alpha); +void fz_end_group(fz_device *dev); +void fz_begin_tile(fz_device *dev, fz_rect area, fz_rect view, float xstep, float ystep, fz_matrix ctm); +void fz_end_tile(fz_device *dev); + fz_device *fz_new_device(void *user); void fz_free_device(fz_device *dev); fz_device *fz_new_trace_device(void); - fz_device *fz_new_bbox_device(fz_bbox *bboxp); - fz_device *fz_new_draw_device(fz_glyph_cache *cache, fz_pixmap *dest); /* |