Graphics Facilities in Jcon

Icon's graphics facilities are defined by Graphics Programming in Icon (Griswold, Jeffery, and Townsend, 1998). This section documents differences from that specification, supplementing Appendix N ("Platform Dependencies") of the book.

Jcon's graphics implementation is nearly complete. The biggest omission is textured drawing.

Graphics Attributes

All attributes listed in the graphics book are implemented, but some cannot be changed successfully. The canvas attribute can be set to normal or hidden but not to maximal or iconic. Changes to the following attributes are ignored: linestyle, fillstyle, pattern, display, iconpos, iconlabel, iconimage.

Because textured drawing is not available, the Pattern() procedure always fails.

Each graphics context is associated with a particular canvas. Thus Couple() always fails and Clone() accepts only a single window argument.

Fonts

Icon generic family names, and all font characteristics, are case-insensitive; depending on the Java implementation, other font family names may be case-sensitive. Because Java never rejects any non-empty font name, Font(s) always succeeds for any well-formed specification.

The generic family names serif, sans, and typewriter work well, including bold and italic variants. The appearance of the generic family mono varies by platform, and bold and italic characteristics are not always effective.

The default font name fixed is mapped to mono,bold,12.

Colors

There is no inherent limit to the number of different colors that can be in use simultaneously. On 8-bit displays, Java approximates colors by selection from a limited palette that can vary from one run to another. The first image below (from Plate 8.2 of the graphics book) shows the surface of color space as rendered on a full-color display. The second image is an example of how Java renders it on an 8-bit display.

full color image quantized image

For named colors, variants (such as light and dark) of the unsaturated hues (brown, pink, and violet) appear less saturated than in Version 9 of Icon. Unlike Version 9, variants of black remain black rather than producing shades of gray.

The default value of the gamma attribute is 1.5.

Mutable colors are not available; NewColor() and Color() always fail. (Few modern display systems support mutable colors; they were briefly useful when graphics memory was still expensive.)

Images

ReadImage() loads images encoded in GIF or JPEG format. If the ReadImage() call specifies a color palette, it is ignored; Java dithers the image if necessary for display. Neither ReadImage() nor DrawImage() ever returns an integer indicating a color shortage.

The image attribute can be set at any time, not just initially, to load a GIF or JPEG file. The image attribute is readable and returns the filename of the most recently loaded image.

WriteImage() attempts to write a JPEG file if the specified filename ends in ".jpg" or ".jpeg" (case insensitive). For all other filenames, a GIF file is written; if the area being written contains more than 256 colors, automatic quantization occurs.

WriteImage(W,s,x,y,w,h,q) accepts a final "quality" parameter not present in Version 9 of Icon. Its allowable range is 0.00 to 1.00, with a default value of 0.75. The quality value is passed directly to Java when writing a JPEG image. Its useful range is perhaps 0.10 to 0.90: Smaller values produce images dominated by artifacts, and larger values increase file size without producing any visible improvement.

If a quality value of less than 0.90 is specified for a GIF image, the maximum number of output colors is reduced to produce a smaller file for color-rich images.

Image reading and writing ignores the gamma attribute.

Pixel() clips the specified region by the window bounds before generating values. This differs from Version 9 of Icon, which generates the background color for out-of-bounds pixels. (The graphics book is silent on this point.)

Events

Java distinguishes between ALT and META keys; in Jcon, either key sets the &meta keyword.

The &meta keyword is never set in conjunction with mouse events; for these events, Java uses the ALT and META flags to encode "which button", so they are unavailable to indicate key states.

Numeric codes for the "outboard" keys such as F1 and HOME differ from those of X and are similar to those of Windows; see the copy of keysyms.icn distributed with Jcon.

When a window is closed by the user, a &resize event is produced with associated &x and &y values of (-1, -1).

Cursors and Pointers

The visible text cursor, when enabled, is a solid, nonblinking underbar.

The mouse position can be read using the pointerx and pointery attributes (or pointerrow and pointercol), but it cannot be set by the program. Attempts to alter these attribute values are ignored.

Acceptable values for the pointer attribute are illustrated in the following figure. For compatibility with other systems, some pointers have multiple names.

pointer shapes

Deprecated Features

Version 9 of Icon retains compatibility support for some old graphics features that are no longer documented. Jcon omits most such support. Two examples are support for very light and very dark colors and the acceptance of bi-level images expressed in decimal notation.


index || intro | usage | differences | graphics | dynamic loading | performance | release notes | installation | references || home