Permalink
Browse files

Fixed HeadlessException by introducing Platform.getScreenResolution().

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/batik/trunk@1076146 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
jmaerki committed Mar 2, 2011
1 parent a5e1a45 commit 6ebe0589ed267c0d25a455b22ecd03ed894be2c2
@@ -18,7 +18,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more
*/
package org.apache.batik.transcoder;
-import java.awt.Toolkit;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
@@ -32,6 +31,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import org.apache.batik.transcoder.keys.BooleanKey;
import org.apache.batik.transcoder.keys.FloatKey;
import org.apache.batik.transcoder.keys.IntegerKey;
+import org.apache.batik.util.Platform;
import org.apache.batik.util.SVGConstants;
import org.xml.sax.XMLFilter;
@@ -93,8 +93,8 @@ Licensed to the Apache Software Foundation (ASF) under one or more
public static float PIXEL_TO_MILLIMETERS;
public static float PIXEL_PER_INCH;
static {
- PIXEL_TO_MILLIMETERS = 25.4f / (float)Toolkit.getDefaultToolkit().getScreenResolution();
- PIXEL_PER_INCH = Toolkit.getDefaultToolkit().getScreenResolution();
+ PIXEL_TO_MILLIMETERS = 25.4f / (float)Platform.getScreenResolution();
+ PIXEL_PER_INCH = Platform.getScreenResolution();
}
public static final int TRANSCODER_ERROR_BASE = 0xff00;
@@ -153,7 +153,9 @@ protected Document createDocument(TranscoderOutput output) {
DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
doc = domImpl.createDocument(SVG_NAMESPACE_URI, SVG_SVG_TAG, null);
- } else doc = output.getDocument();
+ } else {
+ doc = output.getDocument();
+ }
return doc;
}
@@ -184,8 +186,9 @@ protected void writeSVGToOutput(SVGGraphics2D svgGenerator, Element svgRoot,
try {
boolean escaped = false;
- if (hints.containsKey(KEY_ESCAPED))
+ if (hints.containsKey(KEY_ESCAPED)) {
escaped = ((Boolean)hints.get(KEY_ESCAPED)).booleanValue();
+ }
// Output stream
OutputStream os = output.getOutputStream();
if (os != null) {
@@ -20,24 +20,23 @@ Licensed to the Apache Software Foundation (ASF) under one or more
package org.apache.batik.transcoder.wmf.tosvg;
import java.awt.Rectangle;
-import java.awt.Toolkit;
import java.awt.geom.Rectangle2D;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import org.apache.batik.transcoder.wmf.WMFConstants;
+import org.apache.batik.util.Platform;
/**
* This class provides a general framework to read WMF Metafiles.
* @version $Id$
*/
public abstract class AbstractWMFReader {
- // todo should be able to run in headless environment - as is written, will throw exception during init
- public static final float PIXEL_PER_INCH = Toolkit.getDefaultToolkit().getScreenResolution();
- public static final float MM_PER_PIXEL = 25.4f / Toolkit.getDefaultToolkit().getScreenResolution();
+ public static final float PIXEL_PER_INCH = Platform.getScreenResolution();
+ public static final float MM_PER_PIXEL = 25.4f / Platform.getScreenResolution();
protected int left, right, top, bottom, width, height, inch;
protected float scaleX, scaleY, scaleXY;
protected int vpW, vpH, vpX, vpY;
@@ -47,7 +46,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
protected volatile boolean bReading = false;
protected boolean isAldus = false;
- protected boolean isotropic = true;
+ protected boolean isotropic = true;
protected int mtType, mtHeaderSize, mtVersion, mtSize, mtNoObjects;
protected int mtMaxRecord, mtNoParameters;
@@ -60,7 +59,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
public AbstractWMFReader() {
scaleX = 1;
scaleY = 1;
- scaleXY = 1f;
+ scaleXY = 1f;
left = -1;
top = -1;
width = -1;
@@ -77,7 +76,7 @@ public AbstractWMFReader(int width, int height) {
this.height = height;
}
- /**
+ /**
* Read the next short (2 bytes) value in the DataInputStream.
*/
protected short readShort(DataInputStream is) throws IOException {
@@ -89,9 +88,9 @@ protected short readShort(DataInputStream is) throws IOException {
return i;
}
- /**
+ /**
* Read the next int (4 bytes) value in the DataInputStream.
- */
+ */
protected int readInt( DataInputStream is) throws IOException {
byte js[] = new byte[ 4 ];
is.readFully(js);
@@ -362,7 +361,7 @@ public void read(DataInputStream is) throws IOException {
if ( dwIsAldus == WMFConstants.META_ALDUS_APM ) {
// Read the aldus placeable header.
int key = dwIsAldus;
- isAldus = true;
+ isAldus = true;
readShort( is ); // metafile handle, always zero
left = readShort( is );
top = readShort( is );
@@ -388,14 +387,14 @@ public void read(DataInputStream is) throws IOException {
width = right - left;
height = bottom - top;
-
+
// read the beginning of the header
mtType = readShort( is );
- mtHeaderSize = readShort( is );
+ mtHeaderSize = readShort( is );
} else {
// read the beginning of the header, the first int corresponds to the first two parameters
- mtType = ((dwIsAldus << 16) >> 16);
- mtHeaderSize = dwIsAldus >> 16;
+ mtType = ((dwIsAldus << 16) >> 16);
+ mtHeaderSize = dwIsAldus >> 16;
}
mtVersion = readShort( is );
Oops, something went wrong.

0 comments on commit 6ebe058

Please sign in to comment.