Class: CTioga2::Graphics::Styles::ImageStyle

Inherits:
BasicStyle
  • Object
show all
Defined in:
lib/ctioga2/graphics/styles/image.rb

Overview

This class represents the style for an image

Constant Summary

Constants inherited from BasicStyle

BasicStyle::AllStyles, BasicStyle::OldAttrAccessor

Instance Method Summary collapse

Methods inherited from BasicStyle

alias_for, attr_accessor, attribute_type, attribute_types, attributes, deprecated_attribute, from_hash, inherited, #instance_variable_defined?, options_hash, #set_from_hash, sub_style, sub_styles, #to_hash, typed_attribute, #update_from_other

Instance Method Details

#draw_image(t, file, tl, br) ⇒ Object

Draws an image according to this



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ctioga2/graphics/styles/image.rb', line 56

def draw_image(t, file, tl, br)
  info = t.jpg_info(file)
  if ! info
    info = t.load_png(file)
  end

  r = Types::Rect.new(tl, br)
  ul, ll, lr = r.make_corners(t, (@auto_rotate == nil ? true : @auto_rotate), @aspect_ratio || :ignore,
                              info['width']*1.0/info['height'])

  dict = info.dup
  dict.merge!('ul' => ul,
              'll' => ll,
              'lr' => lr)
  
  # @todo provide a way to reuse images ?
  t.context do
    if @transparency
      t.fill_opacity = 1 - @transparency
    end
    t.show_image(dict)
  end
end