// This may look like C code, but it's really -*- C++ -*-
/*
 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */
#ifndef WSVG_IMAGE_H_
#define WSVG_IMAGE_H_

#include <WVectorImage>
#include <WResource>

namespace Wt {

/*! \class WSvgImage WSvgImage WSvgImage
 *  \brief A paint device for rendering using Scalable Vector Graphics (SVG).
 *
 * The %WSVGImage is used by WPaintedWidget to render to the browser
 * using the Support Vector Graphics (SVG).
 */
class WT_API WSvgImage : public WVectorImage, public WResource
{
public:
  /*! \brief Create an SVG paint device.
   */
  WSvgImage(const WLength& width, const WLength& height, WObject *parent = 0);

  virtual void setChanged(int flags);
  virtual void drawArc(const WRectF& rect, double startAngle, double spanAngle);
  virtual void drawImage(const WRectF& rect, const std::string& imgUri,
			 int imgWidth, int imgHeight, const WRectF& sourceRect);
  virtual void drawLine(double x1, double y1, double x2, double y2);
  virtual void drawPath(const WPainterPath& path);
  virtual void drawText(const WRectF& rect, int flags,
			const WString& text);
  virtual void init();
  virtual void done();

  virtual std::string rendered();

protected:
  virtual const std::string resourceMimeType() const;
  virtual bool streamResourceData(std::ostream& stream,
				  const ArgumentMap& arguments);

private:
  bool        newGroup_;
  bool        newClipPath_;
  int         currentClipId_;
  int         nextImgClipId_;

  std::string shapes_;

  void makeNewGroup();
  std::string fillStyle() const;
  std::string strokeStyle() const;
  std::string fontStyle() const;
  std::string clipStyle() const;

  static std::string quote(double s);
  static std::string quote(const std::string& s);

  void drawPlainPath(std::ostream& s, const WPainterPath& path);
};

}

#endif // WSVG_IMAGE_H_
