if (uomNode != null) { UomOgcMapping uomMapping = UomOgcMapping.get(uomNode.getNodeValue()); symbol.setUnitOfMeasure(uomMapping.getUnit());
public TextSymbolizer build() { if (unset) { return null; } Font[] array = null; if (!fonts.isEmpty()) { array = new Font[fonts.size()]; for (int i = 0; i < array.length; i++) { array[i] = fonts.get(i).build(); } } TextSymbolizer ts = sf.createTextSymbolizer( fill.build(), array, halo.build(), label, placement.build(), null); ts.setGeometry(geometry); if (uom != null) { ts.setUnitOfMeasure(uom); } ts.getOptions().putAll(options); ts.setPriority(priority); if (ts instanceof TextSymbolizer2) { TextSymbolizer2 ts2 = (TextSymbolizer2) ts; if (!shield.isUnset()) { ts2.setGraphic(shield.build()); } } reset(); return ts; }
public void visit(TextSymbolizer text) { TextSymbolizer copy = sf.createTextSymbolizer(); copy.setFill(copy(text.getFill())); copy.fonts().clear(); copy.fonts().addAll(copyFonts(text.fonts())); copy.setGeometry(copy(text.getGeometry())); copy.setUnitOfMeasure(text.getUnitOfMeasure()); copy.setHalo(copy(text.getHalo())); copy.setLabel(copy(text.getLabel())); copy.setLabelPlacement(copy(text.getLabelPlacement())); copy.setPriority(copy(text.getPriority())); copy.getOptions().putAll(text.getOptions()); if (text instanceof TextSymbolizer2) { TextSymbolizer2 text2 = (TextSymbolizer2) text; TextSymbolizer2 copy2 = (TextSymbolizer2) copy; copy2.setGraphic(copy(text2.getGraphic())); copy2.setSnippet(copy(text2.getSnippet())); copy2.setFeatureDescription(copy(text2.getFeatureDescription())); copy2.setOtherText(copy(text2.getOtherText())); } if (STRICT && !copy.equals(text)) { throw new IllegalStateException( "Was unable to duplicate provided TextSymbolizer:" + text); } pages.push(copy); }
@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 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 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)); }
public void testTextSymbolizerWithUOM() { TextSymbolizer textSymb = sf.createTextSymbolizer(); textSymb.setUnitOfMeasure(UomOgcMapping.METRE.getUnit()); Expression offset = ff.literal(10); textSymb.setLabelPlacement(sf.createLinePlacement(offset)); textSymb.accept(visitor); TextSymbolizer clone = (TextSymbolizer) visitor.getCopy(); assertCopy(textSymb, clone); assertEqualsContract(textSymb, clone); TextSymbolizer notEq = sf.getDefaultTextSymbolizer(); Expression ancX = ff.literal(10); Expression ancY = ff.literal(10); AnchorPoint ancPoint = sf.createAnchorPoint(ancX, ancY); LabelPlacement placement = sf.createPointPlacement(ancPoint, null, null); notEq.setLabelPlacement(placement); assertEqualsContract(clone, notEq, textSymb); }
scaleIntArrayOption(options, TextSymbolizer.GRAPHIC_MARGIN_KEY, uom); copy.setUnitOfMeasure(Units.PIXEL);
symbol.setUnitOfMeasure(uomMapping.getUnit());
copy.setUnitOfMeasure(text.getUnitOfMeasure()); copy.setHalo(copy(text.getHalo())); copy.setLabel(copy(text.getLabel()));
public void visit(TextSymbolizer text) { TextSymbolizer copy = sf.createTextSymbolizer(); copy.setFill( copy( text.getFill())); copy.setFont( copy( text.getFont())); copy.setGeometry(copy(text.getGeometry())); copy.setUnitOfMeasure(text.getUnitOfMeasure()); copy.setHalo( copy( text.getHalo() )); copy.setLabel( copy( text.getLabel())); copy.setLabelPlacement( copy( text.getLabelPlacement())); copy.setPriority( copy( text.getPriority())); copy.getOptions().putAll(text.getOptions()); if (text instanceof TextSymbolizer2){ TextSymbolizer2 text2 = (TextSymbolizer2) text; TextSymbolizer2 copy2 = (TextSymbolizer2) copy; copy2.setGraphic( copy(text2.getGraphic())); copy2.setSnippet(copy(text2.getSnippet())); copy2.setFeatureDescription(copy(text2.getFeatureDescription())); copy2.setOtherText(copy(text2.getOtherText())); } if( STRICT && !copy.equals( text )){ throw new IllegalStateException("Was unable to duplicate provided TextSymbolizer:"+text ); } pages.push(copy); }
scaleIntArrayOption(options, TextSymbolizer.GRAPHIC_MARGIN_KEY, uom); copy.setUnitOfMeasure(NonSI.PIXEL);