Skip to content
Permalink
Browse files

Parameter for anti-aliasing (#1122)

  • Loading branch information...
wentam authored and devemux86 committed Jun 27, 2019
1 parent eccfea2 commit 933cf104551ee29f8aa1373f9d271b9d140d1a61
@@ -1,5 +1,6 @@
/*
* Copyright 2017-2019 devemux86
* Copyright 2019 Matthew Egeler
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -18,6 +19,11 @@

public enum ParentTilesRendering {QUALITY, SPEED, OFF}

/**
* If true will use anti-aliasing in rendering.
*/
public static boolean ANTI_ALIASING = true;

/**
* If true the <code>MapViewPosition2</code> will be used instead of default <code>MapViewPosition</code>.
*/
@@ -2,6 +2,7 @@
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014 Ludwig M Brinckmann
* Copyright 2015-2017 devemux86
* Copyright 2019 Matthew Egeler
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -17,25 +18,15 @@
package org.mapsforge.map.android.graphics;

import android.annotation.TargetApi;
import android.graphics.BitmapShader;
import android.graphics.DashPathEffect;
import android.graphics.Matrix;
import android.graphics.PathEffect;
import android.graphics.Rect;
import android.graphics.Shader;
import android.graphics.*;
import android.graphics.Shader.TileMode;
import android.graphics.Typeface;
import android.os.Build;

import org.mapsforge.core.graphics.Align;
import org.mapsforge.core.graphics.Cap;
import org.mapsforge.core.graphics.Color;
import org.mapsforge.core.graphics.FontFamily;
import org.mapsforge.core.graphics.FontStyle;
import org.mapsforge.core.graphics.Join;
import org.mapsforge.core.graphics.Paint;
import org.mapsforge.core.graphics.Style;
import org.mapsforge.core.graphics.*;
import org.mapsforge.core.model.Point;
import org.mapsforge.core.util.Parameters;

class AndroidPaint implements Paint {
private static android.graphics.Paint.Align getAndroidAlign(Align align) {
@@ -129,7 +120,7 @@ private static Typeface getTypeface(org.mapsforge.core.graphics.FontFamily fontF

AndroidPaint() {
paint = new android.graphics.Paint();
this.paint.setAntiAlias(true);
this.paint.setAntiAlias(Parameters.ANTI_ALIASING);
this.paint.setStrokeCap(getAndroidCap(Cap.ROUND));
this.paint.setStrokeJoin(android.graphics.Paint.Join.ROUND);
this.paint.setStyle(getAndroidStyle(Style.FILL));
@@ -4,6 +4,7 @@
* Copyright 2017 usrusr
* Copyright 2019 cpt1gl0
* Copyright 2019 Adrian Batzill
* Copyright 2019 Matthew Egeler
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -18,32 +19,21 @@
*/
package org.mapsforge.map.awt.graphics;

import org.mapsforge.core.graphics.Bitmap;
import org.mapsforge.core.graphics.Canvas;
import org.mapsforge.core.graphics.Color;
import org.mapsforge.core.graphics.Filter;
import org.mapsforge.core.graphics.Matrix;
import org.mapsforge.core.graphics.Paint;
import org.mapsforge.core.graphics.Path;
import org.mapsforge.core.graphics.Style;
import org.mapsforge.core.graphics.*;
import org.mapsforge.core.model.Dimension;
import org.mapsforge.core.model.Rectangle;
import org.mapsforge.core.util.Parameters;

import java.awt.AlphaComposite;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ColorConvertOp;
import java.awt.image.IndexColorModel;
import java.awt.image.LookupOp;
import java.awt.image.ShortLookupTable;
import java.awt.image.*;
import java.util.AbstractMap;
import java.util.Map;

@@ -95,7 +85,7 @@ private static Composite selectHillShadingComposite(float magnitude) {

AwtCanvas(Graphics2D graphics2D) {
this.graphics2D = graphics2D;
enableAntiAliasing();
setAntiAlias(Parameters.ANTI_ALIASING);

createFilters();
}
@@ -390,6 +380,8 @@ public void resetClip() {
@Override
public void setAntiAlias(boolean aa) {
this.graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aa ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
this.graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, aa ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
this.graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, aa ? RenderingHints.VALUE_FRACTIONALMETRICS_ON : RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
}

@Override
@@ -400,7 +392,7 @@ public void setBitmap(Bitmap bitmap) {
} else {
this.bufferedImage = AwtGraphicFactory.getBitmap(bitmap);
this.graphics2D = this.bufferedImage.createGraphics();
enableAntiAliasing();
setAntiAlias(Parameters.ANTI_ALIASING);
this.graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
this.graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
}
@@ -465,12 +457,6 @@ public void shadeBitmap(Bitmap bitmap, Rectangle shadeRect, Rectangle tileRect,
this.graphics2D.setComposite(oldComposite);
}

private void enableAntiAliasing() {
this.graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
this.graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
this.graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
}

private void fillColor(java.awt.Color color) {
final Composite originalComposite = this.graphics2D.getComposite();
this.graphics2D.setComposite(AlphaComposite.getInstance(color.getAlpha() == 0 ? AlphaComposite.CLEAR : AlphaComposite.SRC_OVER));

0 comments on commit 933cf10

Please sign in to comment.
You can’t perform that action at this time.