@Test public void testTextSymbolizerArraySingleValue() throws Exception { TextSymbolizer ts = sb.createTextSymbolizer(Color.BLACK, (Font) null, "label"); ts.getOptions().put(TextSymbolizer.GRAPHIC_MARGIN_KEY, "10"); ts.accept(visitor); TextSymbolizer clone = (TextSymbolizer) visitor.getCopy(); assertEquals("20", clone.getOptions().get(TextSymbolizer.GRAPHIC_MARGIN_KEY)); }
/** * Increase stroke width. * * <p>Based on feedback we may need to change the dash array as well. * * <p> */ public void visit(org.geotools.styling.Stroke stroke) { Stroke copy = sf.getDefaultStroke(); copy.setColor(copy(stroke.getColor())); copy.setDashArray(rescaleDashArray(stroke.dashArray())); copy.setDashOffset(rescale(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(rescale(stroke.getWidth())); pages.push(copy); }
font.setSize(rescale(font.getSize())); Displacement disp = pointPlacement.getDisplacement(); if (disp != null) { disp.setDisplacementX(rescale(disp.getDisplacementX())); disp.setDisplacementY(rescale(disp.getDisplacementY())); pointPlacement.setDisplacement(disp); linePlacement.setGap(rescale(linePlacement.getGap())); linePlacement.setInitialGap(rescale(linePlacement.getInitialGap())); linePlacement.setPerpendicularOffset( rescale(linePlacement.getPerpendicularOffset())); copy.getHalo().setRadius(rescale(copy.getHalo().getRadius())); rescaleOption(options, SPACE_AROUND_KEY, DEFAULT_SPACE_AROUND); rescaleOption(options, MAX_DISPLACEMENT_KEY, DEFAULT_MAX_DISPLACEMENT); rescaleOption(options, MIN_GROUP_DISTANCE_KEY, DEFAULT_MIN_GROUP_DISTANCE); rescaleOption(options, LABEL_REPEAT_KEY, DEFAULT_LABEL_REPEAT); rescaleOption(options, AUTO_WRAP_KEY, DEFAULT_AUTO_WRAP); rescaleArrayOption(options, GRAPHIC_MARGIN_KEY, 0); } finally { this.defaultUnit = null;
externalGraphicsCopy[i] = copy(externalGraphics[i]); length = marks.length; for (int i = 0; i < length; i++) { marksCopy[i] = copy(marks[i]); Expression opacityCopy = copy(gr.getOpacity()); Expression rotationCopy = copy(gr.getRotation()); Expression sizeCopy = rescaleGraphicSize(gr); symbolCopys[i] = copy(symbols[i]);
if(dpi != standardDpi) { double scaleFactor = dpi / standardDpi; RescaleStyleVisitor dpiVisitor = new RescaleStyleVisitor(scaleFactor); for (int j = 0; j < ruleList.size(); j++) { dpiVisitor.visit(ruleList.get(j)); ruleList.set(j, (Rule) dpiVisitor.getCopy()); dpiVisitor.visit(elseRuleList.get(j)); elseRuleList.set(j, (Rule) dpiVisitor.getCopy());
@Override public void visit(PointSymbolizer sym) { setRescaling(sym); try { super.visit(sym); } finally { setRescaling(true); } }
/** * Increase stroke width. * <p> * Based on feedback we may need to change the dash array as well. * <p> */ public void visit(org.geotools.styling.Stroke stroke) { Stroke copy = sf.getDefaultStroke(); copy.setColor( copy(stroke.getColor())); copy.setDashArray( rescale(stroke.getDashArray())); copy.setDashOffset( rescale(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( rescale(stroke.getWidth())); pages.push(copy); }
/** Rescale a list of expressions, can handle null. */ protected List<Expression> rescale(List<Expression> expressions) { if (expressions == null || expressions.isEmpty()) { return expressions; } List<Expression> rescaled = new ArrayList<>(expressions.size()); for (Expression expression : expressions) { rescaled.add(rescale(expression)); } return rescaled; }
@Before public void setUp() throws Exception { sf = CommonFactoryFinder.getStyleFactory(null); ff = CommonFactoryFinder.getFilterFactory2(null); sb = new StyleBuilder(sf, ff); scale = 2.0; visitor = new RescaleStyleVisitor(scale); }
@Override public void visit(PolygonSymbolizer sym) { this.defaultUnit = sym.getUnitOfMeasure(); try { super.visit(sym); PolygonSymbolizer copy = (PolygonSymbolizer) pages.peek(); rescaleArrayOption(copy.getOptions(), PolygonSymbolizer.GRAPHIC_MARGIN_KEY, 0); } finally { this.defaultUnit = null; } }
@Override public void visit(RasterSymbolizer sym) { setRescaling(sym); try { super.visit(sym); } finally { setRescaling(true); } } }
externalGraphicsCopy[i] = copy( externalGraphics[i]); length=marks.length; for (int i = 0; i < length; i++) { marksCopy[i] = copy( marks[i]); Expression opacityCopy = copy( gr.getOpacity() ); Expression rotationCopy = copy( gr.getRotation() ); Expression sizeCopy = rescale( gr.getSize() ); symbolCopys[i] = copy( symbols[i] );
protected Expression rescaleGraphicSize(Graphic gr) { return rescale(gr.getSize()); }
@Test public void testTextSymbolizer() throws Exception { TextSymbolizer ts = sb.createTextSymbolizer(Color.BLACK, (Font) null, "label"); ts.getOptions().put(TextSymbolizer.MAX_DISPLACEMENT_KEY, "10"); ts.getOptions().put(TextSymbolizer.GRAPHIC_MARGIN_KEY, "10 20"); ts.accept(visitor); TextSymbolizer clone = (TextSymbolizer) visitor.getCopy(); assertEquals("20", clone.getOptions().get(TextSymbolizer.MAX_DISPLACEMENT_KEY)); assertEquals("20 40", clone.getOptions().get(TextSymbolizer.GRAPHIC_MARGIN_KEY)); }
@Override public void visit(LineSymbolizer sym) { setRescaling(sym); try { super.visit(sym); } finally { setRescaling(true); } }
font.setSize(rescale(font.getSize())); Displacement disp = pointPlacement.getDisplacement(); if (disp != null) { disp.setDisplacementX(rescale(disp.getDisplacementX())); disp.setDisplacementY(rescale(disp.getDisplacementY())); pointPlacement.setDisplacement(disp); linePlacement.setGap(rescale(linePlacement.getGap())); linePlacement.setInitialGap(rescale(linePlacement.getInitialGap())); linePlacement.setPerpendicularOffset(rescale(linePlacement.getPerpendicularOffset())); copy.getHalo().setRadius(rescale(copy.getHalo().getRadius())); rescaleOption(options, SPACE_AROUND_KEY, DEFAULT_SPACE_AROUND); rescaleOption(options, MAX_DISPLACEMENT_KEY, DEFAULT_MAX_DISPLACEMENT); rescaleOption(options, MIN_GROUP_DISTANCE_KEY, DEFAULT_MIN_GROUP_DISTANCE); rescaleOption(options, LABEL_REPEAT_KEY, DEFAULT_LABEL_REPEAT); rescaleOption(options, AUTO_WRAP_KEY, DEFAULT_AUTO_WRAP); rescaleArrayOption(options, GRAPHIC_MARGIN_KEY, 0);
/** * Rescale using listMultiply, if there is only one entry. * * @param expressions * @return */ protected List<Expression> rescaleDashArray(List<Expression> expressions) { if (expressions == null || expressions.isEmpty()) { return expressions; } Expression rescaleToExpression = rescale(ff.literal(1)); // How to test, if it is a measure with a unit or not? String data = ((Literal) rescaleToExpression).getValue().toString(); boolean evaluate = rescaleToExpression instanceof Literal && Character.isDigit(data.charAt(data.length() - 1)); List<Expression> rescaled = new ArrayList<>(expressions.size()); for (Expression expression : expressions) { Expression rescale = ff.function("listMultiply", rescaleToExpression, expression); if (expression instanceof Literal && evaluate) { rescaled.add(ff.literal(rescale.evaluate(null))); } else { rescaled.add(rescale); } } return rescaled; }
@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)); }
@Override public void visit(PolygonSymbolizer sym) { setRescaling(sym); try { super.visit(sym); } finally { setRescaling(true); } }
@Override public void visit(LineSymbolizer sym) { this.defaultUnit = sym.getUnitOfMeasure(); try { super.visit(sym); LineSymbolizer copy = (LineSymbolizer) pages.peek(); copy.setPerpendicularOffset(rescale(copy.getPerpendicularOffset())); } finally { this.defaultUnit = null; } }