Class: HexaPDF::Layout::Style::Border
- Inherits:
-
Object
- Object
- HexaPDF::Layout::Style::Border
- Defined in:
- lib/hexapdf/layout/style.rb
Overview
Represents the border of a rectangular area.
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
The colors of each edge.
-
#draw_on_bounds ⇒ Object
Specifies whether the border should be drawn inside the provided rectangle (
false
, default) or on it (true
). -
#style ⇒ Object
readonly
The styles of each edge.
-
#width ⇒ Object
readonly
The widths of each edge.
Instance Method Summary collapse
-
#draw(canvas, x, y, w, h) ⇒ Object
Draws the border onto the canvas.
-
#initialize(width: 0, color: 0, style: :solid, draw_on_bounds: false) ⇒ Border
constructor
Creates a new border style.
-
#initialize_copy(other) ⇒ Object
Duplicates a Border object’s properties.
-
#none? ⇒ Boolean
Returns
true
if there is no border.
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
#color ⇒ Object (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_bounds ⇒ Object
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 |
#style ⇒ Object (readonly)
The styles of each edge. See Quad.
217 218 219 |
# File 'lib/hexapdf/layout/style.rb', line 217 def style @style end |
#width ⇒ Object (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.
240 241 242 |
# File 'lib/hexapdf/layout/style.rb', line 240 def none? width.simple? && width.top == 0 end |