more work on overlay renderer:

- moved text rendering to overlay
- added grid overlay
This commit is contained in:
Hannes Janetzek
2012-10-13 04:57:27 +02:00
parent 33d8865d7b
commit 4a06553ddc
33 changed files with 2050 additions and 1089 deletions

View File

@@ -17,6 +17,7 @@ package org.oscim.theme.renderinstruction;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback;
import org.oscim.theme.RenderThemeHandler;
import org.oscim.utils.GlUtils;
import org.xml.sax.Attributes;
import android.graphics.Color;
@@ -88,11 +89,7 @@ public final class Area extends RenderInstruction {
blend = -1;
strokeWidth = 0;
color = new float[4];
color[3] = (fill >> 24 & 0xff) / 255.0f;
color[0] = (fill >> 16 & 0xff) / 255.0f * color[3];
color[1] = (fill >> 8 & 0xff) / 255.0f * color[3];
color[2] = (fill >> 0 & 0xff) / 255.0f * color[3];
color = GlUtils.colorToFloatP(fill);
}
/**
@@ -128,41 +125,13 @@ public final class Area extends RenderInstruction {
// Shader shader = BitmapUtils.createBitmapShader(src);
// paintFill.setShader(shader);
// }
// paintFill.setStyle(Style.FILL);
// paintFill.setColor(fill);
// paintFill.setStrokeCap(Cap.ROUND);
// }
//
// if (stroke == Color.TRANSPARENT) {
// paintOutline = null;
// } else {
// paintOutline = new Paint(Paint.ANTI_ALIAS_FLAG);
// paintOutline.setStyle(Style.STROKE);
// paintOutline.setColor(stroke);
// paintOutline.setStrokeCap(Cap.ROUND);
// }
// if (stroke == Color.TRANSPARENT) {
// stroke = null;
// } else{
// stroke = new Line()
// }
color = GlUtils.colorToFloatP(fill);
color = new float[4];
color[3] = (fill >> 24 & 0xff) / 255.0f;
color[0] = (fill >> 16 & 0xff) / 255.0f * color[3];
color[1] = (fill >> 8 & 0xff) / 255.0f * color[3];
color[2] = (fill >> 0 & 0xff) / 255.0f * color[3];
if (blend > 0) {
blendColor = new float[4];
blendColor[3] = (blendFill >> 24 & 0xff) / 255.0f;
blendColor[0] = (blendFill >> 16 & 0xff) / 255.0f * blendColor[3];
blendColor[1] = (blendFill >> 8 & 0xff) / 255.0f * blendColor[3];
blendColor[2] = (blendFill >> 0 & 0xff) / 255.0f * blendColor[3];
} else {
if (blend > 0)
blendColor = GlUtils.colorToFloatP(blendFill);
else
blendColor = null;
}
this.blend = blend;
this.strokeWidth = strokeWidth;
@@ -183,32 +152,10 @@ public final class Area extends RenderInstruction {
// }
public String style;
/**
*
*/
private final int level;
/**
*
*/
// public final Paint paintFill;
/**
*
*/
// public final Paint paintOutline;
/**
*
*/
public final float strokeWidth;
/**
*
*/
public final float color[];
/**
*
*/
public final int fade;
public final float blendColor[];
public final int blend;
}

View File

@@ -20,6 +20,7 @@ import java.util.regex.Pattern;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback;
import org.oscim.theme.RenderThemeHandler;
import org.oscim.utils.GlUtils;
import org.xml.sax.Attributes;
import android.graphics.Color;
@@ -121,11 +122,7 @@ public final class Line extends RenderInstruction {
this.fixed = true;
this.fade = -1;
this.stipple = 2;
color = new float[4];
color[3] = (stroke >> 24 & 0xff) / 255.0f;
color[0] = (stroke >> 16 & 0xff) / 255.0f * color[3];
color[1] = (stroke >> 8 & 0xff) / 255.0f * color[3];
color[2] = (stroke >> 0 & 0xff) / 255.0f * color[3];
color = GlUtils.colorToFloatP(stroke);
}
private static void validate(float strokeWidth) {
@@ -215,11 +212,7 @@ public final class Line extends RenderInstruction {
this.cap = strokeLinecap;
color = new float[4];
color[3] = (stroke >> 24 & 0xff) / 255.0f;
color[0] = (stroke >> 16 & 0xff) / 255.0f * color[3];
color[1] = (stroke >> 8 & 0xff) / 255.0f * color[3];
color[2] = (stroke >> 0 & 0xff) / 255.0f * color[3];
color = GlUtils.colorToFloatP(stroke);
this.width = strokeWidth;
this.level = level;

View File

@@ -53,6 +53,7 @@ public final class Text extends RenderInstruction {
String style = null;
// boolean caption = false;
float dy = 0;
for (int i = 0; i < attributes.getLength(); ++i) {
String name = attributes.getLocalName(i);
String value = attributes.getValue(i);
@@ -82,10 +83,27 @@ public final class Text extends RenderInstruction {
}
validate(elementName, textKey, fontSize, strokeWidth);
Typeface typeface = Typeface.create(fontFamily.toTypeface(), fontStyle.toInt());
Typeface typeface = null;
if (fontFamily == FontFamily.DEFAULT) {
if (fontStyle == FontStyle.NORMAL)
typeface = typefaceNormal;
else if (fontStyle == FontStyle.BOLD)
typeface = typefaceBold;
}
if (typeface == null)
typeface = Typeface.create(fontFamily.toTypeface(), fontStyle.toInt());
return new Text(style, textKey, typeface, fontSize, fill, stroke, strokeWidth, dy, caption);
}
private static Typeface typefaceNormal = Typeface.create(FontFamily.DEFAULT.toTypeface(),
FontStyle.NORMAL.toInt());
private static Typeface typefaceBold = Typeface.create(FontFamily.DEFAULT.toTypeface(),
FontStyle.BOLD.toInt());
private static void validate(String elementName, String textKey, float fontSize,
float strokeWidth) {
if (textKey == null) {
@@ -110,9 +128,15 @@ public final class Text extends RenderInstruction {
public final boolean caption;
public final float dy;
public static Text createText(float fontSize, float strokeWidth, int fill, int outline,
boolean billboard) {
return new Text("", "", typefaceNormal, fontSize, fill, outline, strokeWidth, 0, billboard);
}
private Text(String style, String textKey, Typeface typeface, float fontSize,
int fill, int outline, float strokeWidth, float dy, boolean caption) {
super();
// super();
this.style = style;
this.textKey = textKey;
@@ -123,19 +147,21 @@ public final class Text extends RenderInstruction {
paint.setTextAlign(Align.CENTER);
paint.setTypeface(typeface);
paint.setColor(fill);
paint.setTextSize(fontSize);
stroke = new Paint(Paint.ANTI_ALIAS_FLAG);
stroke.setStyle(Style.STROKE);
stroke.setTextAlign(Align.CENTER);
stroke.setTypeface(typeface);
stroke.setColor(outline);
stroke.setStrokeWidth(strokeWidth);
if (strokeWidth > 0) {
stroke = new Paint(Paint.ANTI_ALIAS_FLAG);
stroke.setStyle(Style.STROKE);
stroke.setTextAlign(Align.CENTER);
stroke.setTypeface(typeface);
stroke.setColor(outline);
stroke.setStrokeWidth(strokeWidth);
stroke.setTextSize(fontSize);
} else
stroke = null;
this.fontSize = fontSize;
paint.setTextSize(fontSize);
stroke.setTextSize(fontSize);
FontMetrics fm = paint.getFontMetrics();
fontHeight = FloatMath.ceil(Math.abs(fm.bottom) + Math.abs(fm.top));
fontDescent = FloatMath.ceil(Math.abs(fm.descent));