Class: XlsxWriter::Image
- Inherits:
-
Object
- Object
- XlsxWriter::Image
- Defined in:
- lib/xlsx_writer/xml/image.rb
Constant Summary collapse
- DEFAULT =
{ :croptop => 0, :cropleft => 0 }
- AUTO =
false
Instance Attribute Summary collapse
- #cropleft ⇒ Object
- #croptop ⇒ Object
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#lcr ⇒ Object
Returns the value of attribute lcr.
-
#original_path ⇒ Object
readonly
Returns the value of attribute original_path.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #absolute_path ⇒ Object
- #generate ⇒ Object
- #generated? ⇒ Boolean
- #id ⇒ Object
-
#initialize(document, original_path, width, height) ⇒ Image
constructor
A new instance of Image.
- #ndx ⇒ Object
- #o_spid ⇒ Object
- #o_title ⇒ Object
- #path ⇒ Object
- #relative_path ⇒ Object
- #rid ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(document, original_path, width, height) ⇒ Image
Returns a new instance of Image.
19 20 21 22 23 24 25 |
# File 'lib/xlsx_writer/xml/image.rb', line 19 def initialize(document, original_path, width, height) @document = document @original_path = original_path @width = width @height = height @mutex = ::Mutex.new end |
Instance Attribute Details
#cropleft ⇒ Object
40 41 42 |
# File 'lib/xlsx_writer/xml/image.rb', line 40 def cropleft @cropleft || DEFAULT[:cropleft] end |
#croptop ⇒ Object
36 37 38 |
# File 'lib/xlsx_writer/xml/image.rb', line 36 def croptop @croptop || DEFAULT[:croptop] end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
11 12 13 |
# File 'lib/xlsx_writer/xml/image.rb', line 11 def document @document end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
14 15 16 |
# File 'lib/xlsx_writer/xml/image.rb', line 14 def height @height end |
#lcr ⇒ Object
Returns the value of attribute lcr.
15 16 17 |
# File 'lib/xlsx_writer/xml/image.rb', line 15 def lcr @lcr end |
#original_path ⇒ Object (readonly)
Returns the value of attribute original_path.
12 13 14 |
# File 'lib/xlsx_writer/xml/image.rb', line 12 def original_path @original_path end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
13 14 15 |
# File 'lib/xlsx_writer/xml/image.rb', line 13 def width @width end |
Instance Method Details
#absolute_path ⇒ Object
89 90 91 |
# File 'lib/xlsx_writer/xml/image.rb', line 89 def absolute_path "/#{relative_path}" end |
#generate ⇒ Object
52 53 54 55 |
# File 'lib/xlsx_writer/xml/image.rb', line 52 def generate path true end |
#generated? ⇒ Boolean
57 58 59 |
# File 'lib/xlsx_writer/xml/image.rb', line 57 def generated? @generated == true end |
#id ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/xlsx_writer/xml/image.rb', line 44 def id if lcr lcr.image_id else o_spid #? end end |
#ndx ⇒ Object
73 74 75 |
# File 'lib/xlsx_writer/xml/image.rb', line 73 def ndx document.images.index(self) + 1 end |
#o_spid ⇒ Object
85 86 87 |
# File 'lib/xlsx_writer/xml/image.rb', line 85 def o_spid "_x0000_s#{1025+ndx}" end |
#o_title ⇒ Object
81 82 83 |
# File 'lib/xlsx_writer/xml/image.rb', line 81 def o_title ::File.basename(original_path) end |
#path ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/xlsx_writer/xml/image.rb', line 61 def path @path || @mutex.synchronize do @path ||= begin memo = ::File.join document.staging_dir, relative_path ::FileUtils.mkdir_p ::File.dirname(memo) ::FileUtils.cp original_path, memo @generated = true memo end end end |
#relative_path ⇒ Object
93 94 95 |
# File 'lib/xlsx_writer/xml/image.rb', line 93 def relative_path "xl/media/image#{ndx}.emf" end |
#rid ⇒ Object
77 78 79 |
# File 'lib/xlsx_writer/xml/image.rb', line 77 def rid "rId#{ndx}" end |
#to_xml ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/xlsx_writer/xml/image.rb', line 27 def to_xml <<-EOS <v:shape id="#{id}" o:spid="#{o_spid}" type="#_x0000_t75" style="position:absolute;margin-left:0;margin-top:0;width:#{width}pt;height:#{height}pt;z-index:1"> <v:imagedata o:relid="#{rid}" o:title="#{o_title}" croptop="#{croptop}" cropleft="#{cropleft}"/> <o:lock v:ext="edit" rotation="t"/> </v:shape> EOS end |