summaryrefslogtreecommitdiff
path: root/source/fitz/path.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-02-18 12:03:51 +0000
committerRobin Watts <robin.watts@artifex.com>2015-02-20 15:04:48 +0000
commit77c90c54e5c311c83a50017074a663db13abfa09 (patch)
treeda6512b9bc88b5324347f3e476881f5931775be4 /source/fitz/path.c
parente9411aba2b71b67b8521f55917ab26585c464b88 (diff)
downloadmupdf-77c90c54e5c311c83a50017074a663db13abfa09.tar.xz
Add fz_trim_path and call it.
Whenever we fz_keep a path, it's an indication that we're going to be keeping the path around for a while (anod not changing it any more). We therefore take the opportunity to trim the path buffers down.
Diffstat (limited to 'source/fitz/path.c')
-rw-r--r--source/fitz/path.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/source/fitz/path.c b/source/fitz/path.c
index 8a085070..8deb85b8 100644
--- a/source/fitz/path.c
+++ b/source/fitz/path.c
@@ -20,6 +20,8 @@ fz_new_path(fz_context *ctx)
fz_path *
fz_keep_path(fz_context *ctx, fz_path *path)
{
+ if (path->refs == 1)
+ fz_trim_path(ctx, path);
return fz_keep_imp(ctx, path, &path->refs);
}
@@ -303,6 +305,20 @@ fz_transform_path(fz_context *ctx, fz_path *path, const fz_matrix *ctm)
fz_transform_point((fz_point *)&path->coords[i], ctm);
}
+void fz_trim_path(fz_context *ctx, fz_path *path)
+{
+ if (path->cmd_cap > path->cmd_len)
+ {
+ path->cmds = fz_resize_array(ctx, path->cmds, path->cmd_len, sizeof(unsigned char));
+ path->cmd_cap = path->cmd_len;
+ }
+ if (path->coord_cap > path->coord_len)
+ {
+ path->coords = fz_resize_array(ctx, path->coords, path->coord_len, sizeof(float));
+ path->coord_cap = path->coord_len;
+ }
+}
+
#ifndef NDEBUG
void
fz_print_path(fz_context *ctx, FILE *out, fz_path *path, int indent)