Class: ElementRect

Inherits:
ElementSvg show all
Defined in:
lib/render_svg3.rb

Instance Method Summary collapse

Methods inherited from ElementSvg

#get_style_properties, #initialize_variables, #load_properties, #load_renderer, #parse_style, #scale, #scale=, #text, #text=, #x_offset, #x_offset=, #y_offset, #y_offset=

Constructor Details

#initializeElementRect

Returns a new instance of ElementRect.



107
108
109
110
111
112
113
# File 'lib/render_svg3.rb', line 107

def initialize()
  super
  local_properties = {'x' => '','y' => '', 'width' => '', 'height' => ''}
  @property.merge!(local_properties)
  @style_property = {'fill' => '', 'stroke' => '', 'stroke-width' => ''}
  @type = :rectangle
end

Instance Method Details

#invokeObject



115
116
117
118
# File 'lib/render_svg3.rb', line 115

def invoke()
  puts " -- render the 'rect' element" 
  render_element()
end

#render_elementObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/render_svg3.rb', line 120

def render_element()
  super do 
    h = @property; hs = @style_property
    x1, y1, x2, y2 =  h['x'].to_i,  h['y'].to_i,  h['x'].to_i + h['width'].to_i,  h['y'].to_i + h['height'].to_i
    #r,g,b = hs['fill'].match(/rgb\((\d{1,5}),(\d{1,5}),(\d{1,5})\)/).captures
    style =  {:fill => hs['fill'], :stroke => hs['stroke'], :stroke_width => hs['stroke-width']}
    
    #scale = run_projectx('registry', 'get-key', :path => 'app/svg_viewer/scale').first.to_f
    x1, y1, x2, y2 = [x1, y1, x2, y2].map {|x| x * @@scale}
    x1, x2 = [x1, x2].map {|x| x + @@x_offset * @@scale}
    y1, y2 = [y1, y2].map {|x| x + @@y_offset * @@scale}

    properties = {:x => x1, :y => y1, :width => x2 - x1, :height => y2 - y1, :style => style}
    #properties = {:x => x1, :y => y1,  :width => x2 - x1, :height => y2 - y1}
    #draw properties
  end
end