prawn 1.0.0.rc2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +9 -0
- data/COPYING +2 -2
- data/Gemfile +8 -15
- data/LICENSE +1 -1
- data/Rakefile +25 -16
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/license.md +8 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/lib/prawn.rb +85 -23
- data/lib/prawn/document.rb +134 -116
- data/lib/prawn/document/bounding_box.rb +33 -4
- data/lib/prawn/document/column_box.rb +18 -6
- data/lib/prawn/document/graphics_state.rb +11 -74
- data/lib/prawn/document/internals.rb +24 -23
- data/lib/prawn/document/span.rb +12 -10
- data/lib/prawn/encoding.rb +8 -9
- data/lib/prawn/errors.rb +13 -32
- data/lib/prawn/font.rb +137 -105
- data/lib/prawn/font/afm.rb +76 -32
- data/lib/prawn/font/dfont.rb +4 -3
- data/lib/prawn/font/ttf.rb +33 -25
- data/lib/prawn/font_metric_cache.rb +47 -0
- data/lib/prawn/graphics.rb +177 -57
- data/lib/prawn/graphics/cap_style.rb +4 -3
- data/lib/prawn/graphics/color.rb +5 -4
- data/lib/prawn/graphics/dash.rb +53 -31
- data/lib/prawn/graphics/join_style.rb +9 -7
- data/lib/prawn/graphics/patterns.rb +4 -15
- data/lib/prawn/graphics/transformation.rb +10 -9
- data/lib/prawn/graphics/transparency.rb +3 -1
- data/lib/prawn/{layout/grid.rb → grid.rb} +72 -54
- data/lib/prawn/image_handler.rb +42 -0
- data/lib/prawn/images.rb +58 -54
- data/lib/prawn/images/image.rb +6 -22
- data/lib/prawn/images/jpg.rb +20 -14
- data/lib/prawn/images/png.rb +58 -121
- data/lib/prawn/layout.rb +12 -15
- data/lib/prawn/measurement_extensions.rb +10 -6
- data/lib/prawn/measurements.rb +27 -21
- data/lib/prawn/outline.rb +108 -147
- data/lib/prawn/repeater.rb +10 -8
- data/lib/prawn/security.rb +59 -40
- data/lib/prawn/security/arcfour.rb +52 -0
- data/lib/prawn/soft_mask.rb +4 -4
- data/lib/prawn/stamp.rb +5 -3
- data/lib/prawn/table.rb +83 -60
- data/lib/prawn/table/cell.rb +17 -21
- data/lib/prawn/table/cell/image.rb +2 -3
- data/lib/prawn/table/cell/in_table.rb +8 -2
- data/lib/prawn/table/cell/span_dummy.rb +5 -0
- data/lib/prawn/table/cell/subtable.rb +3 -2
- data/lib/prawn/table/cell/text.rb +14 -12
- data/lib/prawn/table/cells.rb +58 -14
- data/lib/prawn/table/column_width_calculator.rb +61 -0
- data/lib/prawn/text.rb +27 -26
- data/lib/prawn/text/box.rb +12 -6
- data/lib/prawn/text/formatted.rb +5 -4
- data/lib/prawn/text/formatted/arranger.rb +290 -0
- data/lib/prawn/text/formatted/box.rb +85 -57
- data/lib/prawn/text/formatted/fragment.rb +11 -11
- data/lib/prawn/text/formatted/line_wrap.rb +266 -0
- data/lib/prawn/text/formatted/parser.rb +11 -4
- data/lib/prawn/text/formatted/wrap.rb +156 -0
- data/lib/prawn/utilities.rb +5 -3
- data/manual/document_and_page_options/document_and_page_options.rb +2 -1
- data/manual/document_and_page_options/metadata.rb +3 -3
- data/manual/document_and_page_options/page_size.rb +2 -2
- data/manual/document_and_page_options/print_scaling.rb +20 -0
- data/manual/example_file.rb +2 -7
- data/manual/example_helper.rb +62 -81
- data/manual/graphics/common_lines.rb +2 -0
- data/manual/graphics/helper.rb +11 -4
- data/manual/graphics/stroke_dash.rb +19 -14
- data/manual/manual/cover.rb +16 -0
- data/manual/manual/manual.rb +1 -5
- data/manual/text/fallback_fonts.rb +4 -4
- data/manual/text/formatted_text.rb +5 -5
- data/manual/text/inline.rb +2 -4
- data/manual/text/registering_families.rb +12 -12
- data/manual/text/single_usage.rb +4 -4
- data/manual/text/text.rb +0 -2
- data/prawn.gemspec +21 -13
- data/spec/acceptance/png.rb +23 -0
- data/spec/annotations_spec.rb +16 -32
- data/spec/bounding_box_spec.rb +22 -5
- data/spec/cell_spec.rb +49 -5
- data/spec/column_box_spec.rb +32 -0
- data/spec/destinations_spec.rb +5 -5
- data/spec/document_spec.rb +112 -118
- data/spec/extensions/encoding_helpers.rb +5 -2
- data/spec/font_metric_cache_spec.rb +52 -0
- data/spec/font_spec.rb +121 -120
- data/spec/formatted_text_arranger_spec.rb +24 -24
- data/spec/formatted_text_box_spec.rb +31 -32
- data/spec/formatted_text_fragment_spec.rb +2 -2
- data/spec/graphics_spec.rb +63 -45
- data/spec/grid_spec.rb +24 -13
- data/spec/image_handler_spec.rb +54 -0
- data/spec/images_spec.rb +34 -21
- data/spec/inline_formatted_text_parser_spec.rb +69 -20
- data/spec/jpg_spec.rb +3 -3
- data/spec/line_wrap_spec.rb +25 -14
- data/spec/measurement_units_spec.rb +5 -5
- data/spec/outline_spec.rb +68 -64
- data/spec/png_spec.rb +15 -18
- data/spec/reference_spec.rb +2 -82
- data/spec/repeater_spec.rb +1 -1
- data/spec/security_spec.rb +41 -9
- data/spec/soft_mask_spec.rb +0 -40
- data/spec/span_spec.rb +6 -11
- data/spec/spec_helper.rb +20 -2
- data/spec/stamp_spec.rb +19 -20
- data/spec/stroke_styles_spec.rb +31 -13
- data/spec/table/span_dummy_spec.rb +17 -0
- data/spec/table_spec.rb +268 -43
- data/spec/text_at_spec.rb +13 -27
- data/spec/text_box_spec.rb +35 -30
- data/spec/text_spec.rb +56 -40
- data/spec/transparency_spec.rb +5 -5
- metadata +214 -217
- data/README.md +0 -98
- 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/DejaVuSans.ttf +0 -0
- data/data/fonts/Dustismo_Roman.ttf +0 -0
- data/data/fonts/comicsans.ttf +0 -0
- data/data/fonts/gkai00mp.ttf +0 -0
- data/data/images/16bit.dat +0 -0
- data/data/images/barcode_issue.png +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/page_white_text.dat +0 -0
- data/data/images/rails.dat +0 -0
- data/data/images/rails.png +0 -0
- data/lib/prawn/compatibility.rb +0 -87
- data/lib/prawn/core.rb +0 -87
- data/lib/prawn/core/annotations.rb +0 -61
- data/lib/prawn/core/byte_string.rb +0 -9
- data/lib/prawn/core/destinations.rb +0 -90
- data/lib/prawn/core/document_state.rb +0 -79
- data/lib/prawn/core/literal_string.rb +0 -16
- data/lib/prawn/core/name_tree.rb +0 -177
- data/lib/prawn/core/object_store.rb +0 -320
- data/lib/prawn/core/page.rb +0 -212
- data/lib/prawn/core/pdf_object.rb +0 -125
- data/lib/prawn/core/reference.rb +0 -119
- data/lib/prawn/core/text.rb +0 -268
- data/lib/prawn/core/text/formatted/arranger.rb +0 -294
- data/lib/prawn/core/text/formatted/line_wrap.rb +0 -288
- data/lib/prawn/core/text/formatted/wrap.rb +0 -153
- data/lib/prawn/document/page_geometry.rb +0 -136
- data/lib/prawn/document/snapshot.rb +0 -89
- data/manual/manual/foreword.rb +0 -13
- data/manual/templates/full_template.rb +0 -23
- data/manual/templates/page_template.rb +0 -47
- data/manual/templates/templates.rb +0 -26
- data/manual/text/group.rb +0 -29
- data/spec/name_tree_spec.rb +0 -112
- data/spec/object_store_spec.rb +0 -170
- data/spec/pdf_object_spec.rb +0 -172
- data/spec/snapshot_spec.rb +0 -186
- data/spec/template_spec.rb +0 -351
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
describe "Font metrics caching" do
|
7
|
+
let(:document) { Prawn::Document.new }
|
8
|
+
|
9
|
+
subject { Prawn::FontMetricCache.new( document ) }
|
10
|
+
|
11
|
+
it "should start with an empty cache" do
|
12
|
+
subject.instance_variable_get( :@cache ).should be_empty
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should cache the width of the provided string" do
|
16
|
+
subject.width_of('M', {})
|
17
|
+
|
18
|
+
subject.instance_variable_get( :@cache ).should have(1).entry
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should only cache a single copy of the same string" do
|
22
|
+
subject.width_of('M', {})
|
23
|
+
subject.width_of('M', {})
|
24
|
+
|
25
|
+
subject.instance_variable_get( :@cache ).should have(1).entry
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should cache different copies for different strings" do
|
29
|
+
subject.width_of('M', {})
|
30
|
+
subject.width_of('W', {})
|
31
|
+
|
32
|
+
subject.instance_variable_get( :@cache ).should have(2).entries
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should cache different copies of the same string with different font sizes" do
|
36
|
+
subject.width_of('M', {})
|
37
|
+
|
38
|
+
document.font_size 24
|
39
|
+
subject.width_of('M', {})
|
40
|
+
|
41
|
+
subject.instance_variable_get( :@cache ).should have(2).entries
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should cache different copies of the same string with different fonts" do
|
45
|
+
subject.width_of('M', {})
|
46
|
+
|
47
|
+
document.font 'Courier'
|
48
|
+
subject.width_of('M', {})
|
49
|
+
|
50
|
+
subject.instance_variable_get( :@cache ).should have(2).entries
|
51
|
+
end
|
52
|
+
end
|
data/spec/font_spec.rb
CHANGED
@@ -12,6 +12,32 @@ describe "Font behavior" do
|
|
12
12
|
|
13
13
|
end
|
14
14
|
|
15
|
+
describe "Font objects" do
|
16
|
+
|
17
|
+
it "should be equal" do
|
18
|
+
font1 = Prawn::Document.new.font
|
19
|
+
font2 = Prawn::Document.new.font
|
20
|
+
|
21
|
+
font1.should eql( font2 )
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should always be the same key" do
|
25
|
+
font1 = Prawn::Document.new.font
|
26
|
+
font2 = Prawn::Document.new.font
|
27
|
+
|
28
|
+
hash = Hash.new
|
29
|
+
|
30
|
+
hash[ font1 ] = "Original"
|
31
|
+
hash[ font2 ] = "Overwritten"
|
32
|
+
|
33
|
+
hash.size.should == 1
|
34
|
+
|
35
|
+
hash[ font1 ].should == "Overwritten"
|
36
|
+
hash[ font2 ].should == "Overwritten"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
15
41
|
describe "#width_of" do
|
16
42
|
it "should take character spacing into account" do
|
17
43
|
create_pdf
|
@@ -38,7 +64,7 @@ describe "#width_of" do
|
|
38
64
|
@pdf.font("Helvetica", :style => :bold) {
|
39
65
|
@bold_hello = @pdf.width_of("hello")
|
40
66
|
}
|
41
|
-
|
67
|
+
|
42
68
|
inline_bold_hello.should be > normal_hello
|
43
69
|
inline_bold_hello.should == @bold_hello
|
44
70
|
end
|
@@ -53,6 +79,12 @@ describe "#width_of" do
|
|
53
79
|
|
54
80
|
styled_bold_hello.should == @bold_hello
|
55
81
|
end
|
82
|
+
|
83
|
+
it "should not treat minus as if it were a hyphen", :issue => 578 do
|
84
|
+
create_pdf
|
85
|
+
|
86
|
+
@pdf.width_of("-0.75").should be < @pdf.width_of("25.00")
|
87
|
+
end
|
56
88
|
end
|
57
89
|
|
58
90
|
describe "#font_size" do
|
@@ -65,86 +97,86 @@ end
|
|
65
97
|
|
66
98
|
describe "font style support" do
|
67
99
|
before(:each) { create_pdf }
|
68
|
-
|
100
|
+
|
69
101
|
it "should complain if there is no @current_page" do
|
70
102
|
pdf_without_page = Prawn::Document.new(:skip_page_creation => true)
|
71
103
|
|
72
104
|
lambda{ pdf_without_page.font "Helvetica" }.
|
73
105
|
should raise_error(Prawn::Errors::NotOnPage)
|
74
106
|
end
|
75
|
-
|
76
|
-
it "should allow specifying font style by style name and font family" do
|
107
|
+
|
108
|
+
it "should allow specifying font style by style name and font family" do
|
77
109
|
@pdf.font "Courier", :style => :bold
|
78
|
-
@pdf.text "In Courier bold"
|
79
|
-
|
110
|
+
@pdf.text "In Courier bold"
|
111
|
+
|
80
112
|
@pdf.font "Courier", :style => :bold_italic
|
81
|
-
@pdf.text "In Courier bold-italic"
|
82
|
-
|
113
|
+
@pdf.text "In Courier bold-italic"
|
114
|
+
|
83
115
|
@pdf.font "Courier", :style => :italic
|
84
|
-
@pdf.text "In Courier italic"
|
85
|
-
|
116
|
+
@pdf.text "In Courier italic"
|
117
|
+
|
86
118
|
@pdf.font "Courier", :style => :normal
|
87
|
-
@pdf.text "In Normal Courier"
|
88
|
-
|
119
|
+
@pdf.text "In Normal Courier"
|
120
|
+
|
89
121
|
@pdf.font "Helvetica"
|
90
|
-
@pdf.text "In Normal Helvetica"
|
91
|
-
|
122
|
+
@pdf.text "In Normal Helvetica"
|
123
|
+
|
92
124
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
93
|
-
text.font_settings.map { |e| e[:name] }.should ==
|
94
|
-
[:"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique",
|
125
|
+
text.font_settings.map { |e| e[:name] }.should ==
|
126
|
+
[:"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique",
|
95
127
|
:Courier, :Helvetica]
|
96
128
|
end
|
97
129
|
|
98
130
|
it "should allow font familes to be defined in a single dfont" do
|
99
|
-
file = "#{Prawn::DATADIR}/fonts/
|
100
|
-
@pdf.font_families["
|
101
|
-
:normal => { :file => file, :font => "
|
102
|
-
:italic => { :file => file, :font => "
|
103
|
-
:bold => { :file => file, :font => "
|
104
|
-
:bold_italic => { :file => file, :font => "
|
131
|
+
file = "#{Prawn::DATADIR}/fonts/Panic+Sans.dfont"
|
132
|
+
@pdf.font_families["Panic Sans"] = {
|
133
|
+
:normal => { :file => file, :font => "PanicSans" },
|
134
|
+
:italic => { :file => file, :font => "PanicSans-Italic" },
|
135
|
+
:bold => { :file => file, :font => "PanicSans-Bold" },
|
136
|
+
:bold_italic => { :file => file, :font => "PanicSans-BoldItalic" }
|
105
137
|
}
|
106
138
|
|
107
|
-
@pdf.font "
|
108
|
-
@pdf.text "In
|
139
|
+
@pdf.font "Panic Sans", :style => :italic
|
140
|
+
@pdf.text "In PanicSans-Italic"
|
109
141
|
|
110
142
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
111
143
|
name = text.font_settings.map { |e| e[:name] }.first.to_s
|
112
144
|
name = name.sub(/\w+\+/, "subset+")
|
113
|
-
name.should == "subset+
|
145
|
+
name.should == "subset+PanicSans-Italic"
|
114
146
|
end
|
115
147
|
|
116
148
|
it "should accept Pathname objects for font files" do
|
117
|
-
file = Pathname.new( "#{Prawn::DATADIR}/fonts/
|
118
|
-
@pdf.font_families["
|
149
|
+
file = Pathname.new( "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf" )
|
150
|
+
@pdf.font_families["DejaVu Sans"] = {
|
119
151
|
:normal => file
|
120
152
|
}
|
121
153
|
|
122
|
-
@pdf.font "
|
123
|
-
@pdf.text "In
|
154
|
+
@pdf.font "DejaVu Sans"
|
155
|
+
@pdf.text "In DejaVu Sans"
|
124
156
|
|
125
157
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
126
158
|
name = text.font_settings.map { |e| e[:name] }.first.to_s
|
127
159
|
name = name.sub(/\w+\+/, "subset+")
|
128
|
-
name.should == "subset+
|
160
|
+
name.should == "subset+DejaVuSans"
|
129
161
|
end
|
130
162
|
end
|
131
163
|
|
132
164
|
describe "Transactional font handling" do
|
133
165
|
before(:each) { create_pdf }
|
134
|
-
|
166
|
+
|
135
167
|
it "should allow setting of size directly when font is created" do
|
136
168
|
@pdf.font "Courier", :size => 16
|
137
|
-
@pdf.font_size.should == 16
|
169
|
+
@pdf.font_size.should == 16
|
138
170
|
end
|
139
|
-
|
171
|
+
|
140
172
|
it "should allow temporary setting of a new font using a transaction" do
|
141
173
|
@pdf.font "Helvetica", :size => 12
|
142
|
-
|
174
|
+
|
143
175
|
@pdf.font "Courier", :size => 16 do
|
144
176
|
@pdf.font.name.should == "Courier"
|
145
177
|
@pdf.font_size.should == 16
|
146
178
|
end
|
147
|
-
|
179
|
+
|
148
180
|
@pdf.font.name.should == "Helvetica"
|
149
181
|
@pdf.font_size.should == 12
|
150
182
|
end
|
@@ -159,53 +191,53 @@ describe "Transactional font handling" do
|
|
159
191
|
|
160
192
|
@pdf.font_size.should == 12
|
161
193
|
end
|
162
|
-
|
194
|
+
|
163
195
|
end
|
164
196
|
|
165
197
|
describe "Document#page_fonts" do
|
166
|
-
before(:each) { create_pdf }
|
167
|
-
|
198
|
+
before(:each) { create_pdf }
|
199
|
+
|
168
200
|
it "should register fonts properly by page" do
|
169
201
|
@pdf.font "Courier"; @pdf.text("hello")
|
170
202
|
@pdf.font "Helvetica"; @pdf.text("hello")
|
171
203
|
@pdf.font "Times-Roman"; @pdf.text("hello")
|
172
204
|
["Courier","Helvetica","Times-Roman"].each { |f|
|
173
205
|
page_should_include_font(f)
|
174
|
-
}
|
175
|
-
|
176
|
-
@pdf.start_new_page
|
206
|
+
}
|
207
|
+
|
208
|
+
@pdf.start_new_page
|
177
209
|
@pdf.font "Helvetica"; @pdf.text("hello")
|
178
210
|
page_should_include_font("Helvetica")
|
179
211
|
page_should_not_include_font("Courier")
|
180
212
|
page_should_not_include_font("Times-Roman")
|
181
|
-
end
|
182
|
-
|
213
|
+
end
|
214
|
+
|
183
215
|
def page_includes_font?(font)
|
184
216
|
@pdf.page.fonts.values.map { |e| e.data[:BaseFont] }.include?(font.to_sym)
|
185
|
-
end
|
186
|
-
|
187
|
-
def page_should_include_font(font)
|
217
|
+
end
|
218
|
+
|
219
|
+
def page_should_include_font(font)
|
188
220
|
page_includes_font?(font).should be_true
|
189
|
-
end
|
190
|
-
|
221
|
+
end
|
222
|
+
|
191
223
|
def page_should_not_include_font(font)
|
192
224
|
page_includes_font?(font).should be_false
|
193
225
|
end
|
194
|
-
|
226
|
+
|
195
227
|
end
|
196
|
-
|
228
|
+
|
197
229
|
describe "AFM fonts" do
|
198
|
-
|
230
|
+
|
199
231
|
before do
|
200
232
|
create_pdf
|
201
233
|
@times = @pdf.find_font "Times-Roman"
|
202
234
|
end
|
203
|
-
|
235
|
+
|
204
236
|
it "should calculate string width taking into account accented characters" do
|
205
237
|
input = win1252_string("\xE9")# é in win-1252
|
206
238
|
@times.compute_width_of(input, :size => 12).should == @times.compute_width_of("e", :size => 12)
|
207
239
|
end
|
208
|
-
|
240
|
+
|
209
241
|
it "should calculate string width taking into account kerning pairs" do
|
210
242
|
@times.compute_width_of(win1252_string("To"), :size => 12).should == 13.332
|
211
243
|
@times.compute_width_of(win1252_string("To"), :size => 12, :kerning => true).should == 12.372
|
@@ -252,7 +284,7 @@ describe "AFM fonts" do
|
|
252
284
|
font_dict = zapf.send(:register, nil)
|
253
285
|
font_dict.data[:Encoding].should == nil
|
254
286
|
end
|
255
|
-
|
287
|
+
|
256
288
|
end
|
257
289
|
|
258
290
|
describe "#glyph_present" do
|
@@ -269,12 +301,12 @@ describe "#glyph_present" do
|
|
269
301
|
end
|
270
302
|
|
271
303
|
it "should return true when present in a TTF font" do
|
272
|
-
font = @pdf.find_font("#{Prawn::DATADIR}/fonts/
|
304
|
+
font = @pdf.find_font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
273
305
|
font.glyph_present?("H").should be_true
|
274
306
|
end
|
275
307
|
|
276
308
|
it "should return false when absent in a TTF font" do
|
277
|
-
font = @pdf.find_font("#{Prawn::DATADIR}/fonts/
|
309
|
+
font = @pdf.find_font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
278
310
|
font.glyph_present?("再").should be_false
|
279
311
|
|
280
312
|
font = @pdf.find_font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
|
@@ -283,111 +315,80 @@ describe "#glyph_present" do
|
|
283
315
|
end
|
284
316
|
|
285
317
|
describe "TTF fonts" do
|
286
|
-
|
318
|
+
|
287
319
|
before do
|
288
320
|
create_pdf
|
289
|
-
@
|
321
|
+
@font = @pdf.find_font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
|
290
322
|
end
|
291
|
-
|
323
|
+
|
292
324
|
it "should calculate string width taking into account accented characters" do
|
293
|
-
@
|
325
|
+
@font.compute_width_of("é", :size => 12).should == @font.compute_width_of("e", :size => 12)
|
294
326
|
end
|
295
|
-
|
327
|
+
|
296
328
|
it "should calculate string width taking into account kerning pairs" do
|
297
|
-
@
|
298
|
-
@
|
329
|
+
@font.compute_width_of("To", :size => 12).should be_within(0.01).of(14.65)
|
330
|
+
@font.compute_width_of("To", :size => 12, :kerning => true).should be_within(0.01).of(12.61)
|
299
331
|
end
|
300
|
-
|
332
|
+
|
301
333
|
it "should encode text without kerning by default" do
|
302
|
-
@
|
334
|
+
@font.encode_text("To").should == [[0, "To"]]
|
303
335
|
|
304
336
|
tele = "T\216l\216"
|
305
|
-
result = @
|
337
|
+
result = @font.encode_text("Télé")
|
306
338
|
result.length.should == 1
|
307
339
|
result[0][0].should == 0
|
308
340
|
result[0][1].bytes.to_a.should == tele.bytes.to_a
|
309
341
|
|
310
|
-
@
|
311
|
-
@
|
312
|
-
@
|
342
|
+
@font.encode_text("Technology").should == [[0, "Technology"]]
|
343
|
+
@font.encode_text("Technology...").should == [[0, "Technology..."]]
|
344
|
+
@font.encode_text("Teχnology...").should == [[0, "Te"], [1, "!"], [0, "nology..."]]
|
313
345
|
end
|
314
346
|
|
315
347
|
it "should encode text with kerning if requested" do
|
316
|
-
@
|
317
|
-
@
|
318
|
-
@
|
319
|
-
@
|
320
|
-
@activa.encode_text("Teχnology...", :kerning => true).should == [[0, ["T", 186.0, "e"]], [1, "!"], [0, ["nology", 88.0, "..."]]]
|
348
|
+
@font.encode_text("To", :kerning => true).should == [[0, ["T", 169.921875, "o"]]]
|
349
|
+
@font.encode_text("Technology", :kerning => true).should == [[0, ["T", 169.921875, "echnology"]]]
|
350
|
+
@font.encode_text("Technology...", :kerning => true).should == [[0, ["T", 169.921875, "echnology", 142.578125, "..."]]]
|
351
|
+
@font.encode_text("Teχnology...", :kerning => true).should == [[0, ["T", 169.921875, "e"]], [1, "!"], [0, ["nology", 142.578125, "..."]]]
|
321
352
|
end
|
322
353
|
|
323
354
|
it "should use the ascender, descender, and cap height from the TTF verbatim" do
|
324
355
|
# These metrics are relative to the font's own bbox. They should not be
|
325
356
|
# scaled with font size.
|
326
357
|
ref = @pdf.ref!({})
|
327
|
-
@
|
358
|
+
@font.send :embed, ref, 0
|
328
359
|
|
329
360
|
# Pull out the embedded font descriptor
|
330
361
|
descriptor = ref.data[:FontDescriptor].data
|
331
|
-
descriptor[:Ascent].should ==
|
332
|
-
descriptor[:Descent].should == -
|
333
|
-
descriptor[:CapHeight].should ==
|
362
|
+
descriptor[:Ascent].should == 759
|
363
|
+
descriptor[:Descent].should == -240
|
364
|
+
descriptor[:CapHeight].should == 759
|
334
365
|
end
|
335
366
|
|
336
367
|
describe "when normalizing encoding" do
|
337
|
-
|
338
368
|
it "should not modify the original string when normalize_encoding() is used" do
|
339
369
|
original = "Foo"
|
340
|
-
normalized = @
|
370
|
+
normalized = @font.normalize_encoding(original)
|
341
371
|
original.equal?(normalized).should be_false
|
342
372
|
end
|
343
373
|
|
344
374
|
it "should modify the original string when normalize_encoding!() is used" do
|
345
375
|
original = "Foo"
|
346
|
-
normalized = @
|
376
|
+
normalized = @font.normalize_encoding!(original)
|
347
377
|
original.equal?(normalized).should be_true
|
348
378
|
end
|
349
379
|
|
350
380
|
end
|
351
|
-
|
352
|
-
describe "when used with snapshots or transactions" do
|
353
|
-
|
354
|
-
it "should allow TTF fonts to be used alongside document transactions" do
|
355
|
-
lambda {
|
356
|
-
Prawn::Document.new do
|
357
|
-
font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
|
358
|
-
text "Hi there"
|
359
|
-
transaction { text "Nice, thank you" }
|
360
|
-
end
|
361
|
-
}.should_not raise_error
|
362
|
-
end
|
363
|
-
|
364
|
-
it "should allow TTF fonts to be used inside transactions" do
|
365
|
-
pdf = Prawn::Document.new do
|
366
|
-
transaction do
|
367
|
-
font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
|
368
|
-
text "Hi there"
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
|
-
text = PDF::Inspector::Text.analyze(pdf.render)
|
373
|
-
name = text.font_settings.map { |e| e[:name] }.first.to_s
|
374
|
-
name = name.sub(/\w+\+/, "subset+")
|
375
|
-
name.should == "subset+DejaVuSans"
|
376
|
-
end
|
377
|
-
|
378
|
-
end
|
379
|
-
|
380
381
|
end
|
381
382
|
|
382
383
|
describe "DFont fonts" do
|
383
384
|
before do
|
384
385
|
create_pdf
|
385
|
-
@file = "#{Prawn::DATADIR}/fonts/
|
386
|
+
@file = "#{Prawn::DATADIR}/fonts/Panic+Sans.dfont"
|
386
387
|
end
|
387
388
|
|
388
389
|
it "should list all named fonts" do
|
389
390
|
list = Prawn::Font::DFont.named_fonts(@file)
|
390
|
-
list.sort.should == %w(
|
391
|
+
list.sort.should == %w(PanicSans PanicSans-Italic PanicSans-Bold PanicSans-BoldItalic).sort
|
391
392
|
end
|
392
393
|
|
393
394
|
it "should count the number of fonts in the file" do
|
@@ -396,25 +397,25 @@ describe "DFont fonts" do
|
|
396
397
|
|
397
398
|
it "should default selected font to the first one if not specified" do
|
398
399
|
font = @pdf.find_font(@file)
|
399
|
-
font.basename.should == "
|
400
|
+
font.basename.should == "PanicSans"
|
400
401
|
end
|
401
402
|
|
402
403
|
it "should allow font to be selected by index" do
|
403
404
|
font = @pdf.find_font(@file, :font => 2)
|
404
|
-
font.basename.should == "
|
405
|
+
font.basename.should == "PanicSans-Italic"
|
405
406
|
end
|
406
407
|
|
407
408
|
it "should allow font to be selected by name" do
|
408
|
-
font = @pdf.find_font(@file, :font => "
|
409
|
-
font.basename.should == "
|
409
|
+
font = @pdf.find_font(@file, :font => "PanicSans-BoldItalic")
|
410
|
+
font.basename.should == "PanicSans-BoldItalic"
|
410
411
|
end
|
411
412
|
|
412
413
|
it "should cache font object based on selected font" do
|
413
|
-
f1 = @pdf.find_font(@file, :font => "
|
414
|
-
f2 = @pdf.find_font(@file, :font => "
|
414
|
+
f1 = @pdf.find_font(@file, :font => "PanicSans")
|
415
|
+
f2 = @pdf.find_font(@file, :font => "PanicSans-Bold")
|
415
416
|
f2.object_id.should_not == f1.object_id
|
416
|
-
@pdf.find_font(@file, :font => "
|
417
|
-
@pdf.find_font(@file, :font => "
|
417
|
+
@pdf.find_font(@file, :font => "PanicSans").object_id.should == f1.object_id
|
418
|
+
@pdf.find_font(@file, :font => "PanicSans-Bold").object_id.should == f2.object_id
|
418
419
|
end
|
419
420
|
end
|
420
421
|
|