2

I'm not sure I have found a bug in Android or if there is a bug in my code. I thought it might be another (or new) manifestation of the hardware acceleration bug I've read about. I am running on android 4.2, but setting android:hardwareAccelerated="true" in the manifest file doesn't fix things.

The problem exists in a custom view. It has a complex display so rather than specify all the Path fields separately I parse an SVG file and build the paths up from the data specification of <path> elements. The SGV parser also extracts the SVG drawing area's width and height so that the matrix to transform between SVG space and View space can be generated:

Matrix t = new Matrix();

float scale = Math.min(viewWidth / svgWidth, viewHeight / svgHeight);
t.setScale(scale, scale);

This transform is applied to the canvas in the onDraw(Canvas) method. The issue is that some of the paths render okay and some do not. It is also true of text rendered along a path.

I think I have found the differentiator between being rendered and not rendered: straight lines. The text that was being rendered was on a diagonal line, the text that was not was on a perfectly horizontal one. Moving the text path off horizontal resulted in the text being rendered. So too does changing the horizontal line to a cubic curve with the control points on the line itself - so it renders like a straight line; what I will call a straight curve from now on.

Is it a bug in the Android acceleration code that filters out paths if the bounding box (pre- or post- translation) have zero volume (boundingBox.left - boundingBox.right == 0 or boundingBox.top - boundingBox.bottom == 0)? Maybe! But I have other cases of paths that do not render: paths make up of just straight lines. Even when the bounding box of these paths has volume they don't render. Change one of the path elements from a straight line to a straight curve and the whole path renders just fine.

Of course, from a performance view I don't want to have to render some of my lines as straight curves, I assume that the line drawing code is quicker than the cubic curve one. So I post this to ask if anyone else has encountered this issues and if there is a fix for it.

Many thanks as always.

Community
  • 1
  • 1
Dobbo
  • 1,188
  • 3
  • 16
  • 27
  • Hi, I have a similar problem. Please look at my question:http://stackoverflow.com/questions/16656453/unwanted-warp-effect-drawing-text-on-path-android . Is this similar to Your problem? Got no solution until now...turning of HardwareAcceleration does not fix the problem.... – Opiatefuchs May 23 '13 at 12:04
  • @Opiatefuchs It could well be the same problem. Calling translate(...) on the path seams to be the issue. – Dobbo May 23 '13 at 18:12
  • thanks for reply...so You got no solution until now? – Opiatefuchs May 24 '13 at 08:21
  • No, I coded around it to avoid the situation. I wasn't sure it was a system bug or something I was doing wrong. Given the lack of response I haven't bothered to take it any further. – Dobbo May 24 '13 at 13:25

2 Answers2

5

I just found that I had to close() a Path to have it render on some devices/emulators—even if it was just a transformed version of an existing, closed, Path, and, in fact, even if it was just a new path created directly from the existing path.

For example, Path thisIsInvisible = new Path(existingClosedPath);existingClosedPath would paint just fine on my canvas. thisIsInvisible would silently not show up. But if I called thisIsInvisible.close() just after creating it, it worked fine.

I also found an interesting post from Romain Guy suggesting that with hardware acceleration on, it may be better to use addPath() to do the same job as transform().

Matt Gibson
  • 37,886
  • 9
  • 99
  • 128
  • Google, this is simply retarded. Instead of Path.transform(Matrix, null), one needs to use new Path().addPath(path, Matrix) and it's solved? Why didn't the god damn Path.transform() function worked in the first place? So now I have to test my app on all emulators because of stupid bugs like this? Screw Android. – Martin Vysny Mar 29 '15 at 16:16
1

I had a similar problem with path transformations on android 4.1.2 version. Some paths simply wouldn't transform or draw. Solved it by turning hardware acceleration off. Hope this will help someone in future.

zoroz
  • 76
  • 1
  • 5
  • see my question that i linked above. By turning of hardware acceleration, the drawn text looks warped at runtime and call getDrawingCatche(). By turning on, it looks only warped after call getDrawingCatche() at saved picture, but not at runtime. – Opiatefuchs May 24 '13 at 08:20