SVGHelperUtilities.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. To implement the official SVG Spec, some "extra" methods are needed that are SHARED between classes, but
  3. which in the SVG Spec the classes aren't subclass/superclass of each other - so that there's no way to
  4. implement it without copy/pasting the code.
  5. To improve maintainability, we put those methods here, and then each place we need them has a 1-line method
  6. that delegates to a method body in this class.
  7. */
  8. #import <Foundation/Foundation.h>
  9. #import <QuartzCore/QuartzCore.h>
  10. #import "SVGElement.h"
  11. #import "SVGTransformable.h"
  12. #import "SVGFitToViewBox.h"
  13. #define FORCE_RASTERIZE_LAYERS 0 // If True, all CALayers will be told to rasterize themselves. This MIGHT increase performance (or might not), but leads to blurriness whenever a layer is scaled / zoomed in
  14. #define IMPROVE_PERFORMANCE_BY_WORKING_AROUND_APPLE_FRAME_ALIGNMENT_BUG 1 // NB: Apple's code for rendering ANY CALayer is extremely slow if the layer has non-integer co-ordinates for its "frame" or "bounds" property. This flag technically makes your SVG's render incorrect at sub-pixel level, but often increases performance of Apple's rendering by a factor of 2 or more!
  15. @class SVGGradientLayer;
  16. @interface SVGHelperUtilities : NSObject
  17. /**
  18. According to the SVG Spec, there are two types of element that affect the on-screen size/shape/position/rotation/skew of shapes/images:
  19. 1. Any ancestor that implements SVGTransformable
  20. 2. Any "element that establishes a new viewport" - i.e. the <svg> tag and a few others
  21. This method ONLY looks at current node to establish the above two things, to do a RELATIVE transform (relative to parent node)
  22. */
  23. +(CGAffineTransform) transformRelativeIncludingViewportForTransformableOrViewportEstablishingElement:(SVGElement*) transformableOrSVGSVGElement;
  24. /**
  25. According to the SVG Spec, there are two types of element that affect the on-screen size/shape/position/rotation/skew of shapes/images:
  26. 1. Any ancestor that implements SVGTransformable
  27. 2. Any "element that establishes a new viewport" - i.e. the <svg> tag and a few others
  28. This method recurses upwards to combine the above two things for everything in the tree, to establish an ABSOLUTE transform
  29. */
  30. +(CGAffineTransform) transformAbsoluteIncludingViewportForTransformableOrViewportEstablishingElement:(SVGElement*) transformableOrSVGSVGElement;
  31. /** Some things - e.g. setting layer's Opacity - have to be done for pretty much EVERY SVGElement; this method automatically looks
  32. at the incoming element, uses the protocols that element has (e.g. SVGStylable) to automatically adapt the layer.
  33. This allows each SVGElement subclass to create a custom CALayer as needed (e.g. CATextLayer for text elements), but share the setup
  34. code.
  35. If compiled with FORCE_RASTERIZE_LAYERS, also tells every layer to rasterize itself
  36. */
  37. +(void) configureCALayer:(CALayer*) layer usingElement:(SVGElement*) nonStylableElement;
  38. +(CALayer *) newCALayerForPathBasedSVGElement:(SVGElement*) svgElement withPath:(CGPathRef) path;
  39. + (SVGGradientLayer*)getGradientLayerWithId:(NSString*)gradId
  40. forElement:(SVGElement*)svgElement
  41. withRect:(CGRect)r
  42. transform:(CGAffineTransform)transform;
  43. +(CGColorRef) parseFillForElement:(SVGElement *)svgElement;
  44. +(CGColorRef) parseStrokeForElement:(SVGElement *)svgElement;
  45. +(void) parsePreserveAspectRatioFor:(Element<SVGFitToViewBox>*) element;
  46. @end