neoscore.core.path

class neoscore.core.path.Path[source]

Bases: PaintedObject

A vector path whose elements can be anchored to other objects.

If a Path is in a Flowable, any element parents in the path should be in the same flowable. Likewise, if a path is not in a flowable, all element parts should not be in one either.

__init__(pos: PointDef, parent: Optional[PositionedObject], brush: Optional[BrushDef] = None, pen: Optional[PenDef] = None, rotation: float = 0, background_brush: Optional[BrushDef] = None, z_index: int = 0)[source]
Parameters
  • pos – The position of the path root.

  • parent – The parent object or None

  • brush – The brush to fill shapes with.

  • pen – The pen to draw outlines with.

  • rotation – Angle in degrees. Rotated paths with flowable breaks or path elements parented to other objects are not currently supported.

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

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

classmethod straight_line(start: PointDef, parent: Optional[PositionedObject], end: PointDef, end_parent: Optional[PositionedObject] = None, brush: Optional[BrushDef] = None, pen: Optional[PenDef] = None) Path[source]

Convenience for drawing a single straight line.

Parameters
  • start – The position of the center of the arrow line’s start

  • parent – A parent object

  • end – The position of the end of the line, relative to end_parent if provided or otherwise start

  • end_parent – An optional parent for the end point.

  • brush – The brush to fill shapes with.

  • pen – The pen to draw outlines with. Defaults to no pen.

classmethod rect(pos: PointDef, parent: Optional[PositionedObject], width: Unit, height: Unit, brush: Optional[BrushDef] = None, pen: Optional[PenDef] = None)[source]

Convenience for drawing a rectangle.

classmethod ellipse(pos: PointDef, parent: Optional[PositionedObject], width: Unit, height: Unit, brush: Optional[BrushDef] = None, pen: Optional[PenDef] = None)[source]

Convenience for drawing an ellipse.

pos indicates the top left corner of the ellipse’s bounding rect. To create a path from a center point, use Path.ellipse_from_center.

This can also be used for drawing circles by giving the same width and height.

classmethod ellipse_from_center(center_pos: PointDef, parent: Optional[PositionedObject], width: Unit, height: Unit, brush: Optional[BrushDef] = None, pen: Optional[PenDef] = None)[source]

Convenience for drawing an ellipse from its center point.

The constructed path will have its pos at the ellipse bounding rect’s top left corner.

See also Path.ellipse

classmethod arc(pos: PointDef, parent: Optional[PositionedObject], width: Unit, height: Unit, start_angle: float, stop_angle: float, brush: Optional[BrushDef] = None, pen: Optional[PenDef] = None)[source]

Convenience for drawing an elliptical arc.

Parameters
  • pos – The position of the upper left corner of the traced ellipse. parent: The parent object or None width: The traced ellipse’s width height: The traced ellipse’s height start_angle: The starting arc angle in radians clockwise relative to the 3 o’clock position.

  • parent – The parent object or None

  • width – The full ellipse width

  • height – The full ellipse height

  • start_angle – The start arc angle in radians clockwise relative to the 3 o’clock position.

  • stop_angle – The stopping arc angle, defined like start_angle.

  • brush – The brush to fill shapes with. pen: The pen to draw outlines with.

  • pen – The pen to draw outlines with.

The arc definition can be most easily understood as tracing an ellipse as defined in Path.ellipse(), where pos marks the top-left corner of the ellipse bounding rect. Two angles are provided in clockwise radians relative to the 3 o’clock position. The arc is traced from start_angle clockwise to stop_angle. Consequently, depending on the provided angles the actually drawn path may be far from the Path’s position.

The provided angles are interpreted mod 2*pi. The angle between them must not be 0. This also means arc angles of 2*pi, (i.e. complete ellipses), are not supported as they are interpreted as 0. Complete ellipses should instead be drawn with Path.ellipse().

Raises

ValueError – if invalid angles are given

classmethod arrow(start: PointDef, parent: Optional[PositionedObject], end: PointDef, end_parent: Optional[PositionedObject] = None, brush: Optional[BrushDef] = None, pen: Optional[PenDef] = None, line_width: Unit = Mm(0.35), arrow_head_width: Unit = Mm(1.5), arrow_head_length: Unit = Mm(2.5)) Path[source]

Convenience for drawing an arrow

Parameters
  • start – The position of the center of the arrow line’s start

  • parent – A parent object

  • end – The position of the arrow’s tip, relative to end_parent if provided or start

  • end_parent – An optional parent for the end point.

  • brush – The brush to fill shapes with.

  • pen – The pen to draw outlines with. Defaults to no pen.

  • line_width – The thickness of the arrow’s line

  • arrow_head_width – The width of the arrow head extending perpendicular from the line.

  • arrow_head_length – The length of the arrow head parallel to the line.

Note that end_parent is only used for initially drawing the path. If end_parent moves relative to the path after creation, the path shape will not be automatically updated.

breakable_length

The breakable length of the path.

This is calculated automatically from path contents. By extension, this means that by default all Path objects will automatically wrap in flowables.

property rotation: float

An angle in degrees to rotate about the path origin.

Rotated paths with flowable breaks and path elements anchored to other objects are not currently supported.

property background_brush: Optional[Brush]

An optional brush to paint over the path bounding rect’s background with

property z_index: int

Value controlling draw order with lower values being drawn first

line_to(x: Unit, y: Unit, parent: Optional[PositionedObject] = None)[source]

Draw a path from the current position to a new point.

If the path is empty, this will add two elements, an initial MoveTo(ORIGIN, self) and the requested LineTo.

Parameters
  • x – The end x position

  • y – The end y position

  • parent – An optional parent, whose position the target coordinate will be relative to.

move_to(x: Unit, y: Unit, parent: Optional[PositionedObject] = None)[source]

Close the current sub-path and start a new one.

Parameters
  • x – The end x position

  • y – The end y position

  • parent – An optional parent, whose position the target coordinate will be relative to.

close_subpath()[source]

Close the current sub-path with a line.

Draw a line back to the starting position (including any parent) of the current subpath.

cubic_to(control_1_x: Unit, control_1_y: Unit, control_2_x: Unit, control_2_y: Unit, end_x: Unit, end_y: Unit, control_1_parent: Optional[PositionedObject] = None, control_2_parent: Optional[PositionedObject] = None, end_parent: Optional[PositionedObject] = None)[source]

Draw a cubic bezier curve from the current position to a new point.

If the path is empty, this will add two elements, an initial MoveTo(ORIGIN, self) and the requested CurveTo.

Parameters
  • control_1_x – The x coordinate of the first control point.

  • control_1_y – The y coordinate of the first control point.

  • control_2_x – The x coordinate of the second control point.

  • control_2_y – The y coordinate of the second control point.

  • end_x – The x coordinate of the curve target.

  • end_y – The y coordinate of the curve target.

  • control_1_parent – An optional parent for the first control point. Defaults to self.

  • control_2_parent – An optional parent for the second control point. Defaults to self.

  • end_parent – An optional parent for the curve target. Defaults to self.

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.