123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- #import "SVGSVGElement.h"
- #import "SVGSVGElement_Mutable.h"
- #import "CALayerWithChildHitTest.h"
- #import "DOMHelperUtilities.h"
- #import "SVGHelperUtilities.h"
- #import "SVGElement_ForParser.h"
- #import "SVGKDefine_Private.h"
- @interface SVGSVGElement()
- #pragma mark - elements REQUIRED to implement the spec but not included in SVG Spec due to bugs in the spec writing!
- @property(nonatomic,readwrite) SVGRect requestedViewport;
- @end
- @implementation SVGSVGElement
- @synthesize x;
- @synthesize y;
- @synthesize width;
- @synthesize height;
- @synthesize contentScriptType;
- @synthesize contentStyleType;
- @synthesize viewport;
- @synthesize pixelUnitToMillimeterX;
- @synthesize pixelUnitToMillimeterY;
- @synthesize screenPixelToMillimeterX;
- @synthesize screenPixelToMillimeterY;
- @synthesize useCurrentView;
- @synthesize currentView;
- @synthesize currentScale;
- @synthesize currentTranslate;
- @synthesize source;
- @synthesize viewBox = _viewBox;
- @synthesize preserveAspectRatio;
- #pragma mark - NON SPEC, violating, properties
- -(void)dealloc
- {
- self.viewBox = SVGRectUninitialized();
- }
- #pragma mark - CSS Spec methods (via the DocumentCSS protocol)
- -(void)loadDefaults
- {
- self.styleSheets = [[StyleSheetList alloc] init];
- }
- @synthesize styleSheets;
- -(CSSStyleDeclaration *)getOverrideStyle:(Element *)element pseudoElt:(NSString *)pseudoElt
- {
- NSAssert(FALSE, @"Not implemented yet");
-
- return nil;
- }
- #pragma mark - SVG Spec methods
- -(long) suspendRedraw:(long) maxWaitMilliseconds { NSAssert( FALSE, @"Not implemented yet" ); return 0; }
- -(void) unsuspendRedraw:(long) suspendHandleID { NSAssert( FALSE, @"Not implemented yet" ); }
- -(void) unsuspendRedrawAll { NSAssert( FALSE, @"Not implemented yet" ); }
- -(void) forceRedraw { NSAssert( FALSE, @"Not implemented yet" ); }
- -(void) pauseAnimations { NSAssert( FALSE, @"Not implemented yet" ); }
- -(void) unpauseAnimations { NSAssert( FALSE, @"Not implemented yet" ); }
- -(BOOL) animationsPaused { NSAssert( FALSE, @"Not implemented yet" ); return TRUE; }
- -(float) getCurrentTime { NSAssert( FALSE, @"Not implemented yet" ); return 0.0; }
- -(void) setCurrentTime:(float) seconds { NSAssert( FALSE, @"Not implemented yet" ); }
- -(NodeList*) getIntersectionList:(SVGRect) rect referenceElement:(SVGElement*) referenceElement { NSAssert( FALSE, @"Not implemented yet" ); return nil; }
- -(NodeList*) getEnclosureList:(SVGRect) rect referenceElement:(SVGElement*) referenceElement { NSAssert( FALSE, @"Not implemented yet" ); return nil; }
- -(BOOL) checkIntersection:(SVGElement*) element rect:(SVGRect) rect { NSAssert( FALSE, @"Not implemented yet" ); return FALSE; }
- -(BOOL) checkEnclosure:(SVGElement*) element rect:(SVGRect) rect { NSAssert( FALSE, @"Not implemented yet" ); return FALSE; }
- -(void) deselectAll { NSAssert( FALSE, @"Not implemented yet" );}
- -(SVGNumber) createSVGNumber
- {
- SVGNumber n = { 0 };
- return n;
- }
- -(SVGLength*) createSVGLength
- {
- return [SVGLength new];
- }
- -(SVGAngle*) createSVGAngle { NSAssert( FALSE, @"Not implemented yet" ); return nil; }
- -(SVGPoint*) createSVGPoint { NSAssert( FALSE, @"Not implemented yet" ); return nil; }
- -(SVGMatrix*) createSVGMatrix { NSAssert( FALSE, @"Not implemented yet" ); return nil; }
- -(SVGRect) createSVGRect
- {
- SVGRect r = { 0.0, 0.0, 0.0, 0.0 };
- return r;
- }
- -(SVGTransform*) createSVGTransform { NSAssert( FALSE, @"Not implemented yet" ); return nil; }
- -(SVGTransform*) createSVGTransformFromMatrix:(SVGMatrix*) matrix { NSAssert( FALSE, @"Not implemented yet" ); return nil; }
- -(Element*) getElementById:(NSString*) elementId
- {
- return [DOMHelperUtilities privateGetElementById:elementId childrenOfElement:self];
- }
- #pragma mark - Objective C methods needed given our current non-compliant SVG Parser
- - (void)postProcessAttributesAddingErrorsTo:(SVGKParseResult *)parseResult {
- [super postProcessAttributesAddingErrorsTo:parseResult];
-
-
-
-
-
-
- NSString* stringWidth = [self getAttribute:@"width"];
- NSString* stringHeight = [self getAttribute:@"height"];
-
- NSString* pos_x = [self getAttribute:@"x"];
- NSString* pos_y = [self getAttribute:@"y"];
-
- if (pos_x == nil || pos_x.length < 1)
- self.x = 0;
- else
- self.x = [SVGLength svgLengthFromNSString:pos_x];
-
- if (pos_y == nil || pos_y.length < 1)
- self.y = 0;
- else
- self.y = [SVGLength svgLengthFromNSString:pos_y];
-
- if( stringWidth == nil || stringWidth.length < 1 )
- self.width = nil;
- else
- self.width = [SVGLength svgLengthFromNSString:[self getAttribute:@"width"]];
-
- if( stringHeight == nil || stringHeight.length < 1 )
- self.height = nil;
- else
- self.height = [SVGLength svgLengthFromNSString:[self getAttribute:@"height"]];
-
-
- if( self.width.unitType == SVG_LENGTHTYPE_PERCENTAGE )
- self.width = nil;
- if( self.height.unitType == SVG_LENGTHTYPE_PERCENTAGE )
- self.height = nil;
-
-
- if( self.width != nil && self.height != nil )
- self.requestedViewport = SVGRectMake( [self.x pixelsValue], [self.y pixelsValue], [self.width pixelsValue], [self.height pixelsValue] );
- else
- self.requestedViewport = SVGRectUninitialized();
-
-
-
- self.viewport = self.requestedViewport;
-
- if( [[self getAttribute:@"viewBox"] length] > 0 )
- {
- NSArray* boxElements = [[self getAttribute:@"viewBox"] componentsSeparatedByString:@" "];
- if ([boxElements count] < 2) {
-
- boxElements = [[self getAttribute:@"viewBox"] componentsSeparatedByString:@","];
- }
- _viewBox = SVGRectMake([[boxElements objectAtIndex:0] floatValue], [[boxElements objectAtIndex:1] floatValue], [[boxElements objectAtIndex:2] floatValue], [[boxElements objectAtIndex:3] floatValue]);
- }
- else
- {
- self.viewBox = SVGRectUninitialized();
- }
-
- [SVGHelperUtilities parsePreserveAspectRatioFor:self];
- if( stringWidth == nil || stringWidth.length < 1 )
- self.width = nil;
- else
- self.width = [SVGLength svgLengthFromNSString:[self getAttribute:@"width"]];
-
- SVGKitLogVerbose(@"[%@] DEBUG INFO: set document viewBox = %@", [self class], NSStringFromSVGRect(self.viewBox));
- }
- - (SVGElement *)findFirstElementOfClass:(Class)classParameter {
- for (SVGElement *element in self.childNodes)
- {
- if ([element isKindOfClass:classParameter])
- return element;
- }
-
- return nil;
- }
- - (CALayer *) newLayer
- {
-
- CALayer* _layer = [CALayerWithChildHitTest layer];
-
- [SVGHelperUtilities configureCALayer:_layer usingElement:self];
-
-
- CGRect newBoundsFromSVGTag = CGRectFromSVGRect( self.viewport );
- _layer.frame = newBoundsFromSVGTag;
-
- return _layer;
- }
- - (void)layoutLayer:(CALayer *)layer {
-
-
- }
- #pragma mark - elements REQUIRED to implement the spec but not included in SVG Spec due to bugs in the spec writing!
- -(double)aspectRatioFromWidthPerHeight
- {
- return [self.height pixelsValue] == 0 ? 0 : [self.width pixelsValue] / [self.height pixelsValue];
- }
- -(double)aspectRatioFromViewBox
- {
- return self.viewBox.height == 0 ? 0 : self.viewBox.width / self.viewBox.height;
- }
- @end
|