SVGLength.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*!
  2. SVGLength.h
  3. http://www.w3.org/TR/SVG/types.html#InterfaceSVGLength
  4. // Length Unit Types
  5. const unsigned short SVG_LENGTHTYPE_UNKNOWN = 0;
  6. const unsigned short SVG_LENGTHTYPE_NUMBER = 1;
  7. const unsigned short SVG_LENGTHTYPE_PERCENTAGE = 2;
  8. const unsigned short SVG_LENGTHTYPE_EMS = 3;
  9. const unsigned short SVG_LENGTHTYPE_EXS = 4;
  10. const unsigned short SVG_LENGTHTYPE_PX = 5;
  11. const unsigned short SVG_LENGTHTYPE_CM = 6;
  12. const unsigned short SVG_LENGTHTYPE_MM = 7;
  13. const unsigned short SVG_LENGTHTYPE_IN = 8;
  14. const unsigned short SVG_LENGTHTYPE_PT = 9;
  15. const unsigned short SVG_LENGTHTYPE_PC = 10;
  16. readonly attribute unsigned short unitType;
  17. attribute float value setraises(DOMException);
  18. attribute float valueInSpecifiedUnits setraises(DOMException);
  19. attribute DOMString valueAsString setraises(DOMException);
  20. void newValueSpecifiedUnits(in unsigned short unitType, in float valueInSpecifiedUnits) raises(DOMException);
  21. void convertToSpecifiedUnits(in unsigned short unitType) raises(DOMException);
  22. };
  23. */
  24. #import <Foundation/Foundation.h>
  25. typedef enum SVG_LENGTH_TYPE
  26. {
  27. SVG_LENGTHTYPE_UNKNOWN = 0,
  28. SVG_LENGTHTYPE_NUMBER = 1,
  29. SVG_LENGTHTYPE_PERCENTAGE = 2,
  30. SVG_LENGTHTYPE_EMS = 3,
  31. SVG_LENGTHTYPE_EXS = 4,
  32. SVG_LENGTHTYPE_PX = 5,
  33. SVG_LENGTHTYPE_CM = 6,
  34. SVG_LENGTHTYPE_MM = 7,
  35. SVG_LENGTHTYPE_IN = 8,
  36. SVG_LENGTHTYPE_PT = 9,
  37. SVG_LENGTHTYPE_PC = 10
  38. } SVG_LENGTH_TYPE;
  39. @interface SVGLength : NSObject
  40. @property(nonatomic,readonly) SVG_LENGTH_TYPE unitType;
  41. @property(nonatomic) float value;
  42. @property(nonatomic) float valueInSpecifiedUnits;
  43. @property(nonatomic,strong) NSString* valueAsString;
  44. -(void) newValueSpecifiedUnits:(SVG_LENGTH_TYPE) unitType valueInSpecifiedUnits:(float) valueInSpecifiedUnits;
  45. -(void) convertToSpecifiedUnits:(SVG_LENGTH_TYPE) unitType;
  46. #pragma mark - things outside the spec but needed to make it usable in Objective C
  47. +(SVGLength*) svgLengthZero;
  48. +(SVGLength*) svgLengthFromNSString:(NSString*) s;
  49. /** returns this SVGLength as if it had been converted to pixels, using [self convertToSpecifiedUnits:SVG_LENGTHTYPE_PX]
  50. */
  51. -(float) pixelsValue;
  52. /** to calculate relative values pass in the appropriate viewport dimension (width, height, or diagonal measure)
  53. */
  54. -(float) pixelsValueWithDimension:(float)dimension;
  55. /** to calculate relative gradient values pass in the appropriate viewport dimension (width, height)
  56. * the different between this and `pixelsValueWithDimension` is that this one will treat number value which (0 <= value <= 1.0) as percent value and calculate the result. (used by gradient)
  57. */
  58. -(float) pixelsValueWithGradientDimension:(float)dimension;
  59. /** returns this SVGLength as if it had been converted to a raw number (USE pixelsValue instead, UNLESS you are dealing with something that you expect to be a percentage or
  60. similar non-pixel value), using [self convertToSpecifiedUnits:SVG_LENGTHTYPE_NUMBER]
  61. */
  62. -(float) numberValue;
  63. @end