Obsolete
Status Update
Comments
yo...@scoompa.com <yo...@scoompa.com> #2
Forgot to clarify, this happens only on KitKat, tested on Nexus-7
js...@android.com <js...@android.com>
se...@gmail.com <se...@gmail.com> #3
Thank you for posting this bug! I was banging my head against the computer trying to figure out how I broke my code. I can confirm this on KitKat as well.
ve...@gmail.com <ve...@gmail.com> #4
Have the same defect while drawing text into Bitmap canvas. Spent several hours trying to understand what it was =((
Tested on Nexus 5 & 10.
Tested on Nexus 5 & 10.
pb...@gmail.com <pb...@gmail.com> #5
I can confirm the bug, Nexus4 and Nexus7 with KitKat. Also spent some hours...
Please fix!
Please fix!
yo...@scoompa.com <yo...@scoompa.com> #6
This bug still happens on the new version 4.4.3
mi...@gmail.com <mi...@gmail.com> #7
Problem still persist on the new version 4.4.3
Workaround:
1. do not use paint.setStrokeWidth() greater than 1
or
2. Draw your text into new bitmap, use text size = 256, calculate remaining size as
remaining = requiredFontSize - 256
Save canvas:
canvas.save();
Scale canvas:
canvas.scale(((float)remaining / (float)requiredFontSize) + 1.0f,
((float)remaining / (float)requiredFontSize) + 1.0f,
scalePointX,
scalePointY);
draw bitmap to canvas:
canvas.drawBitmap(bitmap, 0, 0, paint);
restore canvas:
canvas.restore();
Doesn't look perfect because it's based on bitmap resizing, but still better than with this strange bug.
Workaround:
1. do not use paint.setStrokeWidth() greater than 1
or
2. Draw your text into new bitmap, use text size = 256, calculate remaining size as
remaining = requiredFontSize - 256
Save canvas:
canvas.save();
Scale canvas:
canvas.scale(((float)remaining / (float)requiredFontSize) + 1.0f,
((float)remaining / (float)requiredFontSize) + 1.0f,
scalePointX,
scalePointY);
draw bitmap to canvas:
canvas.drawBitmap(bitmap, 0, 0, paint);
restore canvas:
canvas.restore();
Doesn't look perfect because it's based on bitmap resizing, but still better than with this strange bug.
th...@gmail.com <th...@gmail.com> #8
Found a good workaround that hasn't been presented here; works in any Android version.
Instead of using Canvas.drawText(), grab and draw the outline of the text by using this:
String text = "Some text";
mTextOutlinePath = new Path();
// adjust the x,y text origin to your personal needs
mStrokePaint.getTextPath(text, 0, text.length(), getPaddingLeft(), getBaseline(), mTextOutlinePath);
canvas.drawPath(mTextOutlinePath, mFillPaint);
canvas.drawPath(mTextOutlinePath, mStrokePaint);
From what I can tell it results in the same text/stroke as Canvas.DrawText(), except the bug isn't present even if text size is greater than 256. Credit for this alternative method goes to this gentleman:http://stackoverflow.com/a/5817510/708906 (although it wasn't used for this workaround originally).
So the issue probably lies in the source code for Canvas.drawText() (I can't tell what's causing it because it just calls a native method).
=== NOW, I'm going to whine/complain/lament because it makes me feel better ===
This bug makes me want to cry. I spent at least two days figuring out it's a bug and finding a workaround. I can't believe this is still present in 4.4.3. I'm very curious how they introduced this bug since it doesn't seem to be present in older versions of Android =(
But seriously, every once in a while I come across strange behavior and spend hours only to discover it's a bug, and no less a half year old bug. I think people like us spend hours then writing up reports for the bug and working on workarounds. It's very discouraging to see the issues open for so long without a fix.
I'm not the greatest programmer; I don't know how to personally contribute to AOSP to fix it, nor do I have the time to do it. But the time we put into contributing to the bug tracker should count for something.
I suppose now a fix is mostly moot since my workaround seems to be just fine, unless someone discovers a downfall with it. But if it weren't for this workaround I would have literally had to settle for a very subpar hack or simply not present the feature I was working on to our users. So for our sanity please fix more bugs. MOAR BUGS! Thanks.
Instead of using Canvas.drawText(), grab and draw the outline of the text by using this:
String text = "Some text";
mTextOutlinePath = new Path();
// adjust the x,y text origin to your personal needs
mStrokePaint.getTextPath(text, 0, text.length(), getPaddingLeft(), getBaseline(), mTextOutlinePath);
canvas.drawPath(mTextOutlinePath, mFillPaint);
canvas.drawPath(mTextOutlinePath, mStrokePaint);
From what I can tell it results in the same text/stroke as Canvas.DrawText(), except the bug isn't present even if text size is greater than 256. Credit for this alternative method goes to this gentleman:
So the issue probably lies in the source code for Canvas.drawText() (I can't tell what's causing it because it just calls a native method).
=== NOW, I'm going to whine/complain/lament because it makes me feel better ===
This bug makes me want to cry. I spent at least two days figuring out it's a bug and finding a workaround. I can't believe this is still present in 4.4.3. I'm very curious how they introduced this bug since it doesn't seem to be present in older versions of Android =(
But seriously, every once in a while I come across strange behavior and spend hours only to discover it's a bug, and no less a half year old bug. I think people like us spend hours then writing up reports for the bug and working on workarounds. It's very discouraging to see the issues open for so long without a fix.
I'm not the greatest programmer; I don't know how to personally contribute to AOSP to fix it, nor do I have the time to do it. But the time we put into contributing to the bug tracker should count for something.
I suppose now a fix is mostly moot since my workaround seems to be just fine, unless someone discovers a downfall with it. But if it weren't for this workaround I would have literally had to settle for a very subpar hack or simply not present the feature I was working on to our users. So for our sanity please fix more bugs. MOAR BUGS! Thanks.
su...@gmail.com <su...@gmail.com> #9
Hi Team,
I am also facing the same issue. When we are drawing a chart using aChartEngine library the chart labels are not properly displayed in latest android OS devices. This is working fine in older versions. By using the below code my issue is solved and it is working fine in all versions
String text = "Some text";
mTextOutlinePath = new Path();
// adjust the x,y text origin to your personal needs
mStrokePaint.getTextPath(text, 0, text.length(), getPaddingLeft(), getBaseline(), mTextOutlinePath);
canvas.drawPath(mTextOutlinePath, mFillPaint);
canvas.drawPath(mTextOutlinePath, mStrokePaint);
In the below attachment the value "104" is not proper in latest OS versions(4.4+) and it is corrected using the above workaround solution.
Credit for this alternative method goes to this gentleman:http://stackoverflow.com/a/5817510/708906
(although it wasn't used for this workaround originally).
- Thanks
Sujith C R
I am also facing the same issue. When we are drawing a chart using aChartEngine library the chart labels are not properly displayed in latest android OS devices. This is working fine in older versions. By using the below code my issue is solved and it is working fine in all versions
String text = "Some text";
mTextOutlinePath = new Path();
// adjust the x,y text origin to your personal needs
mStrokePaint.getTextPath(text, 0, text.length(), getPaddingLeft(), getBaseline(), mTextOutlinePath);
canvas.drawPath(mTextOutlinePath, mFillPaint);
canvas.drawPath(mTextOutlinePath, mStrokePaint);
In the below attachment the value "104" is not proper in latest OS versions(4.4+) and it is corrected using the above workaround solution.
Credit for this alternative method goes to this gentleman:
(although it wasn't used for this workaround originally).
- Thanks
Sujith C R
ro...@google.com <ro...@google.com>
si...@google.com <si...@google.com>
no...@google.com <no...@google.com> #10
Looks like this is KitKat only issue.
Here is screenshots after API 15.
Here is screenshots after API 15.
Description
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bitmap bitmap = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
int x = 20;
int y = 160;
String text = "Abc";
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setTextSize(256); // << 256 works, 257 does not
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.RED);
canvas.drawText(text, x, y, paint);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(4);
paint.setColor(Color.WHITE);
canvas.drawText(text, x, y, paint);
ImageView imageView = new ImageView(this);
imageView.setImageBitmap(bitmap);
setContentView(imageView);
}