/** * Retrieve the color of a fill object * * @param fill a Fill object * @return color or null if fill was null */ public static Color color(Fill fill) { if (fill == null) { return null; } return color(fill.getColor()); }
/** Reset to produce the default Fill. */ public FillBuilder reset() { unset = false; color = Fill.DEFAULT.getColor(); opacity = Fill.DEFAULT.getOpacity(); graphic.unset(); return this; }
/** * Retrieves the colour of the font fill from a TextSymbolizer. * * @param symbolizer Text symbolizer information. * @return Color of the font's fill, or null if unavailable. */ public static Color textFontFill(TextSymbolizer symbolizer) { if (symbolizer == null) { return null; } Fill fill = symbolizer.getFill(); if (fill == null) { return null; } return color(fill.getColor()); }
/** * Retrieves the fill colour from a PolygonSymbolizer. * * <p>If you are using something fun like rules you will need to do your own thing. * * @param symbolizer Polygon symbolizer information. * @return Color of the polygon's fill, or null if unavailable. */ public static Color polyFill(PolygonSymbolizer symbolizer) { if (symbolizer == null) { return null; } Fill fill = symbolizer.getFill(); if (fill == null) { return null; } return color(fill.getColor()); }
/** * Retrieves the colour of the halo fill a TextSymbolizer. * * @param symbolizer Text symbolizer information. * @return Color of the halo's fill, or null if unavailable. */ public static Color textHaloFill(TextSymbolizer symbolizer) { Halo halo = symbolizer.getHalo(); if (halo == null) { return null; } Fill fill = halo.getFill(); if (fill == null) { return null; } return color(fill.getColor()); }
protected Paint getPaint(Fill fill, Object feature, Symbolizer symbolizer) { if (fill == null) { return null; } // get fill color Paint fillPaint = evalToColor(fill.getColor(), feature, null); // if a graphic fill is to be used, prepare the paint accordingly.... org.geotools.styling.Graphic gr = fill.getGraphicFill(); if (gr != null && gr.graphicalSymbols() != null && gr.graphicalSymbols().size() > 0) { fillPaint = getTexturePaint(gr, feature, symbolizer); } return fillPaint; }
public void visit(Fill fill) { Fill copy = sf.getDefaultFill(); copy.setBackgroundColor(copy(fill.getBackgroundColor())); copy.setColor(copy(fill.getColor())); copy.setGraphicFill(copy(fill.getGraphicFill())); copy.setOpacity(copy(fill.getOpacity())); if (STRICT && !copy.equals(fill)) { throw new IllegalStateException("Was unable to duplicate provided Fill:" + fill); } pages.push(copy); }
/** Computes and returns the fill based on the feature and the symbolizer */ public java.awt.Paint getFill() { Fill fill = ps.getFill(); if (fill == null) { return null; } Paint fillPaint = (Color) fill.getColor().evaluate(feature, Color.class); // if a graphic fill is to be used, prepare the paint accordingly.... org.geotools.styling.Graphic gr = fill.getGraphicFill(); if (gr != null) { SLDStyleFactory fac = new SLDStyleFactory(); fillPaint = fac.getTexturePaint(gr, feature, ps); } return fillPaint; }
/** @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Fill) */ public void visit(Fill fill) { if (fill.getBackgroundColor() != null) { fill.getBackgroundColor().accept(this, null); } if (fill.getColor() != null) { fill.getColor().accept(this, null); } if (fill.getGraphicFill() != null) { fill.getGraphicFill().accept(this); } if (fill.getOpacity() != null) { fill.getOpacity().accept(this, null); } }
public Fill createFill( Expression color, Expression backgroundColor, Expression opacity, Graphic graphicFill) { Fill fill = new FillImpl(filterFactory); if (color == null) { color = Fill.DEFAULT.getColor(); } fill.setColor(color); if (backgroundColor == null) { backgroundColor = Fill.DEFAULT.getBackgroundColor(); } fill.setBackgroundColor(backgroundColor); if (opacity == null) { opacity = Fill.DEFAULT.getOpacity(); } // would be nice to check if this was within bounds but we have to wait until use since it // may depend on an attribute fill.setOpacity(opacity); fill.setGraphicFill(graphicFill); return fill; }
@Override protected void encode(Fill fill) { putColor("fill-color", fill.getColor()); put("fill-opacity", nullIf(fill.getOpacity(), 1d)); if (fill.getGraphicFill() != null) { push("fill-graphic").inline(new GraphicEncoder(fill.getGraphicFill())); } } }
public void visit(Fill fill) { start("Fill"); if (fill.getGraphicFill() != null) { start("GraphicFill"); fill.getGraphicFill().accept(this); end("GraphicFill"); } encodeCssParam("fill", fill.getColor(), "#808080"); encodeCssParam("fill-opacity", fill.getOpacity(), 1.0); end("Fill"); }
@Test public void testEvilExpression1() throws Exception { String yaml = "point: \n" + " symbols: \n" + " - mark: \n" + " fill-color: \\$\\}\\\\\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertThat(SLD.fill(p).getColor(), literal(equalTo("$}\\"))); }
@Test public void testExpressionLong() throws Exception { String yaml = "polygon:\n" + " fill-color: ${recode(MAPCOLOR7, 1.0, '#FFC3C3', 2.0, '#FFE3C3', 3.0, '#FFFFC3', 4.0, '#C3FFE3', 5.0, '#C3FFFF', 6.0, '#C3C3FF', 7.0, '#BFC3FF')}\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); FeatureTypeStyle fs = SLD.defaultStyle(sld).featureTypeStyles().get(0); PolygonSymbolizer symb = (PolygonSymbolizer) fs.rules().get(0).symbolizers().get(0); Expression expr = symb.getFill().getColor(); assertThat(expr, instanceOf(RecodeFunction.class)); List<Expression> params = ((RecodeFunction) expr).getParameters(); assertThat(params.size(), is(7 * 2 + 1)); int i = 0; assertThat(params.get(i++), attribute("MAPCOLOR7")); assertThat(params.get(i++), literal(equalTo(1.0))); assertThat(params.get(i++), literal(isColor("FFC3C3"))); assertThat(params.get(i++), literal(equalTo(2.0))); assertThat(params.get(i++), literal(isColor("FFE3C3"))); assertThat(params.get(i++), literal(equalTo(3.0))); assertThat(params.get(i++), literal(isColor("FFFFC3"))); assertThat(params.get(i++), literal(equalTo(4.0))); assertThat(params.get(i++), literal(isColor("C3FFE3"))); assertThat(params.get(i++), literal(equalTo(5.0))); assertThat(params.get(i++), literal(isColor("C3FFFF"))); assertThat(params.get(i++), literal(equalTo(6.0))); assertThat(params.get(i++), literal(isColor("C3C3FF"))); assertThat(params.get(i++), literal(equalTo(7.0))); assertThat(params.get(i++), literal(isColor("BFC3FF"))); }
@Test public void testDynamicColor() throws Exception { String yaml = "point: \n" + " symbols: \n" + " - mark: \n" + " fill-color: ${colourAttribute}\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertThat(SLD.fill(p).getColor(), attribute("colourAttribute")); }
@Test public void testColorSexegesimal() throws Exception { String yaml = "point: \n" + " symbols: \n" + " - mark: \n" + " fill-color: 1:17:40:20:15\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertThat(SLD.fill(p).getColor(), literal(isColor("FFFFFF"))); }
@Test public void testColorHex() throws Exception { String yaml = "point: \n" + " symbols: \n" + " - mark: \n" + " fill-color: 0x001122\n" + " stroke-color: 0x334455\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertThat(SLD.fill(p).getColor(), literal(isColor("001122"))); assertThat(SLD.stroke(p).getColor(), literal(isColor("334455"))); }
@Test public void testColorQuotedHex() throws Exception { String yaml = "point: \n" + " symbols: \n" + " - mark: \n" + " fill-color: '0x001122'\n" + " stroke-color: '0x334455'\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertThat(SLD.fill(p).getColor(), literal(isColor("001122"))); assertThat(SLD.stroke(p).getColor(), literal(isColor("334455"))); }
@Test public void testColorQuotedHash() throws Exception { String yaml = "point: \n" + " symbols: \n" + " - mark: \n" + " fill-color: '#001122'\n" + " stroke-color: '#334455'\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertThat(SLD.fill(p).getColor(), literal(isColor("001122"))); assertThat(SLD.stroke(p).getColor(), literal(isColor("334455"))); }
@Test public void testColorQuotedBare() throws Exception { String yaml = "point: \n" + " symbols: \n" + " - mark: \n" + " fill-color: '001122'\n" + " stroke-color: '334455'\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertThat(SLD.fill(p).getColor(), literal(isColor("001122"))); assertThat(SLD.stroke(p).getColor(), literal(isColor("334455"))); }