Java Code Examples for java.awt.BasicStroke#getLineJoin()

The following examples show how to use java.awt.BasicStroke#getLineJoin() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DummyGraphics2d.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void setStroke(Stroke s) {
    String l;
    if (s instanceof BasicStroke) {
        BasicStroke bs = (BasicStroke)s;
        l = "setStroke(Stoke):" +
            "\n  s = BasicStroke(" +
            "\n    dash[]: "+Arrays.toString(bs.getDashArray()) +
            "\n    dashPhase: "+bs.getDashPhase() +
            "\n    endCap: "+bs.getEndCap() +
            "\n    lineJoin: "+bs.getLineJoin() +
            "\n    width: "+bs.getLineWidth() +
            "\n    miterLimit: "+bs.getMiterLimit() +
            "\n  )";
    } else {
        l = "setStroke(Stoke):" +
            "\n  s = " + s;
    }
    log.println( l );
    g2D.setStroke( s );
}
 
Example 2
Source File: BasicStrokeValueConverter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public String toAttributeValue( final Object o ) throws BeanException {
  if ( o instanceof BasicStroke == false ) {
    throw new BeanException();
  }
  final BasicStroke s = (BasicStroke) o;
  final float lineWidth = s.getLineWidth();
  final int lineJoin = s.getLineJoin();
  final float dashPhase = s.getDashPhase();
  final int endCap = s.getEndCap();
  final float mitterLimit = s.getMiterLimit();
  final float[] dashArray = s.getDashArray();

  final StringBuilder b = new StringBuilder();
  if ( dashArray != null ) {
    for ( int i = 0; i < dashArray.length; i++ ) {
      if ( i != 0 ) {
        b.append( "," );
      }
      b.append( dashArray[i] );
    }
  }

  return String.format( Locale.US, "BasicStroke:%f:%d:%f:%d:%f:%s", lineWidth, lineJoin, dashPhase, endCap,
      mitterLimit, b.toString() );
}
 
Example 3
Source File: PixelToParallelogramConverter.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void drawRect(SunGraphics2D sg2d,
                     int x, int y, int w, int h)
{
    if (w >= 0 && h >= 0) {
        if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {
            BasicStroke bs = ((BasicStroke) sg2d.stroke);
            if (w > 0 && h > 0) {
                if (bs.getLineJoin() == BasicStroke.JOIN_MITER &&
                    bs.getDashArray() == null)
                {
                    double lw = bs.getLineWidth();
                    drawRectangle(sg2d, x, y, w, h, lw);
                    return;
                }
            } else {
                // Note: This calls the integer version which
                // will verify that the local drawLine optimizations
                // work and call super.drawLine(), if not.
                drawLine(sg2d, x, y, x+w, y+h);
                return;
            }
        }
        super.drawRect(sg2d, x, y, w, h);
    }
}
 
Example 4
Source File: PixelToParallelogramConverter.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public void drawRect(SunGraphics2D sg2d,
                     int x, int y, int w, int h)
{
    if (w >= 0 && h >= 0) {
        if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {
            BasicStroke bs = ((BasicStroke) sg2d.stroke);
            if (w > 0 && h > 0) {
                if (bs.getLineJoin() == BasicStroke.JOIN_MITER &&
                    bs.getDashArray() == null)
                {
                    double lw = bs.getLineWidth();
                    drawRectangle(sg2d, x, y, w, h, lw);
                    return;
                }
            } else {
                // Note: This calls the integer version which
                // will verify that the local drawLine optimizations
                // work and call super.drawLine(), if not.
                drawLine(sg2d, x, y, x+w, y+h);
                return;
            }
        }
        super.drawRect(sg2d, x, y, w, h);
    }
}
 
Example 5
Source File: PixelToParallelogramConverter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void drawRect(SunGraphics2D sg2d,
                     int x, int y, int w, int h)
{
    if (w >= 0 && h >= 0) {
        if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {
            BasicStroke bs = ((BasicStroke) sg2d.stroke);
            if (w > 0 && h > 0) {
                if (bs.getLineJoin() == BasicStroke.JOIN_MITER &&
                    bs.getDashArray() == null)
                {
                    double lw = bs.getLineWidth();
                    drawRectangle(sg2d, x, y, w, h, lw);
                    return;
                }
            } else {
                // Note: This calls the integer version which
                // will verify that the local drawLine optimizations
                // work and call super.drawLine(), if not.
                drawLine(sg2d, x, y, x+w, y+h);
                return;
            }
        }
        super.drawRect(sg2d, x, y, w, h);
    }
}
 
Example 6
Source File: PixelToParallelogramConverter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void draw(SunGraphics2D sg2d, Shape s) {
    if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {
        BasicStroke bs = ((BasicStroke) sg2d.stroke);
        if (s instanceof Rectangle2D) {
            if (bs.getLineJoin() == BasicStroke.JOIN_MITER &&
                bs.getDashArray() == null)
            {
                Rectangle2D r2d = (Rectangle2D) s;
                double w = r2d.getWidth();
                double h = r2d.getHeight();
                double x = r2d.getX();
                double y = r2d.getY();
                if (w >= 0 && h >= 0) {
                    double lw = bs.getLineWidth();
                    drawRectangle(sg2d, x, y, w, h, lw);
                }
                return;
            }
        } else if (s instanceof Line2D) {
            Line2D l2d = (Line2D) s;
            if (drawGeneralLine(sg2d,
                                l2d.getX1(), l2d.getY1(),
                                l2d.getX2(), l2d.getY2()))
            {
                return;
            }
        }
    }

    outpipe.draw(sg2d, s);
}
 
Example 7
Source File: PixelToParallelogramConverter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void draw(SunGraphics2D sg2d, Shape s) {
    if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {
        BasicStroke bs = ((BasicStroke) sg2d.stroke);
        if (s instanceof Rectangle2D) {
            if (bs.getLineJoin() == BasicStroke.JOIN_MITER &&
                bs.getDashArray() == null)
            {
                Rectangle2D r2d = (Rectangle2D) s;
                double w = r2d.getWidth();
                double h = r2d.getHeight();
                double x = r2d.getX();
                double y = r2d.getY();
                if (w >= 0 && h >= 0) {
                    double lw = bs.getLineWidth();
                    drawRectangle(sg2d, x, y, w, h, lw);
                }
                return;
            }
        } else if (s instanceof Line2D) {
            Line2D l2d = (Line2D) s;
            if (drawGeneralLine(sg2d,
                                l2d.getX1(), l2d.getY1(),
                                l2d.getX2(), l2d.getY2()))
            {
                return;
            }
        }
    }

    outpipe.draw(sg2d, s);
}
 
Example 8
Source File: PixelToParallelogramConverter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void draw(SunGraphics2D sg2d, Shape s) {
    if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {
        BasicStroke bs = ((BasicStroke) sg2d.stroke);
        if (s instanceof Rectangle2D) {
            if (bs.getLineJoin() == BasicStroke.JOIN_MITER &&
                bs.getDashArray() == null)
            {
                Rectangle2D r2d = (Rectangle2D) s;
                double w = r2d.getWidth();
                double h = r2d.getHeight();
                double x = r2d.getX();
                double y = r2d.getY();
                if (w >= 0 && h >= 0) {
                    double lw = bs.getLineWidth();
                    drawRectangle(sg2d, x, y, w, h, lw);
                }
                return;
            }
        } else if (s instanceof Line2D) {
            Line2D l2d = (Line2D) s;
            if (drawGeneralLine(sg2d,
                                l2d.getX1(), l2d.getY1(),
                                l2d.getX2(), l2d.getY2()))
            {
                return;
            }
        }
    }

    outpipe.draw(sg2d, s);
}
 
Example 9
Source File: PixelToParallelogramConverter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void draw(SunGraphics2D sg2d, Shape s) {
    if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {
        BasicStroke bs = ((BasicStroke) sg2d.stroke);
        if (s instanceof Rectangle2D) {
            if (bs.getLineJoin() == BasicStroke.JOIN_MITER &&
                bs.getDashArray() == null)
            {
                Rectangle2D r2d = (Rectangle2D) s;
                double w = r2d.getWidth();
                double h = r2d.getHeight();
                double x = r2d.getX();
                double y = r2d.getY();
                if (w >= 0 && h >= 0) {
                    double lw = bs.getLineWidth();
                    drawRectangle(sg2d, x, y, w, h, lw);
                }
                return;
            }
        } else if (s instanceof Line2D) {
            Line2D l2d = (Line2D) s;
            if (drawGeneralLine(sg2d,
                                l2d.getX1(), l2d.getY1(),
                                l2d.getX2(), l2d.getY2()))
            {
                return;
            }
        }
    }

    outpipe.draw(sg2d, s);
}
 
Example 10
Source File: EdgeEditor.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
static Stroke setEndCap(Stroke s, int cap) {
     if(s instanceof BasicStroke) {
BasicStroke b = (BasicStroke)s;
return new BasicStroke(b.getLineWidth(),
		       cap,
		       b.getLineJoin(),
		       b.getMiterLimit(),
		       b.getDashArray(),
		       b.getDashPhase());
     }
     else return s;
   }
 
Example 11
Source File: PdfGraphics2D.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Stroke transformStroke(Stroke stroke) {
    if (!(stroke instanceof BasicStroke))
        return stroke;
    BasicStroke st = (BasicStroke)stroke;
    float scale = (float)Math.sqrt(Math.abs(transform.getDeterminant()));
    float dash[] = st.getDashArray();
    if (dash != null) {
        for (int k = 0; k < dash.length; ++k)
            dash[k] *= scale;
    }
    return new BasicStroke(st.getLineWidth() * scale, st.getEndCap(), st.getLineJoin(), st.getMiterLimit(), dash, st.getDashPhase() * scale);
}
 
Example 12
Source File: PixelToParallelogramConverter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void draw(SunGraphics2D sg2d, Shape s) {
    if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {
        BasicStroke bs = ((BasicStroke) sg2d.stroke);
        if (s instanceof Rectangle2D) {
            if (bs.getLineJoin() == BasicStroke.JOIN_MITER &&
                bs.getDashArray() == null)
            {
                Rectangle2D r2d = (Rectangle2D) s;
                double w = r2d.getWidth();
                double h = r2d.getHeight();
                double x = r2d.getX();
                double y = r2d.getY();
                if (w >= 0 && h >= 0) {
                    double lw = bs.getLineWidth();
                    drawRectangle(sg2d, x, y, w, h, lw);
                }
                return;
            }
        } else if (s instanceof Line2D) {
            Line2D l2d = (Line2D) s;
            if (drawGeneralLine(sg2d,
                                l2d.getX1(), l2d.getY1(),
                                l2d.getX2(), l2d.getY2()))
            {
                return;
            }
        }
    }

    outpipe.draw(sg2d, s);
}
 
Example 13
Source File: PixelToParallelogramConverter.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void draw(SunGraphics2D sg2d, Shape s) {
    if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {
        BasicStroke bs = ((BasicStroke) sg2d.stroke);
        if (s instanceof Rectangle2D) {
            if (bs.getLineJoin() == BasicStroke.JOIN_MITER &&
                bs.getDashArray() == null)
            {
                Rectangle2D r2d = (Rectangle2D) s;
                double w = r2d.getWidth();
                double h = r2d.getHeight();
                double x = r2d.getX();
                double y = r2d.getY();
                if (w >= 0 && h >= 0) {
                    double lw = bs.getLineWidth();
                    drawRectangle(sg2d, x, y, w, h, lw);
                }
                return;
            }
        } else if (s instanceof Line2D) {
            Line2D l2d = (Line2D) s;
            if (drawGeneralLine(sg2d,
                                l2d.getX1(), l2d.getY1(),
                                l2d.getX2(), l2d.getY2()))
            {
                return;
            }
        }
    }

    outpipe.draw(sg2d, s);
}
 
Example 14
Source File: WPathGraphics.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
* Draw the bounding rectangle using transformed coordinates.
*/
@Override
protected void deviceFrameRect(int x, int y, int width, int height,
                                Color color) {

   AffineTransform deviceTransform = getTransform();

   /* check if rotated or sheared */
   int transformType = deviceTransform.getType();
   boolean usePath = ((transformType &
                      (AffineTransform.TYPE_GENERAL_ROTATION |
                       AffineTransform.TYPE_GENERAL_TRANSFORM)) != 0);

   if (usePath) {
       draw(new Rectangle2D.Float(x, y, width, height));
       return;
   }

   Stroke stroke = getStroke();

   if (stroke instanceof BasicStroke) {
       BasicStroke lineStroke = (BasicStroke) stroke;

       int endCap = lineStroke.getEndCap();
       int lineJoin = lineStroke.getLineJoin();


       /* check for default style and try to optimize it by
        * calling the frameRect native function instead of using paths.
        */
       if ((endCap == BasicStroke.CAP_SQUARE) &&
           (lineJoin == BasicStroke.JOIN_MITER) &&
           (lineStroke.getMiterLimit() ==10.0f)) {

           float lineWidth = lineStroke.getLineWidth();
           Point2D.Float penSize = new Point2D.Float(lineWidth,
                                                     lineWidth);

           deviceTransform.deltaTransform(penSize, penSize);
           float deviceLineWidth = Math.min(Math.abs(penSize.x),
                                            Math.abs(penSize.y));

           /* transform upper left coordinate */
           Point2D.Float ul_pos = new Point2D.Float(x, y);
           deviceTransform.transform(ul_pos, ul_pos);

           /* transform lower right coordinate */
           Point2D.Float lr_pos = new Point2D.Float(x + width,
                                                    y + height);
           deviceTransform.transform(lr_pos, lr_pos);

           float w = (float) (lr_pos.getX() - ul_pos.getX());
           float h = (float)(lr_pos.getY() - ul_pos.getY());

           WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob();

           /* use selectStylePen, if supported */
           if (wPrinterJob.selectStylePen(endCap, lineJoin,
                                      deviceLineWidth, color) == true)  {
               wPrinterJob.frameRect((float)ul_pos.getX(),
                                     (float)ul_pos.getY(), w, h);
           }
           /* not supported, must be a Win 9x */
           else {

               double lowerRes = Math.min(wPrinterJob.getXRes(),
                                          wPrinterJob.getYRes());

               if ((deviceLineWidth/lowerRes) < MAX_THINLINE_INCHES) {
                   /* use the default pen styles for thin pens. */
                   wPrinterJob.selectPen(deviceLineWidth, color);
                   wPrinterJob.frameRect((float)ul_pos.getX(),
                                         (float)ul_pos.getY(), w, h);
               }
               else {
                   draw(new Rectangle2D.Float(x, y, width, height));
               }
           }
       }
       else {
           draw(new Rectangle2D.Float(x, y, width, height));
       }
   }
}
 
Example 15
Source File: WPathGraphics.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
* Draw the bounding rectangle using transformed coordinates.
*/
@Override
protected void deviceFrameRect(int x, int y, int width, int height,
                                Color color) {

   AffineTransform deviceTransform = getTransform();

   /* check if rotated or sheared */
   int transformType = deviceTransform.getType();
   boolean usePath = ((transformType &
                      (AffineTransform.TYPE_GENERAL_ROTATION |
                       AffineTransform.TYPE_GENERAL_TRANSFORM)) != 0);

   if (usePath) {
       draw(new Rectangle2D.Float(x, y, width, height));
       return;
   }

   Stroke stroke = getStroke();

   if (stroke instanceof BasicStroke) {
       BasicStroke lineStroke = (BasicStroke) stroke;

       int endCap = lineStroke.getEndCap();
       int lineJoin = lineStroke.getLineJoin();


       /* check for default style and try to optimize it by
        * calling the frameRect native function instead of using paths.
        */
       if ((endCap == BasicStroke.CAP_SQUARE) &&
           (lineJoin == BasicStroke.JOIN_MITER) &&
           (lineStroke.getMiterLimit() ==10.0f)) {

           float lineWidth = lineStroke.getLineWidth();
           Point2D.Float penSize = new Point2D.Float(lineWidth,
                                                     lineWidth);

           deviceTransform.deltaTransform(penSize, penSize);
           float deviceLineWidth = Math.min(Math.abs(penSize.x),
                                            Math.abs(penSize.y));

           /* transform upper left coordinate */
           Point2D.Float ul_pos = new Point2D.Float(x, y);
           deviceTransform.transform(ul_pos, ul_pos);

           /* transform lower right coordinate */
           Point2D.Float lr_pos = new Point2D.Float(x + width,
                                                    y + height);
           deviceTransform.transform(lr_pos, lr_pos);

           float w = (float) (lr_pos.getX() - ul_pos.getX());
           float h = (float)(lr_pos.getY() - ul_pos.getY());

           WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob();

           /* use selectStylePen, if supported */
           if (wPrinterJob.selectStylePen(endCap, lineJoin,
                                      deviceLineWidth, color) == true)  {
               wPrinterJob.frameRect((float)ul_pos.getX(),
                                     (float)ul_pos.getY(), w, h);
           }
           /* not supported, must be a Win 9x */
           else {

               double lowerRes = Math.min(wPrinterJob.getXRes(),
                                          wPrinterJob.getYRes());

               if ((deviceLineWidth/lowerRes) < MAX_THINLINE_INCHES) {
                   /* use the default pen styles for thin pens. */
                   wPrinterJob.selectPen(deviceLineWidth, color);
                   wPrinterJob.frameRect((float)ul_pos.getX(),
                                         (float)ul_pos.getY(), w, h);
               }
               else {
                   draw(new Rectangle2D.Float(x, y, width, height));
               }
           }
       }
       else {
           draw(new Rectangle2D.Float(x, y, width, height));
       }
   }
}
 
Example 16
Source File: SVGGraphics2D.java    From jfreesvg with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a stroke style string based on the current stroke and
 * alpha settings.
 * 
 * @return A stroke style string.
 */
private String strokeStyle() {
    double strokeWidth = 1.0f;
    String strokeCap = DEFAULT_STROKE_CAP;
    String strokeJoin = DEFAULT_STROKE_JOIN;
    float miterLimit = DEFAULT_MITER_LIMIT;
    float[] dashArray = new float[0];
    if (this.stroke instanceof BasicStroke) {
        BasicStroke bs = (BasicStroke) this.stroke;
        strokeWidth = bs.getLineWidth() > 0.0 ? bs.getLineWidth() 
                : this.zeroStrokeWidth;
        switch (bs.getEndCap()) {
            case BasicStroke.CAP_ROUND:
                strokeCap = "round";
                break;
            case BasicStroke.CAP_SQUARE:
                strokeCap = "square";
                break;
            case BasicStroke.CAP_BUTT:
            default:
                // already set to "butt"    
        }
        switch (bs.getLineJoin()) {
            case BasicStroke.JOIN_BEVEL:
                strokeJoin = "bevel";
                break;
            case BasicStroke.JOIN_ROUND:
                strokeJoin = "round";
                break;
            case BasicStroke.JOIN_MITER:
            default:
                // already set to "miter"
        }
        miterLimit = bs.getMiterLimit();
        dashArray = bs.getDashArray();
    }
    StringBuilder b = new StringBuilder();
    b.append("stroke-width: ").append(strokeWidth).append(";");
    b.append("stroke: ").append(svgColorStr()).append(";");
    b.append("stroke-opacity: ").append(getColorAlpha() * getAlpha())
            .append(";");
    if (!strokeCap.equals(DEFAULT_STROKE_CAP)) {
        b.append("stroke-linecap: ").append(strokeCap).append(";");        
    }
    if (!strokeJoin.equals(DEFAULT_STROKE_JOIN)) {
        b.append("stroke-linejoin: ").append(strokeJoin).append(";");        
    }
    if (Math.abs(DEFAULT_MITER_LIMIT - miterLimit) < 0.001) {
        b.append("stroke-miterlimit: ").append(geomDP(miterLimit));        
    }
    if (dashArray != null && dashArray.length != 0) {
        b.append("stroke-dasharray: ");
        for (int i = 0; i < dashArray.length; i++) {
            if (i != 0) b.append(", ");
            b.append(dashArray[i]);
        }
        b.append(";");
    }
    if (this.checkStrokeControlHint) {
        Object hint = getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
        if (RenderingHints.VALUE_STROKE_NORMALIZE.equals(hint) 
                && !this.shapeRendering.equals("crispEdges")) {
            b.append("shape-rendering:crispEdges;");
        }
        if (RenderingHints.VALUE_STROKE_PURE.equals(hint) 
                && !this.shapeRendering.equals("geometricPrecision")) {
            b.append("shape-rendering:geometricPrecision;");
        }
    }
    return b.toString();
}
 
Example 17
Source File: WPathGraphics.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draw a line using a pen created using the specified color
 * and current stroke properties.
 */
@Override
protected void deviceDrawLine(int xBegin, int yBegin, int xEnd, int yEnd,
                              Color color) {
    Stroke stroke = getStroke();

    if (stroke instanceof BasicStroke) {
        BasicStroke lineStroke = (BasicStroke) stroke;

        if (lineStroke.getDashArray() != null) {
            draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd));
            return;
        }

        float lineWidth = lineStroke.getLineWidth();
        Point2D.Float penSize = new Point2D.Float(lineWidth, lineWidth);

        AffineTransform deviceTransform = getTransform();
        deviceTransform.deltaTransform(penSize, penSize);

        float deviceLineWidth = Math.min(Math.abs(penSize.x),
                                         Math.abs(penSize.y));

        Point2D.Float begin_pos = new Point2D.Float(xBegin, yBegin);
        deviceTransform.transform(begin_pos, begin_pos);

        Point2D.Float end_pos = new Point2D.Float(xEnd, yEnd);
        deviceTransform.transform(end_pos, end_pos);

        int endCap = lineStroke.getEndCap();
        int lineJoin = lineStroke.getLineJoin();

        /* check if it's a one-pixel line */
        if ((end_pos.getX() == begin_pos.getX())
            && (end_pos.getY() == begin_pos.getY())) {

            /* endCap other than Round will not print!
             * due to Windows GDI limitation, force it to CAP_ROUND
             */
            endCap = BasicStroke.CAP_ROUND;
        }


        WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob();

        /* call native function that creates pen with style */
        if (wPrinterJob.selectStylePen(endCap, lineJoin,
                                       deviceLineWidth, color)) {
            wPrinterJob.moveTo((float)begin_pos.getX(),
                               (float)begin_pos.getY());
            wPrinterJob.lineTo((float)end_pos.getX(),
                               (float)end_pos.getY());
        }
        /* selectStylePen is not supported, must be Win 9X */
        else {

            /* let's see if we can use a a default pen
             *  if it's round end (Windows' default style)
             *  or it's vertical/horizontal
             *  or stroke is too thin.
             */
            double lowerRes = Math.min(wPrinterJob.getXRes(),
                                       wPrinterJob.getYRes());

            if ((endCap == BasicStroke.CAP_ROUND) ||
             (((xBegin == xEnd) || (yBegin == yEnd)) &&
             (deviceLineWidth/lowerRes < MAX_THINLINE_INCHES))) {

                wPrinterJob.selectPen(deviceLineWidth, color);
                wPrinterJob.moveTo((float)begin_pos.getX(),
                                   (float)begin_pos.getY());
                wPrinterJob.lineTo((float)end_pos.getX(),
                                   (float)end_pos.getY());
            }
            else {
                draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd));
            }
        }
    }
}
 
Example 18
Source File: WPathGraphics.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
* Draw the bounding rectangle using transformed coordinates.
*/
@Override
protected void deviceFrameRect(int x, int y, int width, int height,
                                Color color) {

   AffineTransform deviceTransform = getTransform();

   /* check if rotated or sheared */
   int transformType = deviceTransform.getType();
   boolean usePath = ((transformType &
                      (AffineTransform.TYPE_GENERAL_ROTATION |
                       AffineTransform.TYPE_GENERAL_TRANSFORM)) != 0);

   if (usePath) {
       draw(new Rectangle2D.Float(x, y, width, height));
       return;
   }

   Stroke stroke = getStroke();

   if (stroke instanceof BasicStroke) {
       BasicStroke lineStroke = (BasicStroke) stroke;

       int endCap = lineStroke.getEndCap();
       int lineJoin = lineStroke.getLineJoin();


       /* check for default style and try to optimize it by
        * calling the frameRect native function instead of using paths.
        */
       if ((endCap == BasicStroke.CAP_SQUARE) &&
           (lineJoin == BasicStroke.JOIN_MITER) &&
           (lineStroke.getMiterLimit() ==10.0f)) {

           float lineWidth = lineStroke.getLineWidth();
           Point2D.Float penSize = new Point2D.Float(lineWidth,
                                                     lineWidth);

           deviceTransform.deltaTransform(penSize, penSize);
           float deviceLineWidth = Math.min(Math.abs(penSize.x),
                                            Math.abs(penSize.y));

           /* transform upper left coordinate */
           Point2D.Float ul_pos = new Point2D.Float(x, y);
           deviceTransform.transform(ul_pos, ul_pos);

           /* transform lower right coordinate */
           Point2D.Float lr_pos = new Point2D.Float(x + width,
                                                    y + height);
           deviceTransform.transform(lr_pos, lr_pos);

           float w = (float) (lr_pos.getX() - ul_pos.getX());
           float h = (float)(lr_pos.getY() - ul_pos.getY());

           WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob();

           /* use selectStylePen, if supported */
           if (wPrinterJob.selectStylePen(endCap, lineJoin,
                                      deviceLineWidth, color) == true)  {
               wPrinterJob.frameRect((float)ul_pos.getX(),
                                     (float)ul_pos.getY(), w, h);
           }
           /* not supported, must be a Win 9x */
           else {

               double lowerRes = Math.min(wPrinterJob.getXRes(),
                                          wPrinterJob.getYRes());

               if ((deviceLineWidth/lowerRes) < MAX_THINLINE_INCHES) {
                   /* use the default pen styles for thin pens. */
                   wPrinterJob.selectPen(deviceLineWidth, color);
                   wPrinterJob.frameRect((float)ul_pos.getX(),
                                         (float)ul_pos.getY(), w, h);
               }
               else {
                   draw(new Rectangle2D.Float(x, y, width, height));
               }
           }
       }
       else {
           draw(new Rectangle2D.Float(x, y, width, height));
       }
   }
}
 
Example 19
Source File: WPathGraphics.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draw a line using a pen created using the specified color
 * and current stroke properties.
 */
@Override
protected void deviceDrawLine(int xBegin, int yBegin, int xEnd, int yEnd,
                              Color color) {
    Stroke stroke = getStroke();

    if (stroke instanceof BasicStroke) {
        BasicStroke lineStroke = (BasicStroke) stroke;

        if (lineStroke.getDashArray() != null) {
            draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd));
            return;
        }

        float lineWidth = lineStroke.getLineWidth();
        Point2D.Float penSize = new Point2D.Float(lineWidth, lineWidth);

        AffineTransform deviceTransform = getTransform();
        deviceTransform.deltaTransform(penSize, penSize);

        float deviceLineWidth = Math.min(Math.abs(penSize.x),
                                         Math.abs(penSize.y));

        Point2D.Float begin_pos = new Point2D.Float(xBegin, yBegin);
        deviceTransform.transform(begin_pos, begin_pos);

        Point2D.Float end_pos = new Point2D.Float(xEnd, yEnd);
        deviceTransform.transform(end_pos, end_pos);

        int endCap = lineStroke.getEndCap();
        int lineJoin = lineStroke.getLineJoin();

        /* check if it's a one-pixel line */
        if ((end_pos.getX() == begin_pos.getX())
            && (end_pos.getY() == begin_pos.getY())) {

            /* endCap other than Round will not print!
             * due to Windows GDI limitation, force it to CAP_ROUND
             */
            endCap = BasicStroke.CAP_ROUND;
        }


        WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob();

        /* call native function that creates pen with style */
        if (wPrinterJob.selectStylePen(endCap, lineJoin,
                                       deviceLineWidth, color)) {
            wPrinterJob.moveTo((float)begin_pos.getX(),
                               (float)begin_pos.getY());
            wPrinterJob.lineTo((float)end_pos.getX(),
                               (float)end_pos.getY());
        }
        /* selectStylePen is not supported, must be Win 9X */
        else {

            /* let's see if we can use a a default pen
             *  if it's round end (Windows' default style)
             *  or it's vertical/horizontal
             *  or stroke is too thin.
             */
            double lowerRes = Math.min(wPrinterJob.getXRes(),
                                       wPrinterJob.getYRes());

            if ((endCap == BasicStroke.CAP_ROUND) ||
             (((xBegin == xEnd) || (yBegin == yEnd)) &&
             (deviceLineWidth/lowerRes < MAX_THINLINE_INCHES))) {

                wPrinterJob.selectPen(deviceLineWidth, color);
                wPrinterJob.moveTo((float)begin_pos.getX(),
                                   (float)begin_pos.getY());
                wPrinterJob.lineTo((float)end_pos.getX(),
                                   (float)end_pos.getY());
            }
            else {
                draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd));
            }
        }
    }
}
 
Example 20
Source File: WPathGraphics.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
* Draw the bounding rectangle using transformed coordinates.
*/
@Override
protected void deviceFrameRect(int x, int y, int width, int height,
                                Color color) {

   AffineTransform deviceTransform = getTransform();

   /* check if rotated or sheared */
   int transformType = deviceTransform.getType();
   boolean usePath = ((transformType &
                      (AffineTransform.TYPE_GENERAL_ROTATION |
                       AffineTransform.TYPE_GENERAL_TRANSFORM)) != 0);

   if (usePath) {
       draw(new Rectangle2D.Float(x, y, width, height));
       return;
   }

   Stroke stroke = getStroke();

   if (stroke instanceof BasicStroke) {
       BasicStroke lineStroke = (BasicStroke) stroke;

       int endCap = lineStroke.getEndCap();
       int lineJoin = lineStroke.getLineJoin();


       /* check for default style and try to optimize it by
        * calling the frameRect native function instead of using paths.
        */
       if ((endCap == BasicStroke.CAP_SQUARE) &&
           (lineJoin == BasicStroke.JOIN_MITER) &&
           (lineStroke.getMiterLimit() ==10.0f)) {

           float lineWidth = lineStroke.getLineWidth();
           Point2D.Float penSize = new Point2D.Float(lineWidth,
                                                     lineWidth);

           deviceTransform.deltaTransform(penSize, penSize);
           float deviceLineWidth = Math.min(Math.abs(penSize.x),
                                            Math.abs(penSize.y));

           /* transform upper left coordinate */
           Point2D.Float ul_pos = new Point2D.Float(x, y);
           deviceTransform.transform(ul_pos, ul_pos);

           /* transform lower right coordinate */
           Point2D.Float lr_pos = new Point2D.Float(x + width,
                                                    y + height);
           deviceTransform.transform(lr_pos, lr_pos);

           float w = (float) (lr_pos.getX() - ul_pos.getX());
           float h = (float)(lr_pos.getY() - ul_pos.getY());

           WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob();

           /* use selectStylePen, if supported */
           if (wPrinterJob.selectStylePen(endCap, lineJoin,
                                      deviceLineWidth, color) == true)  {
               wPrinterJob.frameRect((float)ul_pos.getX(),
                                     (float)ul_pos.getY(), w, h);
           }
           /* not supported, must be a Win 9x */
           else {

               double lowerRes = Math.min(wPrinterJob.getXRes(),
                                          wPrinterJob.getYRes());

               if ((deviceLineWidth/lowerRes) < MAX_THINLINE_INCHES) {
                   /* use the default pen styles for thin pens. */
                   wPrinterJob.selectPen(deviceLineWidth, color);
                   wPrinterJob.frameRect((float)ul_pos.getX(),
                                         (float)ul_pos.getY(), w, h);
               }
               else {
                   draw(new Rectangle2D.Float(x, y, width, height));
               }
           }
       }
       else {
           draw(new Rectangle2D.Float(x, y, width, height));
       }
   }
}