<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -33,40 +33,17 @@ module Prawn
       #   pdf.text &quot;Goodbye World&quot;, :at =&gt; [50,50], :size =&gt; 16
       #   pdf.text &quot;Will be wrapped when it hits the edge of your bounding box&quot;
       #
-      # All strings passed to this function should be encoded as UTF-8. 
-      # If you gets unexpected characters appearing in your rendered 
+      # All strings passed to this function should be encoded as UTF-8.
+      # If you get unexpected characters appearing in your rendered 
       # document, check this.
       #
       # If an empty box is rendered to your PDF instead of the character you 
       # wanted it usually means the current font doesn't include that character.
-      # 
+      #
       def text(text,options={})
-        # TODO: if the current font is a built in one, we can't use the utf-8 
-        # string provided by the user. We should convert it to WinAnsi or 
-        # MacRoman or some such.
 
-        if text.respond_to?(:&quot;encode!&quot;)
-          # if we're running under a M17n aware VM, ensure the string provided is
-          # UTF-8 (by converting it if necessary)
-          begin
-            text.encode!(&quot;UTF-8&quot;)
-          rescue
-            raise Prawn::Errors::IncompatibleStringEncoding, &quot;Encoding &quot; +
-            &quot;#{text.encoding} can not be transparently converted to UTF-8. &quot; +
-            &quot;Please ensure the encoding of the string you are attempting &quot; +
-            &quot;to use is set correctly&quot;
-          end
-        else
-          # on a non M17N aware VM, use unpack as a hackish way to verify the
-          # string is valid utf-8. I thought it was better than loading iconv
-          # though.
-          begin
-            text.unpack(&quot;U*&quot;)
-          rescue
-            raise Prawn::Errors::IncompatibleStringEncoding, &quot;The string you &quot; +
-            &quot;are attempting to render is not encoded in valid UTF-8.&quot;
-          end
-        end
+        # check the string is encoded sanely
+        normalize_encoding(text)
 
         if options.key?(:kerning)
           options[:kerning] = false unless font_metrics.has_kerning_data?
@@ -277,6 +254,34 @@ module Prawn
         return basename
       end
 
+      def normalise_encoding(text)
+        # TODO: if the current font is a built in one, we can't use the utf-8
+        # string provided by the user. We should convert it to WinAnsi or
+        # MacRoman or some such.
+        if text.respond_to?(:&quot;encode!&quot;)
+          # if we're running under a M17n aware VM, ensure the string provided is
+          # UTF-8 (by converting it if necessary)
+          begin
+            text.encode!(&quot;UTF-8&quot;)
+          rescue
+            raise Prawn::Errors::IncompatibleStringEncoding, &quot;Encoding &quot; +
+            &quot;#{text.encoding} can not be transparently converted to UTF-8. &quot; +
+            &quot;Please ensure the encoding of the string you are attempting &quot; +
+            &quot;to use is set correctly&quot;
+          end
+        else
+          # on a non M17N aware VM, use unpack as a hackish way to verify the
+          # string is valid utf-8. I thought it was better than loading iconv
+          # though.
+          begin
+            text.unpack(&quot;U*&quot;)
+          rescue
+            raise Prawn::Errors::IncompatibleStringEncoding, &quot;The string you &quot; +
+            &quot;are attempting to render is not encoded in valid UTF-8.&quot;
+          end
+        end
+      end
+
       def register_builtin_font(name) #:nodoc:
         unless BUILT_INS.include?(name)
           raise Prawn::Errors::UnknownFont, &quot;#{name} is not a known font.&quot;</diff>
      <filename>lib/prawn/document/text.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>d335b2a86ebefb68eb7effe6401491fd894e33f8</id>
    </parent>
  </parents>
  <author>
    <name>James Healy</name>
    <email>jimmy@deefa.com</email>
  </author>
  <url>http://github.com/sandal/prawn/commit/6c4bdf74dc677df5f88a77f4dc214feb744af7e2</url>
  <id>6c4bdf74dc677df5f88a77f4dc214feb744af7e2</id>
  <committed-date>2008-07-24T09:05:40-07:00</committed-date>
  <authored-date>2008-07-23T20:59:03-07:00</authored-date>
  <message>Move the text encoding checks to a seperate private function
- Document#text() is getting long and scary.</message>
  <tree>e3e2c6ba3fb5f1497a2030db3480438f7beb36fa</tree>
  <committer>
    <name>Gregory Brown</name>
    <email>gregory.t.brown@gmail.com</email>
  </committer>
</commit>
