mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-04 23:54:53 +00:00
Fix crash on missing viewBox attribute on Pattern element
This commit is contained in:
@@ -118,16 +118,19 @@ class Brush {
|
||||
double w = PropHelper.fromRelative(mPoints[2], width, offsetX, scale, textSize);
|
||||
double h = PropHelper.fromRelative(mPoints[3], height, offsetY, scale, textSize);
|
||||
|
||||
RectF vbRect = mPattern.getViewBox();
|
||||
RectF eRect = new RectF((float)x, (float)y, (float)w, (float)h);
|
||||
Matrix mViewBoxMatrix = ViewBox.getTransform(vbRect, eRect, mPattern.mAlign, mPattern.mMeetOrSlice);
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap(
|
||||
(int) w,
|
||||
(int) h,
|
||||
Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.concat(mViewBoxMatrix);
|
||||
|
||||
RectF vbRect = mPattern.getViewBox();
|
||||
if (vbRect != null && vbRect.width() > 0 && vbRect.height() > 0) {
|
||||
RectF eRect = new RectF((float) x, (float) y, (float) w, (float) h);
|
||||
Matrix mViewBoxMatrix = ViewBox.getTransform(vbRect, eRect, mPattern.mAlign, mPattern.mMeetOrSlice);
|
||||
canvas.concat(mViewBoxMatrix);
|
||||
}
|
||||
|
||||
mPattern.draw(canvas, new Paint(), opacity);
|
||||
|
||||
Matrix patternMatrix = new Matrix();
|
||||
|
||||
@@ -117,12 +117,19 @@ void PatternFunction(void* info, CGContextRef context)
|
||||
RNSVGPainter *_painter = (__bridge RNSVGPainter *)info;
|
||||
RNSVGPattern *_pattern = [_painter pattern];
|
||||
CGRect rect = _painter.paintBounds;
|
||||
|
||||
CGAffineTransform _viewBoxTransform = [RNSVGViewBox getTransform:CGRectMake(_pattern.minX, _pattern.minY, _pattern.vbWidth, _pattern.vbHeight)
|
||||
eRect:rect
|
||||
align:_pattern.align
|
||||
meetOrSlice:_pattern.meetOrSlice];
|
||||
CGContextConcatCTM(context, _viewBoxTransform);
|
||||
CGFloat minX = _pattern.minX;
|
||||
CGFloat minY = _pattern.minY;
|
||||
CGFloat vbWidth = _pattern.vbWidth;
|
||||
CGFloat vbHeight = _pattern.vbHeight;
|
||||
if (vbWidth > 0 && vbHeight > 0) {
|
||||
CGRect vbRect = CGRectMake(minX, minY, vbWidth, vbHeight);
|
||||
CGAffineTransform _viewBoxTransform = [RNSVGViewBox
|
||||
getTransform:vbRect
|
||||
eRect:rect
|
||||
align:_pattern.align
|
||||
meetOrSlice:_pattern.meetOrSlice];
|
||||
CGContextConcatCTM(context, _viewBoxTransform);
|
||||
}
|
||||
|
||||
[_pattern renderTo:context rect:rect];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user