Class WPainter

java.lang.Object
eu.webtoolkit.jwt.WPainter

public class WPainter extends Object
Vector graphics painting class.

The painter class provides a vector graphics interface for painting. It needs to be used in conjunction with a WPaintDevice, onto which it paints. To start painting on a device, either pass the device through the constructor, or use begin().

A typical use is to instantiate a WPainter from within a specialized WPaintedWidget#paintEvent() implementation, to paint on the given paint device, but you can also use a painter to paint directly to a particular paint device of choice, for example to create SVG, PDF or PNG images (as resources).

The painter maintains state such as the current pen, brush, font, getShadow(), transformation and clipping settings (see setClipping() and setClipPath()). A particular state can be saved using save() and later restored using restore().

The painting system distinguishes between device coordinates, logical coordinates, and local coordinates. The device coordinate system ranges from (0, 0) in the top left corner of the device, to (device.width().toPixels(), device.height().toPixels()) for the bottom right corner. The logical coordinate system defines a coordinate system that may be chosen independent of the geometry of the device, which is convenient to make abstraction of the actual device size. Finally, the current local coordinate system may be different from the logical coordinate system because of a transformation set (using translate(), rotate(), and scale()). Initially, the local coordinate system coincides with the logical coordinate system, which coincides with the device coordinate system.

The device coordinates are defined in terms of pixels. Even though most underlying devices are actual vector graphics formats, when used in conjunction with a WPaintedWidget, these vector graphics are rendered by the browser onto a pixel-based canvas (like the rest of the user-interface). The coordinates are defined such that integer values correspond to an imaginary raster which separates the individual pixels, as in the figure below.

The device coordinate system for a 6x5 pixel device

As a consequence, to avoid anti-aliasing effects when drawing straight lines of width one pixel, you will need to use vertices that indicate the middle of a pixel to get a crisp one-pixel wide line, as in the example figure.

By setting a getViewPort() and a getWindow(), a viewPort transformation is defined which maps logical coordinates onto device coordinates. By changing the world transformation (using setWorldTransform(), or translate(), rotate(), scale() operations), it is defined how current local coordinates map onto logical coordinates.

The painter provides support for clipping using an arbitrary path, but not that the WVmlImage paint device only has limited support for clipping.

See Also: