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.