Class: HexaPDF::Content::GraphicObject::Geom2D

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGeom2D

Creates a Geom2D drawing support object.



63
64
65
66
67
# File 'lib/hexapdf/content/graphic_object/geom2d.rb', line 63

def initialize
  @object = nil
  @point_radius = 1
  @path_only = false
end

Instance Attribute Details

#objectObject

The Geom2D object that should be drawn



54
55
56
# File 'lib/hexapdf/content/graphic_object/geom2d.rb', line 54

def object
  @object
end

#path_onlyObject

Specifies whether only paths should be drawn or if they should be stroked/filled too



60
61
62
# File 'lib/hexapdf/content/graphic_object/geom2d.rb', line 60

def path_only
  @path_only
end

#point_radiusObject

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



57
58
59
# File 'lib/hexapdf/content/graphic_object/geom2d.rb', line 57

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.



49
50
51
# File 'lib/hexapdf/content/graphic_object/geom2d.rb', line 49

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.



79
80
81
82
83
84
# File 'lib/hexapdf/content/graphic_object/geom2d.rb', line 79

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.



87
88
89
90
91
92
93
94
95
96
# File 'lib/hexapdf/content/graphic_object/geom2d.rb', line 87

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