public TextParser(Rule rule, Factory factory) { super(rule, factory.style.createTextSymbolizer(), factory); }
/** * Creates a default text symbolizer. Warning: there is no definition of a default text * symbolizer in the SLD standard, this is provided just for convenience and uniformity with the * other symbolizers * * @return the default text symbolizer */ public TextSymbolizer createTextSymbolizer() { TextSymbolizer ts = sf.createTextSymbolizer(); ts.setFill(createFill(Color.BLACK)); ts.setLabel(literalExpression("Label")); ts.fonts().add(createFont("Lucida Sans", 10)); return ts; }
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; }
LabelPlacement labelPlacement, String geometryPropertyName) { TextSymbolizer ts = sf.createTextSymbolizer();
@Before public void setUp() throws TransformException, FactoryException { graphics = Mockito.mock(Graphics2D.class); Mockito.when(graphics.getFontRenderContext()) .thenReturn( new FontRenderContext( new AffineTransform(), RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT, RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT)); style = new TextStyle2D(); style.setFont(new Font("Serif", Font.PLAIN, 10)); shape = new LiteShape2( geometryFactory.createPoint(new Coordinate(10, 10)), ProjectiveTransform.create(new AffineTransform()), null, false); symbolizer = styleFactory.createTextSymbolizer(); }
public void testTextSymbolizerVendorOptions() { TextSymbolizer textSymb = sf.createTextSymbolizer(); textSymb.getOptions().put("autoWrap", "100"); textSymb.accept(visitor); TextSymbolizer clone = (TextSymbolizer) visitor.getCopy(); assertCopy(textSymb, clone); assertEqualsContract(textSymb, clone); }
public void testTextSymbolizerVendorParams() { TextSymbolizer textSymb = sf.createTextSymbolizer(); textSymb.getOptions().put("autoWrap", "100"); textSymb.accept(visitor); TextSymbolizer clone = (TextSymbolizer) visitor.getCopy(); assertCopy(textSymb, clone); assertEqualsContract(textSymb, clone); assertEquals(1, clone.getOptions().size()); assertEquals("100", clone.getOptions().get("autoWrap")); }
TextSymbolizer symbol = StyleFactoryFinder.createStyleFactory().createTextSymbolizer(); symbol.setFill(null);
public void testTextSymbolizerWithGeometryFunction() { TextSymbolizer symb = sf.createTextSymbolizer(); // Set a function as geometry Function geomFunc = ff.function("centroid", ff.property("the_geom")); symb.setGeometry(geomFunc); TextSymbolizer copy = (TextSymbolizer) visitor.copy(symb); // compare it assertEquals( "Any Expression set as Geometry must be correctly replicated", geomFunc, copy.getGeometry()); }
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); }
sf.createTextSymbolizer( labelFill, new Font[] {font},
public void testKerningOffByDefault() throws Exception { TextSymbolizer ts = sf.createTextSymbolizer(); ts.setFill(sf.createFill(null)); Font font = sf.createFont( ff.literal("Serif"), ff.literal("italic"), ff.literal("bold"), ff.literal(20)); ts.setFont(font); ts.getOptions().put(TextSymbolizer.KERNING_KEY, "false"); TextStyle2D tsd = (TextStyle2D) sld.createTextStyle(feature, ts, range); assertEquals(20, tsd.getFont().getSize()); Map<TextAttribute, ?> attributes = tsd.getFont().getAttributes(); Object kerningValue = attributes.get(TextAttribute.KERNING); assertNull(kerningValue); }
public void testKerningOnByDefault() throws Exception { TextSymbolizer ts = sf.createTextSymbolizer(); ts.setFill(sf.createFill(null)); Font font = sf.createFont( ff.literal("Serif"), ff.literal("italic"), ff.literal("bold"), ff.literal(20)); ts.setFont(font); TextStyle2D tsd = (TextStyle2D) sld.createTextStyle(feature, ts, range); assertEquals(20, tsd.getFont().getSize()); Map<TextAttribute, ?> attributes = tsd.getFont().getAttributes(); Object kerningValue = attributes.get(TextAttribute.KERNING); assertEquals(TextAttribute.KERNING_ON, kerningValue); }
sf.createTextSymbolizer( labelFill, new Font[] {font},
@Test public void testTextSymbolizerPriority() throws Exception { StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(); FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(); TextSymbolizer symb = styleFactory.createTextSymbolizer(); symb.setPriority(filterFactory.property("foo")); StringWriter out = new StringWriter(); Ysld.encode(sld(symb), out); YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString())); YamlMap text = obj.seq("feature-styles") .map(0) .seq("rules") .map(0) .seq("symbolizers") .map(0) .map("text"); assertEquals("${foo}", text.str("priority")); }
public void testUnknownFont() throws Exception { TextSymbolizer ts = sf.createTextSymbolizer(); ts.setFill(sf.createFill(null)); Font font = sf.createFont( ff.literal("notExistingFont"), ff.literal("italic"), ff.literal("bold"), ff.literal(20)); ts.setFont(font); TextStyle2D tsd = (TextStyle2D) sld.createTextStyle(feature, ts, range); assertEquals(20, tsd.getFont().getSize()); assertEquals(java.awt.Font.ITALIC | java.awt.Font.BOLD, tsd.getFont().getStyle()); assertEquals("Serif", tsd.getFont().getName()); assertEquals(0.0, tsd.getAnchorX(), 0.0); assertEquals(0.5, tsd.getAnchorY(), 0.0); }
public void testTextSymbolizer() { TextSymbolizer textSymb = styleFactory.createTextSymbolizer(); Expression offset = filterFactory.literal(10); textSymb.setLabelPlacement(styleFactory.createLinePlacement(offset)); TextSymbolizer clone = (TextSymbolizer) ((Cloneable) textSymb).clone(); assertClone(textSymb, clone); TextSymbolizer notEq = styleFactory.getDefaultTextSymbolizer(); Expression ancX = filterFactory.literal(10); Expression ancY = filterFactory.literal(10); AnchorPoint ancPoint = styleFactory.createAnchorPoint(ancX, ancY); LabelPlacement placement = styleFactory.createPointPlacement(ancPoint, null, null); notEq.setLabelPlacement(placement); assertEqualsContract(clone, notEq, textSymb); }
public void testTextSymbolizer() { TextSymbolizer textSymb = sf.createTextSymbolizer(); 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); }
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); }
TextSymbolizer2 symb = (TextSymbolizer2) sf.createTextSymbolizer();