/** * Retrieves the dashes array from a LineSymbolizer. * * @param symbolizer Line symbolizer information. * @return float[] of the line dashes array, or null if unavailable. */ public static float[] lineDash(LineSymbolizer symbolizer) { if (symbolizer == null) { return null; } Stroke stroke = symbolizer.getStroke(); if (stroke == null) { return null; } float[] linedash = stroke.getDashArray(); return linedash; }
/** * Shortcut to retrieve dash array in the case where all expressions are literal numbers. Return * the default value if one of the expressions is not a literal. */ public float[] getDashArray() { if (dashArray == null) { return Stroke.DEFAULT.getDashArray(); } float[] values = new float[dashArray.size()]; int index = 0; for (Expression expression : dashArray) { if (expression instanceof Literal) { Literal literal = (Literal) expression; values[index] = literal.evaluate(null, Float.class); } else { throw new RuntimeException("Dash array is not literal: '" + expression + "'."); } index++; } return values; }
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); } }
@Test public void testStroke() throws Exception { Stroke original = sb.createStroke(Color.RED, 2, new float[] {5, 10}); original.accept(visitor); Stroke clone = (Stroke) visitor.getCopy(); assertEquals(4.0d, clone.getWidth().evaluate(null, Double.class), 0d); assertEquals(10.0f, clone.getDashArray()[0], 0d); assertEquals(20.0f, clone.getDashArray()[1], 0d); }
/** 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; }
@Test public void testNoUnit() throws Exception { Stroke original = sb.createStroke(Color.RED, 2, new float[] {5, 10}); LineSymbolizer ls = sb.createLineSymbolizer(original); ls.accept(visitor); Stroke clone = ((LineSymbolizer) visitor.getCopy()).getStroke(); assertEquals(4.0d, clone.getWidth().evaluate(null, Double.class), 0d); assertEquals(10.0f, clone.getDashArray()[0], 0f); assertEquals(20.0f, clone.getDashArray()[1], 0f); TextSymbolizer ts = sb.createTextSymbolizer(); ts.getOptions().put(TextSymbolizer.SPACE_AROUND_KEY, "10"); ts.accept(visitor); TextSymbolizer clonedTs = (TextSymbolizer) visitor.getCopy(); assertEquals("20.0", clonedTs.getOptions().get(TextSymbolizer.SPACE_AROUND_KEY)); }
@Test public void testAllMeters() throws Exception { Stroke original = sb.createStroke(Color.RED, 2, new float[] {5, 10}); LineSymbolizer ls = sb.createLineSymbolizer(original); ls.setUnitOfMeasure(SI.METRE); ls.accept(visitor); Stroke clone = ((LineSymbolizer) visitor.getCopy()).getStroke(); assertEquals(2d, clone.getWidth().evaluate(null, Double.class), 0d); assertEquals(5f, clone.getDashArray()[0], 0f); assertEquals(10f, clone.getDashArray()[1], 0f); TextSymbolizer ts = sb.createTextSymbolizer(); ts.getOptions().put(TextSymbolizer.SPACE_AROUND_KEY, "10"); ts.setUnitOfMeasure(SI.METRE); ts.accept(visitor); TextSymbolizer clonedTs = (TextSymbolizer) visitor.getCopy(); assertEquals("10.0", clonedTs.getOptions().get(TextSymbolizer.SPACE_AROUND_KEY)); }
@Test public void testAllFeet() throws Exception { Stroke original = sb.createStroke(Color.RED, 2, new float[] {5, 10}); LineSymbolizer ls = sb.createLineSymbolizer(original); ls.setUnitOfMeasure(USCustomary.FOOT); ls.accept(visitor); Stroke clone = ((LineSymbolizer) visitor.getCopy()).getStroke(); assertEquals(2d, clone.getWidth().evaluate(null, Double.class), 0d); assertEquals(5f, clone.getDashArray()[0], 0f); assertEquals(10f, clone.getDashArray()[1], 0f); TextSymbolizer ts = sb.createTextSymbolizer(); ts.getOptions().put(TextSymbolizer.SPACE_AROUND_KEY, "10"); ts.setUnitOfMeasure(USCustomary.FOOT); ts.accept(visitor); TextSymbolizer clonedTs = (TextSymbolizer) visitor.getCopy(); assertEquals("10.0", clonedTs.getOptions().get(TextSymbolizer.SPACE_AROUND_KEY)); }
@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)); } }
@Test public void testSymbolizerMeterOverrideInPixels() throws Exception { Stroke original = sb.createStroke(Color.RED, 2, new float[] {5, 10}); original.setWidth(ff.literal("2px")); LineSymbolizer ls = sb.createLineSymbolizer(original); ls.setUnitOfMeasure(SI.METRE); ls.accept(visitor); Stroke clone = ((LineSymbolizer) visitor.getCopy()).getStroke(); // this one has been rescaled assertEquals(4d, clone.getWidth().evaluate(null, Double.class), 0d); // the dash array did not, it's supposed to be meters assertEquals(5f, clone.getDashArray()[0], 0f); assertEquals(10f, clone.getDashArray()[1], 0f); TextSymbolizer ts = sb.createTextSymbolizer(); ts.getOptions().put(TextSymbolizer.SPACE_AROUND_KEY, "10px"); ts.setUnitOfMeasure(SI.METRE); ts.accept(visitor); TextSymbolizer clonedTs = (TextSymbolizer) visitor.getCopy(); // this one has been rescaled assertEquals("20.0", clonedTs.getOptions().get(TextSymbolizer.SPACE_AROUND_KEY)); }
Stroke update(Stroke stroke) { Expression color = ff.literal(colour); Expression width = copy(stroke.getWidth()); Expression opacity = copy(stroke.getOpacity()); Expression lineJoin = copy(stroke.getLineJoin()); Expression lineCap = copy(stroke.getLineCap()); float[] dashArray = copy(stroke.getDashArray()); Expression dashOffset = copy(stroke.getDashOffset()); Graphic graphicStroke = copy(stroke.getGraphicStroke()); Graphic graphicFill = copy(stroke.getGraphicFill()); return sf.createStroke( color, width, opacity, lineJoin, lineCap, dashArray, dashOffset, graphicFill, graphicStroke); } };
/** * Retrieves the dashes array from a LineSymbolizer. * * @param symbolizer Line symbolizer information. * * @return float[] of the line dashes array, or null if unavailable. */ public static float[] lineDash(LineSymbolizer symbolizer) { if (symbolizer == null) { return null; } Stroke stroke = symbolizer.getStroke(); if (stroke == null) { return null; } float[] linedash = stroke.getDashArray(); return linedash; }
/** * Grabs the dashes array from the first LineSymbolizer. * * @param symbolizer Line symbolizer information. * * @return float[] of the line dashes array, or null if unavailable. */ public static float[] lineDash(LineSymbolizer symbolizer) { if (symbolizer == null) { return null; } Stroke stroke = symbolizer.getStroke(); if (stroke == null) { return null; } float[] linedash = stroke.getDashArray(); return linedash; }
@Override protected void encode(Stroke stroke) { putColor("stroke-color", stroke.getColor()); put("stroke-width", stroke.getWidth()); put("stroke-opacity", nullIf(stroke.getOpacity(), 1d)); put("stroke-linejoin", nullIf(stroke.getLineJoin(), "miter")); putName("stroke-linecap", nullIf(stroke.getLineCap(), "butt")); put("stroke-dasharray", toStringOrNull(stroke.getDashArray())); put("stroke-dashoffset", nullIf(stroke.getDashOffset(), 0)); if (stroke.getGraphicFill() != null) { push("stroke-graphic-fill").inline(new GraphicEncoder(stroke.getGraphicFill())); } if (stroke.getGraphicStroke() != null) { push("stroke-graphic").inline(new GraphicEncoder(stroke.getGraphicStroke())); } }
public Stroke getDefaultStroke() { try { Stroke stroke = createStroke(filterFactory.literal("#000000"), filterFactory.literal(new Integer(1))); stroke.setDashOffset(filterFactory.literal( new Integer(0))); stroke.setDashArray(Stroke.DEFAULT.getDashArray()); stroke.setLineCap(filterFactory.literal("butt")); stroke.setLineJoin(filterFactory.literal("miter")); stroke.setOpacity(filterFactory.literal(new Integer(1))); return stroke; } catch (org.geotools.filter.IllegalFilterException ife) { //we should never be in here throw new RuntimeException("Error creating stroke", ife); } }
public void visit(Stroke stroke) { Stroke copy = sf.getDefaultStroke(); copy.setColor( copy(stroke.getColor())); copy.setDashArray( copy(stroke.getDashArray())); 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); }
public void setEdited(Stroke stroke) { this.stroke = stroke; if (stroke != null) { // implemented using two buttons // stroke.getGraphicFill(); // stroke.getGraphicStroke(); GuiStrokeLineCap.setLineCap(stroke.getLineCap()); GuiStrokeLineJoin.setLineJoin(stroke.getLineJoin()); GuiStrokeDashes.setDashes(stroke.getDashArray()); GuiStrokeDashes.setOffset(stroke.getDashOffset()); GuiStrokeWidth.setExpression(stroke.getWidth()); GuiStrokeColor.setExpression(stroke.getColor()); GuiStrokeAlpha.setExpression(stroke.getOpacity()); } }
/** * 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 update(Stroke stroke) { Expression color = ff.literal(colour); Expression width = copy(stroke.getWidth()); Expression opacity = copy(stroke.getOpacity()); Expression lineJoin = copy(stroke.getLineJoin()); Expression lineCap = copy(stroke.getLineCap()); float[] dashArray = copy(stroke.getDashArray()); Expression dashOffset = copy(stroke.getDashOffset()); Graphic graphicStroke = copy(stroke.getGraphicStroke()); Graphic graphicFill = copy(stroke.getGraphicFill()); return sf.createStroke(color, width, opacity, lineJoin, lineCap, dashArray, dashOffset, graphicFill, graphicStroke); } };
@Override protected void encode(Stroke stroke) { putColor("stroke-color", stroke.getColor()); put("stroke-width", stroke.getWidth()); put("stroke-opacity", nullIf(stroke.getOpacity(), 1d)); put("stroke-linejoin", nullIf(stroke.getLineJoin(), "miter")); putName("stroke-linecap", nullIf(stroke.getLineCap(), "butt")); put("stroke-dasharray", toStringOrNull(stroke.getDashArray())); put("stroke-dashoffset", nullIf(stroke.getDashOffset(), 0)); if (stroke.getGraphicFill() != null) { push("stroke-graphic-fill").inline(new GraphicEncoder(stroke.getGraphicFill())); } if (stroke.getGraphicStroke() != null) { push("stroke-graphic").inline(new GraphicEncoder(stroke.getGraphicStroke())); } }