Class: Pdfrb::Content::GraphicsState

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/content/graphics_state.rb

Overview

Immutable snapshot of the PDF graphics state (s8.4). The Processor holds a stack of these for q (push) / Q (pop). Subclasses (TextState for the text sub-state) compose rather than inherit.

Defined Under Namespace

Classes: TextState

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctm: Pdfrb::Model::Matrix.identity, text_state: TextState.new, fill_color: nil, stroke_color: nil, line_width: 1.0, line_cap: 0, line_join: 0, miter_limit: 10.0, dash_pattern: [].freeze, flatness: 0, alpha_is_shape: false, stroke_alpha: 1.0, fill_alpha: 1.0, blend_mode: :Normal, soft_mask: nil, overprint: false, overprint_mode: 0) ⇒ GraphicsState

Returns a new instance of GraphicsState.



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
# File 'lib/pdfrb/content/graphics_state.rb', line 16

def initialize(ctm: Pdfrb::Model::Matrix.identity,
               text_state: TextState.new,
               fill_color: nil, stroke_color: nil,
               line_width: 1.0, line_cap: 0, line_join: 0,
               miter_limit: 10.0, dash_pattern: [].freeze,
               flatness: 0, alpha_is_shape: false,
               stroke_alpha: 1.0, fill_alpha: 1.0,
               blend_mode: :Normal, soft_mask: nil,
               overprint: false, overprint_mode: 0)
  @ctm = ctm
  @text_state = text_state
  @fill_color = fill_color
  @stroke_color = stroke_color
  @line_width = line_width.to_f
  @line_cap = line_cap.to_i
  @line_join = line_join.to_i
  @miter_limit = miter_limit.to_f
  @dash_pattern = dash_pattern
  @flatness = flatness.to_i
  @alpha_is_shape = alpha_is_shape
  @stroke_alpha = stroke_alpha.to_f
  @fill_alpha = fill_alpha.to_f
  @blend_mode = blend_mode
  @soft_mask = soft_mask
  @overprint = overprint
  @overprint_mode = overprint_mode.to_i
end

Instance Attribute Details

#alpha_is_shapeObject (readonly)

Returns the value of attribute alpha_is_shape.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def alpha_is_shape
  @alpha_is_shape
end

#blend_modeObject (readonly)

Returns the value of attribute blend_mode.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def blend_mode
  @blend_mode
end

#ctmObject (readonly)

Returns the value of attribute ctm.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def ctm
  @ctm
end

#dash_patternObject (readonly)

Returns the value of attribute dash_pattern.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def dash_pattern
  @dash_pattern
end

#fill_alphaObject (readonly)

Returns the value of attribute fill_alpha.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def fill_alpha
  @fill_alpha
end

#fill_colorObject (readonly)

Returns the value of attribute fill_color.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def fill_color
  @fill_color
end

#flatnessObject (readonly)

Returns the value of attribute flatness.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def flatness
  @flatness
end

#line_capObject (readonly)

Returns the value of attribute line_cap.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def line_cap
  @line_cap
end

#line_joinObject (readonly)

Returns the value of attribute line_join.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def line_join
  @line_join
end

#line_widthObject (readonly)

Returns the value of attribute line_width.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def line_width
  @line_width
end

#miter_limitObject (readonly)

Returns the value of attribute miter_limit.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def miter_limit
  @miter_limit
end

#overprintObject (readonly)

Returns the value of attribute overprint.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def overprint
  @overprint
end

#overprint_modeObject (readonly)

Returns the value of attribute overprint_mode.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def overprint_mode
  @overprint_mode
end

#soft_maskObject (readonly)

Returns the value of attribute soft_mask.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def soft_mask
  @soft_mask
end

#stroke_alphaObject (readonly)

Returns the value of attribute stroke_alpha.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def stroke_alpha
  @stroke_alpha
end

#stroke_colorObject (readonly)

Returns the value of attribute stroke_color.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def stroke_color
  @stroke_color
end

#text_stateObject (readonly)

Returns the value of attribute text_state.



10
11
12
# File 'lib/pdfrb/content/graphics_state.rb', line 10

def text_state
  @text_state
end

Instance Method Details

#to_hObject



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/pdfrb/content/graphics_state.rb', line 50

def to_h
  {
    ctm: @ctm, text_state: @text_state,
    fill_color: @fill_color, stroke_color: @stroke_color,
    line_width: @line_width, line_cap: @line_cap,
    line_join: @line_join, miter_limit: @miter_limit,
    dash_pattern: @dash_pattern, flatness: @flatness,
    alpha_is_shape: @alpha_is_shape, stroke_alpha: @stroke_alpha,
    fill_alpha: @fill_alpha, blend_mode: @blend_mode,
    soft_mask: @soft_mask, overprint: @overprint,
    overprint_mode: @overprint_mode
  }
end

#with(**overrides) ⇒ Object

Returns a new GraphicsState with the given overrides (the original is frozen).



46
47
48
# File 'lib/pdfrb/content/graphics_state.rb', line 46

def with(**overrides)
  GraphicsState.new(**to_h.merge(overrides))
end