summaryrefslogtreecommitdiff
path: root/scripts/fontdump.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-04-06 13:39:22 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-04-06 13:39:22 +0200
commit0accac9acc379d627499db1a55743e071df892a7 (patch)
tree212b2514a1af143c67c18830c83ffec2d0dcc822 /scripts/fontdump.c
parent22ad7c043fa3e9b9f23b5ba1960b8c8d90c08f9e (diff)
downloadmupdf-0accac9acc379d627499db1a55743e071df892a7.tar.xz
Move scripts and config files into "scripts" directory.
Diffstat (limited to 'scripts/fontdump.c')
-rw-r--r--scripts/fontdump.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/scripts/fontdump.c b/scripts/fontdump.c
new file mode 100644
index 00000000..37572bea
--- /dev/null
+++ b/scripts/fontdump.c
@@ -0,0 +1,108 @@
+/* fontdump.c -- an "xxd -i" workalike for dumping binary fonts as source code */
+
+#include <stdio.h>
+#include <string.h>
+
+static int
+hexdump(FILE *fo, FILE *fi)
+{
+ int c, n;
+
+ n = 0;
+ c = fgetc(fi);
+ while (c != -1)
+ {
+ n += fprintf(fo, "%d,", c);
+ if (n > 72) {
+ fprintf(fo, "\n");
+ n = 0;
+ }
+ c = fgetc(fi);
+ }
+
+ return n;
+}
+
+int
+main(int argc, char **argv)
+{
+ FILE *fo;
+ FILE *fi;
+ char name[256];
+ char *basename;
+ char *p;
+ int i, len;
+
+ if (argc < 3)
+ {
+ fprintf(stderr, "usage: fontdump output.c input.dat\n");
+ return 1;
+ }
+
+ fo = fopen(argv[1], "wb");
+ if (!fo)
+ {
+ fprintf(stderr, "fontdump: could not open output file '%s'\n", argv[1]);
+ return 1;
+ }
+
+ fprintf(fo, "#ifndef __STRICT_ANSI__\n");
+ fprintf(fo, "#if defined(__linux__) || defined(__FreeBSD__)\n");
+ fprintf(fo, "#define HAVE_INCBIN\n");
+ fprintf(fo, "#endif\n");
+ fprintf(fo, "#endif\n\n");
+
+ for (i = 2; i < argc; i++)
+ {
+ fi = fopen(argv[i], "rb");
+ if (!fi)
+ {
+ fclose(fo);
+ fprintf(stderr, "fontdump: could not open input file '%s'\n", argv[i]);
+ return 1;
+ }
+
+ basename = strrchr(argv[i], '/');
+ if (!basename)
+ basename = strrchr(argv[i], '\\');
+ if (basename)
+ basename++;
+ else
+ basename = argv[i];
+ strcpy(name, basename);
+ p = name;
+ while (*p)
+ {
+ if ((*p == '/') || (*p == '.') || (*p == '\\') || (*p == '-'))
+ *p = '_';
+ p ++;
+ }
+
+ fseek(fi, 0, SEEK_END);
+ len = ftell(fi);
+ fseek(fi, 0, SEEK_SET);
+
+ fprintf(fo, "const unsigned int pdf_font_%s_len = %d;\n", name, len);
+
+ fprintf(fo, "#ifdef HAVE_INCBIN\n");
+ fprintf(fo, "asm(\".globl pdf_font_%s_buf\");\n", name);
+ fprintf(fo, "asm(\".balign 8\");\n");
+ fprintf(fo, "asm(\"pdf_font_%s_buf:\");\n", name);
+ fprintf(fo, "asm(\".incbin \\\"%s\\\"\");\n", argv[i]);
+ fprintf(fo, "#else\n");
+ fprintf(fo, "const unsigned char pdf_font_%s_buf[%d] = {\n", name, len);
+ hexdump(fo, fi);
+ fprintf(fo, "};\n");
+ fprintf(fo, "#endif\n\n");
+
+ fclose(fi);
+ }
+
+ if (fclose(fo))
+ {
+ fprintf(stderr, "fontdump: could not close output file '%s'\n", argv[1]);
+ return 1;
+ }
+
+ return 0;
+}