Fix highres rendering

This commit is contained in:
Victor Shcherb 2012-03-22 23:50:43 +01:00
parent 3281476d2f
commit 2a2c5567a0
5 changed files with 73 additions and 41 deletions

View file

@ -738,7 +738,7 @@
<filter minzoom="15" icon="sport_ski" tag="sport" value="skiing"/>
<filter minzoom="16" icon="sport_diving" tag="sport" value="diving"/>
<filter minzoom="15" icon="theme_park" tag="tourism" value="theme_park"/>
<filter minzoom="16" icon="amenity_bench" tag="amenity" value="bench"/>
<filter minzoom="17" icon="amenity_bench" tag="amenity" value="bench"/>
<filter minzoom="15" icon="leisure_sports_centre" tag="leisure" value="sports_centre"/>
<filter minzoom="16" icon="bird_hide" tag="leisure" value="bird_hide"/>

View file

@ -560,38 +560,45 @@ void drawObject(RenderingContext* rc, BaseMapDataObject* mapObject, SkCanvas* cv
void drawIconsOverCanvas(RenderingContext* rc, SkCanvas* canvas)
{
int skewConstant = (int) getDensityValue(rc, 16);
int iconsW = rc -> width / skewConstant;
int iconsH = rc -> height / skewConstant;
int len = (iconsW * iconsH) / 32;
int alreadyDrawnIcons[len];
memset(alreadyDrawnIcons, 0, sizeof(int)*len);
size_t ji = 0;
SkPaint p;
p.setStyle(SkPaint::kStroke_Style);
for(;ji< rc->iconsToDraw.size(); ji++)
{
IconDrawInfo icon = rc->iconsToDraw.at(ji);
if (icon.y >= 0 && icon.y < rc -> height && icon.x >= 0 && icon.x < rc -> width &&
icon.bmp != NULL) {
int z = (((int) icon.x / skewConstant) + ((int) icon.y / skewConstant) * iconsW);
int i = z / 32;
if (i >= len) {
continue;
}
int ind = alreadyDrawnIcons[i];
int b = z % 32;
// check bit b if it is set
if (((ind >> b) & 1) == 0) {
alreadyDrawnIcons[i] = ind | (1 << b);
SkBitmap* ico = icon.bmp;
PROFILE_NATIVE_OPERATION(rc, canvas->drawBitmap(*ico, icon.x - ico->width() / 2, icon.y - ico->height() / 2, &p));
}
}
if(rc->interrupted()){
return;
}
}
int skewConstant = (int) getDensityValue(rc, 16);
int iconsW = rc -> width / skewConstant;
int iconsH = rc -> height / skewConstant;
int len = (iconsW * iconsH) / 32;
int alreadyDrawnIcons[len];
memset(alreadyDrawnIcons, 0, sizeof(int)*len);
size_t ji = 0;
SkPaint p;
p.setStyle(SkPaint::kStroke_Style);
for(;ji< rc->iconsToDraw.size(); ji++)
{
IconDrawInfo icon = rc->iconsToDraw.at(ji);
if (icon.y >= 0 && icon.y < rc -> height && icon.x >= 0 && icon.x < rc -> width &&
icon.bmp != NULL) {
int z = (((int) icon.x / skewConstant) + ((int) icon.y / skewConstant) * iconsW);
int i = z / 32;
if (i >= len) {
continue;
}
int ind = alreadyDrawnIcons[i];
int b = z % 32;
// check bit b if it is set
if (((ind >> b) & 1) == 0) {
alreadyDrawnIcons[i] = ind | (1 << b);
SkBitmap* ico = icon.bmp;
if(rc->highResMode) {
float left = icon.x - getDensityValue(rc, ico->width() / 2);
float top = icon.y - getDensityValue(rc, ico->height() / 2);
SkRect r = SkRect::MakeXYWH(left, top, getDensityValue(rc, ico->width()), getDensityValue(rc, ico->height()));
PROFILE_NATIVE_OPERATION(rc, canvas->drawBitmapRect(*ico, (SkIRect*) NULL, r, &p));
} else {
PROFILE_NATIVE_OPERATION(rc, canvas->drawBitmap(*ico, icon.x - ico->width() / 2, icon.y - ico->height() / 2, &p));
}
}
}
if(rc->interrupted()){
return;
}
}
}
std::hash_map<int, std::vector<int> > sortObjectsByProperOrder(std::vector <BaseMapDataObject* > mapDataObjects,

View file

@ -534,10 +534,15 @@ void drawTextOverCanvas(RenderingContext* rc, SkCanvas* cv) {
if (text->shieldRes.length() > 0) {
SkBitmap* ico = getCachedBitmap(rc, text->shieldRes);
if (ico != NULL) {
rc->nativeOperations.pause();
cv->drawBitmap(*ico, text->centerX - ico->width() / 2 - 0.5f,
text->centerY - ico->height() / 2 - getDensityValue(rc, 4.5f), &paintIcon);
rc->nativeOperations.start();
if(rc->highResMode) {
float left = text->centerX - getDensityValue(rc, ico->width() / 2) - 0.5f;
float top =text->centerY - getDensityValue(rc, ico->height() / 2) - getDensityValue(rc, 4.5f);
SkRect r = SkRect::MakeXYWH(left, top, getDensityValue(rc, ico->width()), getDensityValue(rc, ico->height()));
PROFILE_NATIVE_OPERATION(rc, cv->drawBitmapRect(*ico, (SkIRect*) NULL, r, &paintIcon));
} else {
PROFILE_NATIVE_OPERATION(rc, cv->drawBitmap(*ico, text->centerX - ico->width() / 2 - 0.5f,
text->centerY - ico->height() / 2 - getDensityValue(rc, 4.5f), &paintIcon));
}
}
}
drawWrappedText(rc, cv, text, textSize, paintText);

View file

@ -36,6 +36,8 @@ import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Shader;
@ -358,7 +360,14 @@ public class OsmandRenderer {
// check bit b if it is set
if (((ind >> b) & 1) == 0) {
alreadyDrawnIcons[i] = ind | (1 << b);
cv.drawBitmap(ico, icon.x - ico.getWidth() / 2, icon.y - ico.getHeight() / 2, paintIcon);
if(rc.highResMode) {
float left = icon.x - rc.getDensityValue(ico.getWidth() / 2);
float top = icon.y - rc.getDensityValue(ico.getHeight() / 2);
cv.drawBitmap(ico, null, new RectF(left, top, left + rc.getDensityValue(ico.getWidth()), top
+ rc.getDensityValue(ico.getHeight())), paintIcon);
} else {
cv.drawBitmap(ico, icon.x - ico.getWidth() / 2, icon.y - ico.getHeight() / 2, paintIcon);
}
}
}
}

View file

@ -237,8 +237,19 @@ public class TextRenderer {
if (text.shieldRes != null) {
Bitmap ico = RenderingIcons.getIcon(context, text.shieldRes);
if (ico != null) {
cv.drawBitmap(ico, text.centerX - ico.getWidth() / 2 - 0.5f,
text.centerY - ico.getHeight() / 2 - rc.getDensityValue(4.5f), paintIcon);
if (rc.highResMode) {
float left = text.centerX - rc.getDensityValue(ico.getWidth() / 2) - 0.5f;
float top = text.centerY - rc.getDensityValue(ico.getHeight() / 2) - rc.getDensityValue(4.5f);
Rect rec = new Rect(0, 0, ico.getWidth(), ico.getHeight());
cv.drawBitmap(ico, rec,
new RectF(left, top, left + rc.getDensityValue(ico.getWidth()), top
+ rc.getDensityValue(ico.getHeight())), paintIcon);
} else {
float left = text.centerX - ico.getWidth() / 2 - 0.5f;
float top = text.centerY - ico.getHeight() / 2 - rc.getDensityValue(4.5f);
cv.drawBitmap(ico, left, top, paintIcon);
}
}
}
@ -298,7 +309,7 @@ public class TextRenderer {
if(render.getIntPropertyValue(render.ALL.R_TEXT_SIZE) > 0){
TextDrawInfo text = new TextDrawInfo(name);
text.fillProperties(render, xMid, yMid);
paintText.setTextSize(text.textSize);
paintText.setTextSize(rc.getDensityValue(text.textSize));
Rect bs = new Rect();
paintText.getTextBounds(name, 0, name.length(), bs);
text.bounds = new RectF(bs);