File: formatted_text.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 (56 lines) | stat: -rw-r--r-- 2,266 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# There are two other text methods available: <code>formatted_text</code> and
# <code>formatted_text_box</code>.
#
# These are useful when the provided text has numerous portions that need to be
# formatted differently. As you might imply from their names the first should
# be used for free flowing text just like the <code>text</code> method and the
# last should be used for positioned text just like <code>text_box</code>.
#
# The main difference between these methods and the <code>text</code> and
# <code>text_box</code> methods is how the text is provided. The
# <code>formatted_text</code> and <code>formatted_text_box</code> methods accept
# an array of hashes. Each hash must provide a <code>:text</code> option which
# is the text string and may provide the following options: <code>:styles</code>
# (an array of symbols), <code>:size</code> (the font size),
# <code>:character_spacing</code> (additional space between the characters),
# <code>:font</code> (the name of a registered font), <code>:color</code> (the
# same input accepted by <code>fill_color</code> and <code>stroke_color</code>),
# <code>:link</code> (an URL to create a link), and <code>:local</code>
# (a link to a local file).

require_relative '../example_helper'

filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::ManualBuilder::Example.generate(filename) do
  formatted_text [
    { text: 'Some bold. ', styles: [:bold] },
    { text: 'Some italic. ', styles: [:italic] },
    { text: 'Bold italic. ', styles: [:bold, :italic] },
    { text: 'Bigger Text. ', size: 20 },
    { text: 'More spacing. ', character_spacing: 3 },
    { text: 'Different Font. ', font: 'Courier' },
    { text: 'Some coloring. ', color: 'FF00FF' },
    {
      text: 'Link to the wiki. ',
      color: '0000FF',
      link: 'https://github.com/prawnpdf/prawn/wiki'
    },
    {
      text: 'Link to a local file. ',
      color: '0000FF',
      local: './local_file.txt'
    }
  ]

  formatted_text_box(
    [
      { text: 'Just your regular' },
      { text: ' text_box ', font: 'Courier' },
      {
        text: 'with some additional formatting options added to the mix.',
        color: [50, 100, 0, 0], styles: [:italic]
      }
    ],
    at: [100, 100], width: 200, height: 100
  )
end