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.



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

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.



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

def color
  @color
end

#draw_on_boundsObject

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



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

def draw_on_bounds
  @draw_on_bounds
end

#styleObject (readonly)

The styles of each edge. See Quad.



207
208
209
# File 'lib/hexapdf/layout/style.rb', line 207

def style
  @style
end

#widthObject (readonly)

The widths of each edge. See Quad.



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

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.



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/hexapdf/layout/style.rb', line 238

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.



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

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)


230
231
232
# File 'lib/hexapdf/layout/style.rb', line 230

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