# IpePainter Class Reference
[Ipe Base]

Interface for drawing. More...

Inherited by IpeBBoxPainter, and IpePdfPainter.

List of all members.

## Public Member Functions

- IpePainter (const IpeStyleSheet *style)
- virtual ~IpePainter ()
- void Transform (const IpeMatrix &m)
- void Untransform (bool direct)
- void Translate (const IpeVector &v)
- void Push ()
- void Pop ()
- void NewPath ()
- void MoveTo (const IpeVector &v)
- void LineTo (const IpeVector &v)
- void CurveTo (const IpeVector &v1, const IpeVector &v2, const IpeVector &v3)
- void CurveTo (const IpeBezier &bezier)
- virtual void Rect (const IpeRect &re)
- void DrawEllipse ()
- void DrawArc (double alpha)
- void ClosePath ()
- void DrawPath ()
- void DrawBitmap (IpeBitmap bitmap)
- void DrawText (const IpeText *text)
- void SetStroke (IpeAttribute color)
- void SetFill (IpeAttribute color)
- void SetLineWidth (IpeAttribute wid)
- void SetDashStyle (IpeAttribute dash)
- void SetLineCap (IpeAttribute cap)
- void SetLineJoin (IpeAttribute join)
- void SetWindRule (IpeAttribute rule)
- void SetTextSize (IpeAttribute size)
- void SetMarkSize (IpeAttribute size)
- void SetMarkShape (int shape)
- const IpeStyleSheet * StyleSheet () const
- IpeAttribute Stroke () const
- IpeAttribute Fill () const
- const IpeMatrix & Matrix () const
- IpeAttribute LineWidth () const
- IpeAttribute DashStyle () const
- IpeAttribute LineCap () const
- IpeAttribute LineJoin () const
- IpeAttribute WindRule () const
- IpeAttribute TextSize () const
- IpeAttribute MarkSize () const
- int MarkShape () const
- const IpeRepository * Repository () const

## Protected Types

- typedef std::list< State > StateSeq

## Protected Member Functions

- virtual void DoPush ()
- virtual void DoPop ()
- virtual void DoNewPath ()
- virtual void DoMoveTo (const IpeVector &v)
- virtual void DoLineTo (const IpeVector &v)
- virtual void DoCurveTo (const IpeVector &v1, const IpeVector &v2, const IpeVector &v3)
- virtual void DoClosePath ()
- virtual void DoDrawPath ()
- virtual void DoDrawBitmap (IpeBitmap bitmap)
- virtual void DoDrawText (const IpeText *text)

## Protected Attributes

- StateSeq iState
- const IpeStyleSheet * iStyleSheet
- int iInPath

## Detailed Description

Interface for drawing.

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

The IpePainter maintains a stack of graphics states, which includes stroke and fill color, line width, dash style, miter limit, line cap and line join, and the current transformation matrix. The IpePainter class takes care of maintaining this stack, and setting of the attributes in the current graphics state.

Setting an attribute with a symbolic value is resolved immediately using the IpeStyleSheet attached to the IpePainter, so calling the Stroke() or Fill() methods of IpePainter 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 (normal, black, solid, etc.).

A null fill color is drawn as if it was void. Ipe objects exploit this: only group objects ever need to explicitly contain a 'void' fill color.

A null stroke color means not to draw any outline on paths. This is only meant to support old Ipe files (before 6.0 pre 25).

The correct way to draw filled objects without boundary is to set the line style to 'void'.

A null dash style is drawn as solid.

A null line width is drawn as whatever is the standard of the drawing medium (that is, as line width 0).

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, DrawEllipse, ClosePath), the transformation operators (Transform, Untransform, Translate), and the stack operators (Push, Pop) are admissible. (Pushs and pops must balance inside path construction. Note that pushs and pops inside path construction only affect the current (painter-internal) tranformation matrix, they do not generate Postscript gsave/grestore operators.) The path is drawn using DrawPath, this ends path construction mode. Path construction operators cannot be used in general mode.

Derived classes need to implement the DoXXX functions for drawing paths, images, and texts.

## Constructor & Destructor Documentation

IpePainter::IpePainter | ( | const IpeStyleSheet * | style | ) |

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

The initial graphics state contains all null attributes.

IpePainter::~IpePainter | ( |  | ) | `[virtual]`

Virtual destructor.

## Member Function Documentation

void IpePainter::Transform | ( | const IpeMatrix & | m | ) |

Concatenate a matrix to current transformation matrix.

void IpePainter::Untransform | ( | bool | direct | ) |

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. If direct is `true`, then the x-direction is also kept.

void IpePainter::Translate | ( | const IpeVector & | v | ) |

Concatenate a translation to current transformation matrix.

void IpePainter::Push | ( |  | ) |

Save current graphics state.

void IpePainter::Pop | ( |  | ) |

Restore previous graphics state.

void IpePainter::NewPath | ( |  | ) |

Enter path construction mode.

void IpePainter::MoveTo | ( | const IpeVector & | v | ) |

Start a new subpath.

void IpePainter::LineTo | ( | const IpeVector & | v | ) |

Add line segment to current subpath.

void IpePainter::CurveTo | ( | const IpeVector & | v1,
|  | const IpeVector & | v2,
|  | const IpeVector & | v3 |
| ) |  |  |

Add a Bezier segment to current subpath.

void IpePainter::CurveTo | ( | const IpeBezier & | bezier | ) | `[inline]`

Overloaded function.

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

void IpePainter::Rect | ( | const IpeRect & | re | ) | `[virtual]`

Add a rectangle subpath to the path.

Has a default implementation in terms of MoveTo and LineTo, but derived classes can reimplement for efficiency.

void IpePainter::DrawEllipse | ( |  | ) |

Draw the unit circle.

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.

This does not modify the transformation matrix. The path is generated as a sequence MoveTo .. CurveTo .. ClosePath operators, but is not actually drawn (DrawPath is not called).

void IpePainter::DrawArc | ( | double | alpha | ) |

Draw an arc of the unit circle of length alpha.

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

The function works by generating a sequence of Bezier splines (see DrawEllipse for details of the transformation). It only generates 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.

void IpePainter::ClosePath | ( |  | ) |

Close the current subpath.

void IpePainter::DrawPath | ( |  | ) |

Fill and/or stroke a path (depending on color).

As in PDF, an "path" can consist of several subpaths.

void IpePainter::DrawBitmap | ( | IpeBitmap | 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 IpePainter::DrawText | ( | const IpeText * | text | ) |

Render a text object.

Stroke color is already set, and the origin is the lower-left corner of the text box.

void IpePainter::SetStroke | ( | IpeAttribute | color | ) |

Set stroke color, resolving symbolic color.

void IpePainter::SetFill | ( | IpeAttribute | color | ) |

Set fill color, resolving symbolic color.

A null fill color will ultimately be rendered as void.

void IpePainter::SetLineWidth | ( | IpeAttribute | wid | ) |

Set line width, resolving symbolic value.

void IpePainter::SetDashStyle | ( | IpeAttribute | dash | ) |

Set dash style, resolving symbolic value.

void IpePainter::SetLineCap | ( | IpeAttribute | cap | ) |

Set line cap.

void IpePainter::SetLineJoin | ( | IpeAttribute | join | ) |

Set line join.

void IpePainter::SetWindRule | ( | IpeAttribute | rule | ) |

Set wind rule (wind or even-odd).

void IpePainter::SetTextSize | ( | IpeAttribute | size | ) |

Set font size of text objects.

Paradoxically, this isn't actually used to render text, but for saving Ipegroup objects! Text goes through the IpeLatex interface, and the visitor that scans for text objects and writes them to the Latex source file finds the text size information itself.

void IpePainter::SetMarkSize | ( | IpeAttribute | size | ) |

Set size of mark objects.

void IpePainter::SetMarkShape | ( | int | shape | ) |

Set shape of mark objects.

const IpeStyleSheet* IpePainter::StyleSheet | ( |  | ) | const`[inline]`

Return style sheet.

IpeAttribute IpePainter::Stroke | ( |  | ) | const`[inline]`

Return current stroke color (always absolute).

IpeAttribute IpePainter::Fill | ( |  | ) | const`[inline]`

Return current fill color (always absolute).

const IpeMatrix& IpePainter::Matrix | ( |  | ) | const`[inline]`

Return current transformation matrix.

IpeAttribute IpePainter::LineWidth | ( |  | ) | const`[inline]`

Return current line width (always absolute).

IpeAttribute IpePainter::DashStyle | ( |  | ) | const`[inline]`

Return current dash style (always absolute).

IpeAttribute IpePainter::LineCap | ( |  | ) | const`[inline]`

Return current line cap.

IpeAttribute IpePainter::LineJoin | ( |  | ) | const`[inline]`

Return current line join.

IpeAttribute IpePainter::WindRule | ( |  | ) | const`[inline]`

Return current wind rule.

IpeAttribute IpePainter::TextSize | ( |  | ) | const`[inline]`

Return current text font size.

IpeAttribute IpePainter::MarkSize | ( |  | ) | const`[inline]`

Return current mark size.

int IpePainter::MarkShape | ( |  | ) | const`[inline]`

Return current mark shape.

const IpeRepository* IpePainter::Repository | ( |  | ) | const`[inline]`

Return repository.

void IpePainter::DoPush | ( |  | ) | `[protected, virtual]`

Perform push on output medium (if necessary).

This is not called when client uses Push during path construction!

void IpePainter::DoPop | ( |  | ) | `[protected, virtual]`

Perform pop on output medium (if necessary).

This is not called when client uses Pop during path construction!

void IpePainter::DoNewPath | ( |  | ) | `[protected, virtual]`

Perform new path operator.

void IpePainter::DoMoveTo | ( | const IpeVector & | v | ) | `[protected, virtual]`

Perform moveto operator.

Reimplemented in IpeBBoxPainter.

void IpePainter::DoLineTo | ( | const IpeVector & | v | ) | `[protected, virtual]`

Perform lineto operator.

Reimplemented in IpeBBoxPainter.

void IpePainter::DoCurveTo | ( | const IpeVector & | v1,
|  | const IpeVector & | v2,
|  | const IpeVector & | v3 |
| ) |  |  | `[protected, virtual]`

Perform curveto operator.

Reimplemented in IpeBBoxPainter.

void IpePainter::DoClosePath | ( |  | ) | `[protected, virtual]`

Perform closepath operator.

void IpePainter::DoDrawPath | ( |  | ) | `[protected, virtual]`

Actually draw the path.

void IpePainter::DoDrawBitmap | ( | IpeBitmap | bitmap | ) | `[protected, virtual]`

Draw a bitmap.

Reimplemented in IpeBBoxPainter.

void IpePainter::DoDrawText | ( | const IpeText * | text | ) | `[protected, virtual]`

Draw a text object.

Reimplemented in IpeBBoxPainter.

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

- ipepainter.h
- ipepainter.cpp