// 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 WVML_IMAGE_H_
#define WVML_IMAGE_H_

#include <WBrush>
#include <WPen>
#include <WTransform>
#include <WVectorImage>
#include <WResource>

namespace Wt {

class WColor;

/*! \class WVmlImage WVmlImage WVmlImage
 *  \brief A paint device for rendering using the VML pseudo-standard.
 *
 * The %WVmlImage is used by WPaintedWidget to render to the browser
 * using the Vector Markup Language (VML) (to support graphics on
 * Internet Explorer browsers).
 *
 * <i>Note: the current implementation has no support for clipping,
 * and only limited support for text, which is rendered in an
 * overlayed DIV. The latter problem will be solved in the future,
 * using VML textpath elements.</i>
 */
class WT_API WVmlImage : public WVectorImage
{
public:
  /*! \brief Create a VML paint device.
   */
  WVmlImage(const WLength& width, const WLength& height);

  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();

private:
  bool       penBrushTransformChanged_;
  bool       busyWithPath_;
  WBrush     currentBrush_;
  WPen       currentPen_;
  WTransform currentTransform_;

  std::string shapes_;

  void        finishPath();
  std::string fillElement(const WBrush& brush) const;
  std::string strokeElement(const WPen& pen) const;
  std::string skewElement(const WTransform& transform) const;

  static std::string colorAttributes(const WColor& color);
  static std::string quote(double s);
  static std::string quote(const std::string& s);
};

}

#endif // WVML_IMAGE_H_
