summaryrefslogtreecommitdiff
path: root/fitz/res_text.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-01-25 19:24:49 +0000
committerRobin Watts <robin.watts@artifex.com>2013-02-06 19:24:12 +0000
commitd3aa37962470253083714b5092a1ba759f674d47 (patch)
treeec60a0857cd3d44d3db5bc0c95aa69335b6b2d47 /fitz/res_text.c
parentc42dac496e0994c4253eb50ce67ceaec864ed379 (diff)
downloadmupdf-d3aa37962470253083714b5092a1ba759f674d47.tar.xz
Change to pass structures by reference rather than value.
This is faster on ARM in particular. The primary changes involve fz_matrix, fz_rect and fz_bbox. Rather than passing 'fz_rect r' into a function, we now consistently pass 'const fz_rect *r'. Where a rect is passed in and modified, we miss the 'const' off. Where possible, we return the pointer to the modified structure to allow 'chaining' of expressions. The basic upshot of this work is that we do far fewer copies of rectangle/matrix structures, and all the copies we do are explicit. This has opened the way to other optimisations, also performed in this commit. Rather than using expressions like: fz_concat(fz_scale(sx, sy), fz_translate(tx, ty)) we now have fz_pre_{scale,translate,rotate} functions. These can be implemented much more efficiently than doing the fully fledged matrix multiplication that fz_concat requires. We add fz_rect_{min,max} functions to return pointers to the min/max points of a rect. These can be used to in transformations to directly manipulate values. With a little casting in the path transformation code we can avoid more needless copying. We rename fz_widget_bbox to the more consistent fz_bound_widget.
Diffstat (limited to 'fitz/res_text.c')
-rw-r--r--fitz/res_text.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/fitz/res_text.c b/fitz/res_text.c
index 2bef6d4a..09a658b1 100644
--- a/fitz/res_text.c
+++ b/fitz/res_text.c
@@ -1,13 +1,13 @@
#include "fitz-internal.h"
fz_text *
-fz_new_text(fz_context *ctx, fz_font *font, fz_matrix trm, int wmode)
+fz_new_text(fz_context *ctx, fz_font *font, const fz_matrix *trm, int wmode)
{
fz_text *text;
text = fz_malloc_struct(ctx, fz_text);
text->font = fz_keep_font(ctx, font);
- text->trm = trm;
+ text->trm = *trm;
text->wmode = wmode;
text->len = 0;
text->cap = 0;
@@ -52,16 +52,18 @@ fz_clone_text(fz_context *ctx, fz_text *old)
return text;
}
-fz_rect
-fz_bound_text(fz_context *ctx, fz_text *text, fz_matrix ctm)
+fz_rect *
+fz_bound_text(fz_context *ctx, fz_text *text, const fz_matrix *ctm, fz_rect *bbox)
{
fz_matrix tm, trm;
- fz_rect bbox;
fz_rect gbox;
int i;
if (text->len == 0)
- return fz_empty_rect;
+ {
+ *bbox = fz_empty_rect;
+ return bbox;
+ }
// TODO: stroke state
@@ -69,8 +71,8 @@ fz_bound_text(fz_context *ctx, fz_text *text, fz_matrix ctm)
tm.e = text->items[0].x;
tm.f = text->items[0].y;
- trm = fz_concat(tm, ctm);
- bbox = fz_bound_glyph(ctx, text->font, text->items[0].gid, trm);
+ fz_concat(&trm, &tm, ctm);
+ fz_bound_glyph(ctx, text->font, text->items[0].gid, &trm, bbox);
for (i = 1; i < text->len; i++)
{
@@ -78,21 +80,21 @@ fz_bound_text(fz_context *ctx, fz_text *text, fz_matrix ctm)
{
tm.e = text->items[i].x;
tm.f = text->items[i].y;
- trm = fz_concat(tm, ctm);
- gbox = fz_bound_glyph(ctx, text->font, text->items[i].gid, trm);
+ fz_concat(&trm, &tm, ctm);
+ fz_bound_glyph(ctx, text->font, text->items[i].gid, &trm, &gbox);
- bbox.x0 = fz_min(bbox.x0, gbox.x0);
- bbox.y0 = fz_min(bbox.y0, gbox.y0);
- bbox.x1 = fz_max(bbox.x1, gbox.x1);
- bbox.y1 = fz_max(bbox.y1, gbox.y1);
+ bbox->x0 = fz_min(bbox->x0, gbox.x0);
+ bbox->y0 = fz_min(bbox->y0, gbox.y0);
+ bbox->x1 = fz_max(bbox->x1, gbox.x1);
+ bbox->y1 = fz_max(bbox->y1, gbox.y1);
}
}
/* Compensate for the glyph cache limited positioning precision */
- bbox.x0 -= 1;
- bbox.y0 -= 1;
- bbox.x1 += 1;
- bbox.y1 += 1;
+ bbox->x0 -= 1;
+ bbox->y0 -= 1;
+ bbox->x1 += 1;
+ bbox->y1 += 1;
return bbox;
}