diff options
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | javascript/util.js | 149 | ||||
-rw-r--r-- | pdf/pdf_js.c | 151 | ||||
-rw-r--r-- | scripts/cquote.c | 126 | ||||
-rw-r--r-- | win32/generate.bat | 6 | ||||
-rw-r--r-- | win32/generated.vcproj | 4 |
6 files changed, 296 insertions, 152 deletions
@@ -105,10 +105,11 @@ $(FITZ_V8_LIB) : $(addprefix $(OUT)/, $(MUCBZ_SRC:%.c=%.o)) libs: $(FITZ_LIB) $(THIRD_LIBS) libs_v8: libs $(FITZ_V8_LIB) -# --- Generated CMAP and FONT files --- +# --- Generated CMAP, FONT and JAVASCRIPT files --- CMAPDUMP := $(OUT)/cmapdump FONTDUMP := $(OUT)/fontdump +CQUOTE := $(OUT)/cquote CMAP_CNS_SRC := $(wildcard cmaps/cns/*) CMAP_GB_SRC := $(wildcard cmaps/gb/*) @@ -117,6 +118,7 @@ CMAP_KOREA_SRC := $(wildcard cmaps/korea/*) FONT_BASE14_SRC := $(wildcard fonts/*.cff) FONT_DROID_SRC := fonts/droid/DroidSans.ttf fonts/droid/DroidSansMono.ttf FONT_CJK_SRC := fonts/droid/DroidSansFallback.ttf +JAVASCRIPT_SRC := javascript/util.js $(GEN)/cmap_cns.h : $(CMAP_CNS_SRC) $(QUIET_GEN) ./$(CMAPDUMP) $@ $(CMAP_CNS_SRC) @@ -134,18 +136,24 @@ $(GEN)/font_droid.h : $(FONT_DROID_SRC) $(GEN)/font_cjk.h : $(FONT_CJK_SRC) $(QUIET_GEN) ./$(FONTDUMP) $@ $(FONT_CJK_SRC) +$(GEN)/js_util.h : $(JAVASCRIPT_SRC) + $(QUIET_GEN) ./$(CQUOTE) $@ $(JAVASCRIPT_SRC) + CMAP_HDR := $(addprefix $(GEN)/, cmap_cns.h cmap_gb.h cmap_japan.h cmap_korea.h) FONT_HDR := $(GEN)/font_base14.h $(GEN)/font_droid.h $(GEN)/font_cjk.h +JAVASCRIPT_HDR := $(GEN)/js_util.h ifeq "$(CROSSCOMPILE)" "" $(CMAP_HDR) : $(CMAPDUMP) | $(GEN) $(FONT_HDR) : $(FONTDUMP) | $(GEN) +$(JAVASCRIPT_HDR) : $(CQUOTE) | $(GEN) endif -generate: $(CMAP_HDR) $(FONT_HDR) +generate: $(CMAP_HDR) $(FONT_HDR) $(JAVASCRIPT_HDR) $(OUT)/pdf_cmap_table.o : $(CMAP_HDR) $(OUT)/pdf_fontfile.o : $(FONT_HDR) +$(OUT)/pdf_js.o : $(JAVASCRIPT_HDR) $(OUT)/cmapdump.o : pdf/pdf_cmap.c pdf/pdf_cmap_parse.c # --- Tools and Apps --- diff --git a/javascript/util.js b/javascript/util.js new file mode 100644 index 00000000..fccddf2a --- /dev/null +++ b/javascript/util.js @@ -0,0 +1,149 @@ +var border = new Array(); +border.s = "Solid"; +border.d = "Dashed"; +border.b = "Beveled"; +border.i = "Inset"; +border.u = "Underline"; +var color = new Array(); +color.transparent = [ "T" ]; +color.black = [ "G", 0]; +color.white = [ "G", 1]; +color.red = [ "RGB", 1,0,0 ]; +color.green = [ "RGB", 0,1,0 ]; +color.blue = [ "RGB", 0,0,1 ]; +color.cyan = [ "CMYK", 1,0,0,0 ]; +color.magenta = [ "CMYK", 0,1,0,0 ]; +color.yellow = [ "CMYK", 0,0,1,0 ]; +color.dkGray = [ "G", 0.25]; +color.gray = [ "G", 0.5]; +color.ltGray = [ "G", 0.75]; + +function AFNumber_Format(nDec,sepStyle,negStyle,currStyle,strCurrency,bCurrencyPrepend) +{ + var val = event.value; + var fracpart; + var intpart; + var point = sepStyle&2 ? ',' : '.'; + var separator = sepStyle&2 ? '.' : ','; + + if (/^\D*\./.test(val)) + val = '0'+val; + + var groups = val.match(/\d+/g); + + switch (groups.length) + { + case 0: + return; + case 1: + fracpart = ''; + intpart = groups[0]; + break; + default: + fracpart = groups.pop(); + intpart = groups.join(''); + break; + } + + // Remove leading zeros + intpart = intpart.replace(/^0*/,''); + if (!intpart) + intpart = '0'; + + if ((sepStyle & 1) == 0) + { + // Add the thousands sepearators: pad to length multiple of 3 with zeros, + // split into 3s, join with separator, and remove the leading zeros + intpart = new Array(2-(intpart.length+2)%3+1).join('0') + intpart; + intpart = intpart.match(/.../g).join(separator).replace(/^0*/,''); + } + + if (!intpart) + intpart = '0'; + + // Adjust fractional part to correct number of decimal places + fracpart += new Array(nDec+1).join('0'); + fracpart = fracpart.substr(0,nDec); + + if (fracpart) + intpart += point+fracpart; + + if (bCurrencyPrepend) + intpart = strCurrency+intpart; + else + intpart += strCurrency; + + if (/-/.test(val)) + { + switch (negStyle) + { + case 0: + intpart = '-'+intpart; + break; + case 1: + break; + case 2: + case 3: + intpart = '('+intpart+')'; + break; + } + } + + if (negStyle&1) + event.target.textColor = /-/.text(val) ? color.red : color.black; + + event.value = intpart; +} + +function AFSimple_Calculate(op, list) +{ + var res; + + switch (op) + { + case 'SUM': + res = 0; + break; + case 'PRD': + res = 1; + break; + case 'AVG': + res = 0; + break; + } + + if (typeof list == 'string') + list = list.split(/ *, */); + + for (var i = 0; i < list.length; i++) + { + var field = getField(list[i]); + var value = Number(field.value); + + switch (op) + { + case 'SUM': + res += value; + break; + case 'PRD': + res *= value; + break; + case 'AVG': + res += value; + break; + case 'MIN': + if (i == 0 || value < res) + res = value; + break; + case 'MAX': + if (i == 0 || value > res) + res = value; + break; + } + } + + if (op == 'AVG') + res /= list.length; + + event.value = res; +} diff --git a/pdf/pdf_js.c b/pdf/pdf_js.c index 88766bf1..a80151ac 100644 --- a/pdf/pdf_js.c +++ b/pdf/pdf_js.c @@ -279,155 +279,8 @@ static void declare_dom(pdf_js *js) static void preload_helpers(pdf_js *js) { pdf_jsimp_execute(js->imp, - "var border = new Array();\n" - "border.s = \"Solid\";\n" - "border.d = \"Dashed\";\n" - "border.b = \"Beveled\";\n" - "border.i = \"Inset\";\n" - "border.u = \"Underline\";\n" - "var color = new Array();\n" - "color.transparent = [ \"T\" ];\n" - "color.black = [ \"G\", 0];\n" - "color.white = [ \"G\", 1];\n" - "color.red = [ \"RGB\", 1,0,0 ];\n" - "color.green = [ \"RGB\", 0,1,0 ];\n" - "color.blue = [ \"RGB\", 0,0,1 ];\n" - "color.cyan = [ \"CMYK\", 1,0,0,0 ];\n" - "color.magenta = [ \"CMYK\", 0,1,0,0 ];\n" - "color.yellow = [ \"CMYK\", 0,0,1,0 ];\n" - "color.dkGray = [ \"G\", 0.25];\n" - "color.gray = [ \"G\", 0.5];\n" - "color.ltGray = [ \"G\", 0.75];\n" - "\n" - "function AFNumber_Format(nDec,sepStyle,negStyle,currStyle,strCurrency,bCurrencyPrepend)\n" - "{\n" - " var val = event.value;\n" - " var fracpart;\n" - " var intpart;\n" - " var point = sepStyle&2 ? ',' : '.';\n" - " var separator = sepStyle&2 ? '.' : ',';\n" - "\n" - " if (/^\\D*\\./.test(val))\n" - " val = '0'+val;\n" - "\n" - " var groups = val.match(/\\d+/g);\n" - "\n" - " switch (groups.length)\n" - " {\n" - " case 0:\n" - " return;\n" - " case 1:\n" - " fracpart = '';\n" - " intpart = groups[0];\n" - " break;\n" - " default:\n" - " fracpart = groups.pop();\n" - " intpart = groups.join('');\n" - " break;\n" - " }\n" - "\n" - " // Remove leading zeros\n" - " intpart = intpart.replace(/^0*/,'');\n" - " if (!intpart)\n" - " intpart = '0';\n" - "\n" - " if ((sepStyle & 1) == 0)\n" - " {\n" - " // Add the thousands sepearators: pad to length multiple of 3 with zeros,\n" - " // split into 3s, join with separator, and remove the leading zeros\n" - " intpart = new Array(2-(intpart.length+2)%3+1).join('0') + intpart;\n" - " intpart = intpart.match(/.../g).join(separator).replace(/^0*/,'');\n" - " }\n" - "\n" - " if (!intpart)\n" - " intpart = '0';\n" - "\n" - " // Adjust fractional part to correct number of decimal places\n" - " fracpart += new Array(nDec+1).join('0');\n" - " fracpart = fracpart.substr(0,nDec);\n" - "\n" - " if (fracpart)\n" - " intpart += point+fracpart;\n" - "\n" - " if (bCurrencyPrepend)\n" - " intpart = strCurrency+intpart;\n" - " else\n" - " intpart += strCurrency;\n" - "\n" - " if (/-/.test(val))\n" - " {\n" - " switch (negStyle)\n" - " {\n" - " case 0:\n" - " intpart = '-'+intpart;\n" - " break;\n" - " case 1:\n" - " break;\n" - " case 2:\n" - " case 3:\n" - " intpart = '('+intpart+')';\n" - " break;\n" - " }\n" - " }\n" - "\n" - " if (negStyle&1)\n" - " event.target.textColor = /-/.text(val) ? color.red : color.black;\n" - "\n" - " event.value = intpart;\n" - "}\n" - "\n" - "function AFSimple_Calculate(op, list)\n" - "{\n" - " var res;\n" - "\n" - " switch (op)\n" - " {\n" - " case 'SUM':\n" - " res = 0;\n" - " break;\n" - " case 'PRD':\n" - " res = 1;\n" - " break;\n" - " case 'AVG':\n" - " res = 0;\n" - " break;\n" - " }\n" - "\n" - " if (typeof list == 'string')\n" - " list = list.split(/ *, */);\n" - "\n" - " for (var i = 0; i < list.length; i++)\n" - " {\n" - " var field = getField(list[i]);\n" - " var value = Number(field.value);\n" - "\n" - " switch (op)\n" - " {\n" - " case 'SUM':\n" - " res += value;\n" - " break;\n" - " case 'PRD':\n" - " res *= value;\n" - " break;\n" - " case 'AVG':\n" - " res += value;\n" - " break;\n" - " case 'MIN':\n" - " if (i == 0 || value < res)\n" - " res = value;\n" - " break;\n" - " case 'MAX':\n" - " if (i == 0 || value > res)\n" - " res = value;\n" - " break;\n" - " }\n" - " }\n" - "\n" - " if (op == 'AVG')\n" - " res /= list.length;\n" - "\n" - " event.value = res;\n" - "}\n"); +#include "../generated/js_util.h" + ); } pdf_js *pdf_new_js(pdf_document *doc) diff --git a/scripts/cquote.c b/scripts/cquote.c new file mode 100644 index 00000000..0363574d --- /dev/null +++ b/scripts/cquote.c @@ -0,0 +1,126 @@ +/* cquote.c -- Turn the contents of a file into a quoted string */ + +#include <stdio.h> +#include <string.h> + +/* We never want to build memento versions of the cquote util */ +#undef MEMENTO + +static void +clean(char *p) +{ + while (*p) + { + if ((*p == '/') || (*p == '.') || (*p == '\\') || (*p == '-')) + *p = '_'; + p ++; + } +} + +int +main(int argc, char **argv) +{ + FILE *fi, *fo; + char name[256]; + char *realname; + int i, c; + + if (argc < 3) + { + fprintf(stderr, "usage: cquote output.c lots of text files\n"); + return 1; + } + + fo = fopen(argv[1], "wb"); + if (!fo) + { + fprintf(stderr, "cquote: could not open output file '%s'\n", argv[1]); + return 1; + } + + fprintf(fo, "/* This is an automatically generated file. Do not edit. */\n"); + + for (i = 2; i < argc; i++) + { + realname = strrchr(argv[i], '/'); + if (!realname) + realname = strrchr(argv[i], '\\'); + if (realname) + realname ++; + else + realname = argv[i]; + + if (strlen(realname) > (sizeof name - 1)) + { + fprintf(stderr, "cquote: file name too long\n"); + if (fclose(fo)) + { + fprintf(stderr, "cquote: could not close output file '%s'\n", argv[1]); + return 1; + } + return 1; + } + + strcpy(name, realname); + clean(name); + + fi = fopen(argv[i], "rb"); + + fprintf(fo, "\n/* %s */\n\n", name); + + fputc('\"', fo); + c = fgetc(fi); + while (c != EOF) + { + int eol = 0; + + switch (c) + { + case '\"': + fprintf(fo, "\\\""); + break; + + case '\\': + fprintf(fo, "\\\\"); + break; + + case '\r': + case '\n': + eol = 1; + break; + + default: + fputc(c, fo); + break; + } + + if (eol) + { + fprintf(fo, "\\n\"\n\""); + while ((c = fgetc(fi)) == '\r' || c == '\n') + ; + } + else + { + c = fgetc(fi); + } + } + + fprintf(fo, "\\n\"\n"); + + if (fclose(fo)) + { + fprintf(stderr, "cmapdump: could not close output file '%s'\n", argv[1]); + return 1; + } + + } + + if (fclose(fo)) + { + fprintf(stderr, "cmapdump: could not close output file '%s'\n", argv[1]); + return 1; + } + + return 0; +} diff --git a/win32/generate.bat b/win32/generate.bat index 0a5d7f49..168071d5 100644 --- a/win32/generate.bat +++ b/win32/generate.bat @@ -5,9 +5,11 @@ if not exist generated mkdir generated cl /nologo -Ifitz -Ipdf scripts/fontdump.c cl /nologo -Ifitz -Ipdf scripts/cmapdump.c +cl /nologo -Ifitz -Ipdf scripts/cquote.c if not exist fontdump.exe goto usage if not exist cmapdump.exe goto usage +if not exist cquote.exe goto usage if not exist generated/font_base14.h fontdump.exe generated/font_base14.h fonts/Dingbats.cff fonts/NimbusMonL-Bold.cff fonts/NimbusMonL-BoldObli.cff fonts/NimbusMonL-Regu.cff fonts/NimbusMonL-ReguObli.cff fonts/NimbusRomNo9L-Medi.cff fonts/NimbusRomNo9L-MediItal.cff fonts/NimbusRomNo9L-Regu.cff fonts/NimbusRomNo9L-ReguItal.cff fonts/NimbusSanL-Bold.cff fonts/NimbusSanL-BoldItal.cff fonts/NimbusSanL-Regu.cff fonts/NimbusSanL-ReguItal.cff fonts/StandardSymL.cff @@ -23,7 +25,9 @@ if not exist generated/cmap_japan.h cmapdump.exe generated/cmap_japan.h cmaps/ja if not exist generated/cmap_korea.h cmapdump.exe generated/cmap_korea.h cmaps/korea/Adobe-Korea1-UCS2 cmaps/korea/Adobe-Korea1-0 cmaps/korea/Adobe-Korea1-1 cmaps/korea/Adobe-Korea1-2 cmaps/korea/KSC-EUC-H cmaps/korea/KSC-EUC-V cmaps/korea/KSC-H cmaps/korea/KSC-Johab-H cmaps/korea/KSC-Johab-V cmaps/korea/KSC-V cmaps/korea/KSCms-UHC-H cmaps/korea/KSCms-UHC-HW-H cmaps/korea/KSCms-UHC-HW-V cmaps/korea/KSCms-UHC-V cmaps/korea/KSCpc-EUC-H cmaps/korea/KSCpc-EUC-V cmaps/korea/UniKS-UCS2-H cmaps/korea/UniKS-UCS2-V cmaps/korea/UniKS-UTF16-H cmaps/korea/UniKS-UTF16-V -del cmapdump.obj fontdump.obj cmapdump.exe fontdump.exe +if not exist generated/js_util.h cquote.exe generated/js_util.h javascript/util.js + +del cmapdump.obj fontdump.obj cquote.obj cmapdump.exe fontdump.exe cquote.exe goto fin diff --git a/win32/generated.vcproj b/win32/generated.vcproj index e5c06f0b..a692a9d4 100644 --- a/win32/generated.vcproj +++ b/win32/generated.vcproj @@ -88,6 +88,10 @@ > </File> <File + RelativePath="..\scripts\cquote.c" + > + </File> + <File RelativePath="..\scripts\fontdump.c" > </File> |