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

The following examples show how to use java.awt.BasicStroke#getLineWidth() . These examples are extracted from open source projects. 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
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 2
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 3
/**
 * Sets the stroke that will be used to draw shapes.
 * 
 * @param s  the stroke ({@code null} not permitted).
 * 
 * @see #getStroke() 
 */
@Override
public void setStroke(Stroke s) {
    nullNotPermitted(s, "s");
    this.stroke = s;
    if (stroke instanceof BasicStroke) {
        BasicStroke bs = (BasicStroke) s;
        double lineWidth = bs.getLineWidth();
        if (lineWidth == 0.0) {
            lineWidth = this.zeroStrokeWidth;
        }
        this.gc.setLineWidth(lineWidth);
        this.gc.setLineCap(awtToJavaFXLineCap(bs.getEndCap()));
        this.gc.setLineJoin(awtToJavaFXLineJoin(bs.getLineJoin()));
        this.gc.setMiterLimit(bs.getMiterLimit());
    }
}
 
Example 4
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
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 6
void strokeTo(Shape src,
              AffineTransform at,
              BasicStroke bs,
              boolean thin,
              NormMode normalize,
              boolean antialias,
              PathConsumer2D pc2d)
{
    float lw;
    if (thin) {
        if (antialias) {
            lw = userSpaceLineWidth(at, 0.5f);
        } else {
            lw = userSpaceLineWidth(at, 1.0f);
        }
    } else {
        lw = bs.getLineWidth();
    }
    strokeTo(src,
             at,
             lw,
             normalize,
             bs.getEndCap(),
             bs.getLineJoin(),
             bs.getMiterLimit(),
             bs.getDashArray(),
             bs.getDashPhase(),
             pc2d);
}
 
Example 7
void strokeTo(Shape src,
              AffineTransform at,
              BasicStroke bs,
              boolean thin,
              NormMode normalize,
              boolean antialias,
              PathConsumer2D pc2d)
{
    float lw;
    if (thin) {
        if (antialias) {
            lw = userSpaceLineWidth(at, 0.5f);
        } else {
            lw = userSpaceLineWidth(at, 1.0f);
        }
    } else {
        lw = bs.getLineWidth();
    }
    strokeTo(src,
             at,
             lw,
             normalize,
             bs.getEndCap(),
             bs.getLineJoin(),
             bs.getMiterLimit(),
             bs.getDashArray(),
             bs.getDashPhase(),
             pc2d);
}
 
Example 8
Source Project: pdfxtk   File: EdgeEditor.java    License: 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 9
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
void strokeTo(Shape src,
              AffineTransform at,
              BasicStroke bs,
              boolean thin,
              NormMode normalize,
              boolean antialias,
              PathConsumer2D pc2d)
{
    float lw;
    if (thin) {
        if (antialias) {
            lw = userSpaceLineWidth(at, 0.5f);
        } else {
            lw = userSpaceLineWidth(at, 1.0f);
        }
    } else {
        lw = bs.getLineWidth();
    }
    strokeTo(src,
             at,
             lw,
             normalize,
             bs.getEndCap(),
             bs.getLineJoin(),
             bs.getMiterLimit(),
             bs.getDashArray(),
             bs.getDashPhase(),
             pc2d);
}
 
Example 11
private void validateBasicStroke(BasicStroke bs) {
    boolean aa = (antialiasHint == SunHints.INTVAL_ANTIALIAS_ON);
    if (transformState < TRANSFORM_TRANSLATESCALE) {
        if (aa) {
            if (bs.getLineWidth() <= MinPenSizeAA) {
                if (bs.getDashArray() == null) {
                    strokeState = STROKE_THIN;
                } else {
                    strokeState = STROKE_THINDASHED;
                }
            } else {
                strokeState = STROKE_WIDE;
            }
        } else {
            if (bs == defaultStroke) {
                strokeState = STROKE_THIN;
            } else if (bs.getLineWidth() <= 1.0f) {
                if (bs.getDashArray() == null) {
                    strokeState = STROKE_THIN;
                } else {
                    strokeState = STROKE_THINDASHED;
                }
            } else {
                strokeState = STROKE_WIDE;
            }
        }
    } else {
        double widthsquared;
        if ((transform.getType() & NON_UNIFORM_SCALE_MASK) == 0) {
            /* sqrt omitted, compare to squared limits below. */
            widthsquared = Math.abs(transform.getDeterminant());
        } else {
            /* First calculate the "maximum scale" of this transform. */
            double A = transform.getScaleX();       // m00
            double C = transform.getShearX();       // m01
            double B = transform.getShearY();       // m10
            double D = transform.getScaleY();       // m11

            /*
             * Given a 2 x 2 affine matrix [ A B ] such that
             *                             [ C D ]
             * v' = [x' y'] = [Ax + Cy, Bx + Dy], we want to
             * find the maximum magnitude (norm) of the vector v'
             * with the constraint (x^2 + y^2 = 1).
             * The equation to maximize is
             *     |v'| = sqrt((Ax+Cy)^2+(Bx+Dy)^2)
             * or  |v'| = sqrt((AA+BB)x^2 + 2(AC+BD)xy + (CC+DD)y^2).
             * Since sqrt is monotonic we can maximize |v'|^2
             * instead and plug in the substitution y = sqrt(1 - x^2).
             * Trigonometric equalities can then be used to get
             * rid of most of the sqrt terms.
             */
            double EA = A*A + B*B;          // x^2 coefficient
            double EB = 2*(A*C + B*D);      // xy coefficient
            double EC = C*C + D*D;          // y^2 coefficient

            /*
             * There is a lot of calculus omitted here.
             *
             * Conceptually, in the interests of understanding the
             * terms that the calculus produced we can consider
             * that EA and EC end up providing the lengths along
             * the major axes and the hypot term ends up being an
             * adjustment for the additional length along the off-axis
             * angle of rotated or sheared ellipses as well as an
             * adjustment for the fact that the equation below
             * averages the two major axis lengths.  (Notice that
             * the hypot term contains a part which resolves to the
             * difference of these two axis lengths in the absence
             * of rotation.)
             *
             * In the calculus, the ratio of the EB and (EA-EC) terms
             * ends up being the tangent of 2*theta where theta is
             * the angle that the long axis of the ellipse makes
             * with the horizontal axis.  Thus, this equation is
             * calculating the length of the hypotenuse of a triangle
             * along that axis.
             */
            double hypot = Math.sqrt(EB*EB + (EA-EC)*(EA-EC));

            /* sqrt omitted, compare to squared limits below. */
            widthsquared = ((EA + EC + hypot)/2.0);
        }
        if (bs != defaultStroke) {
            widthsquared *= bs.getLineWidth() * bs.getLineWidth();
        }
        if (widthsquared <=
            (aa ? MinPenSizeAASquared : MinPenSizeSquared))
        {
            if (bs.getDashArray() == null) {
                strokeState = STROKE_THIN;
            } else {
                strokeState = STROKE_THINDASHED;
            }
        } else {
            strokeState = STROKE_WIDE;
        }
    }
}
 
Example 12
/**
* Draw the bounding rectangle using transformed coordinates.
*/
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 13
private void validateBasicStroke(BasicStroke bs) {
    boolean aa = (antialiasHint == SunHints.INTVAL_ANTIALIAS_ON);
    if (transformState < TRANSFORM_TRANSLATESCALE) {
        if (aa) {
            if (bs.getLineWidth() <= MinPenSizeAA) {
                if (bs.getDashArray() == null) {
                    strokeState = STROKE_THIN;
                } else {
                    strokeState = STROKE_THINDASHED;
                }
            } else {
                strokeState = STROKE_WIDE;
            }
        } else {
            if (bs == defaultStroke) {
                strokeState = STROKE_THIN;
            } else if (bs.getLineWidth() <= 1.0f) {
                if (bs.getDashArray() == null) {
                    strokeState = STROKE_THIN;
                } else {
                    strokeState = STROKE_THINDASHED;
                }
            } else {
                strokeState = STROKE_WIDE;
            }
        }
    } else {
        double widthsquared;
        if ((transform.getType() & NON_UNIFORM_SCALE_MASK) == 0) {
            /* sqrt omitted, compare to squared limits below. */
            widthsquared = Math.abs(transform.getDeterminant());
        } else {
            /* First calculate the "maximum scale" of this transform. */
            double A = transform.getScaleX();       // m00
            double C = transform.getShearX();       // m01
            double B = transform.getShearY();       // m10
            double D = transform.getScaleY();       // m11

            /*
             * Given a 2 x 2 affine matrix [ A B ] such that
             *                             [ C D ]
             * v' = [x' y'] = [Ax + Cy, Bx + Dy], we want to
             * find the maximum magnitude (norm) of the vector v'
             * with the constraint (x^2 + y^2 = 1).
             * The equation to maximize is
             *     |v'| = sqrt((Ax+Cy)^2+(Bx+Dy)^2)
             * or  |v'| = sqrt((AA+BB)x^2 + 2(AC+BD)xy + (CC+DD)y^2).
             * Since sqrt is monotonic we can maximize |v'|^2
             * instead and plug in the substitution y = sqrt(1 - x^2).
             * Trigonometric equalities can then be used to get
             * rid of most of the sqrt terms.
             */
            double EA = A*A + B*B;          // x^2 coefficient
            double EB = 2*(A*C + B*D);      // xy coefficient
            double EC = C*C + D*D;          // y^2 coefficient

            /*
             * There is a lot of calculus omitted here.
             *
             * Conceptually, in the interests of understanding the
             * terms that the calculus produced we can consider
             * that EA and EC end up providing the lengths along
             * the major axes and the hypot term ends up being an
             * adjustment for the additional length along the off-axis
             * angle of rotated or sheared ellipses as well as an
             * adjustment for the fact that the equation below
             * averages the two major axis lengths.  (Notice that
             * the hypot term contains a part which resolves to the
             * difference of these two axis lengths in the absence
             * of rotation.)
             *
             * In the calculus, the ratio of the EB and (EA-EC) terms
             * ends up being the tangent of 2*theta where theta is
             * the angle that the long axis of the ellipse makes
             * with the horizontal axis.  Thus, this equation is
             * calculating the length of the hypotenuse of a triangle
             * along that axis.
             */
            double hypot = Math.sqrt(EB*EB + (EA-EC)*(EA-EC));

            /* sqrt omitted, compare to squared limits below. */
            widthsquared = ((EA + EC + hypot)/2.0);
        }
        if (bs != defaultStroke) {
            widthsquared *= bs.getLineWidth() * bs.getLineWidth();
        }
        if (widthsquared <=
            (aa ? MinPenSizeAASquared : MinPenSizeSquared))
        {
            if (bs.getDashArray() == null) {
                strokeState = STROKE_THIN;
            } else {
                strokeState = STROKE_THINDASHED;
            }
        } else {
            strokeState = STROKE_WIDE;
        }
    }
}
 
Example 14
public void draw( final Graphics2D g2, final Rectangle2D bounds ) {
  final boolean shouldDraw = layoutContext.getBooleanStyleProperty( ElementStyleKeys.DRAW_SHAPE );
  final boolean shouldFill = layoutContext.getBooleanStyleProperty( ElementStyleKeys.FILL_SHAPE );
  if ( shouldFill == false && shouldDraw == false ) {
    return;
  }
  final boolean scale = layoutContext.getBooleanStyleProperty( ElementStyleKeys.SCALE );
  final boolean keepAspectRatio = layoutContext.getBooleanStyleProperty( ElementStyleKeys.KEEP_ASPECT_RATIO );
  final double x = bounds.getX();
  final double y = bounds.getY();
  final double width = bounds.getWidth();
  final double height = bounds.getHeight();

  final Shape scaledShape = ShapeTransform.transformShape( shape, scale, keepAspectRatio, width, height );
  final Graphics2D clone = (Graphics2D) g2.create();
  final double extraPadding;
  if ( layoutContext != null ) {
    final Object o = layoutContext.getStyleProperty( ElementStyleKeys.STROKE );
    if ( o instanceof BasicStroke ) {
      final BasicStroke stroke = (BasicStroke) o;
      extraPadding = stroke.getLineWidth() / 2.0;
    } else {
      extraPadding = 0.5;
    }
  } else {
    extraPadding = 0.5;
  }

  final Rectangle2D.Double drawAreaBounds =
      new Rectangle2D.Double( x - extraPadding, y - extraPadding, width + 2 * extraPadding, height + 2 * extraPadding );

  clone.clip( drawAreaBounds );
  clone.translate( x, y );
  if ( shouldFill ) {
    configureFillColor( layoutContext, clone );
    clone.fill( scaledShape );
  }
  if ( shouldDraw ) {
    configureGraphics( layoutContext, clone );
    clone.draw( scaledShape );
  }
  clone.dispose();
}
 
Example 15
/**
* 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 Project: birt   File: SVGGraphics2D.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Adds stroke color and style information to the element passed in.
 * 
 * @param currentElement
 *            the element to add style information to.
 * @param isClipped
 *            boolean that determines whether to defer the clipping of the
 *            element
 */
protected void setStrokeStyle( Element currentElement, boolean deferClipped )

{
	Element element = currentElement;
	if ( deferStrokColor != null )
	{
		// Need to get the parent element.
		element = deferStrokColor;
	}

	String style = element.getAttribute( "style" ); //$NON-NLS-1$
	if ( style == null )
		style = ""; //$NON-NLS-1$
	if ( color != null )
	{
		style += "stroke:" + serializeToString( color ) + ";"; //$NON-NLS-1$ //$NON-NLS-2$
	}
	if ( ( stroke != null ) && ( stroke instanceof BasicStroke ) )
	{
		BasicStroke bs = (BasicStroke) stroke;
		if ( bs.getLineWidth( ) > 0 )
			style += "stroke-width:" + bs.getLineWidth( ) + ";"; //$NON-NLS-1$ //$NON-NLS-2$
		if ( bs.getDashArray( ) != null )
		{
			StringBuffer dashArrayStr = new StringBuffer( );
			for ( int x = 0; x < bs.getDashArray( ).length; x++ )
			{
				dashArrayStr.append( " " ).append( bs.getDashArray( )[x] ); //$NON-NLS-1$
			}
			if ( !( dashArrayStr.toString( ).equals( "" ) ) ) //$NON-NLS-1$
				style += "stroke-dasharray:" + dashArrayStr + ";"; //$NON-NLS-1$ //$NON-NLS-2$
		}
		style += "stroke-miterlimit:" + bs.getMiterLimit( ) + ";"; //$NON-NLS-1$ //$NON-NLS-2$
		switch ( bs.getLineJoin( ) )
		{
			case BasicStroke.JOIN_BEVEL :
				style += "stroke-linejoin:bevel;"; //$NON-NLS-1$
				break;
			case BasicStroke.JOIN_ROUND :
				style += "stroke-linejoin:round;"; //$NON-NLS-1$
				break;
		}
		switch ( bs.getEndCap( ) )
		{
			case BasicStroke.CAP_ROUND :
				style += "stroke-linecap:round;"; //$NON-NLS-1$
				break;
			case BasicStroke.CAP_SQUARE :
				style += "stroke-linecap:square;"; //$NON-NLS-1$
				break;
		}

	}
	element.setAttribute( "style", style ); //$NON-NLS-1$
	if ( styleClass != null )
		element.setAttribute( "class", styleClass ); //$NON-NLS-1$
	if ( id != null )
		element.setAttribute( "id", id ); //$NON-NLS-1$
	if ( ( clip != null ) && ( !deferClipped ) )
		element.setAttribute( "clip-path", "url(#clip" + clip.hashCode( ) + ")" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

}
 
Example 17
private void validateBasicStroke(BasicStroke bs) {
    boolean aa = (antialiasHint == SunHints.INTVAL_ANTIALIAS_ON);
    if (transformState < TRANSFORM_TRANSLATESCALE) {
        if (aa) {
            if (bs.getLineWidth() <= MinPenSizeAA) {
                if (bs.getDashArray() == null) {
                    strokeState = STROKE_THIN;
                } else {
                    strokeState = STROKE_THINDASHED;
                }
            } else {
                strokeState = STROKE_WIDE;
            }
        } else {
            if (bs == defaultStroke) {
                strokeState = STROKE_THIN;
            } else if (bs.getLineWidth() <= 1.0f) {
                if (bs.getDashArray() == null) {
                    strokeState = STROKE_THIN;
                } else {
                    strokeState = STROKE_THINDASHED;
                }
            } else {
                strokeState = STROKE_WIDE;
            }
        }
    } else {
        double widthsquared;
        if ((transform.getType() & NON_UNIFORM_SCALE_MASK) == 0) {
            /* sqrt omitted, compare to squared limits below. */
            widthsquared = Math.abs(transform.getDeterminant());
        } else {
            /* First calculate the "maximum scale" of this transform. */
            double A = transform.getScaleX();       // m00
            double C = transform.getShearX();       // m01
            double B = transform.getShearY();       // m10
            double D = transform.getScaleY();       // m11

            /*
             * Given a 2 x 2 affine matrix [ A B ] such that
             *                             [ C D ]
             * v' = [x' y'] = [Ax + Cy, Bx + Dy], we want to
             * find the maximum magnitude (norm) of the vector v'
             * with the constraint (x^2 + y^2 = 1).
             * The equation to maximize is
             *     |v'| = sqrt((Ax+Cy)^2+(Bx+Dy)^2)
             * or  |v'| = sqrt((AA+BB)x^2 + 2(AC+BD)xy + (CC+DD)y^2).
             * Since sqrt is monotonic we can maximize |v'|^2
             * instead and plug in the substitution y = sqrt(1 - x^2).
             * Trigonometric equalities can then be used to get
             * rid of most of the sqrt terms.
             */
            double EA = A*A + B*B;          // x^2 coefficient
            double EB = 2*(A*C + B*D);      // xy coefficient
            double EC = C*C + D*D;          // y^2 coefficient

            /*
             * There is a lot of calculus omitted here.
             *
             * Conceptually, in the interests of understanding the
             * terms that the calculus produced we can consider
             * that EA and EC end up providing the lengths along
             * the major axes and the hypot term ends up being an
             * adjustment for the additional length along the off-axis
             * angle of rotated or sheared ellipses as well as an
             * adjustment for the fact that the equation below
             * averages the two major axis lengths.  (Notice that
             * the hypot term contains a part which resolves to the
             * difference of these two axis lengths in the absence
             * of rotation.)
             *
             * In the calculus, the ratio of the EB and (EA-EC) terms
             * ends up being the tangent of 2*theta where theta is
             * the angle that the long axis of the ellipse makes
             * with the horizontal axis.  Thus, this equation is
             * calculating the length of the hypotenuse of a triangle
             * along that axis.
             */
            double hypot = Math.sqrt(EB*EB + (EA-EC)*(EA-EC));

            /* sqrt omitted, compare to squared limits below. */
            widthsquared = ((EA + EC + hypot)/2.0);
        }
        if (bs != defaultStroke) {
            widthsquared *= bs.getLineWidth() * bs.getLineWidth();
        }
        if (widthsquared <=
            (aa ? MinPenSizeAASquared : MinPenSizeSquared))
        {
            if (bs.getDashArray() == null) {
                strokeState = STROKE_THIN;
            } else {
                strokeState = STROKE_THINDASHED;
            }
        } else {
            strokeState = STROKE_WIDE;
        }
    }
}
 
Example 18
private void validateBasicStroke(BasicStroke bs) {
    boolean aa = (antialiasHint == SunHints.INTVAL_ANTIALIAS_ON);
    if (transformState < TRANSFORM_TRANSLATESCALE) {
        if (aa) {
            if (bs.getLineWidth() <= MinPenSizeAA) {
                if (bs.getDashArray() == null) {
                    strokeState = STROKE_THIN;
                } else {
                    strokeState = STROKE_THINDASHED;
                }
            } else {
                strokeState = STROKE_WIDE;
            }
        } else {
            if (bs == defaultStroke) {
                strokeState = STROKE_THIN;
            } else if (bs.getLineWidth() <= 1.0f) {
                if (bs.getDashArray() == null) {
                    strokeState = STROKE_THIN;
                } else {
                    strokeState = STROKE_THINDASHED;
                }
            } else {
                strokeState = STROKE_WIDE;
            }
        }
    } else {
        double widthsquared;
        if ((transform.getType() & NON_UNIFORM_SCALE_MASK) == 0) {
            /* sqrt omitted, compare to squared limits below. */
            widthsquared = Math.abs(transform.getDeterminant());
        } else {
            /* First calculate the "maximum scale" of this transform. */
            double A = transform.getScaleX();       // m00
            double C = transform.getShearX();       // m01
            double B = transform.getShearY();       // m10
            double D = transform.getScaleY();       // m11

            /*
             * Given a 2 x 2 affine matrix [ A B ] such that
             *                             [ C D ]
             * v' = [x' y'] = [Ax + Cy, Bx + Dy], we want to
             * find the maximum magnitude (norm) of the vector v'
             * with the constraint (x^2 + y^2 = 1).
             * The equation to maximize is
             *     |v'| = sqrt((Ax+Cy)^2+(Bx+Dy)^2)
             * or  |v'| = sqrt((AA+BB)x^2 + 2(AC+BD)xy + (CC+DD)y^2).
             * Since sqrt is monotonic we can maximize |v'|^2
             * instead and plug in the substitution y = sqrt(1 - x^2).
             * Trigonometric equalities can then be used to get
             * rid of most of the sqrt terms.
             */
            double EA = A*A + B*B;          // x^2 coefficient
            double EB = 2*(A*C + B*D);      // xy coefficient
            double EC = C*C + D*D;          // y^2 coefficient

            /*
             * There is a lot of calculus omitted here.
             *
             * Conceptually, in the interests of understanding the
             * terms that the calculus produced we can consider
             * that EA and EC end up providing the lengths along
             * the major axes and the hypot term ends up being an
             * adjustment for the additional length along the off-axis
             * angle of rotated or sheared ellipses as well as an
             * adjustment for the fact that the equation below
             * averages the two major axis lengths.  (Notice that
             * the hypot term contains a part which resolves to the
             * difference of these two axis lengths in the absence
             * of rotation.)
             *
             * In the calculus, the ratio of the EB and (EA-EC) terms
             * ends up being the tangent of 2*theta where theta is
             * the angle that the long axis of the ellipse makes
             * with the horizontal axis.  Thus, this equation is
             * calculating the length of the hypotenuse of a triangle
             * along that axis.
             */
            double hypot = Math.sqrt(EB*EB + (EA-EC)*(EA-EC));

            /* sqrt omitted, compare to squared limits below. */
            widthsquared = ((EA + EC + hypot)/2.0);
        }
        if (bs != defaultStroke) {
            widthsquared *= bs.getLineWidth() * bs.getLineWidth();
        }
        if (widthsquared <=
            (aa ? MinPenSizeAASquared : MinPenSizeSquared))
        {
            if (bs.getDashArray() == null) {
                strokeState = STROKE_THIN;
            } else {
                strokeState = STROKE_THINDASHED;
            }
        } else {
            strokeState = STROKE_WIDE;
        }
    }
}
 
Example 19
/**
 * 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 20
Source Project: Bytecoder   File: SunGraphics2D.java    License: Apache License 2.0 4 votes vote down vote up
private void validateBasicStroke(BasicStroke bs) {
    boolean aa = (antialiasHint == SunHints.INTVAL_ANTIALIAS_ON);
    if (transformState < TRANSFORM_TRANSLATESCALE) {
        if (aa) {
            if (bs.getLineWidth() <= MinPenSizeAA) {
                if (bs.getDashArray() == null) {
                    strokeState = STROKE_THIN;
                } else {
                    strokeState = STROKE_THINDASHED;
                }
            } else {
                strokeState = STROKE_WIDE;
            }
        } else {
            if (bs == defaultStroke) {
                strokeState = STROKE_THIN;
            } else if (bs.getLineWidth() <= 1.0f) {
                if (bs.getDashArray() == null) {
                    strokeState = STROKE_THIN;
                } else {
                    strokeState = STROKE_THINDASHED;
                }
            } else {
                strokeState = STROKE_WIDE;
            }
        }
    } else {
        double widthsquared;
        if ((transform.getType() & NON_UNIFORM_SCALE_MASK) == 0) {
            /* sqrt omitted, compare to squared limits below. */
            widthsquared = Math.abs(transform.getDeterminant());
        } else {
            /* First calculate the "maximum scale" of this transform. */
            double A = transform.getScaleX();       // m00
            double C = transform.getShearX();       // m01
            double B = transform.getShearY();       // m10
            double D = transform.getScaleY();       // m11

            /*
             * Given a 2 x 2 affine matrix [ A B ] such that
             *                             [ C D ]
             * v' = [x' y'] = [Ax + Cy, Bx + Dy], we want to
             * find the maximum magnitude (norm) of the vector v'
             * with the constraint (x^2 + y^2 = 1).
             * The equation to maximize is
             *     |v'| = sqrt((Ax+Cy)^2+(Bx+Dy)^2)
             * or  |v'| = sqrt((AA+BB)x^2 + 2(AC+BD)xy + (CC+DD)y^2).
             * Since sqrt is monotonic we can maximize |v'|^2
             * instead and plug in the substitution y = sqrt(1 - x^2).
             * Trigonometric equalities can then be used to get
             * rid of most of the sqrt terms.
             */
            double EA = A*A + B*B;          // x^2 coefficient
            double EB = 2*(A*C + B*D);      // xy coefficient
            double EC = C*C + D*D;          // y^2 coefficient

            /*
             * There is a lot of calculus omitted here.
             *
             * Conceptually, in the interests of understanding the
             * terms that the calculus produced we can consider
             * that EA and EC end up providing the lengths along
             * the major axes and the hypot term ends up being an
             * adjustment for the additional length along the off-axis
             * angle of rotated or sheared ellipses as well as an
             * adjustment for the fact that the equation below
             * averages the two major axis lengths.  (Notice that
             * the hypot term contains a part which resolves to the
             * difference of these two axis lengths in the absence
             * of rotation.)
             *
             * In the calculus, the ratio of the EB and (EA-EC) terms
             * ends up being the tangent of 2*theta where theta is
             * the angle that the long axis of the ellipse makes
             * with the horizontal axis.  Thus, this equation is
             * calculating the length of the hypotenuse of a triangle
             * along that axis.
             */
            double hypot = Math.sqrt(EB*EB + (EA-EC)*(EA-EC));

            /* sqrt omitted, compare to squared limits below. */
            widthsquared = ((EA + EC + hypot)/2.0);
        }
        if (bs != defaultStroke) {
            widthsquared *= bs.getLineWidth() * bs.getLineWidth();
        }
        if (widthsquared <=
            (aa ? MinPenSizeAASquared : MinPenSizeSquared))
        {
            if (bs.getDashArray() == null) {
                strokeState = STROKE_THIN;
            } else {
                strokeState = STROKE_THINDASHED;
            }
        } else {
            strokeState = STROKE_WIDE;
        }
    }
}