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, draw_on_bounds: false) ⇒ Border

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



224
225
226
227
228
229
# File 'lib/hexapdf/layout/style.rb', line 224

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

Instance Attribute Details

#colorObject (readonly)

The colors of each edge. See Quad.



214
215
216
# File 'lib/hexapdf/layout/style.rb', line 214

def color
  @color
end

#draw_on_boundsObject

Specifies whether the border should be drawn inside the provided rectangle (false, default) or on it (true).



221
222
223
# File 'lib/hexapdf/layout/style.rb', line 221

def draw_on_bounds
  @draw_on_bounds
end

#styleObject (readonly)

The styles of each edge. See Quad.



217
218
219
# File 'lib/hexapdf/layout/style.rb', line 217

def style
  @style
end

#widthObject (readonly)

The widths of each edge. See Quad.



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

def width
  @width
end

Instance Method Details

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

Draws the border onto the canvas.

Depending on #draw_on_bounds the border is drawn inside the rectangle (x, y, w, h) or on it.



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/hexapdf/layout/style.rb', line 248

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

  if draw_on_bounds
    x -= width.left / 2.0
    y -= width.bottom / 2.0
    w += (width.left + width.right) / 2.0
    h += (width.top + width.bottom) / 2.0
  end

  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

#initialize_copy(other) ⇒ Object

Duplicates a Border object’s properties.



232
233
234
235
236
237
# File 'lib/hexapdf/layout/style.rb', line 232

def initialize_copy(other)
  super
  @width = @width.dup
  @color = @color.dup
  @style = @style.dup
end

#none?Boolean

Returns true if there is no border.

Returns:

  • (Boolean)


240
241
242
# File 'lib/hexapdf/layout/style.rb', line 240

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