public TextSymbolizerBuilder reset(TextSymbolizer symbolizer) { fill.reset(symbolizer.getFill()); halo.reset(symbolizer.getHalo()); label = symbolizer.getLabel(); geometry = null; LabelPlacement otherPlacement = symbolizer.getLabelPlacement(); if (symbolizer.getLabelPlacement() instanceof PointPlacement) { PointPlacementBuilder builder = new PointPlacementBuilder(this); builder.reset((PointPlacement) otherPlacement); placement = builder; } else if (symbolizer.getLabelPlacement() instanceof LabelPlacement) { LinePlacementBuilder builder = new LinePlacementBuilder(this); builder.reset((LinePlacement) otherPlacement); placement = builder; } else { throw new IllegalArgumentException("Unrecognized label placement: " + otherPlacement); } priority = symbolizer.getPriority(); unset = false; return this; }
@Override public void visit(TextSymbolizer text) { super.visit(text); TextSymbolizer ts = (TextSymbolizer) pages.peek(); // do we have follow line without line placement? if (ts.getLabelPlacement() == null && "true".equalsIgnoreCase(ts.getOptions().get("followLine"))) { ts.setLabelPlacement(new LinePlacementImpl()); } } }
@Override public void visit(TextSymbolizer text) { if (text.getDescription() != null) { text.getDescription().accept(this); } if (text.getFill() != null) { text.getFill().accept(this); } if (text.getHalo() != null) { text.getHalo().accept(this); } if (text.getLabelPlacement() != null) { text.getLabelPlacement().accept(this); } }
@Test public void testTextPlacementType() throws Exception { String yaml = "text: \n" + " placement: line\n" + " offset: 4\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); TextSymbolizer t = SLD.textSymbolizer(SLD.defaultStyle(sld)); assertThat(t.getLabelPlacement(), instanceOf(LinePlacement.class)); Expression e = ((LinePlacement) t.getLabelPlacement()).getPerpendicularOffset(); assertThat(((LinePlacement) t.getLabelPlacement()).getPerpendicularOffset(), literal(4)); }
int textSize = getPositiveValue(font.getSize()); int delta = -1; if (text.getLabelPlacement() instanceof PointPlacement) { PointPlacement pp = (PointPlacement) text.getLabelPlacement(); Displacement pd = pp.getDisplacement(); if (pd != null) {
@Test public void testSuite54() throws IOException { try (InputStream input = YsldTests.ysld("poly", "suite-54.ysld")) { StyledLayerDescriptor sld = Ysld.parse(input); Style style = SLD.styles(sld)[0]; TextSymbolizer text = SLD.textSymbolizer(style); LabelPlacement placement = text.getLabelPlacement(); assertNotNull(placement); } }
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); }
@SuppressWarnings("unchecked") @Test public void testTextAnchor() throws Exception { String yaml = "text: \n" + " anchor: " + tuple(0.75, 0.25) + "\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); TextSymbolizer t = SLD.textSymbolizer(SLD.defaultStyle(sld)); assertThat( ((PointPlacement) t.getLabelPlacement()).getAnchorPoint(), allOf( hasProperty("anchorPointX", literal(0.75)), hasProperty("anchorPointY", literal(0.25)))); }
@SuppressWarnings("unchecked") @Test public void testTextDisplacement() throws Exception { String yaml = "text: \n" + " displacement: " + tuple(10, 42) + "\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); TextSymbolizer p = SLD.textSymbolizer(SLD.defaultStyle(sld)); assertThat( ((PointPlacement) p.getLabelPlacement()).getDisplacement(), allOf( hasProperty("displacementX", literal(10)), hasProperty("displacementY", literal(42)))); }
rescaledTextSymb.getFont().getSize().evaluate(null, Double.class); PointPlacement rescaledPlacement = (PointPlacement) rescaledTextSymb.getLabelPlacement(); double rescaledDisplacementXSize = rescaledPlacement
@Override protected void encode(TextSymbolizer text) { put("label", text.getLabel()); put("priority", text.getPriority()); inline(new FillEncoder(text.getFill())); inline(new HaloEncoder(text.getHalo())); inline(new FontEncoder(text.getFont())); inline(new PlacementEncoder(text.getLabelPlacement())); if (text instanceof TextSymbolizer2) { inline(new GraphicEncoder(((TextSymbolizer2) text).getGraphic(), false)); } super.encode(text); }
if (text.getLabelPlacement() != null) { text.getLabelPlacement().accept(this);
LinePlacement rescaledPlacement = (LinePlacement) rescaledTextSymb.getLabelPlacement(); double rescaledPerpOffset = rescaledPlacement.getPerpendicularOffset().evaluate(null, Double.class);
if (text.getLabelPlacement() != null) { text.getLabelPlacement().accept(this);
if (text.getLabelPlacement() != null) { text.getLabelPlacement().accept(this);
LabelPlacement placement = copy.getLabelPlacement(); if (placement instanceof PointPlacement) {
LabelPlacement placement = copy.getLabelPlacement(); if (placement instanceof PointPlacement) {
assertEquals(Color.black, SLD.color(text.getFill())); PointPlacement place = (PointPlacement) text.getLabelPlacement(); assertEquals(0.5, Filters.asDouble(place.getAnchorPoint().getAnchorPointX()), 0.1); assertEquals(0.5, Filters.asDouble(place.getAnchorPoint().getAnchorPointY()), 0.1);
assertEquals("normal", Filters.asString(font.getStyle())); PointPlacement placement = (PointPlacement) text.getLabelPlacement(); assertEquals(0.5, Filters.asDouble(placement.getAnchorPoint().getAnchorPointX()), 0.1); assertEquals(0.0, Filters.asDouble(placement.getAnchorPoint().getAnchorPointY()), 0.1);
assertEquals("normal", Filters.asString(font.getStyle())); PointPlacement placement = (PointPlacement) text.getLabelPlacement(); assertEquals(0.5, Filters.asDouble(placement.getAnchorPoint().getAnchorPointX()), 0.1); assertEquals(0.0, Filters.asDouble(placement.getAnchorPoint().getAnchorPointY()), 0.1);