Package igraph :: Package drawing :: Module text :: Class TextDrawer
[hide private]
[frames] | no frames]

Class TextDrawer

source code

                 object --+        
                          |        
 baseclasses.AbstractDrawer --+    
                              |    
baseclasses.AbstractCairoDrawer --+
                                  |
                                 TextDrawer

Class that draws text on a Cairo context.

This class supports multi-line text unlike the original Cairo text drawing methods.

Instance Methods [hide private]
 
__init__(self, context, text='', halign='center', valign='center')
Constructs a new instance that will draw the given text on the given Cairo context.
source code
 
draw(self, wrap=False)
Draws the text in the current bounding box of the drawer.
source code
 
get_text_layout(self, x=None, y=None, width=None, wrap=False)
Calculates the layout of the current text. x and y denote the coordinates where the drawing should start. If they are both None, the current position of the context will be used.
source code
 
draw_at(self, x=None, y=None, width=None, wrap=False)
Draws the text by setting up an appropriate path on the Cairo context and filling it. x and y denote the coordinates where the drawing should start. If they are both C{None}, the current position of the context will be used.
source code
 
_iterlines(self)
Iterates over the label line by line and returns a tuple containing the folloing for each line: the line itself, the width of the line and the X-bearing of the line.
source code
 
_iterlines_wrapped(self, width)
Iterates over the label line by line and returns a tuple containing the folloing for each line: the line itself, the width of the line and the X-bearing of the line.
source code
 
text_extents(self)
Returns the X-bearing, Y-bearing, width, height, X-advance and Y-advance of the text.
source code

Inherited from baseclasses.AbstractCairoDrawer (private): _mark_point

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  BOTTOM = 'bottom'
  CENTER = 'center'
  LEFT = 'left'
  RIGHT = 'right'
  TOP = 'top'
Properties [hide private]
  text
Returns the text to be drawn.

Inherited from baseclasses.AbstractCairoDrawer: bbox

Inherited from object: __class__

Method Details [hide private]

__init__(self, context, text='', halign='center', valign='center')
(Constructor)

source code 
Constructs a new instance that will draw the given text on the given Cairo context.
Parameters:
  • context - the context on which we will draw
  • bbox - the bounding box within which we will draw. Can be anything accepted by the constructor of BoundingBox (i.e., a 2-tuple, a 4-tuple or a BoundingBox object).
Overrides: object.__init__

draw(self, wrap=False)

source code 

Draws the text in the current bounding box of the drawer.

Since the class itself is an instance of AbstractCairoDrawer, it has an attribute named bbox which will be used as a bounding box.

Parameters:
  • wrap (boolean) - whether to allow re-wrapping of the text if it does not fit within the bounding box horizontally.
Overrides: baseclasses.AbstractDrawer.draw

get_text_layout(self, x=None, y=None, width=None, wrap=False)

source code 

Calculates the layout of the current text. x and y denote the coordinates where the drawing should start. If they are both None, the current position of the context will be used.

Vertical alignment settings are not taken into account in this method as the text is not drawn within a box.

Parameters:
  • x (float or None) - The X coordinate of the reference point where the layout should start.
  • y (float or None) - The Y coordinate of the reference point where the layout should start.
  • width (float or None) - The width of the box in which the text will be fitted. It matters only when the text is right-aligned or centered. The text will overflow the box if any of the lines is longer than the box width and wrap is False.
  • wrap (boolean) - whether to allow re-wrapping of the text if it does not fit within the given width.
Returns:
a list consisting of (x, y, line) tuples where x and y refer to reference points on the Cairo canvas and line refers to the corresponding text that should be plotted there.

draw_at(self, x=None, y=None, width=None, wrap=False)

source code 

Draws the text by setting up an appropriate path on the Cairo context and filling it. x and y denote the coordinates where the drawing should start. If they are both C{None}, the current position of the context will be used.

Vertical alignment settings are not taken into account in this method as the text is not drawn within a box.

Parameters:
  • x (float or None) - The X coordinate of the reference point where the drawing should start.
  • y (float or None) - The Y coordinate of the reference point where the drawing should start.
  • width (float or None) - The width of the box in which the text will be fitted. It matters only when the text is right-aligned or centered. The text will overflow the box if any of the lines is longer than the box width.
  • wrap (boolean) - whether to allow re-wrapping of the text if it does not fit within the given width.

_iterlines_wrapped(self, width)

source code 

Iterates over the label line by line and returns a tuple containing the folloing for each line: the line itself, the width of the line and the X-bearing of the line.

The difference between this method and _iterlines() is that this method is allowed to re-wrap the line if necessary.

Parameters:
  • width (float or None) - The width of the box in which the text will be fitted. Lines will be wrapped if they are wider than this width.

text_extents(self)

source code 

Returns the X-bearing, Y-bearing, width, height, X-advance and Y-advance of the text.

For multi-line text, the X-bearing and Y-bearing correspond to the first line, while the X-advance is extracted from the last line. and the Y-advance is the sum of all the Y-advances. The width and height correspond to the entire bounding box of the text.


Property Details [hide private]

text

Returns the text to be drawn.
Get Method:
unreachable.text(self) - Returns the text to be drawn.
Set Method:
unreachable.text(self, text) - Sets the text that will be drawn.