File: kerning_and_character_spacing.rb

package info (click to toggle)
ruby-prawn 2.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,320 kB
  • sloc: ruby: 15,654; sh: 43; makefile: 20
file content (36 lines) | stat: -rw-r--r-- 1,394 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Kerning is the process of adjusting the spacing between characters in a
# proportional font. It is usually done with specific letter pairs. We can
# switch it on and off if it is available with the current font. Just pass a
# boolean value to the <code>:kerning</code> option of the text methods.
#
# Character Spacing is the space between characters. It can be increased or
# decreased and will have effect on the whole text. Just pass a number to the
# <code>:character_spacing</code> option from the text methods.

require_relative '../example_helper'

filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::ManualBuilder::Example.generate(filename) do
  font_size(30) do
    text_box 'With kerning:',    kerning: true,  at: [0, y - 40]
    text_box 'Without kerning:', kerning: false, at: [0, y - 80]

    text_box 'Tomato', kerning: true,  at: [250, y - 40]
    text_box 'Tomato', kerning: false, at: [250, y - 80]

    text_box 'WAR', kerning: true,  at: [400, y - 40]
    text_box 'WAR', kerning: false, at: [400, y - 80]

    text_box 'F.', kerning: true,  at: [500, y - 40]
    text_box 'F.', kerning: false, at: [500, y - 80]
  end

  move_down 80

  string = 'What have you done to the space between the characters?'
  [-2, -1, 0, 0.5, 1, 2].each do |spacing|
    move_down 20
    text "#{string} (character_spacing: #{spacing})",
      character_spacing: spacing
  end
end