• R/O
  • SSH
  • HTTPS

dvibrowser: Commit


Commit MetaInfo

Revision123 (tree)
Time2011-03-04 22:56:55
Authornagaotakeyuki

Log Message

Applet support.

Change Summary

Incremental Difference

--- dvibrowser-1.2.0/trunk/dvicore/src/main/java/jp/sourceforge/dvibrowser/dvicore/ctx/FileLocationResolver.java (revision 122)
+++ dvibrowser-1.2.0/trunk/dvicore/src/main/java/jp/sourceforge/dvibrowser/dvicore/ctx/FileLocationResolver.java (revision 123)
@@ -33,6 +33,7 @@
3333 package jp.sourceforge.dvibrowser.dvicore.ctx;
3434 import java.io.File;
3535 import java.net.URL;
36+import java.security.AccessControlException;
3637 import java.util.ArrayList;
3738 import java.util.Collection;
3839 import java.util.List;
@@ -64,7 +65,7 @@
6465 ProgressItem progress = getDviContext().getProgressRecorder().open("preparing " + filename);
6566 List<URL> list = new ArrayList<URL>();
6667 try {
67- {
68+ try {
6869 if ("true".equals(System.getProperty("dvi.ctx.DefaultDviContext.usePackageShareDir"))) {
6970 File f = new File("share", filename);
7071 if (f.exists() && f.canRead()) {
@@ -73,10 +74,12 @@
7374 return list;
7475 }
7576 }
77+ } catch (AccessControlException ex) {
78+ LOGGER.warning(ex.toString());
7679 }
7780
7881 LOGGER.finer("running kpsewhich: " + filename);
79- {
82+ try {
8083 URL url = null;
8184 KpseWhich kpseWhich = new KpseWhich(this);
8285 url = kpseWhich.findURL(filename, true);
@@ -83,17 +86,34 @@
8386 LOGGER.finer("kpsewhich result: " + filename + " => " + url);
8487 if (url != null)
8588 list.add(url);
89+ } catch (RuntimeException ex) {
90+ LOGGER.warning(ex.toString());
8691 }
8792
88- {
93+ try {
8994 URL u = ClassLoader.getSystemResource(systemResourcePath + "/"
9095 + filename);
91- LOGGER.fine("system resource by kpsewhich: " + filename + " => " + u);
96+ LOGGER.fine("system resource by classloader: " + filename + " => " + u);
9297 if (u != null)
9398 list.add(u);
99+ } catch (RuntimeException ex) {
100+ LOGGER.warning(ex.toString());
94101 }
95- } catch (RuntimeException e) {
96- LOGGER.warning(e.toString());
102+
103+ try {
104+ URL u = getClass().getResource(systemResourcePath + "/"
105+ + filename);
106+ LOGGER.fine("resource by classloader: " + filename + " => " + u);
107+ if (u != null)
108+ list.add(u);
109+ } catch (RuntimeException ex) {
110+ LOGGER.warning(ex.toString());
111+ }
112+
113+
114+ if (list.size() == 0) {
115+ LOGGER.warning("Failed to resolve file: " + filename);
116+ }
97117 } finally {
98118 progress.close();
99119 }
--- dvibrowser-1.2.0/trunk/dvicore/src/main/java/jp/sourceforge/dvibrowser/dvicore/ctx/DefaultDviContext.java (revision 122)
+++ dvibrowser-1.2.0/trunk/dvicore/src/main/java/jp/sourceforge/dvibrowser/dvicore/ctx/DefaultDviContext.java (revision 123)
@@ -35,12 +35,16 @@
3535 import java.io.File;
3636 import java.io.InputStream;
3737 import java.net.URL;
38+import java.security.AccessControlException;
3839 import java.util.Collection;
3940 import java.util.Collections;
41+import java.util.Comparator;
4042 import java.util.List;
4143 import java.util.Map;
4244 import java.util.Properties;
45+import java.util.Set;
4346 import java.util.TreeMap;
47+import java.util.TreeSet;
4448 import java.util.concurrent.ExecutionException;
4549 import java.util.concurrent.Future;
4650 import java.util.logging.Logger;
@@ -91,6 +95,13 @@
9195 private final CharacterCodeMapper characterCodeMapper
9296 = new SimpleJisToUnicodeMapper();
9397
98+ private boolean recordResources = false;
99+ private final Set<URL> resources = new TreeSet<URL>(new Comparator<URL>() {
100+ public int compare(URL arg0, URL arg1) {
101+ return arg0.toString().compareTo(arg1.toString());
102+ }
103+ });
104+
94105 private final ProgressRecorder recorder = new ProgressRecorder(this) {
95106 @Override
96107 protected boolean removeEldestElement(ManagedProgressItem item)
@@ -125,13 +136,13 @@
125136 throws DviException
126137 {
127138 File cacheDir = getCacheDirectory();
128- if (!cacheDir.exists()) {
139+ if (cacheDir != null && !cacheDir.exists()) {
129140 if (!cacheDir.mkdirs()) {
130141 throw new DviException("Failed to create cache directory: " + cacheDir);
131142 }
132143 }
133144 File tmpDir = getTemporaryDirectory();
134- if (!tmpDir.exists()) {
145+ if (tmpDir != null && !tmpDir.exists()) {
135146 if (!tmpDir.mkdirs()) {
136147 throw new DviException("Failed to create temporary directory: " + tmpDir);
137148 }
@@ -144,7 +155,11 @@
144155 try {
145156 URL url = DefaultDviContext.class.getResource("default-context.properties");
146157 Properties prop = new Properties();
147- prop.load(url.openStream());
158+ if (null != url) {
159+ prop.load(url.openStream());
160+ } else {
161+ LOGGER.warning("Failed to load default-context.properties");
162+ }
148163 return prop;
149164 } catch (Exception e) {
150165 throw new DviException(e);
@@ -319,6 +334,7 @@
319334 private static final CachedComputer<String, Collection<URL>> dviResourceComputer
320335 = new CachedComputer<String, Collection<URL>>
321336 (new ThreadedComputer<String, Collection<URL>>(1));
337+
322338 public URL getDviResource(String filename) throws DviException
323339 {
324340 if (filename.startsWith(DVICORE_INTERNAL_FILENAME_PREFIX)) {
@@ -329,12 +345,17 @@
329345 }
330346
331347 Computation<String, Collection<URL>> c
332- = new FileLocationResolver(this, "dvi/builtin", filename);
348+ = new FileLocationResolver(this, "/dvi/builtin", filename);
333349 final Future<Collection<URL>> future = dviResourceComputer.compute(c);
334350 try {
335351 final Collection<URL> list = future.get();
336352 for (URL url : list) {
337- LOGGER.finest("resolved resource: filename=" + filename + " url=" + url);
353+ if (recordResources) {
354+ LOGGER.info("resolved resource: filename=" + filename + " url=" + url);
355+ resources.add(url);
356+ } else {
357+ LOGGER.finest("resolved resource: filename=" + filename + " url=" + url);
358+ }
338359 return url;
339360 }
340361 return null;
@@ -350,17 +371,30 @@
350371 public LogicalFont mapLogicalFont(LogicalFont logicalFont)
351372 throws DviException
352373 {
353- if (logicalFont == null) return null;
354- String prefix = getClass().getName();
355- String face = getProperties().getProperty(prefix + ".fontMap." + logicalFont.fontSpec().name());
356- if (face == null) return logicalFont;
357- LogicalFont newLogicalFont = logicalFont.renameTo(face);
358- LOGGER.fine("Map logical font: " + logicalFont + " => " + newLogicalFont);
359- return newLogicalFont;
374+ LogicalFont mapped = logicalFont;
375+ if (logicalFont != null) {
376+ String prefix = getClass().getName();
377+ String faceKey = prefix + ".fontMap." + logicalFont.fontSpec().name();
378+ LOGGER.info("Face key: " + faceKey);
379+ String face = getProperties().getProperty(faceKey);
380+ LOGGER.info("Properties: " + getProperties());
381+ if (face != null) {
382+ mapped = logicalFont.renameTo(face);
383+ LOGGER.info("Rename logical font: " + logicalFont + " => " + mapped);
384+ }
385+ }
386+ LOGGER.info("Map logical font: " + logicalFont + " => " + mapped);
387+ return mapped;
360388 }
361389
390+ // N.B. System.getProperty() throws an exception when invoked
391+ // from inside an applet.
362392 private static String getSystemProperty(String key) {
363- return System.getProperty(key);
393+ try {
394+ return System.getProperty(key);
395+ } catch (AccessControlException ex) {
396+ return null;
397+ }
364398 }
365399
366400 private static final String userDir = getSystemProperty("user.dir");
@@ -370,12 +404,14 @@
370404 public File getApplicationHomeDir()
371405 throws DviException
372406 {
373- File home = new File(userDir);
374- File markFile = new File(home, "dvibrowser.jar");
375- if (markFile.exists()) {
376- // It seems that we are using DviContext from within dvibrowser.
377- return home;
378- }
407+ if (userDir != null) {
408+ File home = new File(userDir);
409+ File markFile = new File(home, "dvibrowser.jar");
410+ if (markFile.exists()) {
411+ // It seems that we are using DviContext from within dvibrowser.
412+ return home;
413+ }
414+ }
379415 return null;
380416 }
381417
@@ -384,11 +420,16 @@
384420 File appHome = getApplicationHomeDir();
385421 if (appHome == null) {
386422 File tmpDir = getTemporaryDirectory();
387- return new File(tmpDir, "cache");
423+ if (tmpDir != null) {
424+ return new File(tmpDir, "cache");
425+ }
388426 } else {
389- File var = new File(userDir, "var");
390- return new File(var, "cache");
427+ if (userDir != null) {
428+ File var = new File(userDir, "var");
429+ return new File(var, "cache");
430+ }
391431 }
432+ return null;
392433 }
393434
394435 public File getTemporaryDirectory() throws DviException
@@ -395,10 +436,13 @@
395436 {
396437 File appHome = getApplicationHomeDir();
397438 if (appHome == null) {
398- return new File(ioTmpDir, "dvicontext");
439+ if (ioTmpDir != null) {
440+ return new File(ioTmpDir, "dvicontext");
441+ }
399442 } else {
400443 return new File(appHome, "tmp");
401444 }
445+ return null;
402446 }
403447
404448 private volatile String [] ghostscriptExecutables = null;
@@ -435,4 +479,16 @@
435479 public MetafontMode getDefaultMetafontMode() throws DviException {
436480 return libraryDefaultMetafontMode;
437481 }
482+
483+public void setRecordResources(boolean recordResources) {
484+ this.recordResources = recordResources;
438485 }
486+
487+public boolean wantRecordResources() {
488+ return recordResources;
489+}
490+
491+public Set<URL> getRecordedResources() {
492+ return resources;
493+}
494+}
--- dvibrowser-1.2.0/trunk/dvicore/src/main/java/jp/sourceforge/dvibrowser/dvicore/render/IntRGBImage.java (revision 122)
+++ dvibrowser-1.2.0/trunk/dvicore/src/main/java/jp/sourceforge/dvibrowser/dvicore/render/IntRGBImage.java (revision 123)
@@ -65,6 +65,7 @@
6565
6666 public void fill(int c) {
6767 for (int i=0; i<buf.length; i++)
68+// buf[i] = 0xff000000 | c;
6869 buf[i] = c;
6970 }
7071
@@ -128,7 +129,7 @@
128129 }
129130 }
130131
131- private static int blend(int c1, int c2, final int alpha10) {
132+ private static int blendARGB(int c1, int c2, final int alpha10) {
132133 int r, g, b;
133134
134135 b = c1 & 0xff;
@@ -147,7 +148,30 @@
147148 r += (alpha10 * ((c2 & 0xff) - r)) >>> 10;
148149 r &= 0xff;
149150
150- return (r << 16) | (g << 8) | b;
151+ return 0xff000000 | (r << 16) | (g << 8) | b;
151152 }
153+
154+ private static int blend(int c1, int c2, final int alpha10) {
155+ int r, g, b;
156+
157+ b = c1 & 0xff;
158+ b += (alpha10 * ((c2 & 0xff) - b)) >>> 10;
159+ b &= 0xff;
160+ c1 >>>= 8;
161+ c2 >>>= 8;
162+
163+ g = c1 & 0xff;
164+ g += (alpha10 * ((c2 & 0xff) - g)) >>> 10;
165+ g &= 0xff;
166+ c1 >>>= 8;
167+ c2 >>>= 8;
168+
169+ r = c1 & 0xff;
170+ r += (alpha10 * ((c2 & 0xff) - r)) >>> 10;
171+ r &= 0xff;
172+
173+ return (r << 16) | (g << 8) | b;
174+ }
175+
152176 }
153177 //BenchMark: dvidump: 535 samples in 19.174 sec. 27.902 samples/sec. 35.839 msec./sample.
--- dvibrowser-1.2.0/trunk/dvicore/src/main/java/jp/sourceforge/dvibrowser/dvicore/font/AWTDynamicPkFont.java (revision 122)
+++ dvibrowser-1.2.0/trunk/dvicore/src/main/java/jp/sourceforge/dvibrowser/dvicore/font/AWTDynamicPkFont.java (revision 123)
@@ -38,6 +38,7 @@
3838 import java.awt.image.BufferedImage;
3939 import java.awt.image.DataBufferByte;
4040 import java.awt.image.Raster;
41+import java.util.logging.Logger;
4142
4243 import jp.sourceforge.dvibrowser.dvicore.DviException;
4344 import jp.sourceforge.dvibrowser.dvicore.DviFontSpec;
@@ -45,11 +46,14 @@
4546 import jp.sourceforge.dvibrowser.dvicore.DviUnit;
4647 import jp.sourceforge.dvibrowser.dvicore.api.CharacterCodeMapper;
4748 import jp.sourceforge.dvibrowser.dvicore.api.DviContextSupport;
49+import jp.sourceforge.dvibrowser.dvicore.util.DviUtils;
4850
4951
5052 public class AWTDynamicPkFont
5153 extends AbstractDynamicPkFont
5254 {
55+ private static final Logger LOGGER = Logger.getLogger(AWTDynamicPkFont.class.getName());
56+
5357 private static final long serialVersionUID = 6218737476095318238L;
5458 private final Font font;
5559 private CharacterCodeMapper mapper;
@@ -87,9 +91,10 @@
8791 throws DviException
8892 {
8993 String unicode = mapToUnicode(lf, code);
94+
95+ LOGGER.finest("str=(" + unicode + ") code=0x" + Integer.toHexString(code)
96+ + " hex=" + DviUtils.hexDump(unicode));
9097
91-// System.out.println("str=(" + unicode + ") code=0x" + Integer.toHexString(code) + " hex=" + DviUtils.hexDump(unicode));
92-
9398 Graphics2D g;
9499 BufferedImage img;
95100
--- dvibrowser-1.2.0/trunk/dvicore/src/main/java/jp/sourceforge/dvibrowser/dvicore/cli/tools/ConvertToImage.java (revision 122)
+++ dvibrowser-1.2.0/trunk/dvicore/src/main/java/jp/sourceforge/dvibrowser/dvicore/cli/tools/ConvertToImage.java (revision 123)
@@ -38,7 +38,9 @@
3838 import java.io.OutputStream;
3939 import java.io.PrintWriter;
4040 import java.io.StringWriter;
41+import java.net.URL;
4142 import java.util.ArrayList;
43+import java.util.Set;
4244 import java.util.logging.Level;
4345 import java.util.logging.Logger;
4446
@@ -56,6 +58,7 @@
5658 import jp.sourceforge.dvibrowser.dvicore.ctx.DefaultDviContext;
5759 import jp.sourceforge.dvibrowser.dvicore.gui.swing.ViewSpec;
5860 import jp.sourceforge.dvibrowser.dvicore.image.split.ImageFileConfig;
61+import jp.sourceforge.dvibrowser.dvicore.util.Benchmark;
5962 import jp.sourceforge.dvibrowser.dvicore.util.DviUtils;
6063 import jp.sourceforge.dvibrowser.dvicore.util.ZipBuilder;
6164
@@ -66,6 +69,7 @@
6669 private static final String OPT_SHRINK_FACTOR = "--shrink-factor=";
6770 private static final String OPT_DPI = "--dpi=";
6871 private static final String OPT_OUTPUT_FILE = "--output-file=";
72+ private static final String OPT_RESOURCES_FILE = "--resources-file=";
6973 private static final String OPT_PAPER_SIZE = "--paper-size=";
7074 private static final String OPT_USE_BBOX = "--use-bbox=";
7175 private static final String OPT_PADDING = "--padding=";
@@ -82,6 +86,7 @@
8286 private DviPaperSize paperSize;
8387 private ImageFileConfig imageFileConfig;
8488 private int padding;
89+ private File resourcesFile;
8590
8691 public Config(DviContextSupport dcs) {
8792 super(dcs);
@@ -167,6 +172,13 @@
167172 if (paperSize == null) {
168173 throw new DviException("Unrecognized papersize: " + s);
169174 }
175+ } else if (a.startsWith(OPT_RESOURCES_FILE)) {
176+ String s = a.substring(OPT_RESOURCES_FILE.length()).trim();
177+ if (!"".equals(s)) {
178+ setResourcesFile(new File(s));
179+ } else {
180+ throw new DviException("Output filename is empty.");
181+ }
170182 } else if (a.startsWith(OPT_OUTPUT_FILE)) {
171183 String s = a.substring(OPT_OUTPUT_FILE.length()).trim();
172184 if (!"".equals(s)) {
@@ -194,7 +206,15 @@
194206 }
195207 }
196208
197- private void setPaddingSize(int padding) {
209+ private void setResourcesFile(File file) {
210+ this.resourcesFile = file;
211+ }
212+
213+ public File getResourcesFile() {
214+ return resourcesFile;
215+ }
216+
217+ private void setPaddingSize(int padding) {
198218 this.setPadding(padding);
199219 }
200220
@@ -220,6 +240,7 @@
220240 pw.println(" --dpi=N Set output DPI to N");
221241 pw.println(" --shrink-factor=N Set shrink factor to N (1--1024)");
222242 pw.println(" --output-file=F Set output zip file to F");
243+ pw.println(" --resources-file=F Set resources file to F");
223244 pw.println(" --padding=N Set padding size to N");
224245 return sw.toString();
225246 }
@@ -313,7 +334,8 @@
313334 public static void main(String[] args)
314335 {
315336 try {
316- DviContext ctx = new DefaultDviContext();
337+ DefaultDviContext ctx = new DefaultDviContext();
338+
317339 Config config = new Config(ctx);
318340 config.parseArguments(args);
319341
@@ -323,10 +345,34 @@
323345 ("Unrecognized command line: " + DviUtils.join(" ", args));
324346 }
325347
348+ File resourcesFile = config.getResourcesFile();
349+
350+ if (resourcesFile != null) {
351+ ctx.setRecordResources(true);
352+ }
353+
354+ Benchmark benchmark = new Benchmark();
355+ benchmark.begin("dvi rendering");
356+ benchmark.addSample();
326357 ConvertToImage app = new ConvertToImage(ctx);
327358 int retcode = app.convert(config);
359+ benchmark.end();
328360
329- LOGGER.info("Finished.");
361+ if (resourcesFile != null) {
362+ Set<URL> resources = ctx.getRecordedResources();
363+ FileOutputStream fos = new FileOutputStream(resourcesFile);
364+ PrintWriter out = new PrintWriter(fos);
365+ for (URL url : resources) {
366+ out.println(url);
367+ }
368+ out.flush();
369+ out.close();
370+ fos.close();
371+ }
372+
373+ LOGGER.info("Finished: " + benchmark.format());
374+ // INT_ARGB: Finished: Benchmark result: dvi rendering: 1 samples in 68.182 sec. 0.015 samples/sec. 68182 msec./sample.
375+ // INT_RGB: Finished: Benchmark result: dvi rendering: 1 samples in 62.976 sec. 0.016 samples/sec. 62976 msec./sample.
330376 System.exit(retcode);
331377 } catch (Exception e) {
332378 DviUtils.logStackTrace(LOGGER, Level.WARNING, e);
--- dvibrowser-1.2.0/trunk/dvicore/pom.xml (revision 122)
+++ dvibrowser-1.2.0/trunk/dvicore/pom.xml (revision 123)
@@ -22,4 +22,17 @@
2222 <scope>test</scope>
2323 </dependency>
2424 </dependencies>
25+ <distributionManagement>
26+ <repository>
27+ <id>aelauth1-release</id>
28+ <name>aelauth1</name>
29+ <url>scp://aelauth1.aiit.ac.jp:49157/var/repo/maven2/release</url>
30+ </repository>
31+ <snapshotRepository>
32+ <id>aelauth1-snapshot</id>
33+ <name>aelauth1-snapshot</name>
34+ <url>scp://aelauth1.aiit.ac.jp:49157/var/repo/maven2/snapshot</url>
35+ </snapshotRepository>
36+ </distributionManagement>
37+
2538 </project>
Show on old repository browser