comparison mupdf-source/docs/examples/trace-device.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 import * as mupdf from "mupdf"
2
3 var Q = JSON.stringify
4
5 var pathPrinter = {
6 moveTo: function (x,y) { print("moveTo", x, y) },
7 lineTo: function (x,y) { print("lineTo", x, y) },
8 curveTo: function (x1,y1,x2,y2,x3,y3) { print("curveTo", x1, y1, x2, y2, x3, y3) },
9 closePath: function () { print("closePath") },
10 }
11
12 var textPrinter = {
13 beginSpan: function (f,m,wmode, bidi, dir, lang) {
14 print("beginSpan",f,m,wmode,bidi,dir,repr(lang));
15 },
16 showGlyph: function (f,m,g,u,v,b) { print("glyph",f,m,g,u,v,b) },
17 endSpan: function () { print("endSpan"); }
18 }
19
20 var traceDevice = {
21 fillPath: function (path, evenOdd, ctm, colorSpace, color, alpha) {
22 print("fillPath", evenOdd, ctm, colorSpace, color, alpha)
23 path.walk(pathPrinter)
24 },
25 clipPath: function (path, evenOdd, ctm) {
26 print("clipPath", evenOdd, ctm)
27 path.walk(pathPrinter)
28 },
29 strokePath: function (path, stroke, ctm, colorSpace, color, alpha) {
30 print("strokePath", Q(stroke), ctm, colorSpace, color, alpha)
31 path.walk(pathPrinter)
32 },
33 clipStrokePath: function (path, stroke, ctm) {
34 print("clipStrokePath", Q(stroke), ctm)
35 path.walk(pathPrinter)
36 },
37
38 fillText: function (text, ctm, colorSpace, color, alpha) {
39 print("fillText", ctm, colorSpace, color, alpha)
40 text.walk(textPrinter)
41 },
42 clipText: function (text, ctm) {
43 print("clipText", ctm)
44 text.walk(textPrinter)
45 },
46 strokeText: function (text, stroke, ctm, colorSpace, color, alpha) {
47 print("strokeText", Q(stroke), ctm, colorSpace, color, alpha)
48 text.walk(textPrinter)
49 },
50 clipStrokeText: function (text, stroke, ctm) {
51 print("clipStrokeText", Q(stroke), ctm)
52 text.walk(textPrinter)
53 },
54 ignoreText: function (text, ctm) {
55 print("ignoreText", ctm)
56 text.walk(textPrinter)
57 },
58
59 fillShade: function (shade, ctm, alpha) {
60 print("fillShade", shade, ctm, alpha)
61 },
62 fillImage: function (image, ctm, alpha) {
63 print("fillImage", image, ctm, alpha)
64 },
65 fillImageMask: function (image, ctm, colorSpace, color, alpha) {
66 print("fillImageMask", image, ctm, colorSpace, color, alpha)
67 },
68 clipImageMask: function (image, ctm) {
69 print("clipImageMask", image, ctm)
70 },
71
72 beginMask: function (area, luminosity, colorspace, color) {
73 print("beginMask", area, luminosity, colorspace, color)
74 },
75 endMask: function () {
76 print("endMask")
77 },
78
79 popClip: function () {
80 print("popClip")
81 },
82
83 beginGroup: function (area, isolated, knockout, blendmode, alpha) {
84 print("beginGroup", area, isolated, knockout, blendmode, alpha)
85 },
86 endGroup: function () {
87 print("endGroup")
88 },
89 beginTile: function (area, view, xstep, ystep, ctm, id) {
90 print("beginTile", area, view, xstep, ystep, ctm, id)
91 return 0
92 },
93 endTile: function () {
94 print("endTile")
95 },
96 beginLayer: function (name) {
97 print("beginLayer", name)
98 },
99 endLayer: function () {
100 print("endLayer")
101 },
102 beginStructure: function (structure, raw, uid) {
103 print("beginStructure", structure, raw, uiw)
104 },
105 endStructure: function () {
106 print("endStructure")
107 },
108 beginMetatext: function (meta, metatext) {
109 print("beginMetatext", meta, metatext)
110 },
111 endMetatext: function () {
112 print("endMetatext")
113 },
114
115 renderFlags: function (set, clear) {
116 print("renderFlags", set, clear)
117 },
118 setDefaultColorSpaces: function (colorSpaces) {
119 print("setDefaultColorSpaces", colorSpaces.getDefaultGray(),
120 colorSpaces.getDefaultRGB(), colorSpaces.getDefaultCMYK(),
121 colorSpaces.getOutputIntent())
122 },
123
124 close: function () {
125 print("close")
126 },
127 }
128
129 if (scriptArgs.length != 2)
130 print("usage: mutool run trace-device.js document.pdf pageNumber")
131 else {
132 var doc = mupdf.Document.openDocument(scriptArgs[0]);
133 var page = doc.loadPage(parseInt(scriptArgs[1])-1);
134 page.run(traceDevice, mupdf.Matrix.identity);
135 }