Search in sources :

Example 1 with AutoNumberingScheme

use of org.apache.poi.sl.usermodel.AutoNumberingScheme in project poi by apache.

the class DrawTextParagraph method getBullet.

protected DrawTextFragment getBullet(Graphics2D graphics, AttributedCharacterIterator firstLineAttr) {
    BulletStyle bulletStyle = paragraph.getBulletStyle();
    if (bulletStyle == null) {
        return null;
    }
    String buCharacter;
    AutoNumberingScheme ans = bulletStyle.getAutoNumberingScheme();
    if (ans != null) {
        buCharacter = ans.format(autoNbrIdx);
    } else {
        buCharacter = bulletStyle.getBulletCharacter();
    }
    if (buCharacter == null) {
        return null;
    }
    String buFont = bulletStyle.getBulletFont();
    if (buFont == null) {
        buFont = paragraph.getDefaultFontFamily();
    }
    assert (buFont != null);
    PlaceableShape<?, ?> ps = getParagraphShape();
    PaintStyle fgPaintStyle = bulletStyle.getBulletFontColor();
    Paint fgPaint;
    if (fgPaintStyle == null) {
        fgPaint = (Paint) firstLineAttr.getAttribute(TextAttribute.FOREGROUND);
    } else {
        fgPaint = new DrawPaint(ps).getPaint(graphics, fgPaintStyle);
    }
    float fontSize = (Float) firstLineAttr.getAttribute(TextAttribute.SIZE);
    Double buSz = bulletStyle.getBulletFontSize();
    if (buSz == null) {
        buSz = 100d;
    }
    if (buSz > 0) {
        fontSize *= buSz * 0.01;
    } else {
        fontSize = (float) -buSz;
    }
    AttributedString str = new AttributedString(mapFontCharset(buCharacter, buFont));
    str.addAttribute(TextAttribute.FOREGROUND, fgPaint);
    str.addAttribute(TextAttribute.FAMILY, buFont);
    str.addAttribute(TextAttribute.SIZE, fontSize);
    TextLayout layout = new TextLayout(str.getIterator(), graphics.getFontRenderContext());
    DrawFactory fact = DrawFactory.getInstance(graphics);
    return fact.getTextFragment(layout, str);
}
Also used : AttributedString(java.text.AttributedString) Paint(java.awt.Paint) TextLayout(java.awt.font.TextLayout) AttributedString(java.text.AttributedString) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) BulletStyle(org.apache.poi.sl.usermodel.TextParagraph.BulletStyle) AutoNumberingScheme(org.apache.poi.sl.usermodel.AutoNumberingScheme)

Example 2 with AutoNumberingScheme

use of org.apache.poi.sl.usermodel.AutoNumberingScheme in project poi by apache.

the class XSLFTextParagraph method getAutoNumberingScheme.

/**
     * @return the auto numbering scheme, or null if not defined
     */
public AutoNumberingScheme getAutoNumberingScheme() {
    ParagraphPropertyFetcher<AutoNumberingScheme> fetcher = new ParagraphPropertyFetcher<AutoNumberingScheme>(getIndentLevel()) {

        public boolean fetch(CTTextParagraphProperties props) {
            if (props.isSetBuAutoNum()) {
                AutoNumberingScheme ans = AutoNumberingScheme.forOoxmlID(props.getBuAutoNum().getType().intValue());
                if (ans != null) {
                    setValue(ans);
                    return true;
                }
            }
            return false;
        }
    };
    fetchParagraphProperty(fetcher);
    return fetcher.getValue();
}
Also used : ParagraphPropertyFetcher(org.apache.poi.xslf.model.ParagraphPropertyFetcher) CTTextParagraphProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties) AutoNumberingScheme(org.apache.poi.sl.usermodel.AutoNumberingScheme)

Aggregations

AutoNumberingScheme (org.apache.poi.sl.usermodel.AutoNumberingScheme)2 Paint (java.awt.Paint)1 TextLayout (java.awt.font.TextLayout)1 AttributedString (java.text.AttributedString)1 PaintStyle (org.apache.poi.sl.usermodel.PaintStyle)1 BulletStyle (org.apache.poi.sl.usermodel.TextParagraph.BulletStyle)1 ParagraphPropertyFetcher (org.apache.poi.xslf.model.ParagraphPropertyFetcher)1 CTTextParagraphProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties)1