private Paint createTextPaint(Color color, float strokeWidth, Style style) { Paint paint = this.graphicFactory.createPaint(); paint.setColor(color); paint.setStrokeWidth(strokeWidth * this.scale); paint.setStyle(style); paint.setTypeface(FontFamily.DEFAULT, FontStyle.BOLD); paint.setTextSize(12 * this.scale); return paint; }
stringBuilder.append(tile.zoomLevel).append(" / ").append(tile.tileX).append(" / ").append(tile.tileY); 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);
/** * 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()); }
private Paint createScaleBarPaint(Color color, float strokeWidth, Style style) { Paint paint = this.graphicFactory.createPaint(); paint.setColor(color); paint.setStrokeWidth(strokeWidth * this.scale); paint.setStyle(style); paint.setStrokeCap(Cap.SQUARE); return paint; }
private static Paint createLineBack(GraphicFactory graphicFactory, DisplayModel displayModel) { Paint paint = graphicFactory.createPaint(); paint.setColor(Color.WHITE); paint.setStrokeWidth(4 * displayModel.getScaleFactor()); paint.setStyle(Style.STROKE); return paint; }
private static Paint createTextFront(GraphicFactory graphicFactory, DisplayModel displayModel) { Paint paint = graphicFactory.createPaint(); paint.setColor(Color.BLUE); paint.setTypeface(FontFamily.DEFAULT, FontStyle.BOLD); paint.setTextSize(12 * displayModel.getScaleFactor()); return paint; }
@Override public void draw(Canvas canvas, Point origin, Matrix matrix, Filter filter) { if (this.paintFront.isTransparent() && (this.paintBack == null || this.paintBack.isTransparent())) { return; int textWidth = this.paintFront.getTextWidth(this.text); if (textWidth > maxTextWidth) { int colorF = this.paintFront.getColor(); if (filter != Filter.NONE) { this.paintFront.setColor(GraphicUtils.filterColor(colorF, filter)); int colorB = this.paintBack.getColor(); if (filter != Filter.NONE) { this.paintBack.setColor(GraphicUtils.filterColor(colorB, filter)); awtCanvas.getGraphicObject().draw(layout.getOutline(affineTransform)); if (filter != Filter.NONE) { this.paintBack.setColor(colorB); drawPosY += layout.getAscent() + layout.getDescent() + layout.getLeading(); if (filter != Filter.NONE) { this.paintFront.setColor(colorF); int color = this.paintBack.getColor(); if (filter != Filter.NONE) { this.paintBack.setColor(GraphicUtils.filterColor(color, filter)); this.paintBack.setColor(color); int color = this.paintFront.getColor();
public PathText(GraphicFactory graphicFactory, DisplayModel displayModel, String elementName, XmlPullParser pullParser) throws XmlPullParserException { super(graphicFactory, displayModel); this.fill = graphicFactory.createPaint(); this.fill.setColor(Color.BLACK); this.fill.setStyle(Style.FILL); this.fill.setTextAlign(Align.CENTER); this.fills = new HashMap<>(); this.rotate = true; this.repeat = true; this.stroke = graphicFactory.createPaint(); this.stroke.setColor(Color.BLACK); this.stroke.setStyle(Style.STROKE); this.stroke.setTextAlign(Align.CENTER); this.strokes = new HashMap<>(); this.dyScaled = new HashMap<>(); this.display = Display.IFSPACE; extractValues(graphicFactory, displayModel, elementName, pullParser); }
@Override public void draw(Canvas canvas, Point origin, Matrix matrix, Filter filter) { Point adjustedStart = xy.offset(-origin.x, -origin.y); Point adjustedEnd = end.offset(-origin.x, -origin.y); if (this.paintBack != null) { int color = this.paintBack.getColor(); if (filter != Filter.NONE) { this.paintBack.setColor(GraphicUtils.filterColor(color, filter)); } canvas.drawTextRotated(text, (int) (adjustedStart.x), (int) (adjustedStart.y), (int) (adjustedEnd.x), (int) (adjustedEnd.y), this.paintBack); if (filter != Filter.NONE) { this.paintBack.setColor(color); } } int color = this.paintFront.getColor(); if (filter != Filter.NONE) { this.paintFront.setColor(GraphicUtils.filterColor(color, filter)); } canvas.drawTextRotated(text, (int) (adjustedStart.x), (int) (adjustedStart.y), (int) (adjustedEnd.x), (int) (adjustedEnd.y), this.paintFront); if (filter != Filter.NONE) { this.paintFront.setColor(color); } }
public Line(GraphicFactory graphicFactory, DisplayModel displayModel, String elementName, XmlPullParser pullParser, int level, String relativePathPrefix) throws IOException, XmlPullParserException { super(graphicFactory, displayModel); this.level = level; this.relativePathPrefix = relativePathPrefix; this.stroke = graphicFactory.createPaint(); this.stroke.setColor(Color.BLACK); this.stroke.setStyle(Style.STROKE); this.stroke.setStrokeCap(Cap.ROUND); this.stroke.setStrokeJoin(Join.ROUND); this.strokes = new HashMap<>(); this.dyScaled = new HashMap<>(); extractValues(graphicFactory, displayModel, elementName, pullParser); }
this.dy = Float.parseFloat(value) * displayModel.getScaleFactor(); } else if (FILL.equals(name)) { this.fill.setColor(XmlUtils.getColor(graphicFactory, value, displayModel.getThemeCallback())); } else if (FONT_FAMILY.equals(name)) { fontFamily = FontFamily.fromString(value); this.priority = Integer.parseInt(value); } else if (STROKE.equals(name)) { this.stroke.setColor(XmlUtils.getColor(graphicFactory, value, displayModel.getThemeCallback())); } else if (STROKE_WIDTH.equals(name)) { this.stroke.setStrokeWidth(XmlUtils.parseNonNegativeFloat(name, value) * displayModel.getScaleFactor()); } else if (SYMBOL_ID.equals(name)) { this.symbolId = value; this.fill.setTypeface(fontFamily, fontStyle); this.stroke.setTypeface(fontFamily, fontStyle);
private void initialize() { ROUTE_NOT_VALID_PAINT = graphicFactory.createPaint(); ROUTE_NOT_VALID_PAINT.setColor(0xFFFF0000); ROUTE_NOT_VALID_PAINT.setStrokeWidth(getRouteLineWidth()); ROUTE_DOWNLOADING_PAINT = graphicFactory.createPaint(); ROUTE_DOWNLOADING_PAINT.setColor(0x993379FF); ROUTE_DOWNLOADING_PAINT.setStrokeWidth(getRouteLineWidth()); ROUTE_DOWNLOADING_PAINT.setDashPathEffect(new float[]{3, 12}); }
@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()); } }
public Area(GraphicFactory graphicFactory, DisplayModel displayModel, String elementName, XmlPullParser pullParser, int level, String relativePathPrefix) throws IOException, XmlPullParserException { super(graphicFactory, displayModel); this.level = level; this.relativePathPrefix = relativePathPrefix; this.fill = graphicFactory.createPaint(); this.fill.setColor(Color.TRANSPARENT); this.fill.setStyle(Style.FILL); this.fill.setStrokeCap(Cap.ROUND); this.stroke = graphicFactory.createPaint(); this.stroke.setColor(Color.TRANSPARENT); this.stroke.setStyle(Style.STROKE); this.stroke.setStrokeCap(Cap.ROUND); this.strokes = new HashMap<>(); extractValues(elementName, pullParser); }
private void internalAdd(List<PairWithLayer> pairWithLayers) { Paint paint = GRAPHIC_FACTORY.createPaint(); paint.setColor(asRGBA(trackColorModel)); paint.setStrokeWidth(preferences.getInt(TRACK_LINE_WIDTH_PREFERENCE, 2)); int tileSize = getTileSize(); List<PairWithLayer> withLayers = new ArrayList<>(); for (PairWithLayer pair : pairWithLayers) { if (!pair.hasCoordinates()) continue; Line line = new Line(asLatLong(pair.getFirst()), asLatLong(pair.getSecond()), paint, tileSize); pair.setLayer(line); withLayers.add(pair); } addLayers(withLayers); } });
Paint paint1; paint1 = AndroidGraphicFactory.INSTANCE.createPaint(); paint1.setStyle(Style.STROKE); paint1.setTextAlign(Align.CENTER); FontFamily fontFamily = FontFamily.DEFAULT; FontStyle fontStyle = FontStyle.BOLD; paint1.setTypeface(fontFamily, fontStyle); paint1.setColor(Color.RED); markerBitmaps.add(new MarkerBitmap(this.getApplicationContext(), bitmapClimbingPeak, markerRedS, new Point(0, 0), 10f, 1, paint1)); Paint paint2; paint2 = AndroidGraphicFactory.INSTANCE.createPaint(); paint2.setStyle(Style.STROKE); paint2.setTextAlign(Align.CENTER); fontFamily = FontFamily.DEFAULT; fontStyle = FontStyle.BOLD; paint2.setTypeface(fontFamily, fontStyle); paint2.setColor(Color.WHITE); markerBitmaps.add(new MarkerBitmap(this.getApplicationContext(), bitmapBalloonSN, bitmapBalloonSS, new Point(0, 0), 9f, 10, paint2)); Paint paint3; paint3 = AndroidGraphicFactory.INSTANCE.createPaint(); paint3.setStyle(Style.STROKE); paint3.setTextAlign(Align.CENTER); fontFamily = FontFamily.DEFAULT; fontStyle = FontStyle.BOLD; paint3.setTypeface(fontFamily, fontStyle);
@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); }
this.scale = scaleFromValue(value); } else if (STROKE.equals(name)) { this.stroke.setColor(XmlUtils.getColor(graphicFactory, value, displayModel.getThemeCallback())); } else if (STROKE_DASHARRAY.equals(name)) { this.strokeDasharray = parseFloatArray(name, value); this.strokeDasharray[f] = this.strokeDasharray[f] * displayModel.getScaleFactor(); this.stroke.setDashPathEffect(this.strokeDasharray); } else if (STROKE_LINECAP.equals(name)) { this.stroke.setStrokeCap(Cap.fromString(value)); } else if (STROKE_LINEJOIN.equals(name)) { this.stroke.setStrokeJoin(Join.fromString(value)); } else if (STROKE_WIDTH.equals(name)) { this.strokeWidth = XmlUtils.parseNonNegativeFloat(name, value) * displayModel.getScaleFactor();
private void extractValues(GraphicFactory graphicFactory, DisplayModel displayModel, String elementName, XmlPullParser pullParser) throws XmlPullParserException { for (int i = 0; i < pullParser.getAttributeCount(); ++i) { String name = pullParser.getAttributeName(i); String value = pullParser.getAttributeValue(i); if (RADIUS.equals(name) || R.equals(name)) { this.radius = XmlUtils.parseNonNegativeFloat(name, value) * displayModel.getScaleFactor(); } else if (CAT.equals(name)) { this.category = value; } else if (FILL.equals(name)) { this.fill.setColor(XmlUtils.getColor(graphicFactory, value, displayModel.getThemeCallback())); } else if (SCALE_RADIUS.equals(name)) { this.scaleRadius = Boolean.parseBoolean(value); } else if (STROKE.equals(name)) { this.stroke.setColor(XmlUtils.getColor(graphicFactory, value, displayModel.getThemeCallback())); } else if (STROKE_WIDTH.equals(name)) { this.strokeWidth = XmlUtils.parseNonNegativeFloat(name, value) * displayModel.getScaleFactor(); } else { throw XmlUtils.createXmlPullParserException(elementName, name, value, i); } } XmlUtils.checkMandatoryAttribute(elementName, RADIUS, this.radius); }
@Override public synchronized void renderWay(RenderCallback renderCallback, final RenderContext renderContext, PolylineContainer way) { if (!bitmapCreated) { try { shaderBitmap = createBitmap(relativePathPrefix, src); } catch (IOException ioException) { // no-op } bitmapCreated = true; } Paint strokePaint = getStrokePaint(renderContext.rendererJob.tile.zoomLevel); if (shaderBitmap != null) { strokePaint.setBitmapShader(shaderBitmap); strokePaint.setBitmapShaderShift(way.getUpperLeft().getOrigin()); } Float dyScale = this.dyScaled.get(renderContext.rendererJob.tile.zoomLevel); if (dyScale == null) { dyScale = this.dy; } renderCallback.renderWay(renderContext, strokePaint, dyScale, this.level, way); }