From 397cd4071a2f313b3b3b40f8b748c9f6103f5002 Mon Sep 17 00:00:00 2001 From: randomguy3 Date: Thu, 2 Feb 2012 12:15:57 +0000 Subject: Generate definitions for the edge styles in the default preamble git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@407 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64 --- tikzit/src/common/EdgeStyle.h | 2 ++ tikzit/src/common/EdgeStyle.m | 32 ++++++++++++++++++++++++++++++++ tikzit/src/common/NodeStyle.m | 25 +++++++++++-------------- tikzit/src/common/Preambles.m | 9 +++++++-- 4 files changed, 52 insertions(+), 16 deletions(-) (limited to 'tikzit/src/common') diff --git a/tikzit/src/common/EdgeStyle.h b/tikzit/src/common/EdgeStyle.h index 19ca173..66144f4 100644 --- a/tikzit/src/common/EdgeStyle.h +++ b/tikzit/src/common/EdgeStyle.h @@ -51,6 +51,8 @@ typedef enum { @property (assign) EdgeDectorationStyle decorationStyle; @property (assign) float thickness; +@property (readonly) NSString *tikz; + - (id)init; - (id)initWithName:(NSString*)nm; + (EdgeStyle*)defaultEdgeStyleWithName:(NSString*)nm; diff --git a/tikzit/src/common/EdgeStyle.m b/tikzit/src/common/EdgeStyle.m index 641d898..5314433 100644 --- a/tikzit/src/common/EdgeStyle.m +++ b/tikzit/src/common/EdgeStyle.m @@ -104,6 +104,38 @@ } } +- (NSString*)tikz { + NSMutableString *buf = [NSMutableString stringWithFormat:@"\\tikzstyle{%@}=[", name]; + + if (tailStyle == AH_Plain) + [buf appendString:@"<"]; + else if (tailStyle == AH_Latex) + [buf appendString:@"latex"]; + + [buf appendString:@"-"]; + + if (headStyle == AH_Plain) + [buf appendString:@">"]; + else if (headStyle == AH_Latex) + [buf appendString:@"latex"]; + + if (decorationStyle != ED_None) { + [buf appendString:@",postaction={decorate},decoration={markings,mark="]; + if (decorationStyle == ED_Arrow) + [buf appendString:@"at position .5 with {\\arrow{>}}"]; + else if (decorationStyle == ED_Tick) + [buf appendString:@"at position .5 with {\\draw (0,-0.1) -- (0,0.1);}"]; + [buf appendString:@"}"]; + } + + if (thickness != 1.0f) { + [buf appendFormat:@",line width=%.3f", thickness]; + } + + [buf appendString:@"]"]; + return buf; +} + - (void)dealloc { [name release]; [super dealloc]; diff --git a/tikzit/src/common/NodeStyle.m b/tikzit/src/common/NodeStyle.m index a2d22c7..b3d9ab2 100644 --- a/tikzit/src/common/NodeStyle.m +++ b/tikzit/src/common/NodeStyle.m @@ -135,28 +135,25 @@ } - (NSString*)tikz { - NSString *fillName, *strokeName; - - NSMutableString *buf = [NSMutableString string]; - - fillName = [fillColorRGB name]; - strokeName = [strokeColorRGB name]; - + NSString *fillName = [fillColorRGB name]; + NSString *strokeName = [strokeColorRGB name]; + NSString *stroke = @""; + if (strokeThickness != 1) { + stroke = [NSString stringWithFormat:@",line width=%@ pt", + [NSNumber numberWithFloat:(float)strokeThickness * 0.4f]]; + } + // If the colors are unknown, fall back on hexnames. These should be defined as colors // in the Preambles class. if (fillName == nil) fillName = [fillColorRGB hexName]; if (strokeName == nil) strokeName = [strokeColorRGB hexName]; - - [buf appendFormat:@"\\tikzstyle{%@}=[%@,fill=%@,draw=%@%@]\n", + + return [NSString stringWithFormat:@"\\tikzstyle{%@}=[%@,fill=%@,draw=%@%@]", name, shapeName, fillName, strokeName, - (strokeThickness != 1) ? - [NSString stringWithFormat:@",line width=%@ pt", - [NSNumber numberWithFloat:(float)strokeThickness * 0.4f]] : @""]; - - return buf; + stroke]; } - (BOOL)strokeColorIsKnown { diff --git a/tikzit/src/common/Preambles.m b/tikzit/src/common/Preambles.m index 4f74dd0..d41f9b0 100644 --- a/tikzit/src/common/Preambles.m +++ b/tikzit/src/common/Preambles.m @@ -28,6 +28,7 @@ static NSString *PREAMBLE_HEAD = @"\\documentclass{article}\n" @"\\usepackage[svgnames]{xcolor}\n" @"\\usepackage{tikz}\n" +@"\\usetikzlibrary{decorations.markings}\n" @"\\pagestyle{empty}\n" @"\n" @"\\pgfdeclarelayer{edgelayer}\n" @@ -102,7 +103,7 @@ static NSString *POSTAMBLE = NSMutableString *colbuf = [NSMutableString string]; NSMutableSet *colors = [NSMutableSet setWithCapacity:2*[styles count]]; for (NodeStyle *st in styles) { - [buf appendFormat:@"%@", [st tikz]]; + [buf appendFormat:@"%@\n", [st tikz]]; ColorRGB *fill = [st fillColorRGB]; ColorRGB *stroke = [st strokeColorRGB]; if ([fill name] == nil && ![colors containsObject:fill]) { @@ -117,8 +118,12 @@ static NSString *POSTAMBLE = [fill hexName], [fill redFloat], [fill greenFloat], [fill blueFloat]]; } } + [buf appendString:@"\n"]; + for (EdgeStyle *st in [styleManager edgeStyles]) { + [buf appendFormat:@"%@\n", [st tikz]]; + } - NSString *defs = [[NSString alloc] initWithFormat:@"%@%@", colbuf, buf]; + NSString *defs = [[NSString alloc] initWithFormat:@"%@\n%@", colbuf, buf]; [pool drain]; return [defs autorelease]; -- cgit v1.2.3