public void visit(Stroke stroke) { Stroke copy = sf.getDefaultStroke(); copy.setColor(copy(stroke.getColor())); copy.setDashArray(copyExpressions(stroke.dashArray())); copy.setDashOffset(copy(stroke.getDashOffset())); copy.setGraphicFill(copy(stroke.getGraphicFill())); copy.setGraphicStroke(copy(stroke.getGraphicStroke())); copy.setLineCap(copy(stroke.getLineCap())); copy.setLineJoin(copy(stroke.getLineJoin())); copy.setOpacity(copy(stroke.getOpacity())); copy.setWidth(copy(stroke.getWidth())); if (STRICT && !copy.equals(stroke)) { throw new IllegalStateException("Was unable to duplicate provided Stroke:" + stroke); } pages.push(copy); }
/** Reset stroke to default values. */ public StrokeBuilder reset() { color = Stroke.DEFAULT.getColor(); width = Stroke.DEFAULT.getWidth(); opacity = Stroke.DEFAULT.getOpacity(); lineCap = Stroke.DEFAULT.getLineCap(); lineJoin = Stroke.DEFAULT.getLineJoin(); dashArray = Stroke.DEFAULT.getDashArray(); dashArrayExpressions = Stroke.DEFAULT.dashArray(); dashOffset = Stroke.DEFAULT.getDashOffset(); graphicFill.unset(); graphicStroke.unset(); unset = false; return this; }
@Override public void visit(Stroke stroke) { if (stroke.getGraphicFill() != null) { stroke.getGraphicFill().accept(this); } if (stroke.getGraphicStroke() != null) { stroke.getGraphicStroke().accept(this); } }
if (stroke.getColor() != null) { stroke.getColor().accept(this, null); if (stroke.getDashOffset() != null) { stroke.getDashOffset().accept(this, null); if (stroke.getGraphicFill() != null) { stroke.getGraphicFill().accept(this); if (stroke.getGraphicStroke() != null) { stroke.getGraphicStroke().accept(this); if (stroke.getLineCap() != null) { stroke.getLineCap().accept(this, null); if (stroke.getLineJoin() != null) { stroke.getLineJoin().accept(this, null); if (stroke.getOpacity() != null) { stroke.getOpacity().accept(this, null); if (stroke.getWidth() != null) { stroke.getWidth().accept(this, null); if (stroke.dashArray() != null) { for (Expression expression : stroke.dashArray()) { expression.accept(this, null);
color = Stroke.DEFAULT.getColor(); stroke.setColor(color); width = Stroke.DEFAULT.getWidth(); stroke.setWidth(width); opacity = Stroke.DEFAULT.getOpacity(); stroke.setOpacity(opacity); lineJoin = Stroke.DEFAULT.getLineJoin(); stroke.setLineJoin(lineJoin); lineCap = Stroke.DEFAULT.getLineCap(); stroke.setLineCap(lineCap); stroke.setDashArray(dashArray); stroke.setDashOffset(dashOffset); stroke.setGraphicFill(graphicFill); stroke.setGraphicStroke(graphicStroke);
/** * Used to rescaleDashArray the provided stroke. * * @param stroke the unscaled stroke, which will be modified in-place. * @param mapScale the mapScale in pixels per meter. * @param uom the unit of measure that will be used to scale. */ protected void rescaleStroke(Stroke stroke, Unit<Length> uom) { if (stroke != null) { stroke.setWidth(rescale(stroke.getWidth(), uom)); stroke.setDashArray(rescaleDashArray(stroke.dashArray(), uom)); stroke.setDashOffset(rescale(stroke.getDashOffset(), uom)); rescale(stroke.getGraphicFill(), uom); rescale(stroke.getGraphicStroke(), uom); } }
@Test public void testFill() { PolygonSymbolizer polygonSymbolizer = sb.createPolygonSymbolizer(Color.BLACK, Color.BLACK, 3); polygonSymbolizer.getFill().setOpacity(ff.literal(0.5)); polygonSymbolizer.getStroke().setOpacity(ff.literal(0.5)); Style style = sb.createStyle(polygonSymbolizer); style.accept(visitor); Style copy = (Style) visitor.getCopy(); PolygonSymbolizer ls = (PolygonSymbolizer) copy.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0); Stroke stroke = ls.getStroke(); assertEquals(colorFunction, stroke.getColor()); assertEquals(Integer.valueOf(3), stroke.getWidth().evaluate(null, Integer.class)); assertNull(stroke.dashArray()); assertEquals(Integer.valueOf(1), stroke.getOpacity().evaluate(null, Integer.class)); Fill fill = ls.getFill(); assertEquals(colorFunction, fill.getColor()); assertEquals(Integer.valueOf(1), fill.getOpacity().evaluate(null, Integer.class)); }
@Override public void visit(Stroke stroke) { super.visit(stroke); Stroke copy = (Stroke) pages.peek(); if (copy.getGraphicFill() != null) { copy.setGraphicFill(null); } if (copy.getGraphicStroke() != null) { copy.setWidth(getSymbolsSize(copy.getGraphicStroke())); copy.setGraphicStroke(null); } copy.setColor(colorFunction); copy.setOpacity(LITERAL_ONE); if (copy.dashArray() != null) { copy.dashArray().clear(); } copy.setDashOffset(null); }
if (LOGGER.isLoggable(Level.FINEST)) LOGGER.finest("setting stroke graphicfill with " + g); stroke.setGraphicFill(g); if (LOGGER.isLoggable(Level.FINEST)) LOGGER.finest("setting stroke graphicStroke with " + g); stroke.setGraphicStroke(g); stroke.setColor(color); } else if (res.equalsIgnoreCase("width") || res.equalsIgnoreCase("stroke-width")) { Expression width = parseCssParameter(child, false); stroke.setWidth(width); } else if (res.equalsIgnoreCase(opacityString) || res.equalsIgnoreCase("stroke-opacity")) { Expression opacity = parseCssParameter(child, false); stroke.setOpacity(opacity); } else if (res.equalsIgnoreCase("linecap") || res.equalsIgnoreCase("stroke-linecap")) { stroke.setLineCap(parseCssParameter(child)); } else if (res.equalsIgnoreCase("linejoin") || res.equalsIgnoreCase("stroke-linejoin")) { stroke.setLineJoin(parseCssParameter(child)); } else if (res.equalsIgnoreCase("dasharray") || res.equalsIgnoreCase("stroke-dasharray")) { stroke.setDashArray(parseDashArray(child)); } else if (res.equalsIgnoreCase("dashoffset") || res.equalsIgnoreCase("stroke-dashoffset")) {
/** * Used to rescale the provided stroke. * * @param stroke * the unscaled stroke, which will be modified in-place. * @param mapScale * the mapScale in pixels per meter. * @param uom * the unit of measure that will be used to scale. */ protected void rescaleStroke(Stroke stroke, double mapScale, Unit<Length> uom) { if (stroke != null) { stroke.setWidth(rescale(stroke.getWidth(), mapScale, uom)); stroke.setDashArray(rescale(stroke.getDashArray(), mapScale, uom)); stroke.setDashOffset(rescale(stroke.getDashOffset(), mapScale, uom)); rescale(stroke.getGraphicFill(), mapScale, uom); rescale(stroke.getGraphicStroke(), mapScale, uom); } }
stroke().setColor(Util.color(map.get("stroke-color"), factory)); stroke().setWidth(Util.expression(map.str("stroke-width"), factory)); stroke().setOpacity(Util.expression(map.str("stroke-opacity"), factory)); stroke().setLineJoin(Util.expression(map.str("stroke-linejoin"), factory)); stroke().setLineCap(Util.expression(map.str("stroke-linecap"), factory)); stroke().setDashArray(Util.floatArray(map.str("stroke-dasharray"))); stroke().setDashOffset(Util.expression(map.str("stroke-dashoffset"), factory));
/** @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Stroke) */ public void visit(Stroke stroke) { handleColor(stroke.getColor()); if (stroke.getGraphicFill() != null) { stroke.getGraphicFill().accept(this); } if (stroke.getGraphicStroke() != null) { stroke.getGraphicStroke().accept(this); } handleOpacity(stroke.getOpacity()); }
stroke.setColor(null); stroke.setGraphicStroke( sb.createGraphic(null, sb.createMark("square", null, sb.createStroke(1)), null)); ps.accept(visitor); PolygonSymbolizer rps = (PolygonSymbolizer) visitor.getCopy(); Mark rm = (Mark) rps.getStroke().getGraphicStroke().graphicalSymbols().get(0); assertEquals(10.0, rm.getStroke().getWidth().evaluate(null, Double.class), 0d); rm = (Mark) rps.getFill().getGraphicFill().graphicalSymbols().get(0); assertEquals(20.0, rm.getStroke().getWidth().evaluate(null, Double.class), 0d); rm = (Mark) lps.getStroke().getGraphicStroke().graphicalSymbols().get(0); assertEquals(10.0, rm.getStroke().getWidth().evaluate(null, Double.class), 0d);
int joinCode; joinType = evalToString(stroke.getLineJoin(), feature, "miter"); int capCode; capType = evalToString(stroke.getLineCap(), feature, "square"); float width = evalToFloat(stroke.getWidth(), feature, 1); float dashOffset = evalToFloat(stroke.getDashOffset(), feature, 0);
public Stroke getDefaultStroke() { try { Stroke stroke = createStroke( filterFactory.literal("#000000"), filterFactory.literal(Integer.valueOf(1))); stroke.setDashOffset(filterFactory.literal(Integer.valueOf(0))); stroke.setDashArray(Stroke.DEFAULT.getDashArray()); stroke.setLineCap(filterFactory.literal("butt")); stroke.setLineJoin(filterFactory.literal("miter")); stroke.setOpacity(filterFactory.literal(Integer.valueOf(1))); return stroke; } catch (org.geotools.filter.IllegalFilterException ife) { // we should never be in here throw new RuntimeException("Error creating stroke", ife); } }
private LineSymbolizer linesym(StyleFactory sFac) throws IllegalFilterException { LineSymbolizer linesym = sFac.createLineSymbolizer(); Stroke myStroke = sFac.getDefaultStroke(); myStroke.setColor(filterFactory.literal("#0000ff")); myStroke.setWidth(filterFactory.literal(Integer.valueOf(5))); LOGGER.fine("got new Stroke " + myStroke); linesym.setStroke(myStroke); return linesym; }
private Paint getStrokePaint(org.geotools.styling.Stroke stroke, Object feature) { if (stroke == null) { return null; } // the foreground color Paint contourPaint = evalToColor(stroke.getColor(), feature, Color.BLACK); // if a graphic fill is to be used, prepare the paint accordingly.... org.geotools.styling.Graphic gr = stroke.getGraphicFill(); if (gr != null && gr.graphicalSymbols() != null && gr.graphicalSymbols().size() > 0) { contourPaint = getTexturePaint(gr, feature, null); } return contourPaint; }
@Test public void testSymbolizerPixelOverrideInMeters() throws Exception { Stroke original = sb.createStroke(Color.RED, 2, new float[] {5, 10}); original.setWidth(ff.literal("2m")); LineSymbolizer ls = sb.createLineSymbolizer(original); ls.accept(visitor); Stroke clone = ((LineSymbolizer) visitor.getCopy()).getStroke(); // this one has not been rescaled assertEquals("2m", clone.getWidth().evaluate(null, String.class)); // the dash array did , it's supposed to be pixels assertEquals(10f, clone.getDashArray()[0], 0f); assertEquals(20f, clone.getDashArray()[1], 0f); TextSymbolizer ts = sb.createTextSymbolizer(); ts.getOptions().put(TextSymbolizer.SPACE_AROUND_KEY, "10m"); ts.accept(visitor); TextSymbolizer clonedTs = (TextSymbolizer) visitor.getCopy(); // this one has not been rescaled assertEquals("10.0m", clonedTs.getOptions().get(TextSymbolizer.SPACE_AROUND_KEY)); } }
/** * This specifies the level of translucency to use when rendering the stroke.<br> * The value is encoded as a floating-point value between 0.0 and 1.0 with 0.0 representing * totally transparent and 1.0 representing totally opaque. A linear scale of translucency is * used for intermediate values.<br> * For example, "0.65" would represent 65% opacity. The default value is 1.0 (opaque). * * @return The opacity of the stroke, where 0.0 is completely transparent and 1.0 is completely * opaque. */ public Expression getOpacity() { if (lineCap == null) { return Stroke.DEFAULT.getOpacity(); } return opacity; }
@Test public void testDynamicStroke() throws Exception { Stroke original = sb.createStroke(Color.RED, 2); original.setDashArray(Arrays.asList((Expression) ff.literal("5 10"))); original.accept(visitor); Stroke clone = (Stroke) visitor.getCopy(); assertEquals(4.0d, Double.valueOf((String) clone.getWidth().evaluate(null)), 0.001); assertNotNull(original.dashArray()); assertEquals(1, original.dashArray().size()); assertEquals("10.0 20.0", ((Expression) clone.dashArray().get(0)).evaluate(null)); }