0
@@ -33,40 +33,17 @@ module Prawn
0
# pdf.text "Goodbye World", :at => [50,50], :size => 16
0
# pdf.text "Will be wrapped when it hits the edge of your bounding box"
0
- # All strings passed to this function should be encoded as UTF-8.
0
- # If you gets unexpected characters appearing in your rendered
0
+ # All strings passed to this function should be encoded as UTF-8.
0
+ # If you get unexpected characters appearing in your rendered
0
# document, check this.
0
# If an empty box is rendered to your PDF instead of the character you
0
# wanted it usually means the current font doesn't include that character.
0
def text(text,options={})
0
- # TODO: if the current font is a built in one, we can't use the utf-8
0
- # string provided by the user. We should convert it to WinAnsi or
0
- # MacRoman or some such.
0
- if text.respond_to?(:"encode!")
0
- # if we're running under a M17n aware VM, ensure the string provided is
0
- # UTF-8 (by converting it if necessary)
0
- raise Prawn::Errors::IncompatibleStringEncoding, "Encoding " +
0
- "#{text.encoding} can not be transparently converted to UTF-8. " +
0
- "Please ensure the encoding of the string you are attempting " +
0
- "to use is set correctly"
0
- # on a non M17N aware VM, use unpack as a hackish way to verify the
0
- # string is valid utf-8. I thought it was better than loading iconv
0
- raise Prawn::Errors::IncompatibleStringEncoding, "The string you " +
0
- "are attempting to render is not encoded in valid UTF-8."
0
+ # check the string is encoded sanely
0
+ normalize_encoding(text)
0
if options.key?(:kerning)
0
options[:kerning] = false unless font_metrics.has_kerning_data?
0
@@ -279,6 +256,34 @@ module Prawn
0
+ def normalise_encoding(text)
0
+ # TODO: if the current font is a built in one, we can't use the utf-8
0
+ # string provided by the user. We should convert it to WinAnsi or
0
+ # MacRoman or some such.
0
+ if text.respond_to?(:"encode!")
0
+ # if we're running under a M17n aware VM, ensure the string provided is
0
+ # UTF-8 (by converting it if necessary)
0
+ raise Prawn::Errors::IncompatibleStringEncoding, "Encoding " +
0
+ "#{text.encoding} can not be transparently converted to UTF-8. " +
0
+ "Please ensure the encoding of the string you are attempting " +
0
+ "to use is set correctly"
0
+ # on a non M17N aware VM, use unpack as a hackish way to verify the
0
+ # string is valid utf-8. I thought it was better than loading iconv
0
+ raise Prawn::Errors::IncompatibleStringEncoding, "The string you " +
0
+ "are attempting to render is not encoded in valid UTF-8."
0
def register_builtin_font(name) #:nodoc:
0
unless BUILT_INS.include?(name)
0
raise Prawn::Errors::UnknownFont, "#{name} is not a known font."
Comments
Good call. I was planning on doing this. I’ll pull it up.