Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SVG images in cells #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/prawn/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require_relative 'table/cell/text'
require_relative 'table/cell/subtable'
require_relative 'table/cell/image'
require_relative 'table/cell/svg'
require_relative 'table/cell/span_dummy'

module Prawn
Expand Down
1 change: 1 addition & 0 deletions lib/prawn/table/cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def self.make(pdf, content, options={})
at = options.delete(:at) || [0, pdf.cursor]

return Cell::Image.new(pdf, at, content) if content.is_a?(Hash) && content[:image]
return Cell::SVG.new(pdf, at, content) if content.is_a?(Hash) && content[:svg]

if content.is_a?(Hash)
options.update(content)
Expand Down
76 changes: 76 additions & 0 deletions lib/prawn/table/cell/svg.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# encoding: utf-8

# image.rb: Table image cells.
#
# Copyright September 2010, Brad Ediger. All Rights Reserved.
#
# This is free software. Please see the LICENSE and COPYING files for details.
module Prawn
class Table
class Cell
# @private
class SVG < Cell
def initialize(pdf, point, options={})
@svg_options = options

super


# @pdf_object, @image_info = @pdf.build_image_object(@file)
# @natural_width, @natural_height = @image_info.calc_image_dimensions(
# @image_options)
end

def svg=(file)
@file = file
end

def svg_width=(width)
@svg_width = width
end

def svg_height=(height)
@svg_height = height
end

# def scale=(s)
# @image_options[:scale] = s
# end

# def fit=(f)
# @image_options[:fit] = f
# end

# def image_height=(h)
# @image_options[:height] = h
# end

# def image_width=(w)
# @image_options[:width] = w
# end

# def position=(p)
# @image_options[:position] = p
# end

# def vposition=(vp)
# @image_options[:vposition] = vp
# end

def natural_content_width
@svg_width
end

def natural_content_height
@svg_height
end

# Embed the SVG on the page
#
def draw_content
@pdf.svg File.read(@file), width: @svg_width, height: @svg_height
end
end
end
end
end