Browse Source

Set font antialiasing from global antialiasing

This is a workaround until we get a proper solution in #59
dev
Andy Meneely 11 years ago
parent
commit
0616512bd6
  1. 10
      CHANGELOG.md
  2. 2
      README.md
  3. 9
      lib/squib/graphics/text.rb
  4. 5
      samples/config_text_markup.rb
  5. 1
      samples/config_text_markup.yml
  6. 10
      spec/data/samples/embed_text.rb.txt

10
CHANGELOG.md

@ -1,14 +1,16 @@
# Squib CHANGELOG # Squib CHANGELOG
# v0.5.0 ## v0.5.0
* Embedding of SVGs and PNGs into text! See README, `text_options.rb`, and `embed_text.rb`, and API documentation. This was a finnicky feature, so feedback and bug reports are welcome. * Embedding of SVGs and PNGs into text! See README, `text_options.rb`, and `embed_text.rb`, and API documentation. This was a finnicky feature, so feedback and bug reports are welcome. (#30)
* Curves! We can now do Bezier curves. Documented, and added to the sample `draw_shapes.rb` (#37). * Curves! We can now do Bezier curves. Documented, and added to the sample `draw_shapes.rb` (#37).
* Smart Quotes! The `text` rule now has a `quotes: 'smart'` option where straight quotes get converted to curly quotes. Assumes UTF-8, or you can specify your own quote characters if you're not in UTF-8. * Smart Quotes! The `text` rule now has a `quotes: 'smart'` option where straight quotes get converted to curly quotes. Assumes UTF-8, or you can specify your own quote characters if you're not in UTF-8. (#50)
Known issues Known issues
* OSX Yosemite will show this warning: `<Error>: The function ‘CGFontGetGlyphPath’ is obsolete and will be removed in an upcoming update. Unfortunately, this application, or a library it uses, is using this obsolete function, and is thereby contributing to an overall degradation of system performance.` This warning will go away when the Ruby Cairo bindings upgrades from 1.14.1 to 1.14.2. * OSX Yosemite will show this warning: `<Error>: The function ‘CGFontGetGlyphPath’ is obsolete and will be removed in an upcoming update. Unfortunately, this application, or a library it uses, is using this obsolete function, and is thereby contributing to an overall degradation of system performance.` This warning will go away when the Ruby Cairo bindings upgrades from 1.14.1 to 1.14.2.
# v0.4.0 Special thanks to [pickfifteen](https://github.com/pickfifteen) for testing, feedback, and pull requests!!
## v0.4.0
* SVG backend support! You can now set the deck's back end to work with SVGs instead of images, making the resulting PDFs vectorized. (You can still save to PNGs too.) This was a big change for Squib, and it's got at least one known issue and probably a few more here and there. See discussion on the README for more details. * SVG backend support! You can now set the deck's back end to work with SVGs instead of images, making the resulting PDFs vectorized. (You can still save to PNGs too.) This was a big change for Squib, and it's got at least one known issue and probably a few more here and there. See discussion on the README for more details.
* Added config option for antialiasing method. My benchmarks showed that 'best' is only 10% slower than 'fast' on extremely alias-intensive tasks, so 'best' is the Squib default now. * Added config option for antialiasing method. My benchmarks showed that 'best' is only 10% slower than 'fast' on extremely alias-intensive tasks, so 'best' is the Squib default now.
* Bugfix: Stray stroke on circles after text (#35) * Bugfix: Stray stroke on circles after text (#35)

2
README.md

@ -442,7 +442,7 @@ Squib supports various configuration properties that can be specified in an exte
* `dpi` (Integer, default: 300). Used in calculations when units are used (e.g. for PDF rendering and unit conversion). * `dpi` (Integer, default: 300). Used in calculations when units are used (e.g. for PDF rendering and unit conversion).
* `hint` (ColorString, default: off). Text hints are used to show the boundaries of text boxes. Can be enabled/disabled for individual commands, or set globally with the `set` command. This setting is overriden by `set` and individual commands. * `hint` (ColorString, default: off). Text hints are used to show the boundaries of text boxes. Can be enabled/disabled for individual commands, or set globally with the `set` command. This setting is overriden by `set` and individual commands.
* `custom_colors` (Hash of Colors, default: {}). Defines globally-available colors available to the deck that can be specified in commands. * `custom_colors` (Hash of Colors, default: {}). Defines globally-available colors available to the deck that can be specified in commands.
* `antialias` (`fast, good, best, none`, 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.

9
lib/squib/graphics/text.rb

@ -76,6 +76,14 @@ module Squib
end end
end end
def set_font_rendering_opts!(layout)
font_options = Cairo::FontOptions.new
font_options.antialias = ANTIALIAS_OPTS[(@deck.antialias.downcase)] || 'gray'
font_options.hint_metrics = 'on' # TODO make this configurable
font_options.hint_style = 'full' # TODO make this configurable
layout.context.font_options = font_options
end
# :nodoc: # :nodoc:
# @api private # @api private
def set_wh!(layout, width, height) def set_wh!(layout, width, height)
@ -160,6 +168,7 @@ module Squib
layout.markup = str layout.markup = str
end end
set_font_rendering_opts!(layout)
set_wh!(layout, width, height) set_wh!(layout, width, height)
set_wrap!(layout, wrap) set_wrap!(layout, wrap)
set_ellipsize!(layout, ellipsize) set_ellipsize!(layout, ellipsize)

5
samples/config_text_markup.rb

@ -1,9 +1,14 @@
require 'squib' require 'squib'
Squib::Deck.new(config: 'config_text_markup.yml') do Squib::Deck.new(config: 'config_text_markup.yml') do
background color: :white
text str: %{"'Yaml ain't markup', he says"}, text str: %{"'Yaml ain't markup', he says"},
x: 10, y: 10, width: 300, height: 200, font: 'Serif 20', x: 10, y: 10, width: 300, height: 200, font: 'Serif 20',
markup: true, hint: :cyan markup: true, hint: :cyan
text str: "Notice also the antialiasing method.",
x: 320, y: 10, width: 300, height: 200, font: 'Arial Bold 20'
save_png prefix: 'config_text_' save_png prefix: 'config_text_'
end end

1
samples/config_text_markup.yml

@ -6,3 +6,4 @@ rdquote: "\u201D"
em_dash: "\u2014" em_dash: "\u2014"
en_dash: "\u2013" en_dash: "\u2013"
ellipsis: "\u2026" ellipsis: "\u2026"
antialias: gray

10
spec/data/samples/embed_text.rb.txt

@ -286,3 +286,13 @@ cairo: restore([])
surface: write_to_png(["_output/embed_multi_00.png"]) surface: write_to_png(["_output/embed_multi_00.png"])
surface: write_to_png(["_output/embed_multi_01.png"]) surface: write_to_png(["_output/embed_multi_01.png"])
surface: write_to_png(["_output/embed_multi_02.png"]) surface: write_to_png(["_output/embed_multi_02.png"])
surface: write_to_png(["_output/embed_multisheet_00.png"])
cairo: set_source([MockDouble, 0, 0])
cairo: paint([])
surface: write_to_png(["_output/embed_multisheet_01.png"])
cairo: set_source([MockDouble, 0, 0])
cairo: paint([])
surface: write_to_png(["_output/embed_multisheet_02.png"])
cairo: set_source([MockDouble, 0, 0])
cairo: paint([])
surface: write_to_png(["_output/embed_multisheet_03.png"])

Loading…
Cancel
Save