Package com.google.code.appengine.awt.geom

Examples of com.google.code.appengine.awt.geom.Rectangle2D


*/
public final class ShapePainter {
    protected static POILogger logger = POILogFactory.getLogger(ShapePainter.class);

    public static void paint(SimpleShape shape, Graphics2D graphics){
        Rectangle2D anchor = shape.getLogicalAnchor2D();
        com.google.code.appengine.awt.Shape outline = shape.getOutline();

        //flip vertical
        if(shape.getFlipVertical()){
            graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight());
            graphics.scale(1, -1);
            graphics.translate(-anchor.getX(), -anchor.getY());
        }
        //flip horizontal
        if(shape.getFlipHorizontal()){
            graphics.translate(anchor.getX() + anchor.getWidth(), 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.getWidth()/2;
            double centerY = anchor.getY() + anchor.getHeight()/2;

            graphics.translate(centerX, centerY);
            graphics.rotate(Math.toRadians(angle));
            graphics.translate(-centerX, -centerY);
        }
View Full Code Here


        setEscherProperty((short)(EscherProperties.GEOMETRY__ADJUSTVALUE + idx), val);
    }

    public com.google.code.appengine.awt.Shape getOutline(){
        ShapeOutline outline = AutoShapes.getShapeOutline(getShapeType());
        Rectangle2D anchor = getLogicalAnchor2D();
        if(outline == null){
            logger.log(POILogger.WARN, "Outline not found for " + ShapeTypes.typeName(getShapeType()));
            return anchor;
        }
        com.google.code.appengine.awt.Shape shape = outline.getOutline(this);
View Full Code Here

    private Point2D drawFrameAndBanner(TextLayout tl, double x, double y, int horizontal,
            int vertical, boolean framed, Color frameColor, double frameWidth,
            boolean banner, Color bannerColor) {

        // calculate string bounds for alignment
        Rectangle2D bounds = tl.getBounds();

        // calculate real bounds
        bounds.setRect(
            bounds.getX(),
            bounds.getY(),
            // care for Italic fonts too
            Math.max(tl.getAdvance(), bounds.getWidth()),
            bounds.getHeight());

        // add x and y
        AffineTransform at = AffineTransform.getTranslateInstance(x, y);

        // horizontal alignment
        if (horizontal == TEXT_RIGHT) {
            at.translate(- bounds.getWidth(), 0);
        } else if (horizontal == TEXT_CENTER) {
            at.translate(- bounds.getWidth() / 2, 0);
        }

        // vertical alignment
        if (vertical == TEXT_BASELINE) {
            // no translation needed
        } else if (vertical == TEXT_TOP) {
            at.translate(0, - bounds.getY());
        } else if (vertical == TEXT_CENTER) {
            // the following adds supersript ascent too,
            // so it does not work
            // at.translate(0, tl.getAscent() / 2);
            // this is nearly the same
            at.translate(0, tl.getDescent());
        } else if (vertical == TEXT_BOTTOM) {
            at.translate(0, - bounds.getHeight() - bounds.getY());
        }

        // transform the bounds
        bounds = at.createTransformedShape(bounds).getBounds2D();
        // create the result with the same transformation
        Point2D result = at.transform(new Point2D.Double(0, 0), new Point2D.Double());

        // space between string and border
        double adjustment = (getFont().getSize2D() * 2) / 10;

        // add the adjustment
        bounds.setRect(
            bounds.getX() - adjustment,
            bounds.getY() - adjustment,
            bounds.getWidth() + 2 * adjustment,
            bounds.getHeight() + 2 * adjustment);

        if (banner) {
            Paint paint = getPaint();
            setColor(bannerColor);
            fill(bounds);
View Full Code Here

                / FONT_SIZE + " 0.0 0.0] readonly def");
    }

    protected void closeIncludeFont() {

        Rectangle2D boundingBox = getFontBBox();
        int llx = (int) Math.round(boundingBox.getX());
        int lly = (int) Math.round(boundingBox.getY());
        int urx = (int) Math.round(boundingBox.getX() + boundingBox.getWidth());
        int ury = (int) Math
                .round(boundingBox.getY() + boundingBox.getHeight());
        fontFile.println("/FontBBox {" + llx + " " + lly + " " + urx + " "
                + ury + "} readonly def");

        fontFile.println("currentdict end");
View Full Code Here

        return _escherContainer;
    }

    public com.google.code.appengine.awt.Shape getOutline(){
        Rectangle2D anchor = getLogicalAnchor2D();
        return new Line2D.Double(anchor.getX(), anchor.getY(), anchor.getX() + anchor.getWidth(), anchor.getY() + anchor.getHeight());
    }
View Full Code Here

        (int) center.getX(),
        (int) center.getY(),
        getX( index, 1 ),
        getY( index, 1 ) );

      Rectangle2D bounds = g.getFontMetrics().getStringBounds( label, g );

      // draw axis label
      ChartFont cfont = props.getTitleChartFont();
      if( cfont != null )
      {
        g.setFont( cfont.getFont() );

      }
      g.drawString(
        label,
        (int) ( getX( index + 1, 1 ) - bounds.getWidth() / 2 ),
        getY( index + 1, 1 ) );
    }

    // draw gridline labels
    g.setColor( Color.darkGray );
    g.setFont( ChartFont.DEFAULT_AXIS_VALUE.getFont() );
    int selectedLine = (int) iRadarChartDataSet.getNumberOfDataItems() / 2;
    for( double i = scaleIncrement; i <= scaleMax; i += scaleIncrement )
    {
      double pos = scaleValue( i );
      Rectangle2D bounds = g.getFont().getStringBounds( "1",
                                        g.getFontRenderContext() );
      g.drawString( props.getGridLabelFormat().format( i ),
                getX( selectedLine, pos ),
                (int) Math.round( getY( selectedLine, pos ) + bounds.getHeight() ) );
    }

  }
View Full Code Here

     *
     * @param path
     */
    public void setPath(GeneralPath path)
    {
        Rectangle2D bounds = path.getBounds2D();
        PathIterator it = path.getPathIterator(new AffineTransform());

        List<byte[]> segInfo = new ArrayList<byte[]>();
        List<Point2D.Double> pntInfo = new ArrayList<Point2D.Double>();
        boolean isClosed = false;
        while (!it.isDone()) {
            double[] vals = new double[6];
            int type = it.currentSegment(vals);
            switch (type) {
                case PathIterator.SEG_MOVETO:
                    pntInfo.add(new Point2D.Double(vals[0], vals[1]));
                    segInfo.add(SEGMENTINFO_MOVETO);
                    break;
                case PathIterator.SEG_LINETO:
                    pntInfo.add(new Point2D.Double(vals[0], vals[1]));
                    segInfo.add(SEGMENTINFO_LINETO);
                    segInfo.add(SEGMENTINFO_ESCAPE);
                    break;
                case PathIterator.SEG_CUBICTO:
                    pntInfo.add(new Point2D.Double(vals[0], vals[1]));
                    pntInfo.add(new Point2D.Double(vals[2], vals[3]));
                    pntInfo.add(new Point2D.Double(vals[4], vals[5]));
                    segInfo.add(SEGMENTINFO_CUBICTO);
                    segInfo.add(SEGMENTINFO_ESCAPE2);
                    break;
                case PathIterator.SEG_QUADTO:
                    //TODO: figure out how to convert SEG_QUADTO into SEG_CUBICTO
                    logger.log(POILogger.WARN, "SEG_QUADTO is not supported");
                    break;
                case PathIterator.SEG_CLOSE:
                    pntInfo.add(pntInfo.get(0));
                    segInfo.add(SEGMENTINFO_LINETO);
                    segInfo.add(SEGMENTINFO_ESCAPE);
                    segInfo.add(SEGMENTINFO_LINETO);
                    segInfo.add(SEGMENTINFO_CLOSE);
                    isClosed = true;
                    break;
            }

            it.next();
        }
        if(!isClosed) segInfo.add(SEGMENTINFO_LINETO);
        segInfo.add(new byte[]{0x00, (byte)0x80});

        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4));

        EscherArrayProperty verticesProp = new EscherArrayProperty((short)(EscherProperties.GEOMETRY__VERTICES + 0x4000), false, null);
        verticesProp.setNumberOfElementsInArray(pntInfo.size());
        verticesProp.setNumberOfElementsInMemory(pntInfo.size());
        verticesProp.setSizeOfElements(0xFFF0);
        for (int i = 0; i < pntInfo.size(); i++) {
            Point2D.Double pnt = pntInfo.get(i);
            byte[] data = new byte[4];
            LittleEndian.putShort(data, 0, (short)((pnt.getX() - bounds.getX())*MASTER_DPI/POINT_DPI));
            LittleEndian.putShort(data, 2, (short)((pnt.getY() - bounds.getY())*MASTER_DPI/POINT_DPI));
            verticesProp.setElement(i, data);
        }
        opt.addEscherProperty(verticesProp);

        EscherArrayProperty segmentsProp = new EscherArrayProperty((short)(EscherProperties.GEOMETRY__SEGMENTINFO + 0x4000), false, null);
        segmentsProp.setNumberOfElementsInArray(segInfo.size());
        segmentsProp.setNumberOfElementsInMemory(segInfo.size());
        segmentsProp.setSizeOfElements(0x2);
        for (int i = 0; i < segInfo.size(); i++) {
            byte[] seg = segInfo.get(i);
            segmentsProp.setElement(i, seg);
        }
        opt.addEscherProperty(segmentsProp);

        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, (int)(bounds.getWidth()*MASTER_DPI/POINT_DPI)));
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, (int)(bounds.getHeight()*MASTER_DPI/POINT_DPI)));

        opt.sortProperties();

        setAnchor(bounds);
    }
View Full Code Here

        return path;
    }

    public com.google.code.appengine.awt.Shape getOutline(){
        GeneralPath path =  getPath();
        Rectangle2D anchor = getAnchor2D();
        Rectangle2D bounds = path.getBounds2D();
        AffineTransform at = new AffineTransform();
        at.translate(anchor.getX(), anchor.getY());
        at.scale(
                anchor.getWidth()/bounds.getWidth(),
                anchor.getHeight()/bounds.getHeight()
        );
        return at.createTransformedShape(path);
    }
View Full Code Here

    /**
     *
     * @return 'absolute' anchor of this shape relative to the parent sheet
     */
    public Rectangle2D getLogicalAnchor2D(){
        Rectangle2D anchor = getAnchor2D();

        //if it is a groupped shape see if we need to transform the coordinates
        if (_parent != null){
            List<Shape> lst = new ArrayList<Shape>();
            lst.add(_parent);
            Shape top = _parent;
            while(top.getParent() != null) {
                top = top.getParent();
                lst.add(top);
            }

            AffineTransform tx = new AffineTransform();
            for(int i = lst.size() - 1; i >= 0; i--) {
                ShapeGroup prnt = (ShapeGroup)lst.get(i);
                Rectangle2D exterior = prnt.getAnchor2D();
                Rectangle2D interior = prnt.getCoordinates();

                double scaleX =  exterior.getWidth() / interior.getWidth();
                double scaleY = exterior.getHeight() / interior.getHeight();

                tx.translate(exterior.getX(), exterior.getY());
                tx.scale(scaleX, scaleY);
                tx.translate(-interior.getX(), -interior.getY());
            }
            anchor = tx.createTransformedShape(anchor).getBounds2D();
        }

        int angle = getRotation();
        if(angle != 0){
            double centerX = anchor.getX() + anchor.getWidth()/2;
            double centerY = anchor.getY() + anchor.getHeight()/2;

            AffineTransform trans = new AffineTransform();
            trans.translate(centerX, centerY);
            trans.rotate(Math.toRadians(angle));
            trans.translate(-centerX, -centerY);

            Rectangle2D rect = trans.createTransformedShape(anchor).getBounds2D();
            if((anchor.getWidth() < anchor.getHeight() && rect.getWidth() > rect.getHeight()) ||
                (anchor.getWidth() > anchor.getHeight() && rect.getWidth() < rect.getHeight())    ){
                trans = new AffineTransform();
                trans.translate(centerX, centerY);
                trans.rotate(Math.PI/2);
                trans.translate(-centerX, -centerY);
                anchor = trans.createTransformedShape(anchor).getBounds2D();
View Full Code Here

            width = Math.max(width, layout.getAdvance());
            height = Math.max(height, (height + (layout.getDescent() + layout.getAscent())));
        }

        // add one character to width
        Rectangle2D charBounds = font.getMaxCharBounds(_frc);
        width += getMarginLeft() + getMarginRight() + charBounds.getWidth();

        // add leading to height
        height += getMarginTop() + getMarginBottom() + leading;

        Rectangle2D anchor = getAnchor2D();
        anchor.setRect(anchor.getX(), anchor.getY(), width, height);
        setAnchor(anchor);

        return anchor;
    }
View Full Code Here

TOP

Related Classes of com.google.code.appengine.awt.geom.Rectangle2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.