prawn 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. data/Rakefile +3 -1
  2. data/data/fonts/Action Man.dfont +0 -0
  3. data/examples/general/measurement_units.rb +2 -2
  4. data/examples/graphics/image_flow.rb +2 -2
  5. data/examples/graphics/stroke_bounds.rb +1 -1
  6. data/examples/m17n/win_ansi_charset.rb +3 -3
  7. data/examples/text/dfont.rb +49 -0
  8. data/examples/text/flowing_text_with_header_and_footer.rb +2 -48
  9. data/examples/text/font_calculations.rb +7 -6
  10. data/examples/text/font_size.rb +4 -4
  11. data/examples/text/text_flow.rb +1 -1
  12. data/lib/prawn.rb +6 -3
  13. data/lib/prawn/compatibility.rb +12 -17
  14. data/lib/prawn/document.rb +10 -10
  15. data/lib/prawn/document/internals.rb +8 -3
  16. data/lib/prawn/document/text.rb +39 -57
  17. data/lib/prawn/document/text/box.rb +1 -2
  18. data/lib/prawn/document/text/wrapping.rb +59 -0
  19. data/lib/prawn/errors.rb +0 -8
  20. data/lib/prawn/font.rb +192 -277
  21. data/lib/prawn/font/afm.rb +199 -0
  22. data/lib/prawn/font/dfont.rb +31 -0
  23. data/lib/prawn/font/ttf.rb +318 -0
  24. data/lib/prawn/graphics.rb +7 -2
  25. data/lib/prawn/images/png.rb +1 -1
  26. data/lib/prawn/reference.rb +7 -4
  27. data/spec/font_spec.rb +154 -61
  28. data/spec/text_spec.rb +47 -6
  29. data/vendor/pdf-inspector/lib/pdf/inspector.rb +1 -1
  30. data/vendor/ttfunk/example.rb +42 -2
  31. data/vendor/ttfunk/lib/ttfunk.rb +96 -42
  32. data/vendor/ttfunk/lib/ttfunk/directory.rb +17 -0
  33. data/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +88 -0
  34. data/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +69 -0
  35. data/vendor/ttfunk/lib/ttfunk/reader.rb +44 -0
  36. data/vendor/ttfunk/lib/ttfunk/resource_file.rb +78 -0
  37. data/vendor/ttfunk/lib/ttfunk/subset.rb +18 -0
  38. data/vendor/ttfunk/lib/ttfunk/subset/base.rb +141 -0
  39. data/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +46 -0
  40. data/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +48 -0
  41. data/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +63 -0
  42. data/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +51 -0
  43. data/vendor/ttfunk/lib/ttfunk/subset_collection.rb +72 -0
  44. data/vendor/ttfunk/lib/ttfunk/table.rb +37 -18
  45. data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +24 -84
  46. data/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +54 -0
  47. data/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +126 -0
  48. data/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +79 -0
  49. data/vendor/ttfunk/lib/ttfunk/table/glyf.rb +64 -0
  50. data/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +81 -0
  51. data/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +37 -0
  52. data/vendor/ttfunk/lib/ttfunk/table/head.rb +38 -19
  53. data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +35 -21
  54. data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +40 -13
  55. data/vendor/ttfunk/lib/ttfunk/table/kern.rb +69 -38
  56. data/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +62 -0
  57. data/vendor/ttfunk/lib/ttfunk/table/loca.rb +43 -0
  58. data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +34 -11
  59. data/vendor/ttfunk/lib/ttfunk/table/name.rb +109 -42
  60. data/vendor/ttfunk/lib/ttfunk/table/os2.rb +78 -0
  61. data/vendor/ttfunk/lib/ttfunk/table/post.rb +91 -0
  62. data/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +43 -0
  63. data/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +35 -0
  64. data/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +23 -0
  65. data/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +17 -0
  66. data/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +17 -0
  67. data/vendor/ttfunk/lib/ttfunk/table/simple.rb +14 -0
  68. metadata +54 -25
  69. data/examples/table/addressbook.csv +0 -6
  70. data/examples/table/cell.rb +0 -40
  71. data/examples/table/currency.csv +0 -1834
  72. data/examples/table/fancy_table.rb +0 -62
  73. data/examples/table/ruport_formatter.rb +0 -53
  74. data/examples/table/table.rb +0 -51
  75. data/examples/table/table_alignment.rb +0 -18
  76. data/examples/table/table_border_color.rb +0 -17
  77. data/examples/table/table_colspan.rb +0 -19
  78. data/examples/table/table_header_color.rb +0 -19
  79. data/examples/table/table_header_underline.rb +0 -15
  80. data/lib/prawn/document/table.rb +0 -338
  81. data/lib/prawn/font/cmap.rb +0 -59
  82. data/lib/prawn/font/metrics.rb +0 -378
  83. data/lib/prawn/font/wrapping.rb +0 -47
  84. data/lib/prawn/graphics/cell.rb +0 -264
  85. data/spec/metrics_spec.rb +0 -62
  86. data/spec/table_spec.rb +0 -179
  87. data/vendor/ttfunk/lib/ttfunk/table/directory.rb +0 -25
@@ -7,7 +7,6 @@
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
9
  require "enumerator"
10
- require "prawn/graphics/cell"
11
10
  require "prawn/graphics/color"
12
11
 
13
12
  module Prawn
@@ -84,7 +83,13 @@ module Prawn
84
83
  add_content("#{width} w")
85
84
  end
86
85
 
87
- # The current line thickness
86
+ # When called without an argument, returns the current line thickness.
87
+ # When called with an argument, sets the line thickness to the specified
88
+ # value (in PDF points)
89
+ #
90
+ # pdf.line_width #=> 1
91
+ # pdf.line_width(5)
92
+ # pdf.line_width #=> 5
88
93
  #
89
94
  def line_width(width=nil)
90
95
  if width
@@ -23,7 +23,7 @@ module Prawn
23
23
 
24
24
  # Process a new PNG image
25
25
  #
26
- # <tt>:data</tt>:: A string containing a full PNG file
26
+ # <tt>data</tt>:: A string containing a full PNG file
27
27
  #
28
28
  def initialize(data)
29
29
  data = StringIO.new(data.dup)
@@ -15,14 +15,16 @@ module Prawn
15
15
  attr_accessor :gen, :data, :offset
16
16
  attr_reader :identifier, :stream
17
17
 
18
- def initialize(id,data)
18
+ def initialize(id, data, &block)
19
19
  @identifier = id
20
20
  @gen = 0
21
21
  @data = data
22
22
  @compressed = false
23
+ @on_encode = block
23
24
  end
24
25
 
25
26
  def object
27
+ @on_encode.call(self) if @on_encode
26
28
  output = "#{@identifier} #{gen} obj\n" <<
27
29
  Prawn::PdfObject(data) << "\n"
28
30
  if @stream
@@ -43,14 +45,15 @@ module Prawn
43
45
  def compress_stream
44
46
  @stream = Zlib::Deflate.deflate(@stream)
45
47
  @data[:Filter] = :FlateDecode
48
+ @data[:Length] ||= @stream.length
46
49
  @compressed = true
47
50
  end
48
51
  end
49
-
52
+
50
53
  module_function
51
54
 
52
- def Reference(*args) #:nodoc:
53
- Reference.new(*args)
55
+ def Reference(*args, &block) #:nodoc:
56
+ Reference.new(*args, &block)
54
57
  end
55
58
 
56
59
  end
data/spec/font_spec.rb CHANGED
@@ -1,46 +1,15 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+ require 'iconv'
4
5
 
5
- describe "Font Metrics" do
6
+ describe "Font behavior" do
6
7
 
7
8
  it "should default to Helvetica if no font is specified" do
8
9
  @pdf = Prawn::Document.new
9
- @pdf.font.metrics.should == Prawn::Font::Metrics["Helvetica"]
10
+ @pdf.font.name.should == "Helvetica"
10
11
  end
11
12
 
12
- it "should use the currently set font for font_metrics" do
13
- @pdf = Prawn::Document.new
14
- @pdf.font "Courier"
15
- @pdf.font.metrics.should == Prawn::Font::Metrics["Courier"]
16
-
17
- comicsans = "#{Prawn::BASEDIR}/data/fonts/comicsans.ttf"
18
- @pdf.font(comicsans)
19
- @pdf.font.metrics.should == Prawn::Font::Metrics[comicsans]
20
- end
21
-
22
- it "should wrap text" do
23
- @pdf = Prawn::Document.new
24
- @pdf.font "Courier"
25
- @pdf.font.metrics.naive_wrap("Please wrap this text about HERE. More text that should be wrapped", 220, @pdf.font.size).should ==
26
- "Please wrap this text about\nHERE. More text that should be\nwrapped"
27
- end
28
-
29
- it "should respect end of line when wrapping text" do
30
- @pdf = Prawn::Document.new
31
- @pdf.font "Courier"
32
- text = "Please wrap only before\nTHIS word. Don't wrap this"
33
- @pdf.font.metrics.naive_wrap(text, 220, @pdf.font.size).should == text
34
- end
35
-
36
- it "should respect end of line when wrapping text and mode is set to 'character'" do
37
- @pdf = Prawn::Document.new
38
- @pdf.font "Courier"
39
- opts = {:mode => :character}
40
- @pdf.font.metrics.naive_wrap("You can wrap this text HERE", 180, @pdf.font.size, opts).should ==
41
- "You can wrap this text HE\nRE"
42
- end
43
-
44
13
  end
45
14
 
46
15
  describe "font style support" do
@@ -66,8 +35,26 @@ describe "font style support" do
66
35
  text.font_settings.map { |e| e[:name] }.should ==
67
36
  [:"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique",
68
37
  :Courier, :Helvetica]
69
- end
70
-
38
+ end
39
+
40
+ it "should allow font familes to be defined in a single dfont" do
41
+ file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
42
+ @pdf.font_families["Action Man"] = {
43
+ :normal => { :file => file, :font => "ActionMan" },
44
+ :italic => { :file => file, :font => "ActionMan-Italic" },
45
+ :bold => { :file => file, :font => "ActionMan-Bold" },
46
+ :bold_italic => { :file => file, :font => "ActionMan-BoldItalic" }
47
+ }
48
+
49
+ @pdf.font "Action Man", :style => :italic
50
+ @pdf.text "In ActionMan-Italic"
51
+
52
+ text = PDF::Inspector::Text.analyze(@pdf.render)
53
+ name = text.font_settings.map { |e| e[:name] }.first
54
+ name = name.unpack("n*")[2..-1].pack("U*")
55
+ name = name.sub(/\w+\+/, "subset+")
56
+ name.should == "subset+ActionMan-Italic"
57
+ end
71
58
  end
72
59
 
73
60
  describe "Transactional font handling" do
@@ -75,51 +62,54 @@ describe "Transactional font handling" do
75
62
 
76
63
  it "should allow setting of size directly when font is created" do
77
64
  @pdf.font "Courier", :size => 16
78
- @pdf.font.size.should == 16
65
+ @pdf.font_size.should == 16
79
66
  end
80
67
 
81
68
  it "should allow temporary setting of a new font using a transaction" do
82
- original = @pdf.font
69
+ @pdf.font "Helvetica", :size => 12
83
70
 
84
71
  @pdf.font "Courier", :size => 16 do
85
72
  @pdf.font.name.should == "Courier"
86
- @pdf.font.size.should == 16
73
+ @pdf.font_size.should == 16
87
74
  end
88
75
 
89
- @pdf.font.should == original
76
+ @pdf.font.name.should == "Helvetica"
77
+ @pdf.font_size.should == 12
78
+ end
79
+
80
+ it "should mask font size when using a transacation" do
81
+ @pdf.font "Courier", :size => 16 do
82
+ @pdf.font_size.should == 16
83
+ end
84
+
85
+ @pdf.font "Times-Roman"
86
+ @pdf.font "Courier"
87
+
88
+ @pdf.font_size.should == 12
90
89
  end
91
90
 
92
91
  end
93
92
 
94
-
95
93
  describe "Document#page_fonts" do
96
94
  before(:each) { create_pdf }
97
95
 
98
- it "should register the current font when changing pages" do
99
- @pdf.font "Courier"
100
- page_should_include_font("Courier")
101
- @pdf.start_new_page
102
- page_should_include_font("Courier")
103
- end
104
-
105
96
  it "should register fonts properly by page" do
106
- @pdf.font "Courier"
107
- @pdf.font "Helvetica"
108
- @pdf.font "Times-Roman"
97
+ @pdf.font "Courier"; @pdf.text("hello")
98
+ @pdf.font "Helvetica"; @pdf.text("hello")
99
+ @pdf.font "Times-Roman"; @pdf.text("hello")
109
100
  ["Courier","Helvetica","Times-Roman"].each { |f|
110
101
  page_should_include_font(f)
111
102
  }
112
103
 
113
104
  @pdf.start_new_page
114
- @pdf.font "Helvetica"
115
- ["Times-Roman","Helvetica"].each { |f|
116
- page_should_include_font(f)
117
- }
118
- page_should_not_include_font("Courier")
105
+ @pdf.font "Helvetica"; @pdf.text("hello")
106
+ page_should_include_font("Helvetica")
107
+ page_should_not_include_font("Courier")
108
+ page_should_not_include_font("Times-Roman")
119
109
  end
120
110
 
121
- def page_includes_font?(font)
122
- @pdf.page_fonts.values.map { |e| e.data[:BaseFont] }.include?(font.to_sym)
111
+ def page_includes_font?(font)
112
+ @pdf.page_fonts.values.map { |e| e.data[:BaseFont] }.include?(font.to_sym)
123
113
  end
124
114
 
125
115
  def page_should_include_font(font)
@@ -136,6 +126,109 @@ describe "Document#page_fonts" do
136
126
 
137
127
  end
138
128
 
139
-
140
-
141
-
129
+ describe "AFM fonts" do
130
+
131
+ setup do
132
+ create_pdf
133
+ @times = @pdf.find_font "Times-Roman"
134
+ @iconv = ::Iconv.new('Windows-1252', 'utf-8')
135
+ end
136
+
137
+ it "should calculate string width taking into account accented characters" do
138
+ @times.width_of(@iconv.iconv("é"), :size => 12).should == @times.width_of("e", :size => 12)
139
+ end
140
+
141
+ it "should calculate string width taking into account kerning pairs" do
142
+ @times.width_of(@iconv.iconv("To"), :size => 12).should == 13.332
143
+ @times.width_of(@iconv.iconv("To"), :size => 12, :kerning => true).should == 12.372
144
+ @times.width_of(@iconv.iconv("Tö"), :size => 12, :kerning => true).should == 12.372
145
+ end
146
+
147
+ it "should encode text without kerning by default" do
148
+ @times.encode_text(@iconv.iconv("To")).should == [[0, "To"]]
149
+ @times.encode_text(@iconv.iconv("Télé")).should == [[0, @iconv.iconv("Télé")]]
150
+ @times.encode_text(@iconv.iconv("Technology")).should == [[0, "Technology"]]
151
+ @times.encode_text(@iconv.iconv("Technology...")).should == [[0, "Technology..."]]
152
+ end
153
+
154
+ it "should encode text with kerning if requested" do
155
+ @times.encode_text(@iconv.iconv("To"), :kerning => true).should == [[0, ["T", 80, "o"]]]
156
+ @times.encode_text(@iconv.iconv("Télé"), :kerning => true).should == [[0, ["T", 70, @iconv.iconv("élé")]]]
157
+ @times.encode_text(@iconv.iconv("Technology"), :kerning => true).should == [[0, ["T", 70, "echnology"]]]
158
+ @times.encode_text(@iconv.iconv("Technology..."), :kerning => true).should == [[0, ["T", 70, "echnology", 65, "..."]]]
159
+ end
160
+
161
+ end
162
+
163
+ describe "TTF fonts" do
164
+
165
+ setup do
166
+ create_pdf
167
+ @activa = @pdf.find_font "#{Prawn::BASEDIR}/data/fonts/Activa.ttf"
168
+ end
169
+
170
+ it "should calculate string width taking into account accented characters" do
171
+ @activa.width_of("é", :size => 12).should == @activa.width_of("e", :size => 12)
172
+ end
173
+
174
+ it "should calculate string width taking into account kerning pairs" do
175
+ @activa.width_of("To", :size => 12).should == 15.228
176
+ @activa.width_of("To", :size => 12, :kerning => true).should == 12.996
177
+ end
178
+
179
+ it "should encode text without kerning by default" do
180
+ @activa.encode_text("To").should == [[0, "To"]]
181
+ @activa.encode_text("Télé").should == [[0, "T\216l\216"]]
182
+ @activa.encode_text("Technology").should == [[0, "Technology"]]
183
+ @activa.encode_text("Technology...").should == [[0, "Technology..."]]
184
+ @activa.encode_text("Teχnology...").should == [[0, "Te"], [1, "!"], [0, "nology..."]]
185
+ end
186
+
187
+ it "should encode text with kerning if requested" do
188
+ @activa.encode_text("To", :kerning => true).should == [[0, ["T", 186.0, "o"]]]
189
+ @activa.encode_text("To", :kerning => true).should == [[0, ["T", 186.0, "o"]]]
190
+ @activa.encode_text("Technology", :kerning => true).should == [[0, ["T", 186.0, "echnology"]]]
191
+ @activa.encode_text("Technology...", :kerning => true).should == [[0, ["T", 186.0, "echnology", 88.0, "..."]]]
192
+ @activa.encode_text("Teχnology...", :kerning => true).should == [[0, ["T", 186.0, "e"]], [1, "!"], [0, ["nology", 88.0, "..."]]]
193
+ end
194
+
195
+ end
196
+
197
+ describe "DFont fonts" do
198
+ setup do
199
+ create_pdf
200
+ @file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
201
+ end
202
+
203
+ it "should list all named fonts" do
204
+ list = Prawn::Font::DFont.named_fonts(@file)
205
+ list.sort.should == %w(ActionMan ActionMan-Italic ActionMan-Bold ActionMan-BoldItalic).sort
206
+ end
207
+
208
+ it "should count the number of fonts in the file" do
209
+ Prawn::Font::DFont.font_count(@file).should == 4
210
+ end
211
+
212
+ it "should default selected font to the first one if not specified" do
213
+ font = @pdf.find_font(@file)
214
+ font.basename.should == "ActionMan"
215
+ end
216
+
217
+ it "should allow font to be selected by index" do
218
+ font = @pdf.find_font(@file, :font => 2)
219
+ font.basename.should == "ActionMan-Italic"
220
+ end
221
+
222
+ it "should allow font to be selected by name" do
223
+ font = @pdf.find_font(@file, :font => "ActionMan-BoldItalic")
224
+ font.basename.should == "ActionMan-BoldItalic"
225
+ end
226
+
227
+ it "should cache font object based on selected font" do
228
+ f1 = @pdf.find_font(@file, :font => "ActionMan")
229
+ f2 = @pdf.find_font(@file, :font => "ActionMan-Bold")
230
+ assert_not_equal f1.object_id, f2.object_id
231
+ assert_equal f1.object_id, @pdf.find_font(@file, :font => "ActionMan").object_id
232
+ assert_equal f2.object_id, @pdf.find_font(@file, :font => "ActionMan-Bold").object_id
233
+ end
234
+ end
data/spec/text_spec.rb CHANGED
@@ -17,6 +17,17 @@ describe "when drawing text" do
17
17
  @pdf.y.should.be.close(position - 3*@pdf.font.height, 0.0001)
18
18
  end
19
19
 
20
+ it "should advance down the document based on font ascender only if final_gap is given" do
21
+ position = @pdf.y
22
+ @pdf.text "Foo", :final_gap => false
23
+
24
+ @pdf.y.should.be.close(position - @pdf.font.ascender, 0.0001)
25
+
26
+ position = @pdf.y
27
+ @pdf.text "Foo\nBar\nBaz", :final_gap => false
28
+ @pdf.y.should.be.close(position - 2*@pdf.font.height - @pdf.font.ascender, 0.0001)
29
+ end
30
+
20
31
  it "should default to 12 point helvetica" do
21
32
  @pdf.text "Blah", :at => [100,100]
22
33
  text = PDF::Inspector::Text.analyze(@pdf.render)
@@ -32,14 +43,19 @@ describe "when drawing text" do
32
43
  end
33
44
 
34
45
  it "should allow setting a default font size" do
35
- @pdf.font.size = 16
46
+ @pdf.font_size = 16
36
47
  @pdf.text "Blah"
37
48
  text = PDF::Inspector::Text.analyze(@pdf.render)
38
49
  text.font_settings[0][:size].should == 16
39
50
  end
51
+
52
+ it "should allow setting font size in DSL style" do
53
+ @pdf.font_size 20
54
+ @pdf.font_size.should == 20
55
+ end
40
56
 
41
57
  it "should allow overriding default font for a single instance" do
42
- @pdf.font.size = 16
58
+ @pdf.font_size = 16
43
59
 
44
60
  @pdf.text "Blah", :size => 11
45
61
  @pdf.text "Blaz"
@@ -49,7 +65,7 @@ describe "when drawing text" do
49
65
  end
50
66
 
51
67
  it "should allow setting a font size transaction with a block" do
52
- @pdf.font.size 16 do
68
+ @pdf.font_size 16 do
53
69
  @pdf.text 'Blah'
54
70
  end
55
71
 
@@ -62,7 +78,7 @@ describe "when drawing text" do
62
78
 
63
79
  it "should allow manual setting the font size " +
64
80
  "when in a font size block" do
65
- @pdf.font.size(16) do
81
+ @pdf.font_size(16) do
66
82
  @pdf.text 'Foo'
67
83
  @pdf.text 'Blah', :size => 11
68
84
  @pdf.text 'Blaz'
@@ -115,8 +131,6 @@ describe "when drawing text" do
115
131
  lambda { @pdf.text str }.should.raise(ArgumentError)
116
132
  end
117
133
  it "should not raise an exception when a shift-jis string is rendered" do
118
- puts "\nFIXME: SJIS not working on 1.9 right now due to TTFunk issue"
119
- return
120
134
  datafile = "#{Prawn::BASEDIR}/data/shift_jis_text.txt"
121
135
  sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
122
136
  @pdf.font("#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf")
@@ -134,4 +148,31 @@ describe "when drawing text" do
134
148
  end
135
149
  end
136
150
 
151
+ it "should wrap text" do
152
+ @pdf = Prawn::Document.new
153
+ @pdf.font "Courier"
154
+
155
+ text = "Please wrap this text about HERE. More text that should be wrapped"
156
+ expect = "Please wrap this text about\nHERE. More text that should be\nwrapped"
157
+
158
+ @pdf.naive_wrap(text, 220, @pdf.font_size).should == expect
159
+ end
160
+
161
+ it "should respect end of line when wrapping text" do
162
+ @pdf = Prawn::Document.new
163
+ @pdf.font "Courier"
164
+ text = "Please wrap only before\nTHIS word. Don't wrap this"
165
+ @pdf.naive_wrap(text, 220, @pdf.font_size).should == text
166
+ end
167
+
168
+ it "should respect end of line when wrapping text and mode is set to 'character'" do
169
+ @pdf = Prawn::Document.new
170
+ @pdf.font "Courier"
171
+
172
+ text = "You can wrap this text HERE"
173
+ expect = "You can wrap this text HE\nRE"
174
+
175
+ @pdf.naive_wrap(text, 180, @pdf.font_size, :mode => :character).should == expect
176
+ end
177
+
137
178
  end
@@ -14,7 +14,7 @@ module PDF
14
14
  end
15
15
 
16
16
  def self.analyze_file(filename,*args,&block)
17
- analyze(File.open(filenmame, "rb") { |f| f.read },*args,&block)
17
+ analyze(File.open(filename, "rb") { |f| f.read },*args,&block)
18
18
  end
19
19
 
20
20
  def self.parse(obj)
@@ -1,5 +1,45 @@
1
1
  $LOAD_PATH << "#{File.dirname(__FILE__)}/lib"
2
2
  require "ttfunk"
3
3
 
4
- file = TTFunk::File.new("data/fonts/DejaVuSans.ttf")
5
- p file.kern.sub_tables[0].keys.sort
4
+ def character_lookup(file, character)
5
+ puts "character : #{character}"
6
+
7
+ character_code = character.unpack("U*").first
8
+ puts "character code: #{character_code}"
9
+
10
+ glyph_id = file.cmap.unicode.first[character_code]
11
+ puts "glyph id : #{glyph_id}"
12
+
13
+ glyph = file.glyph_outlines.for(glyph_id)
14
+ puts "glyph type : %s" % glyph.class.name.split(/::/).last.downcase
15
+ puts "glyph size : %db" % glyph.raw.length
16
+ puts "glyph bbox : (%d,%d)-(%d,%d)" % [glyph.x_min, glyph.y_min, glyph.x_max, glyph.y_max]
17
+
18
+ if glyph.compound?
19
+ puts "components : %d %s" % [glyph.glyph_ids.length, glyph.glyph_ids.inspect]
20
+ end
21
+ end
22
+
23
+ file = TTFunk::File.open(ARGV.first || "data/fonts/DejaVuSans.ttf")
24
+
25
+ puts "-- FONT ------------------------------------"
26
+
27
+ puts "revision : %08x" % file.header.font_revision
28
+ puts "name : #{file.name.font_name.join(', ')}"
29
+ puts "family : #{file.name.font_family.join(', ')}"
30
+ puts "subfamily : #{file.name.font_subfamily.join(', ')}"
31
+ puts "postscript: #{file.name.postscript_name}"
32
+
33
+ puts "-- FONT METRICS ----------------------------"
34
+
35
+ puts "units/em : #{file.header.units_per_em}"
36
+ puts "ascent : #{file.ascent}"
37
+ puts "descent : #{file.descent}"
38
+ puts "line gap : #{file.line_gap}"
39
+ puts "bbox : (%d,%d)-(%d,%d)" % file.bbox
40
+
41
+ puts "-- SIMPLE CHARACTER -> GLYPH LOOKUP --------"
42
+ character_lookup(file, "\xE2\x98\x9C")
43
+
44
+ puts "-- COMPOUND CHARACTER -> GLYPH LOOKUP ------"
45
+ character_lookup(file, "ë")