From d3e3c894673a72753ba9cea5786ab7fbff78e2e8 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 17 Feb 2014 15:46:52 +0100 Subject: Add fz_transform_point_xy to simplify transforming a point. Many times, the idiom p.x = x; p.y = y; fz_transform_point() is used. This function should simplify that use case by both initializing and transforming the point in one call. --- include/mupdf/fitz/math.h | 1 + source/fitz/font.c | 28 +++++++--------------------- source/fitz/geometry.c | 8 ++++++++ source/xps/xps-path.c | 8 ++------ 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/include/mupdf/fitz/math.h b/include/mupdf/fitz/math.h index b2a5cd4a..54c8f0c8 100644 --- a/include/mupdf/fitz/math.h +++ b/include/mupdf/fitz/math.h @@ -561,6 +561,7 @@ fz_irect *fz_translate_irect(fz_irect *a, int xoff, int yoff); Does not throw exceptions. */ fz_point *fz_transform_point(fz_point *restrict point, const fz_matrix *restrict transform); +fz_point *fz_transform_point_xy(fz_point *restrict point, const fz_matrix *restrict transform, float x, float y); /* fz_transform_vector: Apply a transformation to a vector. diff --git a/source/fitz/font.c b/source/fitz/font.c index e8c6fa00..45d75f95 100644 --- a/source/fitz/font.c +++ b/source/fitz/font.c @@ -884,9 +884,7 @@ static int move_to(const FT_Vector *p, void *cc_) fz_path *path = cc->path; fz_point pt; - pt.x = p->x; - pt.y = p->y; - fz_transform_point(&pt, &cc->trm); + fz_transform_point_xy(&pt, &cc->trm, p->x, p->y); fz_moveto(ctx, path, pt.x, pt.y); return 0; } @@ -898,9 +896,7 @@ static int line_to(const FT_Vector *p, void *cc_) fz_path *path = cc->path; fz_point pt; - pt.x = p->x; - pt.y = p->y; - fz_transform_point(&pt, &cc->trm); + fz_transform_point_xy(&pt, &cc->trm, p->x, p->y); fz_lineto(ctx, path, pt.x, pt.y); return 0; } @@ -913,12 +909,8 @@ static int conic_to(const FT_Vector *c, const FT_Vector *p, void *cc_) fz_point ct, pt; fz_point s, c1, c2; - ct.x = c->x; - ct.y = c->y; - fz_transform_point(&ct, &cc->trm); - pt.x = p->x; - pt.y = p->y; - fz_transform_point(&pt, &cc->trm); + fz_transform_point_xy(&ct, &cc->trm, c->x, c->y); + fz_transform_point_xy(&pt, &cc->trm, p->x, p->y); s = fz_currentpoint(ctx, path); c1.x = (s.x + ct.x * 2) / 3; @@ -937,15 +929,9 @@ static int cubic_to(const FT_Vector *c1, const FT_Vector *c2, const FT_Vector *p fz_path *path = cc->path; fz_point c1t, c2t, pt; - c1t.x = c1->x; - c1t.y = c1->y; - fz_transform_point(&c1t, &cc->trm); - c2t.x = c2->x; - c2t.y = c2->y; - fz_transform_point(&c2t, &cc->trm); - pt.x = p->x; - pt.y = p->y; - fz_transform_point(&pt, &cc->trm); + fz_transform_point_xy(&c1t, &cc->trm, c1->x, c1->y); + fz_transform_point_xy(&c2t, &cc->trm, c2->x, c2->y); + fz_transform_point_xy(&pt, &cc->trm, p->x, p->y); fz_curveto(ctx, path, c1t.x, c1t.y, c2t.x, c2t.y, pt.x, pt.y); return 0; diff --git a/source/fitz/geometry.c b/source/fitz/geometry.c index c7c3d198..f65373b8 100644 --- a/source/fitz/geometry.c +++ b/source/fitz/geometry.c @@ -270,6 +270,14 @@ fz_transform_point(fz_point *restrict p, const fz_matrix *restrict m) return p; } +fz_point * +fz_transform_point_xy(fz_point *restrict p, const fz_matrix *restrict m, float x, float y) +{ + p->x = x * m->a + y * m->c + m->e; + p->y = x * m->b + y * m->d + m->f; + return p; +} + fz_point * fz_transform_vector(fz_point *restrict p, const fz_matrix *restrict m) { diff --git a/source/xps/xps-path.c b/source/xps/xps-path.c index ea84a815..84ee53f0 100644 --- a/source/xps/xps-path.c +++ b/source/xps/xps-path.c @@ -58,9 +58,7 @@ xps_draw_arc_segment(fz_context *doc, fz_path *path, const fz_matrix *mtx, float { for (t = th0 + d; t < th1 - d/2; t += d) { - p.x = cosf(t); - p.y = sinf(t); - fz_transform_point(&p, mtx); + fz_transform_point_xy(&p, mtx, cosf(t), sinf(t)); fz_lineto(doc, path, p.x, p.y); } } @@ -69,9 +67,7 @@ xps_draw_arc_segment(fz_context *doc, fz_path *path, const fz_matrix *mtx, float th0 += (float)M_PI * 2; for (t = th0 - d; t > th1 + d/2; t -= d) { - p.x = cosf(t); - p.y = sinf(t); - fz_transform_point(&p, mtx); + fz_transform_point_xy(&p, mtx, cosf(t), sinf(t)); fz_lineto(doc, path, p.x, p.y); } } -- cgit v1.2.3