Feat/font autoscale (#288)
* PoC font autosize feature * Take enumerables or 'auto' keyword for autoscaling * Allo enumerables of font_size per card, where the largest font size that does not ellipsize is chosen * Use ellipsize: :autoscale keyword to determine font autosizing * Use binary search to find the correct font size * Consider new ellipsize option in testcase * Document ellipsize: :autoscale option * Add ellipsize: :autoscale sample to text sample * Fix double multiplication with Pango::SCALE * Scale embedded images with text when autoscaling * Remove stray semicolon * Return dummy value for FontDescription.size in mock_cairo * Update regression test data for autoscale feature. * Add ellipsize: :autoscale example to existing font_autoscale sample * Add missing :autoscale to list of options in documentation
This commit is contained in:
@@ -16,14 +16,20 @@ def autoscale(str_array)
|
||||
end
|
||||
end
|
||||
|
||||
Squib::Deck.new(width: 300, height: 100, cards: 3) do
|
||||
Squib::Deck.new(width: 300, height: 200, cards: 3) do
|
||||
background color: :white
|
||||
rect
|
||||
title = ['Short & Big',
|
||||
'Medium Length & Size',
|
||||
'Super duper long string here, therefore a smaller font.']
|
||||
|
||||
# Scale text based on the string length
|
||||
text str: title, font: 'Arial', font_size: autoscale(title),
|
||||
x: 10, y:10, align: :center, width: 280, ellipsize: false, hint: :red
|
||||
|
||||
# Automatically scale the text down from the specified font_size to the largest size that fits
|
||||
text str: title, font: 'Arial', font_size: 10,
|
||||
x: 10, y:100, align: :center, width: 280, height: 50, ellipsize: :autoscale, hint: :red
|
||||
|
||||
save_sheet columns: 3
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'squib'
|
||||
require 'squib/sample_helpers'
|
||||
|
||||
Squib::Deck.new(width: 1000, height: 1250) do
|
||||
Squib::Deck.new(width: 1000, height: 1450) do
|
||||
draw_graph_paper width, height
|
||||
|
||||
sample 'Font strings are quite expressive. Specify family, modifiers, then size. Font names with spaces in them should end with a comma to help with parsing.' do |x, y|
|
||||
@@ -21,6 +21,11 @@ Squib::Deck.new(width: 1000, height: 1250) do
|
||||
hint: :red, width: 350, font: 'Serif bold 7'
|
||||
end
|
||||
|
||||
sample 'If you specify ellipsize: :autosize, the font size will autoscale.' do |x, y|
|
||||
text str: 'This text doeas not fit with font size 7. It is autoscaled to the largest size that fits instead.', x: x - 50, y: y,
|
||||
hint: :red, width: 350, height: 100, ellipsize: :autoscale, font: 'Serif bold 7'
|
||||
end
|
||||
|
||||
sample 'If you specify the width only, and turn off ellipsize, the height will auto-stretch.' do |x, y|
|
||||
text str: 'This has fixed width, but not fixed height.', x: x, y: y,
|
||||
hint: :red, width: 300, ellipsize: false, font: 'Serif bold 8'
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 230 KiB |
Reference in New Issue
Block a user