Class: HexaPDF::Layout::Style::Border

Inherits:
Object
  • Object
show all
Defined in:
lib/hexapdf/layout/style.rb

Overview

Represents the border of a rectangular area.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width: 0, color: 0, style: :solid) ⇒ Border

Creates a new border style. All arguments can be set to any value that a Quad can process.



204
205
206
207
208
# File 'lib/hexapdf/layout/style.rb', line 204

def initialize(width: 0, color: 0, style: :solid)
  @width = Quad.new(width)
  @color = Quad.new(color)
  @style = Quad.new(style)
end

Instance Attribute Details

#colorObject (readonly)

The colors of each edge. See Quad.



198
199
200
# File 'lib/hexapdf/layout/style.rb', line 198

def color
  @color
end

#styleObject (readonly)

The styles of each edge. See Quad.



201
202
203
# File 'lib/hexapdf/layout/style.rb', line 201

def style
  @style
end

#widthObject (readonly)

The widths of each edge. See Quad.



195
196
197
# File 'lib/hexapdf/layout/style.rb', line 195

def width
  @width
end

Instance Method Details

#draw(canvas, x, y, w, h) ⇒ Object

Draws the border onto the canvas, inside the rectangle (x, y, w, h).



216
217
218
219
220
221
222
223
224
225
226
# File 'lib/hexapdf/layout/style.rb', line 216

def draw(canvas, x, y, w, h)
  return if none?

  canvas.save_graphics_state do
    if width.simple? && color.simple? && style.simple?
      draw_simple_border(canvas, x, y, w, h)
    else
      draw_complex_border(canvas, x, y, w, h)
    end
  end
end

#none?Boolean

Returns true if there is no border.

Returns:

  • (Boolean)


211
212
213
# File 'lib/hexapdf/layout/style.rb', line 211

def none?
  width.simple? && width.top == 0
end