mtg_card_maker 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/LICENSE.txt +59 -14
- data/README.md +251 -69
- data/lib/mtg_card_maker/base_card.rb +24 -1
- data/lib/mtg_card_maker/cli.rb +44 -41
- data/lib/mtg_card_maker/color_scheme.rb +18 -23
- data/lib/mtg_card_maker/css_service.rb +72 -0
- data/lib/mtg_card_maker/fonts/GoudyBookletter1911.ttf +0 -0
- data/lib/mtg_card_maker/fonts/OFL.txt +92 -0
- data/lib/mtg_card_maker/fonts/goudy_bookletter_base64.txt +1 -0
- data/lib/mtg_card_maker/icon_filename_service.rb +118 -0
- data/lib/mtg_card_maker/icon_service.rb +87 -25
- data/lib/mtg_card_maker/icons/black.svg +6 -1
- data/lib/mtg_card_maker/icons/blue.svg +6 -1
- data/lib/mtg_card_maker/icons/colorless.svg +6 -1
- data/lib/mtg_card_maker/icons/double-digit.svg +6 -0
- data/lib/mtg_card_maker/icons/energy.svg +26 -0
- data/lib/mtg_card_maker/icons/green.svg +6 -1
- data/lib/mtg_card_maker/icons/hybrid/2-black.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/2-blue.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/2-green.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/2-red.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/2-white.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/black-blue.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/black-green.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/black-red.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/black-white.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/blue-black.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/blue-green.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/blue-red.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/blue-white.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/colorless-black.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/colorless-blue.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/colorless-green.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/colorless-red.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/colorless-white.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/green-black.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/green-blue.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/green-red.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/green-white.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/red-black.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/red-blue.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/red-green.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/red-white.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/white-black.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/white-blue.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/white-green.svg +19 -0
- data/lib/mtg_card_maker/icons/hybrid/white-red.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/black-blue.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/black-green.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/black-red.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/black-white.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/black.svg +6 -0
- data/lib/mtg_card_maker/icons/phyrexian/blue-black.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/blue-green.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/blue-red.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/blue-white.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/blue.svg +6 -0
- data/lib/mtg_card_maker/icons/phyrexian/colorless.svg +6 -0
- data/lib/mtg_card_maker/icons/phyrexian/green-black.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/green-blue.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/green-red.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/green-white.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/green.svg +6 -0
- data/lib/mtg_card_maker/icons/phyrexian/red-black.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/red-blue.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/red-green.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/red-white.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/red.svg +6 -0
- data/lib/mtg_card_maker/icons/phyrexian/white-black.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/white-blue.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/white-green.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/white-red.svg +19 -0
- data/lib/mtg_card_maker/icons/phyrexian/white.svg +6 -0
- data/lib/mtg_card_maker/icons/red.svg +6 -1
- data/lib/mtg_card_maker/icons/single-digit.svg +6 -0
- data/lib/mtg_card_maker/icons/snow.svg +24 -0
- data/lib/mtg_card_maker/icons/tap.svg +1 -0
- data/lib/mtg_card_maker/icons/tap_legacy.svg +45 -0
- data/lib/mtg_card_maker/icons/untap.svg +1 -0
- data/lib/mtg_card_maker/icons/white.svg +6 -1
- data/lib/mtg_card_maker/icons/x.svg +6 -0
- data/lib/mtg_card_maker/layer_config.rb +21 -46
- data/lib/mtg_card_maker/layers/border_layer.rb +4 -5
- data/lib/mtg_card_maker/layers/frame_layer.rb +1 -1
- data/lib/mtg_card_maker/layers/name_layer.rb +16 -8
- data/lib/mtg_card_maker/layers/power_layer.rb +1 -3
- data/lib/mtg_card_maker/layers/text_box_layer.rb +205 -51
- data/lib/mtg_card_maker/layers/type_line_layer.rb +2 -4
- data/lib/mtg_card_maker/logger.rb +62 -0
- data/lib/mtg_card_maker/mana_cost.rb +59 -128
- data/lib/mtg_card_maker/sprite_sheet_assets.rb +10 -55
- data/lib/mtg_card_maker/sprite_sheet_builder.rb +20 -8
- data/lib/mtg_card_maker/sprite_sheet_service.rb +22 -9
- data/lib/mtg_card_maker/svg_gradient_service.rb +11 -11
- data/lib/mtg_card_maker/symbol_replacement_service.rb +102 -0
- data/lib/mtg_card_maker/text_rendering_service.rb +7 -3
- data/lib/mtg_card_maker/version.rb +1 -1
- data/lib/mtg_card_maker.rb +9 -78
- metadata +79 -12
- data/lib/mtg_card_maker/fonts/Goudy Mediaeval DemiBold.ttf +0 -0
- data/lib/mtg_card_maker/fonts/goudy_base64.txt +0 -1
data/lib/mtg_card_maker/cli.rb
CHANGED
|
@@ -21,7 +21,7 @@ module MtgCardMaker
|
|
|
21
21
|
# --rules-text "Lightning Bolt deals 3 damage to any target." --color red
|
|
22
22
|
#
|
|
23
23
|
# @since 0.1.0
|
|
24
|
-
class CLI < Thor
|
|
24
|
+
class CLI < Thor
|
|
25
25
|
package_name 'mtg_card_maker'
|
|
26
26
|
map 'a' => :add_card
|
|
27
27
|
map 'ac' => :add_card
|
|
@@ -51,7 +51,8 @@ module MtgCardMaker
|
|
|
51
51
|
color: { type: :string,
|
|
52
52
|
default: 'colorless',
|
|
53
53
|
desc: 'Card color (white, blue, black, red, green, colorless)' },
|
|
54
|
-
art: { type: :string, aliases: ['artwork', 'image'], desc: 'Image URL or path for card artwork' }
|
|
54
|
+
art: { type: :string, aliases: ['artwork', 'image'], desc: 'Image URL or path for card artwork' },
|
|
55
|
+
embed_font: { type: :boolean, default: true, desc: 'Embed font as base64 in SVG' }
|
|
55
56
|
}
|
|
56
57
|
end
|
|
57
58
|
|
|
@@ -80,7 +81,7 @@ module MtgCardMaker
|
|
|
80
81
|
config = config.transform_keys(&:to_sym)
|
|
81
82
|
card = BaseCard.new(config)
|
|
82
83
|
card.save(options[:output])
|
|
83
|
-
|
|
84
|
+
logger.success("Generated #{options[:output]}!")
|
|
84
85
|
end
|
|
85
86
|
|
|
86
87
|
# @!method generate_sprite(yaml_file, output_file)
|
|
@@ -89,17 +90,9 @@ module MtgCardMaker
|
|
|
89
90
|
option :cards_per_row, type: :numeric, default: 4, desc: 'Number of cards per row in sprite'
|
|
90
91
|
option :spacing, type: :numeric, default: 30, desc: 'Spacing between cards in pixels'
|
|
91
92
|
def generate_sprite(yaml_file, output_file)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
config = load_yaml_config(yaml_file)
|
|
96
|
-
sprite_service = create_sprite_service
|
|
97
|
-
process_sprite_generation(config, sprite_service, output_file)
|
|
98
|
-
rescue Psych::SyntaxError => e
|
|
99
|
-
handle_yaml_error(e)
|
|
100
|
-
rescue StandardError => e
|
|
101
|
-
handle_general_error(e)
|
|
102
|
-
end
|
|
93
|
+
config = validate_yaml(yaml_file)
|
|
94
|
+
sprite_service = create_sprite_service
|
|
95
|
+
process_sprite_generation(config, sprite_service, output_file)
|
|
103
96
|
end
|
|
104
97
|
|
|
105
98
|
# @!method add_card(yaml_file)
|
|
@@ -107,11 +100,8 @@ module MtgCardMaker
|
|
|
107
100
|
desc 'add_card YAML_FILE [OPTIONS]', 'Add a new card configuration to YAML file'
|
|
108
101
|
card_options.each { |option, config| option option, config }
|
|
109
102
|
def add_card(yaml_file)
|
|
110
|
-
# Create directory
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
# Load existing config or create new one
|
|
114
|
-
config = File.exist?(yaml_file) ? YAML.safe_load_file(yaml_file) : {}
|
|
103
|
+
# Create directory and load/validate config
|
|
104
|
+
config = create_directory_and_load_config(yaml_file)
|
|
115
105
|
|
|
116
106
|
# Generate a unique key for the card
|
|
117
107
|
card_key = generate_card_key(options[:name], config)
|
|
@@ -124,47 +114,40 @@ module MtgCardMaker
|
|
|
124
114
|
|
|
125
115
|
# Save back to file
|
|
126
116
|
File.write(yaml_file, config.to_yaml)
|
|
127
|
-
|
|
128
|
-
|
|
117
|
+
logger.success("Added card '#{options[:name]}' to #{yaml_file}!")
|
|
118
|
+
logger.info("🎴 Key: #{card_key}")
|
|
129
119
|
end
|
|
130
120
|
|
|
131
121
|
private
|
|
132
122
|
|
|
133
|
-
def
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
warn "❌ YAML file not found: #{yaml_file}"
|
|
137
|
-
exit 1
|
|
123
|
+
def logger
|
|
124
|
+
@logger ||= MtgCardMaker::Logger.new
|
|
138
125
|
end
|
|
139
126
|
|
|
140
127
|
def process_sprite_generation(config, sprite_service, output_file)
|
|
141
128
|
if sprite_service.create_sprite_sheet(config, output_file)
|
|
142
129
|
display_success_message(config, sprite_service, output_file)
|
|
143
130
|
else
|
|
144
|
-
|
|
131
|
+
logger.error('Failed to generate sprite sheet')
|
|
145
132
|
exit 1
|
|
146
133
|
end
|
|
147
134
|
end
|
|
148
135
|
|
|
149
136
|
def handle_yaml_error(error)
|
|
150
|
-
|
|
137
|
+
logger.error("Invalid YAML syntax: #{error.message}")
|
|
151
138
|
exit 1
|
|
152
139
|
end
|
|
153
140
|
|
|
154
141
|
def handle_general_error(error)
|
|
155
|
-
|
|
142
|
+
logger.error(error.message)
|
|
156
143
|
exit 1
|
|
157
144
|
end
|
|
158
145
|
|
|
159
146
|
def display_success_message(config, sprite_service, output_file)
|
|
160
|
-
|
|
147
|
+
logger.success("Generated #{output_file}!")
|
|
161
148
|
width, height = sprite_service.sprite_dimensions(config.length)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
def load_yaml_config(yaml_file)
|
|
167
|
-
YAML.safe_load_file(yaml_file)
|
|
149
|
+
logger.info("📏 Sprite dimensions: #{width}x#{height} pixels")
|
|
150
|
+
logger.info("🎨 Contains #{config.length} cards")
|
|
168
151
|
end
|
|
169
152
|
|
|
170
153
|
def create_sprite_service
|
|
@@ -189,9 +172,9 @@ module MtgCardMaker
|
|
|
189
172
|
end
|
|
190
173
|
|
|
191
174
|
def add_optional_fields(config)
|
|
192
|
-
optional_fields = %w[mana_cost power toughness border_color color art]
|
|
175
|
+
optional_fields = %w[mana_cost power toughness border_color color art embed_font]
|
|
193
176
|
optional_fields.each do |field|
|
|
194
|
-
config[field] = options[field.to_sym] if options
|
|
177
|
+
config[field] = options[field.to_sym] if options.key?(field.to_sym)
|
|
195
178
|
end
|
|
196
179
|
|
|
197
180
|
# Handle flavor_text separately to process newlines
|
|
@@ -205,13 +188,33 @@ module MtgCardMaker
|
|
|
205
188
|
text.gsub('\\n', "\n")
|
|
206
189
|
end
|
|
207
190
|
|
|
208
|
-
def
|
|
191
|
+
def create_directory_and_load_config(yaml_file)
|
|
192
|
+
# Create directory if it doesn't exist
|
|
193
|
+
FileUtils.mkdir_p(File.dirname(yaml_file))
|
|
194
|
+
|
|
195
|
+
# Load and validate config
|
|
196
|
+
validate_yaml(yaml_file)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def validate_yaml(yaml_file)
|
|
200
|
+
return {} unless File.exist?(yaml_file)
|
|
201
|
+
|
|
202
|
+
YAML.safe_load_file(yaml_file) || {}
|
|
203
|
+
rescue Psych::SyntaxError => e
|
|
204
|
+
logger.error("Invalid YAML syntax: #{e.message}")
|
|
205
|
+
exit 1
|
|
206
|
+
rescue StandardError => e
|
|
207
|
+
logger.error("Error reading YAML file: #{e.message}")
|
|
208
|
+
exit 1
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def generate_card_key(name, config)
|
|
209
212
|
base_key = name.downcase.gsub(/[^a-z0-9]/, '_').squeeze('_').chomp('_')
|
|
210
213
|
|
|
211
214
|
# If key already exists, append a number
|
|
212
|
-
if
|
|
215
|
+
if config.key?(base_key)
|
|
213
216
|
counter = 1
|
|
214
|
-
counter += 1 while
|
|
217
|
+
counter += 1 while config.key?("#{base_key}_#{counter}")
|
|
215
218
|
"#{base_key}_#{counter}"
|
|
216
219
|
else
|
|
217
220
|
base_key
|
|
@@ -17,14 +17,14 @@ module MtgCardMaker
|
|
|
17
17
|
# colorless_scheme = MtgCardMaker::ColorScheme.colorless
|
|
18
18
|
#
|
|
19
19
|
# @since 0.1.0
|
|
20
|
-
class ColorScheme
|
|
20
|
+
class ColorScheme
|
|
21
21
|
# Predefined color schemes for all MTG colors and card types
|
|
22
22
|
# @return [Hash] the predefined color scheme configurations
|
|
23
23
|
SCHEMES = {
|
|
24
24
|
colorless: {
|
|
25
25
|
frame_gradient: ['#8B8B8B', '#6B6B6B', '#4A4A4A'],
|
|
26
26
|
name_gradient: ['#F5F5F5', '#E8E8E8', '#D4D4D4'],
|
|
27
|
-
|
|
27
|
+
text_box_gradient: ['#F5F5F5', '#E8E8E8', '#D4D4D4'],
|
|
28
28
|
card_gradient: ['#3D3D3D', '#111', '#1A1A1A'],
|
|
29
29
|
primary: '#8B8B8B',
|
|
30
30
|
background: '#E8E8E8',
|
|
@@ -37,7 +37,7 @@ module MtgCardMaker
|
|
|
37
37
|
white: {
|
|
38
38
|
frame_gradient: ['#FFF9C4', '#F5F5F5', '#BDB76B'],
|
|
39
39
|
name_gradient: ['#FFFFFF', '#FFF9C4', '#E0E0E0'],
|
|
40
|
-
|
|
40
|
+
text_box_gradient: ['#FFFFFF', '#F5F5F5', '#E0E0E0'],
|
|
41
41
|
card_gradient: ['#D7CCC8', '#BCAAA4', '#8D6E63'],
|
|
42
42
|
primary: '#8B8B8B',
|
|
43
43
|
background: '#FFFFFF',
|
|
@@ -47,7 +47,7 @@ module MtgCardMaker
|
|
|
47
47
|
blue: {
|
|
48
48
|
frame_gradient: ['#42A5F5', '#1565C0', '#263238'],
|
|
49
49
|
name_gradient: ['#E3F2FD', '#BBDEFB', '#90CAF9'],
|
|
50
|
-
|
|
50
|
+
text_box_gradient: ['#F3F8FF', '#E3F2FD', '#BBDEFB'],
|
|
51
51
|
card_gradient: ['#546E7A', '#37474F', '#263238'],
|
|
52
52
|
primary: '#42A5F5',
|
|
53
53
|
background: '#E3F2FD',
|
|
@@ -57,7 +57,7 @@ module MtgCardMaker
|
|
|
57
57
|
black: {
|
|
58
58
|
frame_gradient: ['#424242', '#212121', '#000'],
|
|
59
59
|
name_gradient: ['#E0E0E0', '#BDBDBD', '#9E9E9E'],
|
|
60
|
-
|
|
60
|
+
text_box_gradient: ['#F5F5F5', '#E0E0E0', '#BDBDBD'],
|
|
61
61
|
card_gradient: ['#424242', '#212121', '#000'],
|
|
62
62
|
primary: '#424242',
|
|
63
63
|
background: '#E0E0E0',
|
|
@@ -67,7 +67,7 @@ module MtgCardMaker
|
|
|
67
67
|
red: {
|
|
68
68
|
frame_gradient: ['#F44336', '#D32F2F', '#B71C1C'],
|
|
69
69
|
name_gradient: ['#FFEBEE', '#FFCDD2', '#EF9A9A'],
|
|
70
|
-
|
|
70
|
+
text_box_gradient: ['#FFEBEE', '#FFCDD2', '#EF9A9A'],
|
|
71
71
|
card_gradient: ['#8D6E63', '#6D4C41', '#4E342E'],
|
|
72
72
|
primary: '#F44336',
|
|
73
73
|
background: '#FFEBEE',
|
|
@@ -77,7 +77,7 @@ module MtgCardMaker
|
|
|
77
77
|
green: {
|
|
78
78
|
frame_gradient: ['#4CAF50', '#388E3C', '#2E7D32'],
|
|
79
79
|
name_gradient: ['#E8F5E8', '#C8E6C9', '#A5D6A7'],
|
|
80
|
-
|
|
80
|
+
text_box_gradient: ['#F1F8E9', '#E8F5E8', '#C8E6C9'],
|
|
81
81
|
card_gradient: ['#6D4C41', '#5D4037', '#4E342E'],
|
|
82
82
|
primary: '#4CAF50',
|
|
83
83
|
background: '#E8F5E8',
|
|
@@ -87,7 +87,7 @@ module MtgCardMaker
|
|
|
87
87
|
gold: {
|
|
88
88
|
frame_gradient: ['#FFD700', '#FFA500', '#FF8C00'],
|
|
89
89
|
name_gradient: ['#F5DEB3', '#E1C16E', '#C9A13B'],
|
|
90
|
-
|
|
90
|
+
text_box_gradient: ['#FFF8DC', '#FFE4B5', '#FFDAB9'],
|
|
91
91
|
card_gradient: ['#8B7355', '#6B4423', '#4A2C0A'],
|
|
92
92
|
primary: '#FFD700',
|
|
93
93
|
background: '#FFF8DC',
|
|
@@ -100,7 +100,7 @@ module MtgCardMaker
|
|
|
100
100
|
artifact: {
|
|
101
101
|
frame_gradient: ['#D2B48C', '#BC8F8F', '#A0522D'],
|
|
102
102
|
name_gradient: ['#F5F5DC', '#DEB887', '#CD853F'],
|
|
103
|
-
|
|
103
|
+
text_box_gradient: ['#F5F5DC', '#DEB887', '#CD853F'],
|
|
104
104
|
card_gradient: ['#8B7355', '#6B4423', '#4A2C0A'],
|
|
105
105
|
primary: '#D2B48C',
|
|
106
106
|
background: '#F5F5DC',
|
|
@@ -169,21 +169,21 @@ module MtgCardMaker
|
|
|
169
169
|
config[:name_gradient]
|
|
170
170
|
end
|
|
171
171
|
|
|
172
|
-
#
|
|
173
|
-
def
|
|
174
|
-
config[:
|
|
172
|
+
# Text box gradient colors
|
|
173
|
+
def text_box_gradient_start
|
|
174
|
+
config[:text_box_gradient][0]
|
|
175
175
|
end
|
|
176
176
|
|
|
177
|
-
def
|
|
178
|
-
config[:
|
|
177
|
+
def text_box_gradient_middle
|
|
178
|
+
config[:text_box_gradient][1]
|
|
179
179
|
end
|
|
180
180
|
|
|
181
|
-
def
|
|
182
|
-
config[:
|
|
181
|
+
def text_box_gradient_end
|
|
182
|
+
config[:text_box_gradient][2]
|
|
183
183
|
end
|
|
184
184
|
|
|
185
|
-
def
|
|
186
|
-
config[:
|
|
185
|
+
def text_box_gradient_colors
|
|
186
|
+
config[:text_box_gradient]
|
|
187
187
|
end
|
|
188
188
|
|
|
189
189
|
# Card gradient colors
|
|
@@ -296,10 +296,5 @@ module MtgCardMaker
|
|
|
296
296
|
def self.artifact
|
|
297
297
|
new(:artifact)
|
|
298
298
|
end
|
|
299
|
-
|
|
300
|
-
# @return [ColorScheme] a silver color scheme
|
|
301
|
-
def self.silver
|
|
302
|
-
new(:silver)
|
|
303
|
-
end
|
|
304
299
|
end
|
|
305
300
|
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module MtgCardMaker
|
|
4
|
+
# Service class for managing CSS styles used across the application
|
|
5
|
+
class CssService
|
|
6
|
+
class << self
|
|
7
|
+
# Generate the font face declaration
|
|
8
|
+
#
|
|
9
|
+
# @param embed [Boolean] whether to embed the font as base64
|
|
10
|
+
# @return [String] the font face CSS
|
|
11
|
+
def font_face(embed: false)
|
|
12
|
+
return '' unless embed
|
|
13
|
+
|
|
14
|
+
font_path = File.join(__dir__, 'fonts', 'goudy_bookletter_base64.txt')
|
|
15
|
+
base64_font_data = File.read(font_path).strip
|
|
16
|
+
<<~CSS
|
|
17
|
+
@font-face {
|
|
18
|
+
font-family: 'Goudy Bookletter 1911';
|
|
19
|
+
src: url(data:font/truetype;charset=utf-8;base64,#{base64_font_data}) format('truetype');
|
|
20
|
+
}
|
|
21
|
+
CSS
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Generate all CSS classes
|
|
25
|
+
#
|
|
26
|
+
# @return [String] the CSS classes
|
|
27
|
+
def css_classes(embed: false)
|
|
28
|
+
<<~CSS
|
|
29
|
+
/* Font Classes */
|
|
30
|
+
.card-name, .card-type {
|
|
31
|
+
font-family: #{font_family(embed)};
|
|
32
|
+
font-weight: #{font_weight(embed)};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.card-rules-text, .mana-cost-text {
|
|
36
|
+
font-family: serif;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.card-flavor-text {
|
|
40
|
+
font-family: serif;
|
|
41
|
+
font-style: italic;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.card-power-toughness {
|
|
45
|
+
font-family: serif;
|
|
46
|
+
font-weight: bold;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.card-copyright {
|
|
50
|
+
font-family: sans-serif;
|
|
51
|
+
}
|
|
52
|
+
CSS
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def font_family(embed)
|
|
56
|
+
embed ? "'Goudy Bookletter 1911', serif" : 'serif'
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def font_weight(embed)
|
|
60
|
+
embed ? 'normal' : 'bold'
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Generate complete CSS styles
|
|
64
|
+
#
|
|
65
|
+
# @param embed [Boolean] whether to embed the font as base64
|
|
66
|
+
# @return [String] the complete CSS styles
|
|
67
|
+
def complete_styles(embed: false)
|
|
68
|
+
font_face(embed: embed) + css_classes(embed: embed)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
Binary file
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
Copyright (c) 2010, Barry Schwartz (crudfactory.com)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
-----------------------------------------------------------
|
|
8
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
9
|
+
-----------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
PREAMBLE
|
|
12
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
13
|
+
development of collaborative font projects, to support the font creation
|
|
14
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
15
|
+
open framework in which fonts may be shared and improved in partnership
|
|
16
|
+
with others.
|
|
17
|
+
|
|
18
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
19
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
20
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
21
|
+
redistributed and/or sold with any software provided that any reserved
|
|
22
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
23
|
+
however, cannot be released under any other type of license. The
|
|
24
|
+
requirement for fonts to remain under this license does not apply
|
|
25
|
+
to any document created using the fonts or their derivatives.
|
|
26
|
+
|
|
27
|
+
DEFINITIONS
|
|
28
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
29
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
30
|
+
include source files, build scripts and documentation.
|
|
31
|
+
|
|
32
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
33
|
+
copyright statement(s).
|
|
34
|
+
|
|
35
|
+
"Original Version" refers to the collection of Font Software components as
|
|
36
|
+
distributed by the Copyright Holder(s).
|
|
37
|
+
|
|
38
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
39
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
40
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
41
|
+
new environment.
|
|
42
|
+
|
|
43
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
44
|
+
writer or other person who contributed to the Font Software.
|
|
45
|
+
|
|
46
|
+
PERMISSION & CONDITIONS
|
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
48
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
49
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
50
|
+
Software, subject to the following conditions:
|
|
51
|
+
|
|
52
|
+
1) Neither the Font Software nor any of its individual components,
|
|
53
|
+
in Original or Modified Versions, may be sold by itself.
|
|
54
|
+
|
|
55
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
56
|
+
redistributed and/or sold with any software, provided that each copy
|
|
57
|
+
contains the above copyright notice and this license. These can be
|
|
58
|
+
included either as stand-alone text files, human-readable headers or
|
|
59
|
+
in the appropriate machine-readable metadata fields within text or
|
|
60
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
61
|
+
|
|
62
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
63
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
64
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
65
|
+
presented to the users.
|
|
66
|
+
|
|
67
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
68
|
+
Software shall not be used to promote, endorse or advertise any
|
|
69
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
70
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
71
|
+
permission.
|
|
72
|
+
|
|
73
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
74
|
+
must be distributed entirely under this license, and must not be
|
|
75
|
+
distributed under any other license. The requirement for fonts to
|
|
76
|
+
remain under this license does not apply to any document created
|
|
77
|
+
using the Font Software.
|
|
78
|
+
|
|
79
|
+
TERMINATION
|
|
80
|
+
This license becomes null and void if any of the above conditions are
|
|
81
|
+
not met.
|
|
82
|
+
|
|
83
|
+
DISCLAIMER
|
|
84
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
85
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
86
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
87
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
88
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
89
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
90
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
91
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
92
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|