prawn_oval_text 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README.rdoc +49 -0
- data/Rakefile +27 -0
- data/examples/example_helper.rb +7 -0
- data/examples/text/text_oval.rb +75 -0
- data/lib/prawn_oval_text.rb +2 -0
- data/lib/prawn_oval_text/formatted/oval.rb +147 -0
- data/lib/prawn_oval_text/oval.rb +71 -0
- data/prawn_oval_text.gemspec +27 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/text_oval_spec.rb +187 -0
- metadata +102 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009 Daniel Nelson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= Prawn Oval Text
|
2
|
+
|
3
|
+
Provides capacity for drawing ellipse and circle shaped text.
|
4
|
+
|
5
|
+
= Usage
|
6
|
+
|
7
|
+
require 'prawn/text/oval'
|
8
|
+
|
9
|
+
then
|
10
|
+
|
11
|
+
text_oval(string, options)
|
12
|
+
|
13
|
+
where acceptable options are
|
14
|
+
|
15
|
+
- :width and :height are the width and height of the ellipse, respectively. If they are equal, then the shape is a circle.
|
16
|
+
|
17
|
+
- :at is a two element array denoting the upper left corner of the bounding box around the ellipse.
|
18
|
+
|
19
|
+
- :center is a two element array denoting the center of the ellipse. If :center is present, then its value overrides that provided by :at.
|
20
|
+
|
21
|
+
- :overflow is :truncate, :shrink_to_fit, or :ellipses, denoting the behavior when the amount of text exceeds the available space. Defaults to :truncate. If :shrink_to_fit, then the font size is decreased
|
22
|
+
|
23
|
+
- :crop denotes the space between top of the oval and the first line. It is used to push the starting line lower in the circle when the combination of oval size and font size result in only a few characters being displayable on the very top line.
|
24
|
+
|
25
|
+
- :leading is the amount of space between lines. Defaults to 0.
|
26
|
+
|
27
|
+
- :kerning is a boolean. Defaults to true. Note that if kerning is on, it will result in slower width computations
|
28
|
+
|
29
|
+
- :align is :center, :left, or :right. Defaults to :center.
|
30
|
+
|
31
|
+
- :min_font_size is the minimum font-size to use when :overflow is set to :shrink_to_fit (ie: the font size will not be reduced to less than this value, even if it means that some text will be cut off). Defaults to 5
|
32
|
+
|
33
|
+
= Example
|
34
|
+
|
35
|
+
{http://mindlev.wordpress.com/files/2009/10/oval_text.pdf}[http://mindlev.wordpress.com/files/2009/10/oval_text.pdf]
|
36
|
+
|
37
|
+
= Changelog
|
38
|
+
|
39
|
+
0.3 - added shrink_to_fit overflow option. fixed so can work with new lines in the text
|
40
|
+
|
41
|
+
0.3.2 - changed default kerning to true to match Prawn default
|
42
|
+
|
43
|
+
0.4.0 - rewrote as descendent of newly rewritten Prawn::Text::Box. notice change of oval_text method to text_oval
|
44
|
+
|
45
|
+
0.10.0 - updated to reflect changes in Prawn::Text developer API
|
46
|
+
|
47
|
+
0.10.2 - added :justify as align option
|
48
|
+
|
49
|
+
2011-02-14 - incorporated Bundler. I must have been linked to master when I produced this (now avoided by use of Bundler) because this was failing at Prawn 0.10.2 because @character_spacing was not set by Text::Box. updated license to MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
3
|
+
Bundler.setup
|
4
|
+
|
5
|
+
require "rake"
|
6
|
+
require "rake/testtask"
|
7
|
+
|
8
|
+
task :default => [:test]
|
9
|
+
|
10
|
+
desc "Run all tests, test-spec, mocha, and pdf-reader required"
|
11
|
+
Rake::TestTask.new do |test|
|
12
|
+
# test.ruby_opts << "-w" # .should == true triggers a lot of warnings
|
13
|
+
test.libs << "spec"
|
14
|
+
test.test_files = Dir[ "spec/*_spec.rb" ]
|
15
|
+
test.verbose = true
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "run all examples"
|
19
|
+
task :examples do
|
20
|
+
mkdir_p "output"
|
21
|
+
examples = Dir["examples/**/*.rb"]
|
22
|
+
t = Time.now
|
23
|
+
puts "Running Examples"
|
24
|
+
examples.each { |file| `ruby -Ilib #{file}` }
|
25
|
+
puts "Ran in #{Time.now - t} s"
|
26
|
+
`mv *.pdf output`
|
27
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
4
|
+
%w[.. example_helper]))
|
5
|
+
|
6
|
+
Prawn::Document.generate("text_oval.pdf") do
|
7
|
+
def get_string(i, j)
|
8
|
+
case i
|
9
|
+
when 0
|
10
|
+
# gqpy to show descender relative to outer circle
|
11
|
+
text = "this is left gqpy " * 20
|
12
|
+
when 1
|
13
|
+
if j == 2
|
14
|
+
text = "this is justify gqpy " * 20
|
15
|
+
else
|
16
|
+
text = "this is center gqpy " * 20
|
17
|
+
end
|
18
|
+
when 2
|
19
|
+
text = "this is right gqpy " * 20
|
20
|
+
end
|
21
|
+
|
22
|
+
case j
|
23
|
+
when 0
|
24
|
+
text.split(" ").slice(0..47).join(" ")
|
25
|
+
when 3
|
26
|
+
text.delete(" ").insert(51, "\n\n")
|
27
|
+
else
|
28
|
+
text
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_options(i, j)
|
33
|
+
options = {
|
34
|
+
:width => bounds.width * 0.3,
|
35
|
+
:height => bounds.width * 0.3,
|
36
|
+
:overflow => :ellipses,
|
37
|
+
:center => [0, 0],
|
38
|
+
:align => :left,
|
39
|
+
:document => self
|
40
|
+
}
|
41
|
+
|
42
|
+
case i
|
43
|
+
when 0
|
44
|
+
options[:valign] = :top if j == 0
|
45
|
+
when 1
|
46
|
+
options[:align] = :center
|
47
|
+
options[:valign] = :center if j == 0
|
48
|
+
options[:align] = :justify if j == 2
|
49
|
+
when 2
|
50
|
+
options[:align] = :right
|
51
|
+
options[:valign] = :bottom if j == 0
|
52
|
+
end
|
53
|
+
|
54
|
+
case j
|
55
|
+
when 1
|
56
|
+
options[:overflow] = :shrink_to_fit
|
57
|
+
when 2
|
58
|
+
options[:leading] = font.height * 0.5
|
59
|
+
options[:overflow] = :truncate
|
60
|
+
end
|
61
|
+
options
|
62
|
+
end
|
63
|
+
|
64
|
+
stroke_color("555555")
|
65
|
+
3.times do |i|
|
66
|
+
4.times do |j|
|
67
|
+
options = get_options(i, j)
|
68
|
+
options[:center][0] = bounds.left + options[:width] * 0.5 + (bounds.width - options[:width]) * 0.5 * i
|
69
|
+
options[:center][1] = bounds.top - options[:height] * 0.5 - (bounds.height - options[:height]) * 0.33 * j
|
70
|
+
oval = Prawn::Text::Oval.new(get_string(i, j), options)
|
71
|
+
stroke_circle(options[:center], options[:width] / 2)
|
72
|
+
oval.render
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# prawn_oval_text/formatted/oval.rb : Implements text ovals
|
4
|
+
#
|
5
|
+
# Copyright October 2009-2011, Daniel Nelson. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
+
|
9
|
+
module Prawn
|
10
|
+
module Text
|
11
|
+
module Formatted
|
12
|
+
|
13
|
+
def formatted_text_oval(text, options={})
|
14
|
+
Text::Formatted::Oval.new(text, options.merge(:document => self)).render
|
15
|
+
end
|
16
|
+
|
17
|
+
# Provides oval shaped text capacity
|
18
|
+
#
|
19
|
+
class Oval < Prawn::Text::Formatted::Box
|
20
|
+
|
21
|
+
DEFAULT_CROP_INCREMENT = 5
|
22
|
+
|
23
|
+
def valid_options
|
24
|
+
super.concat([:crop, :center])
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(formatted_text, options={})
|
28
|
+
|
29
|
+
super(formatted_text, options)
|
30
|
+
|
31
|
+
@horizontal_radius = options[:width] * 0.5
|
32
|
+
@vertical_radius = options[:height] * 0.5
|
33
|
+
@height = options[:height]
|
34
|
+
@center = [@at[0] + @horizontal_radius,
|
35
|
+
@at[1] - @vertical_radius]
|
36
|
+
@center = options[:center] if options[:center]
|
37
|
+
@at = [@center[0] - @horizontal_radius,
|
38
|
+
@center[1] + @vertical_radius]
|
39
|
+
@original_x = @at[0]
|
40
|
+
@align = options[:align] || :center
|
41
|
+
@vertical_align = :top
|
42
|
+
|
43
|
+
# the crop lets us start printing text some distance below the
|
44
|
+
# top of the ellipse, otherwise, there may not be enough space
|
45
|
+
# to display much text, which looks bad
|
46
|
+
crop = [options[:crop] || 0, @document.font.descender].max
|
47
|
+
increase_crop(crop)
|
48
|
+
end
|
49
|
+
|
50
|
+
# def height
|
51
|
+
# @vertical_radius * 2
|
52
|
+
# end
|
53
|
+
|
54
|
+
def available_width
|
55
|
+
@width = compute_max_line_width(@horizontal_radius, @vertical_radius, width_limiting_y)
|
56
|
+
@at[0] = @original_x + @horizontal_radius - @width * 0.5
|
57
|
+
[@width, @line_height].max
|
58
|
+
end
|
59
|
+
|
60
|
+
def render(flags={})
|
61
|
+
@oval_line_height = @document.font.height
|
62
|
+
@oval_descender = @document.font.descender
|
63
|
+
@oval_ascender = @document.font.ascender
|
64
|
+
@oval_line_gap = @document.font.line_gap
|
65
|
+
# begin
|
66
|
+
# results = super(flags)
|
67
|
+
super(flags)
|
68
|
+
# rescue Prawn::Errors::CannotFit
|
69
|
+
# if @baseline_y.abs < @height - @oval_line_height
|
70
|
+
# increase_crop
|
71
|
+
# retry
|
72
|
+
# end
|
73
|
+
# results = []
|
74
|
+
# end
|
75
|
+
# results
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
# Override because oval text is more succeptable to change in the lower
|
81
|
+
# part of the circle (due to ever diminishing space), so we want a
|
82
|
+
# finer-grained font reduction
|
83
|
+
#
|
84
|
+
def shrink_to_fit(text)
|
85
|
+
wrap(text)
|
86
|
+
until @everything_printed || @font_size <= @min_font_size
|
87
|
+
@font_size = [@font_size - 0.3, @min_font_size].max
|
88
|
+
@document.font_size = @font_size
|
89
|
+
wrap(text)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Override because the #word_spacing_for_this_line in
|
94
|
+
# Prawn::Core::Text::Formatted::Wrap recomputes available_width, even
|
95
|
+
# though it has already moved on to the next line
|
96
|
+
#
|
97
|
+
def word_spacing_for_this_line
|
98
|
+
if @align == :justify &&
|
99
|
+
@line_wrap.space_count > 0 &&
|
100
|
+
!@line_wrap.paragraph_finished?
|
101
|
+
(@width - @line_wrap.width) / @line_wrap.space_count
|
102
|
+
else
|
103
|
+
0
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def increase_crop(amount=DEFAULT_CROP_INCREMENT)
|
108
|
+
@crop ||= 0
|
109
|
+
@crop += amount
|
110
|
+
@at[1] -= amount
|
111
|
+
@height -= amount + 1
|
112
|
+
end
|
113
|
+
|
114
|
+
def oval_baseline_y
|
115
|
+
if @baseline_y == 0
|
116
|
+
-@crop - @oval_ascender
|
117
|
+
else
|
118
|
+
@baseline_y - @crop - (@oval_line_height + @leading)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Width_limiting_y is the value of y that will be used to compute x;
|
123
|
+
# whereas, y is the vertical position of the text baseline
|
124
|
+
def width_limiting_y
|
125
|
+
return (oval_baseline_y + @vertical_radius + @oval_ascender) if above_x_axis?
|
126
|
+
(oval_baseline_y + @vertical_radius - @oval_descender)
|
127
|
+
end
|
128
|
+
|
129
|
+
# When we are above the x-axis, the top of the ascender is
|
130
|
+
# limited by the ellipse. When below the y-axis, the bottom
|
131
|
+
# of the descender is limited by the ellipse
|
132
|
+
def above_x_axis?
|
133
|
+
(oval_baseline_y + @vertical_radius).abs > (oval_baseline_y + @vertical_radius - @oval_line_height).abs
|
134
|
+
end
|
135
|
+
|
136
|
+
def compute_max_line_width(a, b, y)
|
137
|
+
# equation of ellipse is x^2 / a^2 + y^2 / b^2 = 1, which
|
138
|
+
# reduces to the following line
|
139
|
+
b_squared = b * b
|
140
|
+
y_squared = [y * y, b_squared].min
|
141
|
+
x = a * Math.sqrt(1 - y_squared / b_squared)
|
142
|
+
2 * x
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# prawn_oval_text/oval.rb : Implements text ovals
|
4
|
+
#
|
5
|
+
# Copyright October 2009-2011, Daniel Nelson. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
+
|
9
|
+
module Prawn
|
10
|
+
module Text
|
11
|
+
# Draws the requested text into an oval. When the text overflows
|
12
|
+
# the oval, you can display ellipses, shrink to fit, or
|
13
|
+
# truncate the text
|
14
|
+
# acceptable options:
|
15
|
+
#
|
16
|
+
# :width and :height are the width and height of the
|
17
|
+
# ellipse, respectively. If they are equal, then the shape
|
18
|
+
# is a circle.
|
19
|
+
#
|
20
|
+
# :at is a two element array denoting the upper left corner
|
21
|
+
# of the bounding box around the ellipse
|
22
|
+
#
|
23
|
+
# :center is a two element array denoting the center of the
|
24
|
+
# ellipse. If :center is present, then its value overrides
|
25
|
+
# that provided by :at
|
26
|
+
#
|
27
|
+
# :overflow is :truncate, :shrink_to_fit, or :ellipses, denoting the
|
28
|
+
# behavior when the amount of text exceeds the available
|
29
|
+
# space. Defaults to :truncate.
|
30
|
+
#
|
31
|
+
# :crop denotes the space between top of the oval and the
|
32
|
+
# first line. It is used to push the starting line lower in
|
33
|
+
# the circle when the combination of oval size and font size
|
34
|
+
# result in only a few characters being displayable on the
|
35
|
+
# very top line.
|
36
|
+
#
|
37
|
+
# :leading is the amount of space between lines. Defaults to 0
|
38
|
+
#
|
39
|
+
# :kerning is a boolean. Defaults to true. Note that if
|
40
|
+
# kerning is on, it will result in slower width
|
41
|
+
# computations
|
42
|
+
#
|
43
|
+
# :align is :center, :left, :right, or :justify. Defaults to :center
|
44
|
+
#
|
45
|
+
# :min_font_size is the minimum font-size to use when
|
46
|
+
# :overflow is set to :shrink_to_fit (ie: the font size
|
47
|
+
# will not be reduced to less than this value, even if it
|
48
|
+
# means that some text will be cut off). Defaults to 5
|
49
|
+
|
50
|
+
# +text+ must be UTF8-encoded.
|
51
|
+
#
|
52
|
+
def text_oval(text, options={})
|
53
|
+
Text::Oval.new(text, options.merge(:document => self)).render
|
54
|
+
end
|
55
|
+
|
56
|
+
# Provides oval shaped text capacity
|
57
|
+
#
|
58
|
+
class Oval < Prawn::Text::Formatted::Oval
|
59
|
+
|
60
|
+
def initialize(string, options={})
|
61
|
+
super([{ :text => string }], options)
|
62
|
+
end
|
63
|
+
|
64
|
+
def render(flags={})
|
65
|
+
leftover = super(flags)
|
66
|
+
leftover.collect { |hash| hash[:text] }.join
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Version numbering: http://wiki.github.com/sandal/prawn/development-roadmap
|
2
|
+
PRAWN_OVAL_TEXT_VERSION = "0.11.1"
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "prawn_oval_text"
|
6
|
+
spec.version = PRAWN_OVAL_TEXT_VERSION
|
7
|
+
spec.platform = Gem::Platform::RUBY
|
8
|
+
spec.summary = "Oval text for Prawn"
|
9
|
+
spec.files = Dir.glob("{examples,lib,spec}/**/**/*") +
|
10
|
+
["Rakefile", "prawn_oval_text.gemspec"]
|
11
|
+
spec.require_path = "lib"
|
12
|
+
spec.required_ruby_version = '>= 1.8.7'
|
13
|
+
spec.required_rubygems_version = ">= 1.3.6"
|
14
|
+
|
15
|
+
spec.test_files = Dir[ "spec/*_spec.rb" ]
|
16
|
+
spec.has_rdoc = true
|
17
|
+
spec.extra_rdoc_files = %w{README.rdoc LICENSE}
|
18
|
+
spec.rdoc_options << '--title' << 'Prawn Oval Text Documentation' <<
|
19
|
+
'--main' << 'README.rdoc' << '-q'
|
20
|
+
spec.authors = ["Daniel Nelson"]
|
21
|
+
spec.email = ["dnelson@bluejade.com"]
|
22
|
+
spec.add_dependency('prawn', '>=0.11.1')
|
23
|
+
spec.homepage = "https://github.com/Bluejade/prawn-oval-text"
|
24
|
+
spec.description = <<END_DESC
|
25
|
+
Adds oval shaped text to Prawn
|
26
|
+
END_DESC
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler"
|
5
|
+
Bundler.setup
|
6
|
+
|
7
|
+
require "prawn"
|
8
|
+
require "test/spec"
|
9
|
+
require "mocha"
|
10
|
+
require "pdf/reader"
|
11
|
+
require "pdf/inspector"
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
14
|
+
require 'prawn_oval_text'
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
Prawn.debug = true
|
19
|
+
|
20
|
+
def create_pdf(klass=Prawn::Document)
|
21
|
+
@pdf = klass.new(:left_margin => 0,
|
22
|
+
:right_margin => 0,
|
23
|
+
:top_margin => 0,
|
24
|
+
:bottom_margin => 0)
|
25
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
3
|
+
|
4
|
+
describe "Text::Oval" do
|
5
|
+
it "should print text" do
|
6
|
+
create_pdf
|
7
|
+
options = {
|
8
|
+
:width => 162.0,
|
9
|
+
:height => 162.0,
|
10
|
+
:center => [81.0, 639.0],
|
11
|
+
:crop => 0,
|
12
|
+
:document => @pdf
|
13
|
+
}
|
14
|
+
text = "Hello world"
|
15
|
+
text_oval = Prawn::Text::Oval.new(text, options)
|
16
|
+
text_oval.render
|
17
|
+
text = PDF::Inspector::Text.analyze(@pdf.render)
|
18
|
+
text.strings[0].should == "Hello"
|
19
|
+
text.strings[1].should == "world"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "Text::Oval with text than can fit in the oval" do
|
24
|
+
before(:each) do
|
25
|
+
create_pdf
|
26
|
+
@text = "Oh hai text oval. " * 10
|
27
|
+
@options = {
|
28
|
+
:width => 162.0,
|
29
|
+
:height => 162.0,
|
30
|
+
:center => [81.0, 639.0],
|
31
|
+
:crop => 0,
|
32
|
+
:document => @pdf
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
it "printed text should match requested text, except for trailing or leading white space and that spaces may be replaced by newlines" do
|
37
|
+
text_oval = Prawn::Text::Oval.new(@text, @options)
|
38
|
+
text_oval.render
|
39
|
+
text_oval.text.gsub("\n", " ").should == @text.strip
|
40
|
+
end
|
41
|
+
|
42
|
+
it "render should return an empty string because no text remains unprinted" do
|
43
|
+
text_oval = Prawn::Text::Oval.new(@text, @options)
|
44
|
+
text_oval.render.should == ""
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should be truncated when the leading is set high enough to prevent all the lines from being printed" do
|
48
|
+
@options[:leading] = 40
|
49
|
+
text_oval = Prawn::Text::Oval.new(@text, @options)
|
50
|
+
text_oval.render
|
51
|
+
text_oval.text.gsub("\n", " ").should.not == @text.strip
|
52
|
+
end
|
53
|
+
|
54
|
+
it "printed text should be identical for all three alignments" do
|
55
|
+
@options[:align] = :left
|
56
|
+
text_oval = Prawn::Text::Oval.new(@text, @options)
|
57
|
+
text_oval.render
|
58
|
+
left_text = text_oval.text
|
59
|
+
|
60
|
+
@options[:align] = :center
|
61
|
+
text_oval = Prawn::Text::Oval.new(@text, @options)
|
62
|
+
text_oval.render
|
63
|
+
center_text = text_oval.text
|
64
|
+
|
65
|
+
@options[:align] = :right
|
66
|
+
text_oval = Prawn::Text::Oval.new(@text, @options)
|
67
|
+
text_oval.render
|
68
|
+
right_text = text_oval.text
|
69
|
+
|
70
|
+
left_text.should == center_text
|
71
|
+
center_text.should == right_text
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "Text::Oval with longer text than can fit in the oval" do
|
76
|
+
before(:each) do
|
77
|
+
create_pdf
|
78
|
+
@text = "Oh hai text oval. " * 15
|
79
|
+
@options = {
|
80
|
+
:width => 162.0,
|
81
|
+
:height => 162.0,
|
82
|
+
:center => [81.0, 639.0],
|
83
|
+
:crop => 0,
|
84
|
+
:document => @pdf
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
context "truncated overflow" do
|
89
|
+
before(:each) do
|
90
|
+
@options[:overflow] = :truncate
|
91
|
+
@text_oval = Prawn::Text::Oval.new(@text, @options)
|
92
|
+
end
|
93
|
+
it "should be truncated" do
|
94
|
+
@text_oval.render
|
95
|
+
@text_oval.text.gsub("\n", " ").should.not == @text.strip
|
96
|
+
end
|
97
|
+
it "render should not return an empty string because some text remains unprinted" do
|
98
|
+
@text_oval.render.should.not == ""
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "shrink_to_fit overflow" do
|
103
|
+
before(:each) do
|
104
|
+
@options[:overflow] = :shrink_to_fit
|
105
|
+
@options[:min_font_size] = 2
|
106
|
+
@text_oval = Prawn::Text::Oval.new(@text, @options)
|
107
|
+
end
|
108
|
+
it "should display the entire text" do
|
109
|
+
@text_oval.render
|
110
|
+
@text_oval.text.gsub("\n", " ").should == @text.strip
|
111
|
+
end
|
112
|
+
it "render should return an empty string because no text remains unprinted" do
|
113
|
+
@text_oval.render.should == ""
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
it "printed text should be identical for all three alignments" do
|
118
|
+
@options[:align] = :left
|
119
|
+
text_oval = Prawn::Text::Oval.new(@text, @options)
|
120
|
+
text_oval.render
|
121
|
+
left_text = text_oval.text
|
122
|
+
|
123
|
+
@options[:align] = :center
|
124
|
+
text_oval = Prawn::Text::Oval.new(@text, @options)
|
125
|
+
text_oval.render
|
126
|
+
center_text = text_oval.text
|
127
|
+
|
128
|
+
@options[:align] = :right
|
129
|
+
text_oval = Prawn::Text::Oval.new(@text, @options)
|
130
|
+
text_oval.render
|
131
|
+
right_text = text_oval.text
|
132
|
+
|
133
|
+
left_text.should == center_text
|
134
|
+
center_text.should == right_text
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "Text::Oval with a single word that is longer than can fit in the oval" do
|
139
|
+
before(:each) do
|
140
|
+
create_pdf
|
141
|
+
@text = "Ohhaitextoval" * 100
|
142
|
+
@options = {
|
143
|
+
:width => 162.0,
|
144
|
+
:height => 162.0,
|
145
|
+
:center => [81.0, 639.0],
|
146
|
+
:crop => 0,
|
147
|
+
:document => @pdf
|
148
|
+
}
|
149
|
+
end
|
150
|
+
|
151
|
+
context "with a crop greater than zero" do
|
152
|
+
it "should print less text than without a crop" do
|
153
|
+
@options[:crop] = 0
|
154
|
+
text_oval = Prawn::Text::Oval.new(@text, @options)
|
155
|
+
text_oval.render
|
156
|
+
full_text = text_oval.text
|
157
|
+
|
158
|
+
@options[:crop] = @pdf.font.height
|
159
|
+
text_oval = Prawn::Text::Oval.new(@text, @options)
|
160
|
+
text_oval.render
|
161
|
+
cropped_text = text_oval.text
|
162
|
+
|
163
|
+
cropped_text.length.should < full_text.length
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "Text::Oval with a solid block of Chinese characters" do
|
169
|
+
before(:each) do
|
170
|
+
create_pdf
|
171
|
+
@text = "写中国字" * 10
|
172
|
+
@options = {
|
173
|
+
:width => 162.0,
|
174
|
+
:height => 162.0,
|
175
|
+
:center => [81.0, 639.0],
|
176
|
+
:crop => 0,
|
177
|
+
:document => @pdf
|
178
|
+
}
|
179
|
+
@pdf.font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
|
180
|
+
end
|
181
|
+
|
182
|
+
it "printed text should match requested text, except for newlines" do
|
183
|
+
text_oval = Prawn::Text::Oval.new(@text, @options)
|
184
|
+
text_oval.render
|
185
|
+
text_oval.text.gsub("\n", "").should == @text.strip
|
186
|
+
end
|
187
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prawn_oval_text
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 49
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 11
|
9
|
+
- 1
|
10
|
+
version: 0.11.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Daniel Nelson
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-05 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: prawn
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 49
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 11
|
33
|
+
- 1
|
34
|
+
version: 0.11.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: " Adds oval shaped text to Prawn\n"
|
38
|
+
email:
|
39
|
+
- dnelson@bluejade.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- README.rdoc
|
46
|
+
- LICENSE
|
47
|
+
files:
|
48
|
+
- examples/example_helper.rb
|
49
|
+
- examples/text/text_oval.rb
|
50
|
+
- lib/prawn_oval_text.rb
|
51
|
+
- lib/prawn_oval_text/formatted/oval.rb
|
52
|
+
- lib/prawn_oval_text/oval.rb
|
53
|
+
- spec/text_oval_spec.rb
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
- Rakefile
|
56
|
+
- prawn_oval_text.gemspec
|
57
|
+
- README.rdoc
|
58
|
+
- LICENSE
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: https://github.com/Bluejade/prawn-oval-text
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --title
|
66
|
+
- Prawn Oval Text Documentation
|
67
|
+
- --main
|
68
|
+
- README.rdoc
|
69
|
+
- -q
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 57
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 8
|
81
|
+
- 7
|
82
|
+
version: 1.8.7
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 23
|
89
|
+
segments:
|
90
|
+
- 1
|
91
|
+
- 3
|
92
|
+
- 6
|
93
|
+
version: 1.3.6
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.5.2
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: Oval text for Prawn
|
101
|
+
test_files:
|
102
|
+
- spec/text_oval_spec.rb
|