Tidied indentation

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@10573 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Nicola Pero 2001-07-25 09:43:15 +00:00
parent 949f20149f
commit 56ca810cfa

View file

@ -38,7 +38,7 @@ typedef struct {
} StringContext; } StringContext;
static void static void
initStringContext(StringContext *ctxt, NSString *string) initStringContext (StringContext *ctxt, NSString *string)
{ {
ctxt->string = string; ctxt->string = string;
ctxt->position = 0; ctxt->position = 0;
@ -46,7 +46,7 @@ initStringContext(StringContext *ctxt, NSString *string)
} }
static int static int
readNSString(StringContext *ctxt) readNSString (StringContext *ctxt)
{ {
return (ctxt->position < ctxt->length ) return (ctxt->position < ctxt->length )
? [ctxt->string characterAtIndex:ctxt->position++]: EOF; ? [ctxt->string characterAtIndex:ctxt->position++]: EOF;
@ -74,7 +74,7 @@ readNSString(StringContext *ctxt)
- (NSNumber*) underline; - (NSNumber*) underline;
- (void) resetParagraphStyle; - (void) resetParagraphStyle;
- (void) resetFont; - (void) resetFont;
- (void) addTab: (float) location type: (NSTextTabType) type; - (void) addTab: (float)location type: (NSTextTabType)type;
@end @end
@ -188,7 +188,7 @@ readNSString(StringContext *ctxt)
changed = YES; changed = YES;
} }
- (void) addTab: (float) location type: (NSTextTabType) type - (void) addTab: (float) location type: (NSTextTabType) type
{ {
NSTextTab *tab = [[NSTextTab alloc] initWithType: NSLeftTabStopType NSTextTab *tab = [[NSTextTab alloc] initWithType: NSLeftTabStopType
location: location]; location: location];
@ -200,7 +200,9 @@ readNSString(StringContext *ctxt)
tabChanged = YES; tabChanged = YES;
} }
else else
[paragraph addTabStop: tab]; {
[paragraph addTabStop: tab];
}
changed = YES; changed = YES;
RELEASE(tab); RELEASE(tab);
@ -224,14 +226,16 @@ readNSString(StringContext *ctxt)
@implementation RTFConsumer @implementation RTFConsumer
+ (NSAttributedString*) parseRTFD: (NSFileWrapper *)wrapper + (NSAttributedString*) parseRTFD: (NSFileWrapper *)wrapper
documentAttributes: (NSDictionary **)dict documentAttributes: (NSDictionary **)dict
{ {
RTFConsumer *consumer = [RTFConsumer new]; RTFConsumer *consumer = [RTFConsumer new];
NSAttributedString *text = nil; NSAttributedString *text = nil;
if ([wrapper isRegularFile]) if ([wrapper isRegularFile])
text = [consumer parseRTF: [wrapper regularFileContents] {
documentAttributes: dict]; text = [consumer parseRTF: [wrapper regularFileContents]
documentAttributes: dict];
}
else if ([wrapper isDirectory]) else if ([wrapper isDirectory])
{ {
NSDictionary *files = [wrapper fileWrappers]; NSDictionary *files = [wrapper fileWrappers];
@ -240,8 +244,10 @@ readNSString(StringContext *ctxt)
//FIXME: We should store the files in the consumer //FIXME: We should store the files in the consumer
// We try to read the main file in the directory // We try to read the main file in the directory
if ((contents = [files objectForKey: @"TXT.rtf"]) != nil) if ((contents = [files objectForKey: @"TXT.rtf"]) != nil)
text = [consumer parseRTF: [contents regularFileContents] {
documentAttributes: dict]; text = [consumer parseRTF: [contents regularFileContents]
documentAttributes: dict];
}
} }
RELEASE(consumer); RELEASE(consumer);
@ -250,7 +256,7 @@ readNSString(StringContext *ctxt)
} }
+ (NSAttributedString*) parseRTF: (NSData *)rtfData + (NSAttributedString*) parseRTF: (NSData *)rtfData
documentAttributes: (NSDictionary **)dict documentAttributes: (NSDictionary **)dict
{ {
RTFConsumer *consumer = [RTFConsumer new]; RTFConsumer *consumer = [RTFConsumer new];
NSAttributedString *text; NSAttributedString *text;
@ -274,7 +280,7 @@ readNSString(StringContext *ctxt)
return self; return self;
} }
- (void)dealloc - (void) dealloc
{ {
RELEASE(fonts); RELEASE(fonts);
RELEASE(attrs); RELEASE(attrs);
@ -340,10 +346,11 @@ readNSString(StringContext *ctxt)
CREATE_AUTORELEASE_POOL(pool); CREATE_AUTORELEASE_POOL(pool);
RTFscannerCtxt scanner; RTFscannerCtxt scanner;
StringContext stringCtxt; StringContext stringCtxt;
// We should read in the first few characters to find out which encoding we have // We should read in the first few characters to find out which
// encoding we have
NSString *rtfString = [[NSString alloc] NSString *rtfString = [[NSString alloc]
initWithData: rtfData initWithData: rtfData
encoding: NSASCIIStringEncoding]; encoding: NSASCIIStringEncoding];
// Reset this RFTConsumer, as it might already have been used! // Reset this RFTConsumer, as it might already have been used!
[self reset]; [self reset];
@ -362,7 +369,9 @@ readNSString(StringContext *ctxt)
RELEASE(pool); RELEASE(pool);
// document attributes // document attributes
if (dict) if (dict)
*dict = [self documentAttributes]; {
*dict = [self documentAttributes];
}
return [self result]; return [self result];
} }
@ -399,13 +408,13 @@ readNSString(StringContext *ctxt)
*/ */
/* handle errors (this is the yacc error mech) */ /* handle errors (this is the yacc error mech) */
void GSRTFerror(const char *msg) void GSRTFerror (const char *msg)
{ {
[NSException raise:NSInvalidArgumentException [NSException raise:NSInvalidArgumentException
format:@"Syntax error in RTF: %s", msg]; format:@"Syntax error in RTF: %s", msg];
} }
void GSRTFgenericRTFcommand(void *ctxt, RTFcmd cmd) void GSRTFgenericRTFcommand (void *ctxt, RTFcmd cmd)
{ {
NSDebugLLog(@"RTFParser", @"encountered rtf cmd:%s", cmd.name); NSDebugLLog(@"RTFParser", @"encountered rtf cmd:%s", cmd.name);
if (!cmd.isEmpty) if (!cmd.isEmpty)
@ -413,40 +422,46 @@ void GSRTFgenericRTFcommand(void *ctxt, RTFcmd cmd)
} }
//Start: we're doing some initialization //Start: we're doing some initialization
void GSRTFstart(void *ctxt) void GSRTFstart (void *ctxt)
{ {
NSDebugLLog(@"RTFParser", @"Start RTF parsing"); NSDebugLLog(@"RTFParser", @"Start RTF parsing");
[RESULT beginEditing]; [RESULT beginEditing];
} }
// Finished to parse one piece of RTF. // Finished to parse one piece of RTF.
void GSRTFstop(void *ctxt) void GSRTFstop (void *ctxt)
{ {
//<!> close all open bolds et al. //<!> close all open bolds et al.
[RESULT endEditing]; [RESULT endEditing];
NSDebugLLog(@"RTFParser", @"End RTF parsing"); NSDebugLLog(@"RTFParser", @"End RTF parsing");
} }
void GSRTFopenBlock(void *ctxt, BOOL ignore) void GSRTFopenBlock (void *ctxt, BOOL ignore)
{ {
if (!IGNORE) if (!IGNORE)
[(RTFConsumer *)ctxt push]; {
[(RTFConsumer *)ctxt push];
}
// Switch off any output for ignored block statements // Switch off any output for ignored block statements
if (ignore) if (ignore)
IGNORE++; {
IGNORE++;
}
} }
void GSRTFcloseBlock(void *ctxt, BOOL ignore) void GSRTFcloseBlock (void *ctxt, BOOL ignore)
{ {
if (ignore) if (ignore)
IGNORE--; {
IGNORE--;
}
if (!IGNORE) if (!IGNORE)
{ {
[(RTFConsumer *)ctxt pop]; [(RTFConsumer *)ctxt pop];
} }
} }
void GSRTFmangleText(void *ctxt, const char *text) void GSRTFmangleText (void *ctxt, const char *text)
{ {
int oldPosition = TEXTPOSITION; int oldPosition = TEXTPOSITION;
int textlen = strlen(text); int textlen = strlen(text);
@ -460,32 +475,41 @@ void GSRTFmangleText(void *ctxt, const char *text)
if (CHANGED) if (CHANGED)
{ {
attributes = [NSMutableDictionary dictionaryWithObjectsAndKeys: attributes = [NSMutableDictionary
[CTXT currentFont], NSFontAttributeName, dictionaryWithObjectsAndKeys:
PARAGRAPH, NSParagraphStyleAttributeName, [CTXT currentFont], NSFontAttributeName,
nil]; PARAGRAPH, NSParagraphStyleAttributeName,
nil];
if (UNDERLINE) if (UNDERLINE)
[attributes setObject: [CTXT underline] {
forKey: NSUnderlineStyleAttributeName]; [attributes setObject: [CTXT underline]
forKey: NSUnderlineStyleAttributeName];
}
if (SCRIPT) if (SCRIPT)
[attributes setObject: [CTXT script] {
forKey: NSSuperscriptAttributeName]; [attributes setObject: [CTXT script]
forKey: NSSuperscriptAttributeName];
}
if (FGCOLOUR != nil) if (FGCOLOUR != nil)
[attributes setObject: FGCOLOUR {
forKey: NSForegroundColorAttributeName]; [attributes setObject: FGCOLOUR
forKey: NSForegroundColorAttributeName];
}
if (BGCOLOUR != nil) if (BGCOLOUR != nil)
[attributes setObject: BGCOLOUR {
forKey: NSBackgroundColorAttributeName]; [attributes setObject: BGCOLOUR
forKey: NSBackgroundColorAttributeName];
}
[RESULT setAttributes: attributes range: [RESULT setAttributes: attributes
NSMakeRange(oldPosition, textlen)]; range: NSMakeRange(oldPosition, textlen)];
CHANGED = NO; CHANGED = NO;
} }
} }
} }
void GSRTFregisterFont(void *ctxt, const char *fontName, void GSRTFregisterFont (void *ctxt, const char *fontName,
RTFfontFamily family, int fontNumber) RTFfontFamily family, int fontNumber)
{ {
NSString *fontNameString; NSString *fontNameString;
NSNumber *fontId = [NSNumber numberWithInt: fontNumber]; NSNumber *fontId = [NSNumber numberWithInt: fontNumber];
@ -502,7 +526,7 @@ void GSRTFregisterFont(void *ctxt, const char *fontName,
[FONTS setObject: fontNameString forKey: fontId]; [FONTS setObject: fontNameString forKey: fontId];
} }
void GSRTFfontNumber(void *ctxt, int fontNumber) void GSRTFfontNumber (void *ctxt, int fontNumber)
{ {
NSNumber *fontId = [NSNumber numberWithInt: fontNumber]; NSNumber *fontId = [NSNumber numberWithInt: fontNumber];
NSString *fontName = [FONTS objectForKey: fontId]; NSString *fontName = [FONTS objectForKey: fontId];
@ -526,7 +550,7 @@ void GSRTFfontNumber(void *ctxt, int fontNumber)
} }
// <N> fontSize is in halfpoints according to spec // <N> fontSize is in halfpoints according to spec
void GSRTFfontSize(void *ctxt, int fontSize) void GSRTFfontSize (void *ctxt, int fontSize)
{ {
float size = halfpoints2points(fontSize); float size = halfpoints2points(fontSize);
@ -537,7 +561,7 @@ void GSRTFfontSize(void *ctxt, int fontSize)
} }
} }
void GSRTFpaperWidth(void *ctxt, int width) void GSRTFpaperWidth (void *ctxt, int width)
{ {
float fwidth = twips2points(width); float fwidth = twips2points(width);
NSMutableDictionary *dict = DOCUMENTATTRIBUTES; NSMutableDictionary *dict = DOCUMENTATTRIBUTES;
@ -545,16 +569,18 @@ void GSRTFpaperWidth(void *ctxt, int width)
NSSize size; NSSize size;
if (val == nil) if (val == nil)
size = NSMakeSize(fwidth, 792); {
size = NSMakeSize(fwidth, 792);
}
else else
{ {
size = [val sizeValue]; size = [val sizeValue];
size.width = fwidth; size.width = fwidth;
} }
[dict setObject: [NSValue valueWithSize: size] forKey: PAPERSIZE]; [dict setObject: [NSValue valueWithSize: size] forKey: PAPERSIZE];
} }
void GSRTFpaperHeight(void *ctxt, int height) void GSRTFpaperHeight (void *ctxt, int height)
{ {
float fheight = twips2points(height); float fheight = twips2points(height);
NSMutableDictionary *dict = DOCUMENTATTRIBUTES; NSMutableDictionary *dict = DOCUMENTATTRIBUTES;
@ -562,48 +588,50 @@ void GSRTFpaperHeight(void *ctxt, int height)
NSSize size; NSSize size;
if (val == nil) if (val == nil)
size = NSMakeSize(612, fheight); {
size = NSMakeSize(612, fheight);
}
else else
{ {
size = [val sizeValue]; size = [val sizeValue];
size.height = fheight; size.height = fheight;
} }
[dict setObject: [NSValue valueWithSize: size] forKey: PAPERSIZE]; [dict setObject: [NSValue valueWithSize: size] forKey: PAPERSIZE];
} }
void GSRTFmarginLeft(void *ctxt, int margin) void GSRTFmarginLeft (void *ctxt, int margin)
{ {
float fmargin = twips2points(margin); float fmargin = twips2points(margin);
NSMutableDictionary *dict = DOCUMENTATTRIBUTES; NSMutableDictionary *dict = DOCUMENTATTRIBUTES;
[dict setObject: [NSNumber numberWithFloat: fmargin] forKey: LEFTMARGIN]; [dict setObject: [NSNumber numberWithFloat: fmargin] forKey: LEFTMARGIN];
} }
void GSRTFmarginRight(void *ctxt, int margin) void GSRTFmarginRight (void *ctxt, int margin)
{ {
float fmargin = twips2points(margin); float fmargin = twips2points(margin);
NSMutableDictionary *dict = DOCUMENTATTRIBUTES; NSMutableDictionary *dict = DOCUMENTATTRIBUTES;
[dict setObject: [NSNumber numberWithFloat: fmargin] forKey: RIGHTMARGIN]; [dict setObject: [NSNumber numberWithFloat: fmargin] forKey: RIGHTMARGIN];
} }
void GSRTFmarginTop(void *ctxt, int margin) void GSRTFmarginTop (void *ctxt, int margin)
{ {
float fmargin = twips2points(margin); float fmargin = twips2points(margin);
NSMutableDictionary *dict = DOCUMENTATTRIBUTES; NSMutableDictionary *dict = DOCUMENTATTRIBUTES;
[dict setObject: [NSNumber numberWithFloat: fmargin] forKey: TOPMARGIN]; [dict setObject: [NSNumber numberWithFloat: fmargin] forKey: TOPMARGIN];
} }
void GSRTFmarginButtom(void *ctxt, int margin) void GSRTFmarginButtom (void *ctxt, int margin)
{ {
float fmargin = twips2points(margin); float fmargin = twips2points(margin);
NSMutableDictionary *dict = DOCUMENTATTRIBUTES; NSMutableDictionary *dict = DOCUMENTATTRIBUTES;
[dict setObject: [NSNumber numberWithFloat: fmargin] forKey: BUTTOMMARGIN]; [dict setObject: [NSNumber numberWithFloat: fmargin] forKey: BUTTOMMARGIN];
} }
void GSRTFfirstLineIndent(void *ctxt, int indent) void GSRTFfirstLineIndent (void *ctxt, int indent)
{ {
NSMutableParagraphStyle *para = PARAGRAPH; NSMutableParagraphStyle *para = PARAGRAPH;
float findent = twips2points(indent); float findent = twips2points(indent);
@ -617,7 +645,7 @@ void GSRTFfirstLineIndent(void *ctxt, int indent)
} }
} }
void GSRTFleftIndent(void *ctxt, int indent) void GSRTFleftIndent (void *ctxt, int indent)
{ {
NSMutableParagraphStyle *para = PARAGRAPH; NSMutableParagraphStyle *para = PARAGRAPH;
float findent = twips2points(indent); float findent = twips2points(indent);
@ -630,7 +658,7 @@ void GSRTFleftIndent(void *ctxt, int indent)
} }
} }
void GSRTFrightIndent(void *ctxt, int indent) void GSRTFrightIndent (void *ctxt, int indent)
{ {
NSMutableParagraphStyle *para = PARAGRAPH; NSMutableParagraphStyle *para = PARAGRAPH;
float findent = twips2points(indent); float findent = twips2points(indent);
@ -643,7 +671,7 @@ void GSRTFrightIndent(void *ctxt, int indent)
} }
} }
void GSRTFtabstop(void *ctxt, int location) void GSRTFtabstop (void *ctxt, int location)
{ {
float flocation = twips2points(location); float flocation = twips2points(location);
@ -653,7 +681,7 @@ void GSRTFtabstop(void *ctxt, int location)
} }
} }
void GSRTFalignCenter(void *ctxt) void GSRTFalignCenter (void *ctxt)
{ {
NSMutableParagraphStyle *para = PARAGRAPH; NSMutableParagraphStyle *para = PARAGRAPH;
@ -664,7 +692,7 @@ void GSRTFalignCenter(void *ctxt)
} }
} }
void GSRTFalignJustified(void *ctxt) void GSRTFalignJustified (void *ctxt)
{ {
NSMutableParagraphStyle *para = PARAGRAPH; NSMutableParagraphStyle *para = PARAGRAPH;
@ -675,7 +703,7 @@ void GSRTFalignJustified(void *ctxt)
} }
} }
void GSRTFalignLeft(void *ctxt) void GSRTFalignLeft (void *ctxt)
{ {
NSMutableParagraphStyle *para = PARAGRAPH; NSMutableParagraphStyle *para = PARAGRAPH;
@ -686,7 +714,7 @@ void GSRTFalignLeft(void *ctxt)
} }
} }
void GSRTFalignRight(void *ctxt) void GSRTFalignRight (void *ctxt)
{ {
NSMutableParagraphStyle *para = PARAGRAPH; NSMutableParagraphStyle *para = PARAGRAPH;
@ -697,7 +725,7 @@ void GSRTFalignRight(void *ctxt)
} }
} }
void GSRTFspaceAbove(void *ctxt, int space) void GSRTFspaceAbove (void *ctxt, int space)
{ {
NSMutableParagraphStyle *para = PARAGRAPH; NSMutableParagraphStyle *para = PARAGRAPH;
float fspace = twips2points(space); float fspace = twips2points(space);
@ -708,7 +736,7 @@ void GSRTFspaceAbove(void *ctxt, int space)
} }
} }
void GSRTFlineSpace(void *ctxt, int space) void GSRTFlineSpace (void *ctxt, int space)
{ {
NSMutableParagraphStyle *para = PARAGRAPH; NSMutableParagraphStyle *para = PARAGRAPH;
float fspace = twips2points(space); float fspace = twips2points(space);
@ -728,21 +756,21 @@ void GSRTFlineSpace(void *ctxt, int space)
} }
} }
void GSRTFdefaultParagraph(void *ctxt) void GSRTFdefaultParagraph (void *ctxt)
{ {
[CTXT resetParagraphStyle]; [CTXT resetParagraphStyle];
} }
void GSRTFstyle(void *ctxt, int style) void GSRTFstyle (void *ctxt, int style)
{ {
} }
void GSRTFdefaultCharacterStyle(void *ctxt) void GSRTFdefaultCharacterStyle (void *ctxt)
{ {
[CTXT resetFont]; [CTXT resetFont];
} }
void GSRTFaddColor(void *ctxt, int red, int green, int blue) void GSRTFaddColor (void *ctxt, int red, int green, int blue)
{ {
NSColor *colour = [NSColor colorWithCalibratedRed: red/255.0 NSColor *colour = [NSColor colorWithCalibratedRed: red/255.0
green: green/255.0 green: green/255.0
@ -752,22 +780,22 @@ void GSRTFaddColor(void *ctxt, int red, int green, int blue)
[COLOURS addObject: colour]; [COLOURS addObject: colour];
} }
void GSRTFaddDefaultColor(void *ctxt) void GSRTFaddDefaultColor (void *ctxt)
{ {
[COLOURS addObject: [NSColor textColor]]; [COLOURS addObject: [NSColor textColor]];
} }
void GSRTFcolorbg(void *ctxt, int color) void GSRTFcolorbg (void *ctxt, int color)
{ {
ASSIGN(BGCOLOUR, [COLOURS objectAtIndex: color]); ASSIGN(BGCOLOUR, [COLOURS objectAtIndex: color]);
} }
void GSRTFcolorfg(void *ctxt, int color) void GSRTFcolorfg (void *ctxt, int color)
{ {
ASSIGN(FGCOLOUR, [COLOURS objectAtIndex: color]); ASSIGN(FGCOLOUR, [COLOURS objectAtIndex: color]);
} }
void GSRTFsubscript(void *ctxt, int script) void GSRTFsubscript (void *ctxt, int script)
{ {
script = (int) (-halfpoints2points(script) / 3.0); script = (int) (-halfpoints2points(script) / 3.0);
@ -778,7 +806,7 @@ void GSRTFsubscript(void *ctxt, int script)
} }
} }
void GSRTFsuperscript(void *ctxt, int script) void GSRTFsuperscript (void *ctxt, int script)
{ {
script = (int) (halfpoints2points(script) / 3.0); script = (int) (halfpoints2points(script) / 3.0);
@ -789,7 +817,7 @@ void GSRTFsuperscript(void *ctxt, int script)
} }
} }
void GSRTFitalic(void *ctxt, BOOL state) void GSRTFitalic (void *ctxt, BOOL state)
{ {
if (state != ITALIC) if (state != ITALIC)
{ {
@ -798,7 +826,7 @@ void GSRTFitalic(void *ctxt, BOOL state)
} }
} }
void GSRTFbold(void *ctxt, BOOL state) void GSRTFbold (void *ctxt, BOOL state)
{ {
if (state != BOLD) if (state != BOLD)
{ {
@ -807,7 +835,7 @@ void GSRTFbold(void *ctxt, BOOL state)
} }
} }
void GSRTFunderline(void *ctxt, BOOL state) void GSRTFunderline (void *ctxt, BOOL state)
{ {
if (state != UNDERLINE) if (state != UNDERLINE)
{ {
@ -816,7 +844,7 @@ void GSRTFunderline(void *ctxt, BOOL state)
} }
} }
void GSRTFparagraph(void *ctxt) void GSRTFparagraph (void *ctxt)
{ {
GSRTFmangleText(ctxt, "\n"); GSRTFmangleText(ctxt, "\n");
CTXT->tabChanged = NO; CTXT->tabChanged = NO;