prawn 0.15.0 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +2 -2
- data/LICENSE +1 -1
- data/README.md +96 -0
- data/Rakefile +27 -30
- 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.alpha +0 -0
- data/data/images/16bit.dat +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/page_white_text.alpha +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/data/pdfs/nested_pages.pdf +13 -13
- data/lib/prawn.rb +21 -85
- data/lib/prawn/compatibility.rb +51 -0
- data/lib/prawn/core.rb +85 -0
- data/lib/prawn/core/annotations.rb +61 -0
- data/lib/prawn/core/byte_string.rb +9 -0
- data/lib/prawn/core/destinations.rb +90 -0
- data/lib/prawn/core/document_state.rb +78 -0
- data/lib/prawn/core/literal_string.rb +16 -0
- data/lib/prawn/core/name_tree.rb +177 -0
- data/lib/prawn/core/object_store.rb +264 -0
- data/lib/prawn/core/page.rb +215 -0
- data/lib/prawn/core/pdf_object.rb +108 -0
- data/lib/prawn/core/reference.rb +115 -0
- data/lib/prawn/core/text.rb +268 -0
- data/lib/prawn/core/text/formatted/arranger.rb +294 -0
- data/lib/prawn/core/text/formatted/line_wrap.rb +273 -0
- data/lib/prawn/core/text/formatted/wrap.rb +153 -0
- data/lib/prawn/document.rb +122 -155
- data/lib/prawn/document/bounding_box.rb +7 -36
- data/lib/prawn/document/column_box.rb +10 -38
- data/lib/prawn/document/graphics_state.rb +74 -11
- data/lib/prawn/document/internals.rb +23 -24
- data/lib/prawn/document/page_geometry.rb +136 -0
- data/lib/prawn/document/snapshot.rb +6 -7
- data/lib/prawn/document/span.rb +10 -12
- data/lib/prawn/encoding.rb +10 -9
- data/lib/prawn/errors.rb +30 -15
- data/lib/prawn/font.rb +104 -136
- data/lib/prawn/font/afm.rb +44 -46
- data/lib/prawn/font/dfont.rb +3 -4
- data/lib/prawn/font/ttf.rb +50 -31
- data/lib/prawn/graphics.rb +57 -302
- data/lib/prawn/graphics/cap_style.rb +3 -4
- data/lib/prawn/graphics/color.rb +5 -13
- data/lib/prawn/graphics/dash.rb +31 -53
- data/lib/prawn/graphics/gradient.rb +84 -0
- data/lib/prawn/graphics/join_style.rb +7 -9
- data/lib/prawn/graphics/transformation.rb +9 -10
- data/lib/prawn/graphics/transparency.rb +1 -3
- data/lib/prawn/images.rb +59 -69
- data/lib/prawn/images/image.rb +22 -6
- data/lib/prawn/images/jpg.rb +14 -20
- data/lib/prawn/images/png.rb +118 -61
- data/lib/prawn/layout.rb +15 -10
- data/lib/prawn/layout/grid.rb +54 -66
- data/lib/prawn/measurement_extensions.rb +6 -10
- data/lib/prawn/measurements.rb +21 -27
- data/lib/prawn/outline.rb +308 -6
- data/lib/prawn/repeater.rb +8 -10
- data/lib/prawn/security.rb +33 -55
- data/lib/prawn/security/arcfour.rb +0 -1
- data/lib/prawn/stamp.rb +3 -5
- data/lib/prawn/table.rb +60 -188
- data/lib/prawn/table/cell.rb +44 -272
- data/lib/prawn/table/cell/image.rb +3 -2
- data/lib/prawn/table/cell/in_table.rb +2 -4
- data/lib/prawn/table/cell/subtable.rb +2 -2
- data/lib/prawn/table/cell/text.rb +18 -41
- data/lib/prawn/table/cells.rb +48 -142
- data/lib/prawn/text.rb +25 -32
- data/lib/prawn/text/box.rb +6 -12
- data/lib/prawn/text/formatted.rb +4 -5
- data/lib/prawn/text/formatted/box.rb +59 -96
- data/lib/prawn/text/formatted/fragment.rb +23 -34
- data/lib/prawn/text/formatted/parser.rb +5 -15
- data/prawn.gemspec +13 -24
- data/spec/annotations_spec.rb +32 -16
- data/spec/bounding_box_spec.rb +17 -119
- data/spec/cell_spec.rb +42 -112
- data/spec/destinations_spec.rb +5 -5
- data/spec/document_spec.rb +111 -155
- data/spec/extensions/mocha.rb +0 -1
- data/spec/font_spec.rb +99 -149
- data/spec/formatted_text_arranger_spec.rb +43 -43
- data/spec/formatted_text_box_spec.rb +44 -43
- data/spec/formatted_text_fragment_spec.rb +8 -8
- data/spec/graphics_spec.rb +68 -151
- data/spec/grid_spec.rb +15 -26
- data/spec/images_spec.rb +30 -51
- data/spec/inline_formatted_text_parser_spec.rb +20 -69
- data/spec/jpg_spec.rb +4 -4
- data/spec/line_wrap_spec.rb +28 -28
- data/spec/measurement_units_spec.rb +6 -6
- data/spec/name_tree_spec.rb +112 -0
- data/spec/object_store_spec.rb +106 -17
- data/spec/outline_spec.rb +63 -103
- data/spec/pdf_object_spec.rb +170 -0
- data/spec/png_spec.rb +25 -25
- data/spec/reference_spec.rb +65 -8
- data/spec/repeater_spec.rb +10 -10
- data/spec/security_spec.rb +12 -44
- data/spec/snapshot_spec.rb +7 -7
- data/spec/span_spec.rb +15 -10
- data/spec/spec_helper.rb +8 -32
- data/spec/stamp_spec.rb +30 -29
- data/spec/stroke_styles_spec.rb +18 -36
- data/spec/table_spec.rb +111 -706
- data/spec/template_spec.rb +297 -0
- data/spec/text_at_spec.rb +33 -19
- data/spec/text_box_spec.rb +64 -100
- data/spec/text_rendering_mode_spec.rb +5 -5
- data/spec/text_spacing_spec.rb +4 -4
- data/spec/text_spec.rb +64 -84
- data/spec/transparency_spec.rb +5 -5
- metadata +290 -463
- checksums.yaml +0 -7
- data/.yardopts +0 -10
- data/Gemfile +0 -11
- data/data/images/16bit.color +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/page_white_text.color +0 -0
- data/lib/prawn/font_metric_cache.rb +0 -47
- data/lib/prawn/graphics/patterns.rb +0 -138
- data/lib/prawn/image_handler.rb +0 -36
- data/lib/prawn/soft_mask.rb +0 -96
- data/lib/prawn/table/cell/span_dummy.rb +0 -93
- data/lib/prawn/table/column_width_calculator.rb +0 -61
- data/lib/prawn/text/formatted/arranger.rb +0 -290
- data/lib/prawn/text/formatted/line_wrap.rb +0 -266
- data/lib/prawn/text/formatted/wrap.rb +0 -150
- data/lib/prawn/utilities.rb +0 -46
- data/manual/basic_concepts/adding_pages.rb +0 -27
- data/manual/basic_concepts/basic_concepts.rb +0 -34
- data/manual/basic_concepts/creation.rb +0 -39
- data/manual/basic_concepts/cursor.rb +0 -33
- data/manual/basic_concepts/measurement.rb +0 -25
- data/manual/basic_concepts/origin.rb +0 -38
- data/manual/basic_concepts/other_cursor_helpers.rb +0 -40
- data/manual/bounding_box/bounding_box.rb +0 -39
- data/manual/bounding_box/bounds.rb +0 -49
- data/manual/bounding_box/canvas.rb +0 -24
- data/manual/bounding_box/creation.rb +0 -23
- data/manual/bounding_box/indentation.rb +0 -46
- data/manual/bounding_box/nesting.rb +0 -45
- data/manual/bounding_box/russian_boxes.rb +0 -40
- data/manual/bounding_box/stretchy.rb +0 -31
- data/manual/document_and_page_options/background.rb +0 -27
- data/manual/document_and_page_options/document_and_page_options.rb +0 -32
- data/manual/document_and_page_options/metadata.rb +0 -23
- data/manual/document_and_page_options/page_margins.rb +0 -38
- data/manual/document_and_page_options/page_size.rb +0 -34
- data/manual/document_and_page_options/print_scaling.rb +0 -20
- data/manual/example_file.rb +0 -111
- data/manual/example_helper.rb +0 -411
- data/manual/example_package.rb +0 -53
- data/manual/example_section.rb +0 -46
- data/manual/graphics/circle_and_ellipse.rb +0 -22
- data/manual/graphics/color.rb +0 -24
- data/manual/graphics/common_lines.rb +0 -30
- data/manual/graphics/fill_and_stroke.rb +0 -42
- data/manual/graphics/fill_rules.rb +0 -37
- data/manual/graphics/gradients.rb +0 -37
- data/manual/graphics/graphics.rb +0 -58
- data/manual/graphics/helper.rb +0 -24
- data/manual/graphics/line_width.rb +0 -35
- data/manual/graphics/lines_and_curves.rb +0 -41
- data/manual/graphics/polygon.rb +0 -29
- data/manual/graphics/rectangle.rb +0 -21
- data/manual/graphics/rotate.rb +0 -28
- data/manual/graphics/scale.rb +0 -41
- data/manual/graphics/soft_masks.rb +0 -46
- data/manual/graphics/stroke_cap.rb +0 -31
- data/manual/graphics/stroke_dash.rb +0 -48
- data/manual/graphics/stroke_join.rb +0 -30
- data/manual/graphics/translate.rb +0 -29
- data/manual/graphics/transparency.rb +0 -35
- data/manual/images/absolute_position.rb +0 -23
- data/manual/images/fit.rb +0 -21
- data/manual/images/horizontal.rb +0 -25
- data/manual/images/images.rb +0 -40
- data/manual/images/plain_image.rb +0 -18
- data/manual/images/scale.rb +0 -22
- data/manual/images/vertical.rb +0 -28
- data/manual/images/width_and_height.rb +0 -25
- data/manual/layout/boxes.rb +0 -27
- data/manual/layout/content.rb +0 -25
- data/manual/layout/layout.rb +0 -28
- data/manual/layout/simple_grid.rb +0 -23
- data/manual/manual/cover.rb +0 -36
- data/manual/manual/foreword.rb +0 -85
- data/manual/manual/how_to_read_this_manual.rb +0 -41
- data/manual/manual/manual.rb +0 -34
- data/manual/outline/add_subsection_to.rb +0 -61
- data/manual/outline/insert_section_after.rb +0 -47
- data/manual/outline/outline.rb +0 -32
- data/manual/outline/sections_and_pages.rb +0 -67
- data/manual/repeatable_content/page_numbering.rb +0 -54
- data/manual/repeatable_content/repeatable_content.rb +0 -31
- data/manual/repeatable_content/repeater.rb +0 -55
- data/manual/repeatable_content/stamp.rb +0 -41
- data/manual/security/encryption.rb +0 -31
- data/manual/security/permissions.rb +0 -38
- data/manual/security/security.rb +0 -28
- data/manual/syntax_highlight.rb +0 -52
- data/manual/table/basic_block.rb +0 -53
- data/manual/table/before_rendering_page.rb +0 -26
- data/manual/table/cell_border_lines.rb +0 -24
- data/manual/table/cell_borders_and_bg.rb +0 -31
- data/manual/table/cell_dimensions.rb +0 -30
- data/manual/table/cell_text.rb +0 -38
- data/manual/table/column_widths.rb +0 -30
- data/manual/table/content_and_subtables.rb +0 -39
- data/manual/table/creation.rb +0 -27
- data/manual/table/filtering.rb +0 -36
- data/manual/table/flow_and_header.rb +0 -17
- data/manual/table/image_cells.rb +0 -33
- data/manual/table/position.rb +0 -29
- data/manual/table/row_colors.rb +0 -20
- data/manual/table/span.rb +0 -30
- data/manual/table/style.rb +0 -22
- data/manual/table/table.rb +0 -52
- data/manual/table/width.rb +0 -27
- data/manual/text/alignment.rb +0 -44
- data/manual/text/color.rb +0 -24
- data/manual/text/column_box.rb +0 -32
- data/manual/text/fallback_fonts.rb +0 -37
- data/manual/text/font.rb +0 -41
- data/manual/text/font_size.rb +0 -45
- data/manual/text/font_style.rb +0 -23
- data/manual/text/formatted_callbacks.rb +0 -60
- data/manual/text/formatted_text.rb +0 -54
- data/manual/text/free_flowing_text.rb +0 -51
- data/manual/text/group.rb +0 -31
- data/manual/text/inline.rb +0 -43
- data/manual/text/kerning_and_character_spacing.rb +0 -39
- data/manual/text/leading.rb +0 -25
- data/manual/text/line_wrapping.rb +0 -41
- data/manual/text/paragraph_indentation.rb +0 -26
- data/manual/text/positioned_text.rb +0 -38
- data/manual/text/registering_families.rb +0 -48
- data/manual/text/rendering_and_color.rb +0 -37
- data/manual/text/right_to_left_text.rb +0 -43
- data/manual/text/rotation.rb +0 -43
- data/manual/text/single_usage.rb +0 -37
- data/manual/text/text.rb +0 -75
- data/manual/text/text_box_excess.rb +0 -32
- data/manual/text/text_box_extensions.rb +0 -45
- data/manual/text/text_box_overflow.rb +0 -44
- data/manual/text/utf8.rb +0 -28
- data/manual/text/win_ansi_charset.rb +0 -59
- data/spec/acceptance/png.rb +0 -23
- data/spec/column_box_spec.rb +0 -65
- data/spec/extensions/encoding_helpers.rb +0 -9
- data/spec/font_metric_cache_spec.rb +0 -52
- data/spec/image_handler_spec.rb +0 -54
- data/spec/soft_mask_spec.rb +0 -117
- data/spec/table/span_dummy_spec.rb +0 -17
data/spec/extensions/mocha.rb
CHANGED
data/spec/font_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
-
require '
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
require 'iconv'
|
5
5
|
|
6
|
-
describe "Font behavior" do
|
6
|
+
describe "Font behavior" do
|
7
7
|
|
8
8
|
it "should default to Helvetica if no font is specified" do
|
9
9
|
@pdf = Prawn::Document.new
|
@@ -12,32 +12,6 @@ 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
|
-
|
41
15
|
describe "#width_of" do
|
42
16
|
it "should take character spacing into account" do
|
43
17
|
create_pdf
|
@@ -50,7 +24,7 @@ describe "#width_of" do
|
|
50
24
|
it "should exclude newlines" do
|
51
25
|
create_pdf
|
52
26
|
# Use a TTF font that has a non-zero width for \n
|
53
|
-
@pdf.font("#{Prawn::
|
27
|
+
@pdf.font("#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf")
|
54
28
|
|
55
29
|
@pdf.width_of("\nhello world\n").should ==
|
56
30
|
@pdf.width_of("hello world")
|
@@ -64,8 +38,8 @@ describe "#width_of" do
|
|
64
38
|
@pdf.font("Helvetica", :style => :bold) {
|
65
39
|
@bold_hello = @pdf.width_of("hello")
|
66
40
|
}
|
67
|
-
|
68
|
-
inline_bold_hello.should
|
41
|
+
|
42
|
+
inline_bold_hello.should.be > normal_hello
|
69
43
|
inline_bold_hello.should == @bold_hello
|
70
44
|
end
|
71
45
|
|
@@ -79,12 +53,6 @@ describe "#width_of" do
|
|
79
53
|
|
80
54
|
styled_bold_hello.should == @bold_hello
|
81
55
|
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
|
88
56
|
end
|
89
57
|
|
90
58
|
describe "#font_size" do
|
@@ -97,38 +65,38 @@ end
|
|
97
65
|
|
98
66
|
describe "font style support" do
|
99
67
|
before(:each) { create_pdf }
|
100
|
-
|
68
|
+
|
101
69
|
it "should complain if there is no @current_page" do
|
102
70
|
pdf_without_page = Prawn::Document.new(:skip_page_creation => true)
|
103
71
|
|
104
72
|
lambda{ pdf_without_page.font "Helvetica" }.
|
105
|
-
should
|
73
|
+
should.raise(Prawn::Errors::NotOnPage)
|
106
74
|
end
|
107
|
-
|
108
|
-
it "should allow specifying font style by style name and font family" do
|
75
|
+
|
76
|
+
it "should allow specifying font style by style name and font family" do
|
109
77
|
@pdf.font "Courier", :style => :bold
|
110
|
-
@pdf.text "In Courier bold"
|
111
|
-
|
78
|
+
@pdf.text "In Courier bold"
|
79
|
+
|
112
80
|
@pdf.font "Courier", :style => :bold_italic
|
113
|
-
@pdf.text "In Courier bold-italic"
|
114
|
-
|
81
|
+
@pdf.text "In Courier bold-italic"
|
82
|
+
|
115
83
|
@pdf.font "Courier", :style => :italic
|
116
|
-
@pdf.text "In Courier italic"
|
117
|
-
|
84
|
+
@pdf.text "In Courier italic"
|
85
|
+
|
118
86
|
@pdf.font "Courier", :style => :normal
|
119
|
-
@pdf.text "In Normal Courier"
|
120
|
-
|
87
|
+
@pdf.text "In Normal Courier"
|
88
|
+
|
121
89
|
@pdf.font "Helvetica"
|
122
|
-
@pdf.text "In Normal Helvetica"
|
123
|
-
|
90
|
+
@pdf.text "In Normal Helvetica"
|
91
|
+
|
124
92
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
125
|
-
text.font_settings.map { |e| e[:name] }.should ==
|
126
|
-
[:"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique",
|
93
|
+
text.font_settings.map { |e| e[:name] }.should ==
|
94
|
+
[:"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique",
|
127
95
|
:Courier, :Helvetica]
|
128
96
|
end
|
129
97
|
|
130
98
|
it "should allow font familes to be defined in a single dfont" do
|
131
|
-
file = "#{Prawn::
|
99
|
+
file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
|
132
100
|
@pdf.font_families["Action Man"] = {
|
133
101
|
:normal => { :file => file, :font => "ActionMan" },
|
134
102
|
:italic => { :file => file, :font => "ActionMan-Italic" },
|
@@ -144,39 +112,24 @@ describe "font style support" do
|
|
144
112
|
name = name.sub(/\w+\+/, "subset+")
|
145
113
|
name.should == "subset+ActionMan-Italic"
|
146
114
|
end
|
147
|
-
|
148
|
-
it "should accept Pathname objects for font files" do
|
149
|
-
file = Pathname.new( "#{Prawn::DATADIR}/fonts/Chalkboard.ttf" )
|
150
|
-
@pdf.font_families["Chalkboard"] = {
|
151
|
-
:normal => file
|
152
|
-
}
|
153
|
-
|
154
|
-
@pdf.font "Chalkboard"
|
155
|
-
@pdf.text "In Chalkboard"
|
156
|
-
|
157
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
158
|
-
name = text.font_settings.map { |e| e[:name] }.first.to_s
|
159
|
-
name = name.sub(/\w+\+/, "subset+")
|
160
|
-
name.should == "subset+Chalkboard"
|
161
|
-
end
|
162
115
|
end
|
163
116
|
|
164
117
|
describe "Transactional font handling" do
|
165
118
|
before(:each) { create_pdf }
|
166
|
-
|
119
|
+
|
167
120
|
it "should allow setting of size directly when font is created" do
|
168
121
|
@pdf.font "Courier", :size => 16
|
169
|
-
@pdf.font_size.should == 16
|
122
|
+
@pdf.font_size.should == 16
|
170
123
|
end
|
171
|
-
|
124
|
+
|
172
125
|
it "should allow temporary setting of a new font using a transaction" do
|
173
126
|
@pdf.font "Helvetica", :size => 12
|
174
|
-
|
127
|
+
|
175
128
|
@pdf.font "Courier", :size => 16 do
|
176
129
|
@pdf.font.name.should == "Courier"
|
177
130
|
@pdf.font_size.should == 16
|
178
131
|
end
|
179
|
-
|
132
|
+
|
180
133
|
@pdf.font.name.should == "Helvetica"
|
181
134
|
@pdf.font_size.should == 12
|
182
135
|
end
|
@@ -191,76 +144,75 @@ describe "Transactional font handling" do
|
|
191
144
|
|
192
145
|
@pdf.font_size.should == 12
|
193
146
|
end
|
194
|
-
|
147
|
+
|
195
148
|
end
|
196
149
|
|
197
150
|
describe "Document#page_fonts" do
|
198
|
-
before(:each) { create_pdf }
|
199
|
-
|
151
|
+
before(:each) { create_pdf }
|
152
|
+
|
200
153
|
it "should register fonts properly by page" do
|
201
154
|
@pdf.font "Courier"; @pdf.text("hello")
|
202
155
|
@pdf.font "Helvetica"; @pdf.text("hello")
|
203
156
|
@pdf.font "Times-Roman"; @pdf.text("hello")
|
204
157
|
["Courier","Helvetica","Times-Roman"].each { |f|
|
205
158
|
page_should_include_font(f)
|
206
|
-
}
|
207
|
-
|
208
|
-
@pdf.start_new_page
|
159
|
+
}
|
160
|
+
|
161
|
+
@pdf.start_new_page
|
209
162
|
@pdf.font "Helvetica"; @pdf.text("hello")
|
210
163
|
page_should_include_font("Helvetica")
|
211
164
|
page_should_not_include_font("Courier")
|
212
165
|
page_should_not_include_font("Times-Roman")
|
213
|
-
end
|
214
|
-
|
166
|
+
end
|
167
|
+
|
215
168
|
def page_includes_font?(font)
|
216
169
|
@pdf.page.fonts.values.map { |e| e.data[:BaseFont] }.include?(font.to_sym)
|
217
|
-
end
|
218
|
-
|
219
|
-
def page_should_include_font(font)
|
220
|
-
|
221
|
-
|
222
|
-
|
170
|
+
end
|
171
|
+
|
172
|
+
def page_should_include_font(font)
|
173
|
+
assert_block("Expected page to include font: #{font}") do
|
174
|
+
page_includes_font?(font)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
223
178
|
def page_should_not_include_font(font)
|
224
|
-
|
179
|
+
assert_block("Did not expect page to include font: #{font}") do
|
180
|
+
not page_includes_font?(font)
|
181
|
+
end
|
225
182
|
end
|
226
|
-
|
183
|
+
|
227
184
|
end
|
228
|
-
|
185
|
+
|
229
186
|
describe "AFM fonts" do
|
230
|
-
|
231
|
-
|
187
|
+
|
188
|
+
setup do
|
232
189
|
create_pdf
|
233
190
|
@times = @pdf.find_font "Times-Roman"
|
191
|
+
@iconv = ::Iconv.new('Windows-1252', 'utf-8')
|
234
192
|
end
|
235
|
-
|
193
|
+
|
236
194
|
it "should calculate string width taking into account accented characters" do
|
237
|
-
|
238
|
-
@times.compute_width_of(input, :size => 12).should == @times.compute_width_of("e", :size => 12)
|
195
|
+
@times.compute_width_of(@iconv.iconv("é"), :size => 12).should == @times.compute_width_of("e", :size => 12)
|
239
196
|
end
|
240
|
-
|
197
|
+
|
241
198
|
it "should calculate string width taking into account kerning pairs" do
|
242
|
-
@times.compute_width_of(
|
243
|
-
@times.compute_width_of(
|
244
|
-
|
245
|
-
input = win1252_string("T\xF6") # Tö in win-1252
|
246
|
-
@times.compute_width_of(input, :size => 12, :kerning => true).should == 12.372
|
199
|
+
@times.compute_width_of(@iconv.iconv("To"), :size => 12).should == 13.332
|
200
|
+
@times.compute_width_of(@iconv.iconv("To"), :size => 12, :kerning => true).should == 12.372
|
201
|
+
@times.compute_width_of(@iconv.iconv("Tö"), :size => 12, :kerning => true).should == 12.372
|
247
202
|
end
|
248
203
|
|
249
204
|
it "should encode text without kerning by default" do
|
250
|
-
@times.encode_text(
|
251
|
-
|
252
|
-
@times.encode_text(
|
253
|
-
@times.encode_text(
|
254
|
-
@times.encode_text(win1252_string("Technology...")).should == [[0, "Technology..."]]
|
205
|
+
@times.encode_text(@iconv.iconv("To")).should == [[0, "To"]]
|
206
|
+
@times.encode_text(@iconv.iconv("Télé")).should == [[0, @iconv.iconv("Télé")]]
|
207
|
+
@times.encode_text(@iconv.iconv("Technology")).should == [[0, "Technology"]]
|
208
|
+
@times.encode_text(@iconv.iconv("Technology...")).should == [[0, "Technology..."]]
|
255
209
|
end
|
256
210
|
|
257
211
|
it "should encode text with kerning if requested" do
|
258
|
-
@times.encode_text(
|
259
|
-
|
260
|
-
|
261
|
-
@times.encode_text(
|
262
|
-
@times.encode_text(win1252_string("Technology"), :kerning => true).should == [[0, ["T", 70, "echnology"]]]
|
263
|
-
@times.encode_text(win1252_string("Technology..."), :kerning => true).should == [[0, ["T", 70, "echnology", 65, "..."]]]
|
212
|
+
@times.encode_text(@iconv.iconv("To"), :kerning => true).should == [[0, ["T", 80, "o"]]]
|
213
|
+
@times.encode_text(@iconv.iconv("Télé"), :kerning => true).should == [[0, ["T", 70, @iconv.iconv("élé")]]]
|
214
|
+
@times.encode_text(@iconv.iconv("Technology"), :kerning => true).should == [[0, ["T", 70, "echnology"]]]
|
215
|
+
@times.encode_text(@iconv.iconv("Technology..."), :kerning => true).should == [[0, ["T", 70, "echnology", 65, "..."]]]
|
264
216
|
end
|
265
217
|
|
266
218
|
describe "when normalizing encoding" do
|
@@ -268,13 +220,13 @@ describe "AFM fonts" do
|
|
268
220
|
it "should not modify the original string when normalize_encoding() is used" do
|
269
221
|
original = "Foo"
|
270
222
|
normalized = @times.normalize_encoding(original)
|
271
|
-
original.equal?(normalized)
|
223
|
+
assert ! original.equal?(normalized)
|
272
224
|
end
|
273
225
|
|
274
226
|
it "should modify the original string when normalize_encoding!() is used" do
|
275
227
|
original = "Foo"
|
276
228
|
normalized = @times.normalize_encoding!(original)
|
277
|
-
original.equal?(normalized)
|
229
|
+
assert original.equal?(normalized)
|
278
230
|
end
|
279
231
|
|
280
232
|
end
|
@@ -284,7 +236,7 @@ describe "AFM fonts" do
|
|
284
236
|
font_dict = zapf.send(:register, nil)
|
285
237
|
font_dict.data[:Encoding].should == nil
|
286
238
|
end
|
287
|
-
|
239
|
+
|
288
240
|
end
|
289
241
|
|
290
242
|
describe "#glyph_present" do
|
@@ -292,52 +244,50 @@ describe "#glyph_present" do
|
|
292
244
|
|
293
245
|
it "should return true when present in an AFM font" do
|
294
246
|
font = @pdf.find_font("Helvetica")
|
295
|
-
font.glyph_present?("H").should
|
247
|
+
font.glyph_present?("H").should.be true
|
296
248
|
end
|
297
249
|
|
298
250
|
it "should return false when absent in an AFM font" do
|
299
251
|
font = @pdf.find_font("Helvetica")
|
300
|
-
font.glyph_present?("再").should
|
252
|
+
font.glyph_present?("再").should.be false
|
301
253
|
end
|
302
254
|
|
303
255
|
it "should return true when present in a TTF font" do
|
304
|
-
font = @pdf.find_font("#{Prawn::
|
305
|
-
font.glyph_present?("H").should
|
256
|
+
font = @pdf.find_font("#{Prawn::BASEDIR}/data/fonts/Activa.ttf")
|
257
|
+
font.glyph_present?("H").should.be true
|
306
258
|
end
|
307
259
|
|
308
260
|
it "should return false when absent in a TTF font" do
|
309
|
-
font = @pdf.find_font("#{Prawn::
|
310
|
-
font.glyph_present?("再").should
|
261
|
+
font = @pdf.find_font("#{Prawn::BASEDIR}/data/fonts/Activa.ttf")
|
262
|
+
font.glyph_present?("再").should.be false
|
311
263
|
|
312
|
-
font = @pdf.find_font("#{Prawn::
|
313
|
-
font.glyph_present?("€").should
|
264
|
+
font = @pdf.find_font("#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf")
|
265
|
+
font.glyph_present?("€").should.be false
|
314
266
|
end
|
315
267
|
end
|
316
268
|
|
317
269
|
describe "TTF fonts" do
|
318
|
-
|
319
|
-
|
270
|
+
|
271
|
+
setup do
|
320
272
|
create_pdf
|
321
|
-
@activa = @pdf.find_font "#{Prawn::
|
273
|
+
@activa = @pdf.find_font "#{Prawn::BASEDIR}/data/fonts/Activa.ttf"
|
322
274
|
end
|
323
|
-
|
275
|
+
|
324
276
|
it "should calculate string width taking into account accented characters" do
|
325
277
|
@activa.compute_width_of("é", :size => 12).should == @activa.compute_width_of("e", :size => 12)
|
326
278
|
end
|
327
|
-
|
279
|
+
|
328
280
|
it "should calculate string width taking into account kerning pairs" do
|
329
281
|
@activa.compute_width_of("To", :size => 12).should == 15.228
|
330
282
|
@activa.compute_width_of("To", :size => 12, :kerning => true).should == 12.996
|
331
283
|
end
|
332
|
-
|
284
|
+
|
333
285
|
it "should encode text without kerning by default" do
|
334
286
|
@activa.encode_text("To").should == [[0, "To"]]
|
335
287
|
|
336
|
-
tele = "T\216l\216"
|
337
|
-
|
338
|
-
|
339
|
-
result[0][0].should == 0
|
340
|
-
result[0][1].bytes.to_a.should == tele.bytes.to_a
|
288
|
+
tele = (RUBY_VERSION < '1.9') ? "T\216l\216" :
|
289
|
+
"T\216l\216".force_encoding("US-ASCII")
|
290
|
+
@activa.encode_text("Télé").should == [[0, tele]]
|
341
291
|
|
342
292
|
@activa.encode_text("Technology").should == [[0, "Technology"]]
|
343
293
|
@activa.encode_text("Technology...").should == [[0, "Technology..."]]
|
@@ -370,33 +320,33 @@ describe "TTF fonts" do
|
|
370
320
|
it "should not modify the original string when normalize_encoding() is used" do
|
371
321
|
original = "Foo"
|
372
322
|
normalized = @activa.normalize_encoding(original)
|
373
|
-
original.equal?(normalized)
|
323
|
+
assert ! original.equal?(normalized)
|
374
324
|
end
|
375
325
|
|
376
326
|
it "should modify the original string when normalize_encoding!() is used" do
|
377
327
|
original = "Foo"
|
378
328
|
normalized = @activa.normalize_encoding!(original)
|
379
|
-
original.equal?(normalized)
|
329
|
+
assert original.equal?(normalized)
|
380
330
|
end
|
381
331
|
|
382
332
|
end
|
383
333
|
|
384
334
|
describe "when used with snapshots or transactions" do
|
385
|
-
|
335
|
+
|
386
336
|
it "should allow TTF fonts to be used alongside document transactions" do
|
387
337
|
lambda {
|
388
338
|
Prawn::Document.new do
|
389
|
-
font "#{Prawn::
|
339
|
+
font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
|
390
340
|
text "Hi there"
|
391
341
|
transaction { text "Nice, thank you" }
|
392
342
|
end
|
393
|
-
}.
|
343
|
+
}.should.not.raise
|
394
344
|
end
|
395
345
|
|
396
346
|
it "should allow TTF fonts to be used inside transactions" do
|
397
347
|
pdf = Prawn::Document.new do
|
398
348
|
transaction do
|
399
|
-
font "#{Prawn::
|
349
|
+
font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
|
400
350
|
text "Hi there"
|
401
351
|
end
|
402
352
|
end
|
@@ -408,13 +358,13 @@ describe "TTF fonts" do
|
|
408
358
|
end
|
409
359
|
|
410
360
|
end
|
411
|
-
|
361
|
+
|
412
362
|
end
|
413
363
|
|
414
364
|
describe "DFont fonts" do
|
415
|
-
|
365
|
+
setup do
|
416
366
|
create_pdf
|
417
|
-
@file = "#{Prawn::
|
367
|
+
@file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
|
418
368
|
end
|
419
369
|
|
420
370
|
it "should list all named fonts" do
|
@@ -444,16 +394,16 @@ describe "DFont fonts" do
|
|
444
394
|
it "should cache font object based on selected font" do
|
445
395
|
f1 = @pdf.find_font(@file, :font => "ActionMan")
|
446
396
|
f2 = @pdf.find_font(@file, :font => "ActionMan-Bold")
|
447
|
-
|
448
|
-
@pdf.find_font(@file, :font => "ActionMan").object_id
|
449
|
-
@pdf.find_font(@file, :font => "ActionMan-Bold").object_id
|
397
|
+
assert_not_equal f1.object_id, f2.object_id
|
398
|
+
assert_equal f1.object_id, @pdf.find_font(@file, :font => "ActionMan").object_id
|
399
|
+
assert_equal f2.object_id, @pdf.find_font(@file, :font => "ActionMan-Bold").object_id
|
450
400
|
end
|
451
401
|
end
|
452
402
|
|
453
403
|
describe "#character_count(text)" do
|
454
404
|
it "should work on TTF fonts" do
|
455
405
|
create_pdf
|
456
|
-
@pdf.font("#{Prawn::
|
406
|
+
@pdf.font("#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf")
|
457
407
|
@pdf.font.character_count("こんにちは世界").should == 7
|
458
408
|
@pdf.font.character_count("Hello, world!").should == 13
|
459
409
|
end
|