Add a "Default font remover" plugin. Refs #12906 (though really fixes it).
This restores our pre-Snow Leopard behavior of sending plaintext when our defualt default font is specified. This also removes the white background Snow Leopard gives us for the attributed string, which would cause it to be sent for every message as well.
The only 'gotcha' here is that, for example, Helvetica-Oblique (italics) is a different actual font than Helvetica. At this point I'm more or less okay with this behavior.
2 // AIDefaultFontRemoval.m
5 // Created by Zachary West on 2009-10-28.
6 // Copyright 2009 . All rights reserved.
9 #import "AIDefaultFontRemovalPlugin.h"
10 #import <AIUtilities/AIFontAdditions.h>
11 #import <AIUtilities/AIColorAdditions.h>
13 @implementation AIDefaultFontRemovalPlugin
16 // We only monitor outgoing messages.
17 [adium.contentController registerContentFilter:self ofType:AIFilterContent direction:AIFilterOutgoing];
20 - (void)uninstallPlugin
22 [adium.contentController unregisterContentFilter:self];
27 [defaultRemovedAttributes release];
31 - (NSAttributedString *)filterAttributedString:(NSAttributedString *)inAttributedString context:(id)context
33 if (!inAttributedString || ![inAttributedString length]) return inAttributedString;
35 NSMutableAttributedString *mutableString = [inAttributedString mutableCopy];
37 if (!defaultRemovedAttributes) {
38 NSFont *defaultFont = [[adium.preferenceController defaultPreferenceForKey:KEY_FORMATTING_FONT
39 group:PREF_GROUP_FORMATTING
40 object:nil] representedFont];
42 defaultRemovedAttributes = [[NSDictionary dictionaryWithObjectsAndKeys:
43 defaultFont, NSFontAttributeName,
44 [NSColor colorWithCalibratedRed:1.0 green:1.0 blue:1.0 alpha:1.0], NSBackgroundColorAttributeName,
48 for (NSString *attributeName in defaultRemovedAttributes.allKeys) {
49 NSUInteger position = 0;
51 while (position < mutableString.length) {
52 NSRange attributeRange;
53 id attributeValue = [mutableString attribute:attributeName
55 effectiveRange:&attributeRange];
57 if (attributeValue && [attributeValue isEqualTo:[defaultRemovedAttributes objectForKey:attributeName]]) {
58 [mutableString removeAttribute:attributeName range:attributeRange];
61 position += attributeRange.length;
65 return [mutableString autorelease];
69 * @brief When should this run?
71 * We want this font removal to occur as early as possible, in case any other filters try and modify the fonts.
73 - (CGFloat)filterPriority
75 return HIGHEST_FILTER_PRIORITY;