Graphics API enhancements, closes #92
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
- Group layer implementation [#99](https://github.com/mapsforge/vtm/issues/99)
|
||||
- Map scale bar new Android implementation [#88](https://github.com/mapsforge/vtm/issues/88)
|
||||
- Render themes area tessellation option [#37](https://github.com/mapsforge/vtm/issues/37)
|
||||
- Graphics API platform enhancements [#92](https://github.com/mapsforge/vtm/issues/92)
|
||||
- vtm-jts create module [#53](https://github.com/mapsforge/vtm/issues/53)
|
||||
- Internal render themes various enhancements
|
||||
- Revive VTM library
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -16,22 +17,35 @@
|
||||
*/
|
||||
package org.oscim.android.canvas;
|
||||
|
||||
import android.graphics.PorterDuff;
|
||||
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.backend.canvas.Canvas;
|
||||
import org.oscim.backend.canvas.Paint;
|
||||
|
||||
public class AndroidCanvas implements Canvas {
|
||||
final android.graphics.Canvas canvas;
|
||||
|
||||
public final android.graphics.Canvas canvas;
|
||||
|
||||
public AndroidCanvas() {
|
||||
canvas = new android.graphics.Canvas();
|
||||
}
|
||||
|
||||
public AndroidCanvas(android.graphics.Canvas canvas) {
|
||||
this.canvas = canvas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBitmap(Bitmap bitmap) {
|
||||
canvas.setBitmap(((AndroidBitmap) bitmap).mBitmap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawText(String string, float x, float y, Paint paint) {
|
||||
if (string != null)
|
||||
canvas.drawText(string, x, y, ((AndroidPaint) paint).mPaint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawText(String string, float x, float y, Paint fill, Paint stroke) {
|
||||
if (string != null) {
|
||||
@@ -45,7 +59,25 @@ public class AndroidCanvas implements Canvas {
|
||||
@Override
|
||||
public void drawBitmap(Bitmap bitmap, float x, float y) {
|
||||
canvas.drawBitmap(((AndroidBitmap) bitmap).mBitmap, x, y, null);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLine(int x1, int y1, int x2, int y2, Paint paint) {
|
||||
canvas.drawLine(x1, y1, x2, y2, ((AndroidPaint) paint).mPaint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillColor(int color) {
|
||||
canvas.drawColor(color, PorterDuff.Mode.CLEAR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return canvas.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return canvas.getWidth();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -17,21 +18,23 @@
|
||||
package org.oscim.android.canvas;
|
||||
|
||||
import android.graphics.Paint.FontMetrics;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
|
||||
import org.oscim.backend.canvas.Paint;
|
||||
|
||||
class AndroidPaint implements Paint {
|
||||
|
||||
private static int getStyle(org.oscim.backend.canvas.Paint.FontStyle fontStyle) {
|
||||
switch (fontStyle) {
|
||||
case BOLD:
|
||||
return 1;
|
||||
return Typeface.BOLD;
|
||||
case BOLD_ITALIC:
|
||||
return 3;
|
||||
return Typeface.BOLD_ITALIC;
|
||||
case ITALIC:
|
||||
return 2;
|
||||
return Typeface.ITALIC;
|
||||
case NORMAL:
|
||||
return 0;
|
||||
return Typeface.NORMAL;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("unknown font style: " + fontStyle);
|
||||
@@ -56,6 +59,8 @@ class AndroidPaint implements Paint {
|
||||
|
||||
final android.graphics.Paint mPaint;
|
||||
|
||||
private final Rect rect = new Rect();
|
||||
|
||||
AndroidPaint() {
|
||||
mPaint = new android.graphics.Paint(
|
||||
android.graphics.Paint.ANTI_ALIAS_FLAG);
|
||||
@@ -73,11 +78,16 @@ class AndroidPaint implements Paint {
|
||||
|
||||
@Override
|
||||
public void setStrokeCap(Cap cap) {
|
||||
android.graphics.Paint.Cap androidCap = android.graphics.Paint.Cap
|
||||
.valueOf(cap.name());
|
||||
android.graphics.Paint.Cap androidCap = android.graphics.Paint.Cap.valueOf(cap.name());
|
||||
mPaint.setStrokeCap(androidCap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStrokeJoin(Join join) {
|
||||
android.graphics.Paint.Join androidJoin = android.graphics.Paint.Join.valueOf(join.name());
|
||||
mPaint.setStrokeJoin(androidJoin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStrokeWidth(float width) {
|
||||
mPaint.setStrokeWidth(width);
|
||||
@@ -90,6 +100,7 @@ class AndroidPaint implements Paint {
|
||||
|
||||
@Override
|
||||
public void setTextAlign(Align align) {
|
||||
// Align text in text layer
|
||||
//mPaint.setTextAlign(android.graphics.Paint.Align.valueOf(align.name()));
|
||||
}
|
||||
|
||||
@@ -122,4 +133,15 @@ class AndroidPaint implements Paint {
|
||||
// //fontDescent = (float) Math.ceil(Math.abs(fm.descent));
|
||||
return Math.abs(fm.bottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTextHeight(String text) {
|
||||
mPaint.getTextBounds(text, 0, text.length(), rect);
|
||||
return rect.height();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTextWidth(String text) {
|
||||
return measureText(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -19,21 +20,30 @@ package org.oscim.awt;
|
||||
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.backend.canvas.Canvas;
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.backend.canvas.Paint;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Shape;
|
||||
import java.awt.font.TextLayout;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class AwtCanvas implements Canvas {
|
||||
|
||||
Graphics2D canvas;
|
||||
private static final java.awt.Color TRANSPARENT = new java.awt.Color(0, 0, 0, 0);
|
||||
|
||||
private BufferedImage bitmap;
|
||||
public Graphics2D canvas;
|
||||
|
||||
public AwtCanvas() {
|
||||
}
|
||||
|
||||
public AwtCanvas(BufferedImage bitmap) {
|
||||
this.bitmap = bitmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,26 +51,51 @@ public class AwtCanvas implements Canvas {
|
||||
if (canvas != null)
|
||||
canvas.dispose();
|
||||
|
||||
AwtBitmap awtBitamp = (AwtBitmap) bitmap;
|
||||
AwtBitmap awtBitmap = (AwtBitmap) bitmap;
|
||||
|
||||
canvas = awtBitamp.bitmap.createGraphics();
|
||||
this.bitmap = awtBitmap.bitmap;
|
||||
canvas = awtBitmap.bitmap.createGraphics();
|
||||
|
||||
canvas.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0));
|
||||
canvas.fillRect(0, 0, bitmap.getWidth(), bitmap.getHeight());
|
||||
|
||||
canvas.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
|
||||
|
||||
//canvas.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
|
||||
// RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
||||
canvas.setRenderingHint(RenderingHints.KEY_RENDERING,
|
||||
RenderingHints.VALUE_RENDER_QUALITY);
|
||||
canvas.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
canvas.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
canvas.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
canvas.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
||||
canvas.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
canvas.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
|
||||
}
|
||||
|
||||
private final AffineTransform tx = new AffineTransform();
|
||||
|
||||
@Override
|
||||
public void drawText(String text, float x, float y, Paint paint) {
|
||||
|
||||
AwtPaint awtPaint = (AwtPaint) paint;
|
||||
|
||||
if (awtPaint.stroke == null) {
|
||||
canvas.setColor(awtPaint.color);
|
||||
canvas.setFont(awtPaint.font);
|
||||
canvas.drawString(text, x, y);
|
||||
} else {
|
||||
canvas.setColor(awtPaint.color);
|
||||
canvas.setStroke(awtPaint.stroke);
|
||||
|
||||
TextLayout tl = new TextLayout(text, awtPaint.font,
|
||||
canvas.getFontRenderContext());
|
||||
tx.setToIdentity();
|
||||
tx.translate(x, y);
|
||||
|
||||
Shape s = tl.getOutline(tx);
|
||||
|
||||
canvas.draw(s);
|
||||
canvas.setColor(awtPaint.color);
|
||||
canvas.fill(s);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawText(String text, float x, float y, Paint fill, Paint stroke) {
|
||||
|
||||
@@ -69,7 +104,7 @@ public class AwtCanvas implements Canvas {
|
||||
if (stroke == null) {
|
||||
canvas.setColor(fillPaint.color);
|
||||
canvas.setFont(fillPaint.font);
|
||||
canvas.drawString(text, x + AwtPaint.TEXT_OFFSET, y);
|
||||
canvas.drawString(text, x, y);
|
||||
} else {
|
||||
AwtPaint strokePaint = (AwtPaint) stroke;
|
||||
|
||||
@@ -91,6 +126,35 @@ public class AwtCanvas implements Canvas {
|
||||
|
||||
@Override
|
||||
public void drawBitmap(Bitmap bitmap, float x, float y) {
|
||||
throw new UnknownError("not implemented");
|
||||
this.canvas.drawImage(((AwtBitmap) bitmap).bitmap, (int) x, (int) y, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLine(int x1, int y1, int x2, int y2, Paint paint) {
|
||||
AwtPaint awtPaint = (AwtPaint) paint;
|
||||
this.canvas.setColor(awtPaint.color);
|
||||
if (awtPaint.stroke != null)
|
||||
this.canvas.setStroke(awtPaint.stroke);
|
||||
this.canvas.drawLine(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillColor(int color) {
|
||||
java.awt.Color awtColor = color == Color.TRANSPARENT ? TRANSPARENT : new java.awt.Color(color);
|
||||
Composite originalComposite = this.canvas.getComposite();
|
||||
this.canvas.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
|
||||
this.canvas.setColor(awtColor);
|
||||
this.canvas.fillRect(0, 0, getWidth(), getHeight());
|
||||
this.canvas.setComposite(originalComposite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return this.bitmap != null ? this.bitmap.getHeight() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return this.bitmap != null ? this.bitmap.getWidth() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,10 +66,12 @@ public class AwtGraphics extends CanvasAdapter {
|
||||
static {
|
||||
image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
|
||||
canvas = image.createGraphics();
|
||||
canvas.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
//canvas.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
||||
//canvas.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
|
||||
canvas.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
canvas.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
canvas.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
||||
canvas.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
canvas.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
|
||||
}
|
||||
|
||||
static synchronized FontMetrics getFontMetrics(Font font) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -23,16 +24,16 @@ import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.font.TextAttribute;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.text.AttributedCharacterIterator.Attribute;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AwtPaint implements Paint {
|
||||
|
||||
final static float TEXT_OFFSET = 2;
|
||||
|
||||
private static int getCap(Cap cap) {
|
||||
switch (cap) {
|
||||
case BUTT:
|
||||
@@ -46,10 +47,54 @@ public class AwtPaint implements Paint {
|
||||
throw new IllegalArgumentException("unknown cap: " + cap);
|
||||
}
|
||||
|
||||
private static String getFontName(FontFamily fontFamily) {
|
||||
switch (fontFamily) {
|
||||
case MONOSPACE:
|
||||
return Font.MONOSPACED;
|
||||
case DEFAULT:
|
||||
case DEFAULT_BOLD:
|
||||
return null;
|
||||
case SANS_SERIF:
|
||||
return Font.SANS_SERIF;
|
||||
case SERIF:
|
||||
return Font.SERIF;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("unknown fontFamily: " + fontFamily);
|
||||
}
|
||||
|
||||
private static int getFontStyle(FontStyle fontStyle) {
|
||||
switch (fontStyle) {
|
||||
case BOLD:
|
||||
return Font.BOLD;
|
||||
case BOLD_ITALIC:
|
||||
return Font.BOLD | Font.ITALIC;
|
||||
case ITALIC:
|
||||
return Font.ITALIC;
|
||||
case NORMAL:
|
||||
return Font.PLAIN;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("unknown fontStyle: " + fontStyle);
|
||||
}
|
||||
|
||||
private static int getJoin(Join join) {
|
||||
switch (join) {
|
||||
case ROUND:
|
||||
return BasicStroke.JOIN_ROUND;
|
||||
case BEVEL:
|
||||
return BasicStroke.JOIN_BEVEL;
|
||||
case MITER:
|
||||
return BasicStroke.JOIN_MITER;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("unknown cap: " + join);
|
||||
}
|
||||
|
||||
static final Font defaultFont;
|
||||
|
||||
static {
|
||||
Map<Attribute, Object> textAttributes = new HashMap<Attribute, Object>();
|
||||
Map<Attribute, Object> textAttributes = new HashMap<>();
|
||||
textAttributes.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
|
||||
textAttributes.put(TextAttribute.FAMILY, "Arial");
|
||||
textAttributes.put(TextAttribute.SIZE, 14);
|
||||
@@ -57,15 +102,19 @@ public class AwtPaint implements Paint {
|
||||
defaultFont = Font.getFont(textAttributes);
|
||||
}
|
||||
|
||||
Color color = new Color(0.1f, 0.1f, 0.1f, 1);
|
||||
FontMetrics fm;
|
||||
Font font = defaultFont; // new Font("Default", Font.PLAIN, 13);
|
||||
Stroke stroke;
|
||||
FontMetrics fm;
|
||||
Color color = new Color(0.1f, 0.1f, 0.1f, 1);
|
||||
|
||||
private int cap;
|
||||
Style style = Style.FILL;
|
||||
private int cap = getCap(Cap.BUTT);
|
||||
private String fontName = defaultFont.getFontName();
|
||||
private int fontStyle = defaultFont.getStyle();
|
||||
private int join = getJoin(Join.MITER);
|
||||
private float strokeWidth;
|
||||
private float textSize = defaultFont.getSize();
|
||||
|
||||
//private Align mAlign;
|
||||
private final BufferedImage bufferedImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
@@ -86,39 +135,45 @@ public class AwtPaint implements Paint {
|
||||
createStroke();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStrokeJoin(Join join) {
|
||||
this.join = getJoin(join);
|
||||
createStroke();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStrokeWidth(float width) {
|
||||
strokeWidth = width + 1;
|
||||
strokeWidth = width;
|
||||
createStroke();
|
||||
|
||||
// int size = font.getSize();
|
||||
// font = font.deriveFont(size + width * 4);
|
||||
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStyle(Style style) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTextAlign(Align align) {
|
||||
//mAlign = align;
|
||||
// Align text in text layer
|
||||
//this.align = align;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTextSize(float textSize) {
|
||||
font = font.deriveFont(textSize);
|
||||
|
||||
this.textSize = textSize;
|
||||
this.font = this.font.deriveFont(textSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTypeface(FontFamily fontFamily, FontStyle fontStyle) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
this.fontName = getFontName(fontFamily);
|
||||
this.fontStyle = getFontStyle(fontStyle);
|
||||
Map<Attribute, Object> textAttributes = new HashMap<>();
|
||||
textAttributes.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
|
||||
this.font = new Font(this.fontName, this.fontStyle, (int) this.textSize).deriveFont(textAttributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -158,6 +213,22 @@ public class AwtPaint implements Paint {
|
||||
if (strokeWidth <= 0) {
|
||||
return;
|
||||
}
|
||||
stroke = new BasicStroke(strokeWidth, cap, BasicStroke.JOIN_MITER, 1, null, 0);
|
||||
stroke = new BasicStroke(strokeWidth, cap, join, join == BasicStroke.JOIN_MITER ? 1.0f : 0, null, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTextHeight(String text) {
|
||||
Graphics2D graphics2d = bufferedImage.createGraphics();
|
||||
FontMetrics fontMetrics = graphics2d.getFontMetrics(this.font);
|
||||
graphics2d.dispose();
|
||||
return (float) this.font.createGlyphVector(fontMetrics.getFontRenderContext(), text).getVisualBounds().getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTextWidth(String text) {
|
||||
Graphics2D graphics2d = bufferedImage.createGraphics();
|
||||
FontMetrics fontMetrics = graphics2d.getFontMetrics(this.font);
|
||||
graphics2d.dispose();
|
||||
return fontMetrics.stringWidth(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2016 Longri
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* 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
|
||||
@@ -19,16 +20,12 @@ import org.oscim.backend.canvas.Canvas;
|
||||
import org.oscim.backend.canvas.Paint;
|
||||
import org.robovm.apple.coregraphics.CGBitmapContext;
|
||||
import org.robovm.apple.coregraphics.CGRect;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* iOS specific implementation of {@link Canvas}.
|
||||
*/
|
||||
public class IosCanvas implements Canvas {
|
||||
|
||||
static final Logger log = LoggerFactory.getLogger(IosCanvas.class);
|
||||
|
||||
CGBitmapContext cgBitmapContext;
|
||||
|
||||
@Override
|
||||
@@ -36,6 +33,16 @@ public class IosCanvas implements Canvas {
|
||||
cgBitmapContext = ((IosBitmap) bitmap).cgBitmapContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawText(String string, float x, float y, Paint paint) {
|
||||
|
||||
//flip Y-axis
|
||||
y = this.cgBitmapContext.getHeight() - y;
|
||||
|
||||
IosPaint iosPaint = (IosPaint) paint;
|
||||
iosPaint.drawLine(this.cgBitmapContext, string, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawText(String string, float x, float y, Paint fill, Paint stroke) {
|
||||
|
||||
@@ -59,4 +66,24 @@ public class IosCanvas implements Canvas {
|
||||
((IosBitmap) bitmap).cgBitmapContext.toImage());
|
||||
this.cgBitmapContext.restoreGState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLine(int x1, int y1, int x2, int y2, Paint paint) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillColor(int color) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return this.cgBitmapContext != null ? (int) this.cgBitmapContext.getHeight() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return this.cgBitmapContext != null ? (int) this.cgBitmapContext.getWidth() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2016 Longri
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* 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
|
||||
@@ -19,6 +20,7 @@ import org.robovm.apple.coregraphics.CGAffineTransform;
|
||||
import org.robovm.apple.coregraphics.CGBitmapContext;
|
||||
import org.robovm.apple.coregraphics.CGBlendMode;
|
||||
import org.robovm.apple.coregraphics.CGLineCap;
|
||||
import org.robovm.apple.coregraphics.CGLineJoin;
|
||||
import org.robovm.apple.coretext.CTFont;
|
||||
import org.robovm.apple.coretext.CTLine;
|
||||
import org.robovm.apple.foundation.NSAttributedString;
|
||||
@@ -26,8 +28,6 @@ import org.robovm.apple.uikit.NSAttributedStringAttributes;
|
||||
import org.robovm.apple.uikit.UIColor;
|
||||
import org.robovm.apple.uikit.UIFont;
|
||||
import org.robovm.apple.uikit.UIFontWeight;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -35,7 +35,30 @@ import java.util.HashMap;
|
||||
* iOS specific implementation of {@link Paint}.
|
||||
*/
|
||||
public class IosPaint implements Paint {
|
||||
private static final Logger log = LoggerFactory.getLogger(IosPaint.class);
|
||||
|
||||
private static CGLineCap getLineCap(Cap cap) {
|
||||
switch (cap) {
|
||||
case BUTT:
|
||||
return CGLineCap.Butt;
|
||||
case ROUND:
|
||||
return CGLineCap.Round;
|
||||
case SQUARE:
|
||||
return CGLineCap.Square;
|
||||
}
|
||||
return CGLineCap.Butt;
|
||||
}
|
||||
|
||||
private static CGLineJoin getLineJoin(Join join) {
|
||||
switch (join) {
|
||||
case MITER:
|
||||
return CGLineJoin.Miter;
|
||||
case ROUND:
|
||||
return CGLineJoin.Round;
|
||||
case BEVEL:
|
||||
return CGLineJoin.Bevel;
|
||||
}
|
||||
return CGLineJoin.Miter;
|
||||
}
|
||||
|
||||
private static final String DEFAULT_FONT_NAME = UIFont.getSystemFont(1, UIFontWeight.Semibold).getFontDescriptor().getPostscriptName();
|
||||
private static final String DEFAULT_FONT_NAME_BOLD = UIFont.getSystemFont(1, UIFontWeight.Bold).getFontDescriptor().getPostscriptName();
|
||||
@@ -43,6 +66,7 @@ public class IosPaint implements Paint {
|
||||
|
||||
private final NSAttributedStringAttributes attribs = new NSAttributedStringAttributes();
|
||||
private CGLineCap cap = CGLineCap.Butt;
|
||||
private CGLineJoin join = CGLineJoin.Miter;
|
||||
private Style style;
|
||||
private float textSize;
|
||||
private FontFamily fontFamily;
|
||||
@@ -95,6 +119,10 @@ public class IosPaint implements Paint {
|
||||
this.cap = getLineCap(cap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStrokeJoin(Join join) {
|
||||
this.join = getLineJoin(join);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStrokeWidth(float width) {
|
||||
@@ -110,7 +138,8 @@ public class IosPaint implements Paint {
|
||||
|
||||
@Override
|
||||
public void setTextAlign(Align align) {
|
||||
// TODO: set Align
|
||||
// Align text in text layer
|
||||
//this.align = align;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -306,15 +335,14 @@ public class IosPaint implements Paint {
|
||||
return descent;
|
||||
}
|
||||
|
||||
private CGLineCap getLineCap(Cap cap) {
|
||||
switch (cap) {
|
||||
case BUTT:
|
||||
return CGLineCap.Butt;
|
||||
case ROUND:
|
||||
return CGLineCap.Round;
|
||||
case SQUARE:
|
||||
return CGLineCap.Square;
|
||||
}
|
||||
return CGLineCap.Butt;
|
||||
@Override
|
||||
public float getTextHeight(String text) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTextWidth(String text) {
|
||||
return measureText(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -38,6 +39,31 @@ public class GwtCanvas implements org.oscim.backend.canvas.Canvas {
|
||||
ctx.setLineJoin(LineJoin.BEVEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawText(String string, float x, float y, Paint paint) {
|
||||
if (bitmap == null) {
|
||||
//log.debug("no bitmap set");
|
||||
return;
|
||||
}
|
||||
|
||||
GwtPaint p = (GwtPaint) paint;
|
||||
|
||||
if (p.stroke && GwtGdxGraphics.NO_STROKE_TEXT)
|
||||
return;
|
||||
|
||||
Context2d ctx = bitmap.pixmap.getContext();
|
||||
ctx.setFont(p.font);
|
||||
|
||||
if (p.stroke) {
|
||||
ctx.setLineWidth(p.strokeWidth);
|
||||
ctx.setStrokeStyle(p.color);
|
||||
ctx.strokeText(string, (int) (x + 1), (int) (y + 1));
|
||||
} else {
|
||||
ctx.setFillStyle(p.color);
|
||||
ctx.fillText(string, (int) (x + 1), (int) (y + 1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawText(String string, float x, float y, Paint fill, Paint stroke) {
|
||||
if (bitmap == null) {
|
||||
@@ -65,5 +91,26 @@ public class GwtCanvas implements org.oscim.backend.canvas.Canvas {
|
||||
|
||||
@Override
|
||||
public void drawBitmap(Bitmap bitmap, float x, float y) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLine(int x1, int y1, int x2, int y2, Paint paint) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillColor(int color) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return this.bitmap != null ? this.bitmap.getHeight() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return this.bitmap != null ? this.bitmap.getWidth() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -26,7 +27,6 @@ public class GwtPaint implements Paint {
|
||||
boolean stroke;
|
||||
|
||||
float strokeWidth;
|
||||
Align mAlign;
|
||||
|
||||
float fontSize = 12;
|
||||
|
||||
@@ -36,8 +36,6 @@ public class GwtPaint implements Paint {
|
||||
//String font = "12px sans-serif";
|
||||
String font = "13px Helvetica";
|
||||
|
||||
//private int cap;
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
return 0;
|
||||
@@ -58,6 +56,11 @@ public class GwtPaint implements Paint {
|
||||
stroke = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStrokeJoin(Join join) {
|
||||
stroke = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStrokeWidth(float width) {
|
||||
stroke = true;
|
||||
@@ -66,11 +69,13 @@ public class GwtPaint implements Paint {
|
||||
|
||||
@Override
|
||||
public void setStyle(Style style) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTextAlign(Align align) {
|
||||
mAlign = align;
|
||||
// Align text in text layer
|
||||
//this.align = align;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,4 +123,15 @@ public class GwtPaint implements Paint {
|
||||
this.font = sb.toString();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTextHeight(String text) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTextWidth(String text) {
|
||||
return measureText(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -14,7 +15,6 @@
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oscim.backend.canvas;
|
||||
|
||||
/**
|
||||
@@ -24,29 +24,29 @@ public interface Canvas {
|
||||
|
||||
/**
|
||||
* Sets the backing {@link Bitmap}.
|
||||
*
|
||||
* @param bitmap the new bitmap
|
||||
*/
|
||||
void setBitmap(Bitmap bitmap);
|
||||
|
||||
/**
|
||||
* Draw text to Canvas.
|
||||
*
|
||||
* @param string the String
|
||||
* @param x
|
||||
* @param y
|
||||
* @param stroke the stroke
|
||||
* @param
|
||||
*/
|
||||
void drawText(String string, float x, float y, Paint paint);
|
||||
|
||||
/**
|
||||
* Draw text to Canvas.
|
||||
*/
|
||||
void drawText(String string, float x, float y, Paint fill, Paint stroke);
|
||||
|
||||
/**
|
||||
* Draw Bitmap to Canvas.
|
||||
*
|
||||
* @param bitmap the Bitmap
|
||||
* @param x
|
||||
* @param y
|
||||
*/
|
||||
void drawBitmap(Bitmap bitmap, float x, float y);
|
||||
|
||||
void drawLine(int x1, int y1, int x2, int y2, Paint paint);
|
||||
|
||||
void fillColor(int color);
|
||||
|
||||
int getHeight();
|
||||
|
||||
int getWidth();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -22,24 +23,28 @@ package org.oscim.backend.canvas;
|
||||
*/
|
||||
public interface Paint {
|
||||
|
||||
public static enum Align {
|
||||
CENTER, LEFT, RIGHT;
|
||||
enum Align {
|
||||
CENTER, LEFT, RIGHT
|
||||
}
|
||||
|
||||
public enum Cap {
|
||||
BUTT, ROUND, SQUARE;
|
||||
enum Cap {
|
||||
BUTT, ROUND, SQUARE
|
||||
}
|
||||
|
||||
public enum Style {
|
||||
enum Join {
|
||||
MITER, ROUND, BEVEL
|
||||
}
|
||||
|
||||
enum Style {
|
||||
FILL, STROKE
|
||||
}
|
||||
|
||||
public enum FontFamily {
|
||||
DEFAULT, DEFAULT_BOLD, MONOSPACE, SANS_SERIF, SERIF;
|
||||
enum FontFamily {
|
||||
DEFAULT, DEFAULT_BOLD, MONOSPACE, SANS_SERIF, SERIF
|
||||
}
|
||||
|
||||
public enum FontStyle {
|
||||
BOLD, BOLD_ITALIC, ITALIC, NORMAL;
|
||||
enum FontStyle {
|
||||
BOLD, BOLD_ITALIC, ITALIC, NORMAL
|
||||
}
|
||||
|
||||
int getColor();
|
||||
@@ -48,6 +53,8 @@ public interface Paint {
|
||||
|
||||
void setStrokeCap(Cap cap);
|
||||
|
||||
void setStrokeJoin(Join join);
|
||||
|
||||
void setStrokeWidth(float width);
|
||||
|
||||
void setStyle(Style style);
|
||||
@@ -63,4 +70,8 @@ public interface Paint {
|
||||
float getFontHeight();
|
||||
|
||||
float getFontDescent();
|
||||
|
||||
float getTextHeight(String text);
|
||||
|
||||
float getTextWidth(String text);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user