Search in sources :

Example 6 with Outline

use of org.apache.poi.sl.draw.geom.Outline in project poi by apache.

the class DrawSimpleShape method draw.

@Override
public void draw(Graphics2D graphics) {
    DrawPaint drawPaint = DrawFactory.getInstance(graphics).getPaint(getShape());
    Paint fill = drawPaint.getPaint(graphics, getShape().getFillStyle().getPaint());
    Paint line = drawPaint.getPaint(graphics, getShape().getStrokeStyle().getPaint());
    // the stroke applies both to the shadow and the shape
    BasicStroke stroke = getStroke();
    graphics.setStroke(stroke);
    Collection<Outline> elems = computeOutlines(graphics);
    // first paint the shadow
    drawShadow(graphics, elems, fill, line);
    // then fill the shape interior
    if (fill != null) {
        for (Outline o : elems) {
            if (o.getPath().isFilled()) {
                Paint fillMod = drawPaint.getPaint(graphics, getShape().getFillStyle().getPaint(), o.getPath().getFill());
                if (fillMod != null) {
                    graphics.setPaint(fillMod);
                    java.awt.Shape s = o.getOutline();
                    graphics.setRenderingHint(Drawable.GRADIENT_SHAPE, s);
                    graphics.fill(s);
                }
            }
        }
    }
    // then draw any content within this shape (text, image, etc.)
    drawContent(graphics);
    // then stroke the shape outline
    if (line != null) {
        graphics.setPaint(line);
        graphics.setStroke(stroke);
        for (Outline o : elems) {
            if (o.getPath().isStroked()) {
                java.awt.Shape s = o.getOutline();
                graphics.setRenderingHint(Drawable.GRADIENT_SHAPE, s);
                graphics.draw(s);
            }
        }
    }
    // draw line decorations
    drawDecoration(graphics, line, stroke);
}
Also used : BasicStroke(java.awt.BasicStroke) Outline(org.apache.poi.sl.draw.geom.Outline) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) Paint(java.awt.Paint)

Example 7 with Outline

use of org.apache.poi.sl.draw.geom.Outline in project poi by apache.

the class DrawFreeformShape method computeOutlines.

protected Collection<Outline> computeOutlines(Graphics2D graphics) {
    List<Outline> lst = new ArrayList<Outline>();
    FreeformShape<?, ?> fsh = getShape();
    Path2D sh = fsh.getPath();
    AffineTransform tx = (AffineTransform) graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
    if (tx == null) {
        tx = new AffineTransform();
    }
    java.awt.Shape canvasShape = tx.createTransformedShape(sh);
    FillStyle fs = fsh.getFillStyle();
    StrokeStyle ss = fsh.getStrokeStyle();
    Path path = new Path(fs != null, ss != null);
    lst.add(new Outline(canvasShape, path));
    return lst;
}
Also used : Path(org.apache.poi.sl.draw.geom.Path) Path2D(java.awt.geom.Path2D) ArrayList(java.util.ArrayList) FillStyle(org.apache.poi.sl.usermodel.FillStyle) AffineTransform(java.awt.geom.AffineTransform) Outline(org.apache.poi.sl.draw.geom.Outline) StrokeStyle(org.apache.poi.sl.usermodel.StrokeStyle)

Aggregations

Outline (org.apache.poi.sl.draw.geom.Outline)7 Path (org.apache.poi.sl.draw.geom.Path)6 AffineTransform (java.awt.geom.AffineTransform)4 Path2D (java.awt.geom.Path2D)3 Rectangle2D (java.awt.geom.Rectangle2D)3 ArrayList (java.util.ArrayList)3 Ellipse2D (java.awt.geom.Ellipse2D)2 DecorationShape (org.apache.poi.sl.usermodel.LineDecoration.DecorationShape)2 DecorationSize (org.apache.poi.sl.usermodel.LineDecoration.DecorationSize)2 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)2 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Paint (java.awt.Paint)1 JAXBContext (javax.xml.bind.JAXBContext)1 Context (org.apache.poi.sl.draw.geom.Context)1 CustomGeometry (org.apache.poi.sl.draw.geom.CustomGeometry)1 FillStyle (org.apache.poi.sl.usermodel.FillStyle)1 LineDecoration (org.apache.poi.sl.usermodel.LineDecoration)1 StrokeStyle (org.apache.poi.sl.usermodel.StrokeStyle)1