当前位置:编程学习 > JAVA >>

itext怎么避免标点符号出现在的首列

看了itex2.1.7的源码
在com.lowagie.text.pdf.BidiLine这个类的processLine方法修改了换行规则
 在 for (; currentChar < totalTextLength; ++currentChar) 里面添加了标点符号的判断:
 ck2 = detailChunks[currentChar+1];
              if (currentChar < totalTextLength-1) {
   nextSurrogate = Utilities.isSurrogatePair(text, currentChar+1);
   if (nextSurrogate){
   nextUnic = ck2.getUnicodeEquivalent(Utilities.convertToUtf32(text, currentChar+1));
   nextCharWidth = ck2.getCharWidth(nextUnic);
   }
   else{
   nextUnic = ck2.getUnicodeEquivalent(text[currentChar+1]);
   nextCharWidth = ck2.getCharWidth(text[currentChar+1]);
   }
    if (width - charWidth - nextCharWidth <= 2) {
       if (ChineseSymbolSplit.isIncludeChar(nextUnic)) {
       System.out.println("不能以标点符号开头!");
     break;
     }
     }

   }
思路是在行结尾时先判断当前字符之后的是否为标点符号,是的话就把标点符号和前面的字符一起换到下一行。
但是测试结果没达到这个效果。
请问有解决过这个问题的大哥吗 --------------------编程问答-------------------- 简单写了一个正则:
str = str.replaceAll("(\n)([,]+)", "$2\n");
[]里面你添加上所有的标点,或者干脆用ASSIC值吧 --------------------编程问答--------------------
引用 1 楼 AA5279AA 的回复:
简单写了一个正则:
str = str.replaceAll("(\n)([,]+)", "$2\n");
[]里面你添加上所有的标点,或者干脆用ASSIC值吧

谢谢,匹配标点我也写了一个,测试了下应该是可以的,现在是在itext内部换行的规则上要做些修改。
补充:Java ,  Java相关
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,