Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/docs/examples/pdf-trace.js @ 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 function showString(str) { | |
| 2 var out, c, i, n; | |
| 3 n = str.length; | |
| 4 if (Array.isArray(str)) { | |
| 5 out = '<'; | |
| 6 for (i = 0; i < n; ++i) { | |
| 7 c = str[i].toString(16); | |
| 8 if (c.length == 1) | |
| 9 out += '0'; | |
| 10 out += c; | |
| 11 } | |
| 12 out += '>'; | |
| 13 } else { | |
| 14 out = '('; | |
| 15 for (i = 0; i < n; ++i) { | |
| 16 c = str[i]; | |
| 17 if (c == '(' || c == ')' || c == '\\') | |
| 18 out += '\\'; | |
| 19 out += c; | |
| 20 } | |
| 21 out += ')'; | |
| 22 } | |
| 23 return out; | |
| 24 } | |
| 25 | |
| 26 function showArray(arr) { | |
| 27 return arr.join(" "); | |
| 28 } | |
| 29 | |
| 30 var traceProcessor = { | |
| 31 op_w: function (a) { print(a, "w"); }, | |
| 32 op_j: function (a) { print(a, "j"); }, | |
| 33 op_J: function (a) { print(a, "J"); }, | |
| 34 op_M: function (a) { print(a, "M"); }, | |
| 35 op_ri: function (a) { print(a, "ri"); }, | |
| 36 op_i: function (a) { print(a, "i"); }, | |
| 37 op_d: function (array, phase) { print("[" + showArray(array) + "]", phase, "d"); }, | |
| 38 op_gs: function (name, dict) { | |
| 39 print("/"+name, "gs"); | |
| 40 dict.forEach(function(v,k) { | |
| 41 print("%", k, v); | |
| 42 }); | |
| 43 }, | |
| 44 | |
| 45 op_q: function () { print("q"); }, | |
| 46 op_Q: function () { print("Q"); }, | |
| 47 op_cm: function (a,b,c,d,e,f) { print(a,b,c,d,e,f, "cm"); }, | |
| 48 | |
| 49 op_m: function (x,y) { print(x, y, "m"); }, | |
| 50 op_l: function (x,y) { print(x, y, "l"); }, | |
| 51 op_c: function (x1,y1,x2,y2,x3,y3) { print(x1,y1,x2,y2,x3,y3, "c"); }, | |
| 52 op_v: function (x2,y2,x3,y3) { print(x2,y2,x3,y3, "v"); }, | |
| 53 op_y: function (x1,y1,x3,y3) { print(x1,y1,x3,y3, "y"); }, | |
| 54 op_h: function () { print("h"); }, | |
| 55 op_re: function (x,y,w,h) { print(x,y,w,h, "re"); }, | |
| 56 | |
| 57 op_S: function () { print("S"); }, | |
| 58 op_s: function () { print("s"); }, | |
| 59 op_F: function () { print("F"); }, | |
| 60 op_f: function () { print("f"); }, | |
| 61 op_fstar: function () { print("f*"); }, | |
| 62 op_B: function () { print("B"); }, | |
| 63 op_Bstar: function () { print("B*"); }, | |
| 64 op_b: function () { print("b"); }, | |
| 65 op_bstar: function () { print("b*"); }, | |
| 66 op_n: function () { print("n"); }, | |
| 67 op_W: function () { print("W"); }, | |
| 68 op_Wstar: function () { print("W*"); }, | |
| 69 | |
| 70 op_BT: function () { print("BT"); }, | |
| 71 op_ET: function () { print("ET"); }, | |
| 72 | |
| 73 op_Tc: function (charspace) { print(charspace, "Tc"); }, | |
| 74 op_Tw: function (wordspace) { print(wordspace, "Tw"); }, | |
| 75 op_Tz: function (scale) { print(scale, "Tz"); }, | |
| 76 op_TL: function (leading) { print(leading, "TL"); }, | |
| 77 op_Tr: function (render) { print(render, "Tr"); }, | |
| 78 op_Ts: function (rise) { print(rise, "Ts"); }, | |
| 79 | |
| 80 op_Tf: function (name,size) { print("/"+name, size, "Tf"); }, | |
| 81 | |
| 82 op_Td: function (x,y) { print(x,y, "Td"); }, | |
| 83 op_TD: function (x,y) { print(x,y, "TD"); }, | |
| 84 op_Tm: function (a,b,c,d,e,f) { print(a,b,c,d,e,f, "Tm"); }, | |
| 85 op_Tstar: function () { print("T*"); }, | |
| 86 | |
| 87 op_TJ: function (text) { | |
| 88 text = text.map(function (x) { | |
| 89 if (typeof x != 'number') | |
| 90 return showString(x); | |
| 91 return x; | |
| 92 }); | |
| 93 print("[" + showArray(text) + "] TJ") | |
| 94 }, | |
| 95 op_Tj: function (text) { print(showString(text), "Tj"); }, | |
| 96 op_squote: function (text) { print(showString(text), "'"); }, | |
| 97 op_dquote: function (aw,ac,text) { print(aw, ac, showString(text), "\""); }, | |
| 98 | |
| 99 op_d0: function (wx,wy) { print(wx,wy, "d0"); }, | |
| 100 op_d1: function (wx,wy,llx,lly,urx,ury) { print(wx,wy,llx,lly,urx,ury, "d1"); }, | |
| 101 | |
| 102 op_CS: function (name,colorspace) { print("/"+name, colorspace, "CS"); }, | |
| 103 op_cs: function (name,colorspace) { print("/"+name, colorspace, "cs"); }, | |
| 104 op_SC_pattern: function (name,pattern,color) { print("/"+name, showArray(color), "SC%pattern"); }, | |
| 105 op_sc_pattern: function (name,pattern,color) { print("/"+name, showArray(color), "sc%pattern"); }, | |
| 106 op_SC_shade: function (name,shade) { print("/"+name, "SC%shade"); }, | |
| 107 op_sc_shade: function (name,shade) { print("/"+name, "sc%shade"); }, | |
| 108 op_SC_color: function (color) { print(showArray(color), "SC%color"); }, | |
| 109 op_sc_color: function (color) { print(showArray(color), "sc%color"); }, | |
| 110 op_G: function (g) { print(g, "G"); }, | |
| 111 op_g: function (g) { print(g, "g"); }, | |
| 112 op_RG: function (r,g,b) { print(r,g,b, "RG"); }, | |
| 113 op_rg: function (r,g,b) { print(r,g,b, "rg"); }, | |
| 114 op_K: function (c,m,y,k) { print(c,m,y,k, "K"); }, | |
| 115 op_k: function (c,m,y,k) { print(c,m,y,k, "k"); }, | |
| 116 | |
| 117 op_BI: function (image) { print("% BI ... ID ... EI"); }, | |
| 118 op_sh: function (name,shade) { print("/"+name, "sh"); }, | |
| 119 op_Do_image: function (name,image) { print("/"+name, "Do%image"); }, | |
| 120 op_Do_form: function (name,form,page_res) { print("/"+name, "Do%form"); }, | |
| 121 | |
| 122 op_MP: function (tag) { print("/"+tag, "MP"); }, | |
| 123 op_DP: function (tag,dict) { print("/"+tag, dict, "DP"); }, | |
| 124 op_BMC: function (tag) { print("/"+tag, "BMC"); }, | |
| 125 op_BDC: function (tag,dict) { print("/"+tag, dict, "BDC"); }, | |
| 126 op_EMC: function () { print("EMC"); }, | |
| 127 | |
| 128 op_BX: function () { print("BX"); }, | |
| 129 op_EX: function () { print("EX"); }, | |
| 130 }; | |
| 131 | |
| 132 var doc = Document.openDocument(scriptArgs[0]); | |
| 133 var page = doc.loadPage(scriptArgs[1]-1); | |
| 134 page.process(traceProcessor); |
