Wt: Wt::WSvgImage Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
Wt::WSvgImage Class Reference
Painting system

A paint device for rendering using Scalable Vector Graphics (SVG). More...

`#include <Wt/WSvgImage.h>`

Inheritance diagram for Wt::WSvgImage:
[legend]

## Public Member Functions
| WSvgImage (const WLength &width, const WLength &height, bool paintUpdate=false)
| Create an SVG paint device.
| ~WSvgImage ()
| Destructor.
virtual WFlags< PaintDeviceFeatureFlag > | features () const override
| Returns device features.
virtual void | setChanged (WFlags< PainterChangeFlag > flags) override
| Indicates changes in painter state.
virtual void | drawArc (const WRectF &rect, double startAngle, double spanAngle) override
| Draws an arc.
virtual void | drawImage (const WRectF &rect, const std::string &imgUri, int imgWidth, int imgHeight, const WRectF &sourceRect) override
| Draws an image.
virtual void | drawLine (double x1, double y1, double x2, double y2) override
| Draws a line.
virtual void | drawRect (const WRectF &rectangle) override
| Draws a rectangle.
virtual void | drawPath (const WPainterPath &path) override
| Draws a path.
virtual void | drawText (const WRectF &rect, WFlags< AlignmentFlag > alignmentFlags, TextFlag textFlag, const WString &text, const WPointF *clipPoint) override
| Draws text.
virtual WTextItem | measureText (const WString &text, double maxWidth=-1, bool wordWrap=false) override
| Measures rendered text size.
virtual WFontMetrics | fontMetrics () override
| Returns font metrics.
virtual void | init () override
| Initializes the device for painting.
virtual void | done () override
| Finishes painting on the device.
virtual bool | paintActive () const override
| Returns whether painting is active.
virtual std::string | rendered () override
| Internal method.
virtual WLength | width () const override
| Returns the device width.
virtual WLength | height () const override
| Returns the device height.
virtual void | handleRequest (const Http::Request &request, Http::Response &response) override
| Handles a request.
Public Member Functions inherited from Wt::WResource
| WResource ()
| Creates a new resource.
| ~WResource ()
| Destroys the resource.
void | suggestFileName (const Wt::WString &name, ContentDisposition disposition=ContentDisposition::Attachment)
| Suggests a filename to the user for the data streamed by this resource.
const Wt::WString & | suggestedFileName () const
| Returns the suggested file name.
void | setDispositionType (ContentDisposition cd)
| Configures the Content-Disposition header.
ContentDisposition | dispositionType () const
| Returns the currently configured content disposition.
void | setChanged ()
| Generates a new URL for this resource and emits the changed signal.
void | setInvalidAfterChanged (bool enabled)
| Return "page not found" for prior resource URLs after change.
bool | invalidAfterChanged () const
| Should "page not found" be returned for outdated resource URLs.
void | setInternalPath (const std::string &path)
| Sets an internal path for this resource.
std::string | internalPath () const
| Returns the internal path.
const std::string & | generateUrl ()
| Generates an URL for this resource.
const std::string & | url () const
| Returns the current URL for this resource.
Signal & | dataChanged ()
| Signal emitted when the data presented in this resource has changed.
void | setUploadProgress (bool enabled)
| Indicate interest in upload progress.
Signal< ::uint64_t, ::uint64_t > & | dataReceived ()
| Signal emitted when data has been received for this resource.
void | write (std::ostream &out, const Http::ParameterMap &parameters=Http::ParameterMap(), const Http::UploadedFileMap &files=Http::UploadedFileMap())
| Stream the resource to a stream.
virtual void | handleAbort (const Http::Request &request)
| Handles a continued request being aborted.
void | haveMoreData ()
| Indicate that more data is available.
void | setTakesUpdateLock (bool enabled)
| Set whether this resource takes the WApplication's update lock.
bool | takesUpdateLock () const
| Returns whether this resources takes the WApplication's update lock.
Public Member Functions inherited from Wt::WObject
void | addChild (std::unique_ptr< WObject > child)
| Add a child WObject whose lifetime is determined by this WObject.
template<typename Child >
Child * | addChild (std::unique_ptr< Child > child)
| Add a child WObject, returning a raw pointer.
std::unique_ptr< WObject > | removeChild (WObject *child)
| Remove a child WObject, so its lifetime is no longer determined by this WObject.
template<typename Child >
std::unique_ptr< Child > | removeChild (Child *child)
| Remove a child WObject, so its lifetime is no longer determined by this WObject.
virtual const std::string | id () const
| Returns the (unique) identifier for this object.
virtual void | setObjectName (const std::string &name)
| Sets an object name.
virtual std::string | objectName () const
| Returns the object name.
void | resetLearnedSlots ()
| Resets learned stateless slot implementations.
template<class T >
void | resetLearnedSlot (void(T::*method)())
| Resets a learned stateless slot implementation.
template<class T >
WStatelessSlot * | implementStateless (void(T::*method)())
| Declares a slot to be stateless and learn client-side behaviour on first invocation.
template<class T >
WStatelessSlot * | implementStateless (void(T::*method)(), void(T::*undoMethod)())
| Declares a slot to be stateless and learn client-side behaviour in advance.
void | isNotStateless ()
| Marks the current function as not stateless.
template<class T >
WStatelessSlot * | implementJavaScript (void(T::*method)(), const std::string &jsCode)
| Provides a JavaScript implementation for a method.
Public Member Functions inherited from Wt::Core::observable
| observable () noexcept
| Default constructor.
virtual | ~observable ()
| Destructor.
template<typename... Args, typename C >
auto | bindSafe (void(C::*method)(Args...)) noexcept
| Protects a method call against object destruction.
template<typename... Args, typename C >
auto | bindSafe (void(C::*method)(Args...) const) const noexcept
| Protects a const method call against object destruction.
template<typename Function >
auto | bindSafe (const Function &function) noexcept
| Protects a function against object destruction.
Public Member Functions inherited from Wt::WVectorImage
Public Member Functions inherited from Wt::WPaintDevice
virtual | ~WPaintDevice ()
| Destructor.

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

## Additional Inherited Members
Public Types inherited from Wt::WObject
typedef void(WObject::*) | Method()
| Typedef for a WObject method without arguments.
Public Types inherited from Wt::WPaintDevice
typedef PaintDeviceFeatureFlag | FeatureFlag
| Typedef for enum Wt::PaintDeviceFeatureFlag.
Static Public Member Functions inherited from Wt::WObject

## Detailed Description

A paint device for rendering using Scalable Vector Graphics (SVG).

The WSvgImage is primarily used by WPaintedWidget to render to the browser in Support Vector Graphics (SVG) format.

You may also use the WSvgImage as an independent resource, for example in conjunction with a WAnchor or WImage, or to make a hard copy of an image in SVG format, using write():

Wt::Chart::WCartesianChart *chart = ...
Wt::WSvgImage svgImage(800, 400);
Wt::WPainter p(&svgImage);
chart->paint(p);
p.end();
std::ofstream f("chart.svg");
svgImage.write(f);
Wt::Chart::WCartesianChart
A cartesian chart.
Definition WCartesianChart.h:408
Wt::Chart::WCartesianChart::paint
virtual void paint(WPainter &painter, const WRectF &rectangle=WRectF()) const override
Paint the chart in a rectangle of the given painter.
Wt::WPainter
Vector graphics painting class.
Definition WPainter.h:147

## Constructor & Destructor Documentation

## ◆ WSvgImage()

Wt::WSvgImage::WSvgImage | ( | const WLength & | width,
|  | const WLength & | height,
|  | bool | paintUpdate = false )

Create an SVG paint device.

If `paintUpdate` is `true`, then only an SVG fragment will be rendered that can be used to update the DOM of an existing SVG image, instead of a full SVG image.

## Member Function Documentation

## ◆ done()

virtual void Wt::WSvgImage::done | ( |  | ) |
| overridevirtual

Finishes painting on the device.

This method is called when a WPainter stopped painting.

See also
  WPainter::end()

Implements Wt::WPaintDevice.

## ◆ drawArc()

virtual void Wt::WSvgImage::drawArc | ( | const WRectF & | rect,
|  | double | startAngle,
|  | double | spanAngle )
| overridevirtual

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.

## ◆ drawImage()

virtual void Wt::WSvgImage::drawImage | ( | const WRectF & | rect,
|  | const std::string & | imageUri,
|  | int | imgWidth,
|  | int | imgHeight,
|  | const WRectF & | sourceRect )
| overridevirtual

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.

## ◆ drawLine()

virtual void Wt::WSvgImage::drawLine | ( | double | x1,
|  | double | y1,
|  | double | x2,
|  | double | y2 )
| overridevirtual

Draws a line.

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

Implements Wt::WPaintDevice.

## ◆ drawPath()

virtual void Wt::WSvgImage::drawPath | ( | const WPainterPath & | path | ) |
| overridevirtual

Draws a path.

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

Implements Wt::WPaintDevice.

## ◆ drawRect()

virtual void Wt::WSvgImage::drawRect | ( | const WRectF & | rectangle | ) |
| overridevirtual

Draws a rectangle.

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

Implements Wt::WPaintDevice.

## ◆ drawText()

virtual void Wt::WSvgImage::drawText | ( | const WRectF & | rect,
|  | WFlags< AlignmentFlag > | alignmentFlags,
|  | TextFlag | textFlag,
|  | const WString & | text,
|  | const WPointF * | clipPoint )
| overridevirtual

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.

## ◆ fontMetrics()

virtual WFontMetrics Wt::WSvgImage::fontMetrics | ( |  | ) |
| overridevirtual

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.

## ◆ handleRequest()

virtual void Wt::WSvgImage::handleRequest | ( | const Http::Request & | request,
|  | Http::Response & | response )
| overridevirtual

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.

## ◆ height()

virtual WLength Wt::WSvgImage::height | ( |  | ) | const
| overridevirtual

Returns the device height.

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

Implements Wt::WPaintDevice.

## ◆ init()

virtual void Wt::WSvgImage::init | ( |  | ) |
| overridevirtual

Initializes the device for painting.

This method is called when a WPainter starts painting.

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

Implements Wt::WPaintDevice.

## ◆ measureText()

virtual WTextItem Wt::WSvgImage::measureText | ( | const WString & | text,
|  | double | maxWidth = -1,
|  | bool | wordWrap = false )
| overridevirtual

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.

## ◆ paintActive()

virtual bool Wt::WSvgImage::paintActive | ( |  | ) | const
| overridevirtual

Returns whether painting is active.

See also
  init(), painter()

Implements Wt::WPaintDevice.

## ◆ painter()

virtual WPainter * Wt::WSvgImage::painter | ( |  | ) | const
| overrideprotectedvirtual

Returns the painter that is currently painting on the device.

See also
  init()

Implements Wt::WPaintDevice.

## ◆ setChanged()

virtual void Wt::WSvgImage::setChanged | ( | WFlags< PainterChangeFlag > | flags | ) |
| overridevirtual

Indicates changes in painter state.

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

See also
  ChangeFlag

Implements Wt::WPaintDevice.

## ◆ width()

virtual WLength Wt::WSvgImage::width | ( |  | ) | const
| overridevirtual

Returns the device width.

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

Implements Wt::WPaintDevice.