use of org.geotools.styling.Fill in project sldeditor by robward-scisys.
the class SLDTreeLeafPointTest method testGetFill.
/**
* Test method for
* {@link com.sldeditor.common.tree.leaf.SLDTreeLeafPoint#getFill(org.opengis.style.Symbolizer)}.
*/
@Test
public void testGetFill() {
SLDTreeLeafPoint leaf = new SLDTreeLeafPoint();
assertNull(leaf.getFill(null));
assertNull(leaf.getFill(DefaultSymbols.createDefaultPolygonSymbolizer()));
PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
Fill expectedFill = null;
Graphic graphic = pointSymbolizer.getGraphic();
if (graphic != null) {
List<GraphicalSymbol> symbolList = graphic.graphicalSymbols();
if ((symbolList != null) && !symbolList.isEmpty()) {
GraphicalSymbol obj = symbolList.get(0);
if (obj != null) {
if (obj instanceof MarkImpl) {
MarkImpl mark = (MarkImpl) obj;
expectedFill = mark.getFill();
}
}
}
}
assertEquals(expectedFill, leaf.getFill(pointSymbolizer));
}
use of org.geotools.styling.Fill in project sldeditor by robward-scisys.
the class LineFillSymbol method convertToFill.
/**
* Convert to fill.
*
* @param layerName the layer name
* @param element the element
* @param transparency the transparency
* @return the list
*/
/* (non-Javadoc)
* @see com.sldeditor.convert.esri.symbols.EsriFillSymbolInterface#convertToFill(java.lang.String, com.google.gson.JsonElement, int)
*/
@Override
public List<Symbolizer> convertToFill(String layerName, JsonElement element, int transparency) {
if (layerName == null) {
return null;
}
if (element == null) {
return null;
}
List<Symbolizer> symbolizerList = new ArrayList<Symbolizer>();
JsonObject obj = element.getAsJsonObject();
Expression size = ff.literal(getDouble(obj, LineFillSymbolKeys.SEPARATION));
Expression opacity = null;
double lineAngle = normaliseAngle(getDouble(obj, CommonSymbolKeys.ANGLE));
Expression rotation = null;
AnchorPoint anchorPoint = null;
Displacement displacement = null;
Expression fillColour = getColour(obj.get(LineFillSymbolKeys.FILL_COLOUR));
Expression fillColourOpacity = null;
Expression join = null;
Expression cap = null;
float[] dashes = null;
Expression offset = null;
Expression width = ff.literal(1.0);
Stroke outlineStroke = null;
List<Stroke> strokeList = SymbolManager.getInstance().getStrokeList(obj.get(LineFillSymbolKeys.OUTLINE));
// TODO
if ((strokeList != null) && (strokeList.size() == 1)) {
outlineStroke = strokeList.get(0);
width = outlineStroke.getWidth();
}
Expression wellKnownName = null;
if (isDoubleEqual(lineAngle, 0.0) || isDoubleEqual(lineAngle, 180.0)) {
wellKnownName = ff.literal("shape://horline");
} else if (isDoubleEqual(lineAngle, 90.0) || isDoubleEqual(lineAngle, 270.0)) {
wellKnownName = ff.literal("shape://vertline");
} else if (isDoubleEqual(lineAngle, 45.0) || isDoubleEqual(lineAngle, 225.0)) {
wellKnownName = ff.literal("shape://slash");
} else if (isDoubleEqual(lineAngle, 135.0) || isDoubleEqual(lineAngle, 315.0)) {
wellKnownName = ff.literal("shape://backslash");
} else {
wellKnownName = ff.literal("shape://vertline");
rotation = ff.literal(lineAngle);
}
Fill fill = null;
Stroke markStroke = styleFactory.stroke(fillColour, fillColourOpacity, width, join, cap, dashes, offset);
Mark mark = styleFactory.createMark(wellKnownName, markStroke, fill, size, rotation);
List<GraphicalSymbol> symbolList = new ArrayList<GraphicalSymbol>();
symbolList.add(mark);
GraphicFill graphicFill = styleFactory.graphicFill(symbolList, opacity, size, rotation, anchorPoint, displacement);
Fill completeFill = styleFactory.fill(graphicFill, null, null);
PolygonSymbolizer polygonSymbolizer = styleFactory.createPolygonSymbolizer();
polygonSymbolizer.setFill(completeFill);
polygonSymbolizer.setStroke(outlineStroke);
symbolizerList.add(polygonSymbolizer);
return symbolizerList;
}
use of org.geotools.styling.Fill in project sldeditor by robward-scisys.
the class PictureFillSymbol method getFill.
/**
* Gets the fill.
*
* @param layerName the layer name
* @param obj the obj
* @param transparency the transparency
* @return the fill
*/
@SuppressWarnings("unused")
private Fill getFill(String layerName, JsonObject obj, int transparency) {
double angle = getInt(obj, CommonSymbolKeys.ANGLE);
double xOffset = getInt(obj, CommonSymbolKeys.X_OFFSET);
double yOffset = getInt(obj, CommonSymbolKeys.Y_OFFSET);
double xScale = getInt(obj, PictureFillSymbolKeys.X_SCALE);
double yScale = getInt(obj, PictureFillSymbolKeys.Y_SCALE);
Graphic graphic = null;
JsonElement pictureElement = obj.get(PictureFillSymbolKeys.PICTURE);
if (pictureElement != null) {
JsonObject pictureObj = pictureElement.getAsJsonObject();
JsonElement imageElement = pictureObj.get(CommonPictureKeys.IMAGE);
if (imageElement != null) {
String imageString = imageElement.getAsString();
byte[] decodedBytes = DatatypeConverter.parseBase64Binary(imageString);
int height = getInt(pictureObj, CommonPictureKeys.HEIGHT);
int width = getInt(pictureObj, CommonPictureKeys.WIDTH);
String imageType = getString(pictureObj, CommonPictureKeys.TYPE);
ByteArrayInputStream bis = new ByteArrayInputStream(decodedBytes);
BufferedImage image = null;
try {
image = ImageIO.read(bis);
bis.close();
} catch (IOException e1) {
e1.printStackTrace();
}
if (image != null) {
String filename = String.format("%s.%s", layerName, imageType);
File file = new File(filename);
BufferedOutputStream buffOutStream = null;
try {
buffOutStream = new BufferedOutputStream(new FileOutputStream(file));
Expression foregroundColour = getColour(obj.get(CommonSymbolKeys.COLOUR));
Expression backgroundColour = getColour(obj.get(PictureFillSymbolKeys.BACKGROUND_COLOUR));
if ((foregroundColour != null) && (backgroundColour != null)) {
setForegroundColour(foregroundColour, backgroundColour, image);
}
ImageIO.write(image, imageType, buffOutStream);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
} finally {
if (buffOutStream != null) {
try {
buffOutStream.close();
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
}
}
String fileExtension = ExternalFilenames.getFileExtension(filename);
String imageFormat = ExternalFilenames.getImageFormat(fileExtension);
ExternalGraphic externalGraphic = styleFactory.createExternalGraphic(file.toURI().toString(), imageFormat);
List<GraphicalSymbol> symbols = getSymbolList(externalGraphic);
Expression size = null;
Expression opacity = null;
Displacement displacement = styleFactory.createDisplacement(ff.literal(xOffset), ff.literal(yOffset));
AnchorPoint anchorPoint = null;
graphic = styleFactory.graphic(symbols, opacity, size, ff.literal(angle), anchorPoint, displacement);
}
}
}
Fill fill = styleFactory.createFill(getColour(obj.get(CommonSymbolKeys.COLOUR)), getColour(obj.get(PictureFillSymbolKeys.BACKGROUND_COLOUR)), getTransparency(transparency), graphic);
return fill;
}
use of org.geotools.styling.Fill in project sldeditor by robward-scisys.
the class TextSymbol method convert.
/* (non-Javadoc)
* @see com.sldeditor.convert.esri.symbols.EsriTextSymbolInterface#convert(org.geotools.styling.TextSymbolizer, com.google.gson.JsonElement, int)
*/
@SuppressWarnings("unused")
@Override
public void convert(TextSymbolizer textSymbolizer, JsonElement element, int transparency) {
if ((element != null) && (textSymbolizer != null)) {
JsonObject obj = element.getAsJsonObject();
double angle = getDouble(obj, CommonSymbolKeys.ANGLE);
int breakCharacter = getInt(obj, TextSymbolKeys.BREAK_CHARACTER);
int textCase = getInt(obj, TextSymbolKeys.CASE);
double characterSpacing = getDouble(obj, TextSymbolKeys.CHARACTER_SPACING);
double characterWidth = getDouble(obj, TextSymbolKeys.CHARACTER_WIDTH);
double size = getDouble(obj, CommonSymbolKeys.SIZE);
size += MXDOptions.getInstance().getFontSizeFactor();
int direction = getInt(obj, TextSymbolKeys.DIRECTION);
double flipAngle = getDouble(obj, TextSymbolKeys.FLIP_ANGLE);
int horizontalAlignment = getInt(obj, TextSymbolKeys.HORIZONTAL_ALIGNMENT);
int verticalAlignment = getInt(obj, TextSymbolKeys.VERTICAL_ALIGNMENT);
double leading = getDouble(obj, TextSymbolKeys.LEADING);
double margin = getDouble(obj, TextSymbolKeys.MARGIN);
double maskSize = getDouble(obj, TextSymbolKeys.MASK_SIZE);
int maskStyle = getInt(obj, TextSymbolKeys.MASK_STYLE);
int position = getInt(obj, TextSymbolKeys.POSITION);
double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET);
double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET);
double shadowXOffset = getDouble(obj, TextSymbolKeys.SHADOW_X_OFFSET);
double shadowYOffset = getDouble(obj, TextSymbolKeys.SHADOW_Y_OFFSET);
double wordSpacing = getDouble(obj, TextSymbolKeys.WORD_SPACING);
boolean CJKCharactersRotation = getBoolean(obj, TextSymbolKeys.CJK_CHARACTERS_ROTATION);
boolean clip = getBoolean(obj, TextSymbolKeys.CLIP);
boolean kerning = getBoolean(obj, TextSymbolKeys.KERNING);
boolean rightToLeft = getBoolean(obj, TextSymbolKeys.RIGHT_TO_LEFT);
boolean rotateWithTransform = getBoolean(obj, TextSymbolKeys.ROTATE_WITH_TRANSFORM);
boolean typeSetting = getBoolean(obj, TextSymbolKeys.TYPE_SETTING);
//
// Point placement
//
AnchorPoint anchorPoint = styleFactory.anchorPoint(ff.literal(0), ff.literal(0));
Displacement displacement = styleFactory.displacement(ff.literal(xOffset), ff.literal(yOffset));
Expression rotationExpression = ff.literal(angle);
styleFactory.pointPlacement(anchorPoint, displacement, rotationExpression);
//
// Font
//
JsonElement fontElement = obj.get(TextSymbolKeys.FONT);
if (fontElement != null) {
JsonObject fontObj = fontElement.getAsJsonObject();
String fontName = getString(fontObj, FontSymbolKeys.FONT_NAME);
boolean bold = getBoolean(fontObj, FontSymbolKeys.BOLD);
boolean italic = getBoolean(fontObj, FontSymbolKeys.ITALIC);
boolean strikeThrough = getBoolean(fontObj, FontSymbolKeys.STRIKE_THROUGH);
boolean underline = getBoolean(fontObj, FontSymbolKeys.UNDERLINE);
int weight = getInt(fontObj, FontSymbolKeys.FONT_WEIGHT);
int charset = getInt(fontObj, FontSymbolKeys.CHARSET);
int fontSize = getInt(obj, FontSymbolKeys.FONT_SIZE);
Expression fontFamilyExpression = ff.literal(fontName);
Expression fontSizeExpression = ff.literal(size);
String fontStyle = "normal";
if (italic) {
fontStyle = "italic";
}
Expression fontStyleExpression = ff.literal(fontStyle);
String fontWeight = "normal";
if (bold) {
fontWeight = "bold";
}
Expression fontWeightExpression = ff.literal(fontWeight);
Font font = styleFactory.createFont(fontFamilyExpression, fontStyleExpression, fontWeightExpression, fontSizeExpression);
textSymbolizer.setFont(font);
}
GraphicFill graphicFill = null;
Expression textColour = getColour(obj.get(CommonSymbolKeys.COLOUR));
Expression opacity = null;
if (transparency != 0) {
opacity = ff.literal(transparency / 255);
}
Fill fill = styleFactory.fill(graphicFill, textColour, opacity);
textSymbolizer.setFill(fill);
String geometryPropertyName = null;
textSymbolizer.setGeometryPropertyName(geometryPropertyName);
Expression shadowColour = getColour(obj.get(TextSymbolKeys.SHADOW_COLOUR));
}
}
use of org.geotools.styling.Fill in project sldeditor by robward-scisys.
the class FillTreeItemTest method testGetTreeString.
/**
* Test method for {@link com.sldeditor.ui.tree.item.FillTreeItem#getTreeString(java.lang.Object)}.
*/
@Test
public void testGetTreeString() {
FillTreeItem item = new FillTreeItem();
String actualValue = item.getTreeString(null, null);
String expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.fill");
assertTrue(actualValue.compareTo(expectedValue) == 0);
Fill fill = DefaultSymbols.createDefaultGraphicFill();
actualValue = item.getTreeString(null, fill);
assertTrue(actualValue.compareTo(expectedValue) == 0);
actualValue = item.getTreeString(null, fill);
assertTrue(actualValue.compareTo(expectedValue) == 0);
}
Aggregations