SVGGradientLayer.h 1.3 KB

123456789101112131415161718192021222324252627
  1. //
  2. // SVGGradientLayer.h
  3. // SVGKit-iOS
  4. //
  5. // Created by zhen ling tsai on 19/7/13.
  6. // Copyright (c) 2013 na. All rights reserved.
  7. //
  8. #import <QuartzCore/QuartzCore.h>
  9. #import "SVGGradientElement.h"
  10. /**
  11. Apple's built-in CAGradientLayer does not support the radial gradient in SVG spec which allows user to provide `cx`, `cy`, `r`, `fx`, `fy`, `fr` 6 args.
  12. The built-in `kCAGradientLayerRadial` type only supports a ellipse and take `cx`, `cy`, `r` 3 args. Sadlly we can not directly use it for radial gardient.
  13. So we have to subclass and use the low-level API `CGContextDrawRadialGradient` using custom drawing to follow SVG spec.
  14. Also, though we can use `CAGradientLayer` for all linear gradient. Apples contains bug rending the gradient using `drawInContext:` method on iOS only (but works well on macOS), which will contains some strange bounding rects. This will break `SVGFastImageView` usage (but works well on SVGLayeredImageView).
  15. So we have to use the low-level API `CGContextDrawLinearGradient` using custom drawing to as well.
  16. */
  17. @interface SVGGradientLayer : CAGradientLayer
  18. @property (nonatomic, strong) SVGGradientElement *gradientElement;
  19. @property (nonatomic, assign) CGRect objectRect;
  20. @property (nonatomic, assign) SVGRect viewportRect;
  21. @property (nonatomic, assign) CGAffineTransform absoluteTransform;
  22. @end