Search in sources :

Example 16 with PaintStyle

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

the class TestXSLFTheme method slide8.

void slide8(XSLFSlide slide) {
    PaintStyle fs = slide.getBackground().getFillStyle().getPaint();
    assertTrue(fs instanceof TexturePaint);
}
Also used : TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle)

Example 17 with PaintStyle

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

the class XSLFShape method getFillPaint.

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

        public boolean fetch(XSLFShape shape) {
            XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(shape.getShapeProperties());
            if (fp == null) {
                return false;
            }
            if (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.getFillRef());
                paint = selectPaint(fp, null, pp, theme, hasPlaceholder);
            }
            if (paint != null) {
                setValue(paint);
                return true;
            }
            return false;
        }
    };
    fetchShapeProperty(fetcher);
    return fetcher.getValue();
}
Also used : CTShapeStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) PropertyFetcher(org.apache.poi.xslf.model.PropertyFetcher) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) XSLFFillProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)

Example 18 with PaintStyle

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

the class TestBugs method bug55983.

@Test
public void bug55983() throws IOException {
    HSLFSlideShow ppt1 = new HSLFSlideShow();
    HSLFSlide sl = ppt1.createSlide();
    sl.getBackground().getFill().setForegroundColor(Color.blue);
    HSLFFreeformShape fs = sl.createFreeform();
    Ellipse2D.Double el = new Ellipse2D.Double(0, 0, 300, 200);
    fs.setAnchor(new Rectangle2D.Double(100, 100, 300, 200));
    fs.setPath(new Path2D.Double(el));
    Color cExp = new Color(50, 100, 150, 200);
    fs.setFillColor(cExp);
    HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
    ppt1.close();
    sl = ppt2.getSlides().get(0);
    fs = (HSLFFreeformShape) sl.getShapes().get(0);
    Color cAct = fs.getFillColor();
    assertEquals(cExp.getRed(), cAct.getRed());
    assertEquals(cExp.getGreen(), cAct.getGreen());
    assertEquals(cExp.getBlue(), cAct.getBlue());
    assertEquals(cExp.getAlpha(), cAct.getAlpha(), 1);
    PaintStyle ps = fs.getFillStyle().getPaint();
    assertTrue(ps instanceof SolidPaint);
    ColorStyle cs = ((SolidPaint) ps).getSolidColor();
    cAct = cs.getColor();
    assertEquals(cExp.getRed(), cAct.getRed());
    assertEquals(cExp.getGreen(), cAct.getGreen());
    assertEquals(cExp.getBlue(), cAct.getBlue());
    assertEquals(255, cAct.getAlpha());
    assertEquals(cExp.getAlpha() * 100000. / 255., cs.getAlpha(), 1);
    ppt2.close();
}
Also used : ColorStyle(org.apache.poi.sl.usermodel.ColorStyle) Path2D(java.awt.geom.Path2D) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) Ellipse2D(java.awt.geom.Ellipse2D) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) Test(org.junit.Test)

Example 19 with PaintStyle

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

the class TestBugs method bug45124.

@Test
public void bug45124() throws IOException {
    SlideShow<?, ?> ppt = open("bug45124.ppt");
    Slide<?, ?> slide1 = ppt.getSlides().get(1);
    TextBox<?, ?> res = slide1.createTextBox();
    res.setAnchor(new java.awt.Rectangle(60, 150, 700, 100));
    res.setText("I am italic-false, bold-true inserted text");
    TextParagraph<?, ?, ?> tp = res.getTextParagraphs().get(0);
    TextRun rt = tp.getTextRuns().get(0);
    rt.setItalic(false);
    assertTrue(rt.isBold());
    tp.setBulletStyle(Color.red, 'A');
    SlideShow<?, ?> ppt2 = HSLFTestDataSamples.writeOutAndReadBack((HSLFSlideShow) ppt);
    ppt.close();
    res = (TextBox<?, ?>) ppt2.getSlides().get(1).getShapes().get(1);
    tp = res.getTextParagraphs().get(0);
    rt = tp.getTextRuns().get(0);
    assertFalse(rt.isItalic());
    assertTrue(rt.isBold());
    PaintStyle ps = tp.getBulletStyle().getBulletFontColor();
    assertTrue(ps instanceof SolidPaint);
    Color actColor = DrawPaint.applyColorTransform(((SolidPaint) ps).getSolidColor());
    assertEquals(Color.red, actColor);
    assertEquals("A", tp.getBulletStyle().getBulletCharacter());
    ppt2.close();
}
Also used : SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) Color(java.awt.Color) TextRun(org.apache.poi.sl.usermodel.TextRun) Test(org.junit.Test)

Example 20 with PaintStyle

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

the class PptxImpl method fillTexture.

private void fillTexture(JSONArray elements, JSONObject element, PaintStyle paintStyle, StreamWriter streamWriter) {
    PaintStyle.TexturePaint texturePaint = (PaintStyle.TexturePaint) paintStyle;
    try {
        InputStream inputStream = texturePaint.getImageData();
        JSONObject object = new JSONObject();
        object.putAll(element);
        object.put(Parser.TYPE_IMAGE, streamWriter.write(texturePaint.getContentType(), "", inputStream));
        elements.add(object);
        inputStream.close();
    } catch (IOException e) {
        logger.warn(e, "保存图片[{}]流数据时发生异常!", texturePaint.getContentType());
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) InputStream(java.io.InputStream) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) IOException(java.io.IOException)

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