Ipelib

Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
ipe::Text Class Reference
Ipe Objects

`#include <ipetext.h>`

Inherits ipe::Object.

## Classes
struct | XForm

## Public Types
enum | TextType { ELabel, EMinipage }
Public Types inherited from ipe::Object
enum | Type { EGroup, EPath, EText, EImage, EReference }

## Public Member Functions
| Text ()
| Text (const AllAttributes &attr, String data, const Vector &pos, TextType type, double width=10.0)
| Text (const Text &rhs)
| ~Text ()
| Text (const XmlAttributes &attr, String data)
virtual Object * | clone () const
virtual Text * | asText ()
virtual Type | type () const
virtual void | saveAsXml (Stream &stream, String layer) const
virtual void | draw (Painter &painter) const
virtual void | drawSimple (Painter &painter) const
virtual void | accept (Visitor &visitor) const
virtual void | addToBBox (Rect &box, const Matrix &m, bool) const
virtual double | distance (const Vector &v, const Matrix &m, double bound) const
virtual void | snapCtl (const Vector &mouse, const Matrix &m, Vector &pos, double &bound) const
virtual void | checkStyle (const Cascade *sheet, AttributeSeq &seq) const
virtual bool | setAttribute (Property prop, Attribute value)
virtual Attribute | getAttribute (Property prop) const noexcept
Vector | align () const
TextType | textType () const
Vector | position () const
String | text () const
void | setStroke (Attribute stroke)
void | setOpacity (Attribute opaq)
Attribute | stroke () const
Attribute | size () const
Attribute | style () const
Attribute | opacity () const
bool | isMinipage () const
void | setTextType (TextType type)
THorizontalAlignment | horizontalAlignment () const
TVerticalAlignment | verticalAlignment () const
void | setHorizontalAlignment (THorizontalAlignment align)
void | setVerticalAlignment (TVerticalAlignment align)
double | width () const
double | height () const
double | depth () const
double | totalHeight () const
void | setSize (Attribute size)
void | setStyle (Attribute style)
void | setWidth (double width)
void | setText (String text)
void | setXForm (XForm *xform) const
const XForm * | getXForm () const
Public Member Functions inherited from ipe::Object
virtual | ~Object ()=0
virtual Group * | asGroup ()
virtual const Group * | asGroup () const
virtual Path * | asPath ()
virtual Image * | asImage ()
virtual Reference * | asReference ()
virtual TPinned | pinned () const
void | setPinned (TPinned pin)
TTransformations | transformations () const
void | setTransformations (TTransformations trans)
void | setMatrix (const Matrix &matrix)
const Matrix & | matrix () const
virtual void | snapVtx (const Vector &mouse, const Matrix &m, Vector &pos, double &bound) const
virtual void | snapBnd (const Vector &mouse, const Matrix &m, Vector &pos, double &bound) const

## Static Public Member Functions
static TVerticalAlignment | makeVAlign (String str, TVerticalAlignment def)
static THorizontalAlignment | makeHAlign (String str, THorizontalAlignment def)
static void | saveAlignment (Stream &stream, THorizontalAlignment h, TVerticalAlignment v)

## Additional Inherited Members
Protected Member Functions inherited from ipe::Object
| Object ()
| Object (const AllAttributes &attr)
| Object (const Object &rhs)
| Object (const XmlAttributes &attr)
void | saveAttributesAsXml (Stream &stream, String layer) const
Static Protected Member Functions inherited from ipe::Object
static void | checkSymbol (Kind kind, Attribute attr, const Cascade *sheet, AttributeSeq &seq)
Protected Attributes inherited from ipe::Object
Matrix | iMatrix
TPinned | iPinned: 8
TTransformations | iTransformations: 8

## Detailed Description

The text object.

The text object stores a Latex source representation, which needs to be translated into PDF by Pdflatex before it can be saved as PDF.

There are two types of text objects: labels and minipages. The textType() method tells you which, or use isMinipage().

The dimensions of a text object are given by width(), height(), and depth(). They are recomputed by Ipe when running LaTeX, with the exception of the width for minipage objects (whose width is fixed). Before Latex has been run, the dimensions are not reliable.

The position of the reference point relative to the text box is given by verticalAlignment() and horizontalAlignment().

The text() must be a legal LaTeX fragment that can be interpreted by LaTeX inside `\hbox`, possibly using the macros or packages defined in the preamble.

## Member Enumeration Documentation

## ◆ TextType

enum ipe::Text::TextType

Enumerator
ELabel |
EMinipage |

## Constructor & Destructor Documentation

## ◆ Text() [1/4]

Text::Text | ( |  | ) |
| explicit

Construct an empty internal text object.

Referenced by clone().

## ◆ Text() [2/4]

Text::Text | ( | const AllAttributes & | attr,
|  | String | data,
|  | const Vector & | pos,
|  | TextType | type,
|  | double | width = `10.0`
| ) |  |
| explicit

Create text object.

References ipe::EAlignTop, ELabel, ipe::ETransformationsTranslations, ipe::AllAttributes::iHorizontalAlignment, ipe::AllAttributes::iLabelStyle, ipe::AllAttributes::iOpacity, ipe::AllAttributes::iStroke, ipe::AllAttributes::iTextSize, ipe::AllAttributes::iTextStyle, ipe::AllAttributes::iTransformableText, ipe::Object::iTransformations, ipe::AllAttributes::iVerticalAlignment, type(), and width().

## ◆ Text() [3/4]

Text::Text | ( | const Text & | rhs | ) |

Copy constructor.

References ipe::Text::XForm::iRefCount.

## ◆ ~Text()

Text::~Text | ( |  | ) |

Destructor.

References ipe::Text::XForm::iRefCount.

## ◆ Text() [4/4]

Text::Text | ( | const XmlAttributes & | attr,
|  | String | data
| ) |  |
| explicit

Create from XML stream.

References ipe::Attribute::BLACK(), ipe::EAlignBottom, ipe::EAlignLeft, ipe::EAlignTop, ELabel, EMinipage, ipe::Lex::getDouble(), ipe::XmlAttributes::has(), isMinipage(), ipe::Attribute::makeColor(), makeHAlign(), ipe::Attribute::makeTextSize(), makeVAlign(), ipe::Attribute::NORMAL(), ipe::Attribute::OPAQUE(), ipe::String::size(), ipe::String::substr(), ipe::Vector::x, and ipe::Vector::y.

## Member Function Documentation

## ◆ clone()

Object * Text::clone | ( |  | ) | const
| virtual

Clone object.

Implements ipe::Object.

References Text().

## ◆ asText()

Text * Text::asText | ( |  | ) |
| virtual

Return pointer to this object.

Reimplemented from ipe::Object.

## ◆ type()

Object::Type Text::type | ( |  | ) | const
| virtual

Implements ipe::Object.

References ipe::Object::EText.

Referenced by setTextType(), and Text().

## ◆ saveAsXml()

void Text::saveAsXml | ( | Stream & | stream,
|  | String | layer
| ) |  | const
| virtual

Save object to XML stream.

Implements ipe::Object.

References ELabel, EMinipage, isMinipage(), ipe::Attribute::NORMAL(), ipe::Attribute::OPAQUE(), ipe::Stream::putXmlString(), saveAlignment(), ipe::Object::saveAttributesAsXml(), ipe::Attribute::string(), ipe::Vector::x, and ipe::Vector::y.

## ◆ draw()

void Text::draw | ( | Painter & | painter | ) | const
| virtual

Save text as PDF.

Implements ipe::Object.

References align(), ipe::Painter::drawText(), ipe::Object::matrix(), ipe::Painter::pop(), ipe::Painter::popMatrix(), ipe::Painter::push(), ipe::Painter::pushMatrix(), ipe::Painter::setOpacity(), ipe::Painter::setStroke(), ipe::Painter::transform(), ipe::Object::transformations(), ipe::Painter::translate(), and ipe::Painter::untransform().

Referenced by ipe::CanvasBase::drawObjects(), and ipe::PdfWriter::~PdfWriter().

## ◆ drawSimple()

void Text::drawSimple | ( | Painter & | painter | ) | const
| virtual

Draw simple version for selecting and transforming.

Implements ipe::Object.

References align(), ipe::Painter::closePath(), ipe::Painter::drawPath(), ipe::EStrokedOnly, ipe::Painter::lineTo(), ipe::Object::matrix(), ipe::Painter::moveTo(), ipe::Painter::newPath(), ipe::Painter::popMatrix(), ipe::Painter::pushMatrix(), totalHeight(), ipe::Painter::transform(), ipe::Object::transformations(), ipe::Painter::translate(), and ipe::Painter::untransform().

## ◆ accept()

void Text::accept | ( | Visitor & | visitor | ) | const
| virtual

Call visitText of visitor.

Implements ipe::Object.

References ipe::Visitor::visitText().

Referenced by ipe::Latex::scanPage().

## ◆ addToBBox()

void Text::addToBBox | ( | Rect & | box,
|  | const Matrix & | m,
|  | bool | cp
| ) |  | const
| virtual

Extend box to include the object transformed by m.

For objects in a page, don't call this directly. The Page caches the bounding box of each object, so it is far more efficient to call Page::bbox.

Control points that lie outside the visual object are included if cp is true.

If called with an empty box and cp == `false`, the result of this function is a tight bounding box for the object, with a little leeway in case the boundary is determined by a spline (it has to be approximated to perform this operation).

Implements ipe::Object.

References ipe::Rect::addPoint().

## ◆ distance()

double Text::distance | ( | const Vector & | v,
|  | const Matrix & | m,
|  | double | bound
| ) |  | const
| virtual

Return distance of transformed object to point v. If larger than bound, can just return bound.

Implements ipe::Object.

## ◆ snapCtl()

void Text::snapCtl | ( | const Vector & | mouse,
|  | const Matrix & | m,
|  | Vector & | pos,
|  | double & | bound
| ) |  | const
| virtual

Compute control point snapping position for transformed object.

Looks only for positions closer than bound. If successful, modify pos and bound. The default implementation does nothing.

Reimplemented from ipe::Object.

References ipe::Object::matrix().

## ◆ checkStyle()

void Text::checkStyle | ( | const Cascade * | sheet,
|  | AttributeSeq & | seq
| ) |  | const
| virtual

Check symbolic size attribute.

Reimplemented from ipe::Object.

References ipe::Matrix::a, align(), ipe::Object::checkSymbol(), ipe::EColor, ELabel, ipe::ELabelStyle, ipe::EOpacity, ipe::ETextSize, ipe::ETextStyle, ipe::ETransformationsRigidMotions, ipe::ETransformationsTranslations, ipe::Object::iTransformations, ipe::Object::matrix(), totalHeight(), and ipe::Matrix::translation().

## ◆ setAttribute()

bool Text::setAttribute | ( | Property | prop,
|  | Attribute | value
| ) |  |
| virtual

Set an attribute on this object.

Returns true if an attribute was actually changed.

Reimplemented from ipe::Object.

References ipe::Attribute::boolean(), ELabel, EMinipage, ipe::EPropHorizontalAlignment, ipe::EPropLabelStyle, ipe::EPropMinipage, ipe::EPropOpacity, ipe::EPropStrokeColor, ipe::EPropTextSize, ipe::EPropTextStyle, ipe::EPropTransformableText, ipe::EPropVerticalAlignment, ipe::EPropWidth, ipe::ETransformationsAffine, ipe::ETransformationsTranslations, horizontalAlignment(), ipe::Attribute::horizontalAlignment(), ipe::Attribute::isEnum(), isMinipage(), ipe::Attribute::isNumber(), ipe::Attribute::NORMAL(), ipe::Attribute::number(), opacity(), ipe::Object::setAttribute(), setOpacity(), setSize(), setStroke(), setStyle(), ipe::Object::setTransformations(), setWidth(), size(), stroke(), style(), ipe::Fixed::toDouble(), ipe::Object::transformations(), verticalAlignment(), ipe::Attribute::verticalAlignment(), and width().

## ◆ getAttribute()

Attribute Text::getAttribute | ( | Property | prop | ) | const
| virtual noexcept

Get setting of an attribute of this object.

If object does not have this attribute, returnes "undefined" attribute.

Reimplemented from ipe::Object.

References ipe::Attribute::Boolean(), ipe::EPropHorizontalAlignment, ipe::EPropLabelStyle, ipe::EPropMinipage, ipe::EPropOpacity, ipe::EPropStrokeColor, ipe::EPropTextSize, ipe::EPropTextStyle, ipe::EPropVerticalAlignment, ipe::EPropWidth, ipe::Fixed::fromDouble(), ipe::Object::getAttribute(), horizontalAlignment(), isMinipage(), opacity(), size(), stroke(), style(), verticalAlignment(), and width().

## ◆ align()

Vector Text::align | ( |  | ) | const

Return position of reference point in text box coordinate system.

Assume a coordinate system where the text box has corners (0,0) and (Width(), TotalHeight()). This function returns the coordinates of the reference point in this coordinate system.

References depth(), ipe::EAlignBaseline, ipe::EAlignBottom, ipe::EAlignHCenter, ipe::EAlignLeft, ipe::EAlignRight, ipe::EAlignTop, ipe::EAlignVCenter, horizontalAlignment(), isMinipage(), totalHeight(), verticalAlignment(), width(), ipe::Vector::x, and ipe::Vector::y.

Referenced by checkStyle(), ipe::CairoPainter::doDrawText(), draw(), drawSimple(), setHorizontalAlignment(), and setVerticalAlignment().

## ◆ textType()

Text::TextType Text::textType | ( |  | ) | const

Return type of text object.

References ELabel.

Referenced by setWidth().

## ◆ position()

Vector ipe::Text::position | ( |  | ) | const
| inline

Return text position.

## ◆ text()

String ipe::Text::text | ( |  | ) | const
| inline

Return text source.

Referenced by ipe::Latex::createLatexSource(), ipe::CairoPainter::doDrawText(), ipe::PdfResources::pageNumber(), and setText().

## ◆ setStroke()

void Text::setStroke | ( | Attribute | stroke | ) |

Set stroke color.

References stroke().

Referenced by ipe::Page::applyTitleStyle(), and setAttribute().

## ◆ setOpacity()

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

Set opacity of the object.

Referenced by setAttribute().

## ◆ stroke()

Attribute ipe::Text::stroke | ( |  | ) | const
| inline

Return stroke color.

Referenced by ipe::Latex::createLatexSource(), getAttribute(), setAttribute(), and setStroke().

## ◆ size()

Attribute ipe::Text::size | ( |  | ) | const
| inline

Return font size.

Referenced by ipe::Latex::addPageNumber(), getAttribute(), setAttribute(), setSize(), and ipe::Latex::takeResources().

## ◆ style()

Attribute ipe::Text::style | ( |  | ) | const
| inline

Return Latex style of text object.

Referenced by ipe::Latex::createLatexSource(), getAttribute(), setAttribute(), and setStyle().

## ◆ opacity()

Attribute ipe::Text::opacity | ( |  | ) | const
| inline

Return opacity of the opject.

References depth(), height(), horizontalAlignment(), isMinipage(), makeHAlign(), makeVAlign(), saveAlignment(), setHorizontalAlignment(), setSize(), setStyle(), setText(), setTextType(), setVerticalAlignment(), setWidth(), totalHeight(), verticalAlignment(), and width().

Referenced by getAttribute(), and setAttribute().

## ◆ isMinipage()

bool ipe::Text::isMinipage | ( |  | ) | const
| inline

Return true if text object is formatted as a minipage.

Equivalent to type being EMinipage.

References EMinipage.

Referenced by align(), ipe::Latex::createLatexSource(), getAttribute(), opacity(), saveAsXml(), setAttribute(), setXForm(), and Text().

## ◆ setTextType()

void Text::setTextType | ( | TextType | type | ) |

Change type.

This invalidates (and destroys) the XForm.

References ipe::Attribute::NORMAL(), setXForm(), and type().

Referenced by opacity().

## ◆ horizontalAlignment()

THorizontalAlignment ipe::Text::horizontalAlignment | ( |  | ) | const
| inline

Return horizontal alignment of text object.

Referenced by align(), getAttribute(), opacity(), and setAttribute().

## ◆ verticalAlignment()

TVerticalAlignment ipe::Text::verticalAlignment | ( |  | ) | const
| inline

Return vertical alignment of text object.

Referenced by align(), getAttribute(), opacity(), and setAttribute().

## ◆ setHorizontalAlignment()

void Text::setHorizontalAlignment | ( | THorizontalAlignment | align | ) |

Change horizontal alignment (text moves with respect to reference point).

References align().

Referenced by ipe::Page::applyTitleStyle(), and opacity().

## ◆ setVerticalAlignment()

void Text::setVerticalAlignment | ( | TVerticalAlignment | align | ) |

Change vertical alignment (text moves with respect to reference point).

References align().

Referenced by ipe::Page::applyTitleStyle(), and opacity().

## ◆ makeVAlign()

TVerticalAlignment Text::makeVAlign | ( | String | str,
|  | TVerticalAlignment | def
| ) |  |
| static

Return vertical alignment indicated by a name, or else default.

References ipe::EAlignBaseline, ipe::EAlignBottom, ipe::EAlignTop, and ipe::EAlignVCenter.

Referenced by opacity(), ipe::ImlParser::parseStyle(), and Text().

## ◆ makeHAlign()

THorizontalAlignment Text::makeHAlign | ( | String | str,
|  | THorizontalAlignment | def
| ) |  |
| static

Return horizontal alignment indicated by a name, or else default.

References ipe::EAlignHCenter, ipe::EAlignLeft, and ipe::EAlignRight.

Referenced by opacity(), ipe::ImlParser::parseStyle(), and Text().

## ◆ saveAlignment()

void Text::saveAlignment | ( | Stream & | stream,
|  | THorizontalAlignment | h,
|  | TVerticalAlignment | v
| ) |  |
| static

References ipe::EAlignBaseline, ipe::EAlignBottom, ipe::EAlignHCenter, ipe::EAlignLeft, ipe::EAlignRight, ipe::EAlignTop, and ipe::EAlignVCenter.

Referenced by opacity(), saveAsXml(), and ipe::StyleSheet::saveAsXml().

## ◆ width()

double ipe::Text::width | ( |  | ) | const
| inline

Return width of text object.

Referenced by align(), ipe::Latex::createLatexSource(), ipe::BBoxPainter::doDrawText(), ipe::CairoPainter::doDrawText(), getAttribute(), opacity(), setAttribute(), setWidth(), and Text().

## ◆ height()

double ipe::Text::height | ( |  | ) | const
| inline

Return height of text object (from baseline to top).

Referenced by opacity().

## ◆ depth()

double ipe::Text::depth | ( |  | ) | const
| inline

Return depth of text object.

References ipe::Text::XForm::iDepth.

Referenced by align(), and opacity().

## ◆ totalHeight()

double ipe::Text::totalHeight | ( |  | ) | const
| inline

Return height + depth of text object.

References ipe::Text::XForm::iDepth.

Referenced by align(), checkStyle(), ipe::BBoxPainter::doDrawText(), ipe::CairoPainter::doDrawText(), drawSimple(), and opacity().

## ◆ setSize()

void Text::setSize | ( | Attribute | size | ) |

Set font size of text.

This invalidates (and destroys) the XForm.

References setXForm(), and size().

Referenced by ipe::Page::applyTitleStyle(), opacity(), and setAttribute().

## ◆ setStyle()

void Text::setStyle | ( | Attribute | style | ) |

Set Latex style of text.

This invalidates (and destroys) the XForm.

References setXForm(), and style().

Referenced by opacity(), and setAttribute().

## ◆ setWidth()

void Text::setWidth | ( | double | width | ) |

Set width of paragraph.

This invalidates (and destroys) the XForm. The function panics if object is not a (true) minipage.

References EMinipage, setXForm(), textType(), and width().

Referenced by opacity(), and setAttribute().

## ◆ setText()

void Text::setText | ( | String | text | ) |

Sets the text of the text object.

This invalidates (and destroys) the XForm.

References setXForm(), and text().

Referenced by opacity(), and ipe::Page::setTitle().

## ◆ setXForm()

void Text::setXForm | ( | XForm * | xform | ) | const

Update the PDF code for this object.

References ipe::Rect::height(), ipe::Text::XForm::iBBox, ipe::Text::XForm::iDepth, ipe::Text::XForm::iRefCount, isMinipage(), ipe::Text::XForm::iStretch, and ipe::Rect::width().

Referenced by setSize(), setStyle(), setText(), setTextType(), and setWidth().

## ◆ getXForm()

const Text::XForm * ipe::Text::getXForm | ( |  | ) | const
| inline

Return the PDF representation of this text object.

If Pdflatex has not been run yet, returns 0.

Referenced by ipe::Latex::createLatexSource(), ipe::PdfPainter::doDrawText(), and ipe::CairoPainter::doDrawText().

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

- ipetext.h
- ipetext.cpp