use of com.revolsys.awt.CloseableAffineTransform 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 com.revolsys.awt.CloseableAffineTransform in project com.revolsys.open by revolsys.
the class Viewport2D method setUseModelCoordinates.
public BaseCloseable setUseModelCoordinates(final Graphics2D graphics, final boolean useModelCoordinates) {
if (useModelCoordinates) {
final CloseableAffineTransform transform = new CloseableAffineTransform(graphics);
final AffineTransform modelToScreenTransform = getModelToScreenTransform();
transform.concatenate(modelToScreenTransform);
return transform;
}
return null;
}
use of com.revolsys.awt.CloseableAffineTransform in project com.revolsys.open by revolsys.
the class SvgMarker method render.
@Override
public void render(final Viewport2D viewport, final Graphics2D graphics, final MarkerStyle style, final double modelX, final double modelY, double orientation) {
final TranscoderInput transcoderInput = this.transcoderInput;
if (transcoderInput != null) {
try (BaseCloseable transformCloseable = new CloseableAffineTransform(graphics)) {
Viewport2D.setUseModelCoordinates(viewport, graphics, false);
final Quantity<Length> markerWidth = style.getMarkerWidth();
final double mapWidth = Viewport2D.toDisplayValue(viewport, markerWidth);
final Quantity<Length> markerHeight = style.getMarkerHeight();
final double mapHeight = Viewport2D.toDisplayValue(viewport, markerHeight);
final String orientationType = style.getMarkerOrientationType();
if ("none".equals(orientationType)) {
orientation = 0;
}
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);
final String verticalAlignment = style.getMarkerVerticalAlignment();
if ("bottom".equals(verticalAlignment)) {
dy -= mapHeight;
} else if ("middle".equals(verticalAlignment)) {
dy -= mapHeight / 2;
}
final String horizontalAlignment = style.getMarkerHorizontalAlignment();
if ("right".equals(horizontalAlignment)) {
dx -= mapWidth;
} else if ("center".equals(horizontalAlignment)) {
dx -= mapWidth / 2;
}
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics.translate(dx, dy);
// changeAttribute(root, "stroke", "#ffffff",
// WebColors.toHex(style.getMarkerLineColor()));
// changeAttribute(root, "color", "#ffffff",
// WebColors.toHex(style.getMarkerLineColor()));
// changeAttribute(root, "fill", "#ffffff",
// WebColors.toHex(style.getMarkerLineColor()));
//
// changeAttribute(root, "stroke", "#000000",
// WebColors.toHex(style.getMarkerFill()));
// changeAttribute(root, "color", "#000000",
// WebColors.toHex(style.getMarkerFill()));
// changeAttribute(root, "fill", "#000000",
// WebColors.toHex(style.getMarkerFill()));
// changeAttribute(root, "stroke", "#444444",
// WebColors.toHex(style.getMarkerFill()));
// changeAttribute(root, "color", "#444444",
// WebColors.toHex(style.getMarkerFill()));
// changeAttribute(root, "fill", "#444444",
// WebColors.toHex(style.getMarkerFill()));
// shape.render(graphics);
final Graphics2DTranscoder transcoder = new Graphics2DTranscoder(graphics);
synchronized (transcoderInput) {
transcoder.transcode(transcoderInput, null);
}
} catch (final Throwable e) {
Logs.error(this, "Unable to render", e);
}
}
}
Aggregations