/** * Returns the distance, that a Rectangle needs to grow (or shrink) to make hit detections on a * shape as specified by the FILL_UNDER_STROKE and STROKE_POSITION attributes of a figure. The * value returned is the number of units that need to be grown (or shrunk) perpendicular to a * stroke on an outline of the shape. */ public static double getPerpendicularHitGrowth(Figure f) { double grow; if (STROKE_COLOR.get(f) == null && STROKE_GRADIENT.get(f) == null) { grow = getPerpendicularFillGrowth(f); } else { double strokeWidth = AttributeKeys.getStrokeTotalWidth(f); grow = getPerpendicularDrawGrowth(f) + strokeWidth / 2d; } return grow; }
/** * Gets the stroke paint for the specified figure based on the attributes STROKE_GRADIENT, * STROKE_OPACITY, STROKE_PAINT and the bounds of the figure. Returns null if the figure is not * filled. */ public static Paint getStrokePaint(Figure f) { double opacity = STROKE_OPACITY.get(f); if (STROKE_GRADIENT.get(f) != null) { return STROKE_GRADIENT.get(f).getPaint(f, opacity); } Color color = STROKE_COLOR.get(f); if (color != null) { if (opacity != 1) { color = new Color((color.getRGB() & 0xffffff) | (int) (opacity * 255) << 24, true); } } return color; }
public void draw(Graphics2D g) { if (AttributeKeys.FILL_COLOR.get(this) != null) { g.setColor(AttributeKeys.FILL_COLOR.get(this)); drawFill(g); } if (STROKE_COLOR.get(this) != null && STROKE_WIDTH.get(this) > 0d) { g.setStroke(AttributeKeys.getStroke(this)); g.setColor(STROKE_COLOR.get(this)); drawStroke(g); } if (TEXT_COLOR.get(this) != null) { if (TEXT_SHADOW_COLOR.get(this) != null && TEXT_SHADOW_OFFSET.get(this) != null) { Dimension2DDouble d = TEXT_SHADOW_OFFSET.get(this); g.translate(d.width, d.height); g.setColor(TEXT_SHADOW_COLOR.get(this)); drawText(g); g.translate(-d.width, -d.height); } g.setColor(TEXT_COLOR.get(this)); drawText(g); } }
/** Sets SVG default values. */ public static void setDefaults(Figure f) { // Fill properties // http://www.w3.org/TR/SVGMobile12/painting.html#FillProperties FILL_COLOR.basicSet(f, Color.black); WINDING_RULE.basicSet(f, WindingRule.NON_ZERO); // Stroke properties // http://www.w3.org/TR/SVGMobile12/painting.html#StrokeProperties STROKE_COLOR.basicSet(f, null); STROKE_WIDTH.basicSet(f, 1d); STROKE_CAP.basicSet(f, BasicStroke.CAP_BUTT); STROKE_JOIN.basicSet(f, BasicStroke.JOIN_MITER); STROKE_MITER_LIMIT.basicSet(f, 4d); IS_STROKE_MITER_LIMIT_FACTOR.basicSet(f, false); STROKE_DASHES.basicSet(f, null); STROKE_DASH_PHASE.basicSet(f, 0d); IS_STROKE_DASH_FACTOR.basicSet(f, false); }
protected Point2D.Double chop(Figure target, Point2D.Double from) { target = getConnectorTarget(target); Rectangle2D.Double r = target.getBounds(); if (STROKE_COLOR.get(target) != null) { double grow; switch (STROKE_PLACEMENT.get(target)) { case CENTER: default: grow = AttributeKeys.getStrokeTotalWidth(target) / 2d; break; case OUTSIDE: grow = AttributeKeys.getStrokeTotalWidth(target); break; case INSIDE: grow = 0d; break; } Geom.grow(r, grow, grow); } return Geom.angleToPoint(r, Geom.pointToAngle(r, from)); }