fix rendering issues

git-svn-id: https://osmand.googlecode.com/svn/trunk@683 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-11-21 21:28:30 +00:00
parent ab9f6a46bd
commit f02c68e6f9
3 changed files with 154 additions and 81 deletions

View file

@ -67,8 +67,9 @@ public class OsmandRenderingRulesParser {
public TextAttributes text = null;
public List<EffectAttributes> effectAttributes = new ArrayList<EffectAttributes>(3);
protected EffectAttributes getEffectAttributes(int i){
while(i >= effectAttributes.size()){
protected EffectAttributes getEffectAttributes(int i) {
i -= 2;
while (i >= effectAttributes.size()) {
effectAttributes.add(new EffectAttributes());
}
return effectAttributes.get(i);
@ -240,6 +241,10 @@ public class OsmandRenderingRulesParser {
mergeInto.text.textShield = toMerge.text.textShield;
}
if(toMerge.text.ref != null && mergeInto.text.ref == null){
mergeInto.text.ref = toMerge.text.ref;
}
if(toMerge.text.textMinDistance != 0 && mergeInto.text.textMinDistance == 0){
mergeInto.text.textMinDistance = toMerge.text.textMinDistance;
}
@ -447,17 +452,31 @@ public class OsmandRenderingRulesParser {
if(s.shader != null){
res+=" shader=" + s.shader; //$NON-NLS-1$
}
if(s.main.color != 0){
res +=" color="+colorToString(s.main.color); //$NON-NLS-1$
}
if(s.icon != null){
res+= " icon="+s.icon; //$NON-NLS-1$
}
if(s.main.strokeWidth != 0){
res+= " strokeWidth="+s.main.strokeWidth; //$NON-NLS-1$
res = generateAttributes(s.main, res, "");
int p = 2;
for(EffectAttributes ef : s.effectAttributes){
res = generateAttributes(ef, res, "_"+(p++));
}
if(s.main.pathEffect != null){
res+= " pathEffect="+s.main.pathEffect; //$NON-NLS-1$
if(s.text != null){
if(s.text.textSize != 0){
res+= " textSize="+s.text.textSize; //$NON-NLS-1$
}
if(s.text.ref != null){
res+= " ref="+s.text.ref; //$NON-NLS-1$
}
if(s.text.textColor != 0){
res+= " textColor="+colorToString(s.text.textColor); //$NON-NLS-1$
}
if(s.text.textShield != null){
res+= " textShield="+s.text.textShield; //$NON-NLS-1$
}
}
if(state == POLYGON_STATE){
// return res;
@ -470,4 +489,18 @@ public class OsmandRenderingRulesParser {
}
return null;
}
private static String generateAttributes(EffectAttributes s, String res, String prefix) {
if(s.color != 0){
res +=" color"+prefix+"="+colorToString(s.color); //$NON-NLS-1$
}
if(s.strokeWidth != 0){
res+= " strokeWidth"+prefix+"="+s.strokeWidth; //$NON-NLS-1$
}
if(s.pathEffect != null){
res+= " pathEffect"+prefix+"="+s.pathEffect; //$NON-NLS-1$
}
return res;
}
}

View file

@ -104,42 +104,53 @@ public class BaseOsmandRender implements RenderingRuleVisitor {
return null;
}
// TODO layer
public boolean renderPolyline(String tag, String val, int zoom, RenderingContext rc, OsmandRenderer o){
boolean r = renderPolylineImpl(tag,val, zoom, rc, o);
public boolean renderPolyline(String tag, String val, int zoom, RenderingContext rc, OsmandRenderer o, int layer){
boolean r = renderPolylineImpl(tag,val, zoom, rc, o, layer);
if(!r){
return renderPolylineImpl(tag, null, zoom, rc, o);
return renderPolylineImpl(tag, null, zoom, rc, o, layer);
}
return r;
}
private boolean renderPolylineImpl(String tag, String val, int zoom, RenderingContext rc, OsmandRenderer o) {
private boolean renderPolylineImpl(String tag, String val, int zoom, RenderingContext rc, OsmandRenderer o, int layer) {
Map<String, List<FilterState>> map = rules[OsmandRenderingRulesParser.LINE_STATE].get(tag);
if (map != null) {
List<FilterState> list = map.get(val);
if (list != null) {
FilterState found = null;
for (FilterState f : list) {
// TODO layer!!!
if (f.minzoom <= zoom && (zoom <= f.maxzoom || f.maxzoom == -1) && f.layer == 0) {
// to not make transparent
rc.main.color = Color.BLACK;
if(f.shader != null){
Integer i = RenderingIcons.getIcons().get(f.shader);
if(i != null){
rc.main.shader = o.getShader(i);
}
}
rc.main.fillArea = false;
applyEffectAttributes(f.main, rc.main, o);
if(f.effectAttributes.size() > 0){
applyEffectAttributes(f.effectAttributes.get(0), rc.second, o);
if(f.effectAttributes.size() > 1){
applyEffectAttributes(f.effectAttributes.get(1), rc.third, o);
}
}
return true;
if (f.minzoom <= zoom && (zoom <= f.maxzoom || f.maxzoom == -1) && f.layer == layer) {
found = f;
break;
}
}
if (found == null) {
for (FilterState f : list) {
if (f.minzoom <= zoom && (zoom <= f.maxzoom || f.maxzoom == -1) && f.layer == 0) {
found = f;
break;
}
}
}
if (found != null) {
// to not make transparent
rc.main.color = Color.BLACK;
if (found.shader != null) {
Integer i = RenderingIcons.getIcons().get(found.shader);
if (i != null) {
rc.main.shader = o.getShader(i);
}
}
rc.main.fillArea = false;
applyEffectAttributes(found.main, rc.main, o);
if (found.effectAttributes.size() > 0) {
applyEffectAttributes(found.effectAttributes.get(0), rc.second, o);
if (found.effectAttributes.size() > 1) {
applyEffectAttributes(found.effectAttributes.get(1), rc.third, o);
}
}
return true;
}
}
}
return false;
@ -204,25 +215,33 @@ public class BaseOsmandRender implements RenderingRuleVisitor {
}
}
public String renderObjectText(String name, String tag, String val, RenderingContext rc) {
public String renderObjectText(String name, String tag, String val, RenderingContext rc, boolean ref) {
if(name == null || name.length() == 0){
return null;
}
String ret = renderObjectTextImpl(name, tag, val, rc);
String ret = renderObjectTextImpl(name, tag, val, rc, ref);
if(rc.textSize > 0){
return ret;
}
return renderObjectTextImpl(name, tag, null, rc);
return renderObjectTextImpl(name, tag, null, rc, ref);
}
private boolean checkRefTextRule(FilterState f, boolean ref){
if(ref){
return f.text != null && f.text.ref != null;
} else {
return f.text == null || f.text.ref == null || "true".equals(f.text.ref); //$NON-NLS-1$
}
}
private String renderObjectTextImpl(String name, String tag, String val, RenderingContext rc) {
private String renderObjectTextImpl(String name, String tag, String val, RenderingContext rc, boolean ref) {
Map<String, List<FilterState>> map = rules[OsmandRenderingRulesParser.TEXT_STATE].get(tag);
if (map != null) {
List<FilterState> list = map.get(val);
if (list != null) {
// first find rule with same text length
for (FilterState f : list) {
if (f.minzoom <= rc.zoom && (rc.zoom <= f.maxzoom || f.maxzoom == -1)) {
if (f.minzoom <= rc.zoom && (rc.zoom <= f.maxzoom || f.maxzoom == -1) && checkRefTextRule(f, ref)) {
if(f.textLength == name.length() && f.text.textSize > 0){
fillTextProperties(f, rc);
return name;
@ -231,7 +250,7 @@ public class BaseOsmandRender implements RenderingRuleVisitor {
}
for (FilterState f : list) {
if (f.minzoom <= rc.zoom && (rc.zoom <= f.maxzoom || f.maxzoom == -1)) {
if (f.minzoom <= rc.zoom && (rc.zoom <= f.maxzoom || f.maxzoom == -1) && checkRefTextRule(f, ref)) {
if(f.textLength == 0 && f.text.textSize > 0){
fillTextProperties(f, rc);
return name;
@ -245,7 +264,7 @@ public class BaseOsmandRender implements RenderingRuleVisitor {
private void fillTextProperties(FilterState f, RenderingContext rc) {
rc.textSize = f.text.textSize;
rc.textColor = f.text.textColor;
rc.textColor = f.text.textColor == 0 ? Color.BLACK : f.text.textColor;
rc.textSize = f.text.textSize;
rc.textMinDistance = f.text.textMinDistance;
rc.showTextOnPath = f.text.textOnPath;

View file

@ -605,7 +605,7 @@ public class OsmandRenderer {
String name = ((MultyPolygon) obj).getName(i);
if (name != null) {
rc.clearText();
name = render.renderObjectText(name, tag, value, rc);
name = render.renderObjectText(name, tag, value, rc, false);
if (rc.textSize > 0 && name != null) {
TextDrawInfo info = new TextDrawInfo(name);
info.fillProperties(rc, xText / cnt, yText / cnt);
@ -671,7 +671,7 @@ public class OsmandRenderer {
String name = obj.getName();
if(name != null){
rc.clearText();
name = render.renderObjectText(name, pair.tag, pair.value, rc);
name = render.renderObjectText(name, pair.tag, pair.value, rc, false);
if (rc.textSize > 0 && name != null) {
TextDrawInfo info = new TextDrawInfo(name);
info.fillProperties(rc, xText, yText);
@ -694,7 +694,7 @@ public class OsmandRenderer {
name = obj.getName();
if (name != null) {
rc.clearText();
name = render.renderObjectText(name, pair.tag, pair.value, rc);
name = render.renderObjectText(name, pair.tag, pair.value, rc, false);
}
}
if(resId == null && name == null){
@ -739,20 +739,20 @@ public class OsmandRenderer {
if(render == null || pair == null){
return;
}
render.renderPolyline(pair.tag, pair.value, rc.zoom, rc, this);
int layer = MapRenderingTypes.getNegativeWayLayer(wholeType);
render.renderPolyline(pair.tag, pair.value, rc.zoom, rc, this, layer);
if(rc.main.strokeWidth == 0){
return;
}
int length = obj.getPointsLength();
if(length < 2){
return;
}
if("highway".equals(pair.tag) && rc.zoom >= 16 && MapRenderingTypes.isOneWayWay(obj.getHighwayAttributes())){ //$NON-NLS-1$
rc.adds = PolylineRenderer.getOneWayProperties();
}
int length = obj.getPointsLength();
if(length < 2){
return;
}
rc.visible++;
Path path = null;
@ -815,44 +815,65 @@ public class OsmandRenderer {
}
if (obj.getName() != null) {
String name = obj.getName();
rc.clearText();
name = TextRenderer.renderObjectText(name, subtype, type, rc.zoom, false, rc);
if(rc.textSize == 0 && rc.showAnotherText != null){
name = TextRenderer.renderObjectText(rc.showAnotherText, subtype, type, rc.zoom, false, rc);
}
if (name != null && rc.textSize > 0) {
if (!rc.showTextOnPath) {
TextDrawInfo text = new TextDrawInfo(name);
text.fillProperties(rc, middlePoint.x, middlePoint.y);
rc.textToDraw.add(text);
}
if(rc.showAnotherText != null){
name = TextRenderer.renderObjectText(rc.showAnotherText, subtype, type, rc.zoom, false, rc);
String ref = null;
if(name.charAt(0) == MapRenderingTypes.REF_CHAR){
ref = name.substring(1);
name = ""; //$NON-NLS-1$
for(int k = 0; k < ref.length(); k++){
if(ref.charAt(k) == MapRenderingTypes.REF_CHAR){
if(k < ref.length() - 1){
name = ref.substring(k + 1);
}
ref = ref.substring(0, k);
break;
}
}
}
if(ref != null){
rc.clearText();
ref = render.renderObjectText(ref, pair.tag, pair.value, rc, true);
TextDrawInfo text = new TextDrawInfo(ref);
if(!rc.showTextOnPath){
text.fillProperties(rc, middlePoint.x, middlePoint.y);
} else {
// TODO
}
rc.textToDraw.add(text);
if (rc.showTextOnPath && paintText.measureText(obj.getName()) < Math.max(Math.abs(xLength), Math.abs(yLength))) {
if (inverse) {
path.rewind();
boolean st = true;
for (int i = obj.getPointsLength() - 1; i >= 0; i--) {
PointF p = calcPoint(obj, i, rc);
if (st) {
st = false;
path.moveTo(p.x, p.y);
} else {
path.lineTo(p.x, p.y);
}
if(name != null && name.length() > 0){
rc.clearText();
name = render.renderObjectText(name, pair.tag, pair.value, rc, false);
if (rc.textSize > 0) {
TextDrawInfo text = new TextDrawInfo(name);
if (!rc.showTextOnPath) {
text.fillProperties(rc, middlePoint.x, middlePoint.y);
rc.textToDraw.add(text);
} else {
if (paintText.measureText(obj.getName()) < Math.max(Math.abs(xLength), Math.abs(yLength))) {
if (inverse) {
path.rewind();
boolean st = true;
for (int i = obj.getPointsLength() - 1; i >= 0; i--) {
PointF p = calcPoint(obj, i, rc);
if (st) {
st = false;
path.moveTo(p.x, p.y);
} else {
path.lineTo(p.x, p.y);
}
}
}
text.fillProperties(rc, xMid / 2, yMid / 2);
text.pathRotate = pathRotate;
text.drawOnPath = path;
text.vOffset = rc.main.strokeWidth / 2 - 1;
rc.textToDraw.add(text);
}
}
TextDrawInfo text = new TextDrawInfo(name);
text.fillProperties(rc, xMid / 2, yMid / 2);
text.pathRotate = pathRotate;
text.drawOnPath = path;
text.vOffset = rc.main.strokeWidth / 2 - 1;
rc.textToDraw.add(text);
}
}
}
}