Class: Prawn::SVG::Paint

Inherits:
Struct
  • Object
show all
Defined in:
lib/prawn/svg/paint.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#colorObject

Returns the value of attribute color

Returns:

  • (Object)

    the current value of color



2
3
4
# File 'lib/prawn/svg/paint.rb', line 2

def color
  @color
end

#urlObject

Returns the value of attribute url

Returns:

  • (Object)

    the current value of url



2
3
4
# File 'lib/prawn/svg/paint.rb', line 2

def url
  @url
end

Class Method Details

.blackObject



8
9
10
# File 'lib/prawn/svg/paint.rb', line 8

def black
  new(Color.black, nil)
end

.noneObject



4
5
6
# File 'lib/prawn/svg/paint.rb', line 4

def none
  new(:none, nil)
end

.parse(value) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/prawn/svg/paint.rb', line 12

def parse(value)
  case CSS::ValuesParser.parse(value)
  in [['url', [url]]]
    # If there is no fallback color, and the URL is unresolvable, the spec says that the document is in error.
    # Chrome appears to treat this the same as an explicit 'none', so we do the same.
    new(:none, url)
  in [['url', [url]], keyword_or_color]
    parse_keyword_or_color(keyword_or_color, url)
  in [['url', [url]], keyword_or_color, ['icc-color', _args]] # rubocop:disable Lint/DuplicateBranch
    parse_keyword_or_color(keyword_or_color, url)
  in [keyword_or_color, ['icc-color', _args]]
    parse_keyword_or_color(keyword_or_color, nil)
  in [keyword_or_color] # rubocop:disable Lint/DuplicateBranch
    parse_keyword_or_color(keyword_or_color, nil)
  else
    nil
  end
end

Instance Method Details

#none?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/prawn/svg/paint.rb', line 44

def none?
  color == :none && (url.nil? || !!@unresolved_url)
end

#resolve(gradients, current_color, color_mode) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/prawn/svg/paint.rb', line 48

def resolve(gradients, current_color, color_mode)
  if url
    if url[0] == '#' && gradients && (gradient = gradients[url[1..]])
      return gradient
    else
      @unresolved_url = true
    end
  end

  case color
  when :currentcolor
    current_color
  when :none
    nil
  else
    color_mode == :cmyk ? color.to_cmyk : color
  end
end