Module: MapPrint::PngHandlers::Texts

Included in:
LegendHandler, MapPrint::PngHandler, ScalebarHandler
Defined in:
lib/map_print/png_handlers/texts.rb

Instance Method Summary collapse

Instance Method Details

#draw_text(png, text, position, options) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/map_print/png_handlers/texts.rb', line 12

def draw_text(png, text, position, options)
  png.combine_options do |c|
    c.density 300
    sanitize_options(options).each do |option, value|
      c.send option, value
    end
    c.draw "text #{position} '#{text}'"
  end
end


4
5
6
7
8
9
10
# File 'lib/map_print/png_handlers/texts.rb', line 4

def print_texts(texts, png)
  (texts || []).each do |text|
    position = "#{text[:position][:x]},#{text[:position][:y]}"

    draw_text(png, text[:text], position, text[:options])
  end
end

#sanitize_options(options) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/map_print/png_handlers/texts.rb', line 22

def sanitize_options(options)
  return {} unless options.is_a?(Hash)
  options[:stroke] = options.delete :color if options[:color]
  options[:fill] = options.delete :fill_color if options[:fill_color]
  options[:gravity] ||= 'NorthWest'
  options[:font] ||= 'Arial'
  options
end