Mozilla2:GFXGraphics

Revision as of 19:56, 17 March 2005 by Roc (talk | contribs) (→‎Filters)

Class Graphics

Your 2d drawing API. To use this you need to first create a surface and call SetSurface().

API

class Graphics {
public:
    Graphics();
    ~Graphics();

    // <insert refcount stuff here>

    void SetSurface(ASurface* surface);
    ASurface* Surface();

    // state
    void Save();
    void Restore();

    // drawing
    void NewPath();
    void ClosePath();

    void Stroke();
    void Fill();
    
    void MoveTo(double x, double y);
    void LineTo(double x, double y);
    void CurveTo(double x1, double y1,
                 double x2, double y2,
                 double x3, double y3);

    void Arc(double xc, double yc,
             double radius,
             double angle1, double angle2);

    void Rectangle(double x, double y, double width, double height);
    void Polygon(const Point<double> points[], unsigned long numPoints);

    // transform stuff
    void Translate(double x, double y);
    void Scale(double x, double y);
    void Rotate(double angle);

    void SetMatrix(const Matrix& matrix);
    void CurrentMatrix(Matrix& matrix) const;


    // properties
    void SetColor(const RGBA& c);
    void CurrentColor(RGBA& c) const;

    void SetDash(double* dashes, int ndash, double offset);
    //void getDash() const;

    void SetLineWidth(double width);
    double LineWidth() const;

    // define enum for operators (clear, src, dst, etc)
    void SetOperator(int op);
    int Operator() const;

    // define line caps (butt, round, square)
    void SetLineCap(int cap);
    int LineCap() const;

    void SetMiterLimit(double limit);
    double MiterLimit() const;

    // clipping
    void Clip(const Rect& rect); // will clip to a rect
    void Clip(const Region& region); // will clip to a region
    void Clip(void); // will clip the last path you've drawn

    // patterns

    // fonts?

private:
    cairo_t *mCairo;
};

Filters

For blending and SVG filters we need an API like this:

class Filter {
  static Filter* CreateOpacityFilter(double alpha);
  // CreateGaussianFilter, etc
};

In Graphics:

  // Start rendering under the filter. We guarantee not to draw outside 'maxArea'.
  void PushFilter(Filter f, Rect maxArea);
  // Completed rendering under the filter, composite what we rendered back to the
  // underlying surface using the filter.
  void PopFilter();

This API lets clients not worry about what resolution to create a temporary surface at, etc. It is GFX/Cairo's responsibility to choose a good resolution, based on the current transformation.

The way to implement this is to transform maxArea to device coordinates, take its bounding box, and use that as the area for the temporary surface.