Exemplo n.º 1
0
    public static void paint(SimpleShape shape, Graphics2D graphics){
        Rectangle2D anchor = shape.GetLogicalAnchor2D();
        java.awt.Shape outline = shape.GetOutline();

        //flip vertical
        if(shape.GetFlipVertical()){
            graphics.translate(anchor.GetX(), anchor.GetY() + anchor.Height);
            graphics.scale(1, -1);
            graphics.translate(-anchor.GetX(), -anchor.GetY());
        }
        //flip horizontal
        if(shape.GetFlipHorizontal()){
            graphics.translate(anchor.GetX() + anchor.Width, anchor.GetY());
            graphics.scale(-1, 1);
            graphics.translate(-anchor.GetX() , -anchor.GetY());
        }

        //rotate transform
        double angle = shape.GetRotation();

        if(angle != 0){
            double centerX = anchor.GetX() + anchor.Width/2;
            double centerY = anchor.GetY() + anchor.Height/2;

            graphics.translate(centerX, centerY);
            graphics.rotate(Math.ToRadians(angle));
            graphics.translate(-centerX, -centerY);
        }

        //fill
        Color FillColor = shape.GetFill().GetForegroundColor();
        if (FillColor != null) {
            //TODO: implement gradient and texture fill patterns
            graphics.SetPaint(FillColor);
            graphics.Fill(outline);
        }

        //border
        Color lineColor = shape.GetLineColor();
        if (lineColor != null){
            graphics.SetPaint(lineColor);
            float width = (float)shape.GetLineWidth();

            int dashing = shape.GetLineDashing();
            //TODO: implement more dashing styles
            float[] dashptrn = null;
            switch(dashing){
                case Line.PEN_SOLID:
                    dashptrn = null;
                    break;
                case Line.PEN_PS_DASH:
                    dashptrn = new float[]{width, width};
                    break;
                case Line.PEN_DOTGEL:
                    dashptrn = new float[]{width*4, width*3};
                    break;
               default:
                    logger.log(POILogger.WARN, "unsupported dashing: " + dashing);
                    dashptrn = new float[]{width, width};
                    break;
            }

            Stroke stroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashptrn, 0.0f);
            graphics.SetStroke(stroke);
            graphics.Draw(outline);
        }
    }