diff options
Diffstat (limited to 'tikzit/src/common')
-rw-r--r-- | tikzit/src/common/CircleShape.m | 38 | ||||
-rw-r--r-- | tikzit/src/common/ColorRGB.m | 20 | ||||
-rw-r--r-- | tikzit/src/common/Edge.m | 45 | ||||
-rw-r--r-- | tikzit/src/common/GraphChange.m | 3 | ||||
-rw-r--r-- | tikzit/src/common/GraphElementData.m | 6 | ||||
-rw-r--r-- | tikzit/src/common/GraphElementProperty.m | 36 | ||||
-rw-r--r-- | tikzit/src/common/Node.m | 15 | ||||
-rw-r--r-- | tikzit/src/common/Preambles.m | 16 | ||||
-rw-r--r-- | tikzit/src/common/PropertyHolder.m | 14 | ||||
-rw-r--r-- | tikzit/src/common/RectangleShape.m | 41 | ||||
-rw-r--r-- | tikzit/src/common/Shape.m | 6 | ||||
-rw-r--r-- | tikzit/src/common/TikzGraphAssembler.m | 3 | ||||
-rw-r--r-- | tikzit/src/common/TikzShape.m | 52 |
13 files changed, 158 insertions, 137 deletions
diff --git a/tikzit/src/common/CircleShape.m b/tikzit/src/common/CircleShape.m index 954cff2..f2d1d52 100644 --- a/tikzit/src/common/CircleShape.m +++ b/tikzit/src/common/CircleShape.m @@ -28,26 +28,26 @@ @implementation CircleShape - (id)init { - [super init]; - - Node *n0,*n1,*n2,*n3; - - n0 = [Node nodeWithPoint:NSMakePoint( 0.0f, 0.2f)]; - n1 = [Node nodeWithPoint:NSMakePoint( 0.2f, 0.0f)]; - n2 = [Node nodeWithPoint:NSMakePoint( 0.0f, -0.2f)]; - n3 = [Node nodeWithPoint:NSMakePoint(-0.2f, 0.0f)]; - - Edge *e0,*e1,*e2,*e3; - - e0 = [Edge edgeWithSource:n0 andTarget:n1]; [e0 setBend:-45]; - e1 = [Edge edgeWithSource:n1 andTarget:n2]; [e1 setBend:-45]; - e2 = [Edge edgeWithSource:n2 andTarget:n3]; [e2 setBend:-45]; - e3 = [Edge edgeWithSource:n3 andTarget:n0]; [e3 setBend:-45]; - - paths = [[NSSet alloc] initWithObjects:[NSArray arrayWithObjects:e0,e1,e2,e3,nil],nil]; + self = [super init]; + if (self) { + Node *n0,*n1,*n2,*n3; + + n0 = [Node nodeWithPoint:NSMakePoint( 0.0f, 0.2f)]; + n1 = [Node nodeWithPoint:NSMakePoint( 0.2f, 0.0f)]; + n2 = [Node nodeWithPoint:NSMakePoint( 0.0f, -0.2f)]; + n3 = [Node nodeWithPoint:NSMakePoint(-0.2f, 0.0f)]; + + Edge *e0,*e1,*e2,*e3; + + e0 = [Edge edgeWithSource:n0 andTarget:n1]; [e0 setBend:-45]; + e1 = [Edge edgeWithSource:n1 andTarget:n2]; [e1 setBend:-45]; + e2 = [Edge edgeWithSource:n2 andTarget:n3]; [e2 setBend:-45]; + e3 = [Edge edgeWithSource:n3 andTarget:n0]; [e3 setBend:-45]; + + paths = [[NSSet alloc] initWithObjects:[NSArray arrayWithObjects:e0,e1,e2,e3,nil],nil]; - styleTikz = @"circle"; - + styleTikz = @"circle"; + } return self; } diff --git a/tikzit/src/common/ColorRGB.m b/tikzit/src/common/ColorRGB.m index 74d1c55..c108cfe 100644 --- a/tikzit/src/common/ColorRGB.m +++ b/tikzit/src/common/ColorRGB.m @@ -205,18 +205,22 @@ static NSMapTable *colorHash = nil; } - (id)initWithRed:(unsigned short)r green:(unsigned short)g blue:(unsigned short)b { - [super init]; - red = r; - green = g; - blue = b; + self = [super init]; + if (self) { + red = r; + green = g; + blue = b; + } return self; } - (id)initWithFloatRed:(float)r green:(float)g blue:(float)b { - [super init]; - red = round(r*255.0f); - green = round(g*255.0f); - blue = round(b*255.0f); + self = [super init]; + if (self) { + red = round(r*255.0f); + green = round(g*255.0f); + blue = round(b*255.0f); + } return self; } diff --git a/tikzit/src/common/Edge.m b/tikzit/src/common/Edge.m index 9b607e6..dfc505c 100644 --- a/tikzit/src/common/Edge.m +++ b/tikzit/src/common/Edge.m @@ -28,32 +28,33 @@ @implementation Edge - (id)init { - [super init]; - data = [[GraphElementData alloc] init]; - bend = 0; - inAngle = 135; - outAngle = 45; - bendMode = EdgeBendModeBasic; - weight = 0.4f; - dirty = YES; - source = nil; - target = nil; - edgeNode = nil; - sourceAnchor = @""; - targetAnchor = @""; - + self = [super init]; + if (self) { + data = [[GraphElementData alloc] init]; + bend = 0; + inAngle = 135; + outAngle = 45; + bendMode = EdgeBendModeBasic; + weight = 0.4f; + dirty = YES; + source = nil; + target = nil; + edgeNode = nil; + sourceAnchor = @""; + targetAnchor = @""; + } return self; } - (id)initWithSource:(Node*)s andTarget:(Node*)t { - [self init]; - - [self setSource:s]; - [self setTarget:t]; - edgeNode = nil; - - dirty = YES; - + self = [self init]; + if (self) { + [self setSource:s]; + [self setTarget:t]; + edgeNode = nil; + + dirty = YES; + } return self; } diff --git a/tikzit/src/common/GraphChange.m b/tikzit/src/common/GraphChange.m index a997f15..cb95332 100644 --- a/tikzit/src/common/GraphChange.m +++ b/tikzit/src/common/GraphChange.m @@ -32,8 +32,7 @@ @implementation GraphChange - (id)init { - [super init]; - return self; + return [super init]; } @synthesize changeType; diff --git a/tikzit/src/common/GraphElementData.m b/tikzit/src/common/GraphElementData.m index a99a432..0750296 100644 --- a/tikzit/src/common/GraphElementData.m +++ b/tikzit/src/common/GraphElementData.m @@ -32,8 +32,10 @@ } - (id)init { - [super init]; - properties = [[NSMutableArray alloc] init]; + self = [super init]; + if (self) { + properties = [[NSMutableArray alloc] init]; + } return self; } diff --git a/tikzit/src/common/GraphElementProperty.m b/tikzit/src/common/GraphElementProperty.m index 1e8ad3a..5a19ace 100644 --- a/tikzit/src/common/GraphElementProperty.m +++ b/tikzit/src/common/GraphElementProperty.m @@ -38,29 +38,35 @@ } - (id)initWithAtomName:(NSString*)n { - [super init]; - [self setKey:n]; - [self setValue:nil]; - isAtom = YES; - isKeyMatch = NO; + self = [super init]; + if (self) { + [self setKey:n]; + [self setValue:nil]; + isAtom = YES; + isKeyMatch = NO; + } return self; } - (id)initWithPropertyValue:(NSString*)v forKey:(NSString*)k { - [super init]; - [self setKey:k]; - [self setValue:v]; - isAtom = NO; - isKeyMatch = NO; + self = [super init]; + if (self) { + [self setKey:k]; + [self setValue:v]; + isAtom = NO; + isKeyMatch = NO; + } return self; } - (id)initWithKeyMatching:(NSString*)k { - [super init]; - [self setKey:k]; - [self setValue:nil]; - isAtom = NO; - isKeyMatch = YES; + self = [super init]; + if (self) { + [self setKey:k]; + [self setValue:nil]; + isAtom = NO; + isKeyMatch = YES; + } return self; } diff --git a/tikzit/src/common/Node.m b/tikzit/src/common/Node.m index 7818a28..e564e5d 100644 --- a/tikzit/src/common/Node.m +++ b/tikzit/src/common/Node.m @@ -29,17 +29,18 @@ @implementation Node - (id)initWithPoint:(NSPoint)p { - [super init]; - data = [[GraphElementData alloc] init]; - style = nil; - label = @""; - point = p; + self = [super init]; + if (self) { + data = [[GraphElementData alloc] init]; + style = nil; + label = @""; + point = p; + } return self; } - (id)init { - [self initWithPoint:NSMakePoint(0.0f, 0.0f)]; - return self; + return [self initWithPoint:NSMakePoint(0.0f, 0.0f)]; } - (id)copyWithZone:(NSZone*)z { diff --git a/tikzit/src/common/Preambles.m b/tikzit/src/common/Preambles.m index 5343127..d6d18e9 100644 --- a/tikzit/src/common/Preambles.m +++ b/tikzit/src/common/Preambles.m @@ -59,13 +59,15 @@ static NSString *POSTAMBLE = } - (id)init { - [super init]; - selectedPreambleName = @"default"; - preambleDict = [[NSMutableDictionary alloc] initWithCapacity:1]; - [preambleDict setObject:[self defaultPreamble] forKey:@"custom"]; - styles = nil; - edges = nil; - styleManager = nil; + self = [super init]; + if (self) { + selectedPreambleName = @"default"; + preambleDict = [[NSMutableDictionary alloc] initWithCapacity:1]; + [preambleDict setObject:[self defaultPreamble] forKey:@"custom"]; + styles = nil; + edges = nil; + styleManager = nil; + } return self; } diff --git a/tikzit/src/common/PropertyHolder.m b/tikzit/src/common/PropertyHolder.m index 82b4889..2b3442f 100644 --- a/tikzit/src/common/PropertyHolder.m +++ b/tikzit/src/common/PropertyHolder.m @@ -27,14 +27,18 @@ - (id)init { - [super init]; - notificationName = @"UnknownPropertyChanged"; + self = [super init]; + if (self) { + notificationName = @"UnknownPropertyChanged"; + } return self; } - (id)initWithNotificationName:(NSString*)n { - [super init]; - notificationName = [n copy]; + self = [super init]; + if (self) { + notificationName = [n copy]; + } return self; } @@ -65,4 +69,4 @@ @end -// vi:ft=objc:ts=4:noet:sts=4:sw=4 +// vi:ft=objc:ts=4:et:sts=4:sw=4 diff --git a/tikzit/src/common/RectangleShape.m b/tikzit/src/common/RectangleShape.m index e332d40..db9c803 100644 --- a/tikzit/src/common/RectangleShape.m +++ b/tikzit/src/common/RectangleShape.m @@ -28,26 +28,27 @@ @implementation RectangleShape - (id)init { - [super init]; - Node *n0,*n1,*n2,*n3; - float sz = 0.2f; - - n0 = [Node nodeWithPoint:NSMakePoint(-sz, sz)]; - n1 = [Node nodeWithPoint:NSMakePoint( sz, sz)]; - n2 = [Node nodeWithPoint:NSMakePoint( sz,-sz)]; - n3 = [Node nodeWithPoint:NSMakePoint(-sz,-sz)]; - - Edge *e0,*e1,*e2,*e3; - - e0 = [Edge edgeWithSource:n0 andTarget:n1]; - e1 = [Edge edgeWithSource:n1 andTarget:n2]; - e2 = [Edge edgeWithSource:n2 andTarget:n3]; - e3 = [Edge edgeWithSource:n3 andTarget:n0]; - - paths = [[NSSet alloc] initWithObjects:[NSArray arrayWithObjects:e0,e1,e2,e3,nil],nil]; - - styleTikz = @"rectangle"; - + self = [super init]; + if (self) { + Node *n0,*n1,*n2,*n3; + float sz = 0.2f; + + n0 = [Node nodeWithPoint:NSMakePoint(-sz, sz)]; + n1 = [Node nodeWithPoint:NSMakePoint( sz, sz)]; + n2 = [Node nodeWithPoint:NSMakePoint( sz,-sz)]; + n3 = [Node nodeWithPoint:NSMakePoint(-sz,-sz)]; + + Edge *e0,*e1,*e2,*e3; + + e0 = [Edge edgeWithSource:n0 andTarget:n1]; + e1 = [Edge edgeWithSource:n1 andTarget:n2]; + e2 = [Edge edgeWithSource:n2 andTarget:n3]; + e3 = [Edge edgeWithSource:n3 andTarget:n0]; + + paths = [[NSSet alloc] initWithObjects:[NSArray arrayWithObjects:e0,e1,e2,e3,nil],nil]; + + styleTikz = @"rectangle"; + } return self; } diff --git a/tikzit/src/common/Shape.m b/tikzit/src/common/Shape.m index 0f1b35b..e86b122 100644 --- a/tikzit/src/common/Shape.m +++ b/tikzit/src/common/Shape.m @@ -51,8 +51,10 @@ } - (id)init { - [super init]; - paths = nil; + self = [super init]; + if (self) { + paths = nil; + } return self; } diff --git a/tikzit/src/common/TikzGraphAssembler.m b/tikzit/src/common/TikzGraphAssembler.m index 0c24b7c..c49298f 100644 --- a/tikzit/src/common/TikzGraphAssembler.m +++ b/tikzit/src/common/TikzGraphAssembler.m @@ -30,7 +30,7 @@ @implementation TikzGraphAssembler - (id)init { - self = nil; + [self release]; return nil; } @@ -126,7 +126,6 @@ yylex(&lval, &lloc, scanner); r = !(yyget_leng(scanner) < [testTikz length]); yylex_destroy(scanner); - [testTikz autorelease]; return r; } diff --git a/tikzit/src/common/TikzShape.m b/tikzit/src/common/TikzShape.m index 8cf823b..9735371 100644 --- a/tikzit/src/common/TikzShape.m +++ b/tikzit/src/common/TikzShape.m @@ -27,32 +27,32 @@ @implementation TikzShape - (id)initWithTikzFile:(NSString*)file { - [super init]; - - NSString *tikz = [NSString stringWithContentsOfFile:file - encoding:NSUTF8StringEncoding - error:NULL]; - if (tikz == nil) return nil; - - Graph *graph = [Graph graphFromTikz:tikz]; - if (graph == nil) return nil; - - NSRect graphBounds = ([graph hasBoundingBox]) ? [graph boundingBox] : [graph bounds]; - - float sz = 0.5f; - - // the "screen" coordinate space fits in the shape bounds - Transformer *t = [Transformer transformer]; - float width_ratio = (2*sz) / graphBounds.size.width; - float height_ratio = (2*sz) / graphBounds.size.height; - [t setScale:MIN(width_ratio, height_ratio)]; - NSRect bds = [t rectToScreen:graphBounds]; - NSPoint shift = NSMakePoint(-NSMidX(bds), - -NSMidY(bds)); - [t setOrigin:shift]; - [graph applyTransformer:t]; - paths = [[graph pathCover] retain]; - + self = [super init]; + if (self) { + NSString *tikz = [NSString stringWithContentsOfFile:file + encoding:NSUTF8StringEncoding + error:NULL]; + if (tikz == nil) return nil; + + Graph *graph = [Graph graphFromTikz:tikz]; + if (graph == nil) return nil; + + NSRect graphBounds = ([graph hasBoundingBox]) ? [graph boundingBox] : [graph bounds]; + + float sz = 0.5f; + + // the "screen" coordinate space fits in the shape bounds + Transformer *t = [Transformer transformer]; + float width_ratio = (2*sz) / graphBounds.size.width; + float height_ratio = (2*sz) / graphBounds.size.height; + [t setScale:MIN(width_ratio, height_ratio)]; + NSRect bds = [t rectToScreen:graphBounds]; + NSPoint shift = NSMakePoint(-NSMidX(bds), + -NSMidY(bds)); + [t setOrigin:shift]; + [graph applyTransformer:t]; + paths = [[graph pathCover] retain]; + } return self; } |