27

I have some code setup in an extended view which does some drawings which are easily scaled (vector-like). (My scale is setup as 0-1.0)

I noticed that when I set my paint fill to FILL, the text drawn on a path looks correct, but when I set the fill to stroke (I just want the outline of the text) the image looks like it is on some LSD trip. Here is my sample code :

    Paint yellowPaint = Paints.getFillTextPaint(0.01f, 0xFFffea3e, 0.065f);
    canvas.drawTextOnPath(mContext.getString(R.string.building_a_partnership),
             Paths.getRoundedTextPath(mOuterCircleRectF, 280f, 350f),
             0, -0.025f, yellowPaint);

public static Paint getFillTextPaint(float f, int color, float textSize) {
        Paint textPaint = new Paint();
        textPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
        textPaint.setStyle(Paint.Style.FILL);
        textPaint.setColor(color);
        textPaint.setTextSize(textSize);
        textPaint.setStrokeWidth(f);
        textPaint.setShadowLayer(0.002f, 0.0f, 0.0f, 0xFF000000);
        textPaint.setTypeface(Typeface.SANS_SERIF);
        return textPaint;
    }

If I change the Paint.Style from FILL to STROKE I get the images below. I have used the canvas.drawText() and it works fine showing the stroked letters. It is only when it is applied to a Path, when it seems to get all weird.

Fill Image

Stroke Image

Eva Dias
  • 1,709
  • 9
  • 36
  • 67
Chrispix
  • 17,941
  • 20
  • 62
  • 70
  • `drawTextOnPath` may not be a supported canvas operation with hardware acceleration turned on. See http://android-developers.blogspot.com/2011/03/android-30-hardware-acceleration.html – Roman Nurik Feb 29 '12 at 20:56
  • Thanks Roman, will check it out. – Chrispix Mar 01 '12 at 04:45
  • So, I tried this instance.setLayerType(View.LAYER_TYPE_SOFTWARE, null); did the drawTextOnPath, then did instance.setLayerType(View.LAYER_TYPE_HARDWARE, null); - Does the same thing. – Chrispix Mar 02 '12 at 02:22
  • Does the same thing on my Nexus One. – Chrispix Mar 02 '12 at 02:30
  • 1
    OK, my guess is this is indeed a bug (just looked at your code). Mind filing at b.android.com/new? I'll notify our Skia folks – Roman Nurik Mar 02 '12 at 03:42
  • Submitted http://code.google.com/p/android/issues/detail?id=26764&thanks=26764&ts=1331581434 – Chrispix Mar 12 '12 at 19:45
  • I seen something similar. It may have to do with scaling after draw along the path. Try not to scale after the draw as a test. – eyespyus Apr 05 '12 at 18:57
  • It turns out that it has to do w/ the scale size being < 1.0 – Chrispix Apr 07 '12 at 05:07
  • 1
    @Chrispix, I didn't try your code, but I could bet that the issue is related to the size (to big) of the text being drawn. If you look again to what looks like LSD trip, you can identify parts of huge characters. Good luck. – Luis Sep 18 '12 at 15:14

1 Answers1

0

Apparently this is due to the fact that my scale factor is 0-1.. There appears to be a bug w/ how rendering a stroke with size < 1.0 is treated. Suggested solution is to use a scale of 0-100..

Chrispix
  • 17,941
  • 20
  • 62
  • 70