File: stroke_cap.rb

package info (click to toggle)
ruby-prawn 2.5.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,528 kB
  • sloc: ruby: 17,688; sh: 43; makefile: 20
file content (35 lines) | stat: -rw-r--r-- 1,037 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

require 'prawn/manual_builder'

Prawn::ManualBuilder::Chapter.new do
  title 'Stroke Cap'

  text do
    prose <<~TEXT
      The cap style defines how the edge of a line or curve will be drawn.
      There are three types: <code>:butt</code> (the default),
      <code>:round</code> and <code>:projecting_square</code>.

      The difference is better seen with thicker lines. With <code>:butt</code>
      lines are drawn starting and ending at the exact points provided. With
      both <code>:round</code> and <code>:projecting_square</code> the line is
      projected beyond the start and end points.

      Just like <code>line_width=</code> the <code>cap_style=</code> method
      needs an explicit receiver to work.
    TEXT
  end

  example axes: true do
    self.line_width = 25

    %i[butt round projecting_square].each_with_index do |cap, i|
      self.cap_style = cap

      y = 250 - (i * 100)
      stroke_horizontal_line 100, 300, at: y
      stroke_circle [400, y], 15
    end
  end
end