Class: Prawn::SVG::Elements::Gradient

Inherits:
Base
  • Object
show all
Defined in:
lib/prawn/svg/elements/gradient.rb

Constant Summary collapse

TAG_NAME_TO_TYPE =
{
  "linearGradient" => :linear,
  "radialGradient" => :radial
}

Constants inherited from Base

Base::COMMA_WSP_REGEXP, Base::MissingAttributesError, Base::PAINT_TYPES, Base::SVG_NAMESPACE, Base::SkipElementError, Base::SkipElementQuietly

Constants included from Attributes::Stroke

Attributes::Stroke::CAP_STYLE_TRANSLATIONS, Attributes::Stroke::JOIN_STYLE_TRANSLATIONS

Instance Attribute Summary collapse

Attributes inherited from Base

#attributes, #base_calls, #calls, #document, #parent_calls, #properties, #source, #state

Instance Method Summary collapse

Methods inherited from Base

#initialize, #name, #parse_and_apply, #process

Methods included from TransformParser

#parse_transform_attribute

Methods included from Attributes::Space

#parse_xml_space_attribute

Methods included from Attributes::Stroke

#parse_stroke_attributes_and_call

Methods included from Attributes::ClipPath

#parse_clip_path_attribute_and_call

Methods included from Attributes::Opacity

#parse_opacity_attributes_and_call

Methods included from Attributes::Transform

#parse_transform_attribute_and_call

Constructor Details

This class inherits a constructor from Prawn::SVG::Elements::Base

Instance Attribute Details

#cxObject (readonly)

Returns the value of attribute cx.



3
4
5
# File 'lib/prawn/svg/elements/gradient.rb', line 3

def cx
  @cx
end

#cyObject (readonly)

Returns the value of attribute cy.



3
4
5
# File 'lib/prawn/svg/elements/gradient.rb', line 3

def cy
  @cy
end

#fxObject (readonly)

Returns the value of attribute fx.



3
4
5
# File 'lib/prawn/svg/elements/gradient.rb', line 3

def fx
  @fx
end

#fyObject (readonly)

Returns the value of attribute fy.



3
4
5
# File 'lib/prawn/svg/elements/gradient.rb', line 3

def fy
  @fy
end

#parent_gradientObject (readonly)

Returns the value of attribute parent_gradient.



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

def parent_gradient
  @parent_gradient
end

#radiusObject (readonly)

Returns the value of attribute radius.



3
4
5
# File 'lib/prawn/svg/elements/gradient.rb', line 3

def radius
  @radius
end

#stopsObject (readonly)

Returns the value of attribute stops.



3
4
5
# File 'lib/prawn/svg/elements/gradient.rb', line 3

def stops
  @stops
end

#transform_matrixObject (readonly)

Returns the value of attribute transform_matrix.



3
4
5
# File 'lib/prawn/svg/elements/gradient.rb', line 3

def transform_matrix
  @transform_matrix
end

#unitsObject (readonly)

Returns the value of attribute units.



3
4
5
# File 'lib/prawn/svg/elements/gradient.rb', line 3

def units
  @units
end

#x1Object (readonly)

Returns the value of attribute x1.



3
4
5
# File 'lib/prawn/svg/elements/gradient.rb', line 3

def x1
  @x1
end

#x2Object (readonly)

Returns the value of attribute x2.



3
4
5
# File 'lib/prawn/svg/elements/gradient.rb', line 3

def x2
  @x2
end

#y1Object (readonly)

Returns the value of attribute y1.



3
4
5
# File 'lib/prawn/svg/elements/gradient.rb', line 3

def y1
  @y1
end

#y2Object (readonly)

Returns the value of attribute y2.



3
4
5
# File 'lib/prawn/svg/elements/gradient.rb', line 3

def y2
  @y2
end

Instance Method Details

#gradient_arguments(element) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/prawn/svg/elements/gradient.rb', line 26

def gradient_arguments(element)
  # Passing in a transformation matrix to the apply_transformations option is supported
  # by a monkey patch installed by prawn-svg.  Prawn only sees this as a truthy variable.
  #
  # See Prawn::SVG::Extensions::AdditionalGradientTransforms for details.
  base_arguments = {stops: stops, apply_transformations: transform_matrix || true}

  arguments = specific_gradient_arguments(element)
  arguments.merge(base_arguments) if arguments
end

#parseObject

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/prawn/svg/elements/gradient.rb', line 10

def parse
  # A gradient tag without an ID is inaccessible and can never be used
  raise SkipElementQuietly if attributes['id'].nil?

  @parent_gradient = document.gradients[href_attribute[1..-1]] if href_attribute && href_attribute[0] == '#'

  assert_compatible_prawn_version
  load_gradient_configuration
  load_coordinates
  load_stops

  document.gradients[attributes['id']] = self

  raise SkipElementQuietly # we don't want anything pushed onto the call stack
end