From: Andreas Beeker Date: Sun, 19 Feb 2017 21:36:45 +0000 (+0000) Subject: BugFix for JDK-6623219 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0744f73adde340bb28c3b3c6cb321ad19798a8d4;p=poi.git BugFix for JDK-6623219 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1783698 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java b/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java index c60d0b45c7..6ce2a7f8ad 100644 --- a/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java +++ b/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java @@ -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}.

+ * + * 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 Font.canDisplayUpTo does not work with supplementary characters + */ + 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; + } } diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java index 0ae8463f6a..50ad6347a4 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java @@ -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";