diff --git a/CHANGELOG.md b/CHANGELOG.md index 5beaf47..0f9a0ba 100644 --- a/CHANGELOG.md +++ b/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) * 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 `warn_png_scale` configuration option to suppress the PNG scale warning. Also: warning only occurs on upscale, not on downscaling (#121) Chores: * Ripped out a lot of old constants used from the old way we handled arguments. Yay negative churn! diff --git a/README.md b/README.md index e942d29..b0e9b01 100644 --- a/README.md +++ b/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). * `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. +* `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: diff --git a/lib/squib/card.rb b/lib/squib/card.rb index d92867b..1f37206 100644 --- a/lib/squib/card.rb +++ b/lib/squib/card.rb @@ -42,7 +42,6 @@ module Squib end end - # A save/restore wrapper for using Cairo # :nodoc: # @api private diff --git a/lib/squib/conf.rb b/lib/squib/conf.rb index ce3f395..c6a80b1 100644 --- a/lib/squib/conf.rb +++ b/lib/squib/conf.rb @@ -26,6 +26,7 @@ module Squib 'smart_quotes' => true, 'text_hint' => 'off', 'warn_ellipsize'=> true, + 'warn_png_scale'=> true, } #Translate the hints to the methods. @@ -108,6 +109,10 @@ module Squib @config_hash['warn_ellipsize'] end + def warn_png_scale? + @config_hash['warn_png_scale'] + end + private def normalize_antialias diff --git a/lib/squib/graphics/image.rb b/lib/squib/graphics/image.rb index d2a1a20..5f29881 100644 --- a/lib/squib/graphics/image.rb +++ b/lib/squib/graphics/image.rb @@ -20,12 +20,15 @@ module Squib png = Squib.cache_load_image(file) use_cairo do |cc| 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.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.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) + box.width = png.width.to_f if box.width == :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.height = png.height.to_f * box.width.to_f / png.width.to_f if box.height == :scale + + 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.flip(trans.flip_vertical, trans.flip_horizontal, box.width / 2, box.height / 2) @@ -49,6 +52,14 @@ module Squib 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: # @api private def svg(file, svg_args, box, paint, trans) diff --git a/lib/squib/project_template/config.yml b/lib/squib/project_template/config.yml index 502d273..4098ce8 100644 --- a/lib/squib/project_template/config.yml +++ b/lib/squib/project_template/config.yml @@ -42,4 +42,8 @@ # By default, Squib warns when a text box is ellipsized. This can get verbose # and can be turned off here # 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 diff --git a/samples/load_images.rb b/samples/load_images.rb index d87a773..f5b369f 100644 --- a/samples/load_images.rb +++ b/samples/load_images.rb @@ -1,6 +1,6 @@ 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' 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 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 - #...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 svg file: 'spanner.svg', x: 200, y: 350, width: 35, height: :scale diff --git a/samples/load_images_config.yml b/samples/load_images_config.yml new file mode 100644 index 0000000..4bd8f3a --- /dev/null +++ b/samples/load_images_config.yml @@ -0,0 +1 @@ +warn_png_scale: false \ No newline at end of file