use of javax.measure.quantity.Length in project com.revolsys.open by revolsys.
the class GeometryStyle method setLineStyle.
public void setLineStyle(final Viewport2D viewport, final Graphics2D graphics) {
final Color color = getLineColor();
graphics.setColor(color);
final Unit<Length> unit = this.lineWidth.getUnit();
final float width = (float) Viewport2D.toModelValue(viewport, this.lineWidth);
final float dashOffset = (float) Viewport2D.toModelValue(viewport, Quantities.getQuantity(this.lineDashOffset, unit));
final float[] dashArray;
final int dashArraySize = this.lineDashArray.size();
if (dashArraySize == 0) {
dashArray = null;
} else {
dashArray = new float[dashArraySize];
for (int i = 0; i < dashArray.length; i++) {
final Double dashDouble = this.lineDashArray.get(i);
final float dashFloat = (float) Viewport2D.toModelValue(viewport, Quantities.getQuantity(dashDouble, unit));
dashArray[i] = dashFloat;
}
}
final int lineCap = this.lineCap.getAwtValue();
final int lineJoin = this.lineJoin.getAwtValue();
final BasicStroke basicStroke = new BasicStroke(width, lineCap, lineJoin, this.lineMiterlimit, dashArray, dashOffset);
graphics.setStroke(basicStroke);
}
use of javax.measure.quantity.Length in project com.revolsys.open by revolsys.
the class TextMarker method render.
@Override
public void render(final Viewport2D viewport, final Graphics2D graphics, final MarkerStyle style, final double modelX, final double modelY, double orientation) {
try (BaseCloseable transformCloseable = new CloseableAffineTransform(graphics)) {
Viewport2D.setUseModelCoordinates(viewport, graphics, false);
final Quantity<Length> markerHeight = style.getMarkerHeight();
final double mapHeight = Viewport2D.toDisplayValue(viewport, markerHeight);
final String orientationType = style.getMarkerOrientationType();
if ("none".equals(orientationType)) {
orientation = 0;
}
final int fontSize = (int) mapHeight;
if (this.font == null || this.font.getSize() != fontSize) {
this.font = Fonts.newFont(this.textFaceName, 0, fontSize);
}
final FontRenderContext fontRenderContext = graphics.getFontRenderContext();
final GlyphVector glyphVector = this.font.createGlyphVector(fontRenderContext, this.text);
final Shape shape = glyphVector.getOutline();
final GeneralPath newShape = new GeneralPath(shape);
final Rectangle2D bounds = newShape.getBounds2D();
final double shapeWidth = bounds.getWidth();
final double shapeHeight = bounds.getHeight();
Viewport2D.translateModelToViewCoordinates(viewport, graphics, modelX, modelY);
final double markerOrientation = style.getMarkerOrientation();
orientation = -orientation + markerOrientation;
if (orientation != 0) {
graphics.rotate(Math.toRadians(orientation));
}
final Quantity<Length> deltaX = style.getMarkerDx();
final Quantity<Length> deltaY = style.getMarkerDy();
double dx = Viewport2D.toDisplayValue(viewport, deltaX);
double dy = Viewport2D.toDisplayValue(viewport, deltaY);
dy -= bounds.getY();
final String verticalAlignment = style.getMarkerVerticalAlignment();
if ("bottom".equals(verticalAlignment)) {
dy -= shapeHeight;
} else if ("auto".equals(verticalAlignment) || "middle".equals(verticalAlignment)) {
dy -= shapeHeight / 2.0;
}
final String horizontalAlignment = style.getMarkerHorizontalAlignment();
if ("right".equals(horizontalAlignment)) {
dx -= shapeWidth;
} else if ("auto".equals(horizontalAlignment) || "center".equals(horizontalAlignment)) {
dx -= shapeWidth / 2;
}
graphics.translate(dx, dy);
if (style.setMarkerFillStyle(viewport, graphics)) {
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
graphics.setFont(this.font);
graphics.drawString(this.text, 0, 0);
}
}
}
use of javax.measure.quantity.Length in project com.revolsys.open by revolsys.
the class Viewport2D method toModelValue.
public double toModelValue(final Quantity<Length> value) {
double convertedValue;
final Unit<Length> unit = value.getUnit();
if (unit.equals(CustomUnits.PIXEL)) {
convertedValue = QuantityType.doubleValue(value, CustomUnits.PIXEL);
final double modelUnitsPerViewUnit = getModelUnitsPerViewUnit();
convertedValue *= modelUnitsPerViewUnit;
} else {
convertedValue = QuantityType.doubleValue(value, Units.METRE);
final CoordinateSystem coordinateSystem = this.geometryFactory2d.getCoordinateSystem();
if (coordinateSystem instanceof GeographicCoordinateSystem) {
final GeographicCoordinateSystem geoCs = (GeographicCoordinateSystem) coordinateSystem;
final double radius = geoCs.getDatum().getEllipsoid().getSemiMajorAxis();
convertedValue = Math.toDegrees(convertedValue / radius);
}
}
return convertedValue;
}
use of javax.measure.quantity.Length in project com.revolsys.open by revolsys.
the class ArcGisRestServerRecordLayer method addTextRenderer.
private void addTextRenderer(final AbstractMultipleRenderer renderers, final MapEx labelProperties) {
final TextStyle textStyle = new TextStyle();
final String alignment = labelProperties.getString("labelPlacement");
if (alignment.endsWith("Left")) {
textStyle.setTextHorizontalAlignment("right");
} else if (alignment.endsWith("Right")) {
textStyle.setTextHorizontalAlignment("left");
} else if (alignment.endsWith("Before")) {
textStyle.setTextHorizontalAlignment("right");
textStyle.setTextPlacementType("vertex(0)");
} else if (alignment.endsWith("Start")) {
textStyle.setTextHorizontalAlignment("left");
textStyle.setTextPlacementType("vertex(0)");
} else if (alignment.endsWith("After")) {
textStyle.setTextHorizontalAlignment("left");
textStyle.setTextPlacementType("vertex(n)");
} else if (alignment.endsWith("End")) {
textStyle.setTextHorizontalAlignment("right");
textStyle.setTextPlacementType("vertex(n)");
} else if (alignment.endsWith("Along")) {
textStyle.setTextHorizontalAlignment("center");
textStyle.setTextPlacementType("auto");
} else {
textStyle.setTextHorizontalAlignment("center");
}
if (alignment.contains("Above")) {
textStyle.setTextVerticalAlignment("bottom");
} else if (alignment.endsWith("Below")) {
textStyle.setTextVerticalAlignment("top");
} else {
textStyle.setTextVerticalAlignment("center");
}
String textName = labelProperties.getString("labelExpression");
textName = textName.replace(" CONCAT ", "");
textName = textName.replaceAll("\"([^\"]+)\"", "$1");
textStyle.setTextName(textName);
final MapEx symbol = labelProperties.getValue("symbol");
if ("esriTS".equals(symbol.getString("type"))) {
final Color textFill = getColor(symbol);
textStyle.setTextFill(textFill);
final Color backgroundColor = getColor(symbol, "backgroundColor");
textStyle.setTextBoxColor(backgroundColor);
// "useCodedValues": false,
// "borderLineColor": null,
// "verticalAlignment": "bottom",
// "horizontalAlignment": "left",
// "rightToLeft": false,
// "kerning": true,
final double angle = symbol.getDouble("angle", 0);
textStyle.setTextOrientation(angle);
final Quantity<Length> textDx = Quantities.getQuantity(symbol.getDouble("xoffset", 0), CustomUnits.PIXEL);
textStyle.setTextDx(textDx);
final Quantity<Length> textDy = Quantities.getQuantity(symbol.getDouble("yoffset", 0), CustomUnits.PIXEL);
textStyle.setTextDx(textDy);
final MapEx font = symbol.getValue("font");
if (font != null) {
final String faceName = font.getString("family", "Arial");
textStyle.setTextFaceName(faceName);
final Quantity<Length> size = Quantities.getQuantity(font.getDouble("size", 10), CustomUnits.PIXEL);
textStyle.setTextSize(size);
}
// "font": {
// "style": "normal",
// "weight": "bold",
// "decoration": "none"
}
final TextStyleRenderer textRenderer = new TextStyleRenderer(this, textStyle);
textRenderer.setName(textName.replace("[", "").replace("]", ""));
long minimumScale = labelProperties.getLong("minScale", Long.MAX_VALUE);
if (minimumScale == 0) {
minimumScale = Long.MAX_VALUE;
}
textRenderer.setMinimumScale(minimumScale);
final long maximumScale = labelProperties.getLong("maxScale", 0);
textRenderer.setMaximumScale(maximumScale);
final String where = labelProperties.getString("where");
textRenderer.setQueryFilter(where);
renderers.addRenderer(textRenderer);
}
use of javax.measure.quantity.Length in project com.revolsys.open by revolsys.
the class PdfViewport method drawText.
@Override
public void drawText(final Record record, final Geometry geometry, final TextStyle style) {
try {
final String label = TextStyleRenderer.getLabel(record, style);
if (Property.hasValue(label) && geometry != null) {
final String textPlacementType = style.getTextPlacementType();
final PointDoubleXYOrientation point = AbstractRecordLayerRenderer.getPointWithOrientation(this, geometry, textPlacementType);
if (point != null) {
final double orientation = point.getOrientation();
this.contentStream.saveGraphicsState();
try {
// style.setTextStyle(viewport, graphics);
final double x = point.getX();
final double y = point.getY();
final double[] location = toViewCoordinates(x, y);
// style.setTextStyle(viewport, graphics);
final Quantity<Length> textDx = style.getTextDx();
double dx = Viewport2D.toDisplayValue(this, textDx);
final Quantity<Length> textDy = style.getTextDy();
double dy = -Viewport2D.toDisplayValue(this, textDy);
final Font font = style.getFont(this);
final FontMetrics fontMetrics = this.canvas.getFontMetrics(font);
double maxWidth = 0;
final String[] lines = label.split("[\\r\\n]");
for (final String line : lines) {
final Rectangle2D bounds = fontMetrics.getStringBounds(line, this.canvas.getGraphics());
final double width = bounds.getWidth();
maxWidth = Math.max(width, maxWidth);
}
final int descent = fontMetrics.getDescent();
final int ascent = fontMetrics.getAscent();
final int leading = fontMetrics.getLeading();
final double maxHeight = lines.length * (ascent + descent) + (lines.length - 1) * leading;
final String verticalAlignment = style.getTextVerticalAlignment();
if ("top".equals(verticalAlignment)) {
} else if ("middle".equals(verticalAlignment)) {
dy -= maxHeight / 2;
} else {
dy -= maxHeight;
}
String horizontalAlignment = style.getTextHorizontalAlignment();
double screenX = location[0];
double screenY = getViewHeightPixels() - location[1];
final String textPlacement = style.getTextPlacementType();
if ("auto".equals(textPlacement)) {
if (screenX < 0) {
screenX = 1;
dx = 0;
horizontalAlignment = "left";
}
final int viewWidth = getViewWidthPixels();
if (screenX + maxWidth > viewWidth) {
screenX = (int) (viewWidth - maxWidth - 1);
dx = 0;
horizontalAlignment = "left";
}
if (screenY < maxHeight) {
screenY = 1;
dy = 0;
}
final int viewHeight = getViewHeightPixels();
if (screenY > viewHeight) {
screenY = viewHeight - 1 - maxHeight;
dy = 0;
}
}
AffineTransform transform = new AffineTransform();
transform.translate(screenX, screenY);
if (orientation != 0) {
transform.rotate(-Math.toRadians(orientation), 0, 0);
}
transform.translate(dx, dy);
for (final String line : lines) {
transform.translate(0, ascent);
final AffineTransform lineTransform = new AffineTransform(transform);
final Rectangle2D bounds = fontMetrics.getStringBounds(line, this.canvas.getGraphics());
final double width = bounds.getWidth();
final double height = bounds.getHeight();
if ("right".equals(horizontalAlignment)) {
transform.translate(-width, 0);
} else if ("center".equals(horizontalAlignment)) {
transform.translate(-width / 2, 0);
}
transform.translate(dx, 0);
transform.scale(1, 1);
if (Math.abs(orientation) > 90) {
transform.rotate(Math.PI, maxWidth / 2, -height / 4);
}
/*
* final double textHaloRadius = Viewport2D.toDisplayValue(this,
* style.getTextHaloRadius()); if (textHaloRadius > 0) {
* graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
* RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); final Stroke savedStroke =
* graphics.getStroke(); final Stroke outlineStroke = new BasicStroke(
* (float)textHaloRadius, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
* graphics.setColor(style.getTextHaloFill()); graphics.setStroke(outlineStroke);
* final Font font = graphics.getFont(); final FontRenderContext fontRenderContext =
* graphics.getFontRenderContext(); final TextLayout textLayout = new TextLayout(line,
* font, fontRenderContext); final Shape outlineShape =
* textLayout.getOutline(TextStyleRenderer.NOOP_TRANSFORM);
* graphics.draw(outlineShape); graphics.setStroke(savedStroke); }
*/
final Color textBoxColor = style.getTextBoxColor();
if (textBoxColor != null) {
this.contentStream.setNonStrokingColor(textBoxColor);
final double cornerSize = Math.max(height / 2, 5);
// final RoundRectangle2D.Double box = new
// RoundRectangle2D.Double(
// bounds.getX() - 3, bounds.getY() - 1, width + 6, height + 2,
// cornerSize, cornerSize);
this.contentStream.fillRect((float) bounds.getX() - 3, (float) bounds.getY() - 1, (float) width + 6, (float) height + 2);
}
this.contentStream.setNonStrokingColor(style.getTextFill());
this.contentStream.beginText();
final PDFont pdfFont = getFont("/org/apache/pdfbox/resources/ttf/ArialMT.ttf");
this.contentStream.setFont(pdfFont, font.getSize2D());
this.contentStream.setTextMatrix(transform);
this.contentStream.drawString(line);
this.contentStream.endText();
transform = lineTransform;
transform.translate(0, leading + descent);
}
} finally {
this.contentStream.restoreGraphicsState();
}
}
}
} catch (final IOException e) {
throw new RuntimeException("Unable to write PDF", e);
}
}
Aggregations