use of org.geotools.styling.TextSymbolizer in project sldeditor by robward-scisys.
the class BatchUpdateFontUtilsTest method testContainsFonts.
/**
* Test method for {@link com.sldeditor.tool.batchupdatefont.BatchUpdateFontUtils#containsFonts(com.sldeditor.common.SLDDataInterface)}.
*/
@Test
public void testContainsFonts() {
StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
SelectedSymbol.getInstance().createNewSLD(sld);
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
String expectedNameLayerValue = "named layer test value";
namedLayer.setName(expectedNameLayerValue);
Style style = DefaultSymbols.createNewStyle();
String expectedNameStyleValue = "style test value";
style.setName(expectedNameStyleValue);
namedLayer.addStyle(style);
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
String expectedNameFTSValue = "feature type style test value";
fts.setName(expectedNameFTSValue);
style.featureTypeStyles().add(fts);
Rule rule = DefaultSymbols.createNewRule();
String expectedRuleValue = "rule test value";
rule.setName(expectedRuleValue);
TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
String expectedNameValue = "symbolizer test value";
symbolizer.setName(expectedNameValue);
rule.symbolizers().add(DefaultSymbols.createDefaultPointSymbolizer());
fts.rules().add(rule);
sld.layers().add(namedLayer);
SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
String sldContents = sldWriter.encodeSLD(null, sld);
SLDData sldData = new SLDData(new StyleWrapper("workspace", "layer.sld"), sldContents);
// Empty sld
List<BatchUpdateFontData> actualList = BatchUpdateFontUtils.containsFonts(null);
assertNull(actualList);
// No fonts
actualList = BatchUpdateFontUtils.containsFonts(sldData);
assertNull(actualList);
// With textsymbolizer
rule.symbolizers().add(symbolizer);
sldContents = sldWriter.encodeSLD(null, sld);
sldData = new SLDData(new StyleWrapper("workspace", "layer.sld"), sldContents);
actualList = BatchUpdateFontUtils.containsFonts(sldData);
assertEquals(1, actualList.size());
assertEquals(rule.getName(), actualList.get(0).getRuleName());
}
use of org.geotools.styling.TextSymbolizer in project polymap4-core by Polymap4.
the class TextStyleSerializer method serialize.
@Override
public void serialize(TextStyle style, Style result) {
// default symbolizer
TextSymbolizer text = sf.createTextSymbolizer();
text.setFill(sf.getDefaultFill());
style.halo.opt().ifPresent(halo -> text.setHalo(sf.createHalo(sf.getDefaultFill(), ff.literal(1))));
style.font.opt().ifPresent(font -> text.setFont(sf.getDefaultFont()));
FeatureTypeStyle fts = defaultFeatureTypeStyle(result, style, text);
fts.setName(style.title.opt().orElse("TextStyle"));
fts.getDescription().setTitle(style.title.opt().orElse("TextStyle"));
accessor.set(rule -> (TextSymbolizer) rule.symbolizers().get(0));
serialize(style, fts);
// font
style.font.opt().ifPresent(font -> {
new FontCompositeSerializer(context).accessor.put(rule -> accessor.get().apply(rule).getFont()).serialize(font, fts);
});
// halo
style.halo.opt().ifPresent(halo -> {
// XXX for what reason ever for halo color an awt.Color does not seem to work
set(fts, halo.color, (value, sym) -> sym.getHalo().getFill().setColor(ff.literal(SLDSerializer2.toHexString((Color) ((Literal) value).getValue()))));
set(fts, halo.opacity, (value, sym) -> sym.getHalo().getFill().setOpacity(value));
set(fts, halo.width, (value, sym) -> sym.getHalo().setRadius(value));
});
}
use of org.geotools.styling.TextSymbolizer in project polymap4-core by Polymap4.
the class StyleModelTest method testSimpleText.
@Test
public void testSimpleText() throws Exception {
FeatureStyle fs = repo.newFeatureStyle();
TextStyle style = fs.members().createElement(TextStyle.defaults);
style.color.createValue(ConstantColor.defaults(0, 0, 0));
style.opacity.createValue(ConstantNumber.defaults(0.0));
style.font.createValue(Font.defaults);
fs.store();
log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
Style result = repo.serializedFeatureStyle(fs.id(), Style.class).get();
assertEquals(1, result.featureTypeStyles().size());
FeatureTypeStyle fts = result.featureTypeStyles().get(0);
assertEquals(1, fts.rules().size());
Rule rule = fts.rules().get(0);
assertEquals(0, rule.getMinScaleDenominator(), 0);
assertEquals(Double.POSITIVE_INFINITY, rule.getMaxScaleDenominator(), 0);
assertEquals(1, rule.symbolizers().size());
assertNull(rule.getFilter());
TextSymbolizer text = (TextSymbolizer) rule.symbolizers().get(0);
// assertEqualsLiteral( 0.5, text.getStroke().getOpacity() );
// assertEqualsLiteral( 5.0, text.getStroke().getWidth() );
assertEqualsLiteral(0.0, text.getFill().getOpacity());
}
Aggregations