prawn-core 0.5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +340 -0
- data/LICENSE +56 -0
- data/README +121 -0
- data/Rakefile +74 -0
- data/data/encodings/win_ansi.txt +29 -0
- data/data/fonts/Action Man.dfont +0 -0
- data/data/fonts/Activa.ttf +0 -0
- data/data/fonts/Chalkboard.ttf +0 -0
- data/data/fonts/Courier-Bold.afm +342 -0
- data/data/fonts/Courier-BoldOblique.afm +342 -0
- data/data/fonts/Courier-Oblique.afm +342 -0
- data/data/fonts/Courier.afm +342 -0
- data/data/fonts/DejaVuSans.ttf +0 -0
- data/data/fonts/Dustismo_Roman.ttf +0 -0
- data/data/fonts/Helvetica-Bold.afm +2827 -0
- data/data/fonts/Helvetica-BoldOblique.afm +2827 -0
- data/data/fonts/Helvetica-Oblique.afm +3051 -0
- data/data/fonts/Helvetica.afm +3051 -0
- data/data/fonts/MustRead.html +19 -0
- data/data/fonts/Symbol.afm +213 -0
- data/data/fonts/Times-Bold.afm +2588 -0
- data/data/fonts/Times-BoldItalic.afm +2384 -0
- data/data/fonts/Times-Italic.afm +2667 -0
- data/data/fonts/Times-Roman.afm +2419 -0
- data/data/fonts/ZapfDingbats.afm +225 -0
- data/data/fonts/comicsans.ttf +0 -0
- data/data/fonts/gkai00mp.ttf +0 -0
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.dat +0 -0
- data/data/images/16bit.png +0 -0
- data/data/images/arrow.png +0 -0
- data/data/images/arrow2.png +0 -0
- data/data/images/barcode_issue.png +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/dice.png +0 -0
- data/data/images/dice_interlaced.png +0 -0
- data/data/images/fractal.jpg +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.dat +0 -0
- data/data/images/page_white_text.png +0 -0
- data/data/images/pigs.jpg +0 -0
- data/data/images/rails.dat +0 -0
- data/data/images/rails.png +0 -0
- data/data/images/ruport.png +0 -0
- data/data/images/ruport_data.dat +0 -0
- data/data/images/ruport_transparent.png +0 -0
- data/data/images/ruport_type0.png +0 -0
- data/data/images/stef.jpg +0 -0
- data/data/images/tru256.bmp +0 -0
- data/data/images/web-links.dat +1 -0
- data/data/images/web-links.png +0 -0
- data/data/shift_jis_text.txt +1 -0
- data/examples/bounding_box/bounding_boxes.rb +44 -0
- data/examples/bounding_box/russian_boxes.rb +37 -0
- data/examples/column_box/column_box_example.rb +44 -0
- data/examples/general/background.rb +20 -0
- data/examples/general/canvas.rb +16 -0
- data/examples/general/measurement_units.rb +52 -0
- data/examples/general/metadata-info.rb +17 -0
- data/examples/general/multi_page_layout.rb +17 -0
- data/examples/general/page_geometry.rb +32 -0
- data/examples/graphics/basic_images.rb +24 -0
- data/examples/graphics/cmyk.rb +13 -0
- data/examples/graphics/curves.rb +12 -0
- data/examples/graphics/hexagon.rb +14 -0
- data/examples/graphics/image_fit.rb +16 -0
- data/examples/graphics/image_flow.rb +38 -0
- data/examples/graphics/image_position.rb +18 -0
- data/examples/graphics/line.rb +33 -0
- data/examples/graphics/png_types.rb +23 -0
- data/examples/graphics/polygons.rb +17 -0
- data/examples/graphics/remote_images.rb +12 -0
- data/examples/graphics/ruport_style_helpers.rb +20 -0
- data/examples/graphics/stroke_bounds.rb +21 -0
- data/examples/m17n/chinese_text_wrapping.rb +20 -0
- data/examples/m17n/euro.rb +16 -0
- data/examples/m17n/sjis.rb +29 -0
- data/examples/m17n/utf8.rb +14 -0
- data/examples/m17n/win_ansi_charset.rb +55 -0
- data/examples/text/alignment.rb +19 -0
- data/examples/text/dfont.rb +49 -0
- data/examples/text/family_based_styling.rb +25 -0
- data/examples/text/font_calculations.rb +92 -0
- data/examples/text/font_size.rb +34 -0
- data/examples/text/kerning.rb +31 -0
- data/examples/text/simple_text.rb +18 -0
- data/examples/text/simple_text_ttf.rb +18 -0
- data/examples/text/span.rb +30 -0
- data/examples/text/text_box.rb +26 -0
- data/examples/text/text_flow.rb +68 -0
- data/lib/prawn/compatibility.rb +38 -0
- data/lib/prawn/core.rb +79 -0
- data/lib/prawn/document.rb +399 -0
- data/lib/prawn/document/annotations.rb +63 -0
- data/lib/prawn/document/bounding_box.rb +377 -0
- data/lib/prawn/document/column_box.rb +89 -0
- data/lib/prawn/document/destinations.rb +81 -0
- data/lib/prawn/document/internals.rb +133 -0
- data/lib/prawn/document/page_geometry.rb +149 -0
- data/lib/prawn/document/span.rb +55 -0
- data/lib/prawn/document/text.rb +186 -0
- data/lib/prawn/document/text/box.rb +83 -0
- data/lib/prawn/document/text/wrapping.rb +59 -0
- data/lib/prawn/encoding.rb +121 -0
- data/lib/prawn/errors.rb +49 -0
- data/lib/prawn/font.rb +292 -0
- data/lib/prawn/font/afm.rb +202 -0
- data/lib/prawn/font/dfont.rb +31 -0
- data/lib/prawn/font/ttf.rb +327 -0
- data/lib/prawn/graphics.rb +257 -0
- data/lib/prawn/graphics/color.rb +141 -0
- data/lib/prawn/images.rb +339 -0
- data/lib/prawn/images/jpg.rb +45 -0
- data/lib/prawn/images/png.rb +217 -0
- data/lib/prawn/literal_string.rb +14 -0
- data/lib/prawn/measurement_extensions.rb +46 -0
- data/lib/prawn/measurements.rb +71 -0
- data/lib/prawn/name_tree.rb +165 -0
- data/lib/prawn/pdf_object.rb +77 -0
- data/lib/prawn/reference.rb +59 -0
- data/spec/annotations_spec.rb +90 -0
- data/spec/bounding_box_spec.rb +141 -0
- data/spec/destinations_spec.rb +15 -0
- data/spec/document_spec.rb +178 -0
- data/spec/font_spec.rb +274 -0
- data/spec/graphics_spec.rb +209 -0
- data/spec/images_spec.rb +79 -0
- data/spec/jpg_spec.rb +25 -0
- data/spec/measurement_units_spec.rb +23 -0
- data/spec/name_tree_spec.rb +103 -0
- data/spec/pdf_object_spec.rb +117 -0
- data/spec/png_spec.rb +236 -0
- data/spec/reference_spec.rb +42 -0
- data/spec/span_spec.rb +45 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/text_box_spec.rb +83 -0
- data/spec/text_spec.rb +178 -0
- data/vendor/pdf-inspector/README +18 -0
- data/vendor/pdf-inspector/lib/pdf/inspector.rb +25 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +80 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/page.rb +16 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/text.rb +31 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +19 -0
- data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
- data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
- data/vendor/ttfunk/example.rb +45 -0
- data/vendor/ttfunk/lib/ttfunk.rb +102 -0
- data/vendor/ttfunk/lib/ttfunk/directory.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +88 -0
- data/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +69 -0
- data/vendor/ttfunk/lib/ttfunk/reader.rb +44 -0
- data/vendor/ttfunk/lib/ttfunk/resource_file.rb +78 -0
- data/vendor/ttfunk/lib/ttfunk/subset.rb +18 -0
- data/vendor/ttfunk/lib/ttfunk/subset/base.rb +141 -0
- data/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +46 -0
- data/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +48 -0
- data/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +63 -0
- data/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +51 -0
- data/vendor/ttfunk/lib/ttfunk/subset_collection.rb +72 -0
- data/vendor/ttfunk/lib/ttfunk/table.rb +46 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +34 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +54 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +126 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +79 -0
- data/vendor/ttfunk/lib/ttfunk/table/glyf.rb +64 -0
- data/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +81 -0
- data/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +37 -0
- data/vendor/ttfunk/lib/ttfunk/table/head.rb +44 -0
- data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +41 -0
- data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +47 -0
- data/vendor/ttfunk/lib/ttfunk/table/kern.rb +79 -0
- data/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +62 -0
- data/vendor/ttfunk/lib/ttfunk/table/loca.rb +43 -0
- data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +40 -0
- data/vendor/ttfunk/lib/ttfunk/table/name.rb +119 -0
- data/vendor/ttfunk/lib/ttfunk/table/os2.rb +78 -0
- data/vendor/ttfunk/lib/ttfunk/table/post.rb +91 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +43 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +35 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +23 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/table/simple.rb +14 -0
- metadata +245 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# FIXME: Introducing TTFunk into Prawn broke this example and a cooresponding
|
4
|
+
# test. Ticket: #139
|
5
|
+
#
|
6
|
+
# Tests passing non utf-8 data into Prawns text function. Should
|
7
|
+
# be transparently converted to utf-8 and rendered as usual.
|
8
|
+
#
|
9
|
+
# NOTE: only works on ruby1.9 compatible VMs, and requires the current
|
10
|
+
# font to include japanese glyphs. On 1.8.x comaptible VMs, an exception
|
11
|
+
# will be raised.
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
14
|
+
require "prawn/core"
|
15
|
+
|
16
|
+
begin
|
17
|
+
ruby_19 do
|
18
|
+
datafile = File.join(File.dirname(__FILE__), "..", "..", "data",
|
19
|
+
"shift_jis_text.txt")
|
20
|
+
sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
|
21
|
+
|
22
|
+
Prawn::Document.generate("sjis.pdf") do
|
23
|
+
font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
|
24
|
+
text sjis_str
|
25
|
+
end
|
26
|
+
end
|
27
|
+
rescue
|
28
|
+
puts "\n FIXME: SJIS Broken due to TTFunk integration."
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Shows that Prawn works out of the box with UTF-8 text, so long as you use
|
4
|
+
# a TTF file with the necessary glyphs for your content.
|
5
|
+
#
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
7
|
+
require "prawn/core"
|
8
|
+
|
9
|
+
Prawn::Document.generate("utf8.pdf") do
|
10
|
+
font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
|
11
|
+
text "ὕαλον ϕαγεῖν δύναμαι· τοῦτο οὔ με βλάπτει." * 20
|
12
|
+
end
|
13
|
+
|
14
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Prints a list of all of the glyphs that can be rendered by Adobe's built
|
4
|
+
# in fonts, along with their character widths and WinAnsi codes. Be sure
|
5
|
+
# to pass these glyphs as UTF-8, and Prawn will transcode them for you.
|
6
|
+
#
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
8
|
+
require 'prawn/core'
|
9
|
+
|
10
|
+
FONT_SIZE = 9.5
|
11
|
+
|
12
|
+
Prawn::Document.generate("win-ansi.pdf") do
|
13
|
+
@skip_encoding = true
|
14
|
+
|
15
|
+
x = 0
|
16
|
+
y = bounds.top
|
17
|
+
|
18
|
+
fields = [[20, :right], [8, :left], [12, :center], [30, :right], [8, :left], [0, :left]]
|
19
|
+
|
20
|
+
font "Helvetica", :size => FONT_SIZE
|
21
|
+
|
22
|
+
Prawn::Encoding::WinAnsi::CHARACTERS.each_with_index do |name, index|
|
23
|
+
next if name == ".notdef"
|
24
|
+
y -= FONT_SIZE
|
25
|
+
|
26
|
+
if y < FONT_SIZE
|
27
|
+
y = bounds.top - FONT_SIZE
|
28
|
+
x += 170
|
29
|
+
end
|
30
|
+
|
31
|
+
code = "%d." % index
|
32
|
+
char = index.chr
|
33
|
+
|
34
|
+
width = 1000 * width_of(char, :size => FONT_SIZE) / FONT_SIZE
|
35
|
+
size = "%d" % width
|
36
|
+
|
37
|
+
data = [code, nil, char, size, nil, name]
|
38
|
+
dx = x
|
39
|
+
fields.zip(data).each do |(total_width, align), field|
|
40
|
+
if field
|
41
|
+
width = width_of(field, :size => FONT_SIZE)
|
42
|
+
|
43
|
+
case align
|
44
|
+
when :left then offset = 0
|
45
|
+
when :right then offset = total_width - width
|
46
|
+
when :center then offset = (total_width - width)/2
|
47
|
+
end
|
48
|
+
|
49
|
+
text(field, :at => [dx + offset, y])
|
50
|
+
end
|
51
|
+
|
52
|
+
dx += total_width
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# This example demonstrates usage of Document#text with the :align option.
|
4
|
+
# Available options are :left, :right, and :center, with :left as default.
|
5
|
+
#
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
7
|
+
require "prawn/core"
|
8
|
+
|
9
|
+
Prawn::Document.generate("alignment.pdf") do
|
10
|
+
text "This text should be left aligned"
|
11
|
+
text "This text should be centered", :align => :center
|
12
|
+
text "This text should be right aligned", :align => :right
|
13
|
+
|
14
|
+
pad(20) { text "This is Flowing from the left. " * 20 }
|
15
|
+
|
16
|
+
pad(20) { text "This is Flowing from the center. " * 20, :align => :center }
|
17
|
+
|
18
|
+
pad(20) { text "This is Flowing from the right. " * 20, :align => :right }
|
19
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
|
+
require "prawn/core"
|
5
|
+
|
6
|
+
DFONT_FILE = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
|
7
|
+
puts "There are #{Prawn::Font::DFont.font_count(DFONT_FILE)} fonts in #{DFONT_FILE}:"
|
8
|
+
Prawn::Font::DFont.named_fonts(DFONT_FILE).each do |name|
|
9
|
+
puts "* #{name}"
|
10
|
+
end
|
11
|
+
|
12
|
+
puts
|
13
|
+
puts "generating sample document in 'dfont.pdf'..."
|
14
|
+
|
15
|
+
Prawn::Document.generate "dfont.pdf" do
|
16
|
+
fill_color "0000ff"
|
17
|
+
|
18
|
+
font DFONT_FILE, :font => "ActionMan-Bold", :size => 24
|
19
|
+
text "Introducing Action Man!"
|
20
|
+
|
21
|
+
move_text_position 24
|
22
|
+
|
23
|
+
font_families["Action Man"] = {
|
24
|
+
:normal => { :file => DFONT_FILE, :font => "ActionMan" },
|
25
|
+
:bold => { :file => DFONT_FILE, :font => "ActionMan-Bold" },
|
26
|
+
:italic => { :file => DFONT_FILE, :font => "ActionMan-Italic" },
|
27
|
+
:bold_italic => { :file => DFONT_FILE, :font => "ActionMan-BoldItalic" }
|
28
|
+
}
|
29
|
+
|
30
|
+
font "Action Man", :size => 16
|
31
|
+
text "Action Man is feeling normal here."
|
32
|
+
|
33
|
+
move_text_position 16
|
34
|
+
|
35
|
+
font "Action Man", :style => :bold, :size => 16
|
36
|
+
text "Action Man is feeling bold here!"
|
37
|
+
|
38
|
+
move_text_position 16
|
39
|
+
|
40
|
+
font "Action Man", :style => :italic, :size => 16
|
41
|
+
text "Here, we see Action Man feeling italicized. Slick!"
|
42
|
+
|
43
|
+
move_text_position 16
|
44
|
+
|
45
|
+
font "Action Man", :style => :bold_italic, :size => 16
|
46
|
+
text "Lastly, we observe Mr. Action Man being bold AND italicized. Excellent!"
|
47
|
+
end
|
48
|
+
|
49
|
+
puts "done"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# This example demonstrates using the :style option for Document#text.
|
4
|
+
# If you are working with TTF fonts, you'll want to check out the
|
5
|
+
# documentation for Document#font_families and register your fonts with it.
|
6
|
+
#
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
8
|
+
require "prawn/core"
|
9
|
+
|
10
|
+
Prawn::Document.generate("family_style.pdf") do
|
11
|
+
["Courier","Helvetica","Times-Roman"].each do |f|
|
12
|
+
[:bold,:bold_italic,:italic,:normal].each do |s|
|
13
|
+
font f, :style => s
|
14
|
+
text "I'm writing in #{f} (#{s})"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
font "Helvetica"
|
19
|
+
|
20
|
+
text "Normal"
|
21
|
+
text "Bold", :style => :bold
|
22
|
+
text "Bold Italic", :style => :bold_italic
|
23
|
+
text "Italic", :style => :italic
|
24
|
+
text "Normal"
|
25
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# This example is a demonstration of how Prawn does its text positioning,
|
4
|
+
# meant to assist those that need to do advanced positioning calculations.
|
5
|
+
# Run the example for a clearer picture of how things work
|
6
|
+
#
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
8
|
+
require 'prawn/core'
|
9
|
+
|
10
|
+
Prawn::Document.generate('font_calculations.pdf') do
|
11
|
+
|
12
|
+
def demonstration
|
13
|
+
font_size 12
|
14
|
+
move_down 10
|
15
|
+
|
16
|
+
stroke_horizontal_rule
|
17
|
+
|
18
|
+
text "When using flowing text, Prawn will position text\n" +
|
19
|
+
"starting font.ascender below the baseline, and leave\n" +
|
20
|
+
"the y-cursor at the baseline of the next line of text"
|
21
|
+
|
22
|
+
stroke_horizontal_rule
|
23
|
+
|
24
|
+
move_down 20
|
25
|
+
|
26
|
+
bl = y - bounds.absolute_bottom
|
27
|
+
|
28
|
+
stroke_horizontal_rule
|
29
|
+
text "When using text positioned with :at, the baseline is used", :at => [0, bl]
|
30
|
+
|
31
|
+
text "(and the Y-cursor is not moved)", :at => [350, bl]
|
32
|
+
|
33
|
+
colors = { :ascender => "ff0000",
|
34
|
+
:descender => "00ff00",
|
35
|
+
:line_gap => "0000ff",
|
36
|
+
:font_height => "005500" }
|
37
|
+
|
38
|
+
|
39
|
+
pad(20) do
|
40
|
+
text "Calculations Demo", :size => 16
|
41
|
+
end
|
42
|
+
|
43
|
+
fill_color colors[:ascender]
|
44
|
+
text "ASCENDER"
|
45
|
+
|
46
|
+
fill_color colors[:descender]
|
47
|
+
text "DESCENDER"
|
48
|
+
|
49
|
+
fill_color colors[:line_gap]
|
50
|
+
text "LINEGAP"
|
51
|
+
|
52
|
+
fill_color colors[:font_height]
|
53
|
+
text "FONT_HEIGHT"
|
54
|
+
|
55
|
+
fill_color "000000"
|
56
|
+
font_size 16
|
57
|
+
|
58
|
+
move_down 40
|
59
|
+
|
60
|
+
bl = y - bounds.absolute_bottom
|
61
|
+
text "The quick brown fox jumps over the lazy dog.", :at => [0, bl]
|
62
|
+
|
63
|
+
stroke_color colors[:ascender]
|
64
|
+
stroke_line [0, bl], [0, bl + font.ascender]
|
65
|
+
stroke_line [0, bl + font.ascender], [bounds.width, bl + font.ascender]
|
66
|
+
|
67
|
+
stroke_color colors[:descender]
|
68
|
+
stroke_line [0,bl], [0, bl + font.descender]
|
69
|
+
stroke_line [0, bl + font.descender], [bounds.width, bl + font.descender]
|
70
|
+
|
71
|
+
stroke_color colors[:line_gap]
|
72
|
+
stroke_line [0, bl + font.descender], [0,bl + font.descender - font.line_gap]
|
73
|
+
stroke_line [0, bl + font.descender - font.line_gap],
|
74
|
+
[bounds.width,bl + font.descender - font.line_gap]
|
75
|
+
|
76
|
+
stroke_color colors[:font_height]
|
77
|
+
stroke_line [bounds.width, bl + font.ascender],
|
78
|
+
[bounds.width, bl + font.descender - font.line_gap]
|
79
|
+
|
80
|
+
stroke_color "000000"
|
81
|
+
fill_color "000000"
|
82
|
+
end
|
83
|
+
|
84
|
+
text "Using AFM", :size => 20
|
85
|
+
demonstration
|
86
|
+
|
87
|
+
move_down 75
|
88
|
+
font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
|
89
|
+
text "Using TTF", :size => 20
|
90
|
+
demonstration
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# This example shows the many ways of setting font sizes in Prawn
|
4
|
+
#
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
6
|
+
require "prawn/core"
|
7
|
+
|
8
|
+
Prawn::Document.generate "font_size.pdf", :page_size => "A4" do
|
9
|
+
|
10
|
+
# Explicit global changes
|
11
|
+
font 'Helvetica'
|
12
|
+
self.font_size = 16
|
13
|
+
|
14
|
+
text 'Font at 16 point'
|
15
|
+
|
16
|
+
# Transactional changes rolled back after block exit
|
17
|
+
font_size 9 do
|
18
|
+
text 'Font at 9 point'
|
19
|
+
# single line changes, not persisted.
|
20
|
+
text 'Font at manual override 20 point', :size => 20
|
21
|
+
text 'Font at 9 point'
|
22
|
+
end
|
23
|
+
|
24
|
+
# Transactional changes rolled back after block exit on full fonts.
|
25
|
+
font("Times-Roman", :style => :italic, :size => 12) do
|
26
|
+
text "Font in times at 12"
|
27
|
+
font_size(16) { text "Font in Times at 16" }
|
28
|
+
end
|
29
|
+
|
30
|
+
text 'Font at 16 point'
|
31
|
+
|
32
|
+
font "Courier", :size => 40
|
33
|
+
text "40 pt!"
|
34
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Demonstration of enabling and disabling kerning support
|
4
|
+
#
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
6
|
+
require "prawn/core"
|
7
|
+
|
8
|
+
Prawn::Document.generate "kerning.pdf" do
|
9
|
+
text "To kern?", :at => [200,720], :size => 24, :kerning => true
|
10
|
+
text "To not kern?", :at => [200,690], :size => 24, :kerning => false
|
11
|
+
|
12
|
+
move_down 100
|
13
|
+
|
14
|
+
pad(30) do
|
15
|
+
text "To kern and wrap. " * 5, :size => 24, :kerning => true
|
16
|
+
end
|
17
|
+
|
18
|
+
text "To not kern and wrap. " * 5, :size => 24, :kerning => false
|
19
|
+
|
20
|
+
font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
|
21
|
+
|
22
|
+
text "To kern?", :at => [200,660], :size => 24, :kerning => true
|
23
|
+
text "To not kern?", :at => [200,630], :size => 24, :kerning => false
|
24
|
+
|
25
|
+
pad(30) do
|
26
|
+
text "To kern and wrap. " * 5, :size => 24, :kerning => true
|
27
|
+
end
|
28
|
+
|
29
|
+
text "To not kern and wrap. " * 5, :size => 24, :kerning => false
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# An early example of basic text generation at absolute positions.
|
4
|
+
# Mostly kept for nostalgia.
|
5
|
+
#
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
7
|
+
require "prawn/core"
|
8
|
+
|
9
|
+
Prawn::Document.generate "simple_text.pdf" do
|
10
|
+
fill_color "0000ff"
|
11
|
+
text "Hello World", :at => [200,420], :size => 32, :rotate => 45
|
12
|
+
font "Times-Roman"
|
13
|
+
fill_color "ff0000"
|
14
|
+
text "Using Another Font", :at => [5,5]
|
15
|
+
start_new_page
|
16
|
+
font "Courier"
|
17
|
+
text "Goodbye World", :at => [288,50]
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# An early example of TTF font embedding. Mostly kept for nostalgia's sake.
|
4
|
+
#
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
6
|
+
require "prawn/core"
|
7
|
+
|
8
|
+
Prawn::Document.generate "simple_text_ttf.pdf" do
|
9
|
+
fill_color "0000ff"
|
10
|
+
font "#{Prawn::BASEDIR}/data/fonts/comicsans.ttf"
|
11
|
+
text "Hello World", :at => [200,720], :size => 32
|
12
|
+
|
13
|
+
font "#{Prawn::BASEDIR}/data/fonts/Chalkboard.ttf"
|
14
|
+
|
15
|
+
pad(20) do
|
16
|
+
text "This is chalkboard wrapping " * 20
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Demonstration of Document#span, which is used for generating flowing
|
4
|
+
# columns of text.
|
5
|
+
#
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
7
|
+
require "prawn/core"
|
8
|
+
|
9
|
+
Prawn::Document.generate("span.pdf") do
|
10
|
+
|
11
|
+
# Spans will typically be used outside of bounding boxes as a way to build
|
12
|
+
# single columns of flowing text that span across pages.
|
13
|
+
#
|
14
|
+
span(350, :position => :center) do
|
15
|
+
text "Here's some centered text in a 350 point column. " * 100
|
16
|
+
end
|
17
|
+
|
18
|
+
# Spans are not really compatible with bounding boxes because they break
|
19
|
+
# the nesting chain and also may position text outside of the bounding box
|
20
|
+
# boundaries, but sometimes you may wish to use them anyway for convenience
|
21
|
+
# Here's an example of how to do that dynamically.
|
22
|
+
#
|
23
|
+
bounding_box([50,300], :width => 400) do
|
24
|
+
text "Here's some default bounding box text. " * 10
|
25
|
+
span(bounds.width,
|
26
|
+
:position => bounds.absolute_left - margin_box.absolute_left) do
|
27
|
+
text "The rain in spain falls mainly on the plains. " * 300
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# A text box is positioned by a top-left corner, width, and height and is
|
4
|
+
# essentially an invisible rectangle that the text wil lflow within. If the
|
5
|
+
# text exceeds the boundaries, it is either truncated, replaced with some
|
6
|
+
# ellipses, or set to expand beyond the bottom boundary.
|
7
|
+
#
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
9
|
+
require 'prawn/core'
|
10
|
+
|
11
|
+
Prawn::Document.generate("text_box.pdf") do
|
12
|
+
|
13
|
+
text_box "Oh hai text box. " * 200,
|
14
|
+
:width => 300, :height => font.height * 5,
|
15
|
+
:overflow => :ellipses,
|
16
|
+
:at => [100,bounds.top]
|
17
|
+
|
18
|
+
text_box "Oh hai text box. " * 200,
|
19
|
+
:width => 250, :height => font.height * 10,
|
20
|
+
:overflow => :truncate,
|
21
|
+
:at => [50, 300]
|
22
|
+
|
23
|
+
move_down 20
|
24
|
+
|
25
|
+
text_box "Oh hai text box. " * 100, :overflow => :expand
|
26
|
+
end
|