import org.apache.poi.sl.usermodel.TextRun;\r
import org.apache.poi.sl.usermodel.TextRun.TextCap;\r
import org.apache.poi.sl.usermodel.TextShape;\r
+import org.apache.poi.util.StringUtil;\r
import org.apache.poi.util.Units;\r
\r
public class DrawTextParagraph implements Drawable {\r
if (indent == null) {\r
indent = Units.toPoints(347663*indentLevel);\r
}\r
- if (paragraph.getClass().getName().contains("HSLF")) {\r
+ if (isHSLF()) {\r
// special handling for HSLF\r
indent -= leftMargin;\r
}\r
String buFont = bulletStyle.getBulletFont();\r
if (buFont == null) buFont = paragraph.getDefaultFontFamily();\r
assert(buFont != null);\r
-\r
+ \r
PlaceableShape<?,?> ps = getParagraphShape();\r
PaintStyle fgPaintStyle = bulletStyle.getBulletFontColor();\r
Paint fgPaint;\r
else fontSize = (float)-buSz;\r
\r
\r
- AttributedString str = new AttributedString(buCharacter);\r
+ AttributedString str = new AttributedString(mapFontCharset(buCharacter,buFont));\r
str.addAttribute(TextAttribute.FOREGROUND, fgPaint);\r
str.addAttribute(TextAttribute.FAMILY, buFont);\r
str.addAttribute(TextAttribute.SIZE, fontSize);\r
*/\r
private String tab2space(TextRun tr) {\r
AttributedString string = new AttributedString(" ");\r
- String typeFace = tr.getFontFamily();\r
- if (typeFace == null) typeFace = "Lucida Sans";\r
- string.addAttribute(TextAttribute.FAMILY, typeFace);\r
+ String fontFamily = tr.getFontFamily();\r
+ if (fontFamily == null) fontFamily = "Lucida Sans";\r
+ string.addAttribute(TextAttribute.FAMILY, fontFamily);\r
\r
Double fs = tr.getFontSize();\r
if (fs == null) fs = 12d;\r
Rectangle2D anchor = DrawShape.getAnchor(graphics, paragraph.getParentShape());\r
\r
int indentLevel = paragraph.getIndentLevel();\r
+ if (indentLevel == -1) {\r
+ // default to 0, if indentLevel is not set\r
+ indentLevel = 0;\r
+ }\r
Double leftMargin = paragraph.getLeftMargin();\r
if (leftMargin == null) {\r
// if the marL attribute is omitted, then a value of 347663 is implied\r
width = ts.getSheet().getSlideShow().getPageSize().getWidth() - anchor.getX();\r
} else {\r
width = anchor.getWidth() - leftInset - rightInset - leftMargin - rightMargin;\r
- if (firstLine) {\r
+ if (firstLine && !isHSLF()) {\r
if (bullet != null){\r
if (indent > 0) width -= indent;\r
} else {\r
// skip empty runs\r
if (runText.isEmpty()) continue;\r
\r
- int beginIndex = text.length();\r
- text.append(runText);\r
- int endIndex = text.length();\r
-\r
- PaintStyle fgPaintStyle = run.getFontColor();\r
- Paint fgPaint = new DrawPaint(ps).getPaint(graphics, fgPaintStyle);\r
- attList.add(new AttributedStringData(TextAttribute.FOREGROUND, fgPaint, beginIndex, endIndex));\r
-\r
// user can pass an custom object to convert fonts\r
String fontFamily = run.getFontFamily();\r
@SuppressWarnings("unchecked")\r
if (fontFamily == null) {\r
fontFamily = paragraph.getDefaultFontFamily();\r
}\r
+ \r
+ int beginIndex = text.length();\r
+ text.append(mapFontCharset(runText,fontFamily));\r
+ int endIndex = text.length();\r
+\r
attList.add(new AttributedStringData(TextAttribute.FAMILY, fontFamily, beginIndex, endIndex));\r
\r
+ PaintStyle fgPaintStyle = run.getFontColor();\r
+ Paint fgPaint = new DrawPaint(ps).getPaint(graphics, fgPaintStyle);\r
+ attList.add(new AttributedStringData(TextAttribute.FOREGROUND, fgPaint, beginIndex, endIndex));\r
+\r
Double fontSz = run.getFontSize();\r
if (fontSz == null) fontSz = paragraph.getDefaultFontSize();\r
attList.add(new AttributedStringData(TextAttribute.SIZE, fontSz.floatValue(), beginIndex, endIndex));\r
return string;\r
}\r
\r
+ protected boolean isHSLF() {\r
+ return paragraph.getClass().getName().contains("HSLF"); \r
+ }\r
+ \r
+ /**\r
+ * Map text charset depending on font family.\r
+ * Currently this only maps for wingdings font (into unicode private use area)\r
+ *\r
+ * @param text the raw text\r
+ * @param fontFamily the font family\r
+ * @return AttributedString with mapped codepoints\r
+ * \r
+ * @see <a href="http://stackoverflow.com/questions/8692095">Drawing exotic fonts in a java applet</a>\r
+ * @see StringUtil#mapMsCodepointString(String)\r
+ */\r
+ protected String mapFontCharset(String text, String fontFamily) {\r
+ // TODO: find a real charset mapping solution instead of hard coding for Wingdings\r
+ String attStr = text;\r
+ if ("Wingdings".equalsIgnoreCase(fontFamily)) {\r
+ // wingdings doesn't contain high-surrogates, so chars are ok\r
+ boolean changed = false;\r
+ char chrs[] = attStr.toCharArray();\r
+ for (int i=0; i<chrs.length; i++) {\r
+ // only change valid chars\r
+ if ((0x20 <= chrs[i] && chrs[i] <= 0x7f) ||\r
+ (0xa0 <= chrs[i] && chrs[i] <= 0xff)) {\r
+ chrs[i] |= 0xf000;\r
+ changed = true;\r
+ }\r
+ }\r
\r
+ if (changed) {\r
+ attStr = new String(chrs);\r
+ }\r
+ }\r
+ return attStr;\r
+ }\r
}\r