From b20318b58cc4a1a5c7a342915c32cd493233ea0f Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Mon, 2 Nov 2020 23:56:27 +0000 Subject: #64867 - Provide PDF rendering with PPTX2PNG git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1883074 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/sl/draw/DrawTextFragment.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/java/org/apache/poi/sl') 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()); } } -- cgit v1.2.3