Changeset 13525
- Timestamp:
- 09/20/2005 05:05:00 PM (3 years ago)
- Files:
-
- branches/adium-0.8/Frameworks/Adium Framework/AIHTMLDecoder.h (modified) (1 diff)
- branches/adium-0.8/Frameworks/Adium Framework/AIHTMLDecoder.m (modified) (12 diffs)
- branches/adium-0.8/Frameworks/AIUtilities Framework/Source/AITextAttributes.h (modified) (1 diff)
- branches/adium-0.8/Frameworks/AIUtilities Framework/Source/AITextAttributes.m (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/adium-0.8/Frameworks/Adium Framework/AIHTMLDecoder.h
r11197 r13525 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 branches/adium-0.8/Frameworks/Adium Framework/AIHTMLDecoder.m
r13109 r13525 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]; … … 620 636 } 621 637 622 if(thingsToInclude.fontTags && thingsToInclude.closingFontTags && openFontTag) [string appendString:CloseFontTag]; //Close any open font tag 623 if(thingsToInclude.headers && pageColor) [string appendString:@"</BODY>"]; //Close the body tag 624 if(thingsToInclude.headers) [string appendString:@"</HTML>"]; //Close the HTML 638 if (thingsToInclude.fontTags && thingsToInclude.closingFontTags && openFontTag) [string appendString:CloseFontTag]; //Close any open font tag 639 if (rightToLeft) { 640 [string appendString:@"</DIV>"]; 641 } 642 if (thingsToInclude.headers && pageColor) [string appendString:@"</BODY>"]; //Close the body tag 643 if (thingsToInclude.headers) [string appendString:@"</HTML>"]; //Close the HTML 625 644 626 645 //KBOTC's odd hackish body background thingy for WMV since no one else will add it … … 652 671 NSMutableAttributedString *attrString; 653 672 AITextAttributes *textAttributes; 654 BOOL send = NO, receive = NO, inDiv = NO, inLogSpan = NO; 673 674 //Reset the div and span ivars 675 send = NO; 676 receive = NO; 677 inDiv = NO; 678 inLogSpan = NO; 655 679 656 680 //set up … … 721 745 //HTML 722 746 if([chunkString caseInsensitiveCompare:HTML] == NSOrderedSame){ 723 //We ignore stuff inside the HTML tag, but don't want to see the end of it747 //We ignore most stuff inside the HTML tag, but don't want to see the end of it. 724 748 [scanner scanUpToCharactersFromSet:absoluteTagEnd intoString:&chunkString]; 725 }else if([chunkString caseInsensitiveCompare:CloseHTML] == NSOrderedSame){ 749 750 } else if ([chunkString caseInsensitiveCompare:CloseHTML] == NSOrderedSame) { 726 751 //We are done 727 752 break; … … 734 759 735 760 [textAttributes setTextColor:[NSColor blackColor]]; 761 736 762 //DIV 737 763 }else if ([chunkString caseInsensitiveCompare:@"DIV"] == NSOrderedSame){ 738 [scanner scanUpToCharactersFromSet:absoluteTagEnd 739 intoString:&chunkString]; 764 if ([scanner scanUpToCharactersFromSet:absoluteTagEnd 765 intoString:&chunkString]) { 766 [self processDivTagArgs:[self parseArguments:chunkString] attributes:textAttributes]; 767 } 740 768 inDiv = YES; 741 if ([chunkString caseInsensitiveCompare:@" class=\"send\""] == NSOrderedSame) { 742 send = YES; 743 receive = NO; 744 } else if ([chunkString caseInsensitiveCompare:@" class=\"receive\""] == NSOrderedSame) { 745 receive = YES; 746 send = NO; 747 } else if ([chunkString caseInsensitiveCompare:@" class=\"status\""] == NSOrderedSame) { 748 [textAttributes setTextColor:[NSColor grayColor]]; 749 } 769 750 770 }else if ([chunkString caseInsensitiveCompare:@"/DIV"] == NSOrderedSame) { 751 771 inDiv = NO; 772 752 773 //LINK 753 774 }else if([chunkString caseInsensitiveCompare:@"A"] == NSOrderedSame){ … … 773 794 }else if([chunkString caseInsensitiveCompare:Font] == NSOrderedSame){ 774 795 if([scanner scanUpToCharactersFromSet:absoluteTagEnd intoString:&chunkString]){ 775 776 //Process the font tag if it's in a log777 if([chunkString caseInsensitiveCompare:@" class=\"sender\""] == NSOrderedSame) {778 if(inDiv && send) {779 [textAttributes setTextColor:[NSColor colorWithCalibratedRed:0.0 green:0.5 blue:0.0 alpha:1.0]];780 } else if(inDiv && receive) {781 [textAttributes setTextColor:[NSColor colorWithCalibratedRed:0.0 green:0.0 blue:0.5 alpha:1.0]];782 }783 }784 785 796 //Process the font tag's contents 786 797 [self processFontTagArgs:[self parseArguments:chunkString] attributes:textAttributes]; … … 793 804 }else if([chunkString caseInsensitiveCompare:Span] == NSOrderedSame){ 794 805 if([scanner scanUpToCharactersFromSet:absoluteTagEnd intoString:&chunkString]){ 795 796 //Process the span tag if it's in a log 797 if([chunkString caseInsensitiveCompare:@" class=\"sender\""] == NSOrderedSame) { 798 if(inDiv && send) { 799 [textAttributes setTextColor:[NSColor colorWithCalibratedRed:0.0 800 green:0.5 801 blue:0.0 802 alpha:1.0]]; 803 inLogSpan = YES; 804 } else if(inDiv && receive) { 805 [textAttributes setTextColor:[NSColor colorWithCalibratedRed:0.0 806 green:0.0 807 blue:0.5 808 alpha:1.0]]; 809 inLogSpan = YES; 810 } 811 } else if([chunkString caseInsensitiveCompare:@" class=\"timestamp\""] == NSOrderedSame){ 812 [textAttributes setTextColor:[NSColor grayColor]]; 813 inLogSpan = YES; 814 } 815 816 //XXX Jabber can send a tag like so: <span style='font-family: Helvetica; font-size: small; '> 806 [self processSpanTagArgs:[self parseArguments:chunkString] attributes:textAttributes]; 817 807 } 808 818 809 } else if ([chunkString caseInsensitiveCompare:CloseSpan] == NSOrderedSame) { 819 810 if(inLogSpan){ … … 914 905 // Ignore <p> for those wacky AIM express users 915 906 } else if ([chunkString caseInsensitiveCompare:P] == NSOrderedSame || 916 [chunkString caseInsensitiveCompare:CloseP] == NSOrderedSame) {917 907 ([chunkString caseInsensitiveCompare:CloseP] == NSOrderedSame)) { 908 918 909 //Invalid 919 910 } else { … … 1061 1052 }else if([arg caseInsensitiveCompare:@"LANG"] == NSOrderedSame){ 1062 1053 [textAttributes setLanguageValue:[inArgs objectForKey:arg]]; 1063 } 1054 1055 } else if ([arg caseInsensitiveCompare:@"sender"] == NSOrderedSame) { 1056 //Ghetto HTML log processing 1057 if (inDiv && send) { 1058 [textAttributes setTextColor:[NSColor colorWithCalibratedRed:0.0 green:0.5 blue:0.0 alpha:1.0]]; 1059 } else if (inDiv && receive) { 1060 [textAttributes setTextColor:[NSColor colorWithCalibratedRed:0.0 green:0.0 blue:0.5 alpha:1.0]]; 1061 } 1062 } 1063 1064 1064 } 1065 1065 } … … 1074 1074 if([arg caseInsensitiveCompare:@"BGCOLOR"] == NSOrderedSame){ 1075 1075 [textAttributes setBackgroundColor:[NSColor colorWithHTMLString:[inArgs objectForKey:arg] defaultColor:[NSColor whiteColor]]]; 1076 } 1076 1077 } 1078 } 1079 } 1080 1081 - (void)processSpanTagArgs:(NSDictionary *)inArgs attributes:(AITextAttributes *)textAttributes 1082 { 1083 NSEnumerator *enumerator; 1084 NSString *arg; 1085 1086 enumerator = [[inArgs allKeys] objectEnumerator]; 1087 while ((arg = [enumerator nextObject])) { 1088 if ([arg caseInsensitiveCompare:@"class"] == NSOrderedSame) { 1089 //Process the span tag if it's in a log 1090 NSString *class = [inArgs objectForKey:arg]; 1091 1092 if ([class caseInsensitiveCompare:@"sender"] == NSOrderedSame) { 1093 if (inDiv && send) { 1094 [textAttributes setTextColor:[NSColor colorWithCalibratedRed:0.0 1095 green:0.5 1096 blue:0.0 1097 alpha:1.0]]; 1098 inLogSpan = YES; 1099 } else if (inDiv && receive) { 1100 [textAttributes setTextColor:[NSColor colorWithCalibratedRed:0.0 1101 green:0.0 1102 blue:0.5 1103 alpha:1.0]]; 1104 inLogSpan = YES; 1105 } 1106 1107 } else if ([class caseInsensitiveCompare:@"timestamp"] == NSOrderedSame) { 1108 [textAttributes setTextColor:[NSColor grayColor]]; 1109 inLogSpan = YES; 1110 } 1111 } 1112 1113 //XXX Jabber can send a tag like so: <span style='font-family: Helvetica; font-size: small; '> 1114 1077 1115 } 1078 1116 } … … 1103 1141 1104 1142 [textAttributes setLinkURL:[NSURL URLWithString:linkString]]; 1143 } 1144 } 1145 } 1146 1147 - (void)processDivTagArgs:(NSDictionary *)inArgs attributes:(AITextAttributes *)textAttributes 1148 { 1149 NSEnumerator *enumerator; 1150 NSString *arg; 1151 1152 enumerator = [[inArgs allKeys] objectEnumerator]; 1153 while ((arg = [enumerator nextObject])) { 1154 if ([arg caseInsensitiveCompare:@"dir"] == NSOrderedSame) { 1155 //Right to left, left to right handling 1156 NSString *direction = [inArgs objectForKey:arg]; 1157 1158 if ([direction caseInsensitiveCompare:@"rtl"] == NSOrderedSame) { 1159 [textAttributes setWritingDirection:NSWritingDirectionRightToLeft]; 1160 1161 } else if ([direction caseInsensitiveCompare:@"ltr"] == NSOrderedSame) { 1162 [textAttributes setWritingDirection:NSWritingDirectionLeftToRight]; 1163 } 1164 1165 } else if ([arg caseInsensitiveCompare:@"class"] == NSOrderedSame) { 1166 NSString *class = [inArgs objectForKey:arg]; 1167 if ([class caseInsensitiveCompare:@"send"] == NSOrderedSame) { 1168 send = YES; 1169 receive = NO; 1170 } else if ([class caseInsensitiveCompare:@"receive"] == NSOrderedSame) { 1171 receive = YES; 1172 send = NO; 1173 } else if ([class caseInsensitiveCompare:@"status"] == NSOrderedSame) { 1174 [textAttributes setTextColor:[NSColor grayColor]]; 1175 } 1105 1176 } 1106 1177 } branches/adium-0.8/Frameworks/AIUtilities Framework/Source/AITextAttributes.h
r11054 r13525 179 179 - (id)languageValue; 180 180 181 - (void)setWritingDirection:(NSWritingDirection)inDirection; 182 181 183 @end branches/adium-0.8/Frameworks/AIUtilities Framework/Source/AITextAttributes.m
r11054 r13525 295 295 } 296 296 297 - (void)setWritingDirection:(NSWritingDirection)inDirection 298 { 299 NSParagraphStyle *paragraphStyle; 300 NSMutableParagraphStyle *newParagraphStyle; 301 302 if (!(paragraphStyle = [dictionary objectForKey:NSParagraphStyleAttributeName])) { 303 paragraphStyle = [NSParagraphStyle defaultParagraphStyle]; 304 } 305 306 newParagraphStyle = [paragraphStyle mutableCopy]; 307 [newParagraphStyle setBaseWritingDirection:inDirection]; 308 [dictionary setObject:newParagraphStyle forKey:NSParagraphStyleAttributeName]; 309 } 310 297 311 @end