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:



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/pdf/core/graphics_state.rb', line 92

def initialize(previous_state = nil)
  if previous_state
    initialize_copy(previous_state)
  else
    @color_space = {}
    @fill_color = '000000'
    @stroke_color = '000000'
    @dash = { dash: nil, space: nil, phase: 0 }
    @cap_style = :butt
    @join_style = :miter
    @line_width = 1
  end
end

Instance Attribute Details

#cap_styleSymbol

Line cap

Returns:

  • (Symbol)


74
75
76
# File 'lib/pdf/core/graphics_state.rb', line 74

def cap_style
  @cap_style
end

#color_spaceHash

Color space

Returns:

  • (Hash)


66
67
68
# File 'lib/pdf/core/graphics_state.rb', line 66

def color_space
  @color_space
end

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

Dash

Returns:

  • (Hash<[:dash, :space, :phase], [nil, Numeric]>)


70
71
72
# File 'lib/pdf/core/graphics_state.rb', line 70

def dash
  @dash
end

#fill_colorString

Fill color

Returns:

  • (String)


86
87
88
# File 'lib/pdf/core/graphics_state.rb', line 86

def fill_color
  @fill_color
end

#join_styleSymbol

Line Join

Returns:

  • (Symbol)


78
79
80
# File 'lib/pdf/core/graphics_state.rb', line 78

def join_style
  @join_style
end

#line_widthNumberic

Line width

Returns:

  • (Numberic)


82
83
84
# File 'lib/pdf/core/graphics_state.rb', line 82

def line_width
  @line_width
end

#stroke_colorObject

Stroke color



89
90
91
# File 'lib/pdf/core/graphics_state.rb', line 89

def stroke_color
  @stroke_color
end

Instance Method Details

#dash_settingString

PDF representation of dash settings

Returns:

  • (String)


109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/pdf/core/graphics_state.rb', line 109

def dash_setting
  return '[] 0 d' unless @dash[:dash]

  array =
    if @dash[:dash].is_a?(Array)
      @dash[:dash]
    else
      [@dash[:dash], @dash[:space]]
    end

  "[#{PDF::Core.real_params(array)}] #{PDF::Core.real(@dash[:phase])} d"
end