--- gnuplot-3.8j.0/term/aquaterm.trm.macosx Mon Jun 9 22:22:13 2003 +++ gnuplot-3.8j.0/term/aquaterm.trm Tue Dec 30 07:11:53 2003 @@ -1,5 +1,5 @@ /* -*- objc -*- - * $Id: aquaterm.trm,v 1.1 2003/06/09 13:22:13 lhecking Exp $ + * $Id: aquaTerm.trm,v 1.23 2003/12/29 22:11:53 persquare Exp $ * */ @@ -78,15 +78,17 @@ #endif /* PM3D */ /* End of entries */ -#define AQUA_XMAX (11.69*72) /* = 842, paper width times screen resolution */ -#define AQUA_YMAX (8.26*72) /* = 595, paper height times screen resolution */ -#define AQUA_VTIC 8 -#define AQUA_HTIC 8 -#define AQUA_VCHAR 16 /* default font is Times at 16 points */ -#define AQUA_HCHAR (AQUA_VCHAR*6/10) - -#define PM3D_COLORS 128 -#define CYCLIC_COLORS 8 +#define AQUA_SCALE_FACTOR 10.0 /* Increase resolution */ +#define AQUA_XMAX (11.69*72.0*AQUA_SCALE_FACTOR) /* = 842, paper width times screen resolution */ +#define AQUA_YMAX (8.26*72.0*AQUA_SCALE_FACTOR) /* = 595, paper height times screen resolution */ +#define AQUA_VTIC (8.0*AQUA_SCALE_FACTOR) +#define AQUA_HTIC (8.0*AQUA_SCALE_FACTOR) +#define AQUA_VCHAR (16.0*AQUA_SCALE_FACTOR) /* default font is Times at 16 points */ +#define AQUA_HCHAR (AQUA_VCHAR*6.0/10.0) + +#define SPECIAL_COLORS 4 +#define CYCLIC_COLORS 9 +//#define PM3D_COLORS (AQT_COLORMAP_SIZE - CYCLIC_COLORS - SPECIAL_COLORS - 1) #define GOT_AQUA_PROTO #endif /* TERM_PROTO */ @@ -94,68 +96,12 @@ #ifndef TERM_PROTO_ONLY #ifdef TERM_BODY +#import -#import -#import -#import #import -#import -#import -#import -#import -#import +#import #import -// -// ---------------------------------------------------------------- -// AQTProtocol - A protocol that lists the Objective-C methods -// that AquaTerm responds to -// ---------------------------------------------------------------- -// -// For documentation of this protocol, see http://aquaterm.sf.net -// -#define AQTProtocolVersion 0.3 - -@protocol AQTProtocol -- (oneway void)openModel:(int)newModel; -- (oneway void)closeModel; -- (bycopy NSDictionary *) getAquaTermInfo; -- (oneway void)setTitle:(bycopy NSString *)newTitle; -- (oneway void)setFontWithName:(bycopy NSString *)fontName size:(bycopy float)fontSize; -- (oneway void)setColor:(bycopy NSColor *)aColor forIndex:(int)colorIndex; -- (oneway void)addString:(bycopy NSString *)text - atPoint:(bycopy NSPoint)point - withJustification:(bycopy int)justification - atAngle:(bycopy float)angle - withIndexedColor:(bycopy int)colorIndex; -- (oneway void)addPolyline:(bycopy NSBezierPath *)aPath withIndexedColor:(bycopy int)colorIndex; -- (oneway void)addPolygon:(bycopy NSBezierPath *)aPath withIndexedColor:(bycopy int)colorIndex; -- (oneway void)addPolyline:(bycopy NSBezierPath *)aPath withRGBColor:(bycopy NSColor *)color; -- (oneway void)addPolygon:(bycopy NSBezierPath *)aPath withRGBColor:(bycopy NSColor *)color; -- (oneway void)addBitmap:(bycopy NSData *)imageData size:(NSSize)theSize bounds:(NSRect)theBounds; -- (oneway void)addImageFromFile:(bycopy NSString *)filename bounds:(NSRect)theBounds; -- (oneway void)render; -- (oneway void)clearRect:(NSRect)rect; -@end /* AQTProtocol */ - - -/* - * The class NSBezierPath doesn't implement replacementObjectForPortCoder so - * we add that behaviour as a category for NSBezierPath - */ -@interface NSBezierPath (NSBezierPathDOCategory) -- (id)replacementObjectForPortCoder:(NSPortCoder *)portCoder; -@end - -@implementation NSBezierPath (NSBezierPathDOCategory) -- (id)replacementObjectForPortCoder:(NSPortCoder *)portCoder -{ - if ([portCoder isBycopy]) - return self; - return [super replacementObjectForPortCoder:portCoder]; -} -@end - /* Debugging extras */ static inline void NOOP_(id x, ...) {;} @@ -165,447 +111,13 @@ #define LOG NOOP_ #endif /* LOGGING */ -#define BUFMAX 50 +static NSAutoreleasePool *arpool; +// static NSAutoreleasePool *innerPool; -static NSAutoreleasePool *arpool; // our autorelease pool -static id gnuTermAccess; // local object manages the D.O. connection -static int currentWindow = 0; // the only option to set (could be set _before_ instatiation of gnuTermAccess) +static AQTAdapter *adapter; +static int currentWindow = 0; // the only option to set (could be set _before_ instatiation of adapter) static char AQUA_title[MAX_LINE_LEN + 1]; static t_sm_palette *aqua_palette = nil; - -// ---------------------------------------------------------------- -// AQTAdapter - A class to mediate between gnuplot C-function calls -// and AquaTerm Objective-C remote messages -// ---------------------------------------------------------------- -// -@interface AQTAdapter : NSObject -{ - @private - id server; - NSMutableDictionary *termInfo; - NSBezierPath *thePath; - int justificationMode; - int linetype; - double linewidth; - double gray; - int pm3dColor; - float textAngle; - int bufCount; -} --(id) server; --(NSMutableDictionary *)termInfo; --(void) invalidateServer; --(void) invalidateServer:(const char *)message; --(BOOL) connectToServer; --(BOOL)checkServerVersion; --(void) updateInfoFromServer; --(void) flushBuffers; --(void) moveToPoint:(NSPoint)point; --(void) lineToPoint:(NSPoint)point; --(void) setLinetype:(int)linetype; --(void) putText:(const char *)str at:(NSPoint)point; --(void) setJustification:(int)mode; --(void) setTextAngle:(int)angle; --(void) setTextfont:(const char *)font; --(void) fillRect:(NSRect)rect style:(int)style; --(void) setLinewidth:(double)linewidth; --(double) linewidth; --(void) setColor:(NSColor *)color forIndex:(int)index; --(void) setFillColor:(double)gray; --(void) setPolygonUsing:(int)count corners:(gpiPoint *)corners; --(void) openModel:(int)newFigure; --(void) closeModel; --(void) renderModel; --(void) setTitle:(NSString *)newTitle; -@end - -@implementation AQTAdapter --(id) init -{ - if (self = [super init]) - { - thePath = [[NSBezierPath alloc] init]; - termInfo = [[NSMutableDictionary alloc] initWithCapacity:0]; - justificationMode = 0; - linetype = 0; - gray = 0.0; - textAngle = 0.0; - pm3dColor = 0; - [self connectToServer]; - } - return self; -} - --(void) dealloc -{ - [termInfo release]; - [thePath release]; - [server release]; - [super dealloc]; -} - --(id) server -{ - return server; -} - --(NSMutableDictionary *)termInfo -{ - return termInfo; -} - --(void) invalidateServer -{ - [self invalidateServer:"Lost connection to server,\nuse \"set term aqua \" to reconnect.\n"]; -} - --(void) invalidateServer:(const char *)message -{ - [server release]; - server = nil; - currentWindow = 0; - printf(message); -} - --(BOOL)connectToServer -{ - BOOL defaultApp = YES; - BOOL didConnect = NO; - NSString *appString; - - server = [NSConnection rootProxyForConnectionWithRegisteredName:@"aquatermServer" host:nil]; - if (server) /* Server is running ready to go */ - { - [server retain]; - didConnect = YES; - } - else /* Server isn't running, we must fire it up */ - { - if (getenv("GNUTERMAPP") == (char *)NULL) - { - appString = [NSString stringWithString:@"AquaTerm"]; - } - else - { - appString = [NSString stringWithCString:getenv("GNUTERMAPP")]; - defaultApp = NO; - } - /* Try to launch application */ - if ([[NSWorkspace sharedWorkspace] launchApplication:appString] == NO) - { - printf("Failed to launch display server (%s).\n", [appString cString]); - if (defaultApp) - { - printf("You must either put the server application in \n"); - printf("the /Applications folder, ~/Applications folder\n"); - printf("or set the environment variable GNUTERMAPP to the\n"); - printf("full path of the server application, e.g.\n"); - printf("setenv GNUTERMAPP \"/some/strange/location/MyServer.app\"\n"); - } - else - { - printf("Check environment variable GNUTERMAPP for errors\n"); - } - } - else - { - do { /* Wait for it to register Server methods with OS */ - server =[NSConnection rootProxyForConnectionWithRegisteredName:@"aquatermServer" host:nil]; - } while (!server); /* This could result in a hang... */ - [server retain]; - didConnect = YES; - } - } - if (didConnect) - { - if ([self checkServerVersion]) - { - [server setProtocolForProxy:@protocol(AQTProtocol)]; - [self updateInfoFromServer]; - } - else - { - [self invalidateServer:"Display server (AquaTerm) is too old, please update it.\nSee http://qauaterm.sf.net for more info and download.\n"]; - didConnect = NO; - } - } - return didConnect; -} - --(BOOL)checkServerVersion -{ - BOOL canRun = NO; - float serverVersion = 0.0; - NS_DURING /* try */ - if ([server respondsToSelector:@selector(getAquaTermInfo)]) - { - serverVersion = [[[server getAquaTermInfo] objectForKey:@"AQTVersion"] floatValue]; - } - NS_HANDLER - if ([[localException name] isEqualToString:@"NSInvalidSendPortException"]) - [self invalidateServer]; - else - [localException raise]; - NS_ENDHANDLER - if (serverVersion >= AQTProtocolVersion) - { - canRun = YES; - } - return canRun; -} - --(void) updateInfoFromServer -{ - NS_DURING /* try */ - [termInfo setDictionary:[server getAquaTermInfo]]; - NS_HANDLER - if ([[localException name] isEqualToString:@"NSInvalidSendPortException"]) - [self invalidateServer]; - else - [localException raise]; - NS_ENDHANDLER -} - --(void) flushBuffers -{ - NS_DURING - if ([thePath isEmpty] == NO) - { - [thePath setLineWidth:linewidth]; - [server addPolyline:thePath withIndexedColor:linetype]; - [thePath removeAllPoints]; - bufCount = 0; - } - NS_HANDLER - if ([[localException name] isEqualToString:@"NSInvalidSendPortException"]) - [self invalidateServer]; - else - [localException raise]; - NS_ENDHANDLER -} - --(void) moveToPoint:(NSPoint)point -{ - - bufCount +=1; - if (bufCount > BUFMAX) - { - [self flushBuffers]; - } - [thePath moveToPoint:point]; -} - --(void) lineToPoint:(NSPoint)point -{ - NSPoint trailPoint; - bufCount +=1; - if (bufCount > BUFMAX) - { - trailPoint = [thePath currentPoint]; - [self flushBuffers]; - [thePath moveToPoint:trailPoint]; - } - [thePath lineToPoint:point]; -} - --(void) setLinetype:(int)newLinetype -{ - if (linetype != newLinetype) - { - [self flushBuffers]; - linetype = newLinetype; - } -} - --(void) putText:(const char *)str at:(NSPoint)point -{ - NS_DURING - [server addString:[NSString stringWithCString:str] - atPoint:point - withJustification:justificationMode - atAngle:textAngle - withIndexedColor:linetype]; - NS_HANDLER - if ([[localException name] isEqualToString:@"NSInvalidSendPortException"]) - [self invalidateServer]; - else - [localException raise]; - NS_ENDHANDLER -} - --(void) setJustification:(int)mode -{ - justificationMode = mode; -} - --(void) setTextAngle:(int)angle -{ - if (angle==0) - { - textAngle = 0.0; - } - else - { - textAngle = 90.0; - } -} - --(void) setTextfont:(const char *)font -{ - NSArray *tempArray = [NSArray arrayWithArray:[[NSString stringWithCString:font] componentsSeparatedByString:@","]]; - // FIXME: Check up on why setFont always is followed by a call with an empty string. - NS_DURING - switch ([tempArray count]) - { - case 2: - [server setFontWithName:[tempArray objectAtIndex:0] size:[[tempArray objectAtIndex:1] floatValue]]; - break; - case 1: - if ([[tempArray objectAtIndex:0] isEqualToString:@""]) - { - [server setFontWithName:[termInfo objectForKey:@"AQTDefaultFontName"] size:[[termInfo objectForKey:@"AQTDefaultFontSize"] floatValue]]; - } - else - { - [server setFontWithName:[tempArray objectAtIndex:0] size:[[termInfo objectForKey:@"AQTDefaultFontSize"] floatValue]]; - } - break; - case 0: - // fallthrough - default: - [server setFontWithName:[termInfo objectForKey:@"AQTDefaultFontName"] size:[[termInfo objectForKey:@"AQTDefaultFontSize"] floatValue]]; - break; - } - NS_HANDLER - if ([[localException name] isEqualToString:@"NSInvalidSendPortException"]) - [self invalidateServer]; - else - [localException raise]; - NS_ENDHANDLER - // - // Read back the new font info. (Not neccessarily what we wanted ;-) - // - [self updateInfoFromServer]; -} - --(void) fillRect:(NSRect)rect style:(int)style -{ - [self flushBuffers]; - NS_DURING - [server clearRect:rect]; - [server render]; - NS_HANDLER - if ([[localException name] isEqualToString:@"NSInvalidSendPortException"]) - [self invalidateServer]; - else - [localException raise]; - NS_ENDHANDLER -} - --(void) setLinewidth:(double)newLinewidth -{ - if (linewidth != newLinewidth) - { - [self flushBuffers]; - linewidth = newLinewidth; - } -} - -- (double) linewidth -{ - return linewidth; -} - --(void) setFillColor:(double)newGray -{ - int newFillColor = (int)(PM3D_COLORS*newGray+.5); - [self flushBuffers]; - pm3dColor = newFillColor; -} - --(void) setColor:(NSColor *)color forIndex:(int)index -{ - NS_DURING - [server setColor:color forIndex:index]; - NS_HANDLER - if ([[localException name] isEqualToString:@"NSInvalidSendPortException"]) - [self invalidateServer]; - else - [localException raise]; - NS_ENDHANDLER -} - --(void) setPolygonUsing:(int)count corners:(gpiPoint *)corners -{ - int i; - NSBezierPath *thePolygon = [NSBezierPath bezierPath]; - NSColor *pColor = [NSColor colorWithCalibratedRed:aqua_palette->color[pm3dColor].r green:aqua_palette->color[pm3dColor].g blue:aqua_palette->color[pm3dColor].b alpha:1.0]; - - [thePolygon moveToPoint:NSMakePoint(corners[0].x, corners[0].y)]; - for (i=1;i< count;i++) - { - [thePolygon lineToPoint:NSMakePoint(corners[i].x, corners[i].y)]; - } - [thePolygon closePath]; - NS_DURING - [server addPolygon:thePolygon withRGBColor:pColor]; - NS_HANDLER - if ([[localException name] isEqualToString:@"NSInvalidSendPortException"]) - [self invalidateServer]; - else - [localException raise]; - NS_ENDHANDLER -} - --(void) openModel:(int)newFigure -{ - NS_DURING - [server openModel:newFigure]; - NS_HANDLER - if ([[localException name] isEqualToString:@"NSInvalidSendPortException"]) - [self invalidateServer]; - else - [localException raise]; - NS_ENDHANDLER -} - --(void) closeModel -{ - NS_DURING - [server closeModel]; - NS_HANDLER - if ([[localException name] isEqualToString:@"NSInvalidSendPortException"]) - [self invalidateServer]; - else - [localException raise]; - NS_ENDHANDLER -} - --(void) renderModel -{ - NS_DURING - [server render]; - NS_HANDLER - if ([[localException name] isEqualToString:@"NSInvalidSendPortException"]) - [self invalidateServer]; - else - [localException raise]; - NS_ENDHANDLER -} - --(void) setTitle:(NSString *)newTitle; -{ - NS_DURING - [server setTitle:newTitle]; - NS_HANDLER - if ([[localException name] isEqualToString:@"NSInvalidSendPortException"]) - [self invalidateServer]; - else - [localException raise]; - NS_ENDHANDLER -} - -@end /* AQTAdapter */ // // ---------------------------------------------------------------- // Gnuplot driver implementation @@ -618,7 +130,6 @@ AQUA_OTHER }; - static struct gen_table AQUA_opts[] = { { "d$efault", AQUA_DEFAULT }, @@ -667,118 +178,147 @@ AQUA_init() { float fontSize, fontWHRatio; - float vTicSize, pixelWHRatio; LOG(@"Aqua Init"); - if (arpool == NULL) /* Make sure we don't leak mem by allocating every time */ + if (arpool == NULL) { - arpool = [[NSAutoreleasePool alloc] init]; - gnuTermAccess = [[AQTAdapter alloc] init]; + arpool = [[NSAutoreleasePool alloc] init]; + adapter = [[AQTAdapter alloc] init]; } else { - if (![gnuTermAccess server]) /* server could be invalid (=nil) for several reasons */ + if (!adapter) /* server could be invalid (=nil) for several reasons */ { - [gnuTermAccess connectToServer]; /* This will reconnect (or print an explanation) */ + printf("Error -- no adapter!\n"); + exit(1); } } - term->xmax =[[[gnuTermAccess termInfo] objectForKey:@"AQTXMax"] unsignedIntValue]; - term->ymax =[[[gnuTermAccess termInfo] objectForKey:@"AQTYMax"] unsignedIntValue]; - fontSize = [[[gnuTermAccess termInfo] objectForKey:@"AQTFontSize"] floatValue]; - fontWHRatio = [[[gnuTermAccess termInfo] objectForKey:@"AQTFontWHRatio"] floatValue]; - pixelWHRatio = [[[gnuTermAccess termInfo] objectForKey:@"AQTPixelWHRatio"] floatValue]; - vTicSize = AQUA_VTIC; - term->v_char = (unsigned int) fontSize; - term->h_char = (unsigned int) (fontWHRatio * fontSize); - term->v_tic = (unsigned int) vTicSize; - term->h_tic = (unsigned int) (vTicSize * pixelWHRatio); - // - // Set up the basic indexed colormap for gnuplot - // - [gnuTermAccess setColor:[NSColor redColor] forIndex:0]; - [gnuTermAccess setColor:[NSColor greenColor] forIndex:1]; - [gnuTermAccess setColor:[NSColor blueColor] forIndex:2]; - [gnuTermAccess setColor:[NSColor magentaColor] forIndex:3]; - [gnuTermAccess setColor:[NSColor cyanColor] forIndex:4]; - [gnuTermAccess setColor:[NSColor colorWithCalibratedRed:0.627 green:0.322 blue:0.176 alpha:1.0] forIndex:5]; // Sienna - [gnuTermAccess setColor:[NSColor colorWithCalibratedRed:1.0 green: 0.647 blue:0.0 alpha:1.0] forIndex:6]; // Orange - [gnuTermAccess setColor:[NSColor colorWithCalibratedRed:1.0 green:0.498 blue:0.314 alpha:1.0] forIndex:7]; // Coral + term->xmax = AQUA_XMAX; + term->ymax = AQUA_YMAX; + term->v_char = (unsigned int) AQUA_VCHAR; + term->h_char = (unsigned int) AQUA_HCHAR; + term->v_tic = (unsigned int) AQUA_VTIC; + term->h_tic = (unsigned int) AQUA_HTIC; } TERM_PUBLIC void AQUA_reset() { + NSLog(@"AQUA_reset"); +// [arpool release]; +// arpool = [[NSAutoreleasePool alloc] init]; } TERM_PUBLIC void AQUA_text() { - [gnuTermAccess flushBuffers]; - [gnuTermAccess closeModel]; + [adapter renderPlot]; } TERM_PUBLIC void AQUA_graphics() { - [gnuTermAccess openModel:currentWindow]; - if(*AQUA_title) - { - [gnuTermAccess setTitle:[NSString stringWithCString:AQUA_title]]; - *AQUA_title = 0; - } + NSString *title; + LOG(@"Pre: (arpool + innerpool, innerpool) =(%d, %d)", [NSAutoreleasePool autoreleasedObjectCount], + [NSAutoreleasePool topAutoreleasePoolCount]); +// [innerPool release]; +// innerPool = [[NSAutoreleasePool alloc] init]; + LOG(@"Post: (arpool + innerpool, innerpool) =(%d, %d)",[NSAutoreleasePool autoreleasedObjectCount], + [NSAutoreleasePool topAutoreleasePoolCount]); + if(*AQUA_title) + { + // title = [NSString stringWithCString:AQUA_title]; <-- FIXME: broken! + *AQUA_title = 0; + } + [adapter openPlotWithIndex:currentWindow]; + [adapter setPlotSize:NSMakeSize(term->xmax/AQUA_SCALE_FACTOR, term->ymax/AQUA_SCALE_FACTOR)]; + [adapter setPlotTitle:[NSString stringWithFormat:@"Figure %d", currentWindow]]; + // + // Set up the basic indexed colormap for gnuplot + // + // Special colors + [adapter setColormapEntry:0 red:0.1 green:0.1 blue:0.1]; // linetype -4 + [adapter setColormapEntry:1 red:0.9 green:0.9 blue:0.9]; // linetype -3 (xor;interactive) light gray + [adapter setColormapEntry:2 red:0.0 green:0.0 blue:0.0]; // linetype -2 (border) black + [adapter setColormapEntry:3 red:0.8 green:0.8 blue:0.8]; // linetype -1 (gridlines) light grey + // Cyclic colors + [adapter setColormapEntry:4 red:1.0 green:0.0 blue:0.0]; // red + [adapter setColormapEntry:5 red:0.0 green:1.0 blue:0.0]; // green + [adapter setColormapEntry:6 red:0.0 green:0.0 blue:1.0]; // blue + [adapter setColormapEntry:7 red:1.0 green:0.0 blue:1.0]; // magenta + [adapter setColormapEntry:8 red:0.0 green:1.0 blue:1.0]; // cyan + [adapter setColormapEntry:9 red:0.6275 green:0.3216 blue:0.1765]; // sienna + [adapter setColormapEntry:10 red:1.0 green:0.6471 blue:0.0];// orange + [adapter setColormapEntry:11 red:0.5 green:0.4980 blue:0.3137];// coral + [adapter setColormapEntry:12 red:0.25 green:0.25 blue:0.25];// grey } TERM_PUBLIC void AQUA_move(unsigned int x, unsigned int y) { - [gnuTermAccess moveToPoint:NSMakePoint(x, y)]; + [adapter moveToPoint:NSMakePoint(x/AQUA_SCALE_FACTOR, y/AQUA_SCALE_FACTOR)]; } TERM_PUBLIC void AQUA_vector(unsigned int x, unsigned int y) { - [gnuTermAccess lineToPoint:NSMakePoint(x, y)]; + [adapter addLineToPoint:NSMakePoint(x/AQUA_SCALE_FACTOR, y/AQUA_SCALE_FACTOR)]; } TERM_PUBLIC void AQUA_linetype(int linetype) { - LOG(@"AQUA_linetype(%d)", linetype); - [gnuTermAccess setLinetype: linetype%CYCLIC_COLORS]; + static int lastType = -99; + LOG(@"AQUA_linetype(%d) ---> entry: %d", linetype, (linetype%CYCLIC_COLORS)+SPECIAL_COLORS); + // Note: this operation maps linestyle -4 to -1 onto colormap entries 0 to 3 + if (linetype != lastType) + { + lastType = linetype; + [adapter takeColorFromColormapEntry:(linetype%CYCLIC_COLORS)+SPECIAL_COLORS]; + } } +static float textAngle = 0.0; +static int textJustify = 0; + TERM_PUBLIC void AQUA_put_text(unsigned int x, unsigned int y, const char *str) { if (!strlen(str)) return; - [gnuTermAccess putText:str at:NSMakePoint(x,y)]; + [adapter addLabel:[NSString stringWithCString: str] + atPoint:NSMakePoint(x/AQUA_SCALE_FACTOR,y/AQUA_SCALE_FACTOR) + angle:textAngle + align:(textJustify | AQTAlignMiddle)]; } TERM_PUBLIC int AQUA_justify_text (enum JUSTIFY mode) { - [gnuTermAccess setJustification:mode]; + textJustify = mode; return (TRUE); } TERM_PUBLIC int AQUA_text_angle (int angle) { - [gnuTermAccess setTextAngle: angle]; +//NSLog(@"Angle %d", angle); + textAngle = (float)angle; return (TRUE); } TERM_PUBLIC int AQUA_set_font(const char *font) /* "font,size" */ { - float fontWHRatio, fontSize; - [gnuTermAccess setTextfont:font]; - // FIXME: Does gnuplot process these values? - fontSize = [[[gnuTermAccess termInfo] objectForKey:@"AQTFontSize"] floatValue]; - fontWHRatio = [[[gnuTermAccess termInfo] objectForKey:@"AQTFontWHRatio"] floatValue]; - term->v_char = (unsigned int) fontSize; - term->h_char = (unsigned int) (fontWHRatio * fontSize); + NSArray *parts = [[NSString stringWithCString:font] componentsSeparatedByString:@","]; + float fontSize = [[parts objectAtIndex:1] floatValue]; + NSLog([NSString stringWithCString:font]); + [adapter setFontname:[parts objectAtIndex:0]]; + [adapter setFontsize:fontSize]; + // FIXME: Does gnuplot process these values? + term->v_char = (unsigned int) (fontSize*AQUA_SCALE_FACTOR); + term->h_char = (unsigned int) (fontSize*AQUA_SCALE_FACTOR*0.6); + return (TRUE); } @@ -792,27 +332,28 @@ AQUA_point(unsigned int x, unsigned int y, int number) { // Avoid changing lw unless necessary +/* if ([gnuTermAccess linewidth] != 1.0) { double tmplw = [gnuTermAccess linewidth]; [gnuTermAccess setLinewidth:1.0]; - [gnuTermAccess moveToPoint:NSMakePoint(x-.5, y)]; - [gnuTermAccess lineToPoint:NSMakePoint(x+.5, y)]; + [gnuTermAccess moveToPoint:NSMakePoint(x/AQUA_SCALE_FACTOR-.5, y/AQUA_SCALE_FACTOR)]; + [gnuTermAccess lineToPoint:NSMakePoint(x/AQUA_SCALE_FACTOR +.5, y/AQUA_SCALE_FACTOR)]; [gnuTermAccess setLinewidth: tmplw]; } else { - [gnuTermAccess moveToPoint:NSMakePoint(x-.5, y)]; - [gnuTermAccess lineToPoint:NSMakePoint(x+.5, y)]; + [gnuTermAccess moveToPoint:NSMakePoint(x/AQUA_SCALE_FACTOR-.5, y/AQUA_SCALE_FACTOR)]; + [gnuTermAccess lineToPoint:NSMakePoint(x/AQUA_SCALE_FACTOR +.5, y/AQUA_SCALE_FACTOR)]; } +*/ do_point(x, y, number); } TERM_PUBLIC void AQUA_suspend(void) /* after one plot of multiplot */ { - [gnuTermAccess flushBuffers]; - [gnuTermAccess renderModel]; + [adapter renderPlot]; } TERM_PUBLIC void @@ -823,13 +364,16 @@ TERM_PUBLIC void AQUA_boxfill(int style, unsigned int x1, unsigned int y1, unsigned int width, unsigned int height) /* clear part of multiplot */ { - [gnuTermAccess fillRect:NSMakeRect(x1,y1,width,height) style:style]; + // FIXME: What does style imply? + NSRect scaledRect = NSMakeRect(x1/AQUA_SCALE_FACTOR, y1/AQUA_SCALE_FACTOR, width/AQUA_SCALE_FACTOR, height/AQUA_SCALE_FACTOR); + [adapter eraseRect:scaledRect]; + [adapter addFilledRect:scaledRect]; } TERM_PUBLIC void AQUA_linewidth(double linewidth) { - [gnuTermAccess setLinewidth:linewidth]; + [adapter setLinewidth:linewidth]; } TERM_PUBLIC void @@ -845,24 +389,38 @@ { if (palette == NULL) { - return 128; + return ([adapter colormapSize] - CYCLIC_COLORS - SPECIAL_COLORS - 1); } else { - aqua_palette = palette; + int i; + for (i = 0; i < palette->colors-1; i++) + { + [adapter setColormapEntry:(SPECIAL_COLORS+CYCLIC_COLORS+i) + red:palette->color[i].r + green:palette->color[i].g + blue:palette->color[i].b]; + } } } TERM_PUBLIC void AQUA_set_color(double gray) { - [gnuTermAccess setFillColor:gray]; + int numPM3DCol = [adapter colormapSize] - CYCLIC_COLORS - SPECIAL_COLORS - 1; + int index = (int)(gray*numPM3DCol) + SPECIAL_COLORS + CYCLIC_COLORS; + [adapter takeColorFromColormapEntry:index]; } TERM_PUBLIC void - AQUA_filled_polygon(int points, gpiPoint *corners) + AQUA_filled_polygon(int pc, gpiPoint *corners) { - [gnuTermAccess setPolygonUsing:points corners:corners]; + int i; + [adapter moveToVertexPoint:NSMakePoint(corners[0].x / AQUA_SCALE_FACTOR, corners[0].y / AQUA_SCALE_FACTOR)]; + for (i=1; i