View | Details | Raw Unified | Return to bug 42408
Collapse All | Expand All

(-)wmf/tosvg/WMFHeaderProperties.java (-14 / +14 lines)
Lines 529-538 Link Here
529
                    readShort( is ); // sx
529
                    readShort( is ); // sx
530
                    float heightDst = (float)readShort( is );
530
                    float heightDst = (float)readShort( is );
531
                    float widthDst = (float)readShort( is ) * scaleXY;       
531
                    float widthDst = (float)readShort( is ) * scaleXY;       
532
                    float dy = (float)readShort( is ) * getVpWFactor() * (float)inch / PIXEL_PER_INCH;
532
                    float dy = (float)readShort( is ) * getVpWFactor() * (float)inch / pixelPerInch;
533
                    float dx = (float)readShort( is ) * getVpWFactor() * (float)inch / PIXEL_PER_INCH * scaleXY; 
533
                    float dx = (float)readShort( is ) * getVpWFactor() * (float)inch / pixelPerInch * scaleXY; 
534
                    widthDst = widthDst * getVpWFactor() * (float)inch / PIXEL_PER_INCH;
534
                    widthDst = widthDst * getVpWFactor() * (float)inch / pixelPerInch;
535
                    heightDst = heightDst * getVpHFactor() * (float)inch / PIXEL_PER_INCH;
535
                    heightDst = heightDst * getVpHFactor() * (float)inch / pixelPerInch;
536
                    resizeImageBounds((int)dx, (int)dy);
536
                    resizeImageBounds((int)dx, (int)dy);
537
                    resizeImageBounds((int)(dx + widthDst), (int)(dy + heightDst));
537
                    resizeImageBounds((int)(dx + widthDst), (int)(dy + heightDst));
538
538
Lines 549-558 Link Here
549
                readShort( is ); // sx
549
                readShort( is ); // sx
550
                float heightDst = (float)readShort( is );
550
                float heightDst = (float)readShort( is );
551
                float widthDst = (float)readShort( is ) * scaleXY;                    
551
                float widthDst = (float)readShort( is ) * scaleXY;                    
552
                float dy = (float)readShort( is ) * getVpHFactor() * (float)inch / PIXEL_PER_INCH;                                         
552
                float dy = (float)readShort( is ) * getVpHFactor() * (float)inch / pixelPerInch;                                         
553
                float dx = (float)readShort( is ) * getVpHFactor() * (float)inch / PIXEL_PER_INCH * scaleXY;  
553
                float dx = (float)readShort( is ) * getVpHFactor() * (float)inch / pixelPerInch * scaleXY;  
554
                widthDst = widthDst * getVpWFactor() * (float)inch / PIXEL_PER_INCH;
554
                widthDst = widthDst * getVpWFactor() * (float)inch / pixelPerInch;
555
                heightDst = heightDst * getVpHFactor() * (float)inch / PIXEL_PER_INCH;                                            
555
                heightDst = heightDst * getVpHFactor() * (float)inch / pixelPerInch;                                            
556
                resizeImageBounds((int)dx, (int)dy);
556
                resizeImageBounds((int)dx, (int)dy);
557
                resizeImageBounds((int)(dx + widthDst), (int)(dy + heightDst));                
557
                resizeImageBounds((int)(dx + widthDst), (int)(dy + heightDst));                
558
558
Lines 567-579 Link Here
567
                readShort( is ); //sx
567
                readShort( is ); //sx
568
                readShort( is ); // hdc
568
                readShort( is ); // hdc
569
                float height = readShort( is ) 
569
                float height = readShort( is ) 
570
                    * (float)inch / PIXEL_PER_INCH * getVpHFactor();
570
                    * (float)inch / pixelPerInch * getVpHFactor();
571
                float width = readShort( is ) 
571
                float width = readShort( is ) 
572
                    * (float)inch / PIXEL_PER_INCH * getVpWFactor() * scaleXY;
572
                    * (float)inch / pixelPerInch * getVpWFactor() * scaleXY;
573
                float dy = 
573
                float dy = 
574
                    (float)inch / PIXEL_PER_INCH * getVpHFactor() * readShort( is );
574
                    (float)inch / pixelPerInch * getVpHFactor() * readShort( is );
575
                float dx = 
575
                float dx = 
576
                    (float)inch / PIXEL_PER_INCH * getVpWFactor() * readShort( is ) * scaleXY;
576
                    (float)inch / pixelPerInch * getVpWFactor() * readShort( is ) * scaleXY;
577
                resizeImageBounds((int)dx, (int)dy);
577
                resizeImageBounds((int)dx, (int)dy);
578
                resizeImageBounds((int)(dx + width), (int)(dy + height));                        
578
                resizeImageBounds((int)(dx + width), (int)(dy + height));                        
579
                }
579
                }
Lines 617-630 Link Here
617
     * the Metafile, in Metafile Units.
617
     * the Metafile, in Metafile Units.
618
     */
618
     */
619
    public int getWidthBoundsUnits() {
619
    public int getWidthBoundsUnits() {
620
        return (int)((float)inch * (float)_bwidth / PIXEL_PER_INCH);
620
        return (int)((float)inch * (float)_bwidth / pixelPerInch);
621
    }
621
    }
622
622
623
    /** @return the height of the Rectangle bounding the figures enclosed in
623
    /** @return the height of the Rectangle bounding the figures enclosed in
624
     * the Metafile in Metafile Units.
624
     * the Metafile in Metafile Units.
625
     */
625
     */
626
    public int getHeightBoundsUnits() {
626
    public int getHeightBoundsUnits() {
627
        return (int)((float)inch * (float)_bheight / PIXEL_PER_INCH);
627
        return (int)((float)inch * (float)_bheight / pixelPerInch);
628
    }
628
    }
629
629
630
    /** @return the X offset of the Rectangle bounding the figures enclosed in
630
    /** @return the X offset of the Rectangle bounding the figures enclosed in
(-)wmf/tosvg/AbstractWMFReader.java (-17 / +38 lines)
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
(-)wmf/tosvg/WMFPainter.java (-3 / +1 lines)
Lines 29-35 Link Here
29
import java.awt.Shape;
29
import java.awt.Shape;
30
import java.awt.Stroke;
30
import java.awt.Stroke;
31
import java.awt.TexturePaint;
31
import java.awt.TexturePaint;
32
import java.awt.Toolkit;
33
import java.awt.font.FontRenderContext;
32
import java.awt.font.FontRenderContext;
34
import java.awt.font.TextLayout;
33
import java.awt.font.TextLayout;
35
import java.awt.geom.AffineTransform;
34
import java.awt.geom.AffineTransform;
Lines 1064-1071 Link Here
1064
        float _width;
1063
        float _width;
1065
        if (penWidth == 0) _width = 1;
1064
        if (penWidth == 0) _width = 1;
1066
        else _width = penWidth;
1065
        else _width = penWidth;
1067
        float _scale = (float)Toolkit.getDefaultToolkit().getScreenResolution() /
1066
        float _scale = currentStore.getPixelPerInch() / currentStore.getMetaFileUnitsPerInch();
1068
            currentStore.getMetaFileUnitsPerInch();
1069
        // need to do this, to put the width in sync with the general scale of the image
1067
        // need to do this, to put the width in sync with the general scale of the image
1070
        float factor = scale  / _scale;
1068
        float factor = scale  / _scale;
1071
        _width = _width * _scale * factor;
1069
        _width = _width * _scale * factor;
(-)wmf/tosvg/WMFTranscoder.java (-2 / +16 lines)
Lines 76-91 Link Here
76
 *  of this portion in Metafile units.
76
 *  of this portion in Metafile units.
77
 *  </ul>
77
 *  </ul>
78
 *  <pre>
78
 *  <pre>
79
 *     transcoder.addTranscodingHint(FromWMFTranscoder.KEY_INPUT_WIDTH, new Integer(input_width));
79
 *     transcoder.addTranscodingHint(WMFTranscoder.KEY_INPUT_WIDTH, new Integer(input_width));
80
 *  </pre>
80
 *  </pre>
81
 *  </li>
81
 *  </li>
82
 *  <li>KEY_WIDTH, KEY_HEIGHT : this Float values allows to force the width and height of the output:
82
 *  <li>KEY_WIDTH, KEY_HEIGHT : this Float values allows to force the width and height of the output:
83
 *  </ul>
83
 *  </ul>
84
 *  <pre>
84
 *  <pre>
85
 *     transcoder.addTranscodingHint(FromWMFTranscoder.KEY_WIDTH, new Float(width));
85
 *     transcoder.addTranscodingHint(WMFTranscoder.KEY_WIDTH, new Float(width));
86
 *  </pre>
86
 *  </pre>
87
 *  </li>
87
 *  </li>
88
 *  <li>KEY_OUTPUT_RESOLUTION : dot-per-inch resolution, useful for headless transcoding:
88
 *  </ul>
89
 *  </ul>
90
 *  <pre>
91
 *     transcoder.addTranscodingHint(WMFTranscoder.KEY_OUTPUT_RESOLUTION, new Float(resol));
92
 *  </pre>
93
 *  </li>
94
 *  </ul>
89
 *
95
 *
90
 * @version $Id$
96
 * @version $Id$
91
 */
97
 */
Lines 114-119 Link Here
114
        // Build a RecordStore from the input
120
        // Build a RecordStore from the input
115
        //
121
        //
116
        WMFRecordStore currentStore = new WMFRecordStore();
122
        WMFRecordStore currentStore = new WMFRecordStore();
123
        
124
        // set the resolution if associated key is defined
125
        if (hints.containsKey(KEY_OUTPUT_RESOLUTION)) {
126
            float dotperinch = ((Float)hints.get(KEY_OUTPUT_RESOLUTION)).floatValue(); 
127
            currentStore.setPixelPerInch(dotperinch);
128
        }
129
        
130
        // read the input
117
        try {
131
        try {
118
            currentStore.read(is);
132
            currentStore.read(is);
119
        } catch (IOException e){
133
        } catch (IOException e){
(-)ToSVGAbstractTranscoder.java (-8 / +6 lines)
Lines 18-24 Link Here
18
 */
18
 */
19
package org.apache.batik.transcoder;
19
package org.apache.batik.transcoder;
20
20
21
import java.awt.Toolkit;
22
import java.io.IOException;
21
import java.io.IOException;
23
import java.io.OutputStream;
22
import java.io.OutputStream;
24
import java.io.OutputStreamWriter;
23
import java.io.OutputStreamWriter;
Lines 90-102 Link Here
90
public abstract class ToSVGAbstractTranscoder extends AbstractTranscoder
89
public abstract class ToSVGAbstractTranscoder extends AbstractTranscoder
91
    implements SVGConstants {
90
    implements SVGConstants {
92
91
93
    public static float PIXEL_TO_MILLIMETERS;
94
    public static float PIXEL_PER_INCH;
95
    static {
96
        PIXEL_TO_MILLIMETERS = 25.4f /  (float)Toolkit.getDefaultToolkit().getScreenResolution();
97
        PIXEL_PER_INCH = Toolkit.getDefaultToolkit().getScreenResolution();
98
    }
99
100
    public static final int TRANSCODER_ERROR_BASE = 0xff00;
92
    public static final int TRANSCODER_ERROR_BASE = 0xff00;
101
    public static final int ERROR_NULL_INPUT = TRANSCODER_ERROR_BASE + 0;
93
    public static final int ERROR_NULL_INPUT = TRANSCODER_ERROR_BASE + 0;
102
    public static final int ERROR_INCOMPATIBLE_INPUT_TYPE = TRANSCODER_ERROR_BASE + 1;
94
    public static final int ERROR_INCOMPATIBLE_INPUT_TYPE = TRANSCODER_ERROR_BASE + 1;
Lines 131-136 Link Here
131
     */
123
     */
132
    public static final TranscodingHints.Key KEY_YOFFSET
124
    public static final TranscodingHints.Key KEY_YOFFSET
133
        = new IntegerKey();
125
        = new IntegerKey();
126
    
127
    /* Keys definition : output resolution (in dots-per-inchs). Best to be equal to the
128
     * screen resolution.
129
     */
130
    public static final TranscodingHints.Key KEY_OUTPUT_RESOLUTION
131
        = new FloatKey();    
134
132
135
    /* Keys definition : Define if the characters will be escaped in the output.
133
    /* Keys definition : Define if the characters will be escaped in the output.
136
     */
134
     */

Return to bug 42408