File: right_to_left_text.rb

package info (click to toggle)
ruby-prawn 1.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,936 kB
  • ctags: 802
  • sloc: ruby: 13,906; sh: 43; makefile: 15
file content (43 lines) | stat: -rw-r--r-- 2,253 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
# encoding: utf-8
#
# Prawn can be used with right-to-left text. The direction can be set
# document-wide, on particular text, or on a text-box. Setting the direction to
# <code>:rtl</code> automatically changes the default alignment to
# <code>:right</code>
#
# You can even override direction on an individual fragment. The one caveat is
# that two fragments going against the main direction cannot be placed next to
# each other without appearing in the wrong order.
#
require File.expand_path(File.join(File.dirname(__FILE__),
                                   %w[.. example_helper]))

filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::ManualBuilder::Example.generate(filename) do
  # set the direction document-wide
  self.text_direction = :rtl

  font("/usr/share/fonts/truetype/arphic-gkai00mp/gkai00mp.ttf", :size => 16) do
    long_text = "写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事写个小"
    text long_text
    move_down 20

    text "You can override the document direction.", :direction => :ltr
    move_down 20

    formatted_text [{ :text => "更可怕的是,同质化竞争对手可以按照" },
                    { :text => "URL", :direction => :ltr },
                    { :text => "中后面这个" },
                    { :text => "ID",  :direction => :ltr },
                    { :text => "来遍历您的" },
                    { :text => "DB",  :direction => :ltr },
                    { :text => "中的内容,写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事,这样的话,你就非常被动了。" }]
    move_down 20

    formatted_text [{ :text => "更可怕的是,同质化竞争对手可以按照" },
                    { :text => "this",  :direction => :ltr },
                    { :text => "won't", :direction => :ltr, :size => 24 },
                    { :text => "work",  :direction => :ltr },
                    { :text => "中的内容,写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事" }]
  end
end