Wt  3.3.9
Public Member Functions | Protected Member Functions | List of all members
Wt::WRasterImage Class Reference

A paint device for rendering to a raster image. More...

#include <Wt/WRasterImage>

Inheritance diagram for Wt::WRasterImage:
Inheritance graph

Public Member Functions

 WRasterImage (const std::string &type, const WLength &width, const WLength &height, WObject *parent=0)
 Creates a raster image. More...
 ~WRasterImage ()
void addFontCollection (const std::string &directory, bool recursive=true)
 Adds a font collection. More...
virtual WFlags< FeatureFlagfeatures () const
 Returns device features.
virtual void setChanged (WFlags< ChangeFlag > flags)
 Indicates changes in painter state. More...
virtual void drawArc (const WRectF &rect, double startAngle, double spanAngle)
 Draws an arc. More...
virtual void drawImage (const WRectF &rect, const std::string &imgUri, int imgWidth, int imgHeight, const WRectF &sourceRect)
 Draws an image. More...
virtual void drawLine (double x1, double y1, double x2, double y2)
 Draws a line. More...
virtual void drawPath (const WPainterPath &path)
 Draws a path. More...
virtual void drawText (const WRectF &rect, WFlags< AlignmentFlag > alignmentFlags, TextFlag textFlag, const WString &text, const WPointF *clipPoint)
 Draws text. More...
virtual WTextItem measureText (const WString &text, double maxWidth=-1, bool wordWrap=false)
 Measures rendered text size. More...
virtual WFontMetrics fontMetrics ()
 Returns font metrics. More...
virtual void init ()
 Initializes the device for painting. More...
virtual void done ()
 Finishes painting on the device. More...
virtual bool paintActive () const
 Returns whether painting is active. More...
virtual WLength width () const
 Returns the device width. More...
virtual WLength height () const
 Returns the device height. More...
virtual void handleRequest (const Http::Request &request, Http::Response &response)
 Handles a request. More...
void setPixel (int x, int y, const WColor &color)
 Low-level paint method. More...
WColor getPixel (int x, int y)
 Low-level paint method. More...
void getPixels (void *data)
 Low-level pixel retrieval. More...
void clear ()
 Clears the image. More...
- Public Member Functions inherited from Wt::WResource
 WResource (WObject *parent=0)
 Creates a new resource.
 ~WResource ()
 Destroys the resource. More...
void suggestFileName (const Wt::WString &name, DispositionType dispositionType=Attachment)
 Suggests a filename to the user for the data streamed by this resource. More...
const Wt::WStringsuggestedFileName () const
 Returns the suggested file name. More...
void setDispositionType (DispositionType cd)
 Configures the Content-Disposition header. More...
DispositionType dispositionType () const
 Returns the currently configured content disposition. More...
void setChanged ()
 Generates a new URL for this resource and emits the changed signal. More...
void setInternalPath (const std::string &path)
 Sets an internal path for this resource. More...
std::string internalPath () const
 Returns the internal path. More...
const std::string & generateUrl ()
 Generates an URL for this resource. More...
const std::string & url () const
 Returns the current URL for this resource. More...
SignaldataChanged ()
 Signal emitted when the data presented in this resource has changed. More...
void setUploadProgress (bool enabled)
 Indicate interest in upload progress. More...
Signal< ::uint64_t,::uint64_t > & dataReceived ()
 Signal emitted when data has been received for this resource. More...
void write (std::ostream &out, const Http::ParameterMap &parameters=Http::ParameterMap(), const Http::UploadedFileMap &files=Http::UploadedFileMap())
 Stream the resource to a stream. More...
virtual void handleAbort (const Http::Request &request)
 Handles a continued request being aborted. More...
void haveMoreData ()
 Indicate that more data is available. More...
- Public Member Functions inherited from Wt::WObject
 WObject (WObject *parent=0)
 Create a WObject with a given parent object. More...
virtual ~WObject ()
 Destructor. More...
virtual const std::string id () const
 Returns the (unique) identifier for this object. More...
virtual void setObjectName (const std::string &name)
 Sets an object name. More...
virtual std::string objectName () const
 Returns the object name. More...
void resetLearnedSlots ()
 Resets learned stateless slot implementations. More...
template<class T >
void resetLearnedSlot (void(T::*method)())
 Resets a learned stateless slot implementation. More...
template<class T >
WStatelessSlot * implementStateless (void(T::*method)())
 Declares a slot to be stateless and learn client-side behaviour on first invocation. More...
template<class T >
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
 Declares a slot to be stateless and learn client-side behaviour in advance. More...
void isNotStateless ()
 Marks the current function as not stateless. More...
template<class T >
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 Provides a JavaScript implementation for a method. More...
void addChild (WObject *child)
 Adds a child object. More...
virtual void removeChild (WObject *child)
 Removes a child object. More...
const std::vector< WObject * > & children () const
 Returns the children.
WObjectparent () const
 Returns the parent object.
- Public Member Functions inherited from Wt::WPaintDevice
virtual ~WPaintDevice ()
 Destructor. More...

Protected Member Functions

virtual WPainterpainter () const
 Returns the painter that is currently painting on the device. More...
virtual void setPainter (WPainter *painter)
 Sets the painter.
- Protected Member Functions inherited from Wt::WResource
void beingDeleted ()
 Prepares the resource for deletion. More...
- Protected Member Functions inherited from Wt::WObject
virtual WStatelessSlot * getStateless (Method method)
 On-demand stateless slot implementation. More...

Additional Inherited Members

- Public Types inherited from Wt::WResource
- Public Types inherited from Wt::WObject
typedef void(WObject::* Method) ()
 Typedef for a WObject method without arguments.
- Public Types inherited from Wt::WPaintDevice
- Static Protected Member Functions inherited from Wt::WObject
static WObjectsender ()
 Returns the sender of the current slot call. More...

Detailed Description

A paint device for rendering to a raster image.

A WRasterImage paint device provides support for creating raster images (such as PNG or GIF images).

It implements two main use-cases:

On Linux, the rendering is provided by GraphicsMagick, and this class is included in the library only if libgraphicsmagick was found during the build of the library. As an alternative, Wt supports certain versions of skia. In general skia is a good and performant renderer, but since it does not have releases, and a not very stable API, we don't recommend it. On Windows, Direct2D is used for rendering, which means that no extra dependencies have to be installed.

If Wt is built to use libpango for font support, then text rendering is done using this library. On Windows, DirectWrite is used for font support functions. In other cases, you may want to configure TrueType font search directories using addFontCollection().

You can use the image as a resource and specialize handleRequest() to paint the contents on the fly. Alternatively can also use write() to serialize to an image file (std::ostream).

The latter usage is illustrated by the code below:

Wt::WRasterImage pngImage("png", 600, 400);
Wt::WPainter p(&pngImage);
std::ofstream f("chart.png", std::ios::out | std::ios::binary);

This paint device has the following limitations:

Constructor & Destructor Documentation

Wt::WRasterImage::WRasterImage ( const std::string &  type,
const WLength width,
const WLength height,
WObject parent = 0 

Creates a raster image.

type indicates an image type. The mime type of the resource is "image/" type.

Wt supports the following image types (amongst others):

  • png: Portable Network Graphics
  • gif: Graphics Interchange Format
  • bmp: Microsoft windows bitmap
  • jpeg: Joint Photographic Experts Group JFIF format

Member Function Documentation

void Wt::WRasterImage::addFontCollection ( const std::string &  directory,
bool  recursive = true 

Adds a font collection.

If Wt has been configured to use libpango, then font matching and character selection is done by libpango, which is seeded with information on installed fonts by fontconfig. In that case, invocations for this method is ignored.

If Wt has not been configured to use libpango, then this method may be used to indicate the location of true type fonts. The main drawback compared to libpango is that font selection is not steered by the need for particular characters, i.e. font selection is independent from the text's need for specific characters. Most truetype fonts provided only partial unicode support. The provided directory will be searched for fonts (currently only TrueType ".ttf" or ".ttc" fonts).

void Wt::WRasterImage::clear ( )

Clears the image.

Fills the image with a white background, or transparent if possible.

void Wt::WRasterImage::done ( )

Finishes painting on the device.

This method is called when a WPainter stopped painting.

See also

Implements Wt::WPaintDevice.

void Wt::WRasterImage::drawArc ( const WRectF rect,
double  startAngle,
double  spanAngle 

Draws an arc.

The arc describes the segment of an ellipse enclosed by the rect. The segment starts at startAngle, and spans an angle given by spanAngle. These angles have as unit degree, and are measured counter-clockwise starting from the 3 o'clock position.

The arc must be stroked, filled, and transformed using the current painter settings.

Implements Wt::WPaintDevice.

void Wt::WRasterImage::drawImage ( const WRectF rect,
const std::string &  imageUri,
int  imgWidth,
int  imgHeight,
const WRectF sourceRect 

Draws an image.

Draws sourceRect from the image with URL imageUri and original dimensions imgWidth and imgHeight to the location, into the rectangle defined by rect.

The image is transformed using the current painter settings.

Implements Wt::WPaintDevice.

void Wt::WRasterImage::drawLine ( double  x1,
double  y1,
double  x2,
double  y2 

Draws a line.

The line must be stroked and transformed using the current painter settings.

Implements Wt::WPaintDevice.

void Wt::WRasterImage::drawPath ( const WPainterPath path)

Draws a path.

The path must be stroked, filled, and transformed using the current painter settings.

Implements Wt::WPaintDevice.

void Wt::WRasterImage::drawText ( const WRectF rect,
WFlags< AlignmentFlag alignmentFlags,
TextFlag  textFlag,
const WString text,
const WPointF clipPoint 

Draws text.

The text must be rendered, stroked and transformed using the current painter settings.

If clipPoint is not null, a check is performed whether the point is inside of the current clip area. If not, the text is not drawn.

Implements Wt::WPaintDevice.

WFontMetrics Wt::WRasterImage::fontMetrics ( )

Returns font metrics.

This returns font metrics for the current font.

Throws a std::logic_error if the underlying device does not provide font metrics.

Implements Wt::WPaintDevice.

WColor Wt::WRasterImage::getPixel ( int  x,
int  y 

Low-level paint method.

Use this method to directly get the color for an individual pixel, when using the paint device without a painter.

void Wt::WRasterImage::getPixels ( void *  data)

Low-level pixel retrieval.

This is a more efficient alternative than calling getPixel() for every pixel.

Parameter data must point to an allocated memory region of width*height 32-bit words. The pixels will be written in row-order from top-left to bottom-right, in RGBA format.

void Wt::WRasterImage::handleRequest ( const Http::Request request,
Http::Response response 

Handles a request.

Reimplement this method so that a proper response is generated for the given request. From the request object you can access request parameters and whether the request is a continuation request. In the response object, you should set the mime type and stream the output data.

A request may also concern a continuation, indicated in Http::Request::continuation(), in which case the next part for a previously created continuation should be served.

While handling a request, which may happen at any time together with event handling, the library makes sure that the resource is not being concurrently deleted, but multiple requests may happend simultaneously for a single resource.

Implements Wt::WResource.

virtual WLength Wt::WRasterImage::height ( ) const

Returns the device height.

The device height, in pixels, establishes the height of the device coordinate system.

Implements Wt::WPaintDevice.

void Wt::WRasterImage::init ( )

Initializes the device for painting.

This method is called when a WPainter starts painting.

See also
WPainter::begin(WPaintDevice *), painter()

Implements Wt::WPaintDevice.

WTextItem Wt::WRasterImage::measureText ( const WString text,
double  maxWidth = -1,
bool  wordWrap = false 

Measures rendered text size.

Returns the bounding rect of the given text when rendered using the current font.

If maxWidth != -1, then the text is truncated to fit in the width.

If wordWrap = true then text is truncated only at word boundaries. Note that in this case the whitespace at the truncated position is included in the text but not accounted for by the returned width (since usually you will not render the whitespace at the end of a line).

Throws a std::logic_error if the underlying device does not provide font metrics.

Implements Wt::WPaintDevice.

virtual bool Wt::WRasterImage::paintActive ( ) const

Returns whether painting is active.

See also
init(), painter()

Implements Wt::WPaintDevice.

virtual WPainter* Wt::WRasterImage::painter ( ) const

Returns the painter that is currently painting on the device.

See also

Implements Wt::WPaintDevice.

void Wt::WRasterImage::setChanged ( WFlags< ChangeFlag flags)

Indicates changes in painter state.

The flags argument is the logical OR of one or more change flags.

See also

Implements Wt::WPaintDevice.

void Wt::WRasterImage::setPixel ( int  x,
int  y,
const WColor color 

Low-level paint method.

Use this method to directly set colors for individual pixels, when using the paint device without a painter.

virtual WLength Wt::WRasterImage::width ( ) const

Returns the device width.

The device width, in pixels, establishes the width of the device coordinate system.

Implements Wt::WPaintDevice.

Generated on Tue Nov 21 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11