Browse Source

Documentation and example of autoscaling

dev
Andy Meneely 11 years ago
parent
commit
985f898729
  1. 1
      lib/squib/api/text.rb
  2. 27
      samples/autoscale_font.rb

1
lib/squib/api/text.rb

@ -19,6 +19,7 @@ module Squib
# For the official documentation, see the [Pango docs](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Pango%3A%3AFontDescription#style). # For the official documentation, see the [Pango docs](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Pango%3A%3AFontDescription#style).
# This [description](http://www.pygtk.org/pygtk2reference/class-pangofontdescription.html) is also quite good. # This [description](http://www.pygtk.org/pygtk2reference/class-pangofontdescription.html) is also quite good.
# See the {file:samples/text-options.rb samples/text.rb} as well. # See the {file:samples/text-options.rb samples/text.rb} as well.
# @option opts font_size [Integer] (nil) an override of font string description, for scaling the font according to the size of the string
# @option opts x [Integer] (0) the x-coordinate to place # @option opts x [Integer] (0) the x-coordinate to place
# @option opts y [Integer] (0) the y-coordinate to place # @option opts y [Integer] (0) the y-coordinate to place
# @option opts color [String] (:black) the color the font will render to. See {file:README.md#Specifying_Colors Specifying Colors} # @option opts color [String] (:black) the color the font will render to. See {file:README.md#Specifying_Colors Specifying Colors}

27
samples/autoscale_font.rb

@ -0,0 +1,27 @@
require 'squib'
# Here's an exmaple of being able to scale a font
# based on the length of individual string.
# Handy for making minor font scales to fill text boxes.
def autoscale(str_array)
str_array.inject([]) do | memo, str |
case str.length
when 0..10
memo << 125
when 11..20
memo << 45
else
memo << 36
end
end
end
Squib::Deck.new(cards: 3) do
background color: :white
title = %w(ShortBig Medium_Length_Name Super_Duper_Long_Name)
text str: title, x: 65, y: 400, align: :center, width: 700,
font: 'Arial', font_size: autoscale(title), hint: :red
save prefix: 'autoscale_', format: :png
end
Loading…
Cancel
Save