Search in sources :

Example 11 with SolidPaint

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

the class DrawPaint method getSolidPaint.

protected Paint getSolidPaint(SolidPaint fill, Graphics2D graphics, final PaintModifier modifier) {
    final ColorStyle orig = fill.getSolidColor();
    ColorStyle cs = new ColorStyle() {

        @Override
        public Color getColor() {
            return orig.getColor();
        }

        @Override
        public int getAlpha() {
            return orig.getAlpha();
        }

        @Override
        public int getHueOff() {
            return orig.getHueOff();
        }

        @Override
        public int getHueMod() {
            return orig.getHueMod();
        }

        @Override
        public int getSatOff() {
            return orig.getSatOff();
        }

        @Override
        public int getSatMod() {
            return orig.getSatMod();
        }

        @Override
        public int getLumOff() {
            return orig.getLumOff();
        }

        @Override
        public int getLumMod() {
            return orig.getLumMod();
        }

        @Override
        public int getShade() {
            int shade = orig.getShade();
            switch(modifier) {
                case DARKEN:
                    return Math.min(100000, Math.max(0, shade) + 40000);
                case DARKEN_LESS:
                    return Math.min(100000, Math.max(0, shade) + 20000);
                default:
                    return shade;
            }
        }

        @Override
        public int getTint() {
            int tint = orig.getTint();
            switch(modifier) {
                case LIGHTEN:
                    return Math.min(100000, Math.max(0, tint) + 40000);
                case LIGHTEN_LESS:
                    return Math.min(100000, Math.max(0, tint) + 20000);
                default:
                    return tint;
            }
        }
    };
    return applyColorTransform(cs);
}
Also used : ColorStyle(org.apache.poi.sl.usermodel.ColorStyle) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint) TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint)

Example 12 with SolidPaint

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

the class TestXSLFTheme method slide1.

void slide1(XSLFSlide slide) {
    assertEquals(Color.WHITE, slide.getBackground().getFillColor());
    XSLFTheme theme = slide.getTheme();
    assertEquals("Office Theme", theme.getName());
    XSLFTextShape sh1 = (XSLFTextShape) getShape(slide, "Rectangle 3");
    XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
    assertTrue(sameColor(Color.white, run1.getFontColor()));
    assertEquals(new Color(79, 129, 189), sh1.getFillColor());
    // solid fill
    assertTrue(sh1.getFillStyle().getPaint() instanceof SolidPaint);
}
Also used : SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) Color(java.awt.Color) TestCommonSL.sameColor(org.apache.poi.sl.TestCommonSL.sameColor)

Example 13 with SolidPaint

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

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

Aggregations

SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)14 Color (java.awt.Color)12 PaintStyle (org.apache.poi.sl.usermodel.PaintStyle)4 BitMaskTextProp (org.apache.poi.hslf.model.textproperties.BitMaskTextProp)2 TextProp (org.apache.poi.hslf.model.textproperties.TextProp)2 TestCommonSL.sameColor (org.apache.poi.sl.TestCommonSL.sameColor)2 ColorStyle (org.apache.poi.sl.usermodel.ColorStyle)2 GradientPaint (org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)2 Test (org.junit.Test)2 CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)2 LinearGradientPaint (java.awt.LinearGradientPaint)1 Paint (java.awt.Paint)1 RadialGradientPaint (java.awt.RadialGradientPaint)1 Ellipse2D (java.awt.geom.Ellipse2D)1 Path2D (java.awt.geom.Path2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 CharFlagsTextProp (org.apache.poi.hslf.model.textproperties.CharFlagsTextProp)1 ParagraphFlagsTextProp (org.apache.poi.hslf.model.textproperties.ParagraphFlagsTextProp)1 DrawPaint (org.apache.poi.sl.draw.DrawPaint)1 Outline (org.apache.poi.sl.draw.geom.Outline)1