Method: HexaPDF::Content::Canvas#line_width

Defined in:
lib/hexapdf/content/canvas.rb

#line_width(width = nil, &block) ⇒ Object Also known as: line_width=

:call-seq:

canvas.line_width                    => current_line_width
canvas.line_width(width)             => canvas
canvas.line_width(width) { block }   => canvas

The line width determines the thickness of a stroked path.

Note that half the line width lies on either side of the path. For example, if a path from (0, 0) to (0, 100) is drawn with a line width of 20, the stroked path is actually 20 units wide, from -10 to 10. And if a rectangle is drawn stroked, but not filled, from (20, 20) with a width and height of 20 and a line width of 10, the “inside” of the rectangle would only be from (25, 25) to (35, 35). Also see the examples below.

Returns the current line width (see GraphicsState#line_width) when no argument is given. Otherwise sets the line width to the given width and returns self. The setter version can also be called in the line_width= form.

If the width and a block are provided, the changed line width is only active during the block by saving and restoring the graphics state.

Examples:

#>pdf
canvas.line_width(10).
  line(10, 100, 10, 190).stroke
canvas.line_width          # => 10
canvas.line_width = 5      # => 5
canvas.line(60, 100, 60, 190).stroke

canvas.line_width(10) do
  canvas.line_width        # => 10
  canvas.line(110, 100, 110, 190).stroke
end
canvas.line_width          # => 5
canvas.line(160, 100, 160, 190).stroke

canvas.line_width(10).rectangle(20, 20, 20, 20).stroke      # The rectangle
canvas.fill_color("hp-blue").rectangle(25, 25, 10, 10).fill # The inside

See: PDF2.0 s8.4.3.2



626
627
628
# File 'lib/hexapdf/content/canvas.rb', line 626

def line_width(width = nil, &block)
  gs_getter_setter(:line_width, :w, width, &block)
end