Ignore:
Timestamp:
01/30/14 11:11:40 (10 years ago)
Author:
jts21
Message:

Add support to PDF2Writer for rotated images, filled polyons, polylines, and arrows (complete with arrowheads)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/items/Line.java

    r737 r789  
    1111import java.awt.Stroke;
    1212import java.awt.geom.AffineTransform;
     13import java.awt.geom.Point2D;
    1314import java.util.ArrayList;
    1415import java.util.Collection;
     
    405406                g.setStroke(new BasicStroke(getPaintThickness(), CAP,
    406407                                BasicStroke.JOIN_MITER));
    407                 paintArrow(g, _start, _startOffset, _endOffset);
    408                 paintArrow(g, _end, _endOffset, _startOffset);
     408                paintArrow(g, getStartArrow());
     409                paintArrow(g, getEndArrow());
    409410
    410411                if (_virtualSpot != null) {
     
    429430
    430431        }
    431 
    432         /**
    433          * Based on code from DeSL (Arrow2D) http://sourceforge.net/projects/desl/
    434          */
    435         private void paintArrow(Graphics2D g, Item withArrow, Point startOffset,
    436                         Point endOffset) {
     432       
     433        /**
     434         * Gets the arrow head
     435         * @param withArrow
     436         * @param startOffset
     437         * @param endOffset
     438         * @return
     439         */
     440        private Shape getArrow(Item withArrow, Point startOffset, Point endOffset) {
    437441                boolean disconnectMode = withArrow._mode == Item.HighlightMode.Disconnect;
    438442                // only draw an arrowhead if necessary
    439443                if (!(this._mode == Item.HighlightMode.Disconnect && disconnectMode)
    440444                                && (!withArrow.hasVisibleArrow() || withArrow.getLines().size() > 1))
    441                         return;
     445                        return null;
    442446
    443447                int x0, x1, y0, y1;
     
    462466                // floating
    463467                if (arrowLength != AUTO_ARROWHEAD_LENGTH && (arrowRatio < 0 || arrowNibPerc < 0)) {
    464                         return;
     468                        return null;
    465469                }
    466470
     
    473477                // wont show the arrow
    474478                if (length <= MINIMUM_ARROW_HEAD_LENGTH)
    475                         return;
     479                        return null;
    476480                if (arrowLength == AUTO_ARROWHEAD_LENGTH) {
    477481                        arrowLength = getAutoArrowheadLength(length);
     
    498502                AffineTransform tx = AffineTransform.getRotateInstance(rad, x0, y0);
    499503               
     504        int[] rx = new int[arrowhead.npoints];
     505        int[] ry = new int[arrowhead.npoints];
     506       
     507        for(int i = 0; i < arrowhead.npoints; i++){
     508            Point2D p = new Point2D.Double(arrowhead.xpoints[i], arrowhead.ypoints[i]);
     509            tx.transform(p,p);
     510            rx[i] = (int) p.getX();
     511            ry[i] = (int) p.getY();
     512        }
     513       
     514        return new Polygon(rx, ry, arrowhead.npoints);
     515        }
     516       
     517        public Polygon getStartArrow() {
     518                return (Polygon) getArrow(_start, _startOffset, _endOffset);
     519        }
     520       
     521        public Polygon getEndArrow() {
     522                return (Polygon) getArrow(_end, _endOffset, _startOffset);
     523        }
     524
     525        /**
     526         * Based on code from DeSL (Arrow2D) http://sourceforge.net/projects/desl/
     527         */
     528        private void paintArrow(Graphics2D g, Shape arrow) {
     529               
     530                if(arrow == null) {
     531                        return;
     532                }
    500533               
    501534                // TODO
     
    508541                g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    509542               
    510                 g.draw(tx.createTransformedShape((Shape) arrowhead));
    511                 g.fill(tx.createTransformedShape((Shape) arrowhead));
     543                g.draw(arrow);
     544                g.fill(arrow);
    512545       
    513546        }
Note: See TracChangeset for help on using the changeset viewer.