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.



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

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.

See: HexaPDF::Content::ColorSpace.device_color_from_specification



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

def color
  @color
end

#draw_on_boundsObject

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



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

def draw_on_bounds
  @draw_on_bounds
end

#styleObject (readonly)

The styles of each edge. See Quad.



219
220
221
# File 'lib/hexapdf/layout/style.rb', line 219

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.



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

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.



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

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)


242
243
244
# File 'lib/hexapdf/layout/style.rb', line 242

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