Class: MapPrint::LegendHandler
- Inherits:
-
Object
- Object
- MapPrint::LegendHandler
- Includes:
- PngHandlers::Texts, Validations::Size
- Defined in:
- lib/map_print/legend_handler.rb
Constant Summary collapse
- OVERFLOW =
{ expand: 'expand', compact: 'compact', hidden: 'hidden' }
- VERTICAL =
'vertical'- HORIZONTAL =
'horizontal'
Instance Method Summary collapse
-
#initialize(legend) ⇒ LegendHandler
constructor
A new instance of LegendHandler.
- #process ⇒ Object
Methods included from Validations::Size
Methods included from PngHandlers::Texts
#draw_text, #print_texts, #sanitize_options
Constructor Details
#initialize(legend) ⇒ LegendHandler
Returns a new instance of LegendHandler.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/map_print/legend_handler.rb', line 17 def initialize(legend) @legend = legend validate_data! overflow_option_adjustments @x_step = @legend[:size][:width] / @legend[:columns] @y_step = @legend[:size][:height] / @legend[:rows] @elements_in_block = @legend[:orientation] == VERTICAL ? @legend[:rows] : @legend[:columns] @legend[:textbox_style] ||= {} if @legend[:textbox_size] @legend[:textbox_style][:size] = "#{@legend[:textbox_size][:width]}x#{@legend[:textbox_size][:height]}" end end |
Instance Method Details
#process ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/map_print/legend_handler.rb', line 31 def process size = @legend[:size] tempfile = Tempfile.new ['legend', '.png'] `convert -density 300 -size #{size[:width]}x#{size[:height]} xc:white #{tempfile.path}` image = MiniMagick::Image.new tempfile.path image_geometry = '' textbox_offset = 0 if @legend[:image_size] image_geometry += "#{@legend[:image_size][:width]}x#{@legend[:image_size][:height]}" textbox_offset += @legend[:image_size][:width] if @legend[:image_size][:width] end textbox_offset += @legend[:textbox_offset] if @legend[:textbox_offset] print(image, image_geometry, textbox_offset) image end |