Class: Prawn::SVG::Elements::Pattern

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

Constant Summary

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 PDFMatrix

#load_matrix, #matrix_for_pdf, #rotation_matrix, #scale_matrix, #translation_matrix

Methods included from Attributes::Space

#parse_xml_space_attribute

Methods included from Attributes::Stroke

#parse_stroke_attributes_and_call

Methods included from Attributes::Mask

#parse_mask_attribute_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

#parent_patternObject (readonly)

Returns the value of attribute parent_pattern.



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

def parent_pattern
  @parent_pattern
end

Instance Method Details

#container?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/prawn/svg/elements/pattern.rb', line 14

def container?
  true
end

#derive_attribute(name) ⇒ Object



48
49
50
# File 'lib/prawn/svg/elements/pattern.rb', line 48

def derive_attribute(name)
  attributes[name] || parent_pattern&.derive_attribute(name)
end

#parseObject

Raises:



4
5
6
7
8
9
10
11
12
# File 'lib/prawn/svg/elements/pattern.rb', line 4

def parse
  raise SkipElementQuietly if attributes['id'].nil?

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

  set_display_none

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

#pattern_arguments(element) ⇒ Object



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
43
44
45
46
# File 'lib/prawn/svg/elements/pattern.rb', line 18

def pattern_arguments(element)
  bbox = element.bounding_box
  units = derive_attribute('patternUnits') || 'objectBoundingBox'
  content_units = derive_attribute('patternContentUnits') || 'userSpaceOnUse'
  view_box_attr = derive_attribute('viewBox')
  par_attr = derive_attribute('preserveAspectRatio')

  tile = compute_tile(units, bbox)
  return nil unless tile

  tile_x, tile_y_bottom, tile_w, tile_h = tile

  transform = Matrix.identity(3)
  if (transform_attr = derive_attribute('patternTransform'))
    transform = parse_transform_attribute(transform_attr, space: :svg)
  end

  content_calls = build_content_calls(content_units, view_box_attr, par_attr, tile_w, tile_h, bbox, units, tile_x, tile_y_bottom)
  return nil if content_calls.nil?

  {
    tile_x:      tile_x,
    tile_y:      tile_y_bottom,
    tile_width:  tile_w,
    tile_height: tile_h,
    transform:   transform,
    calls:       content_calls
  }
end