Ipelib

- Main Page
- Related Pages
- Modules
- Classes

- Class List
- Class Hierarchy
- Class Members

Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ipe::Painter Class Reference
Ipe Base

`#include <ipepainter.h>`

Inherited by ipe::BBoxPainter, ipe::CairoPainter, ipe::PdfPainter, and IpeQtPainter.

## Classes

struct | State

## Public Member Functions

| Painter (const Cascade *style)
virtual | ~Painter ()
void | transform (const Matrix &m)
void | untransform (TTransformations trans)
void | translate (const Vector &v)
void | push ()
void | pop ()
void | pushMatrix ()
void | popMatrix ()
void | newPath ()
void | moveTo (const Vector &v)
void | lineTo (const Vector &v)
void | curveTo (const Vector &v1, const Vector &v2, const Vector &v3)
void | curveTo (const Bezier &bezier)
void | rect (const Rect &re)
void | drawEllipse ()
void | drawArc (const Arc &arc)
void | closePath ()
void | drawPath (TPathMode mode)
void | drawBitmap (Bitmap bitmap)
void | drawText (const Text *text)
void | drawSymbol (Attribute symbol)
void | addClipPath ()
void | setStroke (Attribute color)
void | setFill (Attribute color)
void | setPen (Attribute pen)
void | setDashStyle (Attribute dash)
void | setLineCap (TLineCap cap)
void | setLineJoin (TLineJoin join)
void | setFillRule (TFillRule rule)
void | setSymStroke (Attribute color)
void | setSymFill (Attribute color)
void | setSymPen (Attribute wid)
void | setOpacity (Attribute opaq)
void | setTiling (Attribute til)
void | setGradient (Attribute grad)
const Cascade * | cascade () const
Color | stroke () const
Color | fill () const
const Matrix & | matrix () const
Fixed | pen () const
String | dashStyle () const
void | dashStyle (std::vector< double > &dashes, double &offset) const
TLineCap | lineCap () const
TLineJoin | lineJoin () const
TFillRule | fillRule () const
Color | symStroke () const
Color | symFill () const
Fixed | symPen () const
Fixed | opacity () const
Attribute | tiling () const
Attribute | gradient () const

## Protected Member Functions

virtual void | doPush ()
virtual void | doPop ()
virtual void | doNewPath ()
virtual void | doMoveTo (const Vector &v)
virtual void | doLineTo (const Vector &v)
virtual void | doCurveTo (const Vector &v1, const Vector &v2, const Vector &v3)
virtual void | doDrawArc (const Arc &arc)
virtual void | doClosePath ()
virtual void | doDrawPath (TPathMode mode)
virtual void | doDrawBitmap (Bitmap bitmap)
virtual void | doDrawText (const Text *text)
virtual void | doDrawSymbol (Attribute symbol)
virtual void | doAddClipPath ()
void | drawArcAsBezier (double alpha)

## Protected Attributes

std::list< State > | iState
std::list< Matrix > | iMatrix
const Cascade * | iCascade
int | iInPath

## Detailed Description

Interface for drawing.

Painter-derived classes are used for drawing to the screen and for generating PDF and Postscript output.

The Painter maintains a stack of graphics states, which includes stroke and fill color, line width, dash style, miter limit, line cap and line join. It also maintains a separate stack of transformation matrices. The Painter class takes care of maintaining the stacks, and setting of the attributes in the current graphics state.

Setting an attribute with a symbolic value is resolved immediately using the stylesheet Cascade attached to the Painter, so calling the stroke() or fill() methods of Painter will return the current absolute color.

It's okay to set symbolic attributes that the stylesheet does not define - they are set to a default absolute value (black, solid, etc.).

The painter is either in "general" or in "path construction" mode. The newPath() member starts path construction mode. In this mode, only the path construction operators (moveTo, lineTo, curveTo, rect, drawArc, closePath), the transformation operators (transform, untransform, translate), and the matrix stack operators (pushMatrix, popMatrix) are admissible. The path is drawn using drawPath, this ends path construction mode. Path construction operators cannot be used in general mode.

The graphics state for a path must be set before starting path construction mode, that is, before calling newPath().

Derived classes need to implement the doXXX functions for drawing paths, images, and texts. The transformation matrix has already been applied to the coordinates passed to the doXXX functions.

## Constructor & Destructor Documentation

Painter::Painter | ( | const Cascade * | style | ) |

Constructor takes a (cascaded) style sheet, which is not owned.

The initial graphics state contains all default attributes.

Painter::~Painter | ( |  | ) |

virtual

Virtual destructor.

## Member Function Documentation

void Painter::transform | ( | const Matrix & | m | ) |

Concatenate a matrix to current transformation matrix.

void Painter::untransform | ( | TTransformations | trans | ) |

Reset transformation to original one, but with different origin/direction.

This changes the current transformation matrix to the one set before the first push operation, but maintaining the current origin. Only the operations allowed in allowed are applied.

void Painter::translate | ( | const Vector & | v | ) |

Concatenate a translation to current transformation matrix.

void Painter::push | ( |  | ) |

Save current graphics state.

Cannot be called in path construction mode.

void Painter::pop | ( |  | ) |

Restore previous graphics state.

Cannot be called in path construction mode.

void Painter::pushMatrix | ( |  | ) |

Save current transformation matrix.

void Painter::popMatrix | ( |  | ) |

Restore previous transformation matrix.

void Painter::newPath | ( |  | ) |

Enter path construction mode.

void Painter::moveTo | ( | const Vector & | v | ) |

Start a new subpath.

void Painter::lineTo | ( | const Vector & | v | ) |

Add line segment to current subpath.

void Painter::curveTo | ( | const Vector & | v1,
|  | const Vector & | v2,
|  | const Vector & | v3
| ) |  |

Add a Bezier segment to current subpath.

void ipe::Painter::curveTo | ( | const Bezier & | bezier | ) |

inline

Overloaded function.

Assumes current position is `bezier.iV`[0]

void Painter::rect | ( | const Rect & | re | ) |

Add a rectangle subpath to the path.

This is implemented in terms of moveTo() and lineTo().

void ipe::Painter::drawEllipse | ( |  | ) |

void Painter::drawArc | ( | const Arc & | arc | ) |

Add an elliptic arc to current path.

Assumes the current point is arc.beginp().

void Painter::closePath | ( |  | ) |

Close the current subpath.

void Painter::drawPath | ( | TPathMode | mode | ) |

Fill and/or stroke a path.

As in PDF, a "path" can consist of several subpaths. Whether it is filled or stroked depends on mode.

void Painter::drawBitmap | ( | Bitmap | bitmap | ) |

Render a bitmap.

Assumes the transformation matrix has been set up to map the unit square to the image area on the paper.

void Painter::drawText | ( | const Text * | text | ) |

Render a text object.

Stroke color is already set, and the origin is the lower-left corner of the text box (not the reference point!).

void Painter::drawSymbol | ( | Attribute | symbol | ) |

Render a symbol.

The current coordinate system is already the symbol coordinate system. If the symbol is parameterized, then sym-stroke, sym-fill, and sym-pen are already set.

void Painter::addClipPath | ( |  | ) |

Add current path as clip path.

void Painter::setStroke | ( | Attribute | color | ) |

Set stroke color, resolving symbolic color and "sym-x" colors.

void Painter::setFill | ( | Attribute | color | ) |

Set fill color, resolving symbolic color.

void Painter::setPen | ( | Attribute | pen | ) |

Set pen, resolving symbolic value.

void Painter::setDashStyle | ( | Attribute | dash | ) |

Set dash style, resolving symbolic value.

void Painter::setLineCap | ( | TLineCap | cap | ) |

Set line cap.

If cap is EDefaultCap, the current setting remains unchanged.

void Painter::setLineJoin | ( | TLineJoin | join | ) |

Set line join.

If join is EDefaultJoin, the current setting remains unchanged.

void Painter::setFillRule | ( | TFillRule | rule | ) |

Set fill rule (wind or even-odd).

If the rule is EDefaultRule, the current setting remains unchanged.

void Painter::setSymStroke | ( | Attribute | color | ) |

Set symbol stroke color, resolving symbolic color.

void Painter::setSymFill | ( | Attribute | color | ) |

Set symbol fill color, resolving symbolic color.

void Painter::setSymPen | ( | Attribute | wid | ) |

Set symbol pen, resolving symbolic pen.

void Painter::setOpacity | ( | Attribute | opaq | ) |

Set opacity.

void Painter::setTiling | ( | Attribute | tiling | ) |

Set tiling pattern.

If tiling is not `normal`, resets the gradient pattern.

void Painter::setGradient | ( | Attribute | grad | ) |

Set gradient fill.

If grad is not `normal`, resets the tiling pattern.

const Cascade* ipe::Painter::cascade | ( |  | ) | const

inline

Return style sheet cascade.

Color ipe::Painter::stroke | ( |  | ) | const

inline

Return current stroke color.

Color ipe::Painter::fill | ( |  | ) | const

inline

Return current fill color.

const Matrix& ipe::Painter::matrix | ( |  | ) | const

inline

Return current transformation matrix.

Fixed ipe::Painter::pen | ( |  | ) | const

inline

Return current pen.

String ipe::Painter::dashStyle | ( |  | ) | const

inline

Return current dash style (always absolute attribute).

void Painter::dashStyle | ( | std::vector< double > & | dashes,
|  | double & | offset
| ) |  | const

Return dashstyle as a double sequence.

TLineCap ipe::Painter::lineCap | ( |  | ) | const

inline

Return current line cap.

TLineJoin ipe::Painter::lineJoin | ( |  | ) | const

inline

Return current line join.

TFillRule ipe::Painter::fillRule | ( |  | ) | const

inline

Return current fill rule.

Color ipe::Painter::symStroke | ( |  | ) | const

inline

Return current symbol stroke color.

Color ipe::Painter::symFill | ( |  | ) | const

inline

Return current symbol fill color.

Fixed ipe::Painter::symPen | ( |  | ) | const

inline

Return current symbol pen.

Fixed ipe::Painter::opacity | ( |  | ) | const

inline

Return current opacity.

Attribute ipe::Painter::tiling | ( |  | ) | const

inline

Return current tiling.

Attribute ipe::Painter::gradient | ( |  | ) | const

inline

Return current gradient fill.

void Painter::doPush | ( |  | ) |

protectedvirtual

Perform graphics state push on output medium.

Reimplemented in ipe::BBoxPainter, ipe::CairoPainter, and ipe::PdfPainter.

void Painter::doPop | ( |  | ) |

protectedvirtual

Perform graphics state pop on output medium.

Reimplemented in ipe::BBoxPainter, ipe::CairoPainter, and ipe::PdfPainter.

void Painter::doNewPath | ( |  | ) |

protectedvirtual

Perform new path operator.

Reimplemented in ipe::BBoxPainter, ipe::PdfPainter, and ipe::PsPainter.

void Painter::doMoveTo | ( | const Vector & | v | ) |

protectedvirtual

Perform moveto operator.

The transformation matrix has already been applied.

Reimplemented in ipe::BBoxPainter, ipe::CairoPainter, and ipe::PdfPainter.

void Painter::doLineTo | ( | const Vector & | v | ) |

protectedvirtual

Perform lineto operator.

The transformation matrix has already been applied.

Reimplemented in ipe::BBoxPainter, ipe::CairoPainter, and ipe::PdfPainter.

void Painter::doCurveTo | ( | const Vector & | v1,
|  | const Vector & | v2,
|  | const Vector & | v3
| ) |  |

protectedvirtual

Perform curveto operator.

The transformation matrix has already been applied.

Reimplemented in ipe::BBoxPainter, ipe::CairoPainter, and ipe::PdfPainter.

void Painter::doDrawArc | ( | const Arc & | arc | ) |

protectedvirtual

Draw an elliptic arc.

The default implementations calls drawArcAsBezier(). The transformation matrix has not yet been applied to arc.

Reimplemented in ipe::CairoPainter.

void Painter::doClosePath | ( |  | ) |

protectedvirtual

Perform closepath operator.

Reimplemented in ipe::CairoPainter, and ipe::PdfPainter.

void Painter::doDrawPath | ( | TPathMode | mode | ) |

protectedvirtual

Actually draw the path.

Reimplemented in ipe::BBoxPainter, ipe::CairoPainter, ipe::PdfPainter, and ipe::PsPainter.

void Painter::doDrawBitmap | ( | Bitmap | bitmap | ) |

protectedvirtual

Draw a bitmap.

Reimplemented in ipe::BBoxPainter, ipe::CairoPainter, ipe::PdfPainter, and ipe::PsPainter.

void Painter::doDrawText | ( | const Text * | text | ) |

protectedvirtual

Draw a text object.

Reimplemented in ipe::BBoxPainter, ipe::CairoPainter, and ipe::PdfPainter.

void Painter::doDrawSymbol | ( | Attribute | symbol | ) |

protectedvirtual

Draw a symbol.

The default implementation calls the draw method of the object. Only PDF drawing overrides this to reuse a PDF XForm.

Reimplemented in ipe::PdfPainter.

void Painter::doAddClipPath | ( |  | ) |

protectedvirtual

Add a clip path.

Reimplemented in ipe::BBoxPainter, ipe::CairoPainter, ipe::PdfPainter, and ipe::PsPainter.

void Painter::drawArcAsBezier | ( | double | alpha | ) |

protected

Draw an arc of the unit circle of length alpha.

PDF does not have an "arc" or "circle" primitive, so to draw an arc, circle, or ellipse, Ipe has to translate it into a sequence of Bezier curves.

The approximation is based on the following: The unit circle arc from (1,0) to (cos a, sin a) be approximated by a Bezier spline with control points (1, 0), (1, beta) and their mirror images along the line with slope a/2, where beta = 4.0 * (1.0 - cos(a/2)) / (3 * sin(a/2))

Ipe draws circles by drawing four Bezier curves for the quadrants, and arcs by patching together quarter circle approximations with a piece computed from the formula above.

alpha is normalized to [0, 2 pi], and applied starting from the point (1,0).

The function generates a sequence of Bezier splines as calls to curveTo. It is assumed that the caller has already executed a moveTo to the beginning of the arc at (1,0).

This function may modify the transformation matrix.

## Member Data Documentation

std::list<State> ipe::Painter::iState

protected

std::list<Matrix> ipe::Painter::iMatrix

protected

const Cascade* ipe::Painter::iCascade

protected

int ipe::Painter::iInPath

protected

The documentation for this class was generated from the following files:

- ipepainter.h
- ipepainter.cpp