class HexaPDF::Content::GraphicObject::Geom2D

Parent

This class provides support for drawing Geom2D objects like line segments and polygons.

By default, the paths for the objects are not only added to the canvas but are also stroked or filled (depending on the specific Geom2D object).

Supported Geom2D objects are:

  • Geom2D::Point

  • Geom2D::Segment

  • Geom2D::Polygon

  • Geom2D::PolygonSet

Examples:

canvas.draw(:geom2d, object: ::Geom2D::Point(-10, 10))
canvas.draw(:geom2d, object: ::Geom2D::Polygon([10, 10], [30, 20], [0, 50]))

See: Geom2D - github.com/gettalong/geom2d

Attributes

object[RW]

The Geom2D object that should be drawn.

This attribute must be set before drawing.

path_only[RW]

Specifies whether only paths should be drawn or if they should be stroked/filled too (the default).

Examples:

canvas.draw(:geom2d, object: ::Geom2D::Segment([0, 0], [0, 50]))
canvas.draw(:geom2d, object: ::Geom2D::Segment([0, 0], [50, 0]), path_only: true)

point_radius[RW]

The radius to use when drawing Geom2D::Point objects, defaults to 1.

Examples:

canvas.draw(:geom2d, object: ::Geom2D::Point(0, 0))
canvas.draw(:geom2d, object: ::Geom2D::Point(50, 0), point_radius: 5)

Public Class Methods

configure(**kwargs)

Creates and configures a new Geom2D drawing support object.

See configure for the allowed keyword arguments.

new()

Creates a Geom2D drawing support object.

A call to configure is mandatory afterwards to set the object to be drawn.

Public Instance Methods

configure(object: nil, point_radius: nil, path_only: nil)

Configures the Geom2D drawing support object. The following arguments are allowed:

:object

The object that should be drawn. If this argument has not been set before and is also not given, an error will be raised when calling draw.

:point_radius

The radius of the points when drawing points.

:path_only

Whether only the path should be drawn.

Any arguments not specified are not modified and retain their old value, see the getter methods for the inital values.

Returns self.

Examples:

obj = canvas.graphic_object(:geom2d, object: ::Geom2D::Point(0, 0))
canvas.draw(obj)
canvas.opacity(fill_alpha: 0.5).fill_color("hp-blue").
  draw(obj, point_radius: 10)

draw(canvas)

Draws the Geom2D object onto the given Canvas.

Examples:

obj = canvas.graphic_object(:geom2d, object: ::Geom2D::Point(0, 0))
obj.draw(canvas)