diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2013-01-30 14:05:56 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2013-01-30 14:13:01 +0100 |
commit | 29f7d13d37022303c5d93ddd2942f6b87959f432 (patch) | |
tree | 0f1eeb4f3778713fe99b34649336aa27ddaf9a71 | |
parent | 01e2ccf6ade55cc20e83b80bad81fef6627c9a05 (diff) | |
download | mupdf-29f7d13d37022303c5d93ddd2942f6b87959f432.tar.xz |
Always pass value structs (rect, matrix, etc) as values not by pointer.
-rw-r--r-- | apps/mudraw.c | 2 | ||||
-rw-r--r-- | draw/draw_affine.c | 139 | ||||
-rw-r--r-- | draw/draw_device.c | 4 | ||||
-rw-r--r-- | fitz/dev_list.c | 4 | ||||
-rw-r--r-- | fitz/fitz-internal.h | 4 | ||||
-rw-r--r-- | fitz/fitz.h | 2 | ||||
-rw-r--r-- | fitz/res_path.c | 21 | ||||
-rw-r--r-- | pdf/mupdf-internal.h | 2 | ||||
-rw-r--r-- | pdf/mupdf.h | 4 | ||||
-rw-r--r-- | pdf/pdf_form.c | 6 | ||||
-rw-r--r-- | pdf/pdf_object.c | 24 | ||||
-rw-r--r-- | pdf/pdf_xobject.c | 6 |
12 files changed, 111 insertions, 107 deletions
diff --git a/apps/mudraw.c b/apps/mudraw.c index cf9864ec..d0e597d7 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -220,7 +220,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) } for (;widget; widget = fz_next_widget(inter, widget)) { - fz_rect rect = *fz_widget_bbox(widget); + fz_rect rect = fz_widget_bbox(widget); int w = (rect.x1-rect.x0); int h = (rect.y1-rect.y0); int len; diff --git a/draw/draw_affine.c b/draw/draw_affine.c index e74bef2b..be41aa35 100644 --- a/draw/draw_affine.c +++ b/draw/draw_affine.c @@ -463,135 +463,136 @@ fz_paint_affine_color_near(byte *dp, byte *sp, int sw, int sh, int u, int v, int */ #define MY_EPSILON 0.001 -void -fz_gridfit_matrix(fz_matrix *m) +fz_matrix +fz_gridfit_matrix(fz_matrix m) { - if (fabsf(m->b) < FLT_EPSILON && fabsf(m->c) < FLT_EPSILON) + if (fabsf(m.b) < FLT_EPSILON && fabsf(m.c) < FLT_EPSILON) { - if (m->a > 0) + if (m.a > 0) { float f; /* Adjust left hand side onto pixel boundary */ - f = (float)(int)(m->e); - if (f - m->e > MY_EPSILON) + f = (float)(int)(m.e); + if (f - m.e > MY_EPSILON) f -= 1.0; /* Ensure it moves left */ - m->a += m->e - f; /* width gets wider as f <= m->e */ - m->e = f; + m.a += m.e - f; /* width gets wider as f <= m.e */ + m.e = f; /* Adjust right hand side onto pixel boundary */ - f = (float)(int)(m->a); - if (m->a - f > MY_EPSILON) + f = (float)(int)(m.a); + if (m.a - f > MY_EPSILON) f += 1.0; /* Ensure it moves right */ - m->a = f; + m.a = f; } - else if (m->a < 0) + else if (m.a < 0) { float f; /* Adjust right hand side onto pixel boundary */ - f = (float)(int)(m->e); - if (m->e - f > MY_EPSILON) + f = (float)(int)(m.e); + if (m.e - f > MY_EPSILON) f += 1.0; /* Ensure it moves right */ - m->a += m->e - f; /* width gets wider (more -ve) */ - m->e = f; + m.a += m.e - f; /* width gets wider (more -ve) */ + m.e = f; /* Adjust left hand side onto pixel boundary */ - f = (float)(int)(m->a); - if (f - m->a > MY_EPSILON) + f = (float)(int)(m.a); + if (f - m.a > MY_EPSILON) f -= 1.0; /* Ensure it moves left */ - m->a = f; + m.a = f; } - if (m->d > 0) + if (m.d > 0) { float f; /* Adjust top onto pixel boundary */ - f = (float)(int)(m->f); - if (f - m->f > MY_EPSILON) + f = (float)(int)(m.f); + if (f - m.f > MY_EPSILON) f -= 1.0; /* Ensure it moves upwards */ - m->d += m->f - f; /* width gets wider as f <= m->f */ - m->f = f; + m.d += m.f - f; /* width gets wider as f <= m.f */ + m.f = f; /* Adjust bottom onto pixel boundary */ - f = (float)(int)(m->d); - if (m->d - f > MY_EPSILON) + f = (float)(int)(m.d); + if (m.d - f > MY_EPSILON) f += 1.0; /* Ensure it moves down */ - m->d = f; + m.d = f; } - else if (m->d < 0) + else if (m.d < 0) { float f; /* Adjust bottom onto pixel boundary */ - f = (float)(int)(m->f); - if (m->f - f > MY_EPSILON) + f = (float)(int)(m.f); + if (m.f - f > MY_EPSILON) f += 1.0; /* Ensure it moves down */ - m->d += m->f - f; /* width gets wider (more -ve) */ - m->f = f; + m.d += m.f - f; /* width gets wider (more -ve) */ + m.f = f; /* Adjust top onto pixel boundary */ - f = (float)(int)(m->d); - if (f - m->d > MY_EPSILON) + f = (float)(int)(m.d); + if (f - m.d > MY_EPSILON) f -= 1.0; /* Ensure it moves up */ - m->d = f; + m.d = f; } } - else if (fabsf(m->a) < FLT_EPSILON && fabsf(m->d) < FLT_EPSILON) + else if (fabsf(m.a) < FLT_EPSILON && fabsf(m.d) < FLT_EPSILON) { - if (m->b > 0) + if (m.b > 0) { float f; /* Adjust left hand side onto pixel boundary */ - f = (float)(int)(m->f); - if (f - m->f > MY_EPSILON) + f = (float)(int)(m.f); + if (f - m.f > MY_EPSILON) f -= 1.0; /* Ensure it moves left */ - m->b += m->f - f; /* width gets wider as f <= m->f */ - m->f = f; + m.b += m.f - f; /* width gets wider as f <= m.f */ + m.f = f; /* Adjust right hand side onto pixel boundary */ - f = (float)(int)(m->b); - if (m->b - f > MY_EPSILON) + f = (float)(int)(m.b); + if (m.b - f > MY_EPSILON) f += 1.0; /* Ensure it moves right */ - m->b = f; + m.b = f; } - else if (m->b < 0) + else if (m.b < 0) { float f; /* Adjust right hand side onto pixel boundary */ - f = (float)(int)(m->f); - if (m->f - f > MY_EPSILON) + f = (float)(int)(m.f); + if (m.f - f > MY_EPSILON) f += 1.0; /* Ensure it moves right */ - m->b += m->f - f; /* width gets wider (more -ve) */ - m->f = f; + m.b += m.f - f; /* width gets wider (more -ve) */ + m.f = f; /* Adjust left hand side onto pixel boundary */ - f = (float)(int)(m->b); - if (f - m->b > MY_EPSILON) + f = (float)(int)(m.b); + if (f - m.b > MY_EPSILON) f -= 1.0; /* Ensure it moves left */ - m->b = f; + m.b = f; } - if (m->c > 0) + if (m.c > 0) { float f; /* Adjust top onto pixel boundary */ - f = (float)(int)(m->e); - if (f - m->e > MY_EPSILON) + f = (float)(int)(m.e); + if (f - m.e > MY_EPSILON) f -= 1.0; /* Ensure it moves upwards */ - m->c += m->e - f; /* width gets wider as f <= m->e */ - m->e = f; + m.c += m.e - f; /* width gets wider as f <= m.e */ + m.e = f; /* Adjust bottom onto pixel boundary */ - f = (float)(int)(m->c); - if (m->c - f > MY_EPSILON) + f = (float)(int)(m.c); + if (m.c - f > MY_EPSILON) f += 1.0; /* Ensure it moves down */ - m->c = f; + m.c = f; } - else if (m->c < 0) + else if (m.c < 0) { float f; /* Adjust bottom onto pixel boundary */ - f = (float)(int)(m->e); - if (m->e - f > MY_EPSILON) + f = (float)(int)(m.e); + if (m.e - f > MY_EPSILON) f += 1.0; /* Ensure it moves down */ - m->c += m->e - f; /* width gets wider (more -ve) */ - m->e = f; + m.c += m.e - f; /* width gets wider (more -ve) */ + m.e = f; /* Adjust top onto pixel boundary */ - f = (float)(int)(m->c); - if (f - m->c > MY_EPSILON) + f = (float)(int)(m.c); + if (f - m.c > MY_EPSILON) f -= 1.0; /* Ensure it moves up */ - m->c = f; + m.c = f; } } + return m; } /* Draw an image with an affine transform on destination */ @@ -609,7 +610,7 @@ fz_paint_image_imp(fz_pixmap *dst, fz_irect scissor, fz_pixmap *shape, fz_pixmap void (*paintfn)(byte *dp, byte *sp, int sw, int sh, int u, int v, int fa, int fb, int w, int n, int alpha, byte *color, byte *hp); /* grid fit the image */ - fz_gridfit_matrix(&ctm); + ctm = fz_gridfit_matrix(ctm); /* turn on interpolation for upscaled and non-rectilinear transforms */ dolerp = 0; diff --git a/draw/draw_device.c b/draw/draw_device.c index ebca7fdc..b992ce09 100644 --- a/draw/draw_device.c +++ b/draw/draw_device.c @@ -992,7 +992,7 @@ fz_transform_pixmap(fz_draw_device *dev, fz_pixmap *image, fz_matrix *ctm, int x /* Unrotated or X-flip or Y-flip or XY-flip */ fz_matrix m = *ctm; if (gridfit) - fz_gridfit_matrix(&m); + m = fz_gridfit_matrix(m); scaled = fz_scale_pixmap_cached(ctx, image, m.e, m.f, m.a, m.d, clip, dev->cache_x, dev->cache_y); if (!scaled) return NULL; @@ -1009,7 +1009,7 @@ fz_transform_pixmap(fz_draw_device *dev, fz_pixmap *image, fz_matrix *ctm, int x fz_matrix m = *ctm; fz_irect rclip; if (gridfit) - fz_gridfit_matrix(&m); + m = fz_gridfit_matrix(m); if (clip) { rclip.x0 = clip->y0; diff --git a/fitz/dev_list.c b/fitz/dev_list.c index 55ef4e7d..2e6822e3 100644 --- a/fitz/dev_list.c +++ b/fitz/dev_list.c @@ -334,7 +334,7 @@ fz_list_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, fz_m fz_try(ctx) { node->rect = fz_bound_text(dev->ctx, text, ctm); - fz_adjust_rect_for_stroke(&node->rect, stroke, &ctm); + node->rect = fz_adjust_rect_for_stroke(node->rect, stroke, ctm); node->item.text = fz_clone_text(dev->ctx, text); node->stroke = fz_keep_stroke_state(dev->ctx, stroke); } @@ -378,7 +378,7 @@ fz_list_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, fz_try(ctx) { node->rect = fz_bound_text(dev->ctx, text, ctm); - fz_adjust_rect_for_stroke(&node->rect, stroke, &ctm); + node->rect = fz_adjust_rect_for_stroke(node->rect, stroke, ctm); node->item.text = fz_clone_text(dev->ctx, text); node->stroke = fz_keep_stroke_state(dev->ctx, stroke); } diff --git a/fitz/fitz-internal.h b/fitz/fitz-internal.h index 518ed8c2..0f6b70c3 100644 --- a/fitz/fitz-internal.h +++ b/fitz/fitz-internal.h @@ -300,7 +300,7 @@ static inline int fz_mul255(int a, int b) * AMOUNT (in the 0...256 range). */ #define FZ_BLEND(SRC, DST, AMOUNT) ((((SRC)-(DST))*(AMOUNT) + ((DST)<<8))>>8) -void fz_gridfit_matrix(fz_matrix *m); +fz_matrix fz_gridfit_matrix(fz_matrix m); float fz_matrix_max_expansion(fz_matrix m); /* @@ -1162,7 +1162,7 @@ void fz_transform_path(fz_context *ctx, fz_path *path, fz_matrix transform); fz_path *fz_clone_path(fz_context *ctx, fz_path *old); fz_rect fz_bound_path(fz_context *ctx, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm); -void fz_adjust_rect_for_stroke(fz_rect *r, fz_stroke_state *stroke, fz_matrix *ctm); +fz_rect fz_adjust_rect_for_stroke(fz_rect r, fz_stroke_state *stroke, fz_matrix ctm); fz_stroke_state *fz_new_stroke_state(fz_context *ctx); fz_stroke_state *fz_new_stroke_state_with_len(fz_context *ctx, int len); diff --git a/fitz/fitz.h b/fitz/fitz.h index f3fd7458..71f9f214 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -2653,7 +2653,7 @@ int fz_widget_get_type(fz_widget *widget); /* fz_widget_bbox: get the bounding box of a widget. */ -fz_rect *fz_widget_bbox(fz_widget *widget); +fz_rect fz_widget_bbox(fz_widget *widget); /* fz_text_widget_text: Get the text currently displayed in diff --git a/fitz/res_path.c b/fitz/res_path.c index a030cc29..0f18b482 100644 --- a/fitz/res_path.c +++ b/fitz/res_path.c @@ -309,29 +309,32 @@ fz_bound_path(fz_context *ctx, fz_path *path, fz_stroke_state *stroke, fz_matrix if (stroke) { - fz_adjust_rect_for_stroke(&r, stroke, &ctm); + r = fz_adjust_rect_for_stroke(r, stroke, ctm); } return r; } -void -fz_adjust_rect_for_stroke(fz_rect *r, fz_stroke_state *stroke, fz_matrix *ctm) +fz_rect +fz_adjust_rect_for_stroke(fz_rect r, fz_stroke_state *stroke, fz_matrix ctm) { float expand; if (!stroke) - return; + return r; + expand = stroke->linewidth; if (expand == 0) expand = 1.0f; - expand *= fz_matrix_max_expansion(*ctm); + expand *= fz_matrix_max_expansion(ctm); if ((stroke->linejoin == FZ_LINEJOIN_MITER || stroke->linejoin == FZ_LINEJOIN_MITER_XPS) && stroke->miterlimit > 1) expand *= stroke->miterlimit; - r->x0 -= expand; - r->y0 -= expand; - r->x1 += expand; - r->y1 += expand; + + r.x0 -= expand; + r.y0 -= expand; + r.x1 += expand; + r.y1 += expand; + return r; } void diff --git a/pdf/mupdf-internal.h b/pdf/mupdf-internal.h index fdf6a26d..8e0d24a4 100644 --- a/pdf/mupdf-internal.h +++ b/pdf/mupdf-internal.h @@ -284,7 +284,7 @@ struct pdf_xobject_s }; pdf_xobject *pdf_load_xobject(pdf_document *doc, pdf_obj *obj); -pdf_obj *pdf_new_xobject(pdf_document *doc, fz_rect *bbox, fz_matrix *mat); +pdf_obj *pdf_new_xobject(pdf_document *doc, fz_rect bbox, fz_matrix mat); pdf_xobject *pdf_keep_xobject(fz_context *ctx, pdf_xobject *xobj); void pdf_drop_xobject(fz_context *ctx, pdf_xobject *xobj); void pdf_update_xobject_contents(pdf_document *xref, pdf_xobject *form, fz_buffer *buffer); diff --git a/pdf/mupdf.h b/pdf/mupdf.h index 72248017..475ebd79 100644 --- a/pdf/mupdf.h +++ b/pdf/mupdf.h @@ -22,8 +22,8 @@ pdf_obj *pdf_new_string(fz_context *ctx, const char *str, int len); pdf_obj *pdf_new_indirect(fz_context *ctx, int num, int gen, void *doc); pdf_obj *pdf_new_array(fz_context *ctx, int initialcap); pdf_obj *pdf_new_dict(fz_context *ctx, int initialcap); -pdf_obj *pdf_new_rect(fz_context *ctx, fz_rect *rect); -pdf_obj *pdf_new_matrix(fz_context *ctx, fz_matrix *mtx); +pdf_obj *pdf_new_rect(fz_context *ctx, fz_rect rect); +pdf_obj *pdf_new_matrix(fz_context *ctx, fz_matrix mtx); pdf_obj *pdf_copy_array(fz_context *ctx, pdf_obj *array); pdf_obj *pdf_copy_dict(fz_context *ctx, pdf_obj *dict); diff --git a/pdf/pdf_form.c b/pdf/pdf_form.c index bdec208a..8603986c 100644 --- a/pdf/pdf_form.c +++ b/pdf/pdf_form.c @@ -1186,7 +1186,7 @@ static pdf_xobject *load_or_create_form(pdf_document *doc, pdf_obj *obj, fz_rect formobj = pdf_dict_gets(ap, dn); if (formobj == NULL) { - tobj = pdf_new_xobject(doc, rect, &mat); + tobj = pdf_new_xobject(doc, *rect, mat); pdf_dict_puts(ap, dn, tobj); formobj = tobj; pdf_drop_obj(tobj); @@ -2602,11 +2602,11 @@ void pdf_field_set_text_color(pdf_document *doc, pdf_obj *field, pdf_obj *col) } } -fz_rect *fz_widget_bbox(fz_widget *widget) +fz_rect fz_widget_bbox(fz_widget *widget) { pdf_annot *annot = (pdf_annot *)widget; - return &annot->pagerect; + return annot->pagerect; } char *pdf_text_widget_text(pdf_document *doc, fz_widget *tw) diff --git a/pdf/pdf_object.c b/pdf/pdf_object.c index dba15872..9ebb4aec 100644 --- a/pdf/pdf_object.c +++ b/pdf/pdf_object.c @@ -575,7 +575,7 @@ pdf_array_contains(pdf_obj *arr, pdf_obj *obj) return 0; } -pdf_obj *pdf_new_rect(fz_context *ctx, fz_rect *rect) +pdf_obj *pdf_new_rect(fz_context *ctx, fz_rect rect) { pdf_obj *arr = NULL; pdf_obj *item = NULL; @@ -586,22 +586,22 @@ pdf_obj *pdf_new_rect(fz_context *ctx, fz_rect *rect) { arr = pdf_new_array(ctx, 4); - item = pdf_new_real(ctx, rect->x0); + item = pdf_new_real(ctx, rect.x0); pdf_array_push(arr, item); pdf_drop_obj(item); item = NULL; - item = pdf_new_real(ctx, rect->y0); + item = pdf_new_real(ctx, rect.y0); pdf_array_push(arr, item); pdf_drop_obj(item); item = NULL; - item = pdf_new_real(ctx, rect->x1); + item = pdf_new_real(ctx, rect.x1); pdf_array_push(arr, item); pdf_drop_obj(item); item = NULL; - item = pdf_new_real(ctx, rect->y1); + item = pdf_new_real(ctx, rect.y1); pdf_array_push(arr, item); pdf_drop_obj(item); item = NULL; @@ -616,7 +616,7 @@ pdf_obj *pdf_new_rect(fz_context *ctx, fz_rect *rect) return arr; } -pdf_obj *pdf_new_matrix(fz_context *ctx, fz_matrix *mtx) +pdf_obj *pdf_new_matrix(fz_context *ctx, fz_matrix mtx) { pdf_obj *arr = NULL; pdf_obj *item = NULL; @@ -627,32 +627,32 @@ pdf_obj *pdf_new_matrix(fz_context *ctx, fz_matrix *mtx) { arr = pdf_new_array(ctx, 6); - item = pdf_new_real(ctx, mtx->a); + item = pdf_new_real(ctx, mtx.a); pdf_array_push(arr, item); pdf_drop_obj(item); item = NULL; - item = pdf_new_real(ctx, mtx->b); + item = pdf_new_real(ctx, mtx.b); pdf_array_push(arr, item); pdf_drop_obj(item); item = NULL; - item = pdf_new_real(ctx, mtx->c); + item = pdf_new_real(ctx, mtx.c); pdf_array_push(arr, item); pdf_drop_obj(item); item = NULL; - item = pdf_new_real(ctx, mtx->d); + item = pdf_new_real(ctx, mtx.d); pdf_array_push(arr, item); pdf_drop_obj(item); item = NULL; - item = pdf_new_real(ctx, mtx->e); + item = pdf_new_real(ctx, mtx.e); pdf_array_push(arr, item); pdf_drop_obj(item); item = NULL; - item = pdf_new_real(ctx, mtx->f); + item = pdf_new_real(ctx, mtx.f); pdf_array_push(arr, item); pdf_drop_obj(item); item = NULL; diff --git a/pdf/pdf_xobject.c b/pdf/pdf_xobject.c index 86b45167..e236edd0 100644 --- a/pdf/pdf_xobject.c +++ b/pdf/pdf_xobject.c @@ -111,7 +111,7 @@ pdf_load_xobject(pdf_document *xref, pdf_obj *dict) } pdf_obj * -pdf_new_xobject(pdf_document *xref, fz_rect *bbox, fz_matrix *mat) +pdf_new_xobject(pdf_document *xref, fz_rect bbox, fz_matrix mat) { int idict_num; pdf_obj *idict = NULL; @@ -185,9 +185,9 @@ pdf_new_xobject(pdf_document *xref, fz_rect *bbox, fz_matrix *mat) form->me = NULL; form->iteration = 0; - form->bbox = *bbox; + form->bbox = bbox; - form->matrix = *mat; + form->matrix = mat; form->isolated = 0; form->knockout = 0; |