1

I encounter this problem when displaying text on SurfaceView, some chars can climb up on others, code is here:

private static void fakeDraw(Canvas c)
{
    Paint mPaint = new Paint();
    int color = 0xff000000;
    mPaint.setColor(color);
    mPaint.setStrokeWidth(2);
    mPaint.setStyle(Style.FILL);
    mPaint.setAntiAlias(true);

    FontMetricsInt fm = mPaint.getFontMetricsInt();
    int fh = Math.abs(fm.top); 
    int left = 0;
    int top = 100;
    Rect smallClip = new Rect(left, top-fh, left + 200, top + 30);
    Rect bigClip = new Rect(0, 0, getW(), getH());
    c.drawRect(bigClip, mPaint);
    String text1 = "Evi";
    String text2 = ">>";
    String text3 = "Tom";

    color = 0xff303030;
    mPaint.setColor(color);
    c.drawRect(smallClip, mPaint);

    color = 0xffffffff;
    mPaint.setColor(color);
    c.drawText(text1, left, top, mPaint);

    Rect bounds = new Rect();
    mPaint.getTextBounds(text1, 0, text1.length(), bounds);

    left += bounds.width();
    c.drawText(text2, left, top, mPaint);

    left -= bounds.width();
    top += 12;
    c.drawText(text3, left, top, mPaint);
    mPaint.getTextBounds(text3, 0, text3.length(), bounds);
    left += bounds.width();
    c.drawText(text2, left, top, mPaint);
    }

In the case of a second text Tom>> all displayed correctly, but the first text Evi>> not. The problem is that the chars >> draws in Evi draw space(last char "i")!! It is possible to see if you zoom the picture, what am I doing wrong and how to fix this?

screen shot can be found here: http://img192.imageshack.us/img192/2782/imagexs.png

Arkaha
  • 1,582
  • 3
  • 17
  • 19
  • 1
    That looks like normal antialias behaviour. How does it look with antialias turned off? – RoToRa Jun 07 '10 at 09:55
  • RoToRa, with antialias turned off, it works greate :) thanks! Is there any variant to draw antialiased text without chars clibing? – Arkaha Jun 07 '10 at 10:06
  • I don't really see the problem, could you explain a bit more how you expected the code to behave and what looks wrong to you ? – ee3509 Jun 07 '10 at 09:48
  • When i whant to draw chars in position x, and y, I whant that text draws exact in this position but not in x-1 or some thing like that. – Arkaha Jun 07 '10 at 10:00

2 Answers2

0

Hm, Try specifying particular x / y co-ords? with numbers rather than pre defined strings? give the ">>" different coordinates for it's draw space.

Skizit
  • 43,506
  • 91
  • 209
  • 269
0

just add some space manually

c.drawText(text2, left + 2, top, mPaint);

or add a space char (" ") at start of text2

zed_0xff
  • 32,417
  • 7
  • 53
  • 72