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

#include <ipepainter.h>

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

Classes

struct  State
 

Public Member Functions

 Painter (const Cascade *style)
 
virtual ~Painter ()
 
void setAttributeMap (const AttributeMap *map)
 
Attribute lookup (Kind kind, Attribute sym) const
 
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 setStrokeOpacity (Attribute opaq)
 
void setTiling (Attribute til)
 
void setGradient (Attribute grad)
 
const Cascadecascade () const
 
Color stroke () const
 
Color fill () const
 
const Matrixmatrix () 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
 
Fixed strokeOpacity () const
 
Attribute tiling () const
 
Attribute gradient () const
 
const Statestate () const
 
void setState (const State &state)
 

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< StateiState
 
std::list< MatrixiMatrix
 
const CascadeiCascade
 
const AttributeMapiAttributeMap
 
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::Painter ( const Cascade style)

◆ ~Painter()

Painter::~Painter ( )
virtual

Virtual destructor.

Member Function Documentation

◆ setAttributeMap()

void Painter::setAttributeMap ( const AttributeMap map)

◆ lookup()

Attribute Painter::lookup ( Kind  kind,
Attribute  sym 
) const

◆ transform()

void Painter::transform ( const Matrix m)

◆ untransform()

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.

References ipe::Matrix::a, ipe::ETransformationsAffine, ipe::ETransformationsRigidMotions, iMatrix, ipe::Linear::inverse(), matrix(), and ipe::Matrix::translation().

Referenced by ipe::Group::draw(), ipe::Reference::draw(), ipe::Text::draw(), ipe::Image::draw(), ipe::Path::draw(), ipe::Path::drawArrow(), ipe::Group::drawSimple(), ipe::Reference::drawSimple(), ipe::Text::drawSimple(), ipe::Image::drawSimple(), and ipe::Path::drawSimple().

◆ translate()

void Painter::translate ( const Vector v)

◆ push()

void Painter::push ( )

Save current graphics state.

Cannot be called in path construction mode.

References doPush(), iInPath, iState, and state().

Referenced by ipe::Group::draw(), ipe::Reference::draw(), ipe::Text::draw(), ipe::Image::draw(), ipe::Path::draw(), ipe::Path::drawArrow(), ipe::Group::drawSimple(), and ipe::Reference::drawSimple().

◆ pop()

void Painter::pop ( )

Restore previous graphics state.

Cannot be called in path construction mode.

References doPop(), iInPath, and iState.

Referenced by ipe::Group::draw(), ipe::Reference::draw(), ipe::Text::draw(), ipe::Image::draw(), ipe::Path::draw(), ipe::Path::drawArrow(), ipe::Group::drawSimple(), and ipe::Reference::drawSimple().

◆ pushMatrix()

void Painter::pushMatrix ( )

◆ popMatrix()

void Painter::popMatrix ( )

◆ newPath()

void Painter::newPath ( )

◆ moveTo()

void Painter::moveTo ( const Vector v)

◆ lineTo()

void Painter::lineTo ( const Vector v)

Add line segment to current subpath.

References doLineTo(), iInPath, and matrix().

Referenced by ipe::CurveSegment::draw(), ipe::Path::drawArrow(), ipe::Reference::drawSimple(), ipe::Text::drawSimple(), and rect().

◆ curveTo() [1/2]

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

Add a Bezier segment to current subpath.

References doCurveTo(), iInPath, and matrix().

Referenced by curveTo(), ipe::CurveSegment::draw(), ipe::ClosedSpline::draw(), and drawArcAsBezier().

◆ curveTo() [2/2]

void ipe::Painter::curveTo ( const Bezier bezier)
inline

Overloaded function.

Assumes current position is bezier.iV[0]

References curveTo(), and ipe::Bezier::iV.

◆ rect()

void Painter::rect ( const Rect re)

◆ drawEllipse()

void ipe::Painter::drawEllipse ( )

◆ drawArc()

void Painter::drawArc ( const Arc arc)

Add an elliptic arc to current path.

Assumes the current point is arc.beginp().

References doDrawArc(), and iInPath.

Referenced by ipe::CurveSegment::draw(), ipe::Ellipse::draw(), ipe::SelectTool::draw(), and ipe::Path::drawArrow().

◆ closePath()

void Painter::closePath ( )

◆ drawPath()

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.

References doDrawPath(), and iInPath.

Referenced by ipe::PanTool::draw(), ipe::SelectTool::draw(), ipe::Path::draw(), ipe::Path::drawArrow(), ipe::Reference::drawSimple(), ipe::Text::drawSimple(), ipe::Image::drawSimple(), and ipe::Path::drawSimple().

◆ drawBitmap()

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.

References doDrawBitmap(), and iInPath.

Referenced by ipe::Image::draw().

◆ drawText()

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!).

References doDrawText(), and iInPath.

Referenced by ipe::Text::draw().

◆ drawSymbol()

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.

References doDrawSymbol(), and iInPath.

Referenced by ipe::Reference::draw(), and ipe::Thumbnail::saveRender().

◆ addClipPath()

void Painter::addClipPath ( )

Add current path as clip path.

References doAddClipPath(), and iInPath.

Referenced by ipe::Group::draw(), and ipe::Group::drawSimple().

◆ setStroke()

void Painter::setStroke ( Attribute  color)

◆ setFill()

void Painter::setFill ( Attribute  color)

◆ setPen()

void Painter::setPen ( Attribute  pen)

Set pen, resolving symbolic value.

References ipe::EPen, iInPath, iState, lookup(), ipe::Attribute::number(), pen(), and ipe::Attribute::SYM_PEN().

Referenced by ipe::Path::draw(), and ipe::CanvasBase::drawTool().

◆ setDashStyle()

void Painter::setDashStyle ( Attribute  dash)

Set dash style, resolving symbolic value.

References ipe::EDashStyle, iInPath, iState, lookup(), and ipe::Attribute::string().

Referenced by ipe::Path::draw().

◆ setLineCap()

void Painter::setLineCap ( TLineCap  cap)

Set line cap.

If cap is EDefaultCap, the current setting remains unchanged.

References ipe::EDefaultCap, iInPath, and iState.

Referenced by ipe::Path::draw().

◆ setLineJoin()

void Painter::setLineJoin ( TLineJoin  join)

Set line join.

If join is EDefaultJoin, the current setting remains unchanged.

References ipe::EDefaultJoin, iInPath, and iState.

Referenced by ipe::Path::draw().

◆ setFillRule()

void Painter::setFillRule ( TFillRule  rule)

Set fill rule (wind or even-odd).

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

References ipe::EDefaultRule, iInPath, and iState.

Referenced by ipe::Path::draw().

◆ setSymStroke()

void Painter::setSymStroke ( Attribute  color)

Set symbol stroke color, resolving symbolic color.

References ipe::Attribute::color(), ipe::EColor, iInPath, iState, lookup(), ipe::Attribute::SYM_FILL(), and ipe::Attribute::SYM_STROKE().

Referenced by ipe::Reference::draw(), and ipe::Path::drawArrow().

◆ setSymFill()

void Painter::setSymFill ( Attribute  color)

◆ setSymPen()

void Painter::setSymPen ( Attribute  wid)

Set symbol pen, resolving symbolic pen.

References ipe::EPen, iInPath, iState, lookup(), ipe::Attribute::number(), pen(), and ipe::Attribute::SYM_PEN().

Referenced by ipe::Reference::draw(), and ipe::Path::drawArrow().

◆ setOpacity()

void Painter::setOpacity ( Attribute  opaq)

◆ setStrokeOpacity()

void Painter::setStrokeOpacity ( Attribute  opaq)

Set stroke opacity.

References ipe::EOpacity, iInPath, iState, lookup(), and ipe::Attribute::number().

Referenced by ipe::Path::draw().

◆ setTiling()

void Painter::setTiling ( Attribute  tiling)

Set tiling pattern.

If tiling is not normal, resets the gradient pattern.

References iInPath, ipe::Attribute::isNormal(), iState, ipe::Attribute::NORMAL(), and tiling().

Referenced by ipe::Path::draw().

◆ setGradient()

void Painter::setGradient ( Attribute  grad)

Set gradient fill.

If grad is not normal, resets the tiling pattern.

References iInPath, ipe::Attribute::isNormal(), iState, and ipe::Attribute::NORMAL().

Referenced by ipe::Path::draw().

◆ cascade()

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

◆ stroke()

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

Return current stroke color.

References iState.

Referenced by ipe::CairoPainter::doDrawPath(), ipe::CairoPainter::doDrawText(), and ipe::Path::drawArrow().

◆ fill()

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

Return current fill color.

References iState.

Referenced by ipe::CairoPainter::doDrawPath().

◆ matrix()

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

◆ pen()

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

◆ dashStyle() [1/2]

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

Return current dash style (always absolute attribute).

References iState.

Referenced by dashStyle(), and ipe::CairoPainter::doDrawPath().

◆ dashStyle() [2/2]

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

Return dashstyle as a double sequence.

References dashStyle(), ipe::Lex::eos(), ipe::String::find(), ipe::Lex::getDouble(), and ipe::String::substr().

◆ lineCap()

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

Return current line cap.

References iState.

Referenced by ipe::CairoPainter::doDrawPath().

◆ lineJoin()

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

Return current line join.

References iState.

Referenced by ipe::CairoPainter::doDrawPath().

◆ fillRule()

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

Return current fill rule.

References iState.

Referenced by ipe::PdfPainter::doDrawPath(), and ipe::CairoPainter::doDrawPath().

◆ symStroke()

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

Return current symbol stroke color.

References iState.

◆ symFill()

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

Return current symbol fill color.

References iState.

◆ symPen()

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

Return current symbol pen.

References iState.

◆ opacity()

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

◆ strokeOpacity()

Fixed ipe::Painter::strokeOpacity ( ) const
inline

Return current stroke opacity.

References iState.

Referenced by ipe::CairoPainter::doDrawPath().

◆ tiling()

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

Return current tiling.

References iState.

Referenced by ipe::CairoPainter::doDrawPath(), and setTiling().

◆ gradient()

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

Return current gradient fill.

References iState.

Referenced by ipe::CairoPainter::doDrawPath().

◆ state()

const State& ipe::Painter::state ( ) const
inline

Return full current graphics state.

References iState.

Referenced by ipe::PdfPainter::doPush(), Painter(), ipe::PdfPainter::PdfPainter(), push(), and setState().

◆ setState()

void Painter::setState ( const State state)

Set full graphics state at once.

References iState, and state().

◆ doPush()

void Painter::doPush ( )
protectedvirtual

Perform graphics state push on output medium.

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

Referenced by push().

◆ doPop()

void Painter::doPop ( )
protectedvirtual

Perform graphics state pop on output medium.

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

Referenced by pop().

◆ doNewPath()

void Painter::doNewPath ( )
protectedvirtual

Perform new path operator.

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

Referenced by newPath().

◆ doMoveTo()

void Painter::doMoveTo ( const Vector v)
protectedvirtual

Perform moveto operator.

The transformation matrix has already been applied.

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

Referenced by moveTo().

◆ doLineTo()

void Painter::doLineTo ( const Vector v)
protectedvirtual

Perform lineto operator.

The transformation matrix has already been applied.

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

Referenced by lineTo().

◆ doCurveTo()

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::CairoPainter, ipe::BBoxPainter, and ipe::PdfPainter.

Referenced by curveTo().

◆ doDrawArc()

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.

References drawArcAsBezier(), ipe::Arc::iAlpha, ipe::Arc::iBeta, ipe::Arc::iM, ipe::Arc::isEllipse(), moveTo(), ipe::Angle::normalize(), popMatrix(), pushMatrix(), and transform().

Referenced by drawArc().

◆ doClosePath()

void Painter::doClosePath ( )
protectedvirtual

Perform closepath operator.

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

Referenced by closePath().

◆ doDrawPath()

void Painter::doDrawPath ( TPathMode  mode)
protectedvirtual

Actually draw the path.

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

Referenced by drawPath().

◆ doDrawBitmap()

void Painter::doDrawBitmap ( Bitmap  bitmap)
protectedvirtual

Draw a bitmap.

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

Referenced by drawBitmap().

◆ doDrawText()

void Painter::doDrawText ( const Text text)
protectedvirtual

Draw a text object.

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

Referenced by drawText().

◆ doDrawSymbol()

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.

References cascade(), ipe::Object::draw(), ipe::ESymbol, ipe::Cascade::findSymbol(), iAttributeMap, ipe::Symbol::iObject, and ipe::AttributeMap::map().

Referenced by drawSymbol().

◆ doAddClipPath()

void Painter::doAddClipPath ( )
protectedvirtual

Add a clip path.

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

Referenced by addClipPath().

◆ drawArcAsBezier()

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.

References curveTo().

Referenced by doDrawArc().

Member Data Documentation

◆ iState

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

◆ iMatrix

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

◆ iCascade

const Cascade* ipe::Painter::iCascade
protected

◆ iAttributeMap

const AttributeMap* ipe::Painter::iAttributeMap
protected

◆ iInPath

int ipe::Painter::iInPath
protected

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