Author: aaime Date: 2012-05-11 03:18:53 -0700 (Fri, 11 May 2012) New Revision: 38712 Added: branches/2.7.x/modules/library/render/src/test/java/org/geotools/renderer/lite/MetaBufferEstimatorTest.java branches/2.7.x/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/externalGraphicNoSize.sld branches/2.7.x/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/lineThick.sld branches/2.7.x/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/polygon.sld Modified: branches/2.7.x/modules/library/render/src/main/java/org/geotools/renderer/lite/MetaBufferEstimator.java Log: [GEOT-4139] MetaBufferEstimator won't evaluate graphics size if the size is a NilExpression Modified: branches/2.7.x/modules/library/render/src/main/java/org/geotools/renderer/lite/MetaBufferEstimator.java =================================================================== --- branches/2.7.x/modules/library/render/src/main/java/org/geotools/renderer/lite/MetaBufferEstimator.java 2012-05-11 09:05:43 UTC (rev 38711) +++ branches/2.7.x/modules/library/render/src/main/java/org/geotools/renderer/lite/MetaBufferEstimator.java 2012-05-11 10:18:53 UTC (rev 38712) @@ -58,10 +58,12 @@ import org.geotools.styling.StyledLayerDescriptor; import org.geotools.styling.Symbolizer; import org.geotools.styling.TextSymbolizer; +import org.geotools.styling.TextSymbolizer2; import org.geotools.styling.UserLayer; import org.opengis.filter.Filter; import org.opengis.filter.expression.Expression; import org.opengis.filter.expression.Literal; +import org.opengis.filter.expression.NilExpression; import org.opengis.style.GraphicalSymbol; /** @@ -162,15 +164,22 @@ public void visit(Stroke stroke) { try { Expression width = stroke.getWidth(); - if (width != null) { + if (!isNull(width)) { evaluateWidth(width); } + if(stroke.getGraphicStroke() != null) { + stroke.getGraphicStroke().accept(this); + } } catch (ClassCastException e) { estimateAccurate = false; LOGGER.info("Could not parse stroke width, " + "it's a literal but not a Number..."); } } + + protected boolean isNull(Expression exp) { + return exp == null || exp instanceof NilExpression; + } /** * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Symbolizer) @@ -248,7 +257,13 @@ * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.TextSymbolizer) */ public void visit(TextSymbolizer text) { - // nothing to do here + // take into account label shields if any + if(text instanceof TextSymbolizer2) { + Graphic graphic = ((TextSymbolizer2) text).getGraphic(); + if(graphic != null) { + graphic.accept(this); + } + } } /** @@ -257,7 +272,7 @@ public void visit(Graphic gr) { try { Expression grSize = gr.getSize(); - if (grSize != null) { + if (!isNull(grSize)) { evaluateWidth(grSize); } else { for (GraphicalSymbol gs : gr.graphicalSymbols()) { Added: branches/2.7.x/modules/library/render/src/test/java/org/geotools/renderer/lite/MetaBufferEstimatorTest.java =================================================================== --- branches/2.7.x/modules/library/render/src/test/java/org/geotools/renderer/lite/MetaBufferEstimatorTest.java (rev 0) +++ branches/2.7.x/modules/library/render/src/test/java/org/geotools/renderer/lite/MetaBufferEstimatorTest.java 2012-05-11 10:18:53 UTC (rev 38712) @@ -0,0 +1,82 @@ +package org.geotools.renderer.lite; + +import static org.junit.Assert.*; + +import org.geotools.styling.Style; +import org.junit.Test; + +public class MetaBufferEstimatorTest { + + @Test + public void testExternalGraphic() throws Exception { + Style style = RendererBaseTest.loadStyle(this, "externalGraphic.sld"); + MetaBufferEstimator estimator = new MetaBufferEstimator(); + style.accept(estimator); + assertTrue(estimator.isEstimateAccurate()); + assertEquals(48, estimator.getBuffer()); + } + + @Test + public void testExternalGraphicNoSize() throws Exception { + Style style = RendererBaseTest.loadStyle(this, "externalGraphicNoSize.sld"); + MetaBufferEstimator estimator = new MetaBufferEstimator(); + style.accept(estimator); + assertTrue(estimator.isEstimateAccurate()); + assertEquals(64, estimator.getBuffer()); + } + + @Test + public void testMark() throws Exception { + Style style = RendererBaseTest.loadStyle(this, "markCircle.sld"); + MetaBufferEstimator estimator = new MetaBufferEstimator(); + style.accept(estimator); + assertTrue(estimator.isEstimateAccurate()); + assertEquals(32, estimator.getBuffer()); + } + + @Test + public void testThinLine() throws Exception { + Style style = RendererBaseTest.loadStyle(this, "lineGray.sld"); + MetaBufferEstimator estimator = new MetaBufferEstimator(); + style.accept(estimator); + assertTrue(estimator.isEstimateAccurate()); + assertEquals(1, estimator.getBuffer()); + } + + @Test + public void testThickLine() throws Exception { + Style style = RendererBaseTest.loadStyle(this, "lineThick.sld"); + MetaBufferEstimator estimator = new MetaBufferEstimator(); + style.accept(estimator); + assertTrue(estimator.isEstimateAccurate()); + assertEquals(4, estimator.getBuffer()); + } + + @Test + public void testGraphicStroke() throws Exception { + Style style = RendererBaseTest.loadStyle(this, "lineRailway.sld"); + MetaBufferEstimator estimator = new MetaBufferEstimator(); + style.accept(estimator); + assertTrue(estimator.isEstimateAccurate()); + assertEquals(8, estimator.getBuffer()); + } + + @Test + public void testPolygon() throws Exception { + Style style = RendererBaseTest.loadStyle(this, "polygon.sld"); + MetaBufferEstimator estimator = new MetaBufferEstimator(); + style.accept(estimator); + assertTrue(estimator.isEstimateAccurate()); + assertEquals(1, estimator.getBuffer()); + } + + @Test + public void testLabelShields() throws Exception { + Style style = RendererBaseTest.loadStyle(this, "textLabelShield.sld"); + MetaBufferEstimator estimator = new MetaBufferEstimator(); + style.accept(estimator); + assertTrue(estimator.isEstimateAccurate()); + assertEquals(32, estimator.getBuffer()); + } + +} Added: branches/2.7.x/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/externalGraphicNoSize.sld =================================================================== --- branches/2.7.x/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/externalGraphicNoSize.sld (rev 0) +++ branches/2.7.x/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/externalGraphicNoSize.sld 2012-05-11 10:18:53 UTC (rev 38712) @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" + xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"> + <NamedLayer> + + <Name>Icon</Name> + <UserStyle> + <FeatureTypeStyle> + <Rule> + <PointSymbolizer> + <Graphic> + <ExternalGraphic> + <OnlineResource xlink:type="simple" xlink:href="icon64.png" /> + <Format>image/png</Format> + </ExternalGraphic> + </Graphic> + </PointSymbolizer> + + </Rule> + </FeatureTypeStyle> + </UserStyle> + </NamedLayer> +</StyledLayerDescriptor> \ No newline at end of file Added: branches/2.7.x/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/lineThick.sld =================================================================== --- branches/2.7.x/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/lineThick.sld (rev 0) +++ branches/2.7.x/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/lineThick.sld 2012-05-11 10:18:53 UTC (rev 38712) @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" + xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"> + <NamedLayer> + + <Name>GrayLines</Name> + <UserStyle> + <FeatureTypeStyle> + <Rule> + <LineSymbolizer> + <Stroke> + <CssParameter name="stroke">0x440000</CssParameter> + <CssParameter name="stroke-width">4</CssParameter> + </Stroke> + </LineSymbolizer> + </Rule> + </FeatureTypeStyle> + </UserStyle> + </NamedLayer> +</StyledLayerDescriptor> \ No newline at end of file Added: branches/2.7.x/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/polygon.sld =================================================================== --- branches/2.7.x/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/polygon.sld (rev 0) +++ branches/2.7.x/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/polygon.sld 2012-05-11 10:18:53 UTC (rev 38712) @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<StyledLayerDescriptor version="1.0.0" + xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" + xmlns="http://www.opengis.net/sld" + xmlns:ogc="http://www.opengis.net/ogc" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <!-- a named layer is the basic building block of an sld document --> + + <NamedLayer> + <UserStyle> + <FeatureTypeStyle> + <Rule> + <PolygonSymbolizer> + <Fill> + <CssParameter name="fill">#AAAAAA</CssParameter> + </Fill> + <Stroke/> + </PolygonSymbolizer> + </Rule> + + </FeatureTypeStyle> + </UserStyle> + </NamedLayer> +</StyledLayerDescriptor> + |