Feature #12170
Java replacements for the System.Drawing imaging subset used from 4GL
Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
Due date:
% Done:
0%
billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
reviewer:
production:
No
env_name:
topics:
History
#1 Updated by Greg Shah 8 days ago
Problem¶
GUI applications written for OpenEdge on Windows can use the .NET System.Drawing classes directly from 4GL to load, resize, combine and save images, and to get the icon Windows associates with a file:
USING System.Drawing.* FROM ASSEMBLY. DEFINE VARIABLE oSrc AS System.Drawing.Bitmap NO-UNDO. DEFINE VARIABLE oDst AS System.Drawing.Bitmap NO-UNDO. DEFINE VARIABLE oGfx AS System.Drawing.Graphics NO-UNDO. oSrc = NEW System.Drawing.Bitmap(cImageFile). oDst = NEW System.Drawing.Bitmap(100, 100). oGfx = System.Drawing.Graphics:FromImage(oDst). oGfx:DrawImage(oSrc, 0, 0, 100, 100). oDst:Save(cThumbFile, System.Drawing.Imaging.ImageFormat:Jpeg). oGfx:Dispose(). oSrc:Dispose(). oDst:Dispose(). oIcon = System.Drawing.Icon:ExtractAssociatedIcon(cDocument). oIcon:ToBitmap():Save(cIconFile, System.Drawing.Imaging.ImageFormat:Jpeg).
FWD's front end recognises .NET class references, and the analytics reports list them, but the conversion produces no code for them and there is no runtime support. There is no .NET runtime in a converted system, and none is needed for this subset: Java 2D (BufferedImage, Graphics2D, ImageIO) does all of it, headless, on the server.
Work¶
- Provide FWD replacement classes for these .NET members, with the same names, signatures and behaviour:
System.Drawing.Bitmap:Bitmap(character)(load from file),Bitmap(integer, integer)(new blank image),Save(character),Save(character, ImageFormat),Width,Height,Dispose();System.Drawing.Image:FromFile(character),Width,Height,Save(character, ImageFormat);System.Drawing.Graphics:FromImage(Image),DrawImage(Image, integer, integer),DrawImage(Image, integer, integer, integer, integer)(scaled),DrawImage(Image, Point),Dispose();System.Drawing.Imaging.ImageFormat:Jpeg,Gif(andPngandBmp, which cost nothing extra);System.Drawing.Point:Point(integer, integer);System.Drawing.Icon:ExtractAssociatedIcon(character),ToBitmap().
- Extend the conversion so that
USING System.Drawing.* FROM ASSEMBLYand references to these types resolve to the replacement classes, in the same way as Direct Java Access. A reference to aSystem.Drawingmember not in the list above converts with a warning and fails at run time with a clear message, rather than being silently dropped. Dispose()andDELETE OBJECTrelease the Java image; they must not fail if called twice.Icon:ExtractAssociatedIcon: there is no Windows shell icon store on the server. Ship a set of icons keyed by file extension (PDF, the Office formats, images, text, HTML, archives, and a generic default), resolve the icon from the file name's extension, and allow a project to add or override icons in its configuration. The file must exist, as in .NET: a missing file raises the same error.- File paths go through the same path mapping as other 4GL file access, so Windows-style paths in the code resolve on the server.
- Image formats: JPEG output uses a quality setting close to .NET's default, and GIF output is palette-based. Note in the documentation that the output bytes will not match .NET exactly; size and visual content will.
- Errors: a missing or unreadable file in
Bitmap(character)orImage:FromFileraises an error the 4GL can trap withCATCHorNO-ERROR, matching the error OpenEdge raises when .NET throws. - Update the gap marking for these classes and members.
Testcases¶
- Load a JPEG, GIF, PNG and BMP; read
WidthandHeight; save in each output format; compare dimensions and pixel content (within a tolerance) with the output of the same 4GL program on Windows OpenEdge. - Create a blank bitmap, draw a scaled image and an unscaled overlay at a point, and save. Compare with Windows OpenEdge.
- Combine several images side by side into one new bitmap sized from their widths and the largest height.
ExtractAssociatedIconfor each shipped extension, an unknown extension, an extension overridden in the configuration, and a missing file.Dispose()twice,DELETE OBJECTafterDispose(), and a missing input file trapped withCATCHand withNO-ERROR.