Search in sources :

Example 6 with PaintStyle

use of org.apache.poi.sl.usermodel.PaintStyle 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 7 with PaintStyle

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

the class TestXSLFTheme method slide4.

void slide4(XSLFSlide slide) {
    PaintStyle fs = slide.getBackground().getFillStyle().getPaint();
    assertTrue(fs instanceof GradientPaint);
    XSLFTextShape sh1 = (XSLFTextShape) getShape(slide, "Rectangle 4");
    XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
    assertTrue(sameColor(Color.white, run1.getFontColor()));
    assertEquals(new Color(148, 198, 0), sh1.getFillColor());
    // solid fill
    assertTrue(sh1.getFillStyle().getPaint() instanceof SolidPaint);
    XSLFTextShape sh2 = (XSLFTextShape) getShape(slide, "Title 3");
    XSLFTextRun run2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
    assertTrue(sameColor(new Color(148, 198, 0), run2.getFontColor()));
    // no fill
    assertNull(sh2.getFillColor());
    assertTrue(slide.getSlideLayout().getFollowMasterGraphics());
}
Also used : SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) Color(java.awt.Color) TestCommonSL.sameColor(org.apache.poi.sl.TestCommonSL.sameColor) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)

Example 8 with PaintStyle

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

the class HSLFTextParagraph method getBulletStyle.

@Override
public BulletStyle getBulletStyle() {
    if (!isBullet() && getAutoNumberingScheme() == null) {
        return null;
    }
    return new BulletStyle() {

        @Override
        public String getBulletCharacter() {
            Character chr = HSLFTextParagraph.this.getBulletChar();
            return (chr == null || chr == 0) ? "" : "" + chr;
        }

        @Override
        public String getBulletFont() {
            return HSLFTextParagraph.this.getBulletFont();
        }

        @Override
        public Double getBulletFontSize() {
            return HSLFTextParagraph.this.getBulletSize();
        }

        @Override
        public void setBulletFontColor(Color color) {
            setBulletFontColor(DrawPaint.createSolidPaint(color));
        }

        @Override
        public void setBulletFontColor(PaintStyle color) {
            if (!(color instanceof SolidPaint)) {
                throw new IllegalArgumentException("HSLF only supports SolidPaint");
            }
            SolidPaint sp = (SolidPaint) color;
            Color col = DrawPaint.applyColorTransform(sp.getSolidColor());
            HSLFTextParagraph.this.setBulletColor(col);
        }

        @Override
        public PaintStyle getBulletFontColor() {
            Color col = HSLFTextParagraph.this.getBulletColor();
            return DrawPaint.createSolidPaint(col);
        }

        @Override
        public AutoNumberingScheme getAutoNumberingScheme() {
            return HSLFTextParagraph.this.getAutoNumberingScheme();
        }

        @Override
        public Integer getAutoNumberingStartAt() {
            return HSLFTextParagraph.this.getAutoNumberingStartAt();
        }
    };
}
Also used : SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) Color(java.awt.Color) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle)

Example 9 with PaintStyle

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

the class XSLFSimpleShape method getLinePaint.

protected PaintStyle getLinePaint() {
    XSLFSheet sheet = getSheet();
    final XSLFTheme theme = sheet.getTheme();
    final boolean hasPlaceholder = getPlaceholder() != null;
    PropertyFetcher<PaintStyle> fetcher = new PropertyFetcher<PaintStyle>() {

        @Override
        public boolean fetch(XSLFShape shape) {
            CTLineProperties spPr = getLn(shape, false);
            XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(spPr);
            if (fp != null && fp.isSetNoFill()) {
                setValue(null);
                return true;
            }
            PackagePart pp = shape.getSheet().getPackagePart();
            PaintStyle paint = selectPaint(fp, null, pp, theme, hasPlaceholder);
            if (paint != null) {
                setValue(paint);
                return true;
            }
            CTShapeStyle style = shape.getSpStyle();
            if (style != null) {
                fp = XSLFPropertiesDelegate.getFillDelegate(style.getLnRef());
                paint = selectPaint(fp, null, pp, theme, hasPlaceholder);
                // line color was not found, check if it is defined in the theme
                if (paint == null) {
                    paint = getThemePaint(style, pp);
                }
            }
            if (paint != null) {
                setValue(paint);
                return true;
            }
            return false;
        }

        PaintStyle getThemePaint(CTShapeStyle style, PackagePart pp) {
            // get a reference to a line style within the style matrix.
            CTStyleMatrixReference lnRef = style.getLnRef();
            if (lnRef == null) {
                return null;
            }
            int idx = (int) lnRef.getIdx();
            CTSchemeColor phClr = lnRef.getSchemeClr();
            if (idx <= 0) {
                return null;
            }
            CTLineProperties props = theme.getXmlObject().getThemeElements().getFmtScheme().getLnStyleLst().getLnArray(idx - 1);
            XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(props);
            return selectPaint(fp, phClr, pp, theme, hasPlaceholder);
        }
    };
    fetchShapeProperty(fetcher);
    return fetcher.getValue();
}
Also used : CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) CTLineProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties) PropertyFetcher(org.apache.poi.xslf.model.PropertyFetcher) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) CTShapeStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) CTStyleMatrixReference(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference) XSLFFillProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)

Example 10 with PaintStyle

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

the class XSLFTextRun method getFontColor.

@Override
public PaintStyle getFontColor() {
    final boolean hasPlaceholder = getParentParagraph().getParentShape().getPlaceholder() != null;
    CharacterPropertyFetcher<PaintStyle> fetcher = new CharacterPropertyFetcher<PaintStyle>(_p.getIndentLevel()) {

        public boolean fetch(CTTextCharacterProperties props) {
            if (props == null) {
                return false;
            }
            XSLFShape shape = _p.getParentShape();
            CTShapeStyle style = shape.getSpStyle();
            CTSchemeColor phClr = null;
            if (style != null && style.getFontRef() != null) {
                phClr = style.getFontRef().getSchemeClr();
            }
            XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(props);
            XSLFSheet sheet = shape.getSheet();
            PackagePart pp = sheet.getPackagePart();
            XSLFTheme theme = sheet.getTheme();
            PaintStyle ps = XSLFShape.selectPaint(fp, phClr, pp, theme, hasPlaceholder);
            if (ps != null) {
                setValue(ps);
                return true;
            }
            return false;
        }
    };
    fetchCharacterProperty(fetcher);
    return fetcher.getValue();
}
Also used : CTShapeStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle) CharacterPropertyFetcher(org.apache.poi.xslf.model.CharacterPropertyFetcher) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) XSLFFillProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)

Aggregations

PaintStyle (org.apache.poi.sl.usermodel.PaintStyle)20 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)6 Color (java.awt.Color)5 TexturePaint (org.apache.poi.sl.usermodel.PaintStyle.TexturePaint)5 XSLFFillProperties (org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)5 GradientPaint (org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)4 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)3 DrawPaint (org.apache.poi.sl.draw.DrawPaint)3 Test (org.junit.Test)3 CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)3 CTShapeStyle (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle)3 Paint (java.awt.Paint)2 AttributedString (java.text.AttributedString)2 TestCommonSL.sameColor (org.apache.poi.sl.TestCommonSL.sameColor)2 TextRun (org.apache.poi.sl.usermodel.TextRun)2 PropertyFetcher (org.apache.poi.xslf.model.PropertyFetcher)2 XmlCursor (org.apache.xmlbeans.XmlCursor)2 XmlObject (org.apache.xmlbeans.XmlObject)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Font (java.awt.Font)1