Class: HexaPDF::Content::GraphicObject::Geom2D
- Inherits:
-
Object
- Object
- HexaPDF::Content::GraphicObject::Geom2D
- Defined in:
- lib/hexapdf/content/graphic_object/geom2d.rb
Overview
This class provides support for drawing Geom2D objects like line segments and polygons.
See: Geom2D - github.com/gettalong/geom2d
Instance Attribute Summary collapse
-
#object ⇒ Object
The Geom2D object that should be drawn.
-
#path_only ⇒ Object
Specifies whether only paths should be drawn or if they should be stroked/filled too.
-
#point_radius ⇒ Object
The radius to use when drawing Geom2D::Point objects; defaults to 1.
Class Method Summary collapse
-
.configure(**kwargs) ⇒ Object
Creates and configures a new Geom2D drawing support object.
Instance Method Summary collapse
-
#configure(object:, point_radius: nil, path_only: nil) ⇒ Object
Configures the Geom2D drawing support object.
-
#draw(canvas) ⇒ Object
Draws the Geom2D object onto the given Canvas.
-
#initialize ⇒ Geom2D
constructor
Creates a Geom2D drawing support object.
Constructor Details
#initialize ⇒ Geom2D
Creates a Geom2D drawing support object.
66 67 68 69 70 |
# File 'lib/hexapdf/content/graphic_object/geom2d.rb', line 66 def initialize @object = nil @point_radius = 1 @path_only = false end |
Instance Attribute Details
#object ⇒ Object
The Geom2D object that should be drawn
57 58 59 |
# File 'lib/hexapdf/content/graphic_object/geom2d.rb', line 57 def object @object end |
#path_only ⇒ Object
Specifies whether only paths should be drawn or if they should be stroked/filled too
63 64 65 |
# File 'lib/hexapdf/content/graphic_object/geom2d.rb', line 63 def path_only @path_only end |
#point_radius ⇒ Object
The radius to use when drawing Geom2D::Point objects; defaults to 1
60 61 62 |
# File 'lib/hexapdf/content/graphic_object/geom2d.rb', line 60 def point_radius @point_radius end |
Class Method Details
.configure(**kwargs) ⇒ Object
Creates and configures a new Geom2D drawing support object.
See #configure for the allowed keyword arguments.
52 53 54 |
# File 'lib/hexapdf/content/graphic_object/geom2d.rb', line 52 def self.configure(**kwargs) new.configure(**kwargs) end |
Instance Method Details
#configure(object:, point_radius: nil, path_only: nil) ⇒ Object
Configures the Geom2D drawing support object. The following arguments are allowed:
- :object
-
The object that should be drawn.
- :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.
82 83 84 85 86 87 |
# File 'lib/hexapdf/content/graphic_object/geom2d.rb', line 82 def configure(object:, point_radius: nil, path_only: nil) @object = object @point_radius = point_radius if point_radius @path_only = path_only if path_only self end |
#draw(canvas) ⇒ Object
Draws the Geom2D object onto the given Canvas.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/hexapdf/content/graphic_object/geom2d.rb', line 90 def draw(canvas) case @object when ::Geom2D::Point then draw_point(canvas) when ::Geom2D::Segment then draw_segment(canvas) when ::Geom2D::Polygon then draw_polygon(canvas) when ::Geom2D::PolygonSet then draw_polygon_set(canvas) else raise HexaPDF::Error, "Object of type #{@object.class} unusable" end end |