Lines 19-24
Link Here
|
19 |
|
19 |
|
20 |
package org.apache.batik.transcoder.wmf.tosvg; |
20 |
package org.apache.batik.transcoder.wmf.tosvg; |
21 |
|
21 |
|
|
|
22 |
import java.awt.GraphicsEnvironment; |
22 |
import java.awt.Rectangle; |
23 |
import java.awt.Rectangle; |
23 |
import java.awt.Toolkit; |
24 |
import java.awt.Toolkit; |
24 |
import java.awt.geom.Rectangle2D; |
25 |
import java.awt.geom.Rectangle2D; |
Lines 36-43
Link Here
|
36 |
public abstract class AbstractWMFReader { |
37 |
public abstract class AbstractWMFReader { |
37 |
|
38 |
|
38 |
// todo should be able to run in headless environment - as is written, will throw exception during init |
39 |
// todo should be able to run in headless environment - as is written, will throw exception during init |
39 |
public static final float PIXEL_PER_INCH = Toolkit.getDefaultToolkit().getScreenResolution(); |
40 |
public static float pixelPerInch = 96f; |
40 |
public static final float MM_PER_PIXEL = 25.4f / Toolkit.getDefaultToolkit().getScreenResolution(); |
41 |
public static float mmPerPixel = 25.4f / pixelPerInch; |
41 |
protected int left, right, top, bottom, width, height, inch; |
42 |
protected int left, right, top, bottom, width, height, inch; |
42 |
protected float scaleX, scaleY, scaleXY; |
43 |
protected float scaleX, scaleY, scaleXY; |
43 |
protected int vpW, vpH, vpX, vpY; |
44 |
protected int vpW, vpH, vpX, vpY; |
Lines 68-81
Link Here
|
68 |
right = left + width; |
69 |
right = left + width; |
69 |
bottom = top + height; |
70 |
bottom = top + height; |
70 |
numObjects = 0; |
71 |
numObjects = 0; |
71 |
objectVector = new ArrayList(); |
72 |
objectVector = new ArrayList(); |
|
|
73 |
initializeResolution(); |
72 |
} |
74 |
} |
73 |
|
75 |
|
74 |
public AbstractWMFReader(int width, int height) { |
76 |
public AbstractWMFReader(int width, int height) { |
75 |
this(); |
77 |
this(); |
76 |
this.width = width; |
78 |
this.width = width; |
77 |
this.height = height; |
79 |
this.height = height; |
|
|
80 |
initializeResolution(); |
78 |
} |
81 |
} |
|
|
82 |
|
83 |
private void initializeResolution() { |
84 |
if (GraphicsEnvironment.isHeadless()) { |
85 |
pixelPerInch = 96f; |
86 |
} else { |
87 |
pixelPerInch = Toolkit.getDefaultToolkit().getScreenResolution(); |
88 |
} |
89 |
mmPerPixel = 25.4f / pixelPerInch; |
90 |
} |
91 |
|
92 |
public void setPixelPerInch(float pixelPerInch) { |
93 |
this.pixelPerInch = pixelPerInch; |
94 |
mmPerPixel = 25.4f / pixelPerInch; |
95 |
} |
96 |
|
97 |
public float getPixelPerInch() { |
98 |
return pixelPerInch; |
99 |
} |
79 |
|
100 |
|
80 |
/** |
101 |
/** |
81 |
* Read the next short (2 bytes) value in the DataInputStream. |
102 |
* Read the next short (2 bytes) value in the DataInputStream. |
Lines 127-153
Link Here
|
127 |
* Returns the viewport height, in inches. |
148 |
* Returns the viewport height, in inches. |
128 |
*/ |
149 |
*/ |
129 |
public float getViewportHeightInch() { |
150 |
public float getViewportHeightInch() { |
130 |
return PIXEL_PER_INCH * (float)vpH / (float)inch; |
151 |
return pixelPerInch * (float)vpH / (float)inch; |
131 |
} |
152 |
} |
132 |
|
153 |
|
133 |
/** Return the number of pixels per unit. |
154 |
/** Return the number of pixels per unit. |
134 |
*/ |
155 |
*/ |
135 |
public float getPixelsPerUnit() { |
156 |
public float getPixelsPerUnit() { |
136 |
return PIXEL_PER_INCH / (float)inch; |
157 |
return pixelPerInch / (float)inch; |
137 |
} |
158 |
} |
138 |
|
159 |
|
139 |
/** |
160 |
/** |
140 |
* Returns the viewport width, in pixels. |
161 |
* Returns the viewport width, in pixels. |
141 |
*/ |
162 |
*/ |
142 |
public int getVpW() { |
163 |
public int getVpW() { |
143 |
return (int)(PIXEL_PER_INCH * (float)vpW / (float)inch); |
164 |
return (int)(pixelPerInch * (float)vpW / (float)inch); |
144 |
} |
165 |
} |
145 |
|
166 |
|
146 |
/** |
167 |
/** |
147 |
* Returns the viewport height, in pixels. |
168 |
* Returns the viewport height, in pixels. |
148 |
*/ |
169 |
*/ |
149 |
public int getVpH() { |
170 |
public int getVpH() { |
150 |
return (int)(PIXEL_PER_INCH * (float)vpH / (float)inch); |
171 |
return (int)(pixelPerInch * (float)vpH / (float)inch); |
151 |
} |
172 |
} |
152 |
|
173 |
|
153 |
/** get the left units in the WMF Metafile. This value is given |
174 |
/** get the left units in the WMF Metafile. This value is given |
Lines 215-224
Link Here
|
215 |
/** get the Rectangle defining the viewport of the WMF Metafile, in pixels. |
236 |
/** get the Rectangle defining the viewport of the WMF Metafile, in pixels. |
216 |
*/ |
237 |
*/ |
217 |
public Rectangle2D getRectanglePixel() { |
238 |
public Rectangle2D getRectanglePixel() { |
218 |
float _left = PIXEL_PER_INCH * (float)left / (float)inch; |
239 |
float _left = pixelPerInch * (float)left / (float)inch; |
219 |
float _right = PIXEL_PER_INCH * (float)right / (float)inch; |
240 |
float _right = pixelPerInch * (float)right / (float)inch; |
220 |
float _top = PIXEL_PER_INCH * (float)top / (float)inch; |
241 |
float _top = pixelPerInch * (float)top / (float)inch; |
221 |
float _bottom = PIXEL_PER_INCH * (float)bottom / (float)inch; |
242 |
float _bottom = pixelPerInch * (float)bottom / (float)inch; |
222 |
|
243 |
|
223 |
Rectangle2D.Float rec = new Rectangle2D.Float(_left, _top, _right - _left, _bottom - _top); |
244 |
Rectangle2D.Float rec = new Rectangle2D.Float(_left, _top, _right - _left, _bottom - _top); |
224 |
|
245 |
|
Lines 241-271
Link Here
|
241 |
/** get the width of the WMF Metafile, in pixels. |
262 |
/** get the width of the WMF Metafile, in pixels. |
242 |
*/ |
263 |
*/ |
243 |
public int getWidthPixels() { |
264 |
public int getWidthPixels() { |
244 |
return (int)(PIXEL_PER_INCH * (float)width / (float)inch); |
265 |
return (int)(pixelPerInch * (float)width / (float)inch); |
245 |
} |
266 |
} |
246 |
|
267 |
|
247 |
/** get the factor to transform Metafile dimensions in pixels |
268 |
/** get the factor to transform Metafile dimensions in pixels |
248 |
*/ |
269 |
*/ |
249 |
public float getUnitsToPixels() { |
270 |
public float getUnitsToPixels() { |
250 |
return (PIXEL_PER_INCH / (float)inch); |
271 |
return (pixelPerInch / (float)inch); |
251 |
} |
272 |
} |
252 |
|
273 |
|
253 |
/** get the factor to transform logical units width in pixels |
274 |
/** get the factor to transform logical units width in pixels |
254 |
*/ |
275 |
*/ |
255 |
public float getVpWFactor() { |
276 |
public float getVpWFactor() { |
256 |
return (PIXEL_PER_INCH * (float)width / (float)inch) / (float)vpW; |
277 |
return (pixelPerInch * (float)width / (float)inch) / (float)vpW; |
257 |
} |
278 |
} |
258 |
|
279 |
|
259 |
/** get the factor to transform logical units height in pixels |
280 |
/** get the factor to transform logical units height in pixels |
260 |
*/ |
281 |
*/ |
261 |
public float getVpHFactor() { |
282 |
public float getVpHFactor() { |
262 |
return (PIXEL_PER_INCH * (float)height / (float)inch) / (float)vpH; |
283 |
return (pixelPerInch * (float)height / (float)inch) / (float)vpH; |
263 |
} |
284 |
} |
264 |
|
285 |
|
265 |
/** get the height of the WMF Metafile, in pixels. |
286 |
/** get the height of the WMF Metafile, in pixels. |
266 |
*/ |
287 |
*/ |
267 |
public int getHeightPixels() { |
288 |
public int getHeightPixels() { |
268 |
return (int)(PIXEL_PER_INCH * (float)height / (float)inch); |
289 |
return (int)(pixelPerInch * (float)height / (float)inch); |
269 |
} |
290 |
} |
270 |
|
291 |
|
271 |
/** Return the sign of X coordinates. It is equal to 1 by default, but can be -1 if |
292 |
/** Return the sign of X coordinates. It is equal to 1 by default, but can be -1 if |