我目前正在尝试一种解决方法。似乎对我有用,但我对此并不满意。
function nonBreak(textObj) {
var origString = textObj.text;
var compStr = origString.replace(/(.|[\r\n])*?<nbr>.*?($|\s)/, "");
compStr = origString.replace(compStr, "");
compStr1 = compStr.replace(/<nbr>/, " ");
compStr2 = compStr.replace(/<nbr>/, "\n");
textObj.text = compStr1;
var sizeStr1 = textObj.getMetrics().height;
textObj.text = compStr2;
sizeStr2 = textObj.getMetrics().height;
textObj.text = origString;
if (sizeStr1 == sizeStr2) {
newString1 = origString.replace(/\s?[^ ]*<nbr>.*/, "");
newString2 = origString.replace(newString1 + " ", "");
newString1 = newString1 + "\n";
newString2 = newString2.replace(/<nbr>/, " ");
newString = newString1 + newString2;
textObj.text = newString;
} else {
newString = origString.replace(/<nbr>/, " ");
textObj.text = newString;
}
}
var origString = this.copy_01.text;
var textCopy = this.copy_01;
var countBR = origString.match(/<nbr>/g);
if (countBR !== null) {
for (i = 0; i < countBR.length; i++) {
if (countBR[i] == "<nbr>") {
nonBreak(textCopy);
}
}
}