diff options
-rw-r--r-- | apps/jstest_main.c | 302 | ||||
-rw-r--r-- | apps/pdfapp.c | 2 | ||||
-rw-r--r-- | apps/pdfapp.h | 1 | ||||
-rw-r--r-- | win32/mujstest-v8.vcproj | 257 | ||||
-rw-r--r-- | win32/mupdf.sln | 13 |
5 files changed, 574 insertions, 1 deletions
diff --git a/apps/jstest_main.c b/apps/jstest_main.c new file mode 100644 index 00000000..69cab0b5 --- /dev/null +++ b/apps/jstest_main.c @@ -0,0 +1,302 @@ +#include "fitz.h" +#include "mupdf.h" +#include "muxps.h" +#include "mucbz.h" +#include "pdfapp.h" +#include <ctype.h> + +static pdfapp_t gapp; +static int file_open = 0; +static char filename[1024] = ""; +static char *scriptname; +static char *output; +static int shotcount = 0; + +static char getline_buffer[1024]; + +void winwarn(pdfapp_t *app, char *msg) +{ + fprintf(stderr, "warning: %s", msg); +} + +void winerror(pdfapp_t *app, char *msg) +{ + fprintf(stderr, msg); + exit(1); +} + +static char pd_filename[256] = "The file is encrypted."; +static char pd_password[256] = ""; +static char td_textinput[1024] = ""; +static int pd_okay = 0; + +char *winpassword(pdfapp_t *app, char *filename) +{ + if (pd_password[0] == 0) + return NULL; + return pd_password; +} + +char *wintextinput(pdfapp_t *app, char *inittext) +{ + if (td_textinput[0] != 0) + return td_textinput; + return inittext; +} + +void winhelp(pdfapp_t*app) +{ +} + +void winclose(pdfapp_t *app) +{ + pdfapp_close(app); + exit(0); +} + +void wincursor(pdfapp_t *app, int curs) +{ +} + +void wintitle(pdfapp_t *app, char *title) +{ +} + +void windrawrect(pdfapp_t *app, int x0, int y0, int x1, int y1) +{ +} + +void windrawstring(pdfapp_t *app, int x, int y, char *s) +{ +} + +void winresize(pdfapp_t *app, int w, int h) +{ +} + +void winrepaint(pdfapp_t *app) +{ +} + +void winrepaintsearch(pdfapp_t *app) +{ +} + +void winfullscreen(pdfapp_t *app, int state) +{ +} + +/* + * Event handling + */ + +void windocopy(pdfapp_t *app) +{ +} + +void winreloadfile(pdfapp_t *app) +{ + pdfapp_close(app); + pdfapp_open(app, filename, 1); +} + +void winopenuri(pdfapp_t *app, char *buf) +{ +} + +static void +usage(void) +{ + fprintf(stderr, "mujstest: Scriptable tester for mupdf + js\n"); + fprintf(stderr, "\nSyntax: mujstest -o <filename> <scriptfile>\n"); + fprintf(stderr, "\n<filename> should sensibly be of the form file-%d.png\n"); + fprintf(stderr, "\nscriptfile contains a list of commands:\n"); + fprintf(stderr, "\tPASSWORD <password>\tSet the password\n"); + fprintf(stderr, "\tOPEN <filename>\tOpen a file\n"); + fprintf(stderr, "\tGOTO <page>\tJump to a particular page\n"); + fprintf(stderr, "\tSCREENSHOT\tSave a screenshot\n"); + fprintf(stderr, "\tRESIZE <w> <h>\tResize the screen to a given size\n"); + fprintf(stderr, "\tCLICK <x> <y> <btn>\tClick at a given position\n"); + fprintf(stderr, "\tTEXT <string>\tSet a value to be entered\n"); + exit(1); +} + +static char * +getline(FILE *file) +{ + char c; + char *d = getline_buffer; + + /* Skip over any prefix of whitespace */ + do + { + c = fgetc(file); + } + while (isspace(c)); + + if (c < 0) + return NULL; + + do + { + *d++ = c; + c = fgetc(file); + } + while (c >= 32); + + *d = 0; + + return getline_buffer; +} + +static int +match(char **line, const char *match) +{ + char *s = *line; + + if (s == NULL) + return 0; + + while (isspace(*s)) + s++; + + while (*s == *match) + { + s++; + match++; + } + + if (*match != 0) + return 0; + + /* We matched! Skip over any whitespace */ + while (isspace(*s)) + s++; + + *line = s; + + /* Trim whitespace off the end of the line */ + /* Run to the end of the line */ + while (*s) + s++; + + /* Run back until we find where we started, or non whitespace */ + while (s != *line && isspace(s[-1])) + s--; + + /* Remove the suffix of whitespace */ + *s = 0; + + return 1; +} + +int +main(int argc, char *argv[]) +{ + fz_context *ctx; + FILE *script = NULL; + int c; + + while ((c = fz_getopt(argc, argv, "o:")) != -1) + { + switch(c) + { + case 'o': output = fz_optarg; break; + default: usage(); break; + } + } + + if (fz_optind == argc) + usage(); + + ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT); + if (!ctx) + { + fprintf(stderr, "cannot initialise context\n"); + exit(1); + } + pdfapp_init(ctx, &gapp); + gapp.scrw = 640; + gapp.scrh = 480; + + fz_try(ctx) + { + while (fz_optind < argc) + { + scriptname = argv[fz_optind++]; + script = fopen(scriptname, "rb"); + if (script == NULL) + fz_throw(ctx, "cannot open script: %s", scriptname); + + do + { + char *line = getline(script); + if (match(&line, "%")) + { + /* Comment */ + } + else if (match(&line, "PASSWORD")) + { + strcpy(pd_password, line); + } + else if (match(&line, "OPEN")) + { + if (file_open) + pdfapp_close(&gapp); + strcpy(filename, line); + pdfapp_open(&gapp, line, 0); + file_open = 1; + } + else if (match(&line, "GOTO")) + { + pdfapp_gotopage(&gapp, atoi(line)-1); + } + else if (match(&line, "SCREENSHOT")) + { + char text[1024]; + + sprintf(text, output, ++shotcount); + fz_write_png(ctx, gapp.image, text, 0); + } + else if (match(&line, "RESIZE")) + { + int w, h; + sscanf(line, "%d %d", &w, &h); + pdfapp_onresize(&gapp, w, h); + } + else if (match(&line, "CLICK")) + { + float x, y, b; + int n; + n = sscanf(line, "%f %f %d", &x, &y, &b); + if (n < 1) + x = 0.0f; + if (n < 2) + y = 0.0f; + if (n < 3) + b = 1; + /* state = 1 = transition down */ + pdfapp_onmouse(&gapp, (int)x, (int)y, b, 0, 1); + /* state = -1 = transition up */ + pdfapp_onmouse(&gapp, (int)x, (int)y, b, 0, -1); + } + else if (match(&line, "TEXT")) + { + strcpy(td_textinput, line); + } + } + while (!feof(script)); + + fclose(script); + } + } + fz_catch(ctx) + { + fprintf(stderr, "error: cannot execute '%s'\n", scriptname); + } + + if (file_open) + pdfapp_close(&gapp); + + return 0; +} diff --git a/apps/pdfapp.c b/apps/pdfapp.c index de08a1ce..c37163cf 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -412,7 +412,7 @@ static void pdfapp_gotouri(pdfapp_t *app, char *uri) winopenuri(app, uri); } -static void pdfapp_gotopage(pdfapp_t *app, int number) +void pdfapp_gotopage(pdfapp_t *app, int number) { app->isediting = 0; winrepaint(app); diff --git a/apps/pdfapp.h b/apps/pdfapp.h index bfad92bd..75030c19 100644 --- a/apps/pdfapp.h +++ b/apps/pdfapp.h @@ -114,6 +114,7 @@ void pdfapp_onkey(pdfapp_t *app, int c); void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int state); void pdfapp_oncopy(pdfapp_t *app, unsigned short *ucsbuf, int ucslen); void pdfapp_onresize(pdfapp_t *app, int w, int h); +void pdfapp_gotopage(pdfapp_t *app, int number); void pdfapp_invert(pdfapp_t *app, fz_bbox rect); void pdfapp_inverthit(pdfapp_t *app); diff --git a/win32/mujstest-v8.vcproj b/win32/mujstest-v8.vcproj new file mode 100644 index 00000000..e753392c --- /dev/null +++ b/win32/mujstest-v8.vcproj @@ -0,0 +1,257 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="mujstest-v8" + ProjectGUID="{21E28758-E4D2-4B84-8EC5-B631CEE66B30}" + RootNamespace="mupdf" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)\$(ProjectName)" + ConfigurationType="1" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="..\fitz;..\pdf;..\xps;..\cbz" + PreprocessorDefinitions="FT2_BUILD_LIBRARY;OPJ_STATIC;DEBUG=1" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + WarningLevel="3" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalOptions="/FORCE" + AdditionalDependencies="v8_base.lib v8_snapshot.lib ws2_32.lib winmm.lib" + AdditionalLibraryDirectories=""..\thirdparty\v8-3.9"" + GenerateDebugInformation="true" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)\$(ProjectName)" + ConfigurationType="1" + CharacterSet="2" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + EnableIntrinsicFunctions="true" + AdditionalIncludeDirectories="..\fitz;..\pdf;..\xps;..\cbz" + RuntimeLibrary="0" + EnableFunctionLevelLinking="true" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + GenerateDebugInformation="true" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Memento|Win32" + OutputDirectory="$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)\$(ProjectName)" + ConfigurationType="1" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="..\fitz;..\pdf;..\xps;..\cbz" + PreprocessorDefinitions="FT2_BUILD_LIBRARY;OPJ_STATIC;MEMENTO=1;DEBUG=1" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + WarningLevel="3" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + GenerateDebugInformation="true" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <File + RelativePath="..\apps\jstest_main.c" + > + </File> + <File + RelativePath="..\apps\pdfapp.c" + > + </File> + <File + RelativePath="..\apps\pdfapp.h" + > + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/win32/mupdf.sln b/win32/mupdf.sln index ef64e779..6807711f 100644 --- a/win32/mupdf.sln +++ b/win32/mupdf.sln @@ -31,6 +31,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "generated", "generated.vcpr EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libmupdf-v8", "libmupdf-v8.vcproj", "{2E5DAFDB-A060-4011-B760-32F6A3A4BC9D}" ProjectSection(ProjectDependencies) = postProject + {5F615F91-DFF8-4F05-BF48-6222B7D86519} = {5F615F91-DFF8-4F05-BF48-6222B7D86519} {A5053AA7-02E5-4903-B596-04F17AEB1526} = {A5053AA7-02E5-4903-B596-04F17AEB1526} EndProjectSection EndProject @@ -40,6 +41,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mupdf-v8", "mupdf-v8.vcproj {5EDCF4FD-0291-4FB9-8D96-D58957CA5E3C} = {5EDCF4FD-0291-4FB9-8D96-D58957CA5E3C} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mujstest-v8", "mujstest-v8.vcproj", "{21E28758-E4D2-4B84-8EC5-B631CEE66B30}" + ProjectSection(ProjectDependencies) = postProject + {5EDCF4FD-0291-4FB9-8D96-D58957CA5E3C} = {5EDCF4FD-0291-4FB9-8D96-D58957CA5E3C} + {2E5DAFDB-A060-4011-B760-32F6A3A4BC9D} = {2E5DAFDB-A060-4011-B760-32F6A3A4BC9D} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -95,6 +102,12 @@ Global {9035A4F3-4219-45A5-985D-FBF4D9609713}.Memento|Win32.Build.0 = Memento|Win32 {9035A4F3-4219-45A5-985D-FBF4D9609713}.Release|Win32.ActiveCfg = Release|Win32 {9035A4F3-4219-45A5-985D-FBF4D9609713}.Release|Win32.Build.0 = Release|Win32 + {21E28758-E4D2-4B84-8EC5-B631CEE66B30}.Debug|Win32.ActiveCfg = Debug|Win32 + {21E28758-E4D2-4B84-8EC5-B631CEE66B30}.Debug|Win32.Build.0 = Debug|Win32 + {21E28758-E4D2-4B84-8EC5-B631CEE66B30}.Memento|Win32.ActiveCfg = Memento|Win32 + {21E28758-E4D2-4B84-8EC5-B631CEE66B30}.Memento|Win32.Build.0 = Memento|Win32 + {21E28758-E4D2-4B84-8EC5-B631CEE66B30}.Release|Win32.ActiveCfg = Release|Win32 + {21E28758-E4D2-4B84-8EC5-B631CEE66B30}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE |