summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-06-13 19:02:12 +0100
committerRobin Watts <robin.watts@artifex.com>2012-06-14 19:15:53 +0100
commit836d6a62162e51e7d7925773064c30ef500ded94 (patch)
tree87fc5e7d94b9ec1ba9538523f1f6c16c3cfa9707 /apps
parentf5d721764811484be4e98d7cddc5b83ae72e6277 (diff)
downloadmupdf-836d6a62162e51e7d7925773064c30ef500ded94.tar.xz
Add -j flag to mudraw; create simple mujstest scripts automatically.
We add a new fz_bound_annots function (and associated pdf_bound_annots function) that calls a given callback with the page rectangle of the annotations on a given page. This is marked as being a 'temporary' function, so we can remove it/change it in future if required. It seems likely that we'll want to have some sort of 'iterate over annotations' function eventually, and this does the job for now. Add a -j flag to mudraw that outputs a simple mujstest script. For each page with annotations, the script jumps to that page, then for each annotation on the page, it sets some text to be entered, and clicks the annotation. In the case of text fields, this will cause the text to be entered into that text field; in the case of buttons it will execute the button. At the end of each page with annotations, the script is told to snapshot the page. These test scripts are not designed to be full tests, but they do at least provide an easy way for us to generate scripts where every field in our test suite is interacted with.
Diffstat (limited to 'apps')
-rw-r--r--apps/mudraw.c59
1 files changed, 56 insertions, 3 deletions
diff --git a/apps/mudraw.c b/apps/mudraw.c
index 359b102f..ae22d23d 100644
--- a/apps/mudraw.c
+++ b/apps/mudraw.c
@@ -22,6 +22,7 @@ static int showtext = 0;
static int showtime = 0;
static int showmd5 = 0;
static int showoutline = 0;
+static int showannotrects = 0;
static int savealpha = 0;
static int uselist = 1;
static int alphabits = 8;
@@ -37,6 +38,11 @@ static fz_colorspace *colorspace;
static char *filename;
static int files = 0;
+static char *mujstest_filename = NULL;
+static FILE *mujstest_file = NULL;
+static int mujstest_page = 0;
+static int mujstest_count = 0;
+
static struct {
int count, total;
int min, max;
@@ -68,6 +74,7 @@ static void usage(void)
"\t-G gamma\tgamma correct output\n"
"\t-I\tinvert output\n"
"\t-l\tprint outline\n"
+ "\t-j -\tOutput mujstest file\n"
"\tpages\tcomma separated list of ranges\n");
exit(1);
}
@@ -97,6 +104,18 @@ static int isrange(char *s)
return 1;
}
+static void mujsannot(void *arg, fz_rect *rect)
+{
+ if (mujstest_page >= 0)
+ {
+ fprintf(mujstest_file, "GOTO %d\n", mujstest_page);
+ mujstest_page = -1;
+ }
+ fprintf(mujstest_file, "%% %0.2f %0.2f %0.2f %0.2f\n", rect->x0, rect->y0, rect->x1, rect->y1);
+ fprintf(mujstest_file, "TEXT %dTestText\n", ++mujstest_count);
+ fprintf(mujstest_file, "CLICK %0.2f %0.2f\n", (rect->x0+rect->x1)/2, (rect->y0+rect->y1)/2);
+}
+
static void drawpage(fz_context *ctx, fz_document *doc, int pagenum)
{
fz_page *page;
@@ -122,6 +141,12 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum)
fz_throw(ctx, "cannot load page %d in file '%s'", pagenum, filename);
}
+ if (mujstest_file)
+ {
+ mujstest_page = pagenum;
+ fz_bound_annots(doc, page, mujsannot, NULL);
+ }
+
if (uselist)
{
fz_try(ctx)
@@ -378,6 +403,12 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum)
fz_flush_warnings(ctx);
+ if (mujstest_file && mujstest_page < 0)
+ {
+ fprintf(mujstest_file, "SCREENSHOT\n");
+ }
+
+
if (cookie.errors)
errored = 1;
}
@@ -444,7 +475,7 @@ int main(int argc, char **argv)
fz_var(doc);
- while ((c = fz_getopt(argc, argv, "lo:p:r:R:ab:dgmtx5G:Iw:h:f")) != -1)
+ while ((c = fz_getopt(argc, argv, "lo:p:r:R:ab:dgmtx5G:Iw:h:fj:")) != -1)
{
switch (c)
{
@@ -466,6 +497,7 @@ int main(int argc, char **argv)
case 'h': height = atof(fz_optarg); break;
case 'f': fit = 1; break;
case 'I': invert++; break;
+ case 'j': mujstest_filename = fz_optarg; break;
default: usage(); break;
}
}
@@ -473,12 +505,20 @@ int main(int argc, char **argv)
if (fz_optind == argc)
usage();
- if (!showtext && !showxml && !showtime && !showmd5 && !showoutline && !output)
+ if (!showtext && !showxml && !showtime && !showmd5 && !showoutline && !output && !mujstest_filename)
{
printf("nothing to do\n");
exit(0);
}
+ if (mujstest_filename)
+ {
+ if (strcmp(mujstest_filename, "-") == 0)
+ mujstest_file = stdout;
+ else
+ mujstest_file = fopen(mujstest_filename, "wb");
+ }
+
ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT);
if (!ctx)
{
@@ -541,8 +581,18 @@ int main(int argc, char **argv)
}
if (fz_needs_password(doc))
+ {
if (!fz_authenticate_password(doc, password))
fz_throw(ctx, "cannot authenticate password: %s", filename);
+ if (mujstest_file)
+ fprintf(mujstest_file, "PASSWORD %s\n", password);
+
+ }
+
+ if (mujstest_file)
+ {
+ fprintf(mujstest_file, "OPEN %s\n", filename);
+ }
if (showxml || showtext == TEXT_XML)
printf("<document name=\"%s\">\n", filename);
@@ -550,7 +600,7 @@ int main(int argc, char **argv)
if (showoutline)
drawoutline(ctx, doc);
- if (showtext || showxml || showtime || showmd5 || output)
+ if (showtext || showxml || showtime || showmd5 || output || mujstest_file)
{
if (fz_optind == argc || !isrange(argv[fz_optind]))
drawrange(ctx, doc, "1-");
@@ -601,6 +651,9 @@ int main(int argc, char **argv)
}
}
+ if (mujstest_file && mujstest_file != stdout)
+ fclose(mujstest_file);
+
fz_free_context(ctx);
return (errored != 0);
}