neoscore.core.text

class neoscore.core.text.Text[source]

Bases: PaintedObject

A graphical text object.

__init__(pos: PointDef, parent: Optional[PositionedObject], text: str, font: Optional[Font] = None, brush: Optional[BrushDef] = None, pen: Optional[PenDef] = None, scale: float = 1, rotation: float = 0, background_brush: Optional[BrushDef] = None, z_index: int = 0, breakable: bool = True, alignment_x: AlignmentX = AlignmentX.LEFT, alignment_y: AlignmentY = AlignmentY.BASELINE)[source]
Parameters
  • pos – Position relative to the parent

  • parent – The parent object. Defaults to the document’s first page.

  • text – The text to be displayed

  • font – The font to display the text in.

  • brush – The brush to fill in text shapes with.

  • pen – The pen to trace text outlines with. This defaults to no pen.

  • scale – A scaling factor relative to the font size.

  • rotation – Angle in degrees. Note that breakable rotated text is not currently supported.

  • background_brush – Optional brush used to paint the text’s bounding rect behind it.

  • z_index – Controls draw order with lower values drawn first.

  • breakable – Whether this object should break across lines in Flowable containers.

  • alignment_x – The text’s horizontal alignment relative to pos. Note that text which is not LEFT aligned does not currently display correctly when breaking across flowable lines.

  • alignment_y – The text’s vertical alignment relative to pos.

property breakable_length: Unit

The breakable length of the object.

This is used to determine how and where rendering cuts should be made.

This is derived from other properties and cannot be set directly.

property text: str
property font: Font
property scale: float

A scale factor to be applied to the rendered text.

This is applied in addition to the font size. It has no effect on children.

property rotation: float

An angle in degrees to rotate about the text origin.

Note that breakable rotated text is not currently supported.

This has no effect on children.

property background_brush: Optional[Brush]

The brush to paint over the background with.

property z_index: int

Value controlling draw order with lower values being drawn first

property breakable: bool

Whether this object should be broken across flowable lines.

property alignment_x: AlignmentX

The text’s horizontal alignment relative to pos.

Note that text which is not LEFT aligned does not currently display correctly when breaking across flowable lines.

property alignment_y: AlignmentY

The text’s vertical alignment relative to pos.

bounding_rect

The bounding rect for this text positioned relative to pos.

The rect (x, y) position is relative to the object’s position.

Note that this currently accounts for scaling, but not rotation.

render_complete(pos: Point, flowable_line: Optional[NewLine] = None, flowable_x: Optional[Unit] = None)[source]

Render the entire object.

This is used to render all objects outside flowables, as well as those inside flowables when they fit completely in one line of the flowable.

By default, this is a no-op. Subclasses with rendered appearances should override this.

This and other render methods should generally not be called directly.

Parameters
  • pos – The rendering position in document space for drawing.

  • flowable_line – If in a Flowable, the line in which this object appears

  • flowable_x – If in a Flowable, the flowable x position of this render

render_before_break(pos: Point, flowable_line: NewLine, flowable_x: Unit)[source]

Render the beginning of the object up to a stopping point.

For use in flowable containers when rendering an object that crosses a line or page break. This function should render the beginning portion of the object up to the break.

By default, this is a no-op. Subclasses with rendered appearances should override this.

This and other render methods should generally not be called directly.

Parameters
  • pos – The rendering position in document space for drawing.

  • flowable_line – The line in which this object appears

  • flowable_x – The flowable x position of this render

render_spanning_continuation(pos: Point, flowable_line: NewLine, object_x: Unit)[source]

Render the continuation of an object after a break and before another.

For use in flowable containers when rendering an object that crosses two breaks. This function should render the portion of the object surrounded by breaks on either side.

By default, this is a no-op. Subclasses with rendered appearances should override this.

This and other render methods should generally not be called directly.

Parameters
  • pos – The rendering position in document space for drawing.

  • flowable_line – The line in which this object appears

  • object_x – The local object x position of the line’s start.

render_after_break(pos: Point, flowable_line: NewLine, object_x: Unit)[source]

Render the continuation of an object after a break.

For use in flowable containers when rendering an object that crosses a line or page break. This function should render the ending portion of an object after a break.

By default, this is a no-op. Subclasses with rendered appearances should override this.

This and other render methods should generally not be called directly.

Parameters
  • pos – The rendering position in document space for drawing.

  • flowable_line – The line in which this object appears

  • object_x – The local object x position of the line’s start.