Adium

Changeset 13525

Show
Ignore:
Timestamp:
09/20/2005 05:05:00 PM (3 years ago)
Author:
evands
Message:

Merged [13519] and [13520]. Right-to-left text is now surrounded by a dir=rtl div tag; dir=rtl div tags are decoded back to right-to-left attributed strings. This fixes display of right-to-left text in the message view. Refs #651

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/adium-0.8/Frameworks/Adium Framework/AIHTMLDecoder.h

    r11197 r13525  
    3636                unsigned allowAIMsubprofileLinks: 1; 
    3737        } 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;  
    3844} 
    3945 
  • branches/adium-0.8/Frameworks/Adium Framework/AIHTMLDecoder.m

    r13109 r13525  
    9696- (void)processBodyTagArgs:(NSDictionary *)inArgs attributes:(AITextAttributes *)textAttributes; 
    9797- (void)processLinkTagArgs:(NSDictionary *)inArgs attributes:(AITextAttributes *)textAttributes; 
     98- (void)processSpanTagArgs:(NSDictionary *)inArgs attributes:(AITextAttributes *)textAttributes; 
     99- (void)processDivTagArgs:(NSDictionary *)inArgs attributes:(AITextAttributes *)textAttributes; 
    98100- (NSAttributedString *)processImgTagArgs:(NSDictionary *)inArgs attributes:(AITextAttributes *)textAttributes; 
    99101- (BOOL)appendImage:(NSImage *)attachmentImage toString:(NSMutableString *)string withName:(NSString *)fileSafeChunk  altString:(NSString *)attachmentString imagesPath:(NSString *)imagesPath; 
     
    225227        BOOL                     openFontTag = NO; 
    226228 
    227         //Setup the destination HTML string 
    228         NSMutableString *string = [NSMutableString string]; 
    229         if(thingsToInclude.headers) [string appendString:@"<HTML>"]; 
    230  
    231229        //Setup the incoming message as a regular string, and get its length 
    232230        NSString                *inMessageString = [inMessage string]; 
    233231        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         
    235251        //Setup the default attributes 
    236252        NSString                *currentFamily = [@"Helvetica" retain]; 
     
    620636        } 
    621637         
    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 
    625644         
    626645        //KBOTC's odd hackish body background thingy for WMV since no one else will add it 
     
    652671        NSMutableAttributedString       *attrString; 
    653672        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; 
    655679         
    656680    //set up 
     
    721745                                        //HTML 
    722746                                        if([chunkString caseInsensitiveCompare:HTML] == NSOrderedSame){ 
    723                                                 //We ignore stuff inside the HTML tag, but don't want to see the end of it 
     747                                                //We ignore most stuff inside the HTML tag, but don't want to see the end of it. 
    724748                                                [scanner scanUpToCharactersFromSet:absoluteTagEnd intoString:&chunkString]; 
    725                                         }else if([chunkString caseInsensitiveCompare:CloseHTML] == NSOrderedSame){ 
     749 
     750                                        } else if ([chunkString caseInsensitiveCompare:CloseHTML] == NSOrderedSame) { 
    726751                                                //We are done 
    727752                                                break; 
     
    734759 
    735760                                                [textAttributes setTextColor:[NSColor blackColor]]; 
     761 
    736762                                        //DIV 
    737763                                        }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                                                } 
    740768                                                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 
    750770                                        }else if ([chunkString caseInsensitiveCompare:@"/DIV"] == NSOrderedSame) { 
    751771                                                inDiv = NO; 
     772 
    752773                                        //LINK 
    753774                                        }else if([chunkString caseInsensitiveCompare:@"A"] == NSOrderedSame){ 
     
    773794                                        }else if([chunkString caseInsensitiveCompare:Font] == NSOrderedSame){ 
    774795                                                if([scanner scanUpToCharactersFromSet:absoluteTagEnd intoString:&chunkString]){ 
    775  
    776                                                         //Process the font tag if it's in a log 
    777                                                         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  
    785796                                                        //Process the font tag's contents 
    786797                                                        [self processFontTagArgs:[self parseArguments:chunkString] attributes:textAttributes]; 
     
    793804                                        }else if([chunkString caseInsensitiveCompare:Span] == NSOrderedSame){ 
    794805                                                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]; 
    817807                                                } 
     808 
    818809                                        } else if ([chunkString caseInsensitiveCompare:CloseSpan] == NSOrderedSame) { 
    819810                                                if(inLogSpan){ 
     
    914905                                        // Ignore <p> for those wacky AIM express users 
    915906                                        } else if ([chunkString caseInsensitiveCompare:P] == NSOrderedSame || 
    916                                                            [chunkString caseInsensitiveCompare:CloseP] == NSOrderedSame) { 
    917  
     907                                                           ([chunkString caseInsensitiveCompare:CloseP] == NSOrderedSame)) { 
     908                                                 
    918909                                        //Invalid 
    919910                                        } else { 
     
    10611052                }else if([arg caseInsensitiveCompare:@"LANG"] == NSOrderedSame){ 
    10621053                        [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                 
    10641064        } 
    10651065} 
     
    10741074                if([arg caseInsensitiveCompare:@"BGCOLOR"] == NSOrderedSame){ 
    10751075                        [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                 
    10771115        } 
    10781116} 
     
    11031141 
    11041142                        [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                        } 
    11051176                } 
    11061177        } 
  • branches/adium-0.8/Frameworks/AIUtilities Framework/Source/AITextAttributes.h

    r11054 r13525  
    179179- (id)languageValue; 
    180180 
     181- (void)setWritingDirection:(NSWritingDirection)inDirection; 
     182 
    181183@end 
  • branches/adium-0.8/Frameworks/AIUtilities Framework/Source/AITextAttributes.m

    r11054 r13525  
    295295} 
    296296 
     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 
    297311@end