Chemical Data Processing Library Python API - Version 1.2.0
Public Member Functions | Properties | List of all members
CDPL.Vis.TextBlockPrimitive2D Class Reference

A graphics primitive representing a block of styled text. More...

+ Inheritance diagram for CDPL.Vis.TextBlockPrimitive2D:

Public Member Functions

None __init__ ()
 Construct an empty text block primitive at position (0, 0).
 
None __init__ (TextBlockPrimitive2D prim)
 Initializes a copy of the TextBlockPrimitive2D instance prim. More...
 
TextBlockPrimitive2D assign (TextBlockPrimitive2D prim)
 Replaces the current state of self with a copy of the state of the TextBlockPrimitive2D instance prim. More...
 
None setText (str text)
 Specifies the block's text content. More...
 
None clearText ()
 Clears the block's text content.
 
str getText ()
 Returns the block's text content. More...
 
bool hasText ()
 Tells whether the text block has any visible text (includes whitespace). More...
 
None setPosition (Math.Vector2D pos)
 Sets the position of the text block in 2D space. More...
 
None setPosition (float x, float y)
 Sets the position of the text block to (x, y). More...
 
Math.Vector2D getPosition ()
 Returns the position of the text block. More...
 
None setPen (Pen pen)
 Sets the pen defining the default text color. More...
 
Pen getPen ()
 Returns the pen defining the default text color. More...
 
None setFont (Font font)
 Sets the font used for text rendering. More...
 
Font getFont ()
 Returns the font used for text rendering. More...
 
None setAlignment (int alignment)
 Specifies the way lines should be horizontally aligned. More...
 
int getAlignment ()
 Returns the active horizontal text alignment specification. More...
 
None setLineSpacing (float spacing)
 Sets the line spacing value. More...
 
float getLineSpacing ()
 Returns the active line spacing value. More...
 
None layout (FontMetrics font_metrics)
 Performs a layout of the text for the currently specified font using the provided Vis.FontMetrics instance font_metrics. More...
 
- Public Member Functions inherited from CDPL.Vis.GraphicsPrimitive2D
int getObjectID ()
 Returns the numeric identifier (ID) of the wrapped C++ class instance. More...
 
None render (Renderer2D renderer)
 Visualizes the graphics primitive by means of the Renderer2D instance renderer. More...
 
None getBounds (Rectangle2D bounds, FontMetrics font_metrics=0)
 Calculates the bounds of the graphics primitive. More...
 
GraphicsPrimitive2D clone ()
 Creates a dynamically allocated copy of the graphics primitive. More...
 

Properties

 text = property(getText, setText)
 
 position = property(getPosition, setPosition)
 
 pen = property(getPen, setPen)
 
 font = property(getFont, setFont)
 
 alignment = property(getAlignment, setAlignment)
 
 lineSpacing = property(getLineSpacing, setLineSpacing)
 
- Properties inherited from CDPL.Vis.GraphicsPrimitive2D
 objectID = property(getObjectID)
 

Detailed Description

A graphics primitive representing a block of styled text.

Class TextBlockPrimitive2D is smiliar to Vis.TextLabelPrimitive2D but way more versatile. TextBlockPrimitive2D can store/render text that spans multiple lines with configurable line spacing (see setLineSpacing()) and alignment (see setAlignment()), and supports changing text color and various attributes like font weight and slant for individual text portions. Furthermore, text fragments can be rendered sub/super-scripted, under- and overlined as well as striked out. This is achieved by using an XML-based syntax where a portion of text to be rendered in a particular style is enclosed in specific start and end tags. More information on the syntax, the supported styling tags and their meaning can be found in the documentation of the method setText().

Constructor & Destructor Documentation

◆ __init__()

None CDPL.Vis.TextBlockPrimitive2D.__init__ ( TextBlockPrimitive2D  prim)

Initializes a copy of the TextBlockPrimitive2D instance prim.

Parameters
primThe TextBlockPrimitive2D instance to copy.

Member Function Documentation

◆ assign()

TextBlockPrimitive2D CDPL.Vis.TextBlockPrimitive2D.assign ( TextBlockPrimitive2D  prim)

Replaces the current state of self with a copy of the state of the TextBlockPrimitive2D instance prim.

Parameters
primThe TextBlockPrimitive2D instance to copy.
Returns
self

◆ setText()

None CDPL.Vis.TextBlockPrimitive2D.setText ( str  text)

Specifies the block's text content.

Color, font attributes and style of individual text fragments can be controlled by enclosing the concerned piece of text in specific XML tags. The following tags are supported:

TagEffect/Description

Line break
Boldfaced text
Italicized text
<o>Overlined text
Underlined text
Striked-out text
Subscripted text
Superscripted text
<color>Text color; supports the attributes r, g, b and a with a value in the range [0.0, 1.0]; default component values are r=0, b=0, g=0 and a=1

Newline characters
are regarded and interpreted as such. Tab characters \t are replaced by a single whitespace character. Any other special characters are deleted. The supported tags listed above are all optional. Plain ASCII text will thus be rendered using the set font (see setFont()) and color (see setPen()).

Parameters
textThe text content of the block.
Exceptions
Base.ValueErrorif XML parsing of the specified text failed.

◆ getText()

str CDPL.Vis.TextBlockPrimitive2D.getText ( )

Returns the block's text content.

Returns
The text content of the block.

◆ hasText()

bool CDPL.Vis.TextBlockPrimitive2D.hasText ( )

Tells whether the text block has any visible text (includes whitespace).

Returns
True if there is any visible text and False otherwise.

◆ setPosition() [1/2]

None CDPL.Vis.TextBlockPrimitive2D.setPosition ( Math.Vector2D  pos)

Sets the position of the text block in 2D space.

The position specifies the upper-left corner of the text block's bounding box.

Parameters
posTheposition of the text block.

◆ setPosition() [2/2]

None CDPL.Vis.TextBlockPrimitive2D.setPosition ( float  x,
float  y 
)

Sets the position of the text block to (x, y).

The position specifies the upper-left corner of the text block's bounding box.

Parameters
xThe x-position of the text block.
yThe y-position of the baseline.

◆ getPosition()

Math.Vector2D CDPL.Vis.TextBlockPrimitive2D.getPosition ( )

Returns the position of the text block.

Returns
The position of the text block.
See also
setPosition()

◆ setPen()

None CDPL.Vis.TextBlockPrimitive2D.setPen ( Pen  pen)

Sets the pen defining the default text color.

Parameters
penThe pen defining the default text color.

◆ getPen()

Pen CDPL.Vis.TextBlockPrimitive2D.getPen ( )

Returns the pen defining the default text color.

Returns
The pen defining the default text color.

◆ setFont()

None CDPL.Vis.TextBlockPrimitive2D.setFont ( Font  font)

Sets the font used for text rendering.

Parameters
fontThe font used for text rendering.
Note
Calling this method invalidates the current layout (see layout()).

◆ getFont()

Font CDPL.Vis.TextBlockPrimitive2D.getFont ( )

Returns the font used for text rendering.

Returns
The font used for text rendering.

◆ setAlignment()

None CDPL.Vis.TextBlockPrimitive2D.setAlignment ( int  alignment)

Specifies the way lines should be horizontally aligned.

Possible horizontal alignment values are defined in namespace Vis.Alignment.

Parameters
alignmentThe horizontal text alignment specification.

◆ getAlignment()

int CDPL.Vis.TextBlockPrimitive2D.getAlignment ( )

Returns the active horizontal text alignment specification.

Possible horizontal alignment values are defined in namespace Vis.Alignment.

Returns
The current horizontal text alignment specification.

◆ setLineSpacing()

None CDPL.Vis.TextBlockPrimitive2D.setLineSpacing ( float  spacing)

Sets the line spacing value.

The final base line spacing is the product of the specified line spacing and the font height returned by the method Vis.FontMetrics.getHeight() for the set font.

Parameters
spacingThe desired line spacing.

◆ getLineSpacing()

float CDPL.Vis.TextBlockPrimitive2D.getLineSpacing ( )

Returns the active line spacing value.

Returns
The line spacing value.

◆ layout()

None CDPL.Vis.TextBlockPrimitive2D.layout ( FontMetrics  font_metrics)

Performs a layout of the text for the currently specified font using the provided Vis.FontMetrics instance font_metrics.

Parameters
font_metricsAn instance of a class implementing the Vis.FontMetrics interface.
Note
This method must be called before the text is rendered by calling the method render(). The methods setText() or setFont() invalidate the text layout.