Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/scripts/cmapcleanz.c @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /* cmapclean.c -- parse a CMap file and write it back out */ | |
| 2 | |
| 3 #include <stdio.h> | |
| 4 #include <string.h> | |
| 5 | |
| 6 #include "mupdf/pdf.h" | |
| 7 | |
| 8 void pc(unsigned int c) | |
| 9 { | |
| 10 if (c <= 0xff) printf("<%02x>", c); | |
| 11 else if (c <= 0xffff) printf("<%04x>", c); | |
| 12 else if (c <= 0xffffff) printf("<%06x>", c); | |
| 13 else printf("<%08x>", c); | |
| 14 } | |
| 15 | |
| 16 int | |
| 17 main(int argc, char **argv) | |
| 18 { | |
| 19 fz_context *ctx; | |
| 20 fz_stream *fi; | |
| 21 pdf_cmap *cmap; | |
| 22 int k, m; | |
| 23 int ns, nr; | |
| 24 | |
| 25 if (argc != 2) | |
| 26 { | |
| 27 fprintf(stderr, "usage: cmapclean input.cmap\n"); | |
| 28 return 1; | |
| 29 } | |
| 30 | |
| 31 ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED); | |
| 32 if (!ctx) | |
| 33 { | |
| 34 fprintf(stderr, "cannot initialise context\n"); | |
| 35 return 1; | |
| 36 } | |
| 37 | |
| 38 fi = fz_open_file(ctx, argv[1]); | |
| 39 cmap = pdf_load_cmap(ctx, fi); | |
| 40 fz_drop_stream(ctx, fi); | |
| 41 | |
| 42 printf("begincmap\n"); | |
| 43 printf("/CMapName /%s def\n", cmap->cmap_name); | |
| 44 printf("/WMode %d def\n", cmap->wmode); | |
| 45 if (cmap->usecmap_name[0]) | |
| 46 printf("/%s usecmap\n", cmap->usecmap_name); | |
| 47 | |
| 48 if (cmap->codespace_len) | |
| 49 { | |
| 50 printf("begincodespacerange\n"); | |
| 51 for (k = 0; k < cmap->codespace_len; k++) | |
| 52 { | |
| 53 if (cmap->codespace[k].n == 1) | |
| 54 printf("<%02x><%02x>\n", cmap->codespace[k].low, cmap->codespace[k].high); | |
| 55 else if (cmap->codespace[k].n == 2) | |
| 56 printf("<%04x><%04x>\n", cmap->codespace[k].low, cmap->codespace[k].high); | |
| 57 else if (cmap->codespace[k].n == 3) | |
| 58 printf("<%06x><%06x>\n", cmap->codespace[k].low, cmap->codespace[k].high); | |
| 59 else if (cmap->codespace[k].n == 4) | |
| 60 printf("<%08x><%08x>\n", cmap->codespace[k].low, cmap->codespace[k].high); | |
| 61 else | |
| 62 printf("<%x><%x>\n", cmap->codespace[k].low, cmap->codespace[k].high); | |
| 63 } | |
| 64 printf("endcodespacerange\n"); | |
| 65 } | |
| 66 | |
| 67 /* 16-bit ranges */ | |
| 68 | |
| 69 ns = nr = 0; | |
| 70 for (k = 0; k < cmap->rlen; k++) | |
| 71 if (cmap->ranges[k].high - cmap->ranges[k].low > 0) | |
| 72 ++nr; | |
| 73 else | |
| 74 ++ns; | |
| 75 | |
| 76 if (ns) | |
| 77 { | |
| 78 printf("begincidchar\n"); | |
| 79 for (k = 0; k < cmap->rlen; k++) { | |
| 80 if (cmap->ranges[k].high - cmap->ranges[k].low == 0) { | |
| 81 pc(cmap->ranges[k].low); | |
| 82 printf(" %u\n", cmap->ranges[k].out); | |
| 83 } | |
| 84 } | |
| 85 printf("endcidchar\n"); | |
| 86 } | |
| 87 | |
| 88 if (nr) | |
| 89 { | |
| 90 printf("begincidrange\n"); | |
| 91 for (k = 0; k < cmap->rlen; k++) { | |
| 92 if (cmap->ranges[k].high - cmap->ranges[k].low > 0) { | |
| 93 pc(cmap->ranges[k].low); | |
| 94 putchar(' '); | |
| 95 pc(cmap->ranges[k].high); | |
| 96 printf(" %u\n", cmap->ranges[k].out); | |
| 97 } | |
| 98 } | |
| 99 printf("endcidrange\n"); | |
| 100 } | |
| 101 | |
| 102 /* 32-bit ranges */ | |
| 103 | |
| 104 ns = nr = 0; | |
| 105 for (k = 0; k < cmap->xlen; k++) | |
| 106 if (cmap->xranges[k].high - cmap->xranges[k].low > 0) | |
| 107 ++nr; | |
| 108 else | |
| 109 ++ns; | |
| 110 | |
| 111 if (ns) | |
| 112 { | |
| 113 printf("begincidchar\n"); | |
| 114 for (k = 0; k < cmap->xlen; k++) { | |
| 115 if (cmap->xranges[k].high - cmap->xranges[k].low == 0) { | |
| 116 pc(cmap->xranges[k].low); | |
| 117 printf("%u\n", cmap->xranges[k].out); | |
| 118 } | |
| 119 } | |
| 120 printf("endcidchar\n"); | |
| 121 } | |
| 122 | |
| 123 if (nr) | |
| 124 { | |
| 125 printf("begincidrange\n"); | |
| 126 for (k = 0; k < cmap->xlen; k++) { | |
| 127 if (cmap->xranges[k].high - cmap->xranges[k].low > 0) { | |
| 128 pc(cmap->xranges[k].low); | |
| 129 pc(cmap->xranges[k].high); | |
| 130 printf("%u\n", cmap->xranges[k].out); | |
| 131 } | |
| 132 } | |
| 133 printf("endcidrange\n"); | |
| 134 } | |
| 135 | |
| 136 /* 1-to-many */ | |
| 137 | |
| 138 #if 0 | |
| 139 if (cmap->mlen > 0) | |
| 140 { | |
| 141 printf("beginbfchar\n"); | |
| 142 for (k = 0; k < cmap->mlen; k++) | |
| 143 { | |
| 144 pc(cmap->mranges[k].low); | |
| 145 printf("<"); | |
| 146 for (m = 0; m < cmap->mranges[k].len; ++m) | |
| 147 printf("%04x", cmap->mranges[k].out[m]); | |
| 148 printf(">\n"); | |
| 149 } | |
| 150 printf("endbfchar\n"); | |
| 151 } | |
| 152 #endif | |
| 153 | |
| 154 printf("endcmap\n"); | |
| 155 | |
| 156 fz_drop_context(ctx); | |
| 157 return 0; | |
| 158 } |
