Browse Source

Add warning to suppress png scaling warning

Close #120
dev
Andy Meneely 10 years ago
parent
commit
710d28f5a8
  1. 1
      CHANGELOG.md
  2. 2
      README.md
  3. 1
      lib/squib/card.rb
  4. 5
      lib/squib/conf.rb
  5. 23
      lib/squib/graphics/image.rb
  6. 6
      lib/squib/project_template/config.yml
  7. 4
      samples/load_images.rb
  8. 1
      samples/load_images_config.yml

1
CHANGELOG.md

@ -7,6 +7,7 @@ Features:
* Crop your PNGs and SVGs! This means you can work from spritesheets if you want. New options to `png` and `svg` are documented in the API docs and demonstrated in the `load_images.rb` sample. (#11) * Crop your PNGs and SVGs! This means you can work from spritesheets if you want. New options to `png` and `svg` are documented in the API docs and demonstrated in the `load_images.rb` sample. (#11)
* Flip your PNGs and SVGs! Set `flip_horizontal: true` or `flip_vertical: true` (or both!) to flip the image about it's center. (#11) * Flip your PNGs and SVGs! Set `flip_horizontal: true` or `flip_vertical: true` (or both!) to flip the image about it's center. (#11)
* Added a `grid` shape that fills the whole card with a grid of your choosing. (#68) * Added a `grid` shape that fills the whole card with a grid of your choosing. (#68)
* Added `warn_png_scale` configuration option to suppress the PNG scale warning. Also: warning only occurs on upscale, not on downscaling (#121)
Chores: Chores:
* Ripped out a lot of old constants used from the old way we handled arguments. Yay negative churn! * Ripped out a lot of old constants used from the old way we handled arguments. Yay negative churn!

2
README.md

@ -463,6 +463,8 @@ Squib supports various configuration properties that can be specified in an exte
* `antialias` (`fast, good, best, none, gray, subpixel`, default: best). Set the algorithm that Cairo will use for antialiasing. Using our benchmarks on large decks, `best` is only ~10% slower anyway. For more info see the [Cairo docs](http://www.cairographics.org/manual/cairo-cairo-t.html#cairo-antialias-t). * `antialias` (`fast, good, best, none, gray, subpixel`, default: best). Set the algorithm that Cairo will use for antialiasing. Using our benchmarks on large decks, `best` is only ~10% slower anyway. For more info see the [Cairo docs](http://www.cairographics.org/manual/cairo-cairo-t.html#cairo-antialias-t).
* `backend` (`svg` or `memory`, default: `memory`). Defines how Cairo will store the operations. Memory is recommended for higher quality rendering. * `backend` (`svg` or `memory`, default: `memory`). Defines how Cairo will store the operations. Memory is recommended for higher quality rendering.
* `prefix` (default: `card_`). When using an SVG backend, cards are auto-saved with this prefix and `"%02d"` numbering format. * `prefix` (default: `card_`). When using an SVG backend, cards are auto-saved with this prefix and `"%02d"` numbering format.
* `warn_ellipsize` (default: true). Warn when text is ellipsized
* `warn_png_scale` (default: true). Warn when a PNG file is upscaled
For debugging/sanity purposes, if you want to make sure your configuration options are parsed correclty, the above options are also available as methods within Squib::Deck, for example: For debugging/sanity purposes, if you want to make sure your configuration options are parsed correclty, the above options are also available as methods within Squib::Deck, for example:

1
lib/squib/card.rb

@ -42,7 +42,6 @@ module Squib
end end
end end
# A save/restore wrapper for using Cairo # A save/restore wrapper for using Cairo
# :nodoc: # :nodoc:
# @api private # @api private

5
lib/squib/conf.rb

@ -26,6 +26,7 @@ module Squib
'smart_quotes' => true, 'smart_quotes' => true,
'text_hint' => 'off', 'text_hint' => 'off',
'warn_ellipsize'=> true, 'warn_ellipsize'=> true,
'warn_png_scale'=> true,
} }
#Translate the hints to the methods. #Translate the hints to the methods.
@ -108,6 +109,10 @@ module Squib
@config_hash['warn_ellipsize'] @config_hash['warn_ellipsize']
end end
def warn_png_scale?
@config_hash['warn_png_scale']
end
private private
def normalize_antialias def normalize_antialias

23
lib/squib/graphics/image.rb

@ -20,12 +20,15 @@ module Squib
png = Squib.cache_load_image(file) png = Squib.cache_load_image(file)
use_cairo do |cc| use_cairo do |cc|
cc.translate(box.x, box.y) cc.translate(box.x, box.y)
Squib.logger.warn "PNG scaling results in aliasing." if box.width != :native || box.height != :native box.width = png.width.to_f if box.width == :native
box.width = png.width.to_f if box.width == :native box.height = png.height.to_f if box.height == :native
box.height = png.height.to_f if box.height == :native box.width = png.width.to_f * box.height.to_f / png.height.to_f if box.width == :scale
box.width = png.width.to_f * box.height.to_f / png.height.to_f if box.width == :scale box.height = png.height.to_f * box.width.to_f / png.width.to_f if box.height == :scale
box.height = png.height.to_f * box.width.to_f / png.width.to_f if box.height == :scale
cc.scale(box.width.to_f / png.width.to_f, box.height.to_f / png.height.to_f) scale_width = box.width.to_f / png.width.to_f
scale_height = box.height.to_f / png.height.to_f
warn_png_scale(file, scale_width, scale_height)
cc.scale(scale_width, scale_height)
cc.rotate(trans.angle) cc.rotate(trans.angle)
cc.flip(trans.flip_vertical, trans.flip_horizontal, box.width / 2, box.height / 2) cc.flip(trans.flip_vertical, trans.flip_horizontal, box.width / 2, box.height / 2)
@ -49,6 +52,14 @@ module Squib
end end
end end
# :nodoc:
# @api private
def warn_png_scale(file, scale_width, scale_height)
if @deck.conf.warn_png_scale? && (scale_width > 1.0 || scale_height > 1.0)
Squib.logger.warn "PNG is being upscaled - antialiasing could result: #{file}"
end
end
# :nodoc: # :nodoc:
# @api private # @api private
def svg(file, svg_args, box, paint, trans) def svg(file, svg_args, box, paint, trans)

6
lib/squib/project_template/config.yml

@ -42,4 +42,8 @@
# By default, Squib warns when a text box is ellipsized. This can get verbose # By default, Squib warns when a text box is ellipsized. This can get verbose
# and can be turned off here # and can be turned off here
# warn_ellipsize: true # default # warn_ellipsize: true # default
# warn_ellipsize: false # default # warn_ellipsize: false # turn off entirely
# By default, Squib will warn if a PNG is being up-scaled.
# warn_png_scale: true # default
# warn_png_scale: false # turn off entirely

4
samples/load_images.rb

@ -1,6 +1,6 @@
require 'squib' require 'squib'
Squib::Deck.new(width: 825, height: 1125, cards: 1) do Squib::Deck.new(width: 825, height: 1125, cards: 1, config: 'load_images_config.yml') do
background color: '#0b7c8e' background color: '#0b7c8e'
rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38 rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38
@ -10,7 +10,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 1) do
# Can be scaled if width and height are set # Can be scaled if width and height are set
svg file: 'spanner.svg', x: 50, y: 50, width: 250, height: 250 svg file: 'spanner.svg', x: 50, y: 50, width: 250, height: 250
png file: 'shiny-purse.png', x: 305, y: 50, width: 250, height: 250 png file: 'shiny-purse.png', x: 305, y: 50, width: 250, height: 250
#...but PNGs will warn if it's an upscale #...but PNGs will warn if it's an upscale, unless you disable them in config.yml
# Can be scaled using just width or height, if one of them is set to :scale # Can be scaled using just width or height, if one of them is set to :scale
svg file: 'spanner.svg', x: 200, y: 350, width: 35, height: :scale svg file: 'spanner.svg', x: 200, y: 350, width: 35, height: :scale

1
samples/load_images_config.yml

@ -0,0 +1 @@
warn_png_scale: false
Loading…
Cancel
Save