Changeset 13524
- Timestamp:
- 09/20/2005 04:58:32 PM (3 years ago)
- Files:
-
- trunk/Frameworks/Adium Framework/AIHTMLDecoder.h (modified) (1 diff)
- trunk/Frameworks/Adium Framework/AIHTMLDecoder.m (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Frameworks/Adium Framework/AIHTMLDecoder.h
r11197 r13524 36 36 unsigned allowAIMsubprofileLinks: 1; 37 37 } thingsToInclude; 38 39 //For the horribly ghetto span and div tags used by the HTML logs 40 BOOL send; 41 BOOL receive; 42 BOOL inDiv; 43 BOOL inLogSpan; 38 44 } 39 45 trunk/Frameworks/Adium Framework/AIHTMLDecoder.m
r13123 r13524 96 96 - (void)processBodyTagArgs:(NSDictionary *)inArgs attributes:(AITextAttributes *)textAttributes; 97 97 - (void)processLinkTagArgs:(NSDictionary *)inArgs attributes:(AITextAttributes *)textAttributes; 98 - (void)processSpanTagArgs:(NSDictionary *)inArgs attributes:(AITextAttributes *)textAttributes; 99 - (void)processDivTagArgs:(NSDictionary *)inArgs attributes:(AITextAttributes *)textAttributes; 98 100 - (NSAttributedString *)processImgTagArgs:(NSDictionary *)inArgs attributes:(AITextAttributes *)textAttributes; 99 101 - (BOOL)appendImage:(NSImage *)attachmentImage toString:(NSMutableString *)string withName:(NSString *)fileSafeChunk altString:(NSString *)attachmentString imagesPath:(NSString *)imagesPath; … … 225 227 BOOL openFontTag = NO; 226 228 227 //Setup the destination HTML string228 NSMutableString *string = [NSMutableString string];229 if (thingsToInclude.headers) [string appendString:@"<HTML>"];230 231 229 //Setup the incoming message as a regular string, and get its length 232 230 NSString *inMessageString = [inMessage string]; 233 231 unsigned messageLength = [inMessageString length]; 234 232 233 //Setup the destination HTML string 234 NSMutableString *string = [NSMutableString string]; 235 if (thingsToInclude.headers) { 236 [string appendString:@"<HTML>"]; 237 } 238 239 //If the text is right-to-left, enclose all our HTML in an rtl DIV tag 240 BOOL rightToLeft = NO; 241 if (!thingsToInclude.simpleTagsOnly) { 242 if ((messageLength > 0) && 243 ([[inMessage attribute:NSParagraphStyleAttributeName 244 atIndex:0 245 effectiveRange:nil] baseWritingDirection] == NSWritingDirectionRightToLeft)) { 246 [string appendString:@"<DIV dir=\"rtl\">"]; 247 rightToLeft = YES; 248 } 249 } 250 235 251 //Setup the default attributes 236 252 NSString *currentFamily = [@"Helvetica" retain]; … … 619 635 620 636 if (thingsToInclude.fontTags && thingsToInclude.closingFontTags && openFontTag) [string appendString:CloseFontTag]; //Close any open font tag 637 if (rightToLeft) { 638 [string appendString:@"</DIV>"]; 639 } 621 640 if (thingsToInclude.headers && pageColor) [string appendString:@"</BODY>"]; //Close the body tag 622 641 if (thingsToInclude.headers) [string appendString:@"</HTML>"]; //Close the HTML … … 650 669 NSMutableAttributedString *attrString; 651 670 AITextAttributes *textAttributes; 652 BOOL send = NO, receive = NO, inDiv = NO, inLogSpan = NO; 671 672 //Reset the div and span ivars 673 send = NO; 674 receive = NO; 675 inDiv = NO; 676 inLogSpan = NO; 653 677 654 678 //set up … … 719 743 //HTML 720 744 if ([chunkString caseInsensitiveCompare:HTML] == NSOrderedSame) { 721 //We ignore stuff inside the HTML tag, but don't want to see the end of it745 //We ignore most stuff inside the HTML tag, but don't want to see the end of it. 722 746 [scanner scanUpToCharactersFromSet:absoluteTagEnd intoString:&chunkString]; 747 723 748 } else if ([chunkString caseInsensitiveCompare:CloseHTML] == NSOrderedSame) { 724 749 //We are done … … 732 757 733 758 [textAttributes setTextColor:[NSColor blackColor]]; 759 734 760 //DIV 735 761 } else if ([chunkString caseInsensitiveCompare:@"DIV"] == NSOrderedSame) { 736 [scanner scanUpToCharactersFromSet:absoluteTagEnd 737 intoString:&chunkString]; 762 if ([scanner scanUpToCharactersFromSet:absoluteTagEnd 763 intoString:&chunkString]) { 764 [self processDivTagArgs:[self parseArguments:chunkString] attributes:textAttributes]; 765 } 738 766 inDiv = YES; 739 if ([chunkString caseInsensitiveCompare:@" class=\"send\""] == NSOrderedSame) { 740 send = YES; 741 receive = NO; 742 } else if ([chunkString caseInsensitiveCompare:@" class=\"receive\""] == NSOrderedSame) { 743 receive = YES; 744 send = NO; 745 } else if ([chunkString caseInsensitiveCompare:@" class=\"status\""] == NSOrderedSame) { 746 [textAttributes setTextColor:[NSColor grayColor]]; 747 } 767 748 768 } else if ([chunkString caseInsensitiveCompare:@"/DIV"] == NSOrderedSame) { 749 769 inDiv = NO; 770 750 771 //LINK 751 772 } else if ([chunkString caseInsensitiveCompare:@"A"] == NSOrderedSame) { … … 771 792 } else if ([chunkString caseInsensitiveCompare:Font] == NSOrderedSame) { 772 793 if ([scanner scanUpToCharactersFromSet:absoluteTagEnd intoString:&chunkString]) { 773 774 //Process the font tag if it's in a log775 if ([chunkString caseInsensitiveCompare:@" class=\"sender\""] == NSOrderedSame) {776 if (inDiv && send) {777 [textAttributes setTextColor:[NSColor colorWithCalibratedRed:0.0 green:0.5 blue:0.0 alpha:1.0]];778 } else if (inDiv && receive) {779 [textAttributes setTextColor:[NSColor colorWithCalibratedRed:0.0 green:0.0 blue:0.5 alpha:1.0]];780 }781 }782 783 794 //Process the font tag's contents 784 795 [self processFontTagArgs:[self parseArguments:chunkString] attributes:textAttributes]; … … 791 802 } else if ([chunkString caseInsensitiveCompare:Span] == NSOrderedSame) { 792 803 if ([scanner scanUpToCharactersFromSet:absoluteTagEnd intoString:&chunkString]) { 793 794 //Process the span tag if it's in a log 795 if ([chunkString caseInsensitiveCompare:@" class=\"sender\""] == NSOrderedSame) { 796 if (inDiv && send) { 797 [textAttributes setTextColor:[NSColor colorWithCalibratedRed:0.0 798 green:0.5 799 blue:0.0 800 alpha:1.0]]; 801 inLogSpan = YES; 802 } else if (inDiv && receive) { 803 [textAttributes setTextColor:[NSColor colorWithCalibratedRed:0.0 804 green:0.0 805 blue:0.5 806 alpha:1.0]]; 807 inLogSpan = YES; 808 } 809 } else if ([chunkString caseInsensitiveCompare:@" class=\"timestamp\""] == NSOrderedSame) { 810 [textAttributes setTextColor:[NSColor grayColor]]; 811 inLogSpan = YES; 812 } 813 814 //XXX Jabber can send a tag like so: <span style='font-family: Helvetica; font-size: small; '> 804 [self processSpanTagArgs:[self parseArguments:chunkString] attributes:textAttributes]; 815 805 } 806 816 807 } else if ([chunkString caseInsensitiveCompare:CloseSpan] == NSOrderedSame) { 817 808 if (inLogSpan) { … … 912 903 // Ignore <p> for those wacky AIM express users 913 904 } else if ([chunkString caseInsensitiveCompare:P] == NSOrderedSame || 914 [chunkString caseInsensitiveCompare:CloseP] == NSOrderedSame) {915 905 ([chunkString caseInsensitiveCompare:CloseP] == NSOrderedSame)) { 906 916 907 //Invalid 917 908 } else { … … 1059 1050 } else if ([arg caseInsensitiveCompare:@"LANG"] == NSOrderedSame) { 1060 1051 [textAttributes setLanguageValue:[inArgs objectForKey:arg]]; 1061 } 1052 1053 } else if ([arg caseInsensitiveCompare:@"sender"] == NSOrderedSame) { 1054 //Ghetto HTML log processing 1055 if (inDiv && send) { 1056 [textAttributes setTextColor:[NSColor colorWithCalibratedRed:0.0 green:0.5 blue:0.0 alpha:1.0]]; 1057 } else if (inDiv && receive) { 1058 [textAttributes setTextColor:[NSColor colorWithCalibratedRed:0.0 green:0.0 blue:0.5 alpha:1.0]]; 1059 } 1060 } 1061 1062 1062 } 1063 1063 } … … 1072 1072 if ([arg caseInsensitiveCompare:@"BGCOLOR"] == NSOrderedSame) { 1073 1073 [textAttributes setBackgroundColor:[NSColor colorWithHTMLString:[inArgs objectForKey:arg] defaultColor:[NSColor whiteColor]]]; 1074 } 1074 1075 } 1076 } 1077 } 1078 1079 - (void)processSpanTagArgs:(NSDictionary *)inArgs attributes:(AITextAttributes *)textAttributes 1080 { 1081 NSEnumerator *enumerator; 1082 NSString *arg; 1083 1084 enumerator = [[inArgs allKeys] objectEnumerator]; 1085 while ((arg = [enumerator nextObject])) { 1086 if ([arg caseInsensitiveCompare:@"class"] == NSOrderedSame) { 1087 //Process the span tag if it's in a log 1088 NSString *class = [inArgs objectForKey:arg]; 1089 1090 if ([class caseInsensitiveCompare:@"sender"] == NSOrderedSame) { 1091 if (inDiv && send) { 1092 [textAttributes setTextColor:[NSColor colorWithCalibratedRed:0.0 1093 green:0.5 1094 blue:0.0 1095 alpha:1.0]]; 1096 inLogSpan = YES; 1097 } else if (inDiv && receive) { 1098 [textAttributes setTextColor:[NSColor colorWithCalibratedRed:0.0 1099 green:0.0 1100 blue:0.5 1101 alpha:1.0]]; 1102 inLogSpan = YES; 1103 } 1104 1105 } else if ([class caseInsensitiveCompare:@"timestamp"] == NSOrderedSame) { 1106 [textAttributes setTextColor:[NSColor grayColor]]; 1107 inLogSpan = YES; 1108 } 1109 } 1110 1111 //XXX Jabber can send a tag like so: <span style='font-family: Helvetica; font-size: small; '> 1112 1075 1113 } 1076 1114 } … … 1101 1139 1102 1140 [textAttributes setLinkURL:[NSURL URLWithString:linkString]]; 1141 } 1142 } 1143 } 1144 1145 - (void)processDivTagArgs:(NSDictionary *)inArgs attributes:(AITextAttributes *)textAttributes 1146 { 1147 NSEnumerator *enumerator; 1148 NSString *arg; 1149 1150 enumerator = [[inArgs allKeys] objectEnumerator]; 1151 while ((arg = [enumerator nextObject])) { 1152 if ([arg caseInsensitiveCompare:@"dir"] == NSOrderedSame) { 1153 //Right to left, left to right handling 1154 NSString *direction = [inArgs objectForKey:arg]; 1155 1156 if ([direction caseInsensitiveCompare:@"rtl"] == NSOrderedSame) { 1157 [textAttributes setWritingDirection:NSWritingDirectionRightToLeft]; 1158 1159 } else if ([direction caseInsensitiveCompare:@"ltr"] == NSOrderedSame) { 1160 [textAttributes setWritingDirection:NSWritingDirectionLeftToRight]; 1161 } 1162 1163 } else if ([arg caseInsensitiveCompare:@"class"] == NSOrderedSame) { 1164 NSString *class = [inArgs objectForKey:arg]; 1165 if ([class caseInsensitiveCompare:@"send"] == NSOrderedSame) { 1166 send = YES; 1167 receive = NO; 1168 } else if ([class caseInsensitiveCompare:@"receive"] == NSOrderedSame) { 1169 receive = YES; 1170 send = NO; 1171 } else if ([class caseInsensitiveCompare:@"status"] == NSOrderedSame) { 1172 [textAttributes setTextColor:[NSColor grayColor]]; 1173 } 1103 1174 } 1104 1175 }