diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2020-11-02 23:56:27 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2020-11-02 23:56:27 +0000 |
commit | b20318b58cc4a1a5c7a342915c32cd493233ea0f (patch) | |
tree | b675bf20af0a1713458a2bb784fafa3ed39d5d2e /src/java/org/apache/poi/sl | |
parent | dae47d5cedbca87646a2421618e2afac9b04fd3a (diff) | |
download | poi-b20318b58cc4a1a5c7a342915c32cd493233ea0f.tar.gz poi-b20318b58cc4a1a5c7a342915c32cd493233ea0f.zip |
#64867 - Provide PDF rendering with PPTX2PNG
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1883074 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/sl')
-rw-r--r-- | src/java/org/apache/poi/sl/draw/DrawTextFragment.java | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/java/org/apache/poi/sl/draw/DrawTextFragment.java b/src/java/org/apache/poi/sl/draw/DrawTextFragment.java index cb2ef66df9..7bc23cfa7c 100644 --- a/src/java/org/apache/poi/sl/draw/DrawTextFragment.java +++ b/src/java/org/apache/poi/sl/draw/DrawTextFragment.java @@ -17,7 +17,9 @@ package org.apache.poi.sl.draw; +import java.awt.Color; import java.awt.Graphics2D; +import java.awt.font.TextAttribute; import java.awt.font.TextLayout; import java.text.AttributedCharacterIterator; import java.text.AttributedString; @@ -50,7 +52,22 @@ public class DrawTextFragment implements Drawable { if(textMode != null && textMode == Drawable.TEXT_AS_SHAPES){ layout.draw(graphics, (float)x, (float)yBaseline); } else { - graphics.drawString(str.getIterator(), (float)x, (float)yBaseline ); + try { + graphics.drawString(str.getIterator(), (float) x, (float) yBaseline); + } catch (ClassCastException e) { + // workaround: batik issue, which expects only Color as forground color + replaceForgroundPaintWithBlack(str); + graphics.drawString(str.getIterator(), (float) x, (float) yBaseline); + } + } + } + + private void replaceForgroundPaintWithBlack(AttributedString as) { + AttributedCharacterIterator iter = as.getIterator(new TextAttribute[]{TextAttribute.FOREGROUND}); + for (char ch = iter.first(); + ch != CharacterIterator.DONE; + ch = iter.next()) { + as.addAttribute(TextAttribute.FOREGROUND, Color.BLACK, iter.getBeginIndex(), iter.getEndIndex()); } } |