Class: ElementText

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

#initializeElementText

Returns a new instance of ElementText.



177
178
179
180
181
182
183
184
# File 'lib/render_svg3.rb', line 177

def initialize()
  super
  local_properties = {'x' => '','y' => '', 'fill' => '', 'font-size' => '15'}
  @property.merge!(local_properties)
  @style_property = {'font-size' => '', 'font-style' => '', 'font-weight' => '', 
                     'fill' => '', 'fill-opacity' => '', 'stroke' => '', 'font-family' => '', 'text-align' => 'start'}
  @type = :text
end

Instance Method Details

#invokeObject



186
187
188
189
# File 'lib/render_svg3.rb', line 186

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

#render_elementObject



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/render_svg3.rb', line 191

def render_element()
  super do
    h = @property; style = @style_property
    style.delete_if {|key, value| value.empty?}
    h.merge! style
    x, y =  h['x'].to_i,  h['y'].to_i
    font_size = (h['font-size'].to_f * 0.0625) unless h['font-size'].empty?

    
    fill = h['fill']
    text2 = self.text
    text_align = h['text-align'] 
    @style_property['text-align'] = 'start'
    #@style_property = {'font-size' => '', 'font-style' => '', 'font-weight' => '', 
     #                'fill' => '', 'fill-opacity' => '', 'stroke' => '', 'font-family' => '', 'text-align' => 'start'}
    #puts 'xzx ' + text2 + 'xzx'
   
    #stroke_width = hs['stroke-width'].to_i
    #r,g,b = hs['stroke'].match(/rgb\((\d{1,5}),(\d{1,5}),(\d{1,5})\)/).captures
    #puts 'x0xx ' + font_size.to_s + ' y0yy'
    #scale = run_projectx('registry', 'get-key', :path => 'app/svg_viewer/scale').first.to_f
    x, y, font_size = [x, y, font_size].map {|x| x * @@scale }
    #x_offset = -40
    x += @@x_offset * @@scale
    y += @@y_offset * @@scale
    #puts 'x1xx ' + font_size.to_s + ' y1yy'

    {:x => x, :y => y, :text => text2, :style => {:fill => fill, :text_align => text_align}, :font => {:size => font_size}}
  end
end