@Override public void drawLine(int x1, int y1, int x2, int y2, Paint paint) { if (paint.isTransparent()) { return; } setColorAndStroke(AwtGraphicFactory.getPaint(paint)); this.graphics2D.drawLine(x1, y1, x2, y2); }
@Override public void drawTextRotated(String text, int x1, int y1, int x2, int y2, Paint paint) { if (text == null || text.trim().isEmpty()) { return; } if (paint.isTransparent()) { return; } AffineTransform affineTransform = this.graphics2D.getTransform(); double theta = Math.atan2(y2 - y1, x2 - x1); this.graphics2D.rotate(theta, x1, y1); double lineLength = Math.hypot(x2 - x1, y2 - y1); int textWidth = paint.getTextWidth(text); int dx = (int) (lineLength - textWidth) / 2; int xy = paint.getTextHeight(text) / 3; drawText(text, x1 + dx, y1 + xy, paint); this.graphics2D.setTransform(affineTransform); }
@Override public void drawCircle(int x, int y, int radius, Paint paint) { if (paint.isTransparent()) { return; } AwtPaint awtPaint = AwtGraphicFactory.getPaint(paint); setColorAndStroke(awtPaint); int doubleRadius = radius * 2; Style style = awtPaint.style; switch (style) { case FILL: this.graphics2D.fillOval(x - radius, y - radius, doubleRadius, doubleRadius); return; case STROKE: this.graphics2D.drawOval(x - radius, y - radius, doubleRadius, doubleRadius); return; } throw new IllegalArgumentException(UNKNOWN_STYLE + style); }
@Override public void drawText(String text, int x, int y, Paint paint) { if (text == null || text.trim().isEmpty()) { return; } if (paint.isTransparent()) { return; } AwtPaint awtPaint = AwtGraphicFactory.getPaint(paint); if (awtPaint.stroke == null) { this.graphics2D.setColor(awtPaint.color); this.graphics2D.setFont(awtPaint.font); this.graphics2D.drawString(text, x, y); } else { setColorAndStroke(awtPaint); TextLayout textLayout = new TextLayout(text, awtPaint.font, this.graphics2D.getFontRenderContext()); AffineTransform affineTransform = new AffineTransform(); affineTransform.translate(x, y); this.graphics2D.draw(textLayout.getOutline(affineTransform)); } }
@Override public void drawPath(Path path, Paint paint) { if (paint.isTransparent()) { return; } AwtPaint awtPaint = AwtGraphicFactory.getPaint(paint); AwtPath awtPath = AwtGraphicFactory.getPath(path); setColorAndStroke(awtPaint); this.graphics2D.setPaint(awtPaint.texturePaint); Style style = awtPaint.style; switch (style) { case FILL: this.graphics2D.fill(awtPath.path2D); return; case STROKE: this.graphics2D.draw(awtPath.path2D); return; } throw new IllegalArgumentException(UNKNOWN_STYLE + style); }
/** * Create a new point container, that holds the x-y coordinates of a point, a text variable, two paint objects, and * a reference on a symbolContainer, if the text is connected with a POI. */ protected PointTextContainer(Point point, Display display, int priority, String text, Paint paintFront, Paint paintBack, SymbolContainer symbolContainer, Position position, int maxTextWidth) { super(point, display, priority); this.maxTextWidth = maxTextWidth; this.text = text; this.symbolContainer = symbolContainer; this.paintFront = paintFront; this.paintBack = paintBack; this.position = position; if (paintBack != null) { this.textWidth = paintBack.getTextWidth(text); this.textHeight = paintBack.getTextHeight(text); } else { this.textWidth = paintFront.getTextWidth(text); this.textHeight = paintFront.getTextHeight(text); } this.isVisible = !this.paintFront.isTransparent() || (this.paintBack != null && !this.paintBack.isTransparent()); }
@Test public void isTransparentTest() { Paint paint = new AwtPaint(); Assert.assertFalse(paint.isTransparent()); paint.setColor(Color.TRANSPARENT); Assert.assertTrue(paint.isTransparent()); Bitmap bitmap = org.mapsforge.map.awt.graphics.AwtGraphicFactory.INSTANCE.createBitmap(1, 1); paint.setBitmapShader(bitmap); Assert.assertFalse(paint.isTransparent()); } }
@Override public void drawLine(int x1, int y1, int x2, int y2, Paint paint) { if (paint.isTransparent()) { return; } this.canvas.drawLine(x1, y1, x2, y2, AndroidGraphicFactory.getPaint(paint)); }
@Override public void drawCircle(int x, int y, int radius, Paint paint) { if (paint.isTransparent()) { return; } this.canvas.drawCircle(x, y, radius, AndroidGraphicFactory.getPaint(paint)); }
@Override public void drawText(String text, int x, int y, Paint paint) { if (text == null || text.trim().isEmpty()) { return; } if (paint.isTransparent()) { return; } this.canvas.drawText(text, x, y, AndroidGraphicFactory.getPaint(paint)); }
@Override public void drawTextRotated(String text, int x1, int y1, int x2, int y2, Paint paint) { if (text == null || text.trim().isEmpty()) { return; } if (paint.isTransparent()) { return; } android.graphics.Path path = new android.graphics.Path(); path.moveTo(x1, y1); path.lineTo(x2, y2); this.canvas.drawTextOnPath(text, path, 0, 3, AndroidGraphicFactory.getPaint(paint)); }
@Override public void drawPath(Path path, Paint paint) { if (paint.isTransparent()) { return; } this.canvas.drawPath(AndroidGraphicFactory.getPath(path), AndroidGraphicFactory.getPaint(paint)); }
@Override public void drawLine(int x1, int y1, int x2, int y2, Paint paint) { if (paint.isTransparent()) { return; } setColorAndStroke(AwtGraphicFactory.getPaint(paint)); this.graphics2D.drawLine(x1, y1, x2, y2); }
@Override public void drawCircle(int x, int y, int radius, Paint paint) { if (paint.isTransparent()) { return; } AwtPaint awtPaint = AwtGraphicFactory.getPaint(paint); setColorAndStroke(awtPaint); int doubleRadius = radius * 2; Style style = awtPaint.style; switch (style) { case FILL: this.graphics2D.fillOval(x - radius, y - radius, doubleRadius, doubleRadius); return; case STROKE: this.graphics2D.drawOval(x - radius, y - radius, doubleRadius, doubleRadius); return; } throw new IllegalArgumentException(UNKNOWN_STYLE + style); }
@Override public void drawTextRotated(String text, int x1, int y1, int x2, int y2, Paint paint) { if (text == null || text.trim().isEmpty()) { return; } if (paint.isTransparent()) { return; } AffineTransform affineTransform = this.graphics2D.getTransform(); double theta = Math.atan2(y2 - y1, x2 - x1); this.graphics2D.rotate(theta, x1, y1); double lineLength = Math.hypot(x2 - x1, y2 - y1); int textWidth = paint.getTextWidth(text); int dx = (int) (lineLength - textWidth) / 2; int xy = paint.getTextHeight(text) / 3; drawText(text, x1 + dx, y1 + xy, paint); this.graphics2D.setTransform(affineTransform); }
@Override public void drawText(String text, int x, int y, Paint paint) { if (text == null || text.trim().isEmpty()) { return; } if (paint.isTransparent()) { return; } AwtPaint awtPaint = AwtGraphicFactory.getPaint(paint); if (awtPaint.stroke == null) { this.graphics2D.setColor(awtPaint.color); this.graphics2D.setFont(awtPaint.font); this.graphics2D.drawString(text, x, y); } else { setColorAndStroke(awtPaint); TextLayout textLayout = new TextLayout(text, awtPaint.font, this.graphics2D.getFontRenderContext()); AffineTransform affineTransform = new AffineTransform(); affineTransform.translate(x, y); this.graphics2D.draw(textLayout.getOutline(affineTransform)); } }
@Override public void draw(Canvas canvas, Point origin, Matrix matrix, Filter filter) { if (this.paintFront.isTransparent() && (this.paintBack == null || this.paintBack.isTransparent())) { return;
@Override public void drawPath(Path path, Paint paint) { if (paint.isTransparent()) { return; } AwtPaint awtPaint = AwtGraphicFactory.getPaint(paint); AwtPath awtPath = AwtGraphicFactory.getPath(path); setColorAndStroke(awtPaint); this.graphics2D.setPaint(awtPaint.texturePaint); Style style = awtPaint.style; switch (style) { case FILL: this.graphics2D.fill(awtPath.path2D); return; case STROKE: this.graphics2D.draw(awtPath.path2D); return; } throw new IllegalArgumentException(UNKNOWN_STYLE + style); }
/** * Create a new point container, that holds the x-y coordinates of a point, a text variable, two paint objects, and * a reference on a symbolContainer, if the text is connected with a POI. */ protected PointTextContainer(Point point, Display display, int priority, String text, Paint paintFront, Paint paintBack, SymbolContainer symbolContainer, Position position, int maxTextWidth) { super(point, display, priority); this.maxTextWidth = maxTextWidth; this.text = text; this.symbolContainer = symbolContainer; this.paintFront = paintFront; this.paintBack = paintBack; this.position = position; if (paintBack != null) { this.textWidth = paintBack.getTextWidth(text); this.textHeight = paintBack.getTextHeight(text); } else { this.textWidth = paintFront.getTextWidth(text); this.textHeight = paintFront.getTextHeight(text); } this.isVisible = !this.paintFront.isTransparent() || (this.paintBack != null && !this.paintBack.isTransparent()); }
@Override public void draw(Canvas canvas, Point origin, Matrix matrix, Filter filter) { if (this.paintFront.isTransparent() && (this.paintBack == null || this.paintBack.isTransparent())) { return;