You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/11/09 00:11:22 UTC

svn commit: r1713316 - in /poi: site/src/documentation/content/xdocs/status.xml trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java

Author: kiwiwings
Date: Sun Nov  8 23:11:22 2015
New Revision: 1713316

URL: http://svn.apache.org/viewvc?rev=1713316&view=rev
Log:
#52297 - Bullets are not aligned properly while converting ppt slide to image

Modified:
    poi/site/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java

Modified: poi/site/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1713316&r1=1713315&r2=1713316&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Sun Nov  8 23:11:22 2015
@@ -40,6 +40,8 @@
     </devs>
 
     <release version="3.14-beta1" date="2015-11-??">
+        <action dev="PD" type="add">Add support for HSLF metro blobs</action>
+        <action dev="PD" type="fix" fixes-bug="52297">Bullets are not aligned properly while converting ppt slide to image</action>
         <action dev="PD" type="fix" fixes-bug="55265">DataFormatter correct support for alternate number grouping characters, eg 1234 + #'##0 = 1'234 not 1,234</action>
         <action dev="PD" type="fix" fixes-bug="51622">autoSizeColumn incorrectly sizes columns containing leading whitespace</action>
         <action dev="PD" type="fix" fixes-bug="58576">Rename misspelled SheetUtil.canComputeColumnWidth</action>

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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org