]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Escape Unicode characters properly for list-item labels.
authorJeremias Maerki <jeremias@apache.org>
Mon, 10 Jul 2006 14:12:20 +0000 (14:12 +0000)
committerJeremias Maerki <jeremias@apache.org>
Mon, 10 Jul 2006 14:12:20 +0000 (14:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@420533 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListStyleText.java
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfStringConverter.java

index 230f2e7e64ce637f260072bed8997fa4b68acb92..6091d58f8d9de6499c694ace7dd616864bedddd1 100644 (file)
@@ -63,7 +63,8 @@ public class RtfListStyleText extends RtfListStyle {
         item.writeGroupMark(true);
         //item.writeControlWord("pndec");
         item.writeOneAttribute(RtfListTable.LIST_FONT_TYPE, "2");
-        item.writeControlWord("pntxtb " + text);
+        item.writeControlWord("pntxtb");
+        RtfStringConverter.getInstance().writeRtfString(item.writer, text);
         item.writeGroupMark(false);
     }
     
@@ -103,7 +104,8 @@ public class RtfListStyleText extends RtfListStyle {
             }
         }
         element.writeOneAttributeNS(
-                RtfListTable.LIST_TEXT_FORM, "\\'" + sCount + text);
+                RtfListTable.LIST_TEXT_FORM, "\\'" + sCount 
+                    + RtfStringConverter.getInstance().escape(text));
         element.writeGroupMark(false);
             
         element.writeGroupMark(true);
index e3861ad5b9cc775976ac4d58609e50ec54aeb0d7..abbd8b485b48ba9b35b2c58df50da2f83d5c996b 100644 (file)
@@ -78,7 +78,20 @@ public class RtfStringConverter {
         if (str == null) {
             return;
         }
+        w.write(escape(str));
+    }
 
+    /**
+     * Escapes a String as required by the RTF spec.
+     * @param str String to be escaped
+     * @return the escaped string
+     */
+    public String escape(String str) {
+        if (str == null) {
+            return null;
+        }
+
+        StringBuffer sb = new StringBuffer(Math.max(16, str.length()));
         // TODO: could be made more efficient (binary lookup, etc.)
         for (int i = 0; i < str.length(); i++) {
             final Character c = new Character(str.charAt(i));
@@ -102,20 +115,21 @@ public class RtfStringConverter {
 
             if (replacement != null) {
                 // RTF-escaped char
-                w.write('\\');
-                w.write(replacement);
-                w.write(' ');
+                sb.append('\\');
+                sb.append(replacement);
+                sb.append(' ');
             } else if (c.charValue() > 127) {
                 // write unicode representation - contributed by Michel Jacobson
                 // <jacobson@idf.ext.jussieu.fr>
-                w.write("\\u");
-                w.write(Integer.toString((int)c.charValue()));
-                w.write("\\\'3f");
+                sb.append("\\u");
+                sb.append(Integer.toString((int)c.charValue()));
+                sb.append("\\\'3f");
             } else {
                 // plain char that is understood by RTF natively
-                w.write(c.charValue());
+                sb.append(c.charValue());
             }
         }
+        return sb.toString();
     }
-
+    
 }