BugFix for JDK-6623219
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1783698 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7810671d2d
commit
0744f73add
@ -649,12 +649,12 @@ public class DrawTextParagraph implements Drawable {
|
||||
|
||||
// check for unsupported characters and add a fallback font for these
|
||||
char textChr[] = runText.toCharArray();
|
||||
int nextEnd = f.canDisplayUpTo(textChr, 0, textChr.length);
|
||||
int nextEnd = canDisplayUpTo(f, textChr, 0, textChr.length);
|
||||
int last = nextEnd;
|
||||
boolean isNextValid = (nextEnd == 0);
|
||||
while ( nextEnd != -1 && nextEnd <= textChr.length ) {
|
||||
if (isNextValid) {
|
||||
nextEnd = f.canDisplayUpTo(textChr, nextEnd, textChr.length);
|
||||
nextEnd = canDisplayUpTo(f, textChr, nextEnd, textChr.length);
|
||||
isNextValid = false;
|
||||
} else {
|
||||
if (nextEnd >= textChr.length || f.canDisplay(Character.codePointAt(textChr, nextEnd, textChr.length)) ) {
|
||||
@ -728,4 +728,43 @@ public class DrawTextParagraph implements Drawable {
|
||||
}
|
||||
return attStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether or not this {@code Font} can display the characters in the specified {@code text}
|
||||
* starting at {@code start} and ending at {@code limit}.<p>
|
||||
*
|
||||
* This is a workaround for the Java 6 implementation of {@link Font#canDisplayUpTo(char[], int, int)}
|
||||
*
|
||||
* @param font the font to inspect
|
||||
* @param text the specified array of {@code char} values
|
||||
* @param start the specified starting offset (in
|
||||
* {@code char}s) into the specified array of
|
||||
* {@code char} values
|
||||
* @param limit the specified ending offset (in
|
||||
* {@code char}s) into the specified array of
|
||||
* {@code char} values
|
||||
* @return an offset into {@code text} that points
|
||||
* to the first character in {@code text} that this
|
||||
* {@code Font} cannot display; or {@code -1} if
|
||||
* this {@code Font} can display all characters in
|
||||
* {@code text}.
|
||||
*
|
||||
* @see <a href="https://bugs.openjdk.java.net/browse/JDK-6623219">Font.canDisplayUpTo does not work with supplementary characters</a>
|
||||
*/
|
||||
protected static int canDisplayUpTo(Font font, char[] text, int start, int limit) {
|
||||
for (int i = start; i < limit; i++) {
|
||||
char c = text[i];
|
||||
if (font.canDisplay(c)) {
|
||||
continue;
|
||||
}
|
||||
if (!Character.isHighSurrogate(c)) {
|
||||
return i;
|
||||
}
|
||||
if (!font.canDisplay(Character.codePointAt(text, i, limit))) {
|
||||
return i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class TestPPTX2PNG {
|
||||
private static final POIDataSamples samples = POIDataSamples.getSlideShowInstance();
|
||||
private static final File basedir = null;
|
||||
private static final String files =
|
||||
"53446.ppt, alterman_security.ppt, alterman_security.pptx, KEY02.pptx, themes.pptx, backgrounds.pptx, layouts.pptx, sample.pptx, shapes.pptx";
|
||||
"53446.ppt, alterman_security.ppt, alterman_security.pptx, KEY02.pptx, themes.pptx, backgrounds.pptx, layouts.pptx, sample.pptx, shapes.pptx, 54880_chinese.ppt";
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user