comparison mupdf-source/platform/java/example/TraceDevice.java @ 3:2c135c81b16c

MERGE: upstream PyMuPDF 1.26.4 with MuPDF 1.26.7
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:44:09 +0200
parents b50eed0cc0ef
children
comparison
equal deleted inserted replaced
0:6015a75abc2d 3:2c135c81b16c
1 // Copyright (C) 2004-2023 Artifex Software, Inc.
2 //
3 // This file is part of MuPDF.
4 //
5 // MuPDF is free software: you can redistribute it and/or modify it under the
6 // terms of the GNU Affero General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or (at your option)
8 // any later version.
9 //
10 // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Affero General Public License
16 // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
17 //
18 // Alternative licensing terms are available from the licensor.
19 // For commercial licensing, see <https://www.artifex.com/> or contact
20 // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
21 // CA 94129, USA, for further information.
22
23 package example;
24
25 import com.artifex.mupdf.fitz.*;
26
27 public class TraceDevice extends Device implements PathWalker, TextWalker
28 {
29 public String traceColor(ColorSpace cs, float[] color, float alpha) {
30 String s = cs + " [";
31 int i;
32 for (i = 0; i < color.length; ++i) {
33 if (i > 0) s += " ";
34 s += color[i];
35 }
36 return s + "] " + alpha;
37 }
38 public String traceStroke(StrokeState stroke) {
39 return "c=" + stroke.getStartCap() + "," + stroke.getDashCap() + "," + stroke.getEndCap() +
40 " j=" + stroke.getLineJoin() +
41 " m=" + stroke.getMiterLimit() +
42 " l=" + stroke.getLineWidth();
43 }
44
45 public void moveTo(float x, float y) {
46 System.out.println("moveto " + x + " " + y);
47 }
48
49 public void lineTo(float x, float y) {
50 System.out.println("lineto " + x + " " + y);
51 }
52
53 public void curveTo(float cx1, float cy1, float cx2, float cy2, float ex, float ey) {
54 System.out.println("curveto " + cx1 + " " + cy1 + " " + cx2 + " " + cy2 + " " + ex + " " + ey);
55 }
56
57 public void closePath() {
58 System.out.println("closepath");
59 }
60
61 public void showGlyph(Font font, Matrix trm, int glyph, int unicode, boolean wmode) {
62 System.out.println("glyph '" + (char)unicode + "' " + glyph + "\t" + font + " " + trm);
63 }
64
65 public void tracePath(Path path) {
66 path.walk(this);
67 }
68
69 public void traceText(Text text) {
70 text.walk(this);
71 }
72
73 public void close() {
74 }
75
76 public void fillPath(Path path, boolean evenOdd, Matrix ctm, ColorSpace cs, float[] color, float alpha, int cp) {
77 System.out.println("fillPath " + evenOdd + " " + ctm + " " + traceColor(cs, color, alpha));
78 tracePath(path);
79 }
80
81 public void strokePath(Path path, StrokeState stroke, Matrix ctm, ColorSpace cs, float[] color, float alpha, int cp) {
82 System.out.println("strokePath " + traceStroke(stroke) + " " + ctm + " " + traceColor(cs, color, alpha));
83 tracePath(path);
84 }
85
86 public void clipPath(Path path, boolean evenOdd, Matrix ctm) {
87 System.out.println("clipPath " + evenOdd + " " + ctm);
88 tracePath(path);
89 }
90
91 public void clipStrokePath(Path path, StrokeState stroke, Matrix ctm) {
92 System.out.println("clipStrokePath " + traceStroke(stroke) + " " + ctm);
93 tracePath(path);
94 }
95
96 public void fillText(Text text, Matrix ctm, ColorSpace cs, float[] color, float alpha, int cp) {
97 System.out.println("fillText " + ctm + " " + traceColor(cs, color, alpha));
98 traceText(text);
99 }
100
101 public void strokeText(Text text, StrokeState stroke, Matrix ctm, ColorSpace cs, float[] color, float alpha, int cp) {
102 System.out.println("strokeText " + ctm + " " + traceStroke(stroke) + " " + traceColor(cs, color, alpha));
103 traceText(text);
104 }
105
106 public void clipText(Text text, Matrix ctm) {
107 System.out.println("clipText " + ctm);
108 traceText(text);
109 }
110
111 public void clipStrokeText(Text text, StrokeState stroke, Matrix ctm) {
112 System.out.println("clipStrokeText " + ctm + " " + traceStroke(stroke));
113 traceText(text);
114 }
115
116 public void ignoreText(Text text, Matrix ctm) {
117 System.out.println("ignoreText " + ctm);
118 traceText(text);
119 }
120
121 public void fillShade(Shade shd, Matrix ctm, float alpha, int cp) {
122 System.out.println("fillShade " + ctm + " " + alpha);
123 }
124
125 public void fillImage(Image img, Matrix ctm, float alpha, int cp) {
126 System.out.println("fillImage " + ctm + " " + alpha);
127 }
128
129 public void fillImageMask(Image img, Matrix ctm, ColorSpace cs, float[] color, float alpha, int cp) {
130 System.out.println("fillImageMask " + ctm + " " + traceColor(cs, color, alpha));
131 }
132
133 public void clipImageMask(Image img, Matrix ctm) {
134 System.out.println("clipImageMask " + ctm);
135 }
136
137 public void popClip() {
138 System.out.println("popClip");
139 }
140
141 public void beginMask(Rect rect, boolean luminosity, ColorSpace cs, float[] bc, int cp) {
142 System.out.println("beginMask r=" + rect +
143 " l=" + luminosity +
144 " " + traceColor(cs, bc, 1));
145 }
146
147 public void endMask() {
148 System.out.println("endMask");
149 }
150
151 public void beginGroup(Rect rect, ColorSpace cs, boolean isolated, boolean knockout, int blendmode, float alpha) {
152 System.out.println("beginGroup r=" + rect +
153 " i=" + isolated +
154 " k=" + knockout +
155 " bm=" + blendmode +
156 " a=" + alpha);
157 }
158
159 public void endGroup() {
160 System.out.println("endGroup");
161 }
162
163 public int beginTile(Rect area, Rect view, float xstep, float ystep, Matrix ctm, int id, int doc_id) {
164 System.out.println("beginTile");
165 return 0;
166 }
167
168 public void endTile() {
169 System.out.println("endTile");
170 }
171
172 public void renderFlags(int set, int clear) {
173 System.out.println("renderFlags set=" + set + " clear=" + clear);
174 }
175
176 public void setDefaultColorSpaces(DefaultColorSpaces dcs) {
177 System.out.println("setDefaultColorSpaces" +
178 " gray=" + dcs.getDefaultGray() +
179 " rgb=" + dcs.getDefaultRGB() +
180 " cmyk=" + dcs.getDefaultCMYK() +
181 " outputIntent=" + dcs.getOutputIntent());
182 }
183
184 public void beginLayer(String name) {
185 System.out.println("beginLayer");
186 }
187
188 public void endLayer() {
189 System.out.println("endLayer");
190 }
191
192 public void beginStructure(int standard, String raw, int uid) {
193 System.out.println("beginStructure standard=" + standard +
194 " raw=" + raw +
195 " uid=" + uid);
196 }
197
198 public void endStructure() {
199 System.out.println("endStructure");
200 }
201
202 public void beginMetatext(int meta, String text) {
203 System.out.println("beginMetatext type=" + meta +
204 " text=" + text);
205 }
206
207 public void endMetatext() {
208 System.out.println("endMetatext");
209 }
210
211 public static void main(String[] args) {
212 Document doc = Document.openDocument("pdfref17.pdf");
213 Page page = doc.loadPage(1144);
214 TraceDevice dev = new TraceDevice();
215 page.run(dev, new Matrix());
216 }
217 }