Class: Prawn::SVG::Elements::Rect
- Defined in:
- lib/prawn/svg/elements/rect.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
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
Methods included from PDFMatrix
#load_matrix, #matrix_for_pdf, #rotation_matrix, #scale_matrix, #translation_matrix
Methods included from Attributes::Space
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 Method Details
#apply ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/prawn/svg/elements/rect.rb', line 21 def apply if @radius # n.b. does not support both rx and ry being specified with different values add_call 'rounded_rectangle', [@x, @y], @width, @height, @radius else add_call 'rectangle', [@x, @y], @width, @height end end |
#bounding_box ⇒ Object
30 31 32 |
# File 'lib/prawn/svg/elements/rect.rb', line 30 def bounding_box [@x, @y, @x + @width, @y - @height] end |
#parse ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/prawn/svg/elements/rect.rb', line 2 def parse require_attributes 'width', 'height' @x = x(attributes['x'] || '0') @y = y(attributes['y'] || '0') @width = x_pixels(attributes['width']) @height = y_pixels(attributes['height']) require_positive_value @width, @height @radius = x_pixels(attributes['rx']) || y_pixels(attributes['ry']) if @radius # If you implement separate rx and ry in the future, you'll want to change this # so that rx is constrained to @width/2 and ry is constrained to @height/2. max_value = [@width, @height].min / 2.0 @radius = @radius.clamp(0, max_value) end end |