diff options
| author | Randy Morgan <[email protected]> | 2012-02-02 20:26:15 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-02-02 20:26:15 +0900 |
| commit | 710f5eac4d8d7d017c42348180e9ae0a5e8fec3c (patch) | |
| tree | 4cce6fc0e445705de8e3cad06152a7455c2942bf /lib/axlsx/drawing/pic.rb | |
| parent | d4a00926a263329befc9526a930b274210a13abf (diff) | |
| download | caxlsx-710f5eac4d8d7d017c42348180e9ae0a5e8fec3c.tar.gz caxlsx-710f5eac4d8d7d017c42348180e9ae0a5e8fec3c.zip | |
Adding in hyperlinking for images as per issue #22
Diffstat (limited to 'lib/axlsx/drawing/pic.rb')
| -rw-r--r-- | lib/axlsx/drawing/pic.rb | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb index 250e3e16..f1939e2a 100644 --- a/lib/axlsx/drawing/pic.rb +++ b/lib/axlsx/drawing/pic.rb @@ -47,7 +47,24 @@ module Axlsx yield self if block_given? @picture_locking = PictureLocking.new(options) end + + attr_reader :hyperlink + # sets or updates a hyperlink for this image. + # @param [String] v The href value for the hyper link + # @option options @see Hyperlink#initialize All options available to the Hyperlink class apply - however href will be overridden with the v parameter value. + def hyperlink=(v, options={}) + options[:href] = v + if @hyperlink.is_a?(Hyperlink) + options.each do |o| + @hyperlink.send("#{o[0]}=", o[1]) if @hyperlink.respond_to? "#{o[0]}=" + end + else + @hyperlink = Hyperlink.new(self, options) + end + @hyperlink + end + def image_src=(v) Axlsx::validate_string(v) RestrictionValidator.validate 'Pic.image_src', ALLOWED_EXTENSIONS, File.extname(v).delete('.') @@ -75,7 +92,7 @@ module Axlsx end # The index of this image in the workbooks images collections - # @return [Index] + # @return [Index] def index @anchor.drawing.worksheet.workbook.images.index(self) end @@ -86,6 +103,11 @@ module Axlsx "#{IMAGE_PN % [(index+1), extname]}" end + # The relational id withing the drawing's relationships + def id + @anchor.drawing.charts.size + @anchor.drawing.images.index(self) + 1 + end + # providing access to the anchor's width attribute # @param [Integer] v # @see OneCellAnchor.width @@ -127,13 +149,17 @@ module Axlsx def to_xml(xml) xml.pic { xml.nvPicPr { - xml.cNvPr :id=>"2", :name=>name, :descr=>descr + xml.cNvPr(:id=>"2", :name=>name, :descr=>descr) { + if @hyperlink.is_a?(Hyperlink) + @hyperlink.to_xml(xml) + end + } xml.cNvPicPr { picture_locking.to_xml(xml) } } xml.blipFill { - xml[:a].blip :'xmlns:r' => XML_NS_R, :'r:embed'=>"rId1" + xml[:a].blip :'xmlns:r' => XML_NS_R, :'r:embed'=>"rId#{id}" xml[:a].stretch { xml.fillRect } |
