Skip to content

Commit

Permalink
resolves asciidoctor#242 scale down SVG if width is wider than page
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Jun 26, 2015
1 parent 94de4cd commit a242c2c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/asciidoctor-pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,15 @@ def convert_image node
when 'svg'
begin
svg_obj = ::Prawn::Svg::Interface.new (::IO.read image_path), self, position: position, width: width
actual_w = svg_obj.document.sizing.output_width
# FIXME would be nice of prawn-svg accepted a max width argument
if !width && (actual_w = svg_obj.document.sizing.output_width) > bounds.width
# TODO would be nice to have a recalculate method w/ a new requested width and/or height
#svg_obj.document.sizing.requested_width = bounds.width
#svg_obj.document.sizing.calculate
# instead we'll just reconstruct
svg_obj = ::Prawn::Svg::Interface.new (::IO.read image_path), self, position: position, width: bounds.width
actual_w = svg_obj.document.sizing.output_width
end
actual_h = svg_obj.document.sizing.output_height
rel_left = { left: 0, right: (bounds.width - actual_w), center: ((bounds.width - actual_w) / 2.0) }[position]
# TODO layout SVG without using keep_together (since we know the dimensions already); always render caption
Expand Down

0 comments on commit a242c2c

Please sign in to comment.