Search in sources :

Example 31 with TextSymbolizer

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());
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyleWrapper(com.sldeditor.common.data.StyleWrapper) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) Rule(org.geotools.styling.Rule) BatchUpdateFontData(com.sldeditor.tool.batchupdatefont.BatchUpdateFontData) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Example 32 with TextSymbolizer

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));
    });
}
Also used : Color(java.awt.Color) Style(org.geotools.styling.Style) TextStyle(org.polymap.core.style.model.feature.TextStyle) Literal(org.opengis.filter.expression.Literal) Context(org.polymap.core.style.serialize.FeatureStyleSerializer.Context) TextSymbolizer(org.geotools.styling.TextSymbolizer) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) TextSymbolizer(org.geotools.styling.TextSymbolizer) Color(java.awt.Color) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle)

Example 33 with TextSymbolizer

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());
}
Also used : TextStyle(org.polymap.core.style.model.feature.TextStyle) TextSymbolizer(org.geotools.styling.TextSymbolizer) Style(org.geotools.styling.Style) ConstantStrokeDashStyle(org.polymap.core.style.model.feature.ConstantStrokeDashStyle) ConstantStrokeJoinStyle(org.polymap.core.style.model.feature.ConstantStrokeJoinStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle) TextStyle(org.polymap.core.style.model.feature.TextStyle) ConstantStrokeCapStyle(org.polymap.core.style.model.feature.ConstantStrokeCapStyle) StrokeDashStyle(org.polymap.core.style.model.feature.StrokeDashStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) PointStyle(org.polymap.core.style.model.feature.PointStyle) LineStyle(org.polymap.core.style.model.feature.LineStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) FeatureStyle(org.polymap.core.style.model.FeatureStyle) Test(org.junit.Test)

Aggregations

TextSymbolizer (org.geotools.styling.TextSymbolizer)33 Test (org.junit.Test)19 Font (org.geotools.styling.Font)9 PointSymbolizer (org.geotools.styling.PointSymbolizer)9 Rule (org.geotools.styling.Rule)9 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)8 LineSymbolizer (org.geotools.styling.LineSymbolizer)8 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)8 Style (org.geotools.styling.Style)8 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)6 NamedLayer (org.geotools.styling.NamedLayer)5 SLDTreeLeafText (com.sldeditor.common.tree.leaf.SLDTreeLeafText)4 SLDData (com.sldeditor.common.data.SLDData)3 StyleWrapper (com.sldeditor.common.data.StyleWrapper)3 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)3 VendorOptionPresent (com.sldeditor.common.vendoroption.minversion.VendorOptionPresent)3 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)3 BatchUpdateFontData (com.sldeditor.tool.batchupdatefont.BatchUpdateFontData)3 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)3 Symbolizer (org.geotools.styling.Symbolizer)3