File: cap_style.rb

package info (click to toggle)
ruby-prawn 2.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,380 kB
  • sloc: ruby: 15,820; sh: 43; makefile: 20
file content (47 lines) | stat: -rw-r--r-- 1,082 bytes parent folder | download | duplicates (2)
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
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

# cap_style.rb : Implements stroke cap styling
#
# Contributed by Daniel Nelson. October, 2009
#
# This is free software. Please see the LICENSE and COPYING files for details.
#
module Prawn
  module Graphics
    module CapStyle
      # @group Stable API

      CAP_STYLES = { butt: 0, round: 1, projecting_square: 2 }.freeze

      # Sets the cap style for stroked lines and curves
      #
      # style is one of :butt, :round, or :projecting_square
      #
      # NOTE: If this method is never called, :butt will be used by default.
      #
      def cap_style(style = nil)
        return current_cap_style || :butt if style.nil?

        self.current_cap_style = style

        write_stroke_cap_style
      end

      alias cap_style= cap_style

      private

      def current_cap_style
        graphic_state.cap_style
      end

      def current_cap_style=(style)
        graphic_state.cap_style = style
      end

      def write_stroke_cap_style
        renderer.add_content "#{CAP_STYLES[current_cap_style]} J"
      end
    end
  end
end