| 38 |
import java.io.OutputStream; |
import java.io.OutputStream; |
| 39 |
import java.io.PrintWriter; |
import java.io.PrintWriter; |
| 40 |
import java.io.StringWriter; |
import java.io.StringWriter; |
| 41 |
|
import java.net.URL; |
| 42 |
import java.util.ArrayList; |
import java.util.ArrayList; |
| 43 |
|
import java.util.Set; |
| 44 |
import java.util.logging.Level; |
import java.util.logging.Level; |
| 45 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
| 46 |
|
|
| 58 |
import jp.sourceforge.dvibrowser.dvicore.ctx.DefaultDviContext; |
import jp.sourceforge.dvibrowser.dvicore.ctx.DefaultDviContext; |
| 59 |
import jp.sourceforge.dvibrowser.dvicore.gui.swing.ViewSpec; |
import jp.sourceforge.dvibrowser.dvicore.gui.swing.ViewSpec; |
| 60 |
import jp.sourceforge.dvibrowser.dvicore.image.split.ImageFileConfig; |
import jp.sourceforge.dvibrowser.dvicore.image.split.ImageFileConfig; |
| 61 |
|
import jp.sourceforge.dvibrowser.dvicore.util.Benchmark; |
| 62 |
import jp.sourceforge.dvibrowser.dvicore.util.DviUtils; |
import jp.sourceforge.dvibrowser.dvicore.util.DviUtils; |
| 63 |
import jp.sourceforge.dvibrowser.dvicore.util.ZipBuilder; |
import jp.sourceforge.dvibrowser.dvicore.util.ZipBuilder; |
| 64 |
|
|
| 69 |
private static final String OPT_SHRINK_FACTOR = "--shrink-factor="; |
private static final String OPT_SHRINK_FACTOR = "--shrink-factor="; |
| 70 |
private static final String OPT_DPI = "--dpi="; |
private static final String OPT_DPI = "--dpi="; |
| 71 |
private static final String OPT_OUTPUT_FILE = "--output-file="; |
private static final String OPT_OUTPUT_FILE = "--output-file="; |
| 72 |
|
private static final String OPT_RESOURCES_FILE = "--resources-file="; |
| 73 |
private static final String OPT_PAPER_SIZE = "--paper-size="; |
private static final String OPT_PAPER_SIZE = "--paper-size="; |
| 74 |
private static final String OPT_USE_BBOX = "--use-bbox="; |
private static final String OPT_USE_BBOX = "--use-bbox="; |
| 75 |
private static final String OPT_PADDING = "--padding="; |
private static final String OPT_PADDING = "--padding="; |
| 86 |
private DviPaperSize paperSize; |
private DviPaperSize paperSize; |
| 87 |
private ImageFileConfig imageFileConfig; |
private ImageFileConfig imageFileConfig; |
| 88 |
private int padding; |
private int padding; |
| 89 |
|
private File resourcesFile; |
| 90 |
|
|
| 91 |
public Config(DviContextSupport dcs) { |
public Config(DviContextSupport dcs) { |
| 92 |
super(dcs); |
super(dcs); |
| 172 |
if (paperSize == null) { |
if (paperSize == null) { |
| 173 |
throw new DviException("Unrecognized papersize: " + s); |
throw new DviException("Unrecognized papersize: " + s); |
| 174 |
} |
} |
| 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 |
|
} |
| 182 |
} else if (a.startsWith(OPT_OUTPUT_FILE)) { |
} else if (a.startsWith(OPT_OUTPUT_FILE)) { |
| 183 |
String s = a.substring(OPT_OUTPUT_FILE.length()).trim(); |
String s = a.substring(OPT_OUTPUT_FILE.length()).trim(); |
| 184 |
if (!"".equals(s)) { |
if (!"".equals(s)) { |
| 206 |
} |
} |
| 207 |
} |
} |
| 208 |
|
|
| 209 |
private void setPaddingSize(int padding) { |
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) { |
| 218 |
this.setPadding(padding); |
this.setPadding(padding); |
| 219 |
} |
} |
| 220 |
|
|
| 240 |
pw.println(" --dpi=N Set output DPI to N"); |
pw.println(" --dpi=N Set output DPI to N"); |
| 241 |
pw.println(" --shrink-factor=N Set shrink factor to N (1--1024)"); |
pw.println(" --shrink-factor=N Set shrink factor to N (1--1024)"); |
| 242 |
pw.println(" --output-file=F Set output zip file to F"); |
pw.println(" --output-file=F Set output zip file to F"); |
| 243 |
|
pw.println(" --resources-file=F Set resources file to F"); |
| 244 |
pw.println(" --padding=N Set padding size to N"); |
pw.println(" --padding=N Set padding size to N"); |
| 245 |
return sw.toString(); |
return sw.toString(); |
| 246 |
} |
} |
| 334 |
public static void main(String[] args) |
public static void main(String[] args) |
| 335 |
{ |
{ |
| 336 |
try { |
try { |
| 337 |
DviContext ctx = new DefaultDviContext(); |
DefaultDviContext ctx = new DefaultDviContext(); |
| 338 |
|
|
| 339 |
Config config = new Config(ctx); |
Config config = new Config(ctx); |
| 340 |
config.parseArguments(args); |
config.parseArguments(args); |
| 341 |
|
|
| 345 |
("Unrecognized command line: " + DviUtils.join(" ", args)); |
("Unrecognized command line: " + DviUtils.join(" ", args)); |
| 346 |
} |
} |
| 347 |
|
|
| 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(); |
| 357 |
ConvertToImage app = new ConvertToImage(ctx); |
ConvertToImage app = new ConvertToImage(ctx); |
| 358 |
int retcode = app.convert(config); |
int retcode = app.convert(config); |
| 359 |
|
benchmark.end(); |
| 360 |
|
|
| 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."); |
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. |
| 376 |
System.exit(retcode); |
System.exit(retcode); |
| 377 |
} catch (Exception e) { |
} catch (Exception e) { |
| 378 |
DviUtils.logStackTrace(LOGGER, Level.WARNING, e); |
DviUtils.logStackTrace(LOGGER, Level.WARNING, e); |