10.9提交
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
PLEASE NOTE: Apple has made a PRIVATE implementation of this class, and because of their
|
||||
stupid App Store rules they ban everyone else in the world from using a class with the
|
||||
same name. Instead of making the class public, they have stolen it out of the global
|
||||
namespace. This is the wrong thing to do, but we are required to rename our classes
|
||||
because of this.
|
||||
|
||||
SVG-DOM, via Core DOM:
|
||||
|
||||
http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-102161490
|
||||
|
||||
interface DOMImplementation {
|
||||
boolean hasFeature(in DOMString feature,
|
||||
in DOMString version);
|
||||
// Introduced in DOM Level 2:
|
||||
DocumentType createDocumentType(in DOMString qualifiedName,
|
||||
in DOMString publicId,
|
||||
in DOMString systemId)
|
||||
raises(DOMException);
|
||||
// Introduced in DOM Level 2:
|
||||
Document createDocument(in DOMString namespaceURI,
|
||||
in DOMString qualifiedName,
|
||||
in DocumentType doctype)
|
||||
raises(DOMException);
|
||||
};
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "DocumentType.h"
|
||||
|
||||
@interface AppleSucksDOMImplementation : NSObject
|
||||
|
||||
-(BOOL) hasFeature:(NSString*) feature version:(NSString*) version;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(DocumentType*) createDocumentType:(NSString*) qualifiedName publicId:(NSString*) publicId systemId:(NSString*) systemId;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(Document*) createDocument:(NSString*) namespaceURI qualifiedName:(NSString*) qualifiedName doctype:(DocumentType*) doctype;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
SVG-DOM, via Core DOM:
|
||||
|
||||
http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-637646024
|
||||
|
||||
interface Attr : Node {
|
||||
readonly attribute DOMString name;
|
||||
readonly attribute boolean specified;
|
||||
attribute DOMString value;
|
||||
// raises(DOMException) on setting
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
readonly attribute Element ownerElement;
|
||||
};
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
/** objc won't allow this: @class Node;*/
|
||||
#import "Node.h"
|
||||
@class Element;
|
||||
|
||||
@interface Attr : Node
|
||||
|
||||
/*! NB: The official DOM spec FAILS TO SPECIFY what the value of "name" is */
|
||||
@property(nonatomic,strong,readonly) NSString* name;
|
||||
@property(nonatomic,readonly) BOOL specified;
|
||||
@property(nonatomic,strong,readonly) NSString* value;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
@property(nonatomic,strong,readonly) Element* ownerElement;
|
||||
|
||||
#pragma mark - ObjC methods
|
||||
|
||||
- (id)initWithName:(NSString*) n value:(NSString*) v;
|
||||
- (id)initWithNamespace:(NSString*) ns qualifiedName:(NSString*) qn value:(NSString*) v;
|
||||
|
||||
@end
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
This class is FOR IMPLEMENTATION ONLY, it is NOT part of the SVG Spec.
|
||||
|
||||
All the SVG Basic Shapes are rendered in ObjectiveC using the same CGPath primitive - so this class provides
|
||||
a clean, OOP, way of implementing that.
|
||||
|
||||
Sub-classes MUST write to the "pathForShapeInRelativeCoords" property, and this superclass will automatically generate
|
||||
the required CALayer on the fly, using that CGPath
|
||||
*/
|
||||
|
||||
#import "SVGElement.h"
|
||||
#import "ConverterSVGToCALayer.h"
|
||||
#import "SVGUtils.h"
|
||||
#import "SVGTransformable.h"
|
||||
|
||||
@class SVGGradientElement;
|
||||
@class SVGKPattern;
|
||||
|
||||
@interface BaseClassForAllSVGBasicShapes : SVGElement < SVGStylable, SVGTransformable, ConverterSVGToCALayer >
|
||||
{
|
||||
/* FIXME: are any of these private elements in the SVG spec? */
|
||||
NSString *_styleClass;
|
||||
CGRect _layerRect;
|
||||
}
|
||||
|
||||
/** The actual path as parsed from the original file. THIS MIGHT NOT BE NORMALISED (TODO: perhaps an extra feature?) */
|
||||
@property (nonatomic, readonly) CGPathRef pathForShapeInRelativeCoords;
|
||||
|
||||
@end
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
Class extension that makes the internal properties readWRITE for subclasses to write to
|
||||
*/
|
||||
|
||||
@interface BaseClassForAllSVGBasicShapes ()
|
||||
@property (nonatomic, readwrite) CGPathRef pathForShapeInRelativeCoords;
|
||||
@end
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// CALayer+RecursiveClone.h
|
||||
// SVGKit-iOS
|
||||
//
|
||||
// Created by adam on 22/04/2013.
|
||||
// Copyright (c) 2013 na. All rights reserved.
|
||||
//
|
||||
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
@interface CALayer (RecursiveClone)
|
||||
|
||||
/** Since Apple decided not to expose this common and essential method ... */
|
||||
-(CALayer*) cloneRecursively;
|
||||
|
||||
/** Clones ONLY this layer - none of the sublayers - but uses identical code to cloneRecursively */
|
||||
-(CALayer*) cloneShallow;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,21 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
#import "CALayerWithClipRender.h"
|
||||
|
||||
/*!
|
||||
* Overrides Apple's CALayer purely to change one method, so that hit-testing
|
||||
* is done by checking whether the hit point lies:
|
||||
*
|
||||
* "inside ANY of my child sub-layers (some of which have over-ridden hit-testing too)"
|
||||
*
|
||||
* This implementation is used by SVGGElement (for obvious reasons!)
|
||||
*
|
||||
* This is more useful than Apple's default implementation, but it might cause unexpected
|
||||
* problems in other code (not that I'm aware of any - this override appears to be a common
|
||||
* implementation, c.f. http://stackoverflow.com/questions/2944064/hit-testing-with-calayer-using-the-alpha-properties-of-the-calayer-contents
|
||||
*/
|
||||
@interface CALayerWithChildHitTest : CALayerWithClipRender {
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// CALayerWithClipRender.h
|
||||
// SVGKit-iOS
|
||||
//
|
||||
// Created by David Gileadi on 8/14/14.
|
||||
// Copyright (c) 2014 na. All rights reserved.
|
||||
//
|
||||
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
@interface CALayerWithClipRender : CALayer
|
||||
|
||||
+ (void)maskLayer:(CALayer *)layer inContext:(CGContextRef)ctx;
|
||||
|
||||
@end
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// CAShapeLayerWithClipRender.h
|
||||
// SVGKit-iOS
|
||||
//
|
||||
// Created by David Gileadi on 8/14/14.
|
||||
// Copyright (c) 2014 na. All rights reserved.
|
||||
//
|
||||
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
@interface CAShapeLayerWithClipRender : CAShapeLayer
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,24 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
#import "CAShapeLayerWithClipRender.h"
|
||||
|
||||
/*!
|
||||
* Overrides Apple's CAShapeLayer purely to change one method, so that hit-testing
|
||||
* is done by checking whether the hit point lies:
|
||||
*
|
||||
* "inside ANY part of the layer's CGPath"
|
||||
*
|
||||
* This is used exclusively by SVGShapeElement, but in theory works for any SVG*Element class that
|
||||
* uses CGPath to render itself.
|
||||
*
|
||||
* This is more useful than Apple's default implementation, but it might cause unexpected
|
||||
* problems in other code (not that I'm aware of any - this override appears to be a common
|
||||
* implementation, c.f. http://stackoverflow.com/questions/2944064/hit-testing-with-calayer-using-the-alpha-properties-of-the-calayer-contents
|
||||
*
|
||||
* TODO: should this layer be used in SVGEllipseElement, SVGPolygonElement, etc?
|
||||
*/
|
||||
@interface CAShapeLayerWithHitTest : CAShapeLayerWithClipRender {
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
From SVG-DOM, via Core DOM:
|
||||
|
||||
http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-667469212
|
||||
|
||||
interface CDATASection : Text {
|
||||
};
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class Text;
|
||||
#import "Text.h"
|
||||
|
||||
@interface CDATASection : Text
|
||||
|
||||
- (id)initWithValue:(NSString*) v;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// CGPathAdditions.h
|
||||
// SVGPad
|
||||
//
|
||||
// Copyright Matt Rajca 2011. All rights reserved.
|
||||
//
|
||||
|
||||
#import <CoreGraphics/CoreGraphics.h>
|
||||
|
||||
/*! From original SVGKit, but it seems to be "the opposite of translation" */
|
||||
CGPathRef CGPathCreateByOffsettingPath (CGPathRef aPath, CGFloat x, CGFloat y);
|
||||
|
||||
/*! New SVGKit: carefully named method that does what it claims to: it translates a path by the specified amount */
|
||||
CGPathRef CGPathCreateByTranslatingPath (CGPathRef aPath, CGFloat x, CGFloat y);
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS-CSSPrimitiveValue
|
||||
|
||||
interface CSSPrimitiveValue : CSSValue {
|
||||
|
||||
// UnitTypes
|
||||
const unsigned short CSS_UNKNOWN = 0;
|
||||
const unsigned short CSS_NUMBER = 1;
|
||||
const unsigned short CSS_PERCENTAGE = 2;
|
||||
const unsigned short CSS_EMS = 3;
|
||||
const unsigned short CSS_EXS = 4;
|
||||
const unsigned short CSS_PX = 5;
|
||||
const unsigned short CSS_CM = 6;
|
||||
const unsigned short CSS_MM = 7;
|
||||
const unsigned short CSS_IN = 8;
|
||||
const unsigned short CSS_PT = 9;
|
||||
const unsigned short CSS_PC = 10;
|
||||
const unsigned short CSS_DEG = 11;
|
||||
const unsigned short CSS_RAD = 12;
|
||||
const unsigned short CSS_GRAD = 13;
|
||||
const unsigned short CSS_MS = 14;
|
||||
const unsigned short CSS_S = 15;
|
||||
const unsigned short CSS_HZ = 16;
|
||||
const unsigned short CSS_KHZ = 17;
|
||||
const unsigned short CSS_DIMENSION = 18;
|
||||
const unsigned short CSS_STRING = 19;
|
||||
const unsigned short CSS_URI = 20;
|
||||
const unsigned short CSS_IDENT = 21;
|
||||
const unsigned short CSS_ATTR = 22;
|
||||
const unsigned short CSS_COUNTER = 23;
|
||||
const unsigned short CSS_RECT = 24;
|
||||
const unsigned short CSS_RGBCOLOR = 25;
|
||||
|
||||
readonly attribute unsigned short primitiveType;
|
||||
void setFloatValue(in unsigned short unitType,
|
||||
in float floatValue)
|
||||
raises(DOMException);
|
||||
float getFloatValue(in unsigned short unitType)
|
||||
raises(DOMException);
|
||||
void setStringValue(in unsigned short stringType,
|
||||
in DOMString stringValue)
|
||||
raises(DOMException);
|
||||
DOMString getStringValue()
|
||||
raises(DOMException);
|
||||
Counter getCounterValue()
|
||||
raises(DOMException);
|
||||
Rect getRectValue()
|
||||
raises(DOMException);
|
||||
RGBColor getRGBColorValue()
|
||||
raises(DOMException);
|
||||
*/
|
||||
#import "CSSValue.h"
|
||||
|
||||
typedef enum CSSPrimitiveType
|
||||
{
|
||||
CSS_UNKNOWN = 0,
|
||||
CSS_NUMBER = 1,
|
||||
CSS_PERCENTAGE = 2,
|
||||
CSS_EMS = 3,
|
||||
CSS_EXS = 4,
|
||||
CSS_PX = 5,
|
||||
CSS_CM = 6,
|
||||
CSS_MM = 7,
|
||||
CSS_IN = 8,
|
||||
CSS_PT = 9,
|
||||
CSS_PC = 10,
|
||||
CSS_DEG = 11,
|
||||
CSS_RAD = 12,
|
||||
CSS_GRAD = 13,
|
||||
CSS_MS = 14,
|
||||
CSS_S = 15,
|
||||
CSS_HZ = 16,
|
||||
CSS_KHZ = 17,
|
||||
CSS_DIMENSION = 18,
|
||||
CSS_STRING = 19,
|
||||
CSS_URI = 20,
|
||||
CSS_IDENT = 21,
|
||||
CSS_ATTR = 22,
|
||||
CSS_COUNTER = 23,
|
||||
CSS_RECT = 24,
|
||||
CSS_RGBCOLOR = 25
|
||||
} CSSPrimitiveType;
|
||||
|
||||
@interface CSSPrimitiveValue : CSSValue
|
||||
|
||||
@property(nonatomic) CSSPrimitiveType primitiveType;
|
||||
|
||||
-(void) setFloatValue:(CSSPrimitiveType) unitType floatValue:(float) floatValue;
|
||||
|
||||
-(float) getFloatValue:(CSSPrimitiveType) unitType;
|
||||
|
||||
-(void) setStringValue:(CSSPrimitiveType) stringType stringValue:(NSString*) stringValue;
|
||||
|
||||
-(NSString*) getStringValue;
|
||||
|
||||
-(/* FIXME: have to add this type: Counter*/ void) getCounterValue;
|
||||
|
||||
-(/* FIXME: have to add this type: Rect*/ void) getRectValue;
|
||||
|
||||
-(/* FIXME: have to add this type: RGBColor*/ void) getRGBColorValue;
|
||||
|
||||
@end
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
#import "CSSPrimitiveValue.h"
|
||||
|
||||
@interface CSSPrimitiveValue ()
|
||||
|
||||
@property(nonatomic) float pixelsPerInch;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS-CSSRule
|
||||
|
||||
interface CSSRule {
|
||||
|
||||
// RuleType
|
||||
const unsigned short UNKNOWN_RULE = 0;
|
||||
const unsigned short STYLE_RULE = 1;
|
||||
const unsigned short CHARSET_RULE = 2;
|
||||
const unsigned short IMPORT_RULE = 3;
|
||||
const unsigned short MEDIA_RULE = 4;
|
||||
const unsigned short FONT_FACE_RULE = 5;
|
||||
const unsigned short PAGE_RULE = 6;
|
||||
|
||||
readonly attribute unsigned short type;
|
||||
attribute DOMString cssText;
|
||||
// raises(DOMException) on setting
|
||||
|
||||
readonly attribute CSSStyleSheet parentStyleSheet;
|
||||
readonly attribute CSSRule parentRule;
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class CSSStyleSheet;
|
||||
|
||||
typedef enum CSSRuleType
|
||||
{
|
||||
UNKNOWN_RULE = 0,
|
||||
STYLE_RULE = 1,
|
||||
CHARSET_RULE = 2,
|
||||
IMPORT_RULE = 3,
|
||||
MEDIA_RULE = 4,
|
||||
FONT_FACE_RULE = 5,
|
||||
PAGE_RULE = 6
|
||||
} CSSRuleType;
|
||||
|
||||
@interface CSSRule : NSObject
|
||||
|
||||
@property(nonatomic) unsigned short type;
|
||||
@property(nonatomic,strong) NSString* cssText;
|
||||
|
||||
@property(nonatomic,strong) CSSStyleSheet* parentStyleSheet;
|
||||
@property(nonatomic,strong) CSSRule* parentRule;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,7 @@
|
||||
#import "CSSRuleList.h"
|
||||
|
||||
@interface CSSRuleList ()
|
||||
|
||||
@property(nonatomic,strong) NSMutableArray* internalArray;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS-CSSRuleList
|
||||
|
||||
interface CSSRuleList {
|
||||
readonly attribute unsigned long length;
|
||||
CSSRule item(in unsigned long index);
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "CSSRule.h"
|
||||
|
||||
@interface CSSRuleList : NSObject
|
||||
|
||||
@property(nonatomic,readonly) unsigned long length;
|
||||
|
||||
-(CSSRule*) item:(unsigned long) index;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS-CSSStyleDeclaration
|
||||
|
||||
interface CSSStyleDeclaration {
|
||||
attribute DOMString cssText;
|
||||
// raises(DOMException) on setting
|
||||
|
||||
DOMString getPropertyValue(in DOMString propertyName);
|
||||
CSSValue getPropertyCSSValue(in DOMString propertyName);
|
||||
DOMString removeProperty(in DOMString propertyName)
|
||||
raises(DOMException);
|
||||
DOMString getPropertyPriority(in DOMString propertyName);
|
||||
void setProperty(in DOMString propertyName,
|
||||
in DOMString value,
|
||||
in DOMString priority)
|
||||
raises(DOMException);
|
||||
readonly attribute unsigned long length;
|
||||
DOMString item(in unsigned long index);
|
||||
readonly attribute CSSRule parentRule;
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "CSSValue.h"
|
||||
#import "CSSRule.h"
|
||||
|
||||
@interface CSSStyleDeclaration : NSObject
|
||||
|
||||
/** NOTE: requires special treatment!
|
||||
|
||||
From spec:
|
||||
|
||||
"The parsable textual representation of the declaration block (excluding the surrounding curly braces). Setting this attribute will result in the parsing of the new value and resetting of all the properties in the declaration block including the removal or addition of properties."
|
||||
*/
|
||||
@property(nonatomic,strong) NSString* cssText;
|
||||
|
||||
-(NSString*) getPropertyValue:(NSString*) propertyName;
|
||||
-(CSSValue*) getPropertyCSSValue:(NSString*) propertyName;
|
||||
-(NSString*) removeProperty:(NSString*) propertyName;
|
||||
|
||||
-(NSString*) getPropertyPriority:(NSString*) propertyName;
|
||||
-(void) setProperty:(NSString*) propertyName value:(NSString*) value priority:(NSString*) priority;
|
||||
|
||||
@property(nonatomic) unsigned long length;
|
||||
|
||||
-(NSString*) item:(long) index;
|
||||
|
||||
@property(nonatomic,strong) CSSRule* parentRule;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS-CSSStyleRule
|
||||
|
||||
interface CSSStyleRule : CSSRule {
|
||||
attribute DOMString selectorText;
|
||||
// raises(DOMException) on setting
|
||||
|
||||
readonly attribute CSSStyleDeclaration style;
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "CSSRule.h"
|
||||
#import "CSSStyleDeclaration.h"
|
||||
|
||||
@interface CSSStyleRule : CSSRule
|
||||
|
||||
@property(nonatomic,strong) NSString* selectorText;
|
||||
@property(nonatomic,strong) CSSStyleDeclaration* style;
|
||||
|
||||
#pragma mark - methods needed for ObjectiveC implementation
|
||||
|
||||
- (id)initWithSelectorText:(NSString*) selector styleText:(NSString*) styleText;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS-CSSStyleSheet
|
||||
|
||||
interface CSSStyleSheet : stylesheets::StyleSheet {
|
||||
readonly attribute CSSRule ownerRule;
|
||||
readonly attribute CSSRuleList cssRules;
|
||||
unsigned long insertRule(in DOMString rule,
|
||||
in unsigned long index)
|
||||
raises(DOMException);
|
||||
void deleteRule(in unsigned long index)
|
||||
raises(DOMException);
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "CSSRule.h"
|
||||
#import "CSSRuleList.h"
|
||||
|
||||
@interface CSSStyleSheet : NSObject
|
||||
|
||||
|
||||
@property(nonatomic,strong) CSSRule* ownerRule;
|
||||
@property(nonatomic,strong) CSSRuleList* cssRules;
|
||||
|
||||
-(long) insertRule:(NSString*) rule index:(unsigned long) index;
|
||||
-(void) deleteRule:(unsigned long) index;
|
||||
|
||||
#pragma mark - methods needed for ObjectiveC implementation
|
||||
|
||||
- (id)initWithString:(NSString*) styleSheetBody;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS-CSSValue
|
||||
|
||||
interface CSSValue {
|
||||
|
||||
// UnitTypes
|
||||
const unsigned short CSS_INHERIT = 0;
|
||||
const unsigned short CSS_PRIMITIVE_VALUE = 1;
|
||||
const unsigned short CSS_VALUE_LIST = 2;
|
||||
const unsigned short CSS_CUSTOM = 3;
|
||||
|
||||
attribute DOMString cssText;
|
||||
// raises(DOMException) on setting
|
||||
|
||||
readonly attribute unsigned short cssValueType;
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
typedef enum CSSUnitType
|
||||
{
|
||||
CSS_INHERIT = 0,
|
||||
CSS_PRIMITIVE_VALUE = 1,
|
||||
CSS_VALUE_LIST = 2,
|
||||
CSS_CUSTOM = 3
|
||||
} CSSUnitType;
|
||||
|
||||
@interface CSSValue : NSObject
|
||||
{
|
||||
NSString* _cssText; // for subclasses to manually set
|
||||
}
|
||||
|
||||
@property(nonatomic,strong) NSString* cssText;
|
||||
@property(nonatomic) CSSUnitType cssValueType;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS-CSSValueList
|
||||
|
||||
interface CSSValueList : CSSValue {
|
||||
readonly attribute unsigned long length;
|
||||
CSSValue item(in unsigned long index);
|
||||
*/
|
||||
|
||||
#import "CSSValue.h"
|
||||
|
||||
@interface CSSValueList : CSSValue
|
||||
|
||||
@property(nonatomic,readonly) unsigned long length;
|
||||
|
||||
-(CSSValue*) item:(unsigned long) index;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface CSSValue()
|
||||
|
||||
- (id)initWithUnitType:(CSSUnitType) t;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
From SVG-DOM, via Core DOM:
|
||||
|
||||
http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-FF21A306
|
||||
|
||||
interface CharacterData : Node {
|
||||
attribute DOMString data;
|
||||
// raises(DOMException) on setting
|
||||
// raises(DOMException) on retrieval
|
||||
|
||||
readonly attribute unsigned long length;
|
||||
DOMString substringData(in unsigned long offset,
|
||||
in unsigned long count)
|
||||
raises(DOMException);
|
||||
void appendData(in DOMString arg)
|
||||
raises(DOMException);
|
||||
void insertData(in unsigned long offset,
|
||||
in DOMString arg)
|
||||
raises(DOMException);
|
||||
void deleteData(in unsigned long offset,
|
||||
in unsigned long count)
|
||||
raises(DOMException);
|
||||
void replaceData(in unsigned long offset,
|
||||
in unsigned long count,
|
||||
in DOMString arg)
|
||||
raises(DOMException);
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
/** objc won't allow this: @class Node;*/
|
||||
#import "Node.h"
|
||||
|
||||
@interface CharacterData : Node
|
||||
|
||||
@property(nonatomic,strong,readonly) NSString* data;
|
||||
|
||||
@property(nonatomic,readonly) unsigned long length;
|
||||
|
||||
-(NSString*) substringData:(unsigned long) offset count:(unsigned long) count;
|
||||
-(void) appendData:(NSString*) arg;
|
||||
-(void) insertData:(unsigned long) offset arg:(NSString*) arg;
|
||||
-(void) deleteData:(unsigned long) offset count:(unsigned long) count;
|
||||
-(void) replaceData:(unsigned long) offset count:(unsigned long) count arg:(NSString*) arg;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
From SVG-DOM, via Core DOM:
|
||||
|
||||
http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1728279322
|
||||
|
||||
interface Comment : CharacterData {
|
||||
};
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "CharacterData.h"
|
||||
#ifdef __CARBONCORE__
|
||||
// macOS's out-of-date Carbon API defined the `Comment` struct and cause naming conflict, so we need re-define it and use macro to avoid changing exist API
|
||||
#define Comment SVGKComment
|
||||
#endif
|
||||
@interface Comment : CharacterData
|
||||
|
||||
- (id)initWithValue:(NSString*) v;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,15 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
@protocol ConverterSVGToCALayer < NSObject >
|
||||
|
||||
/*!
|
||||
NB: the returned layer has - as its "name" property - the "identifier" property of the SVGElement that created it;
|
||||
but that can be overwritten by applications (for valid reasons), so we ADDITIONALLY store the identifier into a
|
||||
custom key - kSVGElementIdentifier - on the CALayer. Because it's a custom key, it's (almost) guaranteed not to be
|
||||
overwritten / altered by other application code
|
||||
*/
|
||||
- (CALayer *) newLayer;
|
||||
- (void)layoutLayer:(CALayer *)layer;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1 @@
|
||||
#define DEBUG_DOM_PARSING 0
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
There are some shared methods in DOM specification, where two classes have the same method, but
|
||||
are NOT subclass/superclass of each other. This is very bad from OOP design POV, because it means
|
||||
we end up with copy/paste duplicated code, very VERY likely to gain long term bugs.
|
||||
|
||||
Also, those methods REQUIRE a second, recursive, method or else you can't implement them easily.
|
||||
|
||||
So, we move their implementations into this helper class, so they can share implementation.
|
||||
|
||||
(c.f. Element vs Document - identical methods for getElementsByName)
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class Node, NodeList, Element; // avoiding #import here, to avoid C header loop problems.
|
||||
|
||||
#define DEBUG_DOM_MATCH_ELEMENTS_IDS_AND_NAMES 0 // For debugging SVGKit: causes debug output on getElementById etc
|
||||
|
||||
@interface DOMHelperUtilities : NSObject
|
||||
|
||||
/*! This useful method provides both the DOM level 1 and the DOM level 2 implementations of searching the tree for a node - because THEY ARE DIFFERENT
|
||||
yet very similar
|
||||
*/
|
||||
+(void) privateGetElementsByName:(NSString*) name inNamespace:(NSString*) namespaceURI childrenOfElement:(Node*) parent addToList:(NodeList*) accumulator;
|
||||
|
||||
/*! This is used in multiple base classes in DOM 1 and DOM 2 where they do NOT have shared superclasses, so we have to implement it here in a separate
|
||||
clas as a standalone method */
|
||||
+(Element*) privateGetElementById:(NSString*) idValue childrenOfElement:(Node*) parent;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,7 @@
|
||||
#import "Document.h"
|
||||
|
||||
@interface Document ()
|
||||
|
||||
@property(nonatomic,strong,readwrite) Element* documentElement;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
// Document.h
|
||||
|
||||
NOT a Cocoa / Apple document,
|
||||
NOT an SVG document,
|
||||
BUT INSTEAD: a DOM document (blame w3.org for the too-generic name).
|
||||
|
||||
Required for SVG-DOM
|
||||
|
||||
c.f.:
|
||||
|
||||
http://www.w3.org/TR/DOM-Level-2-Core/core.html#i-Document
|
||||
|
||||
interface Document : Node {
|
||||
readonly attribute DocumentType doctype;
|
||||
readonly attribute DOMImplementation implementation;
|
||||
readonly attribute Element documentElement;
|
||||
Element createElement(in DOMString tagName)
|
||||
raises(DOMException);
|
||||
DocumentFragment createDocumentFragment();
|
||||
Text createTextNode(in DOMString data);
|
||||
Comment createComment(in DOMString data);
|
||||
CDATASection createCDATASection(in DOMString data)
|
||||
raises(DOMException);
|
||||
ProcessingInstruction createProcessingInstruction(in DOMString target,
|
||||
in DOMString data)
|
||||
raises(DOMException);
|
||||
Attr createAttribute(in DOMString name)
|
||||
raises(DOMException);
|
||||
EntityReference createEntityReference(in DOMString name)
|
||||
raises(DOMException);
|
||||
NodeList getElementsByTagName(in DOMString tagname);
|
||||
// Introduced in DOM Level 2:
|
||||
Node importNode(in Node importedNode,
|
||||
in boolean deep)
|
||||
raises(DOMException);
|
||||
// Introduced in DOM Level 2:
|
||||
Element createElementNS(in DOMString namespaceURI,
|
||||
in DOMString qualifiedName)
|
||||
raises(DOMException);
|
||||
// Introduced in DOM Level 2:
|
||||
Attr createAttributeNS(in DOMString namespaceURI,
|
||||
in DOMString qualifiedName)
|
||||
raises(DOMException);
|
||||
// Introduced in DOM Level 2:
|
||||
NodeList getElementsByTagNameNS(in DOMString namespaceURI,
|
||||
in DOMString localName);
|
||||
// Introduced in DOM Level 2:
|
||||
Element getElementById(in DOMString elementId);
|
||||
};
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
/** ObjectiveC won't allow this: @class Node; */
|
||||
#import "Node.h"
|
||||
@class Element;
|
||||
#import "Element.h"
|
||||
//@class Comment;
|
||||
#import "Comment.h"
|
||||
@class CDATASection;
|
||||
#import "CDATASection.h"
|
||||
@class DocumentFragment;
|
||||
#import "DocumentFragment.h"
|
||||
@class EntityReference;
|
||||
#import "EntityReference.h"
|
||||
@class NodeList;
|
||||
#import "NodeList.h"
|
||||
@class ProcessingInstruction;
|
||||
#import "ProcessingInstruction.h"
|
||||
@class DocumentType;
|
||||
#import "DocumentType.h"
|
||||
@class AppleSucksDOMImplementation;
|
||||
#import "AppleSucksDOMImplementation.h"
|
||||
|
||||
@interface Document : Node
|
||||
|
||||
@property(nonatomic,strong,readonly) DocumentType* doctype;
|
||||
@property(nonatomic,strong,readonly) AppleSucksDOMImplementation* implementation;
|
||||
@property(nonatomic,strong,readonly) Element* documentElement;
|
||||
|
||||
|
||||
-(Element*) createElement:(NSString*) tagName __attribute__((ns_returns_retained));
|
||||
-(DocumentFragment*) createDocumentFragment __attribute__((ns_returns_retained));
|
||||
-(Text*) createTextNode:(NSString*) data __attribute__((ns_returns_retained));
|
||||
-(Comment*) createComment:(NSString*) data __attribute__((ns_returns_retained));
|
||||
-(CDATASection*) createCDATASection:(NSString*) data __attribute__((ns_returns_retained));
|
||||
-(ProcessingInstruction*) createProcessingInstruction:(NSString*) target data:(NSString*) data __attribute__((ns_returns_retained));
|
||||
-(Attr*) createAttribute:(NSString*) data __attribute__((ns_returns_retained));
|
||||
-(EntityReference*) createEntityReference:(NSString*) data __attribute__((ns_returns_retained));
|
||||
|
||||
-(NodeList*) getElementsByTagName:(NSString*) data;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(Node*) importNode:(Node*) importedNode deep:(BOOL) deep;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(Element*) createElementNS:(NSString*) namespaceURI qualifiedName:(NSString*) qualifiedName __attribute__((ns_returns_retained));
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(Attr*) createAttributeNS:(NSString*) namespaceURI qualifiedName:(NSString*) qualifiedName;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(NodeList*) getElementsByTagNameNS:(NSString*) namespaceURI localName:(NSString*) localName;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(Element*) getElementById:(NSString*) elementId;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS-DocumentCSS
|
||||
|
||||
interface DocumentCSS : stylesheets::DocumentStyle {
|
||||
CSSStyleDeclaration getOverrideStyle(in Element elt,
|
||||
in DOMString pseudoElt);
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DocumentStyle.h"
|
||||
|
||||
#import "CSSStyleDeclaration.h"
|
||||
|
||||
@class Element;
|
||||
|
||||
@protocol DocumentCSS <DocumentStyle>
|
||||
|
||||
-(CSSStyleDeclaration *)getOverrideStyle:(Element *)element pseudoElt:(NSString *)pseudoElt;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
From SVG-DOM, via Core DOM:
|
||||
|
||||
http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-B63ED1A3
|
||||
|
||||
interface DocumentFragment : Node {
|
||||
};
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
/** objc won't allow this: @class Node;*/
|
||||
#import "Node.h"
|
||||
|
||||
@interface DocumentFragment : Node
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
|
||||
http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/stylesheets.html#StyleSheets-StyleSheet-DocumentStyle
|
||||
|
||||
interface DocumentStyle {
|
||||
readonly attribute StyleSheetList styleSheets;
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "StyleSheetList.h"
|
||||
|
||||
@protocol DocumentStyle <NSObject>
|
||||
|
||||
@property(nonatomic,retain) StyleSheetList* styleSheets;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
From SVG-DOM, via Core DOM:
|
||||
|
||||
http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-412266927
|
||||
|
||||
interface DocumentType : Node {
|
||||
readonly attribute DOMString name;
|
||||
readonly attribute NamedNodeMap entities;
|
||||
readonly attribute NamedNodeMap notations;
|
||||
// Introduced in DOM Level 2:
|
||||
readonly attribute DOMString publicId;
|
||||
// Introduced in DOM Level 2:
|
||||
readonly attribute DOMString systemId;
|
||||
// Introduced in DOM Level 2:
|
||||
readonly attribute DOMString internalSubset;
|
||||
};
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Node.h"
|
||||
#import "NamedNodeMap.h"
|
||||
|
||||
@interface DocumentType : Node
|
||||
|
||||
@property(nonatomic,strong,readonly) NSString* name;
|
||||
@property(nonatomic,strong,readonly) NamedNodeMap* entities;
|
||||
@property(nonatomic,strong,readonly) NamedNodeMap* notations;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
@property(nonatomic,strong,readonly) NSString* publicId;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
@property(nonatomic,strong,readonly) NSString* systemId;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
@property(nonatomic,strong,readonly) NSString* internalSubset;
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
From SVG-DOM, via Core-DOM:
|
||||
|
||||
http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-745549614
|
||||
|
||||
interface Element : Node {
|
||||
readonly attribute DOMString tagName;
|
||||
DOMString getAttribute(in DOMString name);
|
||||
void setAttribute(in DOMString name,
|
||||
in DOMString value)
|
||||
raises(DOMException);
|
||||
void removeAttribute(in DOMString name)
|
||||
raises(DOMException);
|
||||
Attr getAttributeNode(in DOMString name);
|
||||
Attr setAttributeNode(in Attr newAttr)
|
||||
raises(DOMException);
|
||||
Attr removeAttributeNode(in Attr oldAttr)
|
||||
raises(DOMException);
|
||||
NodeList getElementsByTagName(in DOMString name);
|
||||
// Introduced in DOM Level 2:
|
||||
DOMString getAttributeNS(in DOMString namespaceURI,
|
||||
in DOMString localName);
|
||||
// Introduced in DOM Level 2:
|
||||
void setAttributeNS(in DOMString namespaceURI,
|
||||
in DOMString qualifiedName,
|
||||
in DOMString value)
|
||||
raises(DOMException);
|
||||
// Introduced in DOM Level 2:
|
||||
void removeAttributeNS(in DOMString namespaceURI,
|
||||
in DOMString localName)
|
||||
raises(DOMException);
|
||||
// Introduced in DOM Level 2:
|
||||
Attr getAttributeNodeNS(in DOMString namespaceURI,
|
||||
in DOMString localName);
|
||||
// Introduced in DOM Level 2:
|
||||
Attr setAttributeNodeNS(in Attr newAttr)
|
||||
raises(DOMException);
|
||||
// Introduced in DOM Level 2:
|
||||
NodeList getElementsByTagNameNS(in DOMString namespaceURI,
|
||||
in DOMString localName);
|
||||
// Introduced in DOM Level 2:
|
||||
boolean hasAttribute(in DOMString name);
|
||||
// Introduced in DOM Level 2:
|
||||
boolean hasAttributeNS(in DOMString namespaceURI,
|
||||
in DOMString localName);
|
||||
};
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
/** objc won't allow this: @class Node;*/
|
||||
#import "Node.h"
|
||||
@class Attr;
|
||||
#import "Attr.h"
|
||||
@class NodeList;
|
||||
#import "NodeList.h"
|
||||
|
||||
@interface Element : Node
|
||||
|
||||
@property(nonatomic,strong,readonly) NSString* tagName;
|
||||
|
||||
-(NSString*) getAttribute:(NSString*) name;
|
||||
-(void) setAttribute:(NSString*) name value:(NSString*) value;
|
||||
-(void) removeAttribute:(NSString*) name;
|
||||
-(Attr*) getAttributeNode:(NSString*) name;
|
||||
-(Attr*) setAttributeNode:(Attr*) newAttr;
|
||||
-(Attr*) removeAttributeNode:(Attr*) oldAttr;
|
||||
-(NodeList*) getElementsByTagName:(NSString*) name;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(NSString*) getAttributeNS:(NSString*) namespaceURI localName:(NSString*) localName;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(void) setAttributeNS:(NSString*) namespaceURI qualifiedName:(NSString*) qualifiedName value:(NSString*) value;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(void) removeAttributeNS:(NSString*) namespaceURI localName:(NSString*) localName;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(Attr*) getAttributeNodeNS:(NSString*) namespaceURI localName:(NSString*) localName;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(Attr*) setAttributeNodeNS:(Attr*) newAttr;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(NodeList*) getElementsByTagNameNS:(NSString*) namespaceURI localName:(NSString*) localName;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(BOOL) hasAttribute:(NSString*) name;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(BOOL) hasAttributeNS:(NSString*) namespaceURI localName:(NSString*) localName;
|
||||
|
||||
#pragma mark - Objective-C init methods (not in SVG Spec - you're supposed to use SVGDocument's createXXX methods instead)
|
||||
|
||||
- (id)initWithLocalName:(NSString*) n attributes:(NSMutableDictionary*) attributes;
|
||||
- (id)initWithQualifiedName:(NSString*) n inNameSpaceURI:(NSString*) nsURI attributes:(NSMutableDictionary*) attributes;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
From SVG-DOM, via Core DOM:
|
||||
|
||||
http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-11C98490
|
||||
|
||||
interface EntityReference : Node {
|
||||
};
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
/** objc won't allow this: @class Node; */
|
||||
#import "Node.h"
|
||||
|
||||
@interface EntityReference : Node
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/stylesheets.html#StyleSheets-MediaList
|
||||
|
||||
interface MediaList {
|
||||
attribute DOMString mediaText;
|
||||
// raises(DOMException) on setting
|
||||
|
||||
readonly attribute unsigned long length;
|
||||
DOMString item(in unsigned long index);
|
||||
void deleteMedium(in DOMString oldMedium)
|
||||
raises(DOMException);
|
||||
void appendMedium(in DOMString newMedium)
|
||||
raises(DOMException);
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface MediaList : NSObject
|
||||
|
||||
@property(nonatomic,strong) NSString* mediaText;
|
||||
@property(nonatomic) unsigned long length;
|
||||
|
||||
-(NSString*) item:(unsigned long) index;
|
||||
-(void) deleteMedium:(NSString*) oldMedium;
|
||||
-(void) appendMedium:(NSString*) newMedium;
|
||||
|
||||
@end
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// NSCharacterSet+SVGKExtensions.h
|
||||
// Avatar
|
||||
//
|
||||
// Created by Devin Chalmers on 3/6/13.
|
||||
// Copyright (c) 2013 DJZ. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NSCharacterSet (SVGKExtensions)
|
||||
|
||||
+ (NSCharacterSet *)SVGWhitespaceCharacterSet;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// NSData+NSInputStream.h
|
||||
// Tidbits
|
||||
//
|
||||
// Created by Ewan Mellor on 6/16/13.
|
||||
// Copyright (c) 2013 Tipbit, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NSData (NSInputStream)
|
||||
|
||||
/**
|
||||
* @param capacity May be NSUIntegerMax, in which case just an ordinary [NSMutableData data] is used. Otherwise this is given to NSMutableData dataWithCapacity:].
|
||||
* @param error May be nil.
|
||||
* @return The data or nil on failure in which case *error will be set.
|
||||
*/
|
||||
+(NSData*)dataWithContentsOfStream:(NSInputStream*)input initialCapacity:(NSUInteger)capacity error:(NSError **)error;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
From SVG-DOM, via Core-DOM:
|
||||
|
||||
http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1780488922
|
||||
|
||||
interface NamedNodeMap {
|
||||
Node getNamedItem(in DOMString name);
|
||||
Node setNamedItem(in Node arg)
|
||||
raises(DOMException);
|
||||
Node removeNamedItem(in DOMString name)
|
||||
raises(DOMException);
|
||||
Node item(in unsigned long index);
|
||||
readonly attribute unsigned long length;
|
||||
// Introduced in DOM Level 2:
|
||||
Node getNamedItemNS(in DOMString namespaceURI,
|
||||
in DOMString localName);
|
||||
// Introduced in DOM Level 2:
|
||||
Node setNamedItemNS(in Node arg)
|
||||
raises(DOMException);
|
||||
// Introduced in DOM Level 2:
|
||||
Node removeNamedItemNS(in DOMString namespaceURI,
|
||||
in DOMString localName)
|
||||
raises(DOMException);
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class Node;
|
||||
#import "Node.h"
|
||||
|
||||
@interface NamedNodeMap : NSObject </** needed so we can output SVG text in the [Node appendToXML:..] methods */ NSCopying>
|
||||
|
||||
-(Node*) getNamedItem:(NSString*) name;
|
||||
-(Node*) setNamedItem:(Node*) arg;
|
||||
-(Node*) removeNamedItem:(NSString*) name;
|
||||
-(Node*) item:(unsigned long) index;
|
||||
|
||||
@property(readonly) unsigned long length;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(Node*) getNamedItemNS:(NSString*) namespaceURI localName:(NSString*) localName;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(Node*) setNamedItemNS:(Node*) arg;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(Node*) removeNamedItemNS:(NSString*) namespaceURI localName:(NSString*) localName;
|
||||
|
||||
#pragma mark - MISSING METHOD FROM SVG Spec, without which you cannot parse documents (don't understand how they intended you to fulfil the spec without this method)
|
||||
|
||||
-(Node*) setNamedItemNS:(Node*) arg inNodeNamespace:(NSString*) nodesNamespace;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,17 @@
|
||||
@interface NamedNodeMap ()
|
||||
|
||||
/**
|
||||
DOM1 is very basic and ignores namespaces - dangerous! It's recommended to avoid DOM1 calls throughout your apps and code!
|
||||
|
||||
@return an Array of "nodes from the nodemap (Node)"
|
||||
*/
|
||||
-(NSArray*) allNodesUnsortedDOM1;
|
||||
|
||||
/**
|
||||
DOM2 requires everything to have a namespace - much better than DOM1
|
||||
|
||||
@return a Dictionary of "namespace (string)" mapped to "node from nodemap (Node)"
|
||||
*/
|
||||
-(NSDictionary*) allNodesUnsortedDOM2;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
Makes the writable properties all package-private, effectively
|
||||
*/
|
||||
#import "Node.h"
|
||||
|
||||
@interface Node()
|
||||
@property(nonatomic,strong,readwrite) NSString* nodeName;
|
||||
@property(nonatomic,strong,readwrite) NSString* nodeValue;
|
||||
|
||||
@property(nonatomic,readwrite) DOMNodeType nodeType;
|
||||
@property(nonatomic,weak,readwrite) Node* parentNode;
|
||||
@property(nonatomic,strong,readwrite) NodeList* childNodes;
|
||||
@property(nonatomic,strong,readwrite) NamedNodeMap* attributes;
|
||||
|
||||
@property(nonatomic,weak,readwrite) Document* ownerDocument;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
@property(nonatomic,strong,readwrite) NSString* namespaceURI;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
@property(nonatomic,strong,readwrite) NSString* prefix;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
@property(nonatomic,strong,readwrite) NSString* localName;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
// Node.h
|
||||
*
|
||||
http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247
|
||||
|
||||
interface Node {
|
||||
|
||||
// NodeType
|
||||
const unsigned short ELEMENT_NODE = 1;
|
||||
const unsigned short ATTRIBUTE_NODE = 2;
|
||||
const unsigned short TEXT_NODE = 3;
|
||||
const unsigned short CDATA_SECTION_NODE = 4;
|
||||
const unsigned short ENTITY_REFERENCE_NODE = 5;
|
||||
const unsigned short ENTITY_NODE = 6;
|
||||
const unsigned short PROCESSING_INSTRUCTION_NODE = 7;
|
||||
const unsigned short COMMENT_NODE = 8;
|
||||
const unsigned short DOCUMENT_NODE = 9;
|
||||
const unsigned short DOCUMENT_TYPE_NODE = 10;
|
||||
const unsigned short DOCUMENT_FRAGMENT_NODE = 11;
|
||||
const unsigned short NOTATION_NODE = 12;
|
||||
|
||||
readonly attribute DOMString nodeName;
|
||||
attribute DOMString nodeValue;
|
||||
// raises(DOMException) on setting
|
||||
// raises(DOMException) on retrieval
|
||||
|
||||
readonly attribute unsigned short nodeType;
|
||||
readonly attribute Node parentNode;
|
||||
readonly attribute NodeList childNodes;
|
||||
readonly attribute Node firstChild;
|
||||
readonly attribute Node lastChild;
|
||||
readonly attribute Node previousSibling;
|
||||
readonly attribute Node nextSibling;
|
||||
readonly attribute NamedNodeMap attributes;
|
||||
// Modified in DOM Level 2:
|
||||
readonly attribute Document ownerDocument;
|
||||
Node insertBefore(in Node newChild,
|
||||
in Node refChild)
|
||||
raises(DOMException);
|
||||
Node replaceChild(in Node newChild,
|
||||
in Node oldChild)
|
||||
raises(DOMException);
|
||||
Node removeChild(in Node oldChild)
|
||||
raises(DOMException);
|
||||
Node appendChild(in Node newChild)
|
||||
raises(DOMException);
|
||||
boolean hasChildNodes();
|
||||
Node cloneNode(in boolean deep);
|
||||
// Modified in DOM Level 2:
|
||||
void normalize();
|
||||
// Introduced in DOM Level 2:
|
||||
boolean isSupported(in DOMString feature,
|
||||
in DOMString version);
|
||||
// Introduced in DOM Level 2:
|
||||
readonly attribute DOMString namespaceURI;
|
||||
// Introduced in DOM Level 2:
|
||||
attribute DOMString prefix;
|
||||
// raises(DOMException) on setting
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
readonly attribute DOMString localName;
|
||||
// Introduced in DOM Level 2:
|
||||
boolean hasAttributes();
|
||||
};
|
||||
|
||||
-------------------------------
|
||||
|
||||
// DOM Level 3 that we *need*, partly because SVG Spec makes one brief reference to it: http://www.w3.org/TR/SVG/text.html#InterfaceSVGTextContentElement
|
||||
|
||||
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-textContent
|
||||
|
||||
// Introduced in DOM Level 3:
|
||||
attribute DOMString textContent;
|
||||
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class Document;
|
||||
/** objc won't allow this: #import "Document.h"*/
|
||||
@class NodeList;
|
||||
/** objc won't allow this: #import "NodeList.h"*/
|
||||
@class NamedNodeMap;
|
||||
/** objc won't allow this: #import "NamedNodeMap.h"*/
|
||||
|
||||
typedef enum DOMNodeType
|
||||
{
|
||||
DOMNodeType_ELEMENT_NODE = 1,
|
||||
DOMNodeType_ATTRIBUTE_NODE = 2,
|
||||
DOMNodeType_TEXT_NODE = 3,
|
||||
DOMNodeType_CDATA_SECTION_NODE = 4,
|
||||
DOMNodeType_ENTITY_REFERENCE_NODE = 5,
|
||||
DOMNodeType_ENTITY_NODE = 6,
|
||||
DOMNodeType_PROCESSING_INSTRUCTION_NODE = 7,
|
||||
DOMNodeType_COMMENT_NODE = 8,
|
||||
DOMNodeType_DOCUMENT_NODE = 9,
|
||||
DOMNodeType_DOCUMENT_TYPE_NODE = 10,
|
||||
DOMNodeType_DOCUMENT_FRAGMENT_NODE = 11,
|
||||
DOMNodeType_NOTATION_NODE = 12
|
||||
} DOMNodeType;
|
||||
|
||||
@interface Node : NSObject
|
||||
|
||||
@property(nonatomic,strong,readonly) NSString* nodeName;
|
||||
@property(nonatomic,strong,readonly) NSString* nodeValue;
|
||||
|
||||
@property(nonatomic,readonly) DOMNodeType nodeType;
|
||||
@property(nonatomic,weak,readonly) Node* parentNode;
|
||||
@property(nonatomic,strong,readonly) NodeList* childNodes;
|
||||
@property(nonatomic,weak,readonly) Node* firstChild;
|
||||
@property(nonatomic,weak,readonly) Node* lastChild;
|
||||
@property(nonatomic,weak,readonly) Node* previousSibling;
|
||||
@property(nonatomic,weak,readonly) Node* nextSibling;
|
||||
@property(nonatomic,strong,readonly) NamedNodeMap* attributes; /**< NB: according to DOM Spec, this is null if the Node is NOT subclassed as an Element */
|
||||
|
||||
// Modified in DOM Level 2:
|
||||
@property(nonatomic,weak,readonly) Document* ownerDocument;
|
||||
|
||||
-(Node*) insertBefore:(Node*) newChild refChild:(Node*) refChild;
|
||||
|
||||
-(Node*) replaceChild:(Node*) newChild oldChild:(Node*) oldChild;
|
||||
-(Node*) removeChild:(Node*) oldChild;
|
||||
-(Node*) appendChild:(Node*) newChild;
|
||||
|
||||
@property(nonatomic) BOOL hasChildNodes;
|
||||
|
||||
-(Node*) cloneNode:(BOOL) deep;
|
||||
|
||||
// Modified in DOM Level 2:
|
||||
-(void) normalize;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
-(BOOL) isSupportedFeature:(NSString*) feature version:(NSString*) version;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
@property(nonatomic,strong,readonly) NSString* namespaceURI;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
@property(nonatomic,strong,readonly) NSString* prefix;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
@property(nonatomic,strong,readonly) NSString* localName;
|
||||
|
||||
// Introduced in DOM Level 2:
|
||||
@property(nonatomic) BOOL hasAttributes;
|
||||
|
||||
// DOM Level 3 that we *need*, partly because SVG Spec makes one brief reference to it: http://www.w3.org/TR/SVG/text.html#InterfaceSVGTextContentElement
|
||||
|
||||
// Introduced in DOM Level 3: http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-textContent
|
||||
@property(weak, nonatomic,readonly) NSString* textContent;
|
||||
|
||||
#pragma mark - Objective-C init methods (not in SVG Spec - you're supposed to use SVGDocument's createXXX methods instead)
|
||||
/** Designated initializers - 2 pairs (one for DOM 1, no namespace, the other for DOM 2, with namespace) of 2 methods (one for nodes that REQUIRE a value, the other for nodes that MUST NOT have a value) */
|
||||
- (id)initType:(DOMNodeType) nt name:(NSString*) n;
|
||||
- (id)initType:(DOMNodeType) nt name:(NSString*) n value:(NSString*) v;
|
||||
- (id)initType:(DOMNodeType) nt name:(NSString*) n inNamespace:(NSString*) nsURI;
|
||||
- (id)initType:(DOMNodeType) nt name:(NSString*) n value:(NSString*) v inNamespace:(NSString*) nsURI;
|
||||
|
||||
#pragma mark - Objective-C serialization method to serialize a DOM tree back to XML (used heavily in SVGKit's output/conversion features)
|
||||
|
||||
/** EXPERIMENTAL: not fully implemented or tested - this correctly outputs most SVG files, but is missing esoteric
|
||||
features such as EntityReferences, currently they are simply ignored
|
||||
|
||||
This method should be used hand-in-hand with the proprietary SVGDocument method "allNamespaces" and the SVGSVGElement method "
|
||||
|
||||
@param outputString an empty MUTABLE string we can accumulate with output (NB: this method uses a lot of memory, needs to accumulate data)
|
||||
|
||||
@param prefixesByKNOWNNamespace (required): a dictionary mapping "XML namespace URI" to "prefix to use inside the xml-tags", e.g. "http://w3.org/2000/svg" usually is mapped to "svg" (or to "", signifying it's the default namespace). This MUST include ALL NAMESPACES FOUND IN THE DOCUMENT (it's recommended you use SVGDocument's "allPrefixesByNamespace" method, and some post-processing, to get an accurate input here)
|
||||
|
||||
@param prefixesByACTIVENamespace (required): a mutable dictionary listing which elements of the other dictionary are active in-scope - i.e. which namespaces have been output by this node or a higher node in the tree. You pass-in an empty dictionary to the root SVG node and it fills it in as required.
|
||||
*/
|
||||
-(void) appendXMLToString:(NSMutableString*) outputString availableNamespaces:(NSDictionary*) prefixesByKNOWNNamespace activeNamespaces:(NSMutableDictionary*) prefixesByACTIVENamespace;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
Makes the writable properties all package-private, effectively
|
||||
*/
|
||||
|
||||
#import "NodeList.h"
|
||||
|
||||
@interface NodeList()
|
||||
|
||||
@property(nonatomic,strong) NSMutableArray* internalArray;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
Implemented internally via an NSArray
|
||||
|
||||
NB: contains a slight "upgrade" from the SVG Spec to make it support Objective-C's
|
||||
Fast Enumeration feature
|
||||
|
||||
From SVG DOM, via CoreDOM:
|
||||
|
||||
http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-536297177
|
||||
|
||||
interface NodeList {
|
||||
Node item(in unsigned long index);
|
||||
readonly attribute unsigned long length;
|
||||
};
|
||||
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class Node;
|
||||
#import "Node.h"
|
||||
|
||||
@interface NodeList : NSObject <NSFastEnumeration>
|
||||
|
||||
@property(readonly) NSUInteger length;
|
||||
|
||||
-(Node*) item:(NSUInteger) index;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
SVG-DOM, via Core DOM:
|
||||
|
||||
http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1004215813
|
||||
|
||||
interface ProcessingInstruction : Node {
|
||||
readonly attribute DOMString target;
|
||||
attribute DOMString data;
|
||||
// raises(DOMException) on setting
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
/** objc won't allow this: @class Node;*/
|
||||
#import "Node.h"
|
||||
|
||||
@interface ProcessingInstruction : Node
|
||||
@property(nonatomic,strong,readonly) NSString* target;
|
||||
@property(nonatomic,strong,readonly) NSString* data;
|
||||
|
||||
-(id) initProcessingInstruction:(NSString*) target value:(NSString*) data;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,42 @@
|
||||
/*!
|
||||
SVGAngle
|
||||
|
||||
http://www.w3.org/TR/SVG/types.html#InterfaceSVGAngle
|
||||
|
||||
// Angle Unit Types
|
||||
const unsigned short SVG_ANGLETYPE_UNKNOWN = 0;
|
||||
const unsigned short SVG_ANGLETYPE_UNSPECIFIED = 1;
|
||||
const unsigned short SVG_ANGLETYPE_DEG = 2;
|
||||
const unsigned short SVG_ANGLETYPE_RAD = 3;
|
||||
const unsigned short SVG_ANGLETYPE_GRAD = 4;
|
||||
|
||||
readonly attribute unsigned short unitType;
|
||||
attribute float value setraises(DOMException);
|
||||
attribute float valueInSpecifiedUnits setraises(DOMException);
|
||||
attribute DOMString valueAsString setraises(DOMException);
|
||||
|
||||
void newValueSpecifiedUnits(in unsigned short unitType, in float valueInSpecifiedUnits) raises(DOMException);
|
||||
void convertToSpecifiedUnits(in unsigned short unitType) raises(DOMException);
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface SVGAngle : NSObject
|
||||
|
||||
/*! Angle Unit Types */
|
||||
typedef enum SVGKAngleType
|
||||
{
|
||||
SVG_ANGLETYPE_UNKNOWN = 0,
|
||||
SVG_ANGLETYPE_UNSPECIFIED = 1,
|
||||
SVG_ANGLETYPE_DEG = 2,
|
||||
SVG_ANGLETYPE_RAD = 3,
|
||||
SVG_ANGLETYPE_GRAD = 4
|
||||
} SVGKAngleType;
|
||||
|
||||
@property(nonatomic, readonly) SVGKAngleType unitType;
|
||||
@property(nonatomic) float value;
|
||||
@property(nonatomic) float valueInSpecifiedUnits;
|
||||
@property(nonatomic,strong) NSString* valueAsString;
|
||||
|
||||
-(void) newValueSpecifiedUnits:(SVGKAngleType) unitType valueInSpecifiedUnits:(float) valueInSpecifiedUnits;
|
||||
-(void) convertToSpecifiedUnits:(SVGKAngleType) unitType;
|
||||
@end
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
http://www.w3.org/TR/SVG/coords.html#InterfaceSVGAnimatedPreserveAspectRatio
|
||||
|
||||
readonly attribute SVGPreserveAspectRatio baseVal;
|
||||
readonly attribute SVGPreserveAspectRatio animVal;
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SVGPreserveAspectRatio.h"
|
||||
|
||||
@interface SVGAnimatedPreserveAspectRatio : NSObject
|
||||
|
||||
@property(nonatomic,strong) SVGPreserveAspectRatio* baseVal;
|
||||
@property(nonatomic,strong, readonly) SVGPreserveAspectRatio* animVal;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// SVGCircleElement.h
|
||||
// SVGKit
|
||||
//
|
||||
// Copyright Matt Rajca 2010-2011. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SVGEllipseElement.h"
|
||||
|
||||
@interface SVGCircleElement : SVGEllipseElement { }
|
||||
|
||||
@property (nonatomic, readonly) CGFloat r;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
http://www.w3.org/TR/SVG/masking.html#InterfaceSVGClipPathElement
|
||||
|
||||
interface SVGClipPathElement : SVGElement,
|
||||
SVGTests,
|
||||
SVGLangSpace,
|
||||
SVGExternalResourcesRequired,
|
||||
SVGStylable,
|
||||
SVGTransformable,
|
||||
SVGUnitTypes {
|
||||
*/
|
||||
|
||||
#import "SVGElement.h"
|
||||
#import "SVGElement_ForParser.h"
|
||||
|
||||
#import "ConverterSVGToCALayer.h"
|
||||
#import "SVGTransformable.h"
|
||||
#import "SVGUnitTypes.h"
|
||||
|
||||
|
||||
// Does NOT implement ConverterSVGToCALayer because <clipPath> elements are never rendered directly; they're only referenced via clip-path attributes in other elements
|
||||
@interface SVGClipPathElement : SVGElement <SVGTransformable, SVGStylable>
|
||||
|
||||
@property(nonatomic, readonly) SVG_UNIT_TYPE clipPathUnits;
|
||||
|
||||
- (CALayer *) newLayer;
|
||||
- (void)layoutLayer:(CALayer *)layer toMaskLayer:(CALayer *)maskThis;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
http://www.w3.org/TR/SVG/struct.html#InterfaceSVGDefsElement
|
||||
|
||||
*/
|
||||
#import "SVGElement.h"
|
||||
|
||||
@interface SVGDefsElement : SVGElement { }
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// SVGDescriptionElement.h
|
||||
// SVGKit
|
||||
//
|
||||
// Copyright Matt Rajca 2010-2011. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SVGElement.h"
|
||||
|
||||
@interface SVGDescriptionElement : SVGElement { }
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
SVG DOM, cf:
|
||||
|
||||
http://www.w3.org/TR/SVG11/struct.html#InterfaceSVGDocument
|
||||
|
||||
interface SVGDocument : Document,
|
||||
DocumentEvent {
|
||||
readonly attribute DOMString title;
|
||||
readonly attribute DOMString referrer;
|
||||
readonly attribute DOMString domain;
|
||||
readonly attribute DOMString URL;
|
||||
readonly attribute SVGSVGElement rootElement;
|
||||
};
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Document.h"
|
||||
#import "SVGSVGElement.h"
|
||||
|
||||
@interface SVGDocument : Document
|
||||
|
||||
@property (nonatomic, strong, readonly) NSString* title;
|
||||
@property (nonatomic, strong, readonly) NSString* referrer;
|
||||
@property (nonatomic, strong, readonly) NSString* domain;
|
||||
@property (nonatomic, strong, readonly) NSString* URL;
|
||||
@property (nonatomic, strong, readonly) SVGSVGElement* rootElement;
|
||||
|
||||
#pragma mark - Objective-C init methods (not part of DOM spec, but necessary!)
|
||||
|
||||
- (id)init;
|
||||
|
||||
#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
|
||||
|
||||
/**
|
||||
Recursively goes through the document finding all declared namespaces in-use by any tag or attribute.
|
||||
|
||||
@return a dictionary mapping "namespace" to "ARRAY of prefix-strings"
|
||||
*/
|
||||
-(NSMutableDictionary*) allPrefixesByNamespace;
|
||||
|
||||
/**
|
||||
As per allPrefixesByNamespace, but takes the output and guarantees that:
|
||||
|
||||
1. There is AT MOST ONE namespace with no prefix
|
||||
2. The "prefixless" namespace is the SVG namespace (if possible. This should always be possible for an SVG doc!)
|
||||
3. All other namespaces have EXACTLY ONE prefix (if there are multiple, it discards excess ones)
|
||||
4. All prefixes are UNIQUE (not used by more than one Namespace)
|
||||
|
||||
This is critically important when writing-out an SVG file to disk - As far as I can tell, it's a major ommission from
|
||||
the XML Spec (which SVG sits on top of). Without this info, you can't construct the appropriate/correct "xmlns" directives
|
||||
at the start of a file.
|
||||
|
||||
USAGE INSTRUCTIONS:
|
||||
|
||||
1. Call this method to get the complete list of namespaces, including any prefixes used
|
||||
2. Invoke Node's "appendXMLToString:..." method, passing-in this output, so it can correctly output prefixes for all nodes and subnodes
|
||||
|
||||
@return a dictionary mapping "namespace" to "prefix-string or empty-string for the default namespace"
|
||||
*/
|
||||
-(NSMutableDictionary*) allPrefixesByNamespaceNormalized;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
Makes the writable properties all package-private, effectively
|
||||
*/
|
||||
|
||||
#import "SVGDocument.h"
|
||||
|
||||
@interface SVGDocument ()
|
||||
@property (nonatomic, strong, readwrite) NSString* title;
|
||||
@property (nonatomic, strong, readwrite) NSString* referrer;
|
||||
@property (nonatomic, strong, readwrite) NSString* domain;
|
||||
@property (nonatomic, strong, readwrite) NSString* URL;
|
||||
@property (nonatomic, strong, readwrite) SVGSVGElement* rootElement;
|
||||
@end
|
||||
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
SVGElement
|
||||
|
||||
http://www.w3.org/TR/SVG/types.html#InterfaceSVGElement
|
||||
|
||||
NB: "id" is illegal in Objective-C language, so we use "identifier" instead
|
||||
*/
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
#import "Element.h"
|
||||
#import "Node+Mutable.h"
|
||||
#import "SVGStylable.h"
|
||||
#import "SVGLength.h"
|
||||
|
||||
#define DEBUG_SVG_ELEMENT_PARSING 0
|
||||
|
||||
@class SVGSVGElement;
|
||||
//obj-c's compiler sucks, and doesn't allow this line: #import "SVGSVGElement.h"
|
||||
|
||||
@interface SVGElement : Element <SVGStylable>
|
||||
|
||||
@property (nonatomic, readwrite, strong) NSString *identifier; // 'id' is reserved in Obj-C, so we have to break SVG Spec here, slightly
|
||||
@property (nonatomic, strong) NSString* xmlbase;
|
||||
/*!
|
||||
|
||||
http://www.w3.org/TR/SVG/intro.html#TermSVGDocumentFragment
|
||||
|
||||
SVG document fragment
|
||||
The XML document sub-tree which starts with an ‘svg’ element. An SVG document fragment can consist of a stand-alone SVG document, or a fragment of a parent XML document enclosed by an ‘svg’ element. When an ‘svg’ element is a descendant of another ‘svg’ element, there are two SVG document fragments, one for each ‘svg’ element. (One SVG document fragment is contained within another SVG document fragment.)
|
||||
*/
|
||||
@property (nonatomic, weak) SVGSVGElement* rootOfCurrentDocumentFragment;
|
||||
|
||||
/*! The viewport is set / re-set whenever an SVG node specifies a "width" (and optionally: a "height") attribute,
|
||||
assuming that SVG node is one of: svg, symbol, image, foreignobject
|
||||
|
||||
The spec isn't clear what happens if this element redefines the viewport itself, but IMHO it implies that the
|
||||
viewportElement becomes a reference to "self" */
|
||||
@property (nonatomic, weak) SVGElement* viewportElement;
|
||||
|
||||
|
||||
#pragma mark - NON-STANDARD features of class (these are things that are NOT in the SVG spec, and should NOT be in SVGKit's implementation - they should be moved to a different class, although WE DO STILL NEED THESE in order to implement the spec, and to provide SVGKit features!)
|
||||
|
||||
/*! This is used when generating CALayer objects, to store the id of the SVGElement that created the CALayer */
|
||||
#define kSVGElementIdentifier @"SVGElementIdentifier"
|
||||
|
||||
|
||||
#pragma mark - SVG-spec supporting methods that aren't in the Spec itself
|
||||
|
||||
- (id)initWithLocalName:(NSString*) n attributes:(NSMutableDictionary*) attributes;
|
||||
- (id)initWithQualifiedName:(NSString*) n inNameSpaceURI:(NSString*) nsURI attributes:(NSMutableDictionary*) attributes;
|
||||
|
||||
-(void) reCalculateAndSetViewportElementReferenceUsingFirstSVGAncestor:(SVGElement*) firstAncestor;
|
||||
|
||||
/**
|
||||
Convenience method for reading an attribute (SVG defines all as strings), converting it into an SVGLength object
|
||||
*/
|
||||
-(SVGLength*) getAttributeAsSVGLength:(NSString*) attributeName;
|
||||
|
||||
#pragma mark - CSS cascading special attributes. c.f. full list here: http://www.w3.org/TR/SVG/propidx.html
|
||||
|
||||
-(NSString*) cascadedValueForStylableProperty:(NSString*) stylableProperty;
|
||||
-(NSString*) cascadedValueForStylableProperty:(NSString*) stylableProperty inherit:(BOOL)inherit;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
http://www.w3.org/TR/SVG/struct.html#InterfaceSVGElementInstance
|
||||
|
||||
interface SVGElementInstance : EventTarget {
|
||||
readonly attribute SVGElement correspondingElement;
|
||||
readonly attribute SVGUseElement correspondingUseElement;
|
||||
readonly attribute SVGElementInstance parentNode;
|
||||
readonly attribute SVGElementInstanceList childNodes;
|
||||
readonly attribute SVGElementInstance firstChild;
|
||||
readonly attribute SVGElementInstance lastChild;
|
||||
readonly attribute SVGElementInstance previousSibling;
|
||||
readonly attribute SVGElementInstance nextSibling;
|
||||
*/
|
||||
|
||||
#import "SVGElement.h"
|
||||
#import "SVGElementInstanceList.h"
|
||||
|
||||
@class SVGUseElement;
|
||||
#import "SVGUseElement.h"
|
||||
|
||||
/**
|
||||
ADDITIONAL IMPLEMENTATION NOTES:
|
||||
|
||||
We make the two back-links into the SVG DOM Tree ("correspondingElement" and "correspondingUseElement") weak references to prevent
|
||||
a retain-cycle.
|
||||
|
||||
If you delete parts of the original tree, but don't do anything to update your USE tags / elements, then ... the back-links will
|
||||
become nil. This seems the most rational, "what you would expect", behaviour.
|
||||
*/
|
||||
|
||||
@interface SVGElementInstance : NSObject
|
||||
|
||||
|
||||
/*The corresponding element to which this object is an instance. For example, if a ‘use’ element references a ‘rect’ element, then an SVGElementInstance is created, with its correspondingElement being the SVGRectElement object for the ‘rect’ element. */
|
||||
@property(nonatomic, weak, readonly) SVGElement* correspondingElement;
|
||||
|
||||
|
||||
/* The corresponding ‘use’ element to which this SVGElementInstance object belongs. When ‘use’ elements are nested (e.g., a ‘use’ references another ‘use’ which references a graphics element such as a ‘rect’), then the correspondingUseElement is the outermost ‘use’ (i.e., the one which indirectly references the ‘rect’, not the one with the direct reference). */
|
||||
@property(nonatomic, weak, readonly) SVGUseElement* correspondingUseElement;
|
||||
|
||||
/* The parent of this SVGElementInstance within the instance tree. All SVGElementInstance objects have a parent except the SVGElementInstance which corresponds to the element which was directly referenced by the ‘use’ element, in which case parentNode is null. */
|
||||
@property(nonatomic,strong, readonly) SVGElementInstance* parentNode;
|
||||
|
||||
/* An SVGElementInstanceList that contains all children of this SVGElementInstance within the instance tree. If there are no children, this is an SVGElementInstanceList containing no entries (i.e., an empty list).
|
||||
firstChild (readonly SVGElementInstance) */
|
||||
@property(nonatomic,strong, readonly) SVGElementInstanceList* childNodes;
|
||||
|
||||
|
||||
/* The first child of this SVGElementInstance within the instance tree. If there is no such SVGElementInstance, this returns null. */
|
||||
@property(nonatomic,strong, readonly) SVGElementInstance* firstChild;
|
||||
|
||||
/* The last child of this SVGElementInstance within the instance tree. If there is no such SVGElementInstance, this returns null. */
|
||||
@property(nonatomic,strong, readonly) SVGElementInstance* lastChild;
|
||||
|
||||
/* The SVGElementInstance immediately preceding this SVGElementInstance. If there is no such SVGElementInstance, this returns null. */
|
||||
@property(nonatomic,strong, readonly) SVGElementInstance* previousSibling;
|
||||
|
||||
/* The SVGElementInstance immediately following this SVGElementInstance. If there is no such SVGElementInstance, this returns null. */
|
||||
@property(nonatomic,strong, readonly) SVGElementInstance* nextSibling;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
http://www.w3.org/TR/SVG/struct.html#InterfaceSVGElementInstanceList
|
||||
|
||||
interface SVGElementInstanceList {
|
||||
|
||||
readonly attribute unsigned long length;
|
||||
|
||||
SVGElementInstance item(in unsigned long index);
|
||||
*/
|
||||
|
||||
#import "SVGElement.h"
|
||||
|
||||
@class SVGElementInstance;
|
||||
|
||||
@interface SVGElementInstanceList : SVGElement
|
||||
|
||||
@property(nonatomic, readonly) unsigned long length;
|
||||
|
||||
-(SVGElementInstance*) item:(unsigned long) index;
|
||||
|
||||
@end
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// SVGElementInstanceList_Internal.h
|
||||
// SVGKit-iOS
|
||||
//
|
||||
// Created by adam on 29/09/2012.
|
||||
// Copyright (c) 2012 na. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SVGElementInstanceList.h"
|
||||
|
||||
@interface SVGElementInstanceList ()
|
||||
|
||||
@property(nonatomic,strong) NSMutableArray* internalArray;
|
||||
|
||||
@end
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
#import "SVGElementInstance.h"
|
||||
|
||||
@interface SVGElementInstance ()
|
||||
@property(nonatomic,weak, readwrite) SVGElement* correspondingElement;
|
||||
@property(nonatomic,weak, readwrite) SVGUseElement* correspondingUseElement;
|
||||
@property(nonatomic,strong, readwrite) SVGElementInstance* parentNode;
|
||||
@property(nonatomic,strong, readwrite) SVGElementInstanceList* childNodes;
|
||||
@end
|
||||
@@ -0,0 +1,18 @@
|
||||
#import "SVGElement.h"
|
||||
|
||||
#import "SVGKParseResult.h"
|
||||
|
||||
@interface SVGElement ()
|
||||
|
||||
|
||||
+ (BOOL)shouldStoreContent; // to optimize parser, default is NO
|
||||
|
||||
- (void)loadDefaults; // should be overriden to set element defaults
|
||||
|
||||
/*! Overridden by sub-classes. Be sure to call [super postProcessAttributesAddingErrorsTo:attributes];
|
||||
Returns nil, or an error if something failed trying to parse attributes (usually:
|
||||
unsupported SVG feature that's not implemented yet)
|
||||
*/
|
||||
- (void)postProcessAttributesAddingErrorsTo:(SVGKParseResult *)parseResult;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// SVGEllipseElement.h
|
||||
// SVGKit
|
||||
//
|
||||
// Copyright Matt Rajca 2010-2011. All rights reserved.
|
||||
//
|
||||
|
||||
#import "BaseClassForAllSVGBasicShapes.h"
|
||||
#import "BaseClassForAllSVGBasicShapes_ForSubclasses.h"
|
||||
|
||||
@interface SVGEllipseElement : BaseClassForAllSVGBasicShapes { }
|
||||
|
||||
@property (nonatomic, readonly) CGFloat cx;
|
||||
@property (nonatomic, readonly) CGFloat cy;
|
||||
@property (nonatomic, readonly) CGFloat rx;
|
||||
@property (nonatomic, readonly) CGFloat ry;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* http://www.w3.org/TR/SVG/types.html#InterfaceSVGFitToViewBox
|
||||
|
||||
interface SVGFitToViewBox {
|
||||
readonly attribute SVGAnimatedRect viewBox;
|
||||
readonly attribute SVGAnimatedPreserveAspectRatio preserveAspectRatio;
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
#import "SVGRect.h"
|
||||
#import "SVGAnimatedPreserveAspectRatio.h"
|
||||
|
||||
@protocol SVGFitToViewBox <NSObject>
|
||||
|
||||
@property (nonatomic) /* SVGAnimatedRect */ SVGRect viewBox;
|
||||
|
||||
@property(nonatomic,retain) SVGAnimatedPreserveAspectRatio* preserveAspectRatio;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
http://www.w3.org/TR/SVG/struct.html#InterfaceSVGGElement
|
||||
|
||||
interface SVGGElement : SVGElement,
|
||||
SVGTests,
|
||||
SVGLangSpace,
|
||||
SVGExternalResourcesRequired,
|
||||
SVGStylable,
|
||||
SVGTransformable {
|
||||
*/
|
||||
|
||||
#import "SVGElement.h"
|
||||
#import "SVGElement_ForParser.h"
|
||||
|
||||
#import "ConverterSVGToCALayer.h"
|
||||
#import "SVGTransformable.h"
|
||||
|
||||
|
||||
@interface SVGGElement : SVGElement <SVGTransformable, SVGStylable, ConverterSVGToCALayer >
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
//
|
||||
http://www.w3.org/TR/SVG/pservers.html#InterfaceSVGGradientElement
|
||||
|
||||
interface SVGGradientElement : SVGElement,
|
||||
|
||||
SVGURIReference,
|
||||
SVGExternalResourcesRequired,
|
||||
SVGStylable,
|
||||
SVGUnitTypes {
|
||||
|
||||
// Spread Method Types
|
||||
const unsigned short SVG_SPREADMETHOD_UNKNOWN = 0;
|
||||
const unsigned short SVG_SPREADMETHOD_PAD = 1;
|
||||
const unsigned short SVG_SPREADMETHOD_REFLECT = 2;
|
||||
const unsigned short SVG_SPREADMETHOD_REPEAT = 3;
|
||||
|
||||
readonly attribute SVGAnimatedEnumeration gradientUnits;
|
||||
readonly attribute SVGAnimatedTransformList gradientTransform;
|
||||
readonly attribute SVGAnimatedEnumeration spreadMethod;
|
||||
|
||||
*/
|
||||
|
||||
#import "SVGElement.h"
|
||||
#import "SVGRect.h"
|
||||
#import "SVGGradientStop.h"
|
||||
#import "SVGTransformable.h"
|
||||
#import "SVGPreserveAspectRatio.h"
|
||||
#import "SVGUnitTypes.h"
|
||||
|
||||
typedef NS_ENUM(NSUInteger, SVGSpreadMethod) {
|
||||
SVGSpreadMethodUnkown = 0,
|
||||
SVGSpreadMethodPad = 1,
|
||||
SVGSpreadMethodReflect = 2,
|
||||
SVGSpreadMethodRepeat = 3
|
||||
};
|
||||
|
||||
@class SVGGradientLayer;
|
||||
@interface SVGGradientElement : SVGElement <SVGTransformable> /* NB: does NOT implemente "SVGLayeredElement" because spec says that these specifically NEVER appear in the output */
|
||||
|
||||
@property (readonly, strong) NSArray *stops; /* FIXME: not in SVG Spec */
|
||||
@property (readonly, strong) NSArray *locations; /* FIXME: not in SVG Spec */
|
||||
@property (readonly, strong) NSArray *colors; /* FIXME: not in SVG Spec */
|
||||
|
||||
@property (readonly, assign) SVG_UNIT_TYPE gradientUnits;
|
||||
@property (readonly, assign) SVGSpreadMethod spreadMethod; /* FIXME: currently only support `pad`. other methods are not supported */
|
||||
|
||||
|
||||
-(void)addStop:(SVGGradientStop *)gradientStop; /* FIXME: not in SVG Spec */
|
||||
|
||||
-(NSString*) getAttributeInheritedIfNil:(NSString*)attrName;
|
||||
-(SVGGradientLayer *)newGradientLayerForObjectRect:(CGRect)objectRect
|
||||
viewportRect:(SVGRect)viewportRect
|
||||
transform:(CGAffineTransform)transform;
|
||||
|
||||
- (void)synthesizeProperties; // resolve any xlink:hrefs to other gradients
|
||||
@end
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// SVGGradientLayer.h
|
||||
// SVGKit-iOS
|
||||
//
|
||||
// Created by zhen ling tsai on 19/7/13.
|
||||
// Copyright (c) 2013 na. All rights reserved.
|
||||
//
|
||||
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
#import "SVGGradientElement.h"
|
||||
|
||||
/**
|
||||
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.
|
||||
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.
|
||||
So we have to subclass and use the low-level API `CGContextDrawRadialGradient` using custom drawing to follow SVG spec.
|
||||
|
||||
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).
|
||||
So we have to use the low-level API `CGContextDrawLinearGradient` using custom drawing to as well.
|
||||
*/
|
||||
@interface SVGGradientLayer : CAGradientLayer
|
||||
|
||||
@property (nonatomic, strong) SVGGradientElement *gradientElement;
|
||||
@property (nonatomic, assign) CGRect objectRect;
|
||||
@property (nonatomic, assign) SVGRect viewportRect;
|
||||
@property (nonatomic, assign) CGAffineTransform absoluteTransform;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
http://www.w3.org/TR/SVG/pservers.html#InterfaceSVGStopElement
|
||||
|
||||
interface SVGStopElement : SVGElement,
|
||||
SVGStylable {
|
||||
readonly attribute SVGAnimatedNumber offset;
|
||||
*/
|
||||
|
||||
#import "SVGElement.h"
|
||||
#import "SVGUtils.h"
|
||||
|
||||
|
||||
@interface SVGGradientStop : SVGElement
|
||||
|
||||
@property (nonatomic, readonly)CGFloat offset; /** FIXME: wrong units */
|
||||
@property (nonatomic, readonly)CGFloat stopOpacity; /** FIXME: not in SVG Spec */
|
||||
@property (nonatomic, readonly)SVGColor stopColor; /** FIXME: not in SVG Spec */
|
||||
|
||||
//@property (nonatomic, readonly)NSDictionary *style; //misc unaccounted for properties
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// SVGGroupElement.h
|
||||
// SVGKit
|
||||
//
|
||||
// Copyright Matt Rajca 2010-2011. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SVGElement.h"
|
||||
#import "ConverterSVGToCALayer.h"
|
||||
|
||||
@interface SVGGroupElement : SVGElement < ConverterSVGToCALayer > { }
|
||||
|
||||
@property (nonatomic, readonly) CGFloat opacity;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
To implement the official SVG Spec, some "extra" methods are needed that are SHARED between classes, but
|
||||
which in the SVG Spec the classes aren't subclass/superclass of each other - so that there's no way to
|
||||
implement it without copy/pasting the code.
|
||||
|
||||
To improve maintainability, we put those methods here, and then each place we need them has a 1-line method
|
||||
that delegates to a method body in this class.
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
#import "SVGElement.h"
|
||||
#import "SVGTransformable.h"
|
||||
#import "SVGFitToViewBox.h"
|
||||
|
||||
#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
|
||||
#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!
|
||||
@class SVGGradientLayer;
|
||||
@interface SVGHelperUtilities : NSObject
|
||||
|
||||
/**
|
||||
According to the SVG Spec, there are two types of element that affect the on-screen size/shape/position/rotation/skew of shapes/images:
|
||||
|
||||
1. Any ancestor that implements SVGTransformable
|
||||
2. Any "element that establishes a new viewport" - i.e. the <svg> tag and a few others
|
||||
|
||||
This method ONLY looks at current node to establish the above two things, to do a RELATIVE transform (relative to parent node)
|
||||
*/
|
||||
+(CGAffineTransform) transformRelativeIncludingViewportForTransformableOrViewportEstablishingElement:(SVGElement*) transformableOrSVGSVGElement;
|
||||
/**
|
||||
According to the SVG Spec, there are two types of element that affect the on-screen size/shape/position/rotation/skew of shapes/images:
|
||||
|
||||
1. Any ancestor that implements SVGTransformable
|
||||
2. Any "element that establishes a new viewport" - i.e. the <svg> tag and a few others
|
||||
|
||||
This method recurses upwards to combine the above two things for everything in the tree, to establish an ABSOLUTE transform
|
||||
*/
|
||||
+(CGAffineTransform) transformAbsoluteIncludingViewportForTransformableOrViewportEstablishingElement:(SVGElement*) transformableOrSVGSVGElement;
|
||||
|
||||
|
||||
/** Some things - e.g. setting layer's Opacity - have to be done for pretty much EVERY SVGElement; this method automatically looks
|
||||
at the incoming element, uses the protocols that element has (e.g. SVGStylable) to automatically adapt the layer.
|
||||
|
||||
This allows each SVGElement subclass to create a custom CALayer as needed (e.g. CATextLayer for text elements), but share the setup
|
||||
code.
|
||||
|
||||
If compiled with FORCE_RASTERIZE_LAYERS, also tells every layer to rasterize itself
|
||||
*/
|
||||
+(void) configureCALayer:(CALayer*) layer usingElement:(SVGElement*) nonStylableElement;
|
||||
|
||||
+(CALayer *) newCALayerForPathBasedSVGElement:(SVGElement*) svgElement withPath:(CGPathRef) path;
|
||||
+ (SVGGradientLayer*)getGradientLayerWithId:(NSString*)gradId
|
||||
forElement:(SVGElement*)svgElement
|
||||
withRect:(CGRect)r
|
||||
transform:(CGAffineTransform)transform;
|
||||
|
||||
+(CGColorRef) parseFillForElement:(SVGElement *)svgElement;
|
||||
+(CGColorRef) parseStrokeForElement:(SVGElement *)svgElement;
|
||||
+(void) parsePreserveAspectRatioFor:(Element<SVGFitToViewBox>*) element;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,18 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "SVGElement.h"
|
||||
#import "SVGTransformable.h"
|
||||
#import "SVGFitToViewBox.h"
|
||||
|
||||
#import "SVGElement_ForParser.h" // to resolve Xcode circular dependencies; in long term, parsing SHOULD NOT HAPPEN inside any class whose name starts "SVG" (because those are reserved classes for the SVG Spec)
|
||||
|
||||
@interface SVGImageElement : SVGElement <SVGTransformable, SVGStylable, ConverterSVGToCALayer, SVGFitToViewBox>
|
||||
|
||||
@property (nonatomic, readonly) CGFloat x;
|
||||
@property (nonatomic, readonly) CGFloat y;
|
||||
@property (nonatomic, readonly) CGFloat width;
|
||||
@property (nonatomic, readonly) CGFloat height;
|
||||
|
||||
@property (nonatomic, strong, readonly) NSString *href;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
SVGKDefine.h
|
||||
|
||||
SVGKDefine define some common macro used for public header or private header.
|
||||
Currently here are some platform define to allow us to simply write code cross Apple's platforms.
|
||||
*/
|
||||
|
||||
#ifndef SVGKDefine_h
|
||||
#define SVGKDefine_h
|
||||
|
||||
#include "TargetConditionals.h"
|
||||
|
||||
// Apple's defines from TargetConditionals.h are a bit weird.
|
||||
// Seems like TARGET_OS_MAC is always defined (on all platforms).
|
||||
// To determine if we are running on OSX, we can only rely on TARGET_OS_IPHONE=0 and all the other platforms
|
||||
#if !TARGET_OS_IPHONE && !TARGET_OS_IOS && !TARGET_OS_TV && !TARGET_OS_WATCH
|
||||
#define SVGKIT_MAC 1
|
||||
#else
|
||||
#define SVGKIT_MAC 0
|
||||
#endif
|
||||
|
||||
// iOS and tvOS are very similar, UIKit exists on both platforms
|
||||
// Note: watchOS also has UIKit, but it's very limited
|
||||
#if TARGET_OS_IOS || TARGET_OS_TV
|
||||
#define SVGKIT_UIKIT 1
|
||||
#else
|
||||
#define SVGKIT_UIKIT 0
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
#define SVGKIT_IOS 1
|
||||
#else
|
||||
#define SVGKIT_IOS 0
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_TV
|
||||
#define SVGKIT_TV 1
|
||||
#else
|
||||
#define SVGKIT_TV 0
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_WATCH
|
||||
#define SVGKIT_WATCH 1
|
||||
#else
|
||||
#define SVGKIT_WATCH 0
|
||||
#endif
|
||||
|
||||
#if SVGKIT_MAC
|
||||
#ifndef UIImage
|
||||
#define UIImage NSImage
|
||||
#endif
|
||||
#ifndef UIImageView
|
||||
#define UIImageView NSImageView
|
||||
#endif
|
||||
#ifndef UIView
|
||||
#define UIView NSView
|
||||
#endif
|
||||
#ifndef UIColor
|
||||
#define UIColor NSColor
|
||||
#endif
|
||||
#ifndef UIFont
|
||||
#define UIFont NSFont
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if SVGKIT_MAC
|
||||
#import <AppKit/AppKit.h>
|
||||
#else
|
||||
#import <UIKit/UIKit.h>
|
||||
#endif
|
||||
|
||||
#endif /* SVGKDefine_h */
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
SVGKDefine_Private.h
|
||||
|
||||
SVGKDefine define some common macro used for private header.
|
||||
*/
|
||||
|
||||
#ifndef SVGKDefine_Private_h
|
||||
#define SVGKDefine_Private_h
|
||||
|
||||
#import "SVGKDefine.h"
|
||||
@import CocoaLumberjack;
|
||||
|
||||
// These macro is only used inside framework project, does not expose to public header and effect user's define
|
||||
|
||||
#define SVGKIT_LOG_CONTEXT 556
|
||||
|
||||
#define SVGKitLogError(frmt, ...) LOG_MAYBE(NO, LOG_LEVEL_DEF, DDLogFlagError, SVGKIT_LOG_CONTEXT, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
|
||||
#define SVGKitLogWarn(frmt, ...) LOG_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, DDLogFlagWarning, SVGKIT_LOG_CONTEXT, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
|
||||
#define SVGKitLogInfo(frmt, ...) LOG_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, DDLogFlagInfo, SVGKIT_LOG_CONTEXT, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
|
||||
#define SVGKitLogDebug(frmt, ...) LOG_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, DDLogFlagDebug, SVGKIT_LOG_CONTEXT, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
|
||||
#define SVGKitLogVerbose(frmt, ...) LOG_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, DDLogFlagVerbose, SVGKIT_LOG_CONTEXT, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
|
||||
|
||||
#if DEBUG
|
||||
static const int ddLogLevel = DDLogLevelVerbose;
|
||||
#else
|
||||
static const int ddLogLevel = DDLogLevelWarning;
|
||||
#endif
|
||||
|
||||
#if SVGKIT_MAC
|
||||
#define NSStringFromCGRect(rect) NSStringFromRect(rect)
|
||||
#define NSStringFromCGSize(size) NSStringFromSize(size)
|
||||
#define NSStringFromCGPoint(point) NSStringFromPoint(point)
|
||||
#endif
|
||||
|
||||
#endif /* SVGKDefine_Private_h */
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
General-purpose exporter from loaded-SVGKImage object into an NSData byte-array.
|
||||
|
||||
Uses the default color format from [SVGKImage+CGContext newCGContextAutosizedToFit] (currently RGBA / CGColorSpaceCreateDeviceRGB)
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SVGKImage.h"
|
||||
|
||||
@interface SVGKExporterNSData : NSObject
|
||||
|
||||
/**
|
||||
Highest-performance version of .UIImage property (this minimizes memory usage and can lead to large speed-ups e.g. when using SVG images as textures with OpenGLES)
|
||||
|
||||
Delegates to [ exportAsNSData:... flipYaxis:TRUE]
|
||||
*/
|
||||
+(NSData*) exportAsNSData:(SVGKImage*) image;
|
||||
|
||||
/**
|
||||
Highest-performance version of .UIImage property (this minimizes memory usage and can lead to large speed-ups e.g. when using SVG images as textures with OpenGLES)
|
||||
|
||||
Delegates to exportAsNSData:... antiAliased:TRUE curveFlatnessFactor:1.0 interpolationQuality:kCGInterpolationDefault flipYaxis:...]
|
||||
*/
|
||||
+(NSData*) exportAsNSData:(SVGKImage*) image flipYaxis:(BOOL) flipYaxis;
|
||||
|
||||
/**
|
||||
Highest-performance version of .UIImage property (this minimizes memory usage and can lead to large speed-ups e.g. when using SVG images as textures with OpenGLES)
|
||||
|
||||
NB: we could probably achieve get even higher performance in OpenGL by sidestepping NSData entirely and using raw byte arrays (should result in zero-copy).
|
||||
|
||||
@param shouldAntialias = Apple defaults to TRUE, but turn it off for small speed boost
|
||||
@param multiplyFlatness = how many pixels a curve can be flattened by (Apple's internal setting) to make it faster to render but less accurate
|
||||
@param interpolationQuality = Apple internal setting, c.f. Apple docs for CGInterpolationQuality
|
||||
*/
|
||||
+(NSData*) exportAsNSData:(SVGKImage*) image antiAliased:(BOOL) shouldAntialias curveFlatnessFactor:(CGFloat) multiplyFlatness interpolationQuality:(CGInterpolationQuality) interpolationQuality flipYaxis:(BOOL) flipYaxis;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
General-purpose exporter from loaded-SVGKImage object into a new, rasterised NSImage.
|
||||
|
||||
Uses the default color format from UIGraphicsBeginImageContextWithOptions(...)
|
||||
*/
|
||||
|
||||
#import "SVGKDefine.h"
|
||||
|
||||
#if SVGKIT_MAC
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SVGKImage.h"
|
||||
|
||||
@interface SVGKExporterNSImage : NSObject
|
||||
|
||||
/**
|
||||
Higher-performance version of .NSImage property (the property uses this method, but you can tweak the parameters for better performance / worse accuracy)
|
||||
|
||||
NB: you can get BETTER performance using the exportNSDataAntiAliased: version of this method, becuase you bypass Apple's slow code for making NSImage objects
|
||||
|
||||
Delegates to exportAsNSImage:... antiAliased:TRUE curveFlatnessFactor:1.0 interpolationQuality:kCGInterpolationDefault]
|
||||
*/
|
||||
+(NSImage*) exportAsNSImage:(SVGKImage*) image;
|
||||
|
||||
/**
|
||||
Higher-performance version of .NSImage property (the property uses this method, but you can tweak the parameters for better performance / worse accuracy)
|
||||
|
||||
NB: you can get BETTER performance using the exportNSDataAntiAliased: version of this method, becuase you bypass Apple's slow code for making NSImage objects
|
||||
|
||||
@param shouldAntialias = Apple defaults to TRUE, but turn it off for small speed boost
|
||||
@param multiplyFlatness = how many pixels a curve can be flattened by (Apple's internal setting) to make it faster to render but less accurate
|
||||
@param interpolationQuality = Apple internal setting, c.f. Apple docs for CGInterpolationQuality
|
||||
*/
|
||||
+(NSImage*) exportAsNSImage:(SVGKImage*) image antiAliased:(BOOL) shouldAntialias curveFlatnessFactor:(CGFloat) multiplyFlatness interpolationQuality:(CGInterpolationQuality) interpolationQuality;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* SVGKIT_MAC */
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
General-purpose exporter from loaded-SVGKImage object into a new, rasterised UIImage.
|
||||
|
||||
Uses the default color format from UIGraphicsBeginImageContextWithOptions(...)
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SVGKImage.h"
|
||||
|
||||
@interface SVGKExporterUIImage : NSObject
|
||||
|
||||
/**
|
||||
Higher-performance version of .UIImage property (the property uses this method, but you can tweak the parameters for better performance / worse accuracy)
|
||||
|
||||
NB: you can get BETTER performance using the exportNSDataAntiAliased: version of this method, becuase you bypass Apple's slow code for making UIImage objects
|
||||
|
||||
Delegates to exportAsUIImage:... antiAliased:TRUE curveFlatnessFactor:1.0 interpolationQuality:kCGInterpolationDefault]
|
||||
*/
|
||||
+(UIImage*) exportAsUIImage:(SVGKImage*) image;
|
||||
|
||||
/**
|
||||
Higher-performance version of .UIImage property (the property uses this method, but you can tweak the parameters for better performance / worse accuracy)
|
||||
|
||||
NB: you can get BETTER performance using the exportNSDataAntiAliased: version of this method, becuase you bypass Apple's slow code for making UIImage objects
|
||||
|
||||
@param shouldAntialias = Apple defaults to TRUE, but turn it off for small speed boost
|
||||
@param multiplyFlatness = how many pixels a curve can be flattened by (Apple's internal setting) to make it faster to render but less accurate
|
||||
@param interpolationQuality = Apple internal setting, c.f. Apple docs for CGInterpolationQuality
|
||||
*/
|
||||
+(UIImage*) exportAsUIImage:(SVGKImage*) image antiAliased:(BOOL) shouldAntialias curveFlatnessFactor:(CGFloat) multiplyFlatness interpolationQuality:(CGInterpolationQuality) interpolationQuality;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,35 @@
|
||||
#import "SVGKImageView.h"
|
||||
#import "SVGKit.h"
|
||||
|
||||
/**
|
||||
* SVGKit's version of UIImageView - with some improvements over Apple's design
|
||||
|
||||
WARNING 1: CAAnimations are NOT supported
|
||||
- because of the way this class works, any animations you add to the SVGKImage's CALayerTree *will be ignored*. If you need to animate the elements of an SVG file, use SVGKLayer instead (although that class is missing some of the features of this class, and is a little harder to use)
|
||||
|
||||
WARNING 2: UIScrollView requires special-case code
|
||||
- Apple's implementation of UIScrollView is badly broken for zooming. To workaround this, you MUST disable the auto-redraw on this class BEFORE zooming a UIScrollView. You can re-enable it after the zoom has finished. You MUST ALSO make a manual call to "fix" the transform of the view each time Apple sends you the "didFinishZooming:atScale" method. There is an example of this in the demo project (currently named "iOS-Demo.xcodeproj") showing exactly how to do this. It only requires 2 lines of code, but Apple's documentation makes it clear that this is the only way to work in harmony with UIScrollView's internal hacks.
|
||||
- to disable auto-redraw-on-resize, set the BOOL: disableAutoRedrawAtHighestResolution to FALSE
|
||||
|
||||
Basic usage:
|
||||
- as per UIImageView, simpy:
|
||||
- SVGKImageView *skv = [[SVGKImageView alloc] initWithSVGKImage: [SVGKImage imageNamed:@"image.svg"]];
|
||||
- [self.view addSubview: skv];
|
||||
|
||||
Advanced usage:
|
||||
- to make the contents shrink to half their actual size, and tile to fill, set self.tileRatio = CGSizeMake( 2.0f, 2.0f );
|
||||
NOTE: I'd prefer to do this view UIViewContentMode, but Apple didn't make it extensible
|
||||
- to disable tiling (by default, it's disabled), set self.tileRatio = CGSizeZero, and all the tiling will be side-stepped
|
||||
- FOR VERY ADVANCED USAGE: instead of this class, use the lower-level "SVGKLayeredImageView" class, which lets you modify every individual layer
|
||||
|
||||
Performance:
|
||||
- NOTE: the way this works - calling Apple's renderInContext: method - MAY BE artificially slow, because of Apple's implementation
|
||||
- NOTE: you MUST NOT call SVGKImage.CALayerTree.transform - that will have unexpected side-effects, because of Apple's implementation
|
||||
(hence: we currently use renderInContext:, even though we'd prefer not to :( )
|
||||
*/
|
||||
@interface SVGKFastImageView : SVGKImageView
|
||||
|
||||
@property(nonatomic) CGSize tileRatio;
|
||||
@property(nonatomic) BOOL disableAutoRedrawAtHighestResolution;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
Contains methods for low-level exporting of SVGKImage into CGContext's / OpenGL textures / etc
|
||||
|
||||
Process:
|
||||
1. Create a CGContextRef; either use your own code (e.g. with OpenGL, you usually want to do this by hand and check PoT),
|
||||
or use the [self newCGContextAutosizedToFit] method.
|
||||
2. Use the renderToContext:::: method (preferred) or the pure, low-level renderInContext: method (not preferred) to
|
||||
draw into your context
|
||||
3. ...do whatever you want with the results (e.g. use one of the Exporters to export it to raw NSData bytes, or similar)
|
||||
*/
|
||||
#import "SVGKImage.h"
|
||||
|
||||
@interface SVGKImage (CGContext)
|
||||
|
||||
/** Creates a CGContext with correct pixel size using sizing info from the source SVG (or returns NULL if that's not possible)
|
||||
*/
|
||||
-(CGContextRef) newCGContextAutosizedToFit;
|
||||
|
||||
/**
|
||||
WARNING: due to bugs in Apple's code (c.f. CALayer.h header file for notes from Apple - they say "use caution"),
|
||||
this method is NOT a perfect render of CA; it uses Apple's own "approximation", as used in [CALayer renderInContext:],
|
||||
which ignores e.g. masking and some other CA core features
|
||||
|
||||
Generally, for performance and safety, you should use renderToContext:antiAliased:curveFlatnessFactor:interpolationQuality:flipYaxis:
|
||||
instead of this method (it performs checks and optional performance optimizations)
|
||||
*/
|
||||
- (void)renderInContext:(CGContextRef)ctx;
|
||||
|
||||
/**
|
||||
The standard basic method used by all the different "export..." methods in this class and others
|
||||
*/
|
||||
-(void) renderToContext:(CGContextRef) context antiAliased:(BOOL) shouldAntialias curveFlatnessFactor:(CGFloat) multiplyFlatness interpolationQuality:(CGInterpolationQuality) interpolationQuality flipYaxis:(BOOL) flipYaxis;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,317 @@
|
||||
/*
|
||||
SVGKImage
|
||||
|
||||
The main class in SVGKit - this is the one you'll normally interact with
|
||||
|
||||
c.f. SVGKit.h for more info on using SVGKit
|
||||
|
||||
What is an SVGKImage?
|
||||
|
||||
An SVGKImage is as close to "the SVG version of a UIImage" as we could possibly get. We cannot
|
||||
subclass UIImage because Apple has defined UIImage as immutable - and SVG images actually change
|
||||
(each time you zoom in, we want to re-render the SVG as a higher-resolution set of pixels)
|
||||
|
||||
We use the exact same method names as UIImage, and try to be literally as identical as possible.
|
||||
|
||||
Creating an SVGKImage:
|
||||
|
||||
- PREFERRED: use the "imageNamed:" method
|
||||
- CUSTOM SVGKSource class: use the "initWithSource:" method
|
||||
- CUSTOM PARSING: Parse using SVGKParser, then send the parse-result to "initWithParsedSVG:"
|
||||
|
||||
|
||||
Data:
|
||||
- UIImage: not supported yet: will be a cached UIImage that is re-generated on demand. Will enable us to implement an SVGKImageView
|
||||
that works as a drop-in replacement for UIImageView
|
||||
|
||||
- DOMTree: the SVG DOM spec, the root element of a tree of SVGElement subclasses
|
||||
- CALayerTree: the root element of a tree of CALayer subclasses
|
||||
|
||||
- size: as per the UIImage.size, returns a size in Apple Points (i.e. 320 == width of iPhone, irrespective of Retina)
|
||||
- scale: ??? unknown how we'll define this, but could be useful when doing auto-re-render-on-zoom
|
||||
- svgWidth: the internal SVGLength used to generate the correct .size
|
||||
- svgHeight: the internal SVGLength used to generate the correct .size
|
||||
- rootElement: the SVGSVGElement instance that is the root of the parse SVG tree. Use this to access the full SVG document
|
||||
|
||||
*/
|
||||
|
||||
#import "SVGKDefine.h"
|
||||
#import "SVGKParser.h" // needed for asynchronous loading method-signature
|
||||
|
||||
@class SVGDocument;
|
||||
@class SVGSVGElement;
|
||||
@class SVGKSource;
|
||||
@class SVGKParseResult;
|
||||
|
||||
#define ENABLE_GLOBAL_IMAGE_CACHE_FOR_SVGKIMAGE_IMAGE_NAMED 1 // if ENABLED, then ALL instances created with imageNamed: are shared, and are NEVER RELEASED
|
||||
|
||||
@class SVGDefsElement;
|
||||
|
||||
@class SVGKImage; // needed for typedef below
|
||||
typedef void (^SVGKImageAsynchronousLoadingDelegate)(SVGKImage* loadedImage, SVGKParseResult* parseResult );
|
||||
|
||||
@interface SVGKImage : NSObject // doesn't extend UIImage because Apple made UIImage immutable
|
||||
{
|
||||
#if ENABLE_GLOBAL_IMAGE_CACHE_FOR_SVGKIMAGE_IMAGE_NAMED
|
||||
BOOL cameFromGlobalCache;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Generates an image on the fly
|
||||
|
||||
NB you can get MUCH BETTER performance using the methods such as exportUIImageAntiAliased and exportNSDataAntiAliased
|
||||
*/
|
||||
@property (weak, nonatomic, readonly) UIImage* UIImage;
|
||||
|
||||
@property (nonatomic, strong, readonly) SVGKSource* source;
|
||||
@property (nonatomic, strong, readonly) SVGKParseResult* parseErrorsAndWarnings;
|
||||
|
||||
@property (nonatomic, strong, readonly) SVGDocument* DOMDocument;
|
||||
@property (nonatomic, strong, readonly) SVGSVGElement* DOMTree; // needs renaming + (possibly) replacing by DOMDocument
|
||||
@property (nonatomic, strong, readonly) CALayer* CALayerTree;
|
||||
#if ENABLE_GLOBAL_IMAGE_CACHE_FOR_SVGKIMAGE_IMAGE_NAMED
|
||||
@property (nonatomic, strong, readonly) NSString* nameUsedToInstantiate;
|
||||
#endif
|
||||
|
||||
#pragma mark - methods to quick load an SVG as an image
|
||||
/**
|
||||
This is the preferred method for loading SVG files.
|
||||
|
||||
Like Apple's [UIImage imageNamed:] method, it has a global cache of loaded SVG files to greatly
|
||||
increase performance. Unlike UIImage, SVGKImage's tend to be light in memory usage, but if needed,
|
||||
you can disable this at compile-time by setting ENABLE_GLOBAL_IMAGE_CACHE_FOR_SVGKIMAGE_IMAGE_NAMED to 0.
|
||||
|
||||
As of SVGKit 1.2.0, this method:
|
||||
|
||||
- Finds the SVG file (adding .svg extension if missing) in the App's sandboxed Documents folder
|
||||
- If that's missing, it finds the same file in the App's Bundle (i.e. the files stored at compile-time by Xcode, and shipped as the app)
|
||||
- Creates an SVGKSource so that you can later inspect exactly where it found the file
|
||||
*/
|
||||
+ (SVGKImage *)imageNamed:(NSString *)name;
|
||||
+ (SVGKImage *)imageNamed:(NSString *)name withCacheKey:(NSString *)key;
|
||||
+ (SVGKImage *)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle;
|
||||
+ (SVGKImage *)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle withCacheKey:(NSString *)key;
|
||||
/**
|
||||
Almost identical to imageNamed: except that it performs the parse in a separate thread.
|
||||
|
||||
Returns an SVGKParser object that you can cancel, or inspect for progress (using parser.currentParseRun)
|
||||
|
||||
UNLESS the image was already loaded, and a cached version can be returned - in which case,
|
||||
returns nil and immmediately calls the completion block
|
||||
*/
|
||||
+(SVGKParser *) imageAsynchronouslyNamed:(NSString *)name onCompletion:(SVGKImageAsynchronousLoadingDelegate) blockCompleted;
|
||||
+ (SVGKImage *)imageWithContentsOfFile:(NSString *)path;
|
||||
+ (SVGKImage *)imageWithContentsOfURL:(NSURL *)url;
|
||||
+ (SVGKParser*) imageParserWithContentsOfFileAsynchronously:(NSString *)aPath onCompletion:(SVGKImageAsynchronousLoadingDelegate)blockCompleted;
|
||||
+ (SVGKImage*) imageWithContentsOfFileAsynchronously:(NSString *)aPath onCompletion:(SVGKImageAsynchronousLoadingDelegate)blockCompleted;
|
||||
|
||||
/**
|
||||
PREFERABLY: these are our only method, apart from the convenience "imageNamed"
|
||||
|
||||
Creating an SVG from raw data; this is not recommended: SVG requires knowledge
|
||||
of at least the URL where it came from (as it can contain relative file-links internally).
|
||||
|
||||
If you need to create an SVG e.g. directly from raw bytes, then you MUST use
|
||||
this method and ADDITIONALLY wrap your data into an SVGKSource.
|
||||
|
||||
This is because SVG's cannot parse correctly without the metadata about where
|
||||
the file came from: e.g. they cannot process relative links, cross-references, etc.
|
||||
*/
|
||||
+(SVGKImage*) imageWithData:(NSData *)newNSData; // if you have custom source's you want to use
|
||||
+ (SVGKParser*) imageParserWithDataAsynchronously:(NSData *)newNSData onCompletion:(SVGKImageAsynchronousLoadingDelegate)blockCompleted;
|
||||
+ (SVGKImage*) imageWithDataAsynchronously:(NSData *)newNSData onCompletion:(SVGKImageAsynchronousLoadingDelegate)blockCompleted;
|
||||
|
||||
/**
|
||||
PREFERABLY: these are our only method, apart from the convenience "imageNamed"
|
||||
|
||||
The first one is synchronous, the second is asynchronous.
|
||||
|
||||
If you need to create an SVG e.g. directly from raw bytes, then you MUST use
|
||||
this method and ADDITIONALLY wrap your data into an SVGKSource.
|
||||
|
||||
This is because SVG's cannot parse correctly without the metadata about where
|
||||
the file came from: e.g. they cannot process relative links, cross-references, etc.
|
||||
*/
|
||||
+(SVGKImage*) imageWithSource:(SVGKSource *)newSource; // if you have custom source's you want to use
|
||||
|
||||
/**
|
||||
This is the asynchronous version of imageWithSource:
|
||||
*/
|
||||
+(SVGKParser *) imageWithSource:(SVGKSource *)source onCompletion:(SVGKImageAsynchronousLoadingDelegate)blockCompleted;
|
||||
|
||||
- (id)initWithContentsOfFile:(NSString *)path;
|
||||
- (id)initWithData:(NSData *)data;
|
||||
|
||||
#pragma mark - UIImage methods cloned and re-implemented as SVG intelligent methods
|
||||
|
||||
/** NB: if an SVG defines no limits to itself - neither a viewbox, nor an <svg width=""> nor an <svg height=""> - and
|
||||
you have not explicitly given the SVGKImage instance a "user defined size" (by setting .size) ... then there is NO
|
||||
LEGAL SIZE VALUE for self.size to return, and it WILL ASSERT!
|
||||
|
||||
Use this method to double-check, before calling .size, whether it's going to give you a legal value safely
|
||||
*/
|
||||
-(BOOL) hasSize;
|
||||
|
||||
/**
|
||||
NB: always call "hasSize" before calling this method; some SVG's may have NO DEFINED SIZE, and so
|
||||
the .size method could return an invalid value (c.f. the hasSize method for details on how to
|
||||
workaround that issue)
|
||||
|
||||
SVG's are infinitely scalable, by definition - but authors can OPTIONALLY set a "preferred size".
|
||||
|
||||
Also, we allow you to set an explicit "this is the size I'm going to render at, deal with it" size,
|
||||
which will OVERRIDE the author's own size (if they configured one), and force the SVG to resize itself
|
||||
to fit your dictated size.
|
||||
|
||||
(NB: this is as per the spec, so it's OK)
|
||||
|
||||
NOTE: if you change this property, it will invalidate any cached render-data, and all future
|
||||
renders will be done at this pixel-size/pixel-resolution
|
||||
|
||||
NOTE: when you read the .UIImage property of this class, it generates a bitmap using the
|
||||
current value of this property (or x2 if retina display) -- and if you've never set the
|
||||
property, it will use the de-facto value obtained by reading the SVG file and looking for
|
||||
author-dictated size, etc
|
||||
*/
|
||||
@property(nonatomic) CGSize size;
|
||||
|
||||
/**
|
||||
|
||||
TODO: From UIImage. Not needed, I think?
|
||||
|
||||
@property(nonatomic,readonly) CIImage *CIImage __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0); // returns underlying CIImage or nil if CGImageRef based
|
||||
*/
|
||||
|
||||
// the these draw the image 'right side up' in the usual coordinate system with 'point' being the top-left.
|
||||
|
||||
- (void)drawAtPoint:(CGPoint)point; // mode = kCGBlendModeNormal, alpha = 1.0
|
||||
|
||||
#pragma mark - unsupported / unimplemented UIImage methods (should add as a feature)
|
||||
|
||||
/**
|
||||
According to SVG Spec, default scale is "1.0", and the correct way to resize/scale an image is by:
|
||||
|
||||
1. setting an explicit "<svg width="..." height="...">"
|
||||
|
||||
...or, alternatively, you can do:
|
||||
|
||||
1. setting an explicit "<svg viewbox="..."
|
||||
|
||||
(in which case, we'll use the viewbox width + height as stand-ins for your missing <svg width="" height="")
|
||||
|
||||
Either way, you should also do:
|
||||
|
||||
2. set an explicit SVGKImage.size = "..."
|
||||
|
||||
However, there are cases where none of those are possible. e.g. because your SVG file is badly written and missing
|
||||
both of those bits of data. So, to support these situations, we allow you to set a global "scale" that will be applied
|
||||
to your SVG file *if and only if* it has no explicit viewbox / width+height
|
||||
|
||||
*/
|
||||
@property(nonatomic) CGFloat scale;
|
||||
|
||||
- (void)drawAtPoint:(CGPoint)point blendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;
|
||||
- (void)drawInRect:(CGRect)rect; // mode = kCGBlendModeNormal, alpha = 1.0
|
||||
- (void)drawInRect:(CGRect)rect blendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;
|
||||
|
||||
- (void)drawAsPatternInRect:(CGRect)rect; // draws the image as a CGPattern
|
||||
|
||||
// animated images. When set as UIImageView.image, animation will play in an infinite loop until removed. Drawing will render the first image
|
||||
#if SVGKIT_UIKIT
|
||||
+ (UIImage *)animatedImageNamed:(NSString *)name duration:(NSTimeInterval)duration ;//__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0); read sequnce of files with suffix starting at 0 or 1
|
||||
+ (UIImage *)animatedResizableImageNamed:(NSString *)name capInsets:(UIEdgeInsets)capInsets duration:(NSTimeInterval)duration ;//__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0); // squence of files
|
||||
+ (UIImage *)animatedImageWithImages:(NSArray *)images duration:(NSTimeInterval)duration ;//__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
|
||||
#endif
|
||||
/**
|
||||
|
||||
TODO: From UIImage. Not needed, I think?
|
||||
|
||||
@property(nonatomic,readonly) NSArray *images __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0); // default is nil for non-animated images
|
||||
@property(nonatomic,readonly) NSTimeInterval duration __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0); // total duration for all frames. default is 0 for non-animated images
|
||||
*/
|
||||
#pragma mark ---------end of unsupported items
|
||||
|
||||
#pragma mark - core methods for interacting with an SVG image usefully (not from UIImage)
|
||||
|
||||
/*! If you want to provide a custom SVGKSource */
|
||||
- (id)initWithSource:(SVGKSource *)source;
|
||||
|
||||
/*! If you already have a parsed SVG, and just want to upgrade it to an SVGKImage
|
||||
|
||||
This is the designated initialiser used by all other init methods
|
||||
|
||||
NB: this is frequently used if you have to add custom SVGKParserExtensions to parse an
|
||||
SVG which contains custom tags
|
||||
*/
|
||||
- (id)initWithParsedSVG:(SVGKParseResult *)parseResult fromSource:(SVGKSource*) parseSource;
|
||||
|
||||
|
||||
/*! Creates a new instance each time you call it. This should ONLY be used if you specifically need to duplicate
|
||||
the CALayer's (e.g. because you want to render a temporary clone of the CALayers somewhere else on screen,
|
||||
and you're going to modify them).
|
||||
|
||||
For all other use-cases, you should probably use the .CALayerTree property, which is automatically cached between
|
||||
calls - but MUST NOT be altered!
|
||||
*/
|
||||
-(CALayer *)newCALayerTree;
|
||||
|
||||
/*! uses the current .CALayerTree property to find the layer, recursing down the tree (or creates a new
|
||||
CALayerTree on demand, and caches it)
|
||||
|
||||
i.e. this takes advantage of the cached CALayerTree instance, and also correctly uses the SVG.viewBox info
|
||||
that was used when generating the original CALayerTree
|
||||
*/
|
||||
- (CALayer *)layerWithIdentifier:(NSString *)identifier;
|
||||
|
||||
/*! uses the current .CALayerTree property to find the layer, recursing down the tree (or creates a new
|
||||
CALayerTree on demand, and caches it)
|
||||
|
||||
i.e. this takes advantage of the cached CALayerTree instance, and also correctly uses the SVG.viewBox info
|
||||
that was used when generating the original CALayerTree
|
||||
*/
|
||||
- (CALayer *)layerWithIdentifier:(NSString *)identifier layer:(CALayer *)layer;
|
||||
|
||||
/*! As for layerWithIdentifier: but works out the absolute position of the layer,
|
||||
effectively pulling it out of the layer-tree (the newly created layer has NO SUPERLAYER,
|
||||
because it no longer needs one)
|
||||
|
||||
Useful for extracting individual features from an SVG
|
||||
|
||||
WARNING: will assert if you supply a nil identifier string
|
||||
WARNING: some SVG editors (e.g. Adobe Illustrator) don't bother creating an 'id' attribute for every node (the spec allows this,
|
||||
but strongly discourages it). Inkscape does the right thing and generates an automatic 'id' for every node. If you are loading
|
||||
docs that have many 'anonymous' nodes, you'll need to get actual pointer refs to the layers you need to work with, and use the
|
||||
alternate version of this method.
|
||||
*/
|
||||
-(CALayer*) newCopyPositionedAbsoluteLayerWithIdentifier:(NSString *)identifier;
|
||||
|
||||
/*! As for layerWithIdentifier: but works out the absolute position of the layer,
|
||||
effectively pulling it out of the layer-tree (the newly created layer has NO SUPERLAYER,
|
||||
because it no longer needs one)
|
||||
|
||||
Useful for extracting individual features from an SVG
|
||||
|
||||
Note that this ONLY clones the layer, does NOT include its sublayers. If you want to get a copy that includes
|
||||
the sublayers, use [self newCopyPositionedAbsoluteOfLayer:withSubLayers:TRUE]
|
||||
*/
|
||||
-(CALayer*) newCopyPositionedAbsoluteOfLayer:(CALayer *)originalLayer;
|
||||
|
||||
/**
|
||||
As for newCopyPositionedAbsoluteOfLayer:, but allows you to choose between 1 layer only (default)
|
||||
or a recursive copy which includes all sublayers.
|
||||
|
||||
Only the root/parent layer will be positioned absolute - all the sublayers will still be relatively-positioned
|
||||
within their parents.
|
||||
*/
|
||||
-(CALayer*) newCopyPositionedAbsoluteOfLayer:(CALayer *)originalLayer withSubLayers:(BOOL) recursive;
|
||||
|
||||
/*! returns all the individual CALayer's in the full layer tree, indexed by the SVG identifier of the SVG node that created that layer */
|
||||
- (NSDictionary*) dictionaryOfLayers;
|
||||
|
||||
#pragma mark - Useful bonus methods, will probably move to a different class at some point
|
||||
|
||||
/** alters the SVG image's size directly (by changing the viewport) so that it will fit inside the specifed area without stretching or deforming */
|
||||
-(void) scaleToFitInside:(CGSize) maxSize;
|
||||
+(void) clearCache;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// SVGKitImageRep.h
|
||||
// SVGKit
|
||||
//
|
||||
// Created by C.W. Betts on 12/5/12.
|
||||
//
|
||||
//
|
||||
|
||||
#import "SVGKDefine.h"
|
||||
|
||||
#if SVGKIT_MAC
|
||||
#import <Cocoa/Cocoa.h>
|
||||
@class SVGKImage;
|
||||
@class SVGKSource;
|
||||
|
||||
@interface SVGKImageRep : NSImageRep
|
||||
@property (nonatomic, strong, readonly) SVGKImage *image;
|
||||
|
||||
//Function used by NSImageRep to init.
|
||||
+ (instancetype)imageRepWithData:(NSData *)d;
|
||||
+ (instancetype)imageRepWithContentsOfFile:(NSString *)filename;
|
||||
+ (instancetype)imageRepWithContentsOfURL:(NSURL *)url;
|
||||
+ (instancetype)imageRepWithSVGImage:(SVGKImage*)theImage;
|
||||
+ (instancetype)imageRepWithSVGSource:(SVGKSource*)theSource;
|
||||
|
||||
- (instancetype)initWithData:(NSData *)theData;
|
||||
- (instancetype)initWithContentsOfURL:(NSURL *)theURL;
|
||||
- (instancetype)initWithContentsOfFile:(NSString *)thePath;
|
||||
- (instancetype)initWithSVGString:(NSString *)theString;
|
||||
- (instancetype)initWithSVGImage:(SVGKImage*)theImage;
|
||||
- (instancetype)initWithSVGSource:(SVGKSource*)theSource;
|
||||
|
||||
- (NSData *)TIFFRepresentation;
|
||||
- (NSData *)TIFFRepresentationWithSize:(NSSize)theSize;
|
||||
- (NSData *)TIFFRepresentationUsingCompression:(NSTIFFCompression)comp factor:(float)factor;
|
||||
- (NSData *)TIFFRepresentationUsingCompression:(NSTIFFCompression)comp factor:(float)factor size:(NSSize)asize;
|
||||
|
||||
+ (void)loadSVGKImageRep;
|
||||
+ (void)unloadSVGKImageRep;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* SVGKIT_MAC */
|
||||
@@ -0,0 +1,26 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "SVGKImage.h" // cannot import "SVGKit.h" because that would cause ciruclar imports
|
||||
|
||||
/**
|
||||
* SVGKit's version of UIImageView - with some improvements over Apple's design. There are multiple versions of this class, for different use cases.
|
||||
|
||||
STANDARD USAGE:
|
||||
- SVGKImageView *myImageView = [[SVGKFastImageView alloc] initWithSVGKImage: [SVGKImage imageNamed:@"image.svg"]];
|
||||
- [self.view addSubview: myImageView];
|
||||
|
||||
NB: the "SVGKFastImageView" is the one you want 9 times in 10. The alternative classes (e.g. SVGKLayeredImageView) are for advanced usage.
|
||||
|
||||
NB: read the class-comment for each subclass carefully before deciding what to use.
|
||||
|
||||
*/
|
||||
@interface SVGKImageView : UIView
|
||||
|
||||
@property(nonatomic,strong) SVGKImage* image;
|
||||
@property(nonatomic) BOOL showBorder; /**< mostly for debugging - adds a coloured 1-pixel border around the image */
|
||||
|
||||
@property(nonatomic,readonly) NSTimeInterval timeIntervalForLastReRenderOfSVGFromMemory;
|
||||
|
||||
- (id)initWithSVGKImage:(SVGKImage*) im;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// SVGKInlineResource.h
|
||||
// SVGKit-iOS
|
||||
//
|
||||
// Created by lizhuoli on 2018/11/2.
|
||||
// Copyright © 2018 na. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SVGKDefine.h"
|
||||
|
||||
/** Contains some inline resource define, such as default SVG, broekn image string, etc */
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/** Return the brkoken image base64 string */
|
||||
FOUNDATION_EXPORT NSString * const SVGKGetBrokenImageString(void);
|
||||
/** Return the shared broken image representation */
|
||||
FOUNDATION_EXPORT UIImage * const SVGKGetBrokenImageRepresentation(void);
|
||||
/** Return the default empty SVG content string */
|
||||
FOUNDATION_EXPORT NSString * const SVGKGetDefaultContentString(void);
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,37 @@
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
#import "SVGKit.h"
|
||||
|
||||
/**
|
||||
* SVGKLayer: this is the "low level" equivalent of SVGKImageView, and allows you to perform e.g. CoreAnimation on the individual elemetns / layers
|
||||
within an SVG Image.
|
||||
|
||||
NB: this class is MORE COMPLEX than SVGKImageView, and requires you to DO MORE WORK. It is also LOWER PERFORMANCE for basic usage - it expects
|
||||
YOU to do the work if you want caching, OpenGL acceration, etc. To give you total access to the rendering, we have to disable all the performance
|
||||
optimizations coded into SVGKImageView
|
||||
|
||||
Basic usage:
|
||||
- NOTE: most of the time, you DO NOT WANT this class, you instead want to use SVGKImageView, which does lots more work for you.
|
||||
- Usage as per CALayer:
|
||||
- SVGKLayer *skl = [[SVGKLayer alloc] init];
|
||||
- skl.SVGImage = [SVGKImage imageNamed:@"image.svg"];
|
||||
- [self.view.layer addSublayer: skl];
|
||||
|
||||
Advanced usage:
|
||||
- Note that EVERY ELEMENT in the original SVG is rendered as a SEPARATE CALayer - you can access all the layers by name, and animate them
|
||||
- ...c.f. the demo project (currently "iOS-Demo.xcodeproj" and how we animate the Monkey.svg file, wobbling its head
|
||||
|
||||
Performance:
|
||||
- NOTE: to give you full control of the layers, I had to delete the "auto-re-rasterize at highest pixel detail". I cannot find a way to make that work with Apple's hierarchy of CALayers (it only works when manually blitting). If anyone can figure this out, we'd all be extermely grateful!
|
||||
- NOTE: the way this works - adding all layers individually - can have complex effects on performance. Some SVG files will render surprisingly fast, others surpisingly slow.
|
||||
... you MUST understand Apple's complete rendering system in detail to undertand what's going on (not recommended for beginners!)
|
||||
- NOTE: you MUST NOT call SVGKImage.CALayerTree.transform - that will have unexpected side-effects, because of Apple's implementation
|
||||
*/
|
||||
@interface SVGKLayer : CALayer
|
||||
|
||||
@property(nonatomic,strong) SVGKImage* SVGImage;
|
||||
@property(nonatomic) BOOL showBorder; /**< mostly for debugging - adds a coloured 1-pixel border around the image */
|
||||
|
||||
@property (nonatomic, strong) NSDate* startRenderTime, * endRenderTime; /**< for debugging, lets you know how long it took to add/generate the CALayer (may have been cached! Only SVGKImage knows true times) */
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,28 @@
|
||||
#import "SVGKImageView.h"
|
||||
#import "SVGKit.h"
|
||||
|
||||
/**
|
||||
* SVGKit's ADVANCED version of UIImageView - for most cases, you want to use the simple version instead (SVGKImageView)
|
||||
|
||||
This class is similar to SVGKImageView, but it DOES NOT HAVE the performance optimizations, and it WILL NOT AUTO-DRAW AT FULL RESOLUTION.
|
||||
|
||||
However, it DOES SUPPORT CORE ANIMATION (which SVGKImageView cannot do), and in some cases that's more important.
|
||||
|
||||
Basic usage:
|
||||
- as per SVGKImageView:
|
||||
- SVGKLayeredImageView *skv = [[SVGKLayeredImageView alloc] initWithSVGKImage: [SVGKImage imageNamed:@"image.svg"]];
|
||||
- [self.view addSubview: skv];
|
||||
|
||||
Advanced usage:
|
||||
- to access the underlying layers, typecast the .layer property:
|
||||
- SVGKLayeredImageView *skv = [[SVGKLayeredImageView alloc] initWithSVGKImage: [SVGKImage imageNamed:@"image.svg"]];
|
||||
- SVGKLayer* layer = (SVGKLayer*) skv.layer;
|
||||
|
||||
For Mac user:
|
||||
`SVGKLayeredImageView` is a layer-hosting view. It uses the `SVGKLayer` layer class for rendering.
|
||||
|
||||
*/
|
||||
|
||||
@interface SVGKLayeredImageView : SVGKImageView
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
Reports detailed information from an attempted run of the SVG Parser
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class SVGSVGElement, SVGDocument;
|
||||
#import "SVGSVGElement.h"
|
||||
#import "SVGDocument.h"
|
||||
|
||||
@protocol SVGKParserExtension;
|
||||
#import "SVGKParserExtension.h"
|
||||
|
||||
@interface SVGKParseResult : NSObject
|
||||
|
||||
@property(nonatomic, strong) NSMutableArray* warnings, * errorsRecoverable, * errorsFatal;
|
||||
@property(nonatomic) BOOL libXMLFailed;
|
||||
/** 0.0 = no parsing done yet, 0.x = partially parsed, 1.0 = parse complete (no fatal errors) */
|
||||
@property(nonatomic) double parseProgressFractionApproximate;
|
||||
|
||||
@property(nonatomic,strong) SVGSVGElement* rootOfSVGTree; /**< both are needed, see spec */
|
||||
@property(nonatomic,strong) SVGDocument* parsedDocument; /**< both are needed, see spec */
|
||||
|
||||
@property(nonatomic,strong) NSMutableDictionary* namespacesEncountered; /**< maps "prefix" to "uri" */
|
||||
|
||||
-(void) addSourceError:(NSError*) fatalError;
|
||||
-(void) addParseWarning:(NSError*) warning;
|
||||
-(void) addParseErrorRecoverable:(NSError*) recoverableError;
|
||||
-(void) addParseErrorFatal:(NSError*) fatalError;
|
||||
-(void) addSAXError:(NSError*) saxError;
|
||||
|
||||
#if ENABLE_PARSER_EXTENSIONS_CUSTOM_DATA
|
||||
/*! Each SVGKParserExtension can optionally save extra data here */
|
||||
@property(nonatomic,retain) NSMutableDictionary* extensionsData;
|
||||
|
||||
-(NSMutableDictionary*) dictionaryForParserExtension:(NSObject<SVGKParserExtension>*) extension;
|
||||
#endif
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
SVGKParser.h
|
||||
|
||||
The main parser for SVGKit. All the magic starts here. Either use:
|
||||
|
||||
A: +parseSourceUsingDefaultSVGKParser
|
||||
|
||||
...or use:
|
||||
|
||||
B: 1. -initWithSource:
|
||||
B: 2. -addDefaultSVGParserExtensions
|
||||
B: ...
|
||||
B: 3. (as many times as you need) -addParserExtension:
|
||||
B: ...
|
||||
B: 4. -parseSynchronously
|
||||
|
||||
Note that "A" above does ALL the steps in B for you. If you need a custom set of Parser Extensions, you'll need to
|
||||
do all the steps in B yourself
|
||||
|
||||
|
||||
PARSING
|
||||
---
|
||||
Actual parsing of an SVG is split into three places:
|
||||
|
||||
1. High level, XML parsing: this file (SVGKParser)
|
||||
2. Mid level, parsing the structure of a document, and special XML tags: any class that extends "SVGKParserExtension"
|
||||
3. Mid level, parsing SVG tags only: SVGKParserSVG (it's an extension that just does base SVG)
|
||||
4. Low level, parsing individual tags within a file, and precise co-ordinates: all the "SVG...Element" classes parse themselves
|
||||
|
||||
IDEALLY, we'd like to change that to:
|
||||
|
||||
1. High level, XML parsing: this file (SVGKParser)
|
||||
2. Mid level, parsing the structure of a document, and special XML tags: any class that extends "SVGKParserExtension"
|
||||
3. Mid level, parsing SVG tags only, but also handling all the different tags: SVGKParserSVG
|
||||
4. Lowest level, parsing co-ordinate lists, numbers, strings: yacc/lex parser (in an unnamed class that hasn't been written yet)
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "SVGKSource.h"
|
||||
#import "SVGKParserExtension.h"
|
||||
#import "SVGKParseResult.h"
|
||||
|
||||
#import "SVGElement.h"
|
||||
|
||||
|
||||
|
||||
/*! RECOMMENDED: leave this set to 1 to get warnings about "legal, but poorly written" SVG */
|
||||
#define PARSER_WARN_FOR_ANONYMOUS_SVG_G_TAGS 1
|
||||
|
||||
/*! Verbose parser logging - ONLY needed if you have an SVG file that's failing to load / crashing */
|
||||
#define DEBUG_VERBOSE_LOG_EVERY_TAG 0
|
||||
#define DEBUG_XML_PARSER 0
|
||||
|
||||
@interface SVGKParser : NSObject {
|
||||
@private
|
||||
NSMutableString *_storedChars;
|
||||
//NSMutableArray *_elementStack;
|
||||
NSMutableArray * _stackOfParserExtensions;
|
||||
Node * _parentOfCurrentNode;
|
||||
}
|
||||
|
||||
@property(nonatomic,strong,readonly) SVGKSource* source;
|
||||
@property(nonatomic,strong,readonly) NSMutableArray* externalStylesheets;
|
||||
@property(nonatomic,strong,readonly) SVGKParseResult* currentParseRun;
|
||||
|
||||
@property(nonatomic,strong) NSMutableArray* parserExtensions;
|
||||
@property(nonatomic,strong) NSMutableDictionary* parserKnownNamespaces; /**< maps "uri" to "array of parser-extensions" */
|
||||
|
||||
#pragma mark - NEW
|
||||
|
||||
/**
|
||||
If you kept the SVGKParser instance when you started a parse, you can
|
||||
hand that instance to another thread and the OTHER thread can trigger
|
||||
a cancel.
|
||||
|
||||
It is not instantaneous, but kicks in as soon as more data is read from
|
||||
the raw bytes-stream, so it's pretty quick
|
||||
*/
|
||||
+(void) cancelParser:(SVGKParser*) parserToCancel;
|
||||
|
||||
/**
|
||||
Creates an SVGKParser, and adds the "standard" extensions for parsing
|
||||
a standard SVG file; you can then add any of your own custom extensions
|
||||
before triggering the parse with e.g. "parseSynchronously"
|
||||
*/
|
||||
+(SVGKParser *) newParserWithDefaultSVGKParserExtensions:(SVGKSource *)source;
|
||||
|
||||
/**
|
||||
Delegates to [self newParserWithDefaultSVGKParserExtensions:], and then auto-starts
|
||||
the parse SYNCHRONOUSLY (may take anything from 0.001 seconds up to 30+ seconds
|
||||
for a huge SVG file).
|
||||
|
||||
Returns the fully-parsed result, including any errors
|
||||
*/
|
||||
+ (SVGKParseResult*) parseSourceUsingDefaultSVGKParser:(SVGKSource*) source;
|
||||
|
||||
/**
|
||||
This MIGHT now be safe to call multiple times on different threads
|
||||
(NB: the only reason it wasn't safe before was major bugs in libxml
|
||||
that break libxml in horrible ways, see the source code to this class
|
||||
for more info)
|
||||
*/
|
||||
- (SVGKParseResult*) parseSynchronously;
|
||||
|
||||
+(NSDictionary *) NSDictionaryFromCSSAttributes: (Attr*) styleAttribute;
|
||||
|
||||
|
||||
|
||||
#pragma mark - OLD - POTENTIALLY DELETE THESE ONCE THEY'VE ALL BEEN CHECKED AND CONVERTED
|
||||
|
||||
- (id)initWithSource:(SVGKSource *)doc;
|
||||
|
||||
/*! Adds the default SVG-tag parsers (everything in the SVG namespace); you should always use these, unless you
|
||||
are massively customizing SVGKit's parser! */
|
||||
-(void) addDefaultSVGParserExtensions;
|
||||
/*! NB: you ALMOST ALWAYS want to first call "addDefaultSVGParserExtensions" */
|
||||
- (void) addParserExtension:(NSObject<SVGKParserExtension>*) extension;
|
||||
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
According to the DOM spec, all nodes in an XML document must be parsed; if we lack specific information for them,
|
||||
i.e. if we have no other, more specific, parser - then we must parse them as the most basic objects, i.e. Node,
|
||||
Element, etc
|
||||
|
||||
This is a special, magical parser that matches "no namespace" - i.e. matches what happens when no namspace was declared\
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SVGKParserExtension.h"
|
||||
|
||||
@interface SVGKParserDOM : NSObject <SVGKParserExtension>
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
Parses the "<defs>" and "<use>" tags in SVG files.
|
||||
|
||||
NB: relies upon other parsers to parse the actual CONTENTS of a "defs" or "use" tag
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SVGKParserExtension.h"
|
||||
|
||||
@interface SVGKParserDefsAndUse : NSObject <SVGKParserExtension>
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
SVGParserExtension.h
|
||||
|
||||
A protocol that lets us split "parsing an SVG" into lots of smaller parsing classes
|
||||
|
||||
PARSING
|
||||
---
|
||||
Actual parsing of an SVG is split into three places:
|
||||
|
||||
1. High level, XML parsing: SVGParser
|
||||
2. ALL THE REST, this class: parsing the structure of a document, and special XML tags: any class that extends "SVGParserExtension"
|
||||
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "SVGKSource.h"
|
||||
|
||||
@class SVGKParseResult;
|
||||
#import "SVGKParseResult.h"
|
||||
|
||||
#import "Node.h"
|
||||
|
||||
/*! Experimental: allow SVGKit parser-extensions to insert custom data into an SVGKParseResult */
|
||||
#define ENABLE_PARSER_EXTENSIONS_CUSTOM_DATA 0
|
||||
|
||||
@protocol SVGKParserExtension <NSObject>
|
||||
|
||||
/*! Array of URI's as NSString's, one string for each XMLnamespace that this parser-extension can parse
|
||||
*
|
||||
* e.g. the main parser returns "[NSArray arrayWithObjects:@"http://www.w3.org/2000/svg", nil];"
|
||||
*/
|
||||
-(NSArray*) supportedNamespaces;
|
||||
|
||||
/*! Array of NSString's, one string for each XML tag (within a supported namespace!) that this parser-extension can parse
|
||||
*
|
||||
* e.g. the main parser returns "[NSArray arrayWithObjects:@"svg", @"title", @"defs", @"path", @"line", @"circle", ...etc... , nil];"
|
||||
*/
|
||||
-(NSArray*) supportedTags;
|
||||
|
||||
/*!
|
||||
Because SVG-DOM uses DOM, custom parsers can return any object they like - so long as its some kind of
|
||||
subclass of DOM's Node class
|
||||
*/
|
||||
- (Node*)handleStartElement:(NSString *)name document:(SVGKSource*) document namePrefix:(NSString*)prefix namespaceURI:(NSString*) XMLNSURI attributes:(NSMutableDictionary *)attributes parseResult:(SVGKParseResult*) parseResult parentNode:(Node*) parentNode;
|
||||
|
||||
/**
|
||||
Primarily used by the few nodes - <TEXT> and <TSPAN> - that need to post-process their text-content.
|
||||
In SVG, almost all data is stored in the attributes instead
|
||||
*/
|
||||
-(void)handleEndElement:(Node *)newNode document:(SVGKSource *)document parseResult:(SVGKParseResult *)parseResult;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// SVGParserLinearGradient.h
|
||||
// SVGPad
|
||||
//
|
||||
// Created by Kevin Stich on 1/31/12.
|
||||
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SVGKParserSVG.h"
|
||||
|
||||
|
||||
@class SVGGradientElement;
|
||||
|
||||
@interface SVGKParserGradient : SVGKParserSVG {
|
||||
SVGGradientElement *currentElement;
|
||||
}
|
||||
|
||||
@end
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// SVGKParserPatternsAndGradients.h
|
||||
// SVGKit
|
||||
//
|
||||
// Created by adam applecansuckmybigtodger on 28/06/2012.
|
||||
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SVGKParser.h"
|
||||
|
||||
@interface SVGKParserPatternsAndGradients : NSObject <SVGKParserExtension>
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,8 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "SVGKParser.h"
|
||||
|
||||
@interface SVGKParserSVG : NSObject <SVGKParserExtension> {
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// SVGStyleParser.h
|
||||
// SVGPad
|
||||
//
|
||||
// Created by Kevin Stich on 2/2/12.
|
||||
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SVGKParser.h"
|
||||
|
||||
@interface SVGKParserStyles : NSObject <SVGKParserExtension> {
|
||||
@private
|
||||
// NSSet *_tags, *_namespaces;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,14 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SVGKDefine.h"
|
||||
|
||||
/** lightweight wrapper for UIColor so that we can draw with fill patterns */
|
||||
@interface SVGKPattern : NSObject
|
||||
|
||||
+ (SVGKPattern*) patternWithColor:(UIColor*)color;
|
||||
+ (SVGKPattern*) patternWithImage:(UIImage*)image;
|
||||
|
||||
@property (readwrite,nonatomic,strong) UIColor* color;
|
||||
|
||||
- (CGColorRef) CGColor;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,81 @@
|
||||
/*!
|
||||
// SVGKPointsAndPathsParser.h
|
||||
|
||||
This class really needs to be "upgraded" by wrapping it in a class named
|
||||
|
||||
SVGPathElement
|
||||
|
||||
and naming methods in that new class so that they adhere to the method names used in the official SVG standard's SVGPathElement spec:
|
||||
|
||||
http://www.w3.org/TR/SVG11/paths.html#InterfaceSVGPathElement
|
||||
|
||||
...
|
||||
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
/**
|
||||
* Partially spammy; not as spammy as DEBUG_PATH_CREATION
|
||||
*/
|
||||
#define VERBOSE_PARSE_SVG_COMMAND_STRINGS 0
|
||||
|
||||
/*! Very useful for debugging the parser - this will output one line of logging
|
||||
* for every CGPath command that's actually done; you can then compare these lines
|
||||
* to the input source file, and manually check what's being sent to the renderer
|
||||
* versus what was expected
|
||||
*
|
||||
* this is MORE SPAMMY than VERBOSE_PARSE_SVG_COMMAND_STRINGS
|
||||
*/
|
||||
#define DEBUG_PATH_CREATION 0
|
||||
|
||||
typedef NS_ENUM(NSUInteger, SVGCurveType) {
|
||||
SVGCurveTypePoint,
|
||||
SVGCurveTypeCubic,
|
||||
SVGCurveTypeQuadratic,
|
||||
};
|
||||
|
||||
typedef struct SVGCurve
|
||||
{
|
||||
SVGCurveType type;
|
||||
CGPoint c1;
|
||||
CGPoint c2;
|
||||
CGPoint p;
|
||||
} SVGCurve;
|
||||
|
||||
|
||||
@interface SVGKPointsAndPathsParser : NSObject
|
||||
|
||||
+ (SVGCurve) startingCurve;
|
||||
|
||||
+ (SVGCurve) readMovetoDrawtoCommandGroups:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin isRelative:(BOOL) isRelative;
|
||||
+ (SVGCurve) readMovetoDrawto:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin isRelative:(BOOL) isRelative;
|
||||
+ (SVGCurve) readMoveto:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin isRelative:(BOOL) isRelative;
|
||||
+ (SVGCurve) readMovetoArgumentSequence:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin isRelative:(BOOL) isRelative;
|
||||
|
||||
+ (SVGCurve) readLinetoCommand:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin isRelative:(BOOL) isRelative;
|
||||
+ (SVGCurve) readLinetoArgumentSequence:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin isRelative:(BOOL) isRelative;
|
||||
+ (SVGCurve) readVerticalLinetoCommand:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin isRelative:(BOOL) isRelative;
|
||||
+ (SVGCurve) readVerticalLinetoArgumentSequence:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin isRelative:(BOOL) isRelative;
|
||||
+ (SVGCurve) readHorizontalLinetoArgumentSequence:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin isRelative:(BOOL) isRelative;
|
||||
+ (SVGCurve) readHorizontalLinetoCommand:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin isRelative:(BOOL) isRelative;
|
||||
|
||||
+ (SVGCurve) readQuadraticCurvetoCommand:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin isRelative:(BOOL) isRelative;
|
||||
+ (SVGCurve) readQuadraticCurvetoArgumentSequence:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin isRelative:(BOOL) isRelative;
|
||||
+ (SVGCurve) readQuadraticCurvetoArgument:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin;
|
||||
+ (SVGCurve) readSmoothQuadraticCurvetoCommand:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin withPrevCurve:(SVGCurve)prevCurve;
|
||||
+ (SVGCurve) readSmoothQuadraticCurvetoArgumentSequence:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin withPrevCurve:(SVGCurve)prevCurve;
|
||||
+ (SVGCurve) readSmoothQuadraticCurvetoArgument:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin withPrevCurve:(SVGCurve)prevCurve;
|
||||
|
||||
+ (SVGCurve) readCurvetoCommand:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin isRelative:(BOOL) isRelative;
|
||||
+ (SVGCurve) readCurvetoArgumentSequence:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin isRelative:(BOOL) isRelative;
|
||||
+ (SVGCurve) readCurvetoArgument:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin;
|
||||
+ (SVGCurve) readSmoothCurvetoCommand:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin withPrevCurve:(SVGCurve)prevCurve isRelative:(BOOL) isRelative;
|
||||
+ (SVGCurve) readSmoothCurvetoArgumentSequence:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin withPrevCurve:(SVGCurve)prevCurve isRelative:(BOOL) isRelative;
|
||||
+ (SVGCurve) readSmoothCurvetoArgument:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin withPrevCurve:(SVGCurve)prevCurve;
|
||||
|
||||
+ (SVGCurve) readEllipticalArcArguments:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin isRelative:(BOOL) isRelative;
|
||||
|
||||
+ (SVGCurve) readCloseCommand:(NSScanner*)scanner path:(CGMutablePathRef)path relativeTo:(CGPoint)origin;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
SVGKSource.h
|
||||
|
||||
SVGKSource represents the info about where an SVG image's data came from ... from disk, from URL, from raw string - or anywhere
|
||||
|
||||
----
|
||||
NOTE: you should avoid instantiating SVGKSource directly; it is better to instantiate one of the subclasses, both because this
|
||||
allows faster / more direct reading of raw data, and because it preserves the information about "where" the SVG was loaded from.
|
||||
----
|
||||
|
||||
Once it has been parsed / loaded, that info is NOT PART OF the in-memory SVG any more - if you were to save the file, you could
|
||||
save it in a different location, with a different SVG Spec, etc.
|
||||
|
||||
However, it's useful for debugging (and for optional "save this document in same place it was loaded from / same format"
|
||||
to store this info at runtime just in case it's needed later.
|
||||
|
||||
Also, it helps during parsing to keep track of some document-level information
|
||||
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface SVGKSource : NSObject <NSCopying>
|
||||
|
||||
@property (nonatomic, strong) NSString* svgLanguageVersion; /**< <svg version=""> */
|
||||
@property (nonatomic, strong) NSInputStream* stream;
|
||||
|
||||
/** If known, the amount of data in bytes contained in this source (e.g. the filesize for a
|
||||
file, or the Content-Length header for a URL). Otherwise "0" for "unknown" */
|
||||
@property (nonatomic) uint64_t approximateLengthInBytesOr0;
|
||||
|
||||
/** Apple's NSDictionary has major design bugs, it does NOT support OOP programming;
|
||||
it is implemented on top of a C/C++ basic Strings table, and if you want to put objects
|
||||
in as keys, you have to generate a unique-but-stable string from each instead */
|
||||
@property(nonatomic,strong) NSString* keyForAppleDictionaries;
|
||||
|
||||
/** This should ONLY be used by subclasses that are implementing NSCopying methods. All other
|
||||
uses are discouraged / dangerous. If you use this, you MUST manually set self.stream correctly */
|
||||
- (id) initForCopying;
|
||||
|
||||
/**
|
||||
Subclasses convert their proprietary data into something that implements NSInputStream, which allows the
|
||||
base class to handle everything else
|
||||
*/
|
||||
- (id)initWithInputSteam:(NSInputStream*)stream;
|
||||
- (SVGKSource *)sourceFromRelativePath:(NSString *)path;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
|
||||
*/
|
||||
#import "SVGKSource.h"
|
||||
|
||||
@interface SVGKSourceLocalFile : SVGKSource
|
||||
|
||||
@property (nonatomic, strong) NSString* filePath;
|
||||
@property (nonatomic, readonly) BOOL wasRelative;
|
||||
|
||||
+ (SVGKSourceLocalFile*)sourceFromFilename:(NSString*)p;
|
||||
|
||||
+ (SVGKSourceLocalFile *)internalSourceAnywhereInBundleUsingName:(NSString *)name;
|
||||
+ (SVGKSourceLocalFile *)internalSourceAnywhereInBundle:(NSBundle *)bundle usingName:(NSString *)name;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
|
||||
*/
|
||||
#import "SVGKSource.h"
|
||||
|
||||
@interface SVGKSourceNSData : SVGKSource
|
||||
|
||||
@property (nonatomic, strong) NSData* rawData;
|
||||
@property (nonatomic, strong) NSURL* effectiveURL;
|
||||
|
||||
+ (SVGKSource*)sourceFromData:(NSData*)data URLForRelativeLinks:(NSURL*) url;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
|
||||
*/
|
||||
#import "SVGKSource.h"
|
||||
|
||||
@interface SVGKSourceString : SVGKSource
|
||||
|
||||
@property (nonatomic, strong) NSString* rawString;
|
||||
|
||||
+ (SVGKSource*)sourceFromContentsOfString:(NSString*)rawString;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
|
||||
*/
|
||||
#import "SVGKSource.h"
|
||||
|
||||
@interface SVGKSourceURL : SVGKSource
|
||||
|
||||
@property (nonatomic, strong) NSURL* URL;
|
||||
|
||||
+ (SVGKSource*)sourceFromURL:(NSURL*)u;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,176 @@
|
||||
/*!
|
||||
|
||||
SVGKit - https://github.com/SVGKit/SVGKit
|
||||
|
||||
THE MOST IMPORTANT ELEMENTS YOU'LL INTERACT WITH:
|
||||
|
||||
1. SVGKImage = contains most of the convenience methods for loading / reading / displaying SVG files
|
||||
2. SVGKImageView = the easiest / fastest way to display an SVGKImage on screen
|
||||
3. SVGKLayer = the low-level way of getting an SVG as a bunch of layers
|
||||
|
||||
SVGKImage makes heavy use of the following classes - you'll often use these classes (most of them given to you by an SVGKImage):
|
||||
|
||||
4. SVGKSource = the "file" or "URL" for loading the SVG data
|
||||
5. SVGKParseResult = contains the parsed SVG file AND/OR the list of errors during parsing
|
||||
|
||||
*/
|
||||
|
||||
#import "SVGKDefine.h"
|
||||
|
||||
|
||||
// MARK: - Framework Header File Content
|
||||
|
||||
@interface SVGKit : NSObject
|
||||
|
||||
+ (void) enableLogging;
|
||||
|
||||
@end
|
||||
|
||||
//! Project version number for SVGKitFramework-iOS.
|
||||
FOUNDATION_EXPORT double SVGKitFramework_VersionNumber;
|
||||
|
||||
//! Project version string for SVGKitFramework-iOS.
|
||||
FOUNDATION_EXPORT const unsigned char SVGKitFramework_VersionString[];
|
||||
|
||||
// In this header, you should import all the public headers of your framework using statements like #import <SVGKitFramework_iOS/PublicHeader.h>
|
||||
|
||||
// Core DOM
|
||||
#import "AppleSucksDOMImplementation.h"
|
||||
#import "Attr.h"
|
||||
#import "CDATASection.h"
|
||||
#import "CharacterData.h"
|
||||
#import "Comment.h"
|
||||
#import "CSSStyleDeclaration.h"
|
||||
#import "CSSRule.h"
|
||||
#import "CSSStyleSheet.h"
|
||||
#import "CSSStyleRule.h"
|
||||
#import "CSSRuleList.h"
|
||||
#import "CSSRuleList+Mutable.h"
|
||||
#import "CSSPrimitiveValue.h"
|
||||
#import "CSSPrimitiveValue_ConfigurablePixelsPerInch.h"
|
||||
#import "CSSValueList.h"
|
||||
#import "CSSValue_ForSubclasses.h"
|
||||
#import "CSSValue.h"
|
||||
#import "Document+Mutable.h"
|
||||
#import "Document.h"
|
||||
#import "DocumentCSS.h"
|
||||
#import "DocumentStyle.h"
|
||||
#import "StyleSheetList+Mutable.h"
|
||||
#import "StyleSheetList.h"
|
||||
#import "StyleSheet.h"
|
||||
#import "MediaList.h"
|
||||
#import "DocumentFragment.h"
|
||||
#import "DocumentType.h"
|
||||
#import "DOMHelperUtilities.h"
|
||||
#import "Element.h"
|
||||
#import "EntityReference.h"
|
||||
#import "NamedNodeMap.h"
|
||||
#import "NamedNodeMap_Iterable.h"
|
||||
#import "Node+Mutable.h"
|
||||
#import "Node.h"
|
||||
#import "NodeList+Mutable.h"
|
||||
#import "NodeList.h"
|
||||
#import "ProcessingInstruction.h"
|
||||
#import "Text.h"
|
||||
#import "DOMGlobalSettings.h"
|
||||
|
||||
// SVG DOM
|
||||
#import "SVGAngle.h"
|
||||
#import "SVGAnimatedPreserveAspectRatio.h"
|
||||
#import "SVGDefsElement.h"
|
||||
#import "SVGDocument.h"
|
||||
#import "SVGDocument_Mutable.h"
|
||||
#import "SVGElementInstance.h"
|
||||
#import "SVGElementInstance_Mutable.h"
|
||||
#import "SVGElementInstanceList.h"
|
||||
#import "SVGElementInstanceList_Internal.h"
|
||||
#import "SVGGElement.h"
|
||||
#import "SVGStylable.h"
|
||||
#import "SVGLength.h"
|
||||
#import "SVGMatrix.h"
|
||||
#import "SVGNumber.h"
|
||||
#import "SVGPoint.h"
|
||||
#import "SVGPreserveAspectRatio.h"
|
||||
#import "SVGRect.h"
|
||||
#import "SVGSVGElement_Mutable.h"
|
||||
#import "SVGTransform.h"
|
||||
#import "SVGUseElement.h"
|
||||
#import "SVGUseElement_Mutable.h"
|
||||
#import "SVGViewSpec.h"
|
||||
#import "SVGHelperUtilities.h"
|
||||
#import "SVGTransformable.h"
|
||||
#import "SVGFitToViewBox.h"
|
||||
#import "SVGTextPositioningElement.h"
|
||||
#import "SVGTextContentElement.h"
|
||||
#import "SVGTextPositioningElement_Mutable.h"
|
||||
#import "ConverterSVGToCALayer.h"
|
||||
#import "SVGGradientElement.h"
|
||||
#import "SVGGradientStop.h"
|
||||
#import "SVGLinearGradientElement.h"
|
||||
#import "SVGRadialGradientElement.h"
|
||||
#import "SVGStyleCatcher.h"
|
||||
#import "SVGStyleElement.h"
|
||||
#import "SVGCircleElement.h"
|
||||
#import "SVGDescriptionElement.h"
|
||||
#import "SVGElement.h"
|
||||
#import "SVGElement_ForParser.h"
|
||||
#import "SVGEllipseElement.h"
|
||||
#import "SVGGroupElement.h"
|
||||
#import "SVGImageElement.h"
|
||||
#import "SVGLineElement.h"
|
||||
#import "SVGPathElement.h"
|
||||
#import "SVGPolygonElement.h"
|
||||
#import "SVGPolylineElement.h"
|
||||
#import "SVGRectElement.h"
|
||||
#import "BaseClassForAllSVGBasicShapes.h"
|
||||
#import "BaseClassForAllSVGBasicShapes_ForSubclasses.h"
|
||||
#import "SVGSVGElement.h"
|
||||
#import "SVGTextElement.h"
|
||||
#import "SVGTitleElement.h"
|
||||
#import "SVGSwitchElement.h"
|
||||
#import "SVGClipPathElement.h"
|
||||
#import "TinySVGTextAreaElement.h"
|
||||
|
||||
// Parser
|
||||
|
||||
#import "SVGKImage+CGContext.h"
|
||||
#import "SVGKExporterNSData.h"
|
||||
#if SVGKIT_MAC
|
||||
#import "SVGKExporterNSImage.h"
|
||||
#else
|
||||
#import "SVGKExporterUIImage.h"
|
||||
#endif
|
||||
#import "SVGKSourceLocalFile.h"
|
||||
#import "SVGKSourceString.h"
|
||||
#import "SVGKSourceURL.h"
|
||||
#import "SVGKParserDefsAndUse.h"
|
||||
#import "SVGKParserDOM.h"
|
||||
#import "SVGKParserGradient.h"
|
||||
#import "SVGKParserPatternsAndGradients.h"
|
||||
#import "SVGKParserStyles.h"
|
||||
#import "SVGKParserSVG.h"
|
||||
#import "SVGKParser.h"
|
||||
#import "SVGKParseResult.h"
|
||||
#import "SVGKParserExtension.h"
|
||||
#import "SVGKPointsAndPathsParser.h"
|
||||
#import "CALayer+RecursiveClone.h"
|
||||
#import "SVGGradientLayer.h"
|
||||
#import "SVGTextLayer.h"
|
||||
#import "CALayerWithChildHitTest.h"
|
||||
#import "CAShapeLayerWithHitTest.h"
|
||||
#import "CGPathAdditions.h"
|
||||
#import "SVGKLayer.h"
|
||||
#import "SVGKImage.h"
|
||||
#import "SVGKSource.h"
|
||||
#import "NSCharacterSet+SVGKExtensions.h"
|
||||
#import "SVGKFastImageView.h"
|
||||
#import "SVGKImageView.h"
|
||||
#import "SVGKLayeredImageView.h"
|
||||
#import "SVGKPattern.h"
|
||||
#import "SVGUtils.h"
|
||||
#if SVGKIT_MAC
|
||||
#import "SVGKImageRep.h"
|
||||
#endif
|
||||
#import "NSData+NSInputStream.h"
|
||||
#import "SVGKSourceNSData.h"
|
||||
#import "SVGKInlineResource.h"
|
||||
@@ -0,0 +1,79 @@
|
||||
/*!
|
||||
SVGLength.h
|
||||
|
||||
http://www.w3.org/TR/SVG/types.html#InterfaceSVGLength
|
||||
|
||||
// Length Unit Types
|
||||
const unsigned short SVG_LENGTHTYPE_UNKNOWN = 0;
|
||||
const unsigned short SVG_LENGTHTYPE_NUMBER = 1;
|
||||
const unsigned short SVG_LENGTHTYPE_PERCENTAGE = 2;
|
||||
const unsigned short SVG_LENGTHTYPE_EMS = 3;
|
||||
const unsigned short SVG_LENGTHTYPE_EXS = 4;
|
||||
const unsigned short SVG_LENGTHTYPE_PX = 5;
|
||||
const unsigned short SVG_LENGTHTYPE_CM = 6;
|
||||
const unsigned short SVG_LENGTHTYPE_MM = 7;
|
||||
const unsigned short SVG_LENGTHTYPE_IN = 8;
|
||||
const unsigned short SVG_LENGTHTYPE_PT = 9;
|
||||
const unsigned short SVG_LENGTHTYPE_PC = 10;
|
||||
|
||||
readonly attribute unsigned short unitType;
|
||||
attribute float value setraises(DOMException);
|
||||
attribute float valueInSpecifiedUnits setraises(DOMException);
|
||||
attribute DOMString valueAsString setraises(DOMException);
|
||||
|
||||
void newValueSpecifiedUnits(in unsigned short unitType, in float valueInSpecifiedUnits) raises(DOMException);
|
||||
void convertToSpecifiedUnits(in unsigned short unitType) raises(DOMException);
|
||||
};
|
||||
*/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
typedef enum SVG_LENGTH_TYPE
|
||||
{
|
||||
SVG_LENGTHTYPE_UNKNOWN = 0,
|
||||
SVG_LENGTHTYPE_NUMBER = 1,
|
||||
SVG_LENGTHTYPE_PERCENTAGE = 2,
|
||||
SVG_LENGTHTYPE_EMS = 3,
|
||||
SVG_LENGTHTYPE_EXS = 4,
|
||||
SVG_LENGTHTYPE_PX = 5,
|
||||
SVG_LENGTHTYPE_CM = 6,
|
||||
SVG_LENGTHTYPE_MM = 7,
|
||||
SVG_LENGTHTYPE_IN = 8,
|
||||
SVG_LENGTHTYPE_PT = 9,
|
||||
SVG_LENGTHTYPE_PC = 10
|
||||
} SVG_LENGTH_TYPE;
|
||||
|
||||
|
||||
@interface SVGLength : NSObject
|
||||
|
||||
@property(nonatomic,readonly) SVG_LENGTH_TYPE unitType;
|
||||
@property(nonatomic) float value;
|
||||
@property(nonatomic) float valueInSpecifiedUnits;
|
||||
@property(nonatomic,strong) NSString* valueAsString;
|
||||
|
||||
-(void) newValueSpecifiedUnits:(SVG_LENGTH_TYPE) unitType valueInSpecifiedUnits:(float) valueInSpecifiedUnits;
|
||||
-(void) convertToSpecifiedUnits:(SVG_LENGTH_TYPE) unitType;
|
||||
|
||||
#pragma mark - things outside the spec but needed to make it usable in Objective C
|
||||
|
||||
+(SVGLength*) svgLengthZero;
|
||||
+(SVGLength*) svgLengthFromNSString:(NSString*) s;
|
||||
|
||||
/** returns this SVGLength as if it had been converted to pixels, using [self convertToSpecifiedUnits:SVG_LENGTHTYPE_PX]
|
||||
*/
|
||||
-(float) pixelsValue;
|
||||
|
||||
/** to calculate relative values pass in the appropriate viewport dimension (width, height, or diagonal measure)
|
||||
*/
|
||||
-(float) pixelsValueWithDimension:(float)dimension;
|
||||
|
||||
/** to calculate relative gradient values pass in the appropriate viewport dimension (width, height)
|
||||
* 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)
|
||||
*/
|
||||
-(float) pixelsValueWithGradientDimension:(float)dimension;
|
||||
|
||||
/** 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
|
||||
similar non-pixel value), using [self convertToSpecifiedUnits:SVG_LENGTHTYPE_NUMBER]
|
||||
*/
|
||||
-(float) numberValue;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// SVGLineElement.h
|
||||
// SVGKit
|
||||
//
|
||||
// Copyright Matt Rajca 2010-2011. All rights reserved.
|
||||
//
|
||||
|
||||
#import "BaseClassForAllSVGBasicShapes.h"
|
||||
|
||||
@interface SVGLineElement : BaseClassForAllSVGBasicShapes { }
|
||||
|
||||
@property (nonatomic, readonly) CGFloat x1;
|
||||
@property (nonatomic, readonly) CGFloat y1;
|
||||
@property (nonatomic, readonly) CGFloat x2;
|
||||
@property (nonatomic, readonly) CGFloat y2;
|
||||
|
||||
@end
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user