From 87751361fa708379171d62ea36e4cc1c06b49cd4 Mon Sep 17 00:00:00 2001 From: joe-sharp Date: Sun, 24 Aug 2025 18:42:20 -0500 Subject: [PATCH] fix: enhance SVG initialization and scaling in card rendering - Updated the SVG initialization in the MtgCardMaker to include a viewBox for proper scaling. - Modified the sprite sheet builder to wrap card elements in an SVG tag with a viewBox for consistent rendering. --- color_cards_sprite.svg | 32 ++++++++++++++++------ lib/mtg_card_maker.rb | 2 +- lib/mtg_card_maker/sprite_sheet_builder.rb | 7 ++++- output_card.svg | 2 +- spec/fixtures/art_layer.svg | 2 +- spec/fixtures/border_layer.svg | 2 +- spec/fixtures/complete_card.svg | 2 +- spec/fixtures/frame_layer.svg | 2 +- spec/fixtures/name_layer.svg | 2 +- spec/fixtures/power_layer.svg | 2 +- spec/fixtures/text_box_layer.svg | 2 +- spec/fixtures/type_line_layer.svg | 2 +- 12 files changed, 40 insertions(+), 19 deletions(-) diff --git a/color_cards_sprite.svg b/color_cards_sprite.svg index 61989ef..2ac0cdc 100644 --- a/color_cards_sprite.svg +++ b/color_cards_sprite.svg @@ -283,6 +283,7 @@ + @@ -338,8 +339,10 @@ The light of justice never fades, even in the darkest of times. - + + + @@ -420,8 +423,10 @@ Knowledge flows like water, finding its way through any barrier. - + + + @@ -475,8 +480,10 @@ Death is not the end, but a transformation into something darker. - + + + @@ -538,8 +545,10 @@ exile it instead. Fire consumes all, leaving only ash and memory. - + + + @@ -610,8 +619,10 @@ the battlefield tapped. 4/12 - + + + @@ -671,8 +682,10 @@ A piece of jewelry, usually containing a gemstone, that can produce mana. Perhaps a Ruby? - + + + @@ -742,8 +755,10 @@ third person as 'The Equipped One'. - + + + @@ -826,5 +841,6 @@ comprehension. 8/8 - + + diff --git a/lib/mtg_card_maker.rb b/lib/mtg_card_maker.rb index 0e9bbdf..6247e08 100644 --- a/lib/mtg_card_maker.rb +++ b/lib/mtg_card_maker.rb @@ -161,7 +161,7 @@ class Template def initialize(width: CARD_WIDTH, height: CARD_HEIGHT, embed_font: false) @width = width @height = height - @svg = Victor::SVG.new width: width, height: height + @svg = Victor::SVG.new width: width, height: height, viewBox: "0 0 #{width} #{height}" embed_font(embed: embed_font) end diff --git a/lib/mtg_card_maker/sprite_sheet_builder.rb b/lib/mtg_card_maker/sprite_sheet_builder.rb index 08c6d46..5d1a098 100644 --- a/lib/mtg_card_maker/sprite_sheet_builder.rb +++ b/lib/mtg_card_maker/sprite_sheet_builder.rb @@ -65,7 +65,12 @@ def add_card_to_sprite(xml, card_file, index, embed_font) return unless svg_element xml.g(transform: "translate(#{position[:x]}, #{position[:y]})") do - add_card_children(xml, svg_element, embed_font) + # Add the card with its own viewBox for proper scaling + xml.svg(viewBox: "0 0 #{CARD_WIDTH} #{CARD_HEIGHT}", + width: CARD_WIDTH, + height: CARD_HEIGHT) do + add_card_children(xml, svg_element, embed_font) + end end end diff --git a/output_card.svg b/output_card.svg index 51231e5..4c9fb7c 100644 --- a/output_card.svg +++ b/output_card.svg @@ -1,4 +1,4 @@ - +