summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2015-02-17 14:41:50 +0100
committerTor Andersson <tor.andersson@artifex.com>2015-02-17 18:06:11 +0100
commit31186b61d979ba02c04ce68dcb66f7a5f1229c93 (patch)
tree84aa2debf18e6e4bab6c803e4b759b8851ce0ff4
parent72679561cddc6b2586e596f62492b79dcf9f118d (diff)
downloadmupdf-31186b61d979ba02c04ce68dcb66f7a5f1229c93.tar.xz
Use embedded superclass struct instead of user pointer in devices.
-rw-r--r--include/mupdf/fitz/device.h5
-rw-r--r--source/fitz/bbox-device.c108
-rw-r--r--source/fitz/device.c15
-rw-r--r--source/fitz/draw-device.c174
-rw-r--r--source/fitz/list-device.c105
-rw-r--r--source/fitz/stext-device.c67
-rw-r--r--source/fitz/svg-device.c119
-rw-r--r--source/fitz/test-device.c55
-rw-r--r--source/fitz/trace-device.c2
-rw-r--r--source/pdf/pdf-device.c148
10 files changed, 382 insertions, 416 deletions
diff --git a/include/mupdf/fitz/device.h b/include/mupdf/fitz/device.h
index fea65ff8..e8098502 100644
--- a/include/mupdf/fitz/device.h
+++ b/include/mupdf/fitz/device.h
@@ -99,8 +99,7 @@ struct fz_device_s
int hints;
int flags;
- void *user;
- void (*drop_user)(fz_context *, fz_device *);
+ void (*drop_imp)(fz_context *, fz_device *);
void (*begin_page)(fz_context *, fz_device *, const fz_rect *rect, const fz_matrix *ctm);
void (*end_page)(fz_context *, fz_device *);
@@ -164,7 +163,7 @@ void fz_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const f
int fz_begin_tile_id(fz_context *ctx, fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id);
void fz_end_tile(fz_context *ctx, fz_device *dev);
-fz_device *fz_new_device(fz_context *ctx, void *user);
+void *fz_new_device(fz_context *ctx, int size);
/*
fz_drop_device: Free a devices of any type and its resources.
diff --git a/source/fitz/bbox-device.c b/source/fitz/bbox-device.c
index b11a78a7..2c639499 100644
--- a/source/fitz/bbox-device.c
+++ b/source/fitz/bbox-device.c
@@ -2,32 +2,34 @@
#define STACK_SIZE 96
-typedef struct fz_bbox_data_s
+typedef struct fz_bbox_device_s
{
+ fz_device super;
+
fz_rect *result;
int top;
fz_rect stack[STACK_SIZE];
/* mask content and tiles are ignored */
int ignore;
-} fz_bbox_data;
+} fz_bbox_device;
static void
fz_bbox_add_rect(fz_context *ctx, fz_device *dev, const fz_rect *rect, int clip)
{
- fz_bbox_data *data = dev->user;
+ fz_bbox_device *bdev = (fz_bbox_device*)dev;
fz_rect r = *rect;
- if (0 < data->top && data->top <= STACK_SIZE)
+ if (0 < bdev->top && bdev->top <= STACK_SIZE)
{
- fz_intersect_rect(&r, &data->stack[data->top-1]);
+ fz_intersect_rect(&r, &bdev->stack[bdev->top-1]);
}
- if (!clip && data->top <= STACK_SIZE && !data->ignore)
+ if (!clip && bdev->top <= STACK_SIZE && !bdev->ignore)
{
- fz_union_rect(data->result, &r);
+ fz_union_rect(bdev->result, &r);
}
- if (clip && ++data->top <= STACK_SIZE)
+ if (clip && ++bdev->top <= STACK_SIZE)
{
- data->stack[data->top-1] = r;
+ bdev->stack[bdev->top-1] = r;
}
}
@@ -126,9 +128,9 @@ fz_bbox_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const
static void
fz_bbox_pop_clip(fz_context *ctx, fz_device *dev)
{
- fz_bbox_data *data = dev->user;
- if (data->top > 0)
- data->top--;
+ fz_bbox_device *bdev = (fz_bbox_device*)dev;
+ if (bdev->top > 0)
+ bdev->top--;
else
fz_warn(ctx, "unexpected pop clip");
}
@@ -136,17 +138,17 @@ fz_bbox_pop_clip(fz_context *ctx, fz_device *dev)
static void
fz_bbox_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *rect, int luminosity, fz_colorspace *colorspace, float *color)
{
- fz_bbox_data *data = dev->user;
+ fz_bbox_device *bdev = (fz_bbox_device*)dev;
fz_bbox_add_rect(ctx, dev, rect, 1);
- data->ignore++;
+ bdev->ignore++;
}
static void
fz_bbox_end_mask(fz_context *ctx, fz_device *dev)
{
- fz_bbox_data *data = dev->user;
- assert(data->ignore > 0);
- data->ignore--;
+ fz_bbox_device *bdev = (fz_bbox_device*)dev;
+ assert(bdev->ignore > 0);
+ bdev->ignore--;
}
static void
@@ -164,68 +166,66 @@ fz_bbox_end_group(fz_context *ctx, fz_device *dev)
static int
fz_bbox_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id)
{
- fz_bbox_data *data = dev->user;
+ fz_bbox_device *bdev = (fz_bbox_device*)dev;
fz_rect r = *area;
fz_bbox_add_rect(ctx, dev, fz_transform_rect(&r, ctm), 0);
- data->ignore++;
+ bdev->ignore++;
return 0;
}
static void
fz_bbox_end_tile(fz_context *ctx, fz_device *dev)
{
- fz_bbox_data *data = dev->user;
- assert(data->ignore > 0);
- data->ignore--;
+ fz_bbox_device *bdev = (fz_bbox_device*)dev;
+ assert(bdev->ignore > 0);
+ bdev->ignore--;
}
static void
-fz_bbox_drop_user(fz_context *ctx, fz_device *dev)
+fz_bbox_drop_imp(fz_context *ctx, fz_device *dev)
{
- fz_bbox_data *data = dev->user;
- if (data->top > 0)
- fz_warn(ctx, "items left on stack in bbox device: %d", data->top);
- fz_free(ctx, dev->user);
+ fz_bbox_device *bdev = (fz_bbox_device*)dev;
+ if (bdev->top > 0)
+ fz_warn(ctx, "items left on stack in bbox device: %d", bdev->top);
}
fz_device *
fz_new_bbox_device(fz_context *ctx, fz_rect *result)
{
- fz_device *dev;
+ fz_bbox_device *dev = fz_new_device(ctx, sizeof *dev);
+
+ dev->super.drop_imp = fz_bbox_drop_imp;
- fz_bbox_data *user = fz_malloc_struct(ctx, fz_bbox_data);
- user->result = result;
- user->top = 0;
- user->ignore = 0;
- dev = fz_new_device(ctx, user);
- dev->drop_user = fz_bbox_drop_user;
+ dev->super.fill_path = fz_bbox_fill_path;
+ dev->super.stroke_path = fz_bbox_stroke_path;
+ dev->super.clip_path = fz_bbox_clip_path;
+ dev->super.clip_stroke_path = fz_bbox_clip_stroke_path;
- dev->fill_path = fz_bbox_fill_path;
- dev->stroke_path = fz_bbox_stroke_path;
- dev->clip_path = fz_bbox_clip_path;
- dev->clip_stroke_path = fz_bbox_clip_stroke_path;
+ dev->super.fill_text = fz_bbox_fill_text;
+ dev->super.stroke_text = fz_bbox_stroke_text;
+ dev->super.clip_text = fz_bbox_clip_text;
+ dev->super.clip_stroke_text = fz_bbox_clip_stroke_text;
- dev->fill_text = fz_bbox_fill_text;
- dev->stroke_text = fz_bbox_stroke_text;
- dev->clip_text = fz_bbox_clip_text;
- dev->clip_stroke_text = fz_bbox_clip_stroke_text;
+ dev->super.fill_shade = fz_bbox_fill_shade;
+ dev->super.fill_image = fz_bbox_fill_image;
+ dev->super.fill_image_mask = fz_bbox_fill_image_mask;
+ dev->super.clip_image_mask = fz_bbox_clip_image_mask;
- dev->fill_shade = fz_bbox_fill_shade;
- dev->fill_image = fz_bbox_fill_image;
- dev->fill_image_mask = fz_bbox_fill_image_mask;
- dev->clip_image_mask = fz_bbox_clip_image_mask;
+ dev->super.pop_clip = fz_bbox_pop_clip;
- dev->pop_clip = fz_bbox_pop_clip;
+ dev->super.begin_mask = fz_bbox_begin_mask;
+ dev->super.end_mask = fz_bbox_end_mask;
+ dev->super.begin_group = fz_bbox_begin_group;
+ dev->super.end_group = fz_bbox_end_group;
- dev->begin_mask = fz_bbox_begin_mask;
- dev->end_mask = fz_bbox_end_mask;
- dev->begin_group = fz_bbox_begin_group;
- dev->end_group = fz_bbox_end_group;
+ dev->super.begin_tile = fz_bbox_begin_tile;
+ dev->super.end_tile = fz_bbox_end_tile;
- dev->begin_tile = fz_bbox_begin_tile;
- dev->end_tile = fz_bbox_end_tile;
+ dev->result = result;
+ dev->top = 0;
+ dev->ignore = 0;
*result = fz_empty_rect;
- return dev;
+ return (fz_device*)dev;
}
diff --git a/source/fitz/device.c b/source/fitz/device.c
index 36a0f534..cb622a84 100644
--- a/source/fitz/device.c
+++ b/source/fitz/device.c
@@ -1,14 +1,9 @@
#include "mupdf/fitz.h"
-fz_device *
-fz_new_device(fz_context *ctx, void *user)
+void *
+fz_new_device(fz_context *ctx, int size)
{
- fz_device *dev = fz_malloc_struct(ctx, fz_device);
- dev->hints = 0;
- dev->flags = 0;
- dev->user = user;
- dev->error_depth = 0;
- return dev;
+ return Memento_label(fz_calloc(ctx, 1, size), "fz_device");
}
void
@@ -16,8 +11,8 @@ fz_drop_device(fz_context *ctx, fz_device *dev)
{
if (dev == NULL)
return;
- if (dev->drop_user)
- dev->drop_user(ctx, dev);
+ if (dev->drop_imp)
+ dev->drop_imp(ctx, dev);
fz_free(ctx, dev->container);
fz_free(ctx, dev);
}
diff --git a/source/fitz/draw-device.c b/source/fitz/draw-device.c
index 1c093fc6..fad44050 100644
--- a/source/fitz/draw-device.c
+++ b/source/fitz/draw-device.c
@@ -37,6 +37,7 @@ struct fz_draw_state_s {
struct fz_draw_device_s
{
+ fz_device super;
fz_gel *gel;
int flags;
int top;
@@ -268,7 +269,7 @@ static void
fz_draw_fill_path(fz_context *ctx, fz_device *devp, fz_path *path, int even_odd, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
fz_gel *gel = dev->gel;
float expansion = fz_matrix_expansion(ctm);
@@ -322,7 +323,7 @@ static void
fz_draw_stroke_path(fz_context *ctx, fz_device *devp, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
fz_gel *gel = dev->gel;
float expansion = fz_matrix_expansion(ctm);
@@ -384,7 +385,7 @@ fz_draw_stroke_path(fz_context *ctx, fz_device *devp, fz_path *path, fz_stroke_s
static void
fz_draw_clip_path(fz_context *ctx, fz_device *devp, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
fz_gel *gel = dev->gel;
float expansion = fz_matrix_expansion(ctm);
@@ -450,7 +451,7 @@ fz_draw_clip_path(fz_context *ctx, fz_device *devp, fz_path *path, const fz_rect
static void
fz_draw_clip_stroke_path(fz_context *ctx, fz_device *devp, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
fz_gel *gel = dev->gel;
float expansion = fz_matrix_expansion(ctm);
@@ -562,7 +563,7 @@ static void
fz_draw_fill_text(fz_context *ctx, fz_device *devp, fz_text *text, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
unsigned char colorbv[FZ_MAX_COLORS + 1];
unsigned char shapebv;
@@ -639,7 +640,7 @@ fz_draw_stroke_text(fz_context *ctx, fz_device *devp, fz_text *text, fz_stroke_s
const fz_matrix *ctm, fz_colorspace *colorspace,
float *color, float alpha)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
unsigned char colorbv[FZ_MAX_COLORS + 1];
float colorfv[FZ_MAX_COLORS];
@@ -701,7 +702,7 @@ fz_draw_stroke_text(fz_context *ctx, fz_device *devp, fz_text *text, fz_stroke_s
static void
fz_draw_clip_text(fz_context *ctx, fz_device *devp, fz_text *text, const fz_matrix *ctm, int accumulate)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
fz_irect bbox;
fz_pixmap *mask, *dest, *shape;
fz_matrix tm, trm;
@@ -833,7 +834,7 @@ fz_draw_clip_text(fz_context *ctx, fz_device *devp, fz_text *text, const fz_matr
static void
fz_draw_clip_stroke_text(fz_context *ctx, fz_device *devp, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
fz_irect bbox;
fz_pixmap *mask, *dest, *shape;
fz_matrix tm, trm;
@@ -941,7 +942,7 @@ fz_draw_ignore_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_mat
static void
fz_draw_fill_shade(fz_context *ctx, fz_device *devp, fz_shade *shade, const fz_matrix *ctm, float alpha)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
fz_rect bounds;
fz_irect bbox, scissor;
fz_pixmap *dest, *shape;
@@ -1089,7 +1090,7 @@ fz_transform_pixmap(fz_context *ctx, fz_draw_device *dev, fz_pixmap *image, fz_m
static void
fz_draw_fill_image(fz_context *ctx, fz_device *devp, fz_image *image, const fz_matrix *ctm, float alpha)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
fz_pixmap *converted = NULL;
fz_pixmap *scaled = NULL;
fz_pixmap *pixmap;
@@ -1196,7 +1197,7 @@ static void
fz_draw_fill_image_mask(fz_context *ctx, fz_device *devp, fz_image *image, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
unsigned char colorbv[FZ_MAX_COLORS + 1];
float colorfv[FZ_MAX_COLORS];
fz_pixmap *scaled = NULL;
@@ -1267,7 +1268,7 @@ fz_draw_fill_image_mask(fz_context *ctx, fz_device *devp, fz_image *image, const
static void
fz_draw_clip_image_mask(fz_context *ctx, fz_device *devp, fz_image *image, const fz_rect *rect, const fz_matrix *ctm)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
fz_irect bbox;
fz_pixmap *mask = NULL;
fz_pixmap *dest = NULL;
@@ -1368,7 +1369,7 @@ fz_draw_clip_image_mask(fz_context *ctx, fz_device *devp, fz_image *image, const
static void
fz_draw_pop_clip(fz_context *ctx, fz_device *devp)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
fz_draw_state *state;
if (dev->top == 0)
@@ -1425,7 +1426,7 @@ fz_draw_pop_clip(fz_context *ctx, fz_device *devp)
static void
fz_draw_begin_mask(fz_context *ctx, fz_device *devp, const fz_rect *rect, int luminosity, fz_colorspace *colorspace, float *colorfv)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
fz_pixmap *dest;
fz_irect bbox;
fz_draw_state *state = push_stack(ctx, dev);
@@ -1480,7 +1481,7 @@ fz_draw_begin_mask(fz_context *ctx, fz_device *devp, const fz_rect *rect, int lu
static void
fz_draw_end_mask(fz_context *ctx, fz_device *devp)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
fz_pixmap *temp, *dest;
fz_irect bbox;
int luminosity;
@@ -1539,7 +1540,7 @@ fz_draw_end_mask(fz_context *ctx, fz_device *devp)
static void
fz_draw_begin_group(fz_context *ctx, fz_device *devp, const fz_rect *rect, int isolated, int knockout, int blendmode, float alpha)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
fz_irect bbox;
fz_pixmap *dest;
fz_draw_state *state = &dev->stack[dev->top];
@@ -1599,7 +1600,7 @@ fz_draw_begin_group(fz_context *ctx, fz_device *devp, const fz_rect *rect, int i
static void
fz_draw_end_group(fz_context *ctx, fz_device *devp)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
int blendmode;
int isolated;
float alpha;
@@ -1766,7 +1767,7 @@ fz_tile_size(fz_context *ctx, tile_record *tile)
static int
fz_draw_begin_tile(fz_context *ctx, fz_device *devp, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
fz_pixmap *dest = NULL;
fz_pixmap *shape;
fz_irect bbox;
@@ -1856,7 +1857,7 @@ fz_draw_begin_tile(fz_context *ctx, fz_device *devp, const fz_rect *area, const
static void
fz_draw_end_tile(fz_context *ctx, fz_device *devp)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
float xstep, ystep;
fz_matrix ttm, ctm, shapectm;
fz_irect area, scissor;
@@ -2011,9 +2012,9 @@ fz_draw_end_tile(fz_context *ctx, fz_device *devp)
}
static void
-fz_draw_drop_user(fz_context *ctx, fz_device *devp)
+fz_draw_drop_imp(fz_context *ctx, fz_device *devp)
{
- fz_draw_device *dev = devp->user;
+ fz_draw_device *dev = (fz_draw_device*)devp;
fz_gel *gel = dev->gel;
/* pop and free the stacks */
@@ -2039,99 +2040,92 @@ fz_draw_drop_user(fz_context *ctx, fz_device *devp)
fz_drop_scale_cache(ctx, dev->cache_x);
fz_drop_scale_cache(ctx, dev->cache_y);
fz_drop_gel(ctx, gel);
- fz_free(ctx, dev);
}
fz_device *
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);
+ fz_draw_device *dev = fz_new_device(ctx, sizeof *dev);
+
+ dev->super.drop_imp = fz_draw_drop_imp;
+
+ dev->super.fill_path = fz_draw_fill_path;
+ dev->super.stroke_path = fz_draw_stroke_path;
+ dev->super.clip_path = fz_draw_clip_path;
+ dev->super.clip_stroke_path = fz_draw_clip_stroke_path;
+
+ dev->super.fill_text = fz_draw_fill_text;
+ dev->super.stroke_text = fz_draw_stroke_text;
+ dev->super.clip_text = fz_draw_clip_text;
+ dev->super.clip_stroke_text = fz_draw_clip_stroke_text;
+ dev->super.ignore_text = fz_draw_ignore_text;
+
+ dev->super.fill_image_mask = fz_draw_fill_image_mask;
+ dev->super.clip_image_mask = fz_draw_clip_image_mask;
+ dev->super.fill_image = fz_draw_fill_image;
+ dev->super.fill_shade = fz_draw_fill_shade;
+
+ dev->super.pop_clip = fz_draw_pop_clip;
+
+ dev->super.begin_mask = fz_draw_begin_mask;
+ dev->super.end_mask = fz_draw_end_mask;
+ dev->super.begin_group = fz_draw_begin_group;
+ dev->super.end_group = fz_draw_end_group;
+
+ dev->super.begin_tile = fz_draw_begin_tile;
+ dev->super.end_tile = fz_draw_end_tile;
+
+ dev->flags = 0;
+ dev->top = 0;
+ dev->stack = &dev->init_stack[0];
+ dev->stack_cap = STACK_SIZE;
+ dev->stack[0].dest = dest;
+ dev->stack[0].shape = NULL;
+ dev->stack[0].mask = NULL;
+ dev->stack[0].blendmode = 0;
+ dev->stack[0].scissor.x0 = dest->x;
+ dev->stack[0].scissor.y0 = dest->y;
+ dev->stack[0].scissor.x1 = dest->x + dest->w;
+ dev->stack[0].scissor.y1 = dest->y + dest->h;
- fz_var(dev);
fz_try(ctx)
{
- ddev->gel = fz_new_gel(ctx);
- ddev->flags = 0;
- ddev->top = 0;
- ddev->cache_x = fz_new_scale_cache(ctx);
- ddev->cache_y = fz_new_scale_cache(ctx);
- ddev->stack = &ddev->init_stack[0];
- ddev->stack_cap = STACK_SIZE;
- ddev->stack[0].dest = dest;
- ddev->stack[0].shape = NULL;
- ddev->stack[0].mask = NULL;
- ddev->stack[0].blendmode = 0;
- ddev->stack[0].scissor.x0 = dest->x;
- ddev->stack[0].scissor.y0 = dest->y;
- ddev->stack[0].scissor.x1 = dest->x + dest->w;
- ddev->stack[0].scissor.y1 = dest->y + dest->h;
-
- dev = fz_new_device(ctx, ddev);
+ dev->gel = fz_new_gel(ctx);
+ dev->cache_x = fz_new_scale_cache(ctx);
+ dev->cache_y = fz_new_scale_cache(ctx);
}
fz_catch(ctx)
{
- fz_drop_scale_cache(ctx, ddev->cache_x);
- fz_drop_scale_cache(ctx, ddev->cache_y);
- fz_drop_gel(ctx, ddev->gel);
- fz_free(ctx, ddev);
+ fz_drop_device(ctx, (fz_device*)dev);
fz_rethrow(ctx);
}
- dev->drop_user = fz_draw_drop_user;
- dev->fill_path = fz_draw_fill_path;
- dev->stroke_path = fz_draw_stroke_path;
- dev->clip_path = fz_draw_clip_path;
- dev->clip_stroke_path = fz_draw_clip_stroke_path;
-
- dev->fill_text = fz_draw_fill_text;
- dev->stroke_text = fz_draw_stroke_text;
- dev->clip_text = fz_draw_clip_text;
- dev->clip_stroke_text = fz_draw_clip_stroke_text;
- dev->ignore_text = fz_draw_ignore_text;
-
- dev->fill_image_mask = fz_draw_fill_image_mask;
- dev->clip_image_mask = fz_draw_clip_image_mask;
- dev->fill_image = fz_draw_fill_image;
- dev->fill_shade = fz_draw_fill_shade;
-
- dev->pop_clip = fz_draw_pop_clip;
-
- dev->begin_mask = fz_draw_begin_mask;
- dev->end_mask = fz_draw_end_mask;
- dev->begin_group = fz_draw_begin_group;
- dev->end_group = fz_draw_end_group;
-
- dev->begin_tile = fz_draw_begin_tile;
- dev->end_tile = fz_draw_end_tile;
-
- return dev;
+ return (fz_device*)dev;
}
fz_device *
fz_new_draw_device_with_bbox(fz_context *ctx, fz_pixmap *dest, const fz_irect *clip)
{
- fz_device *dev = fz_new_draw_device(ctx, dest);
- fz_draw_device *ddev = dev->user;
-
- if (clip->x0 > ddev->stack[0].scissor.x0)
- ddev->stack[0].scissor.x0 = clip->x0;
- if (clip->x1 < ddev->stack[0].scissor.x1)
- ddev->stack[0].scissor.x1 = clip->x1;
- if (clip->y0 > ddev->stack[0].scissor.y0)
- ddev->stack[0].scissor.y0 = clip->y0;
- if (clip->y1 < ddev->stack[0].scissor.y1)
- ddev->stack[0].scissor.y1 = clip->y1;
- return dev;
+ fz_draw_device *dev = (fz_draw_device*)fz_new_draw_device(ctx, dest);
+
+ if (clip->x0 > dev->stack[0].scissor.x0)
+ dev->stack[0].scissor.x0 = clip->x0;
+ if (clip->x1 < dev->stack[0].scissor.x1)
+ dev->stack[0].scissor.x1 = clip->x1;
+ if (clip->y0 > dev->stack[0].scissor.y0)
+ dev->stack[0].scissor.y0 = clip->y0;
+ if (clip->y1 < dev->stack[0].scissor.y1)
+ dev->stack[0].scissor.y1 = clip->y1;
+
+ return (fz_device*)dev;
}
fz_device *
fz_new_draw_device_type3(fz_context *ctx, fz_pixmap *dest)
{
- fz_device *dev = fz_new_draw_device(ctx, dest);
- fz_draw_device *ddev = dev->user;
- ddev->flags |= FZ_DRAWDEV_FLAGS_TYPE3;
- return dev;
+ fz_draw_device *dev = (fz_draw_device*)fz_new_draw_device(ctx, dest);
+ dev->flags |= FZ_DRAWDEV_FLAGS_TYPE3;
+ return (fz_device*)dev;
}
fz_irect *
diff --git a/source/fitz/list-device.c b/source/fitz/list-device.c
index f56bc879..72a63ef4 100644
--- a/source/fitz/list-device.c
+++ b/source/fitz/list-device.c
@@ -2,6 +2,12 @@
typedef struct fz_display_node_s fz_display_node;
+typedef struct fz_list_device_s
+{
+ fz_device super;
+ fz_display_list *list;
+} fz_list_device;
+
#define STACK_SIZE 96
typedef enum fz_display_command_e
@@ -101,8 +107,11 @@ fz_new_display_node(fz_context *ctx, fz_display_command cmd, const fz_matrix *ct
}
static void
-fz_append_display_node(fz_display_list *list, fz_display_node *node)
+fz_append_display_node(fz_context *ctx, fz_device *dev_, fz_display_node *node)
{
+ fz_list_device *dev = (fz_list_device*)dev_;
+ fz_display_list *list = dev->list;
+
switch (node->cmd)
{
case FZ_CMD_CLIP_PATH:
@@ -234,14 +243,14 @@ fz_list_begin_page(fz_context *ctx, fz_device *dev, const fz_rect *mediabox, con
fz_display_node *node = fz_new_display_node(ctx, FZ_CMD_BEGIN_PAGE, ctm, NULL, NULL, 0);
node->rect = *mediabox;
fz_transform_rect(&node->rect, ctm);
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
fz_list_end_page(fz_context *ctx, fz_device *dev)
{
fz_display_node *node = fz_new_display_node(ctx, FZ_CMD_END_PAGE, &fz_identity, NULL, NULL, 0);
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -261,7 +270,7 @@ fz_list_fill_path(fz_context *ctx, fz_device *dev, fz_path *path, int even_odd,
fz_free_display_node(ctx, node);
fz_rethrow(ctx);
}
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -281,7 +290,7 @@ fz_list_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, fz_stroke_st
fz_free_display_node(ctx, node);
fz_rethrow(ctx);
}
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -302,7 +311,7 @@ fz_list_clip_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect
fz_free_display_node(ctx, node);
fz_rethrow(ctx);
}
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -323,7 +332,7 @@ fz_list_clip_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, const f
fz_free_display_node(ctx, node);
fz_rethrow(ctx);
}
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -342,7 +351,7 @@ fz_list_fill_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matri
fz_free_display_node(ctx, node);
fz_rethrow(ctx);
}
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -363,7 +372,7 @@ fz_list_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_st
fz_free_display_node(ctx, node);
fz_rethrow(ctx);
}
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -385,7 +394,7 @@ fz_list_clip_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matri
fz_free_display_node(ctx, node);
fz_rethrow(ctx);
}
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -404,7 +413,7 @@ fz_list_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stro
fz_free_display_node(ctx, node);
fz_rethrow(ctx);
}
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -422,7 +431,7 @@ fz_list_ignore_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_mat
fz_free_display_node(ctx, node);
fz_rethrow(ctx);
}
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -430,7 +439,7 @@ fz_list_pop_clip(fz_context *ctx, fz_device *dev)
{
fz_display_node *node;
node = fz_new_display_node(ctx, FZ_CMD_POP_CLIP, &fz_identity, NULL, NULL, 0);
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -440,7 +449,7 @@ fz_list_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_ma
node = fz_new_display_node(ctx, FZ_CMD_FILL_SHADE, ctm, NULL, NULL, alpha);
fz_bound_shade(ctx, shade, ctm, &node->rect);
node->item.shade = fz_keep_shade(ctx, shade);
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -451,7 +460,7 @@ fz_list_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_ma
node->rect = fz_unit_rect;
fz_transform_rect(&node->rect, ctm);
node->item.image = fz_keep_image(ctx, image);
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -463,7 +472,7 @@ fz_list_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const
node->rect = fz_unit_rect;
fz_transform_rect(&node->rect, ctm);
node->item.image = fz_keep_image(ctx, image);
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -476,7 +485,7 @@ fz_list_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const
if (rect)
fz_intersect_rect(&node->rect, rect);
node->item.image = fz_keep_image(ctx, image);
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -486,7 +495,7 @@ fz_list_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *rect, int lum
node = fz_new_display_node(ctx, FZ_CMD_BEGIN_MASK, &fz_identity, colorspace, color, 0);
node->rect = *rect;
node->flag = luminosity;
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -494,7 +503,7 @@ fz_list_end_mask(fz_context *ctx, fz_device *dev)
{
fz_display_node *node;
node = fz_new_display_node(ctx, FZ_CMD_END_MASK, &fz_identity, NULL, NULL, 0);
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -506,7 +515,7 @@ fz_list_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *rect, int is
node->item.blendmode = blendmode;
node->flag |= isolated ? ISOLATED : 0;
node->flag |= knockout ? KNOCKOUT : 0;
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static void
@@ -514,7 +523,7 @@ fz_list_end_group(fz_context *ctx, fz_device *dev)
{
fz_display_node *node;
node = fz_new_display_node(ctx, FZ_CMD_END_GROUP, &fz_identity, NULL, NULL, 0);
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
static int
@@ -530,7 +539,7 @@ fz_list_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const f
node->color[3] = view->y0;
node->color[4] = view->x1;
node->color[5] = view->y1;
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
return 0;
}
@@ -539,44 +548,46 @@ fz_list_end_tile(fz_context *ctx, fz_device *dev)
{
fz_display_node *node;
node = fz_new_display_node(ctx, FZ_CMD_END_TILE, &fz_identity, NULL, NULL, 0);
- fz_append_display_node(dev->user, node);
+ fz_append_display_node(ctx, dev, node);
}
fz_device *
fz_new_list_device(fz_context *ctx, fz_display_list *list)
{
- fz_device *dev = fz_new_device(ctx, list);
+ fz_list_device *dev = fz_new_device(ctx, sizeof *dev);
+
+ dev->super.begin_page = fz_list_begin_page;
+ dev->super.end_page = fz_list_end_page;
- dev->begin_page = fz_list_begin_page;
- dev->end_page = fz_list_end_page;
+ dev->super.fill_path = fz_list_fill_path;
+ dev->super.stroke_path = fz_list_stroke_path;
+ dev->super.clip_path = fz_list_clip_path;
+ dev->super.clip_stroke_path = fz_list_clip_stroke_path;
- dev->fill_path = fz_list_fill_path;
- dev->stroke_path = fz_list_stroke_path;
- dev->clip_path = fz_list_clip_path;
- dev->clip_stroke_path = fz_list_clip_stroke_path;
+ dev->super.fill_text = fz_list_fill_text;
+ dev->super.stroke_text = fz_list_stroke_text;
+ dev->super.clip_text = fz_list_clip_text;
+ dev->super.clip_stroke_text = fz_list_clip_stroke_text;
+ dev->super.ignore_text = fz_list_ignore_text;
- dev->fill_text = fz_list_fill_text;
- dev->stroke_text = fz_list_stroke_text;
- dev->clip_text = fz_list_clip_text;
- dev->clip_stroke_text = fz_list_clip_stroke_text;
- dev->ignore_text = fz_list_ignore_text;
+ dev->super.fill_shade = fz_list_fill_shade;
+ dev->super.fill_image = fz_list_fill_image;
+ dev->super.fill_image_mask = fz_list_fill_image_mask;
+ dev->super.clip_image_mask = fz_list_clip_image_mask;
- dev->fill_shade = fz_list_fill_shade;
- dev->fill_image = fz_list_fill_image;
- dev->fill_image_mask = fz_list_fill_image_mask;
- dev->clip_image_mask = fz_list_clip_image_mask;
+ dev->super.pop_clip = fz_list_pop_clip;
- dev->pop_clip = fz_list_pop_clip;
+ dev->super.begin_mask = fz_list_begin_mask;
+ dev->super.end_mask = fz_list_end_mask;
+ dev->super.begin_group = fz_list_begin_group;
+ dev->super.end_group = fz_list_end_group;
- dev->begin_mask = fz_list_begin_mask;
- dev->end_mask = fz_list_end_mask;
- dev->begin_group = fz_list_begin_group;
- dev->end_group = fz_list_end_group;
+ dev->super.begin_tile = fz_list_begin_tile;
+ dev->super.end_tile = fz_list_end_tile;
- dev->begin_tile = fz_list_begin_tile;
- dev->end_tile = fz_list_end_tile;
+ dev->list = list;
- return dev;
+ return (fz_device*)dev;
}
static void
diff --git a/source/fitz/stext-device.c b/source/fitz/stext-device.c
index dd1249c8..cdba39f8 100644
--- a/source/fitz/stext-device.c
+++ b/source/fitz/stext-device.c
@@ -25,6 +25,7 @@ typedef struct span_soup_s span_soup;
struct fz_text_device_s
{
+ fz_device super;
fz_text_sheet *sheet;
fz_text_page *page;
span_soup *spans;
@@ -788,7 +789,7 @@ static void
fz_text_fill_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- fz_text_device *tdev = dev->user;
+ fz_text_device *tdev = (fz_text_device*)dev;
fz_text_style *style;
style = fz_lookup_text_style(ctx, tdev->sheet, text, ctm, colorspace, color, alpha, NULL);
fz_text_extract(ctx, tdev, text, ctm, style);
@@ -798,7 +799,7 @@ static void
fz_text_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- fz_text_device *tdev = dev->user;
+ fz_text_device *tdev = (fz_text_device*)dev;
fz_text_style *style;
style = fz_lookup_text_style(ctx, tdev->sheet, text, ctm, colorspace, color, alpha, stroke);
fz_text_extract(ctx, tdev, text, ctm, style);
@@ -807,7 +808,7 @@ fz_text_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_st
static void
fz_text_clip_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate)
{
- fz_text_device *tdev = dev->user;
+ fz_text_device *tdev = (fz_text_device*)dev;
fz_text_style *style;
style = fz_lookup_text_style(ctx, tdev->sheet, text, ctm, NULL, NULL, 0, NULL);
fz_text_extract(ctx, tdev, text, ctm, style);
@@ -816,7 +817,7 @@ fz_text_clip_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matri
static void
fz_text_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm)
{
- fz_text_device *tdev = dev->user;
+ fz_text_device *tdev = (fz_text_device*)dev;
fz_text_style *style;
style = fz_lookup_text_style(ctx, tdev->sheet, text, ctm, NULL, NULL, 0, stroke);
fz_text_extract(ctx, tdev, text, ctm, style);
@@ -825,7 +826,7 @@ fz_text_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stro
static void
fz_text_ignore_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm)
{
- fz_text_device *tdev = dev->user;
+ fz_text_device *tdev = (fz_text_device*)dev;
fz_text_style *style;
style = fz_lookup_text_style(ctx, tdev->sheet, text, ctm, NULL, NULL, 0, NULL);
fz_text_extract(ctx, tdev, text, ctm, style);
@@ -835,7 +836,7 @@ static void
fz_text_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *img, const fz_matrix *ctm,
fz_colorspace *cspace, float *color, float alpha)
{
- fz_text_device *tdev = dev->user;
+ fz_text_device *tdev = (fz_text_device*)dev;
fz_text_page *page = tdev->page;
fz_image_block *block;
@@ -956,7 +957,7 @@ fz_bidi_reorder_text_page(fz_context *ctx, fz_text_page *page)
static void
fz_text_begin_page(fz_context *ctx, fz_device *dev, const fz_rect *mediabox, const fz_matrix *ctm)
{
- fz_text_device *tdev = dev->user;
+ fz_text_device *tdev = (fz_text_device*)dev;
if (tdev->page->len)
{
@@ -973,7 +974,7 @@ fz_text_begin_page(fz_context *ctx, fz_device *dev, const fz_rect *mediabox, con
static void
fz_text_end_page(fz_context *ctx, fz_device *dev)
{
- fz_text_device *tdev = dev->user;
+ fz_text_device *tdev = (fz_text_device*)dev;
add_span_to_soup(ctx, tdev->spans, tdev->cur_span);
tdev->cur_span = NULL;
@@ -989,37 +990,35 @@ fz_text_end_page(fz_context *ctx, fz_device *dev)
}
static void
-fz_text_drop_user(fz_context *ctx, fz_device *dev)
+fz_text_drop_imp(fz_context *ctx, fz_device *dev)
{
- fz_text_device *tdev = dev->user;
+ fz_text_device *tdev = (fz_text_device*)dev;
free_span_soup(ctx, tdev->spans);
- fz_free(ctx, tdev);
}
fz_device *
fz_new_text_device(fz_context *ctx, fz_text_sheet *sheet, fz_text_page *page)
{
- fz_device *dev;
-
- fz_text_device *tdev = fz_malloc_struct(ctx, fz_text_device);
- tdev->sheet = sheet;
- tdev->page = page;
- tdev->spans = NULL;
- tdev->cur_span = NULL;
- tdev->lastchar = ' ';
-
- dev = fz_new_device(ctx, tdev);
- dev->hints = FZ_IGNORE_IMAGE | FZ_IGNORE_SHADE;
- dev->begin_page = fz_text_begin_page;
- dev->end_page = fz_text_end_page;
- dev->drop_user = fz_text_drop_user;
- dev->fill_text = fz_text_fill_text;
- dev->stroke_text = fz_text_stroke_text;
- dev->clip_text = fz_text_clip_text;
- dev->clip_stroke_text = fz_text_clip_stroke_text;
- dev->ignore_text = fz_text_ignore_text;
- dev->fill_image = fz_text_fill_image;
- dev->fill_image_mask = fz_text_fill_image_mask;
-
- return dev;
+ fz_text_device *dev = fz_new_device(ctx, sizeof *dev);
+
+ dev->super.hints = FZ_IGNORE_IMAGE | FZ_IGNORE_SHADE;
+
+ dev->super.drop_imp = fz_text_drop_imp;
+ dev->super.begin_page = fz_text_begin_page;
+ dev->super.end_page = fz_text_end_page;
+ dev->super.fill_text = fz_text_fill_text;
+ dev->super.stroke_text = fz_text_stroke_text;
+ dev->super.clip_text = fz_text_clip_text;
+ dev->super.clip_stroke_text = fz_text_clip_stroke_text;
+ dev->super.ignore_text = fz_text_ignore_text;
+ dev->super.fill_image = fz_text_fill_image;
+ dev->super.fill_image_mask = fz_text_fill_image_mask;
+
+ dev->sheet = sheet;
+ dev->page = page;
+ dev->spans = NULL;
+ dev->cur_span = NULL;
+ dev->lastchar = ' ';
+
+ return (fz_device*)dev;
}
diff --git a/source/fitz/svg-device.c b/source/fitz/svg-device.c
index 29acc530..8d977597 100644
--- a/source/fitz/svg-device.c
+++ b/source/fitz/svg-device.c
@@ -31,6 +31,8 @@ struct font_s
struct svg_device_s
{
+ fz_device super;
+
fz_output *out;
fz_output *out_store;
fz_output *defs;
@@ -305,7 +307,7 @@ svg_dev_text(fz_context *ctx, svg_device *sdev, const fz_matrix *ctm, fz_text *t
static font *
svg_dev_text_as_paths_defs(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
int i, font_idx;
font *fnt;
@@ -392,7 +394,7 @@ static void
svg_dev_text_as_paths_fill(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha, font *fnt)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
fz_matrix local_trm, local_trm2;
@@ -433,7 +435,7 @@ svg_dev_text_as_paths_stroke(fz_context *ctx, fz_device *dev, fz_text *text,
fz_stroke_state *stroke, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha, font *fnt)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
fz_matrix local_trm, local_trm2;
@@ -476,7 +478,7 @@ static void
svg_dev_fill_path(fz_context *ctx, fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
fz_printf(ctx, out, "<path");
@@ -492,7 +494,7 @@ static void
svg_dev_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
fz_printf(ctx, out, "<path");
@@ -506,7 +508,7 @@ svg_dev_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, fz_stroke_st
static void
svg_dev_clip_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out;
int num = sdev->id++;
@@ -526,7 +528,7 @@ svg_dev_clip_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect
static void
svg_dev_clip_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out;
fz_rect bounds;
@@ -552,7 +554,7 @@ static void
svg_dev_fill_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
font *fnt;
@@ -568,7 +570,7 @@ static void
svg_dev_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
font *fnt;
@@ -583,7 +585,7 @@ svg_dev_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_st
static void
svg_dev_clip_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
fz_rect bounds;
@@ -609,7 +611,7 @@ svg_dev_clip_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matri
static void
svg_dev_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out;
fz_rect bounds;
@@ -636,7 +638,7 @@ svg_dev_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stro
static void
svg_dev_ignore_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
float black[3] = { 0, 0, 0};
@@ -687,7 +689,7 @@ send_data_base64(fz_context *ctx, fz_output *out, fz_buffer *buffer)
static void
svg_dev_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
fz_matrix local_ctm = *ctm;
@@ -729,7 +731,7 @@ svg_dev_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_ma
static void
svg_dev_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
fz_rect rect;
@@ -775,7 +777,7 @@ static void
svg_dev_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out;
fz_matrix local_ctm = *ctm;
@@ -819,7 +821,7 @@ fz_colorspace *colorspace, float *color, float alpha)
static void
svg_dev_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out;
fz_matrix local_ctm = *ctm;
fz_matrix scale = { 0 };
@@ -860,7 +862,7 @@ svg_dev_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const
static void
svg_dev_pop_clip(fz_context *ctx, fz_device *dev)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
/* FIXME */
@@ -870,7 +872,7 @@ svg_dev_pop_clip(fz_context *ctx, fz_device *dev)
static void
svg_dev_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int luminosity, fz_colorspace *colorspace, float *color)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out;
int mask = sdev->id++;
@@ -884,7 +886,7 @@ svg_dev_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int lum
static void
svg_dev_end_mask(fz_context *ctx, fz_device *dev)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
int mask = 0;
@@ -900,7 +902,7 @@ svg_dev_end_mask(fz_context *ctx, fz_device *dev)
static void
svg_dev_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int isolated, int knockout, int blendmode, float alpha)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
/* SVG 1.1 doesn't support adequate blendmodes/knockout etc, so just ignore it for now */
@@ -910,7 +912,7 @@ svg_dev_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int is
static void
svg_dev_end_group(fz_context *ctx, fz_device *dev)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
fz_printf(ctx, out, "</g>\n");
@@ -919,7 +921,7 @@ svg_dev_end_group(fz_context *ctx, fz_device *dev)
static int
svg_dev_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out;
int num;
tile *t;
@@ -960,7 +962,7 @@ svg_dev_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const f
static void
svg_dev_end_tile(fz_context *ctx, fz_device *dev)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
int num, cp = -1;
tile *t;
@@ -1028,9 +1030,9 @@ svg_dev_end_tile(fz_context *ctx, fz_device *dev)
}
static void
-svg_dev_drop_user(fz_context *ctx, fz_device *dev)
+svg_dev_drop_imp(fz_context *ctx, fz_device *dev)
{
- svg_device *sdev = dev->user;
+ svg_device *sdev = (svg_device*)dev;
fz_output *out = sdev->out;
fz_free(ctx, sdev->tiles);
@@ -1038,58 +1040,47 @@ svg_dev_drop_user(fz_context *ctx, fz_device *dev)
fz_drop_output(ctx, sdev->defs);
fz_printf(ctx, out, "</svg>\n");
-
- fz_free(ctx, sdev);
}
fz_device *fz_new_svg_device(fz_context *ctx, fz_output *out, float page_width, float page_height)
{
- svg_device *sdev = fz_malloc_struct(ctx, svg_device);
- fz_device *dev;
+ svg_device *dev = fz_new_device(ctx, sizeof *dev);
- fz_try(ctx)
- {
- sdev->out = out;
- sdev->out_store = out;
- sdev->id = 0;
+ dev = fz_new_device(ctx, sizeof *dev);
- dev = fz_new_device(ctx, sdev);
- }
- fz_catch(ctx)
- {
- fz_free(ctx, sdev);
- fz_rethrow(ctx);
- }
+ dev->super.drop_imp = svg_dev_drop_imp;
- dev->drop_user = svg_dev_drop_user;
+ dev->super.fill_path = svg_dev_fill_path;
+ dev->super.stroke_path = svg_dev_stroke_path;
+ dev->super.clip_path = svg_dev_clip_path;
+ dev->super.clip_stroke_path = svg_dev_clip_stroke_path;
- dev->fill_path = svg_dev_fill_path;
- dev->stroke_path = svg_dev_stroke_path;
- dev->clip_path = svg_dev_clip_path;
- dev->clip_stroke_path = svg_dev_clip_stroke_path;
+ dev->super.fill_text = svg_dev_fill_text;
+ dev->super.stroke_text = svg_dev_stroke_text;
+ dev->super.clip_text = svg_dev_clip_text;
+ dev->super.clip_stroke_text = svg_dev_clip_stroke_text;
+ dev->super.ignore_text = svg_dev_ignore_text;
- dev->fill_text = svg_dev_fill_text;
- dev->stroke_text = svg_dev_stroke_text;
- dev->clip_text = svg_dev_clip_text;
- dev->clip_stroke_text = svg_dev_clip_stroke_text;
- dev->ignore_text = svg_dev_ignore_text;
+ dev->super.fill_shade = svg_dev_fill_shade;
+ dev->super.fill_image = svg_dev_fill_image;
+ dev->super.fill_image_mask = svg_dev_fill_image_mask;
+ dev->super.clip_image_mask = svg_dev_clip_image_mask;
- dev->fill_shade = svg_dev_fill_shade;
- dev->fill_image = svg_dev_fill_image;
- dev->fill_image_mask = svg_dev_fill_image_mask;
- dev->clip_image_mask = svg_dev_clip_image_mask;
+ dev->super.pop_clip = svg_dev_pop_clip;
- dev->pop_clip = svg_dev_pop_clip;
+ dev->super.begin_mask = svg_dev_begin_mask;
+ dev->super.end_mask = svg_dev_end_mask;
+ dev->super.begin_group = svg_dev_begin_group;
+ dev->super.end_group = svg_dev_end_group;
- dev->begin_mask = svg_dev_begin_mask;
- dev->end_mask = svg_dev_end_mask;
- dev->begin_group = svg_dev_begin_group;
- dev->end_group = svg_dev_end_group;
+ dev->super.begin_tile = svg_dev_begin_tile;
+ dev->super.end_tile = svg_dev_end_tile;
- dev->begin_tile = svg_dev_begin_tile;
- dev->end_tile = svg_dev_end_tile;
+ dev->super.hints |= FZ_MAINTAIN_CONTAINER_STACK;
- dev->hints |= FZ_MAINTAIN_CONTAINER_STACK;
+ dev->out = out;
+ dev->out_store = out;
+ dev->id = 0;
fz_printf(ctx, out, "<?xml version=\"1.0\" standalone=\"no\"?>\n");
fz_printf(ctx, out, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
@@ -1098,5 +1089,5 @@ fz_device *fz_new_svg_device(fz_context *ctx, fz_output *out, float page_width,
"width=\"%gcm\" height=\"%gcm\" viewBox=\"0 0 %g %g\">\n",
page_width*2.54/72, page_height*2.54/72, page_width, page_height);
- return dev;
+ return (fz_device*)dev;
}
diff --git a/source/fitz/test-device.c b/source/fitz/test-device.c
index 16736c80..d0bd08c7 100644
--- a/source/fitz/test-device.c
+++ b/source/fitz/test-device.c
@@ -1,10 +1,11 @@
#include <mupdf/fitz.h>
-struct test
+typedef struct fz_test_device_s
{
+ fz_device super;
int *is_color;
float threshold;
-};
+} fz_test_device;
static int
is_rgb_color(float threshold, float r, float g, float b)
@@ -27,7 +28,7 @@ is_rgb_color_u8(int threshold_u8, int r, int g, int b)
static void
fz_test_color(fz_context *ctx, fz_device *dev, fz_colorspace *colorspace, const float *color)
{
- struct test *t = dev->user;
+ fz_test_device *t = (fz_test_device*)dev;
if (!*t->is_color && colorspace && colorspace != fz_device_gray(ctx))
{
@@ -123,7 +124,7 @@ fz_test_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_ma
static void
fz_test_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha)
{
- struct test *t = dev->user;
+ fz_test_device *t = (fz_test_device*)dev;
fz_pixmap *pix;
unsigned int count, i, k;
@@ -247,45 +248,23 @@ fz_test_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const
fz_test_color(ctx, dev, colorspace, color);
}
-static void
-fz_test_free(fz_context *ctx, fz_device *dev)
-{
- if (dev == NULL)
- return;
- fz_free(ctx, dev->user);
- dev->user = NULL;
-}
-
fz_device *
fz_new_test_device(fz_context *ctx, int *is_color, float threshold)
{
- struct test *t;
- fz_device *dev;
-
- t = fz_malloc_struct(ctx, struct test);
- t->is_color = is_color;
- t->threshold = threshold;
+ fz_test_device *dev = fz_new_device(ctx, sizeof *dev);
- fz_try(ctx)
- {
- dev = fz_new_device(ctx, t);
- }
- fz_catch(ctx)
- {
- fz_free(ctx, t);
- fz_rethrow(ctx);
- }
+ dev->super.fill_path = fz_test_fill_path;
+ dev->super.stroke_path = fz_test_stroke_path;
+ dev->super.fill_text = fz_test_fill_text;
+ dev->super.stroke_text = fz_test_stroke_text;
+ dev->super.fill_shade = fz_test_fill_shade;
+ dev->super.fill_image = fz_test_fill_image;
+ dev->super.fill_image_mask = fz_test_fill_image_mask;
- dev->fill_path = fz_test_fill_path;
- dev->stroke_path = fz_test_stroke_path;
- dev->fill_text = fz_test_fill_text;
- dev->stroke_text = fz_test_stroke_text;
- dev->fill_shade = fz_test_fill_shade;
- dev->fill_image = fz_test_fill_image;
- dev->fill_image_mask = fz_test_fill_image_mask;
- dev->drop_user = fz_test_free;
+ dev->is_color = is_color;
+ dev->threshold = threshold;
- *t->is_color = 0;
+ *dev->is_color = 0;
- return dev;
+ return (fz_device*)dev;
}
diff --git a/source/fitz/trace-device.c b/source/fitz/trace-device.c
index 3a0bba0a..97dd4f79 100644
--- a/source/fitz/trace-device.c
+++ b/source/fitz/trace-device.c
@@ -303,7 +303,7 @@ fz_trace_end_tile(fz_context *ctx, fz_device *dev)
fz_device *fz_new_trace_device(fz_context *ctx)
{
- fz_device *dev = fz_new_device(ctx, NULL);
+ fz_device *dev = fz_new_device(ctx, sizeof *dev);
dev->begin_page = fz_trace_begin_page;
dev->end_page = fz_trace_end_page;
diff --git a/source/pdf/pdf-device.c b/source/pdf/pdf-device.c
index 471aaced..b5db7e3a 100644
--- a/source/pdf/pdf-device.c
+++ b/source/pdf/pdf-device.c
@@ -72,6 +72,8 @@ struct group_entry_s
struct pdf_device_s
{
+ fz_device super;
+
pdf_document *doc;
pdf_obj *contents;
pdf_obj *resources;
@@ -855,7 +857,7 @@ static void
pdf_dev_fill_path(fz_context *ctx, fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
gstate *gs = CURRENT_GSTATE(pdev);
pdf_dev_end_text(ctx, pdev);
@@ -870,7 +872,7 @@ static void
pdf_dev_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
gstate *gs = CURRENT_GSTATE(pdev);
pdf_dev_end_text(ctx, pdev);
@@ -885,7 +887,7 @@ pdf_dev_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, fz_stroke_st
static void
pdf_dev_clip_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
gstate *gs;
pdf_dev_end_text(ctx, pdev);
@@ -899,7 +901,7 @@ pdf_dev_clip_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect
static void
pdf_dev_clip_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
gstate *gs;
pdf_dev_end_text(ctx, pdev);
@@ -918,7 +920,7 @@ static void
pdf_dev_fill_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
fz_matrix trm = text->trm;
float size = fz_matrix_expansion(&trm);
@@ -936,7 +938,7 @@ static void
pdf_dev_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
fz_matrix trm = text->trm;
float size = fz_matrix_expansion(&trm);
@@ -953,7 +955,7 @@ pdf_dev_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_st
static void
pdf_dev_clip_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
fz_matrix trm = text->trm;
float size = fz_matrix_expansion(&trm);
@@ -968,7 +970,7 @@ pdf_dev_clip_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matri
static void
pdf_dev_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
fz_matrix trm = text->trm;
float size = fz_matrix_expansion(&trm);
@@ -983,7 +985,7 @@ pdf_dev_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stro
static void
pdf_dev_ignore_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
fz_matrix trm = text->trm;
float size = fz_matrix_expansion(&trm);
@@ -998,7 +1000,7 @@ pdf_dev_ignore_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_mat
static void
pdf_dev_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
int num;
gstate *gs = CURRENT_GSTATE(pdev);
fz_matrix local_ctm = *ctm;
@@ -1016,7 +1018,7 @@ pdf_dev_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_ma
static void
pdf_dev_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
/* FIXME */
pdf_dev_end_text(ctx, pdev);
@@ -1026,7 +1028,7 @@ static void
pdf_dev_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
gstate *gs = CURRENT_GSTATE(pdev);
int num;
fz_matrix local_ctm = *ctm;
@@ -1046,7 +1048,7 @@ fz_colorspace *colorspace, float *color, float alpha)
static void
pdf_dev_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
/* FIXME */
pdf_dev_end_text(ctx, pdev);
@@ -1056,7 +1058,7 @@ pdf_dev_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const
static void
pdf_dev_pop_clip(fz_context *ctx, fz_device *dev)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
/* FIXME */
pdf_dev_end_text(ctx, pdev);
@@ -1066,7 +1068,7 @@ pdf_dev_pop_clip(fz_context *ctx, fz_device *dev)
static void
pdf_dev_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int luminosity, fz_colorspace *colorspace, float *color)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
pdf_document *doc = pdev->doc;
gstate *gs;
pdf_obj *smask = NULL;
@@ -1130,7 +1132,7 @@ pdf_dev_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int lum
static void
pdf_dev_end_mask(fz_context *ctx, fz_device *dev)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
pdf_document *doc = pdev->doc;
gstate *gs = CURRENT_GSTATE(pdev);
fz_buffer *buf = fz_keep_buffer(ctx, gs->buf);
@@ -1151,7 +1153,7 @@ pdf_dev_end_mask(fz_context *ctx, fz_device *dev)
static void
pdf_dev_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int isolated, int knockout, int blendmode, float alpha)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
pdf_document *doc = pdev->doc;
int num;
pdf_obj *form_ref;
@@ -1189,7 +1191,7 @@ pdf_dev_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int is
static void
pdf_dev_end_group(fz_context *ctx, fz_device *dev)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
pdf_document *doc = pdev->doc;
gstate *gs = CURRENT_GSTATE(pdev);
fz_buffer *buf = fz_keep_buffer(ctx, gs->buf);
@@ -1206,7 +1208,7 @@ pdf_dev_end_group(fz_context *ctx, fz_device *dev)
static int
pdf_dev_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
/* FIXME */
pdf_dev_end_text(ctx, pdev);
@@ -1216,16 +1218,16 @@ pdf_dev_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const f
static void
pdf_dev_end_tile(fz_context *ctx, fz_device *dev)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
/* FIXME */
pdf_dev_end_text(ctx, pdev);
}
static void
-pdf_dev_drop_user(fz_context *ctx, fz_device *dev)
+pdf_dev_drop_imp(fz_context *ctx, fz_device *dev)
{
- pdf_device *pdev = dev->user;
+ pdf_device *pdev = (pdf_device*)dev;
pdf_document *doc = pdev->doc;
gstate *gs = CURRENT_GSTATE(pdev);
int i;
@@ -1258,72 +1260,68 @@ pdf_dev_drop_user(fz_context *ctx, fz_device *dev)
fz_free(ctx, pdev->images);
fz_free(ctx, pdev->alphas);
fz_free(ctx, pdev->gstates);
- fz_free(ctx, pdev);
}
fz_device *pdf_new_pdf_device(fz_context *ctx, pdf_document *doc, pdf_obj *contents, pdf_obj *resources, const fz_matrix *ctm)
{
- pdf_device *pdev = fz_malloc_struct(ctx, pdf_device);
- fz_device *dev;
+ pdf_device *dev = fz_new_device(ctx, sizeof *dev);
- fz_try(ctx)
- {
- pdev->doc = doc;
- pdev->contents = pdf_keep_obj(ctx, contents);
- pdev->resources = pdf_keep_obj(ctx, resources);
- pdev->gstates = fz_malloc_struct(ctx, gstate);
- pdev->gstates[0].buf = fz_new_buffer(ctx, 256);
- pdev->gstates[0].ctm = *ctm;
- pdev->gstates[0].colorspace[0] = fz_device_gray(ctx);
- pdev->gstates[0].colorspace[1] = fz_device_gray(ctx);
- pdev->gstates[0].color[0][0] = 1;
- pdev->gstates[0].color[1][0] = 1;
- pdev->gstates[0].alpha[0] = 1.0;
- pdev->gstates[0].alpha[1] = 1.0;
- pdev->gstates[0].font = -1;
- pdev->gstates[0].horizontal_scaling = 100;
- pdev->num_gstates = 1;
- pdev->max_gstates = 1;
-
- dev = fz_new_device(ctx, pdev);
- }
- fz_catch(ctx)
- {
- if (pdev->gstates)
- fz_drop_buffer(ctx, pdev->gstates[0].buf);
- fz_free(ctx, pdev);
- fz_rethrow(ctx);
- }
+ dev->super.drop_imp = pdf_dev_drop_imp;
- dev->drop_user = pdf_dev_drop_user;
+ dev->super.fill_path = pdf_dev_fill_path;
+ dev->super.stroke_path = pdf_dev_stroke_path;
+ dev->super.clip_path = pdf_dev_clip_path;
+ dev->super.clip_stroke_path = pdf_dev_clip_stroke_path;
- dev->fill_path = pdf_dev_fill_path;
- dev->stroke_path = pdf_dev_stroke_path;
- dev->clip_path = pdf_dev_clip_path;
- dev->clip_stroke_path = pdf_dev_clip_stroke_path;
+ dev->super.fill_text = pdf_dev_fill_text;
+ dev->super.stroke_text = pdf_dev_stroke_text;
+ dev->super.clip_text = pdf_dev_clip_text;
+ dev->super.clip_stroke_text = pdf_dev_clip_stroke_text;
+ dev->super.ignore_text = pdf_dev_ignore_text;
- dev->fill_text = pdf_dev_fill_text;
- dev->stroke_text = pdf_dev_stroke_text;
- dev->clip_text = pdf_dev_clip_text;
- dev->clip_stroke_text = pdf_dev_clip_stroke_text;
- dev->ignore_text = pdf_dev_ignore_text;
+ dev->super.fill_shade = pdf_dev_fill_shade;
+ dev->super.fill_image = pdf_dev_fill_image;
+ dev->super.fill_image_mask = pdf_dev_fill_image_mask;
+ dev->super.clip_image_mask = pdf_dev_clip_image_mask;
- dev->fill_shade = pdf_dev_fill_shade;
- dev->fill_image = pdf_dev_fill_image;
- dev->fill_image_mask = pdf_dev_fill_image_mask;
- dev->clip_image_mask = pdf_dev_clip_image_mask;
+ dev->super.pop_clip = pdf_dev_pop_clip;
- dev->pop_clip = pdf_dev_pop_clip;
+ dev->super.begin_mask = pdf_dev_begin_mask;
+ dev->super.end_mask = pdf_dev_end_mask;
+ dev->super.begin_group = pdf_dev_begin_group;
+ dev->super.end_group = pdf_dev_end_group;
- dev->begin_mask = pdf_dev_begin_mask;
- dev->end_mask = pdf_dev_end_mask;
- dev->begin_group = pdf_dev_begin_group;
- dev->end_group = pdf_dev_end_group;
+ dev->super.begin_tile = pdf_dev_begin_tile;
+ dev->super.end_tile = pdf_dev_end_tile;
- dev->begin_tile = pdf_dev_begin_tile;
- dev->end_tile = pdf_dev_end_tile;
+ fz_try(ctx)
+ {
+ dev->doc = doc;
+ dev->contents = pdf_keep_obj(ctx, contents);
+ dev->resources = pdf_keep_obj(ctx, resources);
+ dev->gstates = fz_malloc_struct(ctx, gstate);
+ dev->gstates[0].buf = fz_new_buffer(ctx, 256);
+ dev->gstates[0].ctm = *ctm;
+ dev->gstates[0].colorspace[0] = fz_device_gray(ctx);
+ dev->gstates[0].colorspace[1] = fz_device_gray(ctx);
+ dev->gstates[0].color[0][0] = 1;
+ dev->gstates[0].color[1][0] = 1;
+ dev->gstates[0].alpha[0] = 1.0;
+ dev->gstates[0].alpha[1] = 1.0;
+ dev->gstates[0].font = -1;
+ dev->gstates[0].horizontal_scaling = 100;
+ dev->num_gstates = 1;
+ dev->max_gstates = 1;
+ }
+ fz_catch(ctx)
+ {
+ if (dev->gstates)
+ fz_drop_buffer(ctx, dev->gstates[0].buf);
+ fz_free(ctx, dev);
+ fz_rethrow(ctx);
+ }
- return dev;
+ return (fz_device*)dev;
}
fz_device *pdf_page_write(fz_context *ctx, pdf_document *doc, pdf_page *page)