@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); }
/** * 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()); }
String text = stringBuilder.toString(); int x = (int) (tilePosition.point.x + (tile.tileSize - this.paintBack.getTextWidth(text)) / 2); int y = (int) (tilePosition.point.y + (tile.tileSize + this.paintBack.getTextHeight(text)) / 2); canvas.drawText(text, x, y, this.paintBack); canvas.drawText(text, x, y, this.paintFront);
Math.round(canvas.getHeight() * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint); canvas.drawText(scaleText2, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText2)), paint); Math.round(canvas.getHeight() * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint); canvas.drawText(scaleText2, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText2)), paint); Math.round(canvas.getHeight() * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint); canvas.drawText(scaleText2, Math.round(canvas.getWidth() - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.getTextWidth(scaleText2)), Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText2)), paint); if (scaleText2.length() == 0) { canvas.drawText(scaleText1, Math.round((canvas.getWidth() - this.paintScaleTextStroke.getTextWidth(scaleText1)) * 0.5f), Math.round(SCALE_BAR_MARGIN * scale + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText1)), paint); } else { canvas.drawText(scaleText1, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), Math.round(canvas.getHeight() * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint); canvas.drawText(scaleText2, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText2)), paint); if (scaleText2.length() == 0) { canvas.drawText(scaleText1, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), Math.round(SCALE_BAR_MARGIN * scale + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText1)), paint); } else { canvas.drawText(scaleText1, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), Math.round(canvas.getHeight() * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint); canvas.drawText(scaleText2, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText2)), paint);
double textHeight = (stroke == null) ? fill.getTextHeight(text) : stroke.getTextHeight(text); final Rectangle tileBoundary = Tile.getBoundaryAbsolute(upperLeft, lowerRight);
String text = convertCoordinate(latitude); int pixelX = (canvas.getWidth() - this.textFront.getTextWidth(text)) / 2; int pixelY = (int) (MercatorProjection.latitudeToPixelY(latitude, mapSize) - topLeftPoint.y) + this.textFront.getTextHeight(text) / 2; canvas.drawText(text, pixelX, pixelY, this.textBack); canvas.drawText(text, pixelX, pixelY, this.textFront); String text = convertCoordinate(longitude); int pixelX = (int) (MercatorProjection.longitudeToPixelX(longitude, mapSize) - topLeftPoint.x) - this.textFront.getTextWidth(text) / 2; int pixelY = (canvas.getHeight() + this.textFront.getTextHeight(text)) / 2; canvas.drawText(text, pixelX, pixelY, this.textBack); canvas.drawText(text, pixelX, pixelY, this.textFront);
@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); }
public static Bitmap getBitmapFromTitle(String title, Paint paint) { if (!captionViews.containsKey(title)) { TextView bubbleView = new TextView(context); Utils.setBackground(bubbleView, context.getResources().getDrawable(R.drawable.caption_background)); bubbleView.setGravity(Gravity.CENTER); bubbleView.setMaxEms(20); bubbleView.setTextSize(10); bubbleView.setPadding(5, -2, 5, -2); bubbleView.setTextColor(android.graphics.Color.BLACK); bubbleView.setText(title); //Measure the view at the exact dimensions (otherwise the text won't center correctly) int widthSpec = View.MeasureSpec.makeMeasureSpec(paint.getTextWidth(title), View.MeasureSpec.EXACTLY); int heightSpec = View.MeasureSpec.makeMeasureSpec(paint.getTextHeight(title), View.MeasureSpec.EXACTLY); bubbleView.measure(widthSpec, heightSpec); //Layout the view at the width and height bubbleView.layout(0, 0, paint.getTextWidth(title), paint.getTextHeight(title)); captionViews.put(title, Utils.viewToBitmap(context, bubbleView)); captionViews.get(title).incrementRefCount(); // FIXME: is never reduced! } return captionViews.get(title); }
/** * 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()); }
String text = stringBuilder.toString(); int x = (int) (tilePosition.point.x + (tile.tileSize - this.paintBack.getTextWidth(text)) / 2); int y = (int) (tilePosition.point.y + (tile.tileSize + this.paintBack.getTextHeight(text)) / 2); canvas.drawText(text, x, y, this.paintBack); canvas.drawText(text, x, y, this.paintFront);
@Override public void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) { super.draw(boundingBox, zoomLevel, canvas, topLeftPoint); long mapSize = MercatorProjection.getMapSize(zoomLevel, this.displayModel.getTileSize()); int pixelX = (int) (MercatorProjection.longitudeToPixelX(position.longitude, mapSize) - topLeftPoint.x); int pixelY = (int) (MercatorProjection.latitudeToPixelY(position.latitude, mapSize) - topLeftPoint.y); String text = Integer.toString(count); canvas.drawText(text, pixelX - BLACK.getTextWidth(text) / 2, pixelY + BLACK.getTextHeight(text) / 2, BLACK); }
Math.round(canvas.getHeight() * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint); canvas.drawText(scaleText2, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText2)), paint); Math.round(canvas.getHeight() * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint); canvas.drawText(scaleText2, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText2)), paint); Math.round(canvas.getHeight() * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint); canvas.drawText(scaleText2, Math.round(canvas.getWidth() - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.getTextWidth(scaleText2)), Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText2)), paint); if (scaleText2.length() == 0) { canvas.drawText(scaleText1, Math.round((canvas.getWidth() - this.paintScaleTextStroke.getTextWidth(scaleText1)) * 0.5f), Math.round(SCALE_BAR_MARGIN * scale + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText1)), paint); } else { canvas.drawText(scaleText1, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), Math.round(canvas.getHeight() * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint); canvas.drawText(scaleText2, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText2)), paint); if (scaleText2.length() == 0) { canvas.drawText(scaleText1, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), Math.round(SCALE_BAR_MARGIN * scale + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText1)), paint); } else { canvas.drawText(scaleText1, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), Math.round(canvas.getHeight() * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint); canvas.drawText(scaleText2, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText2)), paint);
double textHeight = (stroke == null) ? fill.getTextHeight(text) : stroke.getTextHeight(text); final Rectangle tileBoundary = Tile.getBoundaryAbsolute(upperLeft, lowerRight);
String text = convertCoordinate(latitude); int pixelX = (canvas.getWidth() - this.textFront.getTextWidth(text)) / 2; int pixelY = (int) (MercatorProjection.latitudeToPixelY(latitude, mapSize) - topLeftPoint.y) + this.textFront.getTextHeight(text) / 2; canvas.drawText(text, pixelX, pixelY, this.textBack); canvas.drawText(text, pixelX, pixelY, this.textFront); String text = convertCoordinate(longitude); int pixelX = (int) (MercatorProjection.longitudeToPixelX(longitude, mapSize) - topLeftPoint.x) - this.textFront.getTextWidth(text) / 2; int pixelY = (canvas.getHeight() + this.textFront.getTextHeight(text)) / 2; canvas.drawText(text, pixelX, pixelY, this.textBack); canvas.drawText(text, pixelX, pixelY, this.textFront);
int y = (int) (top + halfBitmapHeight + cluster.getClusterManager().markerIconBmps .get(markerType).getPaint().getTextHeight(cluster.getTitle()) / 2); canvas.drawText(cluster.getTitle(), x, y, cluster.getClusterManager().markerIconBmps