paragraph.py: fix encoding issue in _splitWord
authorrptlab
Thu, 26 Sep 2013 13:22:48 +0000
changeset 3774 ac441fbfeb92
parent 3773 dc1ef08c7277
child 3776 ae103172eea8
paragraph.py: fix encoding issue in _splitWord
src/reportlab/platypus/paragraph.py
--- a/src/reportlab/platypus/paragraph.py	Thu Sep 26 10:47:38 2013 +0000
+++ b/src/reportlab/platypus/paragraph.py	Thu Sep 26 13:22:48 2013 +0000
@@ -562,19 +562,34 @@
     R = []
     maxlineno = len(maxWidths)-1
     lineWidth = 0
-    wordText = ''
-    for c in w:
-        cw = stringWidth(c,fontName,fontSize,encoding)
-        newLineWidth = lineWidth+cw
-        if newLineWidth>maxWidth:
-            R.append(_SplitText(wordText))
-            lineno += 1
-            maxWidth = maxWidths[min(maxlineno,lineno)]
-            newLineWidth = cw
-            wordText = ''
-        wordText += c
-        lineWidth = newLineWidth
-    R.append(_SplitText(wordText))
+    wordText = u''
+    if isinstance(w,str):
+        w = w.decode('utf8')
+        for c in w:
+            cw = stringWidth(c,fontName,fontSize,encoding)
+            newLineWidth = lineWidth+cw
+            if newLineWidth>maxWidth:
+                R.append(_SplitText(wordText.encode(encoding)))
+                lineno += 1
+                maxWidth = maxWidths[min(maxlineno,lineno)]
+                newLineWidth = cw
+                wordText = u''
+            wordText += c
+            lineWidth = newLineWidth
+        R.append(_SplitText(wordText.encode(encoding)))
+    else:
+        for c in w:
+            cw = stringWidth(c,fontName,fontSize,encoding)
+            newLineWidth = lineWidth+cw
+            if newLineWidth>maxWidth:
+                R.append(_SplitText(wordText))
+                lineno += 1
+                maxWidth = maxWidths[min(maxlineno,lineno)]
+                newLineWidth = cw
+                wordText = u''
+            wordText += c
+            lineWidth = newLineWidth
+        R.append(_SplitText(wordText))
     return R
 
 def _split_blParaSimple(blPara,start,stop):