Class: PDF::Core::GraphicState

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/core/graphics_state.rb

Overview

Graphics state. It’s a partial represenation of PDF graphics state. Only the parts implemented in Prawn are present here.

NOTE: This class may be a good candidate for a copy-on-write hash.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(previous_state = nil) ⇒ GraphicState

Returns a new instance of GraphicState.

Parameters:

Source Code
lib/pdf/core/graphics_state.rb, line 92
92
def initialize(previous_state = nil)
93
  if previous_state
94
    initialize_copy(previous_state)
95
  else
96
    @color_space = {}
97
    @fill_color = '000000'
98
    @stroke_color = '000000'
99
    @dash = { dash: nil, space: nil, phase: 0 }
100
    @cap_style = :butt
101
    @join_style = :miter
102
    @line_width = 1
103
  end
104
end

Instance Attribute Details

#cap_styleSymbol

Line cap

Returns:

  • (Symbol)
Source Code
lib/pdf/core/graphics_state.rb, line 74
74
def cap_style
75
  @cap_style
76
end

#color_spaceHash

Color space

Returns:

  • (Hash)
Source Code
lib/pdf/core/graphics_state.rb, line 66
66
def color_space
67
  @color_space
68
end

#dashHash<[:dash, :space, :phase], [nil, Numeric]>

Dash

Returns:

  • (Hash<[:dash, :space, :phase], [nil, Numeric]>)
Source Code
lib/pdf/core/graphics_state.rb, line 70
70
def dash
71
  @dash
72
end

#fill_colorString

Fill color

Returns:

  • (String)
Source Code
lib/pdf/core/graphics_state.rb, line 86
86
def fill_color
87
  @fill_color
88
end

#join_styleSymbol

Line Join

Returns:

  • (Symbol)
Source Code
lib/pdf/core/graphics_state.rb, line 78
78
def join_style
79
  @join_style
80
end

#line_widthNumberic

Line width

Returns:

  • (Numberic)
Source Code
lib/pdf/core/graphics_state.rb, line 82
82
def line_width
83
  @line_width
84
end

#stroke_colorObject

Stroke color

Source Code
lib/pdf/core/graphics_state.rb, line 89
89
def stroke_color
90
  @stroke_color
91
end

Instance Method Details

#dash_settingString

PDF representation of dash settings

Returns:

  • (String)
Source Code
lib/pdf/core/graphics_state.rb, line 109
109
def dash_setting
110
  return '[] 0 d' unless @dash[:dash]
111
112
  array =
113
    if @dash[:dash].is_a?(Array)
114
      @dash[:dash]
115
    else
116
      [@dash[:dash], @dash[:space]]
117
    end
118
119
  "[#{PDF::Core.real_params(array)}] #{PDF::Core.real(@dash[:phase])} d"
120
end