prawn 2.0.1 → 2.0.2

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 (129) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +7 -5
  3. data/lib/prawn.rb +4 -4
  4. data/lib/prawn/document.rb +47 -46
  5. data/lib/prawn/document/bounding_box.rb +13 -19
  6. data/lib/prawn/document/column_box.rb +3 -5
  7. data/lib/prawn/document/internals.rb +0 -1
  8. data/lib/prawn/document/span.rb +12 -12
  9. data/lib/prawn/errors.rb +32 -33
  10. data/lib/prawn/font.rb +29 -36
  11. data/lib/prawn/font/afm.rb +20 -20
  12. data/lib/prawn/font/dfont.rb +0 -1
  13. data/lib/prawn/font/ttf.rb +30 -27
  14. data/lib/prawn/font_metric_cache.rb +4 -8
  15. data/lib/prawn/graphics.rb +37 -42
  16. data/lib/prawn/graphics/cap_style.rb +1 -1
  17. data/lib/prawn/graphics/color.rb +21 -23
  18. data/lib/prawn/graphics/dash.rb +5 -6
  19. data/lib/prawn/graphics/join_style.rb +1 -2
  20. data/lib/prawn/graphics/patterns.rb +25 -21
  21. data/lib/prawn/graphics/transformation.rb +4 -5
  22. data/lib/prawn/graphics/transparency.rb +6 -8
  23. data/lib/prawn/grid.rb +21 -14
  24. data/lib/prawn/image_handler.rb +2 -2
  25. data/lib/prawn/images.rb +29 -31
  26. data/lib/prawn/images/image.rb +1 -1
  27. data/lib/prawn/images/jpg.rb +10 -12
  28. data/lib/prawn/images/png.rb +13 -13
  29. data/lib/prawn/measurements.rb +7 -14
  30. data/lib/prawn/outline.rb +6 -6
  31. data/lib/prawn/repeater.rb +1 -5
  32. data/lib/prawn/security.rb +17 -25
  33. data/lib/prawn/security/arcfour.rb +1 -1
  34. data/lib/prawn/soft_mask.rb +11 -12
  35. data/lib/prawn/stamp.rb +16 -8
  36. data/lib/prawn/text.rb +23 -20
  37. data/lib/prawn/text/box.rb +3 -6
  38. data/lib/prawn/text/formatted/arranger.rb +9 -12
  39. data/lib/prawn/text/formatted/box.rb +23 -22
  40. data/lib/prawn/text/formatted/fragment.rb +0 -4
  41. data/lib/prawn/text/formatted/line_wrap.rb +13 -24
  42. data/lib/prawn/text/formatted/parser.rb +16 -20
  43. data/lib/prawn/text/formatted/wrap.rb +2 -7
  44. data/lib/prawn/utilities.rb +6 -3
  45. data/lib/prawn/version.rb +1 -1
  46. data/manual/basic_concepts/basic_concepts.rb +0 -2
  47. data/manual/basic_concepts/view.rb +1 -1
  48. data/manual/bounding_box/bounding_box.rb +0 -3
  49. data/manual/bounding_box/russian_boxes.rb +7 -8
  50. data/manual/bounding_box/stretchy.rb +0 -1
  51. data/manual/contents.rb +2 -2
  52. data/manual/cover.rb +11 -12
  53. data/manual/document_and_page_options/document_and_page_options.rb +2 -5
  54. data/manual/document_and_page_options/metadata.rb +10 -10
  55. data/manual/document_and_page_options/page_size.rb +0 -1
  56. data/manual/graphics/fill_rules.rb +5 -4
  57. data/manual/graphics/graphics.rb +0 -3
  58. data/manual/graphics/lines_and_curves.rb +1 -1
  59. data/manual/graphics/rotate.rb +0 -2
  60. data/manual/graphics/scale.rb +4 -2
  61. data/manual/graphics/soft_masks.rb +0 -1
  62. data/manual/graphics/stroke_cap.rb +1 -1
  63. data/manual/graphics/stroke_join.rb +1 -1
  64. data/manual/graphics/translate.rb +3 -3
  65. data/manual/graphics/transparency.rb +0 -1
  66. data/manual/how_to_read_this_manual.rb +0 -1
  67. data/manual/images/images.rb +0 -3
  68. data/manual/layout/boxes.rb +5 -5
  69. data/manual/layout/content.rb +2 -2
  70. data/manual/layout/layout.rb +0 -3
  71. data/manual/outline/outline.rb +0 -3
  72. data/manual/repeatable_content/page_numbering.rb +1 -1
  73. data/manual/repeatable_content/repeatable_content.rb +0 -3
  74. data/manual/repeatable_content/repeater.rb +6 -6
  75. data/manual/security/encryption.rb +0 -2
  76. data/manual/security/permissions.rb +0 -2
  77. data/manual/security/security.rb +0 -3
  78. data/manual/text/alignment.rb +3 -3
  79. data/manual/text/color.rb +0 -1
  80. data/manual/text/column_box.rb +0 -1
  81. data/manual/text/fallback_fonts.rb +2 -2
  82. data/manual/text/formatted_callbacks.rb +3 -2
  83. data/manual/text/paragraph_indentation.rb +2 -3
  84. data/manual/text/registering_families.rb +13 -9
  85. data/manual/text/rotation.rb +0 -1
  86. data/manual/text/text.rb +0 -3
  87. data/manual/text/text_box_overflow.rb +7 -5
  88. data/manual/text/utf8.rb +1 -1
  89. data/manual/text/win_ansi_charset.rb +2 -2
  90. data/prawn.gemspec +4 -4
  91. data/spec/acceptance/png.rb +6 -7
  92. data/spec/annotations_spec.rb +21 -28
  93. data/spec/bounding_box_spec.rb +100 -109
  94. data/spec/column_box_spec.rb +26 -32
  95. data/spec/destinations_spec.rb +2 -4
  96. data/spec/document_spec.rb +145 -151
  97. data/spec/extensions/mocha.rb +0 -1
  98. data/spec/font_metric_cache_spec.rb +7 -7
  99. data/spec/font_spec.rb +103 -102
  100. data/spec/formatted_text_arranger_spec.rb +76 -74
  101. data/spec/formatted_text_box_spec.rb +170 -159
  102. data/spec/formatted_text_fragment_spec.rb +57 -56
  103. data/spec/graphics_spec.rb +158 -175
  104. data/spec/grid_spec.rb +28 -29
  105. data/spec/image_handler_spec.rb +4 -5
  106. data/spec/images_spec.rb +50 -36
  107. data/spec/inline_formatted_text_parser_spec.rb +397 -393
  108. data/spec/jpg_spec.rb +4 -6
  109. data/spec/line_wrap_spec.rb +54 -55
  110. data/spec/measurement_units_spec.rb +12 -15
  111. data/spec/outline_spec.rb +77 -98
  112. data/spec/png_spec.rb +55 -65
  113. data/spec/reference_spec.rb +3 -3
  114. data/spec/repeater_spec.rb +20 -26
  115. data/spec/security_spec.rb +42 -49
  116. data/spec/soft_mask_spec.rb +4 -5
  117. data/spec/span_spec.rb +5 -6
  118. data/spec/spec_helper.rb +2 -4
  119. data/spec/stamp_spec.rb +41 -22
  120. data/spec/stroke_styles_spec.rb +36 -39
  121. data/spec/text_at_spec.rb +28 -29
  122. data/spec/text_box_spec.rb +160 -165
  123. data/spec/text_rendering_mode_spec.rb +9 -9
  124. data/spec/text_spacing_spec.rb +13 -13
  125. data/spec/text_spec.rb +116 -124
  126. data/spec/text_with_inline_formatting_spec.rb +5 -5
  127. data/spec/transparency_spec.rb +20 -20
  128. data/spec/view_spec.rb +0 -1
  129. metadata +7 -7
@@ -8,45 +8,45 @@
8
8
  #
9
9
  module Prawn
10
10
  module Errors
11
- # Raised when a table is spanned in an impossible way.
12
- #
13
- InvalidTableSpan = Class.new(StandardError)
11
+ # Raised when a table is spanned in an impossible way.
12
+ #
13
+ InvalidTableSpan = Class.new(StandardError)
14
14
 
15
- # This error is raised when a method requiring a current page is called
16
- # without being on a page.
17
- #
18
- NotOnPage = Class.new(StandardError)
15
+ # This error is raised when a method requiring a current page is called
16
+ # without being on a page.
17
+ #
18
+ NotOnPage = Class.new(StandardError)
19
19
 
20
- # This error is raised when Prawn cannot find a specified font
21
- #
22
- UnknownFont = Class.new(StandardError)
20
+ # This error is raised when Prawn cannot find a specified font
21
+ #
22
+ UnknownFont = Class.new(StandardError)
23
23
 
24
- # Raised when Prawn is asked to draw something into a too-small box
25
- #
26
- CannotFit = Class.new(StandardError)
24
+ # Raised when Prawn is asked to draw something into a too-small box
25
+ #
26
+ CannotFit = Class.new(StandardError)
27
27
 
28
- # Raised if group() is called with a block that is too big to be
29
- # rendered in the current context.
30
- #
31
- CannotGroup = Class.new(StandardError)
28
+ # Raised if group() is called with a block that is too big to be
29
+ # rendered in the current context.
30
+ #
31
+ CannotGroup = Class.new(StandardError)
32
32
 
33
- # This error is raised when Prawn is being used on a M17N aware VM,
34
- # and the user attempts to add text that isn't compatible with UTF-8
35
- # to their document
36
- #
37
- IncompatibleStringEncoding = Class.new(StandardError)
33
+ # This error is raised when Prawn is being used on a M17N aware VM,
34
+ # and the user attempts to add text that isn't compatible with UTF-8
35
+ # to their document
36
+ #
37
+ IncompatibleStringEncoding = Class.new(StandardError)
38
38
 
39
- # This error is raised when Prawn encounters an unknown key in functions
40
- # that accept an options hash. This usually means there is a typo in your
41
- # code or that the option you are trying to use has a different name than
42
- # what you have specified.
43
- #
44
- UnknownOption = Class.new(StandardError)
39
+ # This error is raised when Prawn encounters an unknown key in functions
40
+ # that accept an options hash. This usually means there is a typo in your
41
+ # code or that the option you are trying to use has a different name than
42
+ # what you have specified.
43
+ #
44
+ UnknownOption = Class.new(StandardError)
45
45
 
46
- # this error is raised when a user attempts to embed an image of an unsupported
47
- # type. This can either a completely unsupported format, or a dialect of a
48
- # supported format (ie. some types of PNG)
49
- UnsupportedImageType = Class.new(StandardError)
46
+ # this error is raised when a user attempts to embed an image of an unsupported
47
+ # type. This can either a completely unsupported format, or a dialect of a
48
+ # supported format (ie. some types of PNG)
49
+ UnsupportedImageType = Class.new(StandardError)
50
50
 
51
51
  # This error is raised when a named element has alredy been
52
52
  # created. For example, in the stamp module, stamps must have
@@ -75,6 +75,5 @@ module Prawn
75
75
  # Raised when unrecognized content is provided for a table cell.
76
76
  #
77
77
  UnrecognizedTableContent = Class.new(StandardError)
78
-
79
78
  end
80
79
  end
@@ -12,7 +12,6 @@ require_relative "font/dfont"
12
12
  require_relative "font_metric_cache"
13
13
 
14
14
  module Prawn
15
-
16
15
  class Document
17
16
  # @group Stable API
18
17
 
@@ -48,11 +47,11 @@ module Prawn
48
47
  # the :style option you need to map those font styles to their respective font files.
49
48
  # See font_families for more information.
50
49
  #
51
- def font(name=nil, options={})
50
+ def font(name = nil, options = {})
52
51
  return((defined?(@font) && @font) || font("Helvetica")) if name.nil?
53
52
 
54
53
  if state.pages.empty? && !state.page.in_stamp_stream?
55
- raise Prawn::Errors::NotOnPage
54
+ fail Prawn::Errors::NotOnPage
56
55
  end
57
56
 
58
57
  new_font = find_font(name.to_s, options)
@@ -95,7 +94,7 @@ module Prawn
95
94
  # When called without an argument, this method returns the current font
96
95
  # size.
97
96
  #
98
- def font_size(points=nil)
97
+ def font_size(points = nil)
99
98
  return @font_size unless points
100
99
  size_before_yield = @font_size
101
100
  @font_size = points
@@ -127,7 +126,7 @@ module Prawn
127
126
  # By putting width_of here, on Document itself, extensions may easily override
128
127
  # it and redefine the width calculation behavior.
129
128
  #++
130
- def width_of(string, options={})
129
+ def width_of(string, options = {})
131
130
  if p = options[:inline_format]
132
131
  p = [] unless p.is_a?(Array)
133
132
 
@@ -170,21 +169,21 @@ module Prawn
170
169
  #
171
170
  def font_families
172
171
  @font_families ||= {}.merge!(
173
- { "Courier" => { :bold => "Courier-Bold",
174
- :italic => "Courier-Oblique",
175
- :bold_italic => "Courier-BoldOblique",
176
- :normal => "Courier" },
177
-
178
- "Times-Roman" => { :bold => "Times-Bold",
179
- :italic => "Times-Italic",
180
- :bold_italic => "Times-BoldItalic",
181
- :normal => "Times-Roman" },
182
-
183
- "Helvetica" => { :bold => "Helvetica-Bold",
184
- :italic => "Helvetica-Oblique",
185
- :bold_italic => "Helvetica-BoldOblique",
186
- :normal => "Helvetica" }
187
- })
172
+ "Courier" => { :bold => "Courier-Bold",
173
+ :italic => "Courier-Oblique",
174
+ :bold_italic => "Courier-BoldOblique",
175
+ :normal => "Courier" },
176
+
177
+ "Times-Roman" => { :bold => "Times-Bold",
178
+ :italic => "Times-Italic",
179
+ :bold_italic => "Times-BoldItalic",
180
+ :normal => "Times-Roman" },
181
+
182
+ "Helvetica" => { :bold => "Helvetica-Bold",
183
+ :italic => "Helvetica-Oblique",
184
+ :bold_italic => "Helvetica-BoldOblique",
185
+ :normal => "Helvetica" }
186
+ )
188
187
  end
189
188
 
190
189
  # @group Experimental API
@@ -192,7 +191,7 @@ module Prawn
192
191
  # Sets the font directly, given an actual Font object
193
192
  # and size.
194
193
  #
195
- def set_font(font, size=nil) # :nodoc:
194
+ def set_font(font, size = nil) # :nodoc:
196
195
  @font = font
197
196
  @font_size = size if size
198
197
  end
@@ -228,7 +227,7 @@ module Prawn
228
227
  # ++
229
228
  #
230
229
  # @private
231
- def find_font(name, options={}) #:nodoc:
230
+ def find_font(name, options = {}) #:nodoc:
232
231
  if font_families.key?(name)
233
232
  family, name = name, font_families[name][options[:style] || :normal]
234
233
  if name.is_a?(::Hash)
@@ -241,10 +240,7 @@ module Prawn
241
240
  if name.is_a? Prawn::Font
242
241
  font_registry[key] = name
243
242
  else
244
- font_registry[key] ||= Font.load( self,
245
- name,
246
- options.merge(family: family)
247
- )
243
+ font_registry[key] ||= Font.load(self, name, options.merge(family: family))
248
244
  end
249
245
  end
250
246
 
@@ -256,7 +252,7 @@ module Prawn
256
252
 
257
253
  private
258
254
 
259
- def width_of_inline_formatted_string(string, options={})
255
+ def width_of_inline_formatted_string(string, options = {})
260
256
  # Build up an Arranger with the entire string on one line, finalize it,
261
257
  # and find its width.
262
258
  arranger = Prawn::Text::Formatted::Arranger.new(self, options)
@@ -266,15 +262,14 @@ module Prawn
266
262
  arranger.line_width
267
263
  end
268
264
 
269
- def width_of_string(string, options={})
270
- font_metric_cache.width_of( string, options )
265
+ def width_of_string(string, options = {})
266
+ font_metric_cache.width_of(string, options)
271
267
  end
272
268
  end
273
269
 
274
270
  # Provides font information and helper functions.
275
271
  #
276
272
  class Font
277
-
278
273
  # The current font name
279
274
  attr_reader :name
280
275
 
@@ -287,7 +282,7 @@ module Prawn
287
282
  # Shortcut interface for constructing a font object. Filenames of the form
288
283
  # *.ttf will call Font::TTF.new, *.dfont Font::DFont.new, and anything else
289
284
  # will be passed through to Font::AFM.new()
290
- def self.load(document, src, options={})
285
+ def self.load(document, src, options = {})
291
286
  case font_format(src, options)
292
287
  when 'ttf' then TTF.new(document, src, options)
293
288
  when 'dfont' then DFont.new(document, src, options)
@@ -305,7 +300,7 @@ module Prawn
305
300
  end
306
301
  end
307
302
 
308
- def initialize(document,name,options={}) #:nodoc:
303
+ def initialize(document, name, options = {}) #:nodoc:
309
304
  @document = document
310
305
  @name = name
311
306
  @options = options
@@ -340,7 +335,7 @@ module Prawn
340
335
  # and the new string will be returned. For an in-place (destructive)
341
336
  # version, see normalize_encoding!.
342
337
  def normalize_encoding(string)
343
- raise NotImplementedError, "subclasses of Prawn::Font must implement #normalize_encoding"
338
+ fail NotImplementedError, "subclasses of Prawn::Font must implement #normalize_encoding"
344
339
  end
345
340
 
346
341
  # Destructive version of normalize_encoding; normalizes the encoding of a
@@ -391,7 +386,7 @@ module Prawn
391
386
 
392
387
  # Compliments the #hash implementation above
393
388
  #
394
- def eql?( other ) #:nodoc:
389
+ def eql?(other) #:nodoc:
395
390
  self.class == other.class && self.name == other.name &&
396
391
  self.family == other.family && size == other.send(:size)
397
392
  end
@@ -407,7 +402,5 @@ module Prawn
407
402
  def size
408
403
  @document.font_size
409
404
  end
410
-
411
405
  end
412
-
413
406
  end
@@ -10,7 +10,6 @@ require_relative "../encoding"
10
10
 
11
11
  module Prawn
12
12
  class Font
13
-
14
13
  # @private
15
14
 
16
15
  class AFM < Font
@@ -37,15 +36,16 @@ module Prawn
37
36
  ".", "/usr/lib/afm",
38
37
  "/usr/local/lib/afm",
39
38
  "/usr/openwin/lib/fonts/afm",
40
- Prawn::DATADIR+'/fonts']
39
+ Prawn::DATADIR + '/fonts'
40
+ ]
41
41
  end
42
42
  end
43
43
 
44
44
  attr_reader :attributes #:nodoc:
45
45
 
46
- def initialize(document, name, options={}) #:nodoc:
46
+ def initialize(document, name, options = {}) #:nodoc:
47
47
  unless BUILT_INS.include?(name)
48
- raise Prawn::Errors::UnknownFont, "#{name} is not a known font."
48
+ fail Prawn::Errors::UnknownFont, "#{name} is not a known font."
49
49
  end
50
50
 
51
51
  super
@@ -54,7 +54,7 @@ module Prawn
54
54
 
55
55
  file_name = @name.dup
56
56
  file_name << ".afm" unless file_name =~ /\.afm$/
57
- file_name = file_name[0] == ?/ ? file_name : find_font(file_name)
57
+ file_name = file_name[0] == '/' ? file_name : find_font(file_name)
58
58
 
59
59
  font_data = @@font_data[file_name] ||= parse_afm(file_name)
60
60
  @glyph_widths = font_data[:glyph_widths]
@@ -76,12 +76,12 @@ module Prawn
76
76
  end
77
77
 
78
78
  # NOTE: String *must* be encoded as WinAnsi
79
- def compute_width_of(string, options={}) #:nodoc:
79
+ def compute_width_of(string, options = {}) #:nodoc:
80
80
  scale = (options[:size] || size) / 1000.0
81
81
 
82
82
  if options[:kerning]
83
83
  strings, numbers = kern(string).partition { |e| e.is_a?(String) }
84
- total_kerning_offset = numbers.inject(0.0) { |s,r| s + r }
84
+ total_kerning_offset = numbers.inject(0.0) { |s, r| s + r }
85
85
  (unscaled_width_of(strings.join) - total_kerning_offset) * scale
86
86
  else
87
87
  unscaled_width_of(string) * scale
@@ -104,8 +104,8 @@ module Prawn
104
104
  ::Encoding::UndefinedConversionError
105
105
 
106
106
  raise Prawn::Errors::IncompatibleStringEncoding,
107
- "Your document includes text that's not compatible with the Windows-1252 character set.\n"+
108
- "If you need full UTF-8 support, use TTF fonts instead of PDF's built-in fonts\n."
107
+ "Your document includes text that's not compatible with the Windows-1252 character set.\n" \
108
+ "If you need full UTF-8 support, use TTF fonts instead of PDF's built-in fonts\n."
109
109
  end
110
110
 
111
111
  def to_utf8(text)
@@ -130,7 +130,7 @@ module Prawn
130
130
  #
131
131
  # The +text+ parameter must be in WinAnsi encoding (cp1252).
132
132
  #
133
- def encode_text(text, options={})
133
+ def encode_text(text, options = {})
134
134
  [[0, options[:kerning] ? kern(text) : text]]
135
135
  end
136
136
 
@@ -143,9 +143,11 @@ module Prawn
143
143
  private
144
144
 
145
145
  def register(subset)
146
- font_dict = {:Type => :Font,
147
- :Subtype => :Type1,
148
- :BaseFont => name.to_sym}
146
+ font_dict = {
147
+ :Type => :Font,
148
+ :Subtype => :Type1,
149
+ :BaseFont => name.to_sym
150
+ }
149
151
 
150
152
  # Symbolic AFM fonts (Symbol, ZapfDingbats) have their own encodings
151
153
  font_dict.merge!(:Encoding => :WinAnsiEncoding) unless symbolic?
@@ -161,12 +163,11 @@ module Prawn
161
163
  self.class.metrics_path.find { |f| File.exist? "#{f}/#{file}" } + "/#{file}"
162
164
  rescue NoMethodError
163
165
  raise Prawn::Errors::UnknownFont,
164
- "Couldn't find the font: #{file} in any of:\n" +
165
- self.class.metrics_path.join("\n")
166
+ "Couldn't find the font: #{file} in any of:\n" + self.class.metrics_path.join("\n")
166
167
  end
167
168
 
168
169
  def parse_afm(file_name)
169
- data = {:glyph_widths => {}, :bounding_boxes => {}, :kern_pairs => {}, :attributes => {}}
170
+ data = { :glyph_widths => {}, :bounding_boxes => {}, :kern_pairs => {}, :attributes => {} }
170
171
  section = []
171
172
 
172
173
  File.foreach(file_name) do |line|
@@ -204,12 +205,11 @@ module Prawn
204
205
  end
205
206
 
206
207
  character_hash = Hash[Encoding::WinAnsi::CHARACTERS.zip((0..Encoding::WinAnsi::CHARACTERS.size).to_a)]
207
- data[:kern_pair_table] = data[:kern_pairs].inject({}) do |h,p|
208
+ data[:kern_pair_table] = data[:kern_pairs].each_with_object({}) do |p, h|
208
209
  h[p[0].map { |n| character_hash[n] }] = p[1]
209
- h
210
210
  end
211
211
 
212
- data.each_value { |hash| hash.freeze }
212
+ data.each_value(&:freeze)
213
213
  data.freeze
214
214
  end
215
215
 
@@ -247,7 +247,7 @@ module Prawn
247
247
  private
248
248
 
249
249
  def unscaled_width_of(string)
250
- string.bytes.inject(0) do |s,r|
250
+ string.bytes.inject(0) do |s, r|
251
251
  s + @glyph_table[r]
252
252
  end
253
253
  end
@@ -12,7 +12,6 @@ module Prawn
12
12
  class Font
13
13
  # @private
14
14
  class DFont < TTF
15
-
16
15
  # Returns a list of the names of all named fonts in the given dfont file.
17
16
  # Note that fonts are not required to be named in a dfont file, so the
18
17
  # list may be empty even if the file does contain fonts. Also, note that
@@ -12,7 +12,6 @@ require 'ttfunk/subset_collection'
12
12
 
13
13
  module Prawn
14
14
  class Font
15
-
16
15
  # @private
17
16
  class TTF < Font
18
17
  attr_reader :ttf, :subsets
@@ -21,7 +20,7 @@ module Prawn
21
20
  true
22
21
  end
23
22
 
24
- def initialize(document, name, options={})
23
+ def initialize(document, name, options = {})
25
24
  super
26
25
 
27
26
  @ttf = read_ttf_file
@@ -38,10 +37,10 @@ module Prawn
38
37
  end
39
38
 
40
39
  # NOTE: +string+ must be UTF8-encoded.
41
- def compute_width_of(string, options={}) #:nodoc:
40
+ def compute_width_of(string, options = {}) #:nodoc:
42
41
  scale = (options[:size] || size) / 1000.0
43
42
  if options[:kerning]
44
- kern(string).inject(0) do |s,r|
43
+ kern(string).inject(0) do |s, r|
45
44
  if r.is_a?(Numeric)
46
45
  s - r
47
46
  else
@@ -49,7 +48,7 @@ module Prawn
49
48
  end
50
49
  end * scale
51
50
  else
52
- string.codepoints.inject(0) do |s,r|
51
+ string.codepoints.inject(0) do |s, r|
53
52
  s + character_width_by_code(r)
54
53
  end * scale
55
54
  end
@@ -74,7 +73,7 @@ module Prawn
74
73
  #
75
74
  # The +text+ parameter must be UTF8-encoded.
76
75
  #
77
- def encode_text(text,options={})
76
+ def encode_text(text, options = {})
78
77
  text = text.chomp
79
78
 
80
79
  if options[:kerning]
@@ -115,14 +114,18 @@ module Prawn
115
114
  end
116
115
 
117
116
  def italic_angle
118
- @italic_angle ||= if @ttf.postscript.exists?
117
+ return @italic_angle if @italic_angle
118
+
119
+ if @ttf.postscript.exists?
119
120
  raw = @ttf.postscript.italic_angle
120
121
  hi, low = raw >> 16, raw & 0xFF
121
122
  hi = -((hi ^ 0xFFFF) + 1) if hi & 0x8000 != 0
122
- "#{hi}.#{low}".to_f
123
+ @italic_angle = "#{hi}.#{low}".to_f
123
124
  else
124
- 0
125
+ @italic_angle = 0
125
126
  end
127
+
128
+ @italic_angle
126
129
  end
127
130
 
128
131
  def cap_height
@@ -143,7 +146,7 @@ module Prawn
143
146
  end
144
147
 
145
148
  def serif?
146
- @serif ||= [1,2,3,4,5,7].include?(family_class)
149
+ @serif ||= [1, 2, 3, 4, 5, 7].include?(family_class)
147
150
  end
148
151
 
149
152
  def script?
@@ -166,9 +169,9 @@ module Prawn
166
169
  text.encode(::Encoding::UTF_8)
167
170
  rescue => e
168
171
  puts e
169
- raise Prawn::Errors::IncompatibleStringEncoding, "Encoding " +
170
- "#{text.encoding} can not be transparently converted to UTF-8. " +
171
- "Please ensure the encoding of the string you are attempting " +
172
+ raise Prawn::Errors::IncompatibleStringEncoding, "Encoding " \
173
+ "#{text.encoding} can not be transparently converted to UTF-8. " \
174
+ "Please ensure the encoding of the string you are attempting " \
172
175
  "to use is set correctly"
173
176
  end
174
177
  end
@@ -191,7 +194,7 @@ module Prawn
191
194
  private
192
195
 
193
196
  def cmap
194
- @cmap ||= @ttf.cmap.unicode.first or raise("no unicode cmap for font")
197
+ @cmap ||= @ttf.cmap.unicode.first or fail("no unicode cmap for font")
195
198
  end
196
199
 
197
200
  # +string+ must be UTF8-encoded.
@@ -244,7 +247,7 @@ module Prawn
244
247
  end
245
248
 
246
249
  def register(subset)
247
- temp_name = @ttf.name.postscript_name.gsub("\0","").to_sym
250
+ temp_name = @ttf.name.postscript_name.gsub("\0", "").to_sym
248
251
  ref = @document.ref!(:Type => :Font, :BaseFont => temp_name)
249
252
 
250
253
  # Embed the font metrics in the document after everything has been
@@ -264,25 +267,25 @@ module Prawn
264
267
 
265
268
  # empirically, it looks like Adobe Reader will not display fonts
266
269
  # if their font name is more than 33 bytes long. Strange. But true.
267
- basename = font.name.postscript_name[0, 33].gsub("\0","")
270
+ basename = font.name.postscript_name[0, 33].gsub("\0", "")
268
271
 
269
- raise "Can't detect a postscript name for #{file}" if basename.nil?
272
+ fail "Can't detect a postscript name for #{file}" if basename.nil?
270
273
 
271
274
  fontfile = @document.ref!(:Length1 => font_content.size)
272
275
  fontfile.stream << font_content
273
276
  fontfile.stream.compress!
274
277
 
275
278
  descriptor = @document.ref!(:Type => :FontDescriptor,
276
- :FontName => basename.to_sym,
277
- :FontFile2 => fontfile,
278
- :FontBBox => bbox,
279
- :Flags => pdf_flags,
280
- :StemV => stemV,
281
- :ItalicAngle => italic_angle,
282
- :Ascent => @ascender,
283
- :Descent => @descender,
284
- :CapHeight => cap_height,
285
- :XHeight => x_height)
279
+ :FontName => basename.to_sym,
280
+ :FontFile2 => fontfile,
281
+ :FontBBox => bbox,
282
+ :Flags => pdf_flags,
283
+ :StemV => stemV,
284
+ :ItalicAngle => italic_angle,
285
+ :Ascent => @ascender,
286
+ :Descent => @descender,
287
+ :CapHeight => cap_height,
288
+ :XHeight => x_height)
286
289
 
287
290
  hmtx = font.horizontal_metrics
288
291
  widths = font.cmap.tables.first.code_map.map { |gid|