SVGDocument.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. SVG DOM, cf:
  3. http://www.w3.org/TR/SVG11/struct.html#InterfaceSVGDocument
  4. interface SVGDocument : Document,
  5. DocumentEvent {
  6. readonly attribute DOMString title;
  7. readonly attribute DOMString referrer;
  8. readonly attribute DOMString domain;
  9. readonly attribute DOMString URL;
  10. readonly attribute SVGSVGElement rootElement;
  11. };
  12. */
  13. #import <Foundation/Foundation.h>
  14. #import "Document.h"
  15. #import "SVGSVGElement.h"
  16. @interface SVGDocument : Document
  17. @property (nonatomic, strong, readonly) NSString* title;
  18. @property (nonatomic, strong, readonly) NSString* referrer;
  19. @property (nonatomic, strong, readonly) NSString* domain;
  20. @property (nonatomic, strong, readonly) NSString* URL;
  21. @property (nonatomic, strong, readonly) SVGSVGElement* rootElement;
  22. #pragma mark - Objective-C init methods (not part of DOM spec, but necessary!)
  23. - (id)init;
  24. #pragma mark - Serialization methods that we think ought to be part of the SVG spec, as they are needed for a good implementation, but we can't find in the main Spec
  25. /**
  26. Recursively goes through the document finding all declared namespaces in-use by any tag or attribute.
  27. @return a dictionary mapping "namespace" to "ARRAY of prefix-strings"
  28. */
  29. -(NSMutableDictionary*) allPrefixesByNamespace;
  30. /**
  31. As per allPrefixesByNamespace, but takes the output and guarantees that:
  32. 1. There is AT MOST ONE namespace with no prefix
  33. 2. The "prefixless" namespace is the SVG namespace (if possible. This should always be possible for an SVG doc!)
  34. 3. All other namespaces have EXACTLY ONE prefix (if there are multiple, it discards excess ones)
  35. 4. All prefixes are UNIQUE (not used by more than one Namespace)
  36. This is critically important when writing-out an SVG file to disk - As far as I can tell, it's a major ommission from
  37. the XML Spec (which SVG sits on top of). Without this info, you can't construct the appropriate/correct "xmlns" directives
  38. at the start of a file.
  39. USAGE INSTRUCTIONS:
  40. 1. Call this method to get the complete list of namespaces, including any prefixes used
  41. 2. Invoke Node's "appendXMLToString:..." method, passing-in this output, so it can correctly output prefixes for all nodes and subnodes
  42. @return a dictionary mapping "namespace" to "prefix-string or empty-string for the default namespace"
  43. */
  44. -(NSMutableDictionary*) allPrefixesByNamespaceNormalized;
  45. @end