Bug 44722 - WMFTranscoder/WMFPainter writes out "?" instead of numbers in resulting SVG document when attempting to convert a WMF image without a viewport width specified
Summary: WMFTranscoder/WMFPainter writes out "?" instead of numbers in resulting SVG d...
Status: NEW
Alias: None
Product: Batik - Now in Jira
Classification: Unclassified
Component: Utilities (show other bugs)
Version: 1.7
Hardware: PC Windows XP
: P1 critical
Target Milestone: ---
Assignee: Batik Developer's Mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-31 16:07 UTC by Brent Pacheco
Modified: 2009-07-05 02:19 UTC (History)
0 users



Attachments
This attachment contains a WMF witha viewport width of 0 and the resulting svg images after it has been processed by a modified & unmodifed WMFTranscoder (315.14 KB, application/x-zip-compressed)
2008-03-31 16:07 UTC, Brent Pacheco
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Brent Pacheco 2008-03-31 16:07:24 UTC
Created attachment 21747 [details]
This attachment contains a WMF witha viewport width of 0 and the resulting svg images after it has been processed by a modified & unmodifed WMFTranscoder

Line 118 on WMFPainter.java resets the scale based on a calculation of scale * the width in pixels / the viewport width.  In the event that the viewport width is zero, division by zero occurs and a the scale is set as "Infinity."  This causes lots of issues downstream and eventually the SVG file is written out with "?" in place of numbers in the <path> tags, and the SVG renders completely blank.  If this line is commented out, then the SVG resembles the original WMF, except that only about half of the original content is rendered in the view port.  See the attachment for the original WMF image and the resulting two SVG files.
Comment 1 Hervé Girod 2009-07-04 10:17:30 UTC
The problem is in the big readRecords method, with the META_SETWINDOWEXT switch. A variable _bext is used to be sure that the viewPort is set only the first time. In this example, the first META_SETWINDOWEXT records all have 0 width and height. The solution is to allow to reset the viewPort after it has been set before. It is wise to also not allow to set viewPort if width or height are 0, as this is an error in the WMF File.

I have applied this solution in my working copy of Batik, and it works. I will propose the (small) patch soon.
Comment 2 Hervé Girod 2009-07-05 02:19:39 UTC
I will send a patch as soon as I can, but these lines in WMFRecordStore:

if (_bext && functionId == WMFConstants.META_SETWINDOWEXT) {
   vpW = width;
   vpH = height;
   if (! isotropic) scaleXY = (float)vpW / (float)vpH;
   vpW = (int)(vpW * scaleXY);                      
   _bext = false;
}

should be changed to:

if (functionId == WMFConstants.META_SETWINDOWEXT) {
   if ((width > 0) && (height > 0)) {
       vpW = width;
       vpH = height;
       if (! isotropic) scaleXY = (float)vpW / (float)vpH;
       vpW = (int)(vpW * scaleXY);  
   }                    
}

Of course, _bext is not useful anymore. The check for width and height being
greater than 0 is "just in case". There are so many faulty WMF files in the
wild ;)