1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Source/AIDefaultFontRemovalPlugin.m Wed Oct 28 10:44:02 2009 -0400
1.3 @@ -0,0 +1,78 @@
1.4 +//
1.5 +// AIDefaultFontRemoval.m
1.6 +// Adium
1.7 +//
1.8 +// Created by Zachary West on 2009-10-28.
1.9 +// Copyright 2009 . All rights reserved.
1.10 +//
1.11 +
1.12 +#import "AIDefaultFontRemovalPlugin.h"
1.13 +#import <AIUtilities/AIFontAdditions.h>
1.14 +#import <AIUtilities/AIColorAdditions.h>
1.15 +
1.16 +@implementation AIDefaultFontRemovalPlugin
1.17 +- (void)installPlugin
1.18 +{
1.19 + // We only monitor outgoing messages.
1.20 + [adium.contentController registerContentFilter:self ofType:AIFilterContent direction:AIFilterOutgoing];
1.21 +}
1.22 +
1.23 +- (void)uninstallPlugin
1.24 +{
1.25 + [adium.contentController unregisterContentFilter:self];
1.26 +}
1.27 +
1.28 +- (void)dealloc
1.29 +{
1.30 + [defaultRemovedAttributes release];
1.31 + [super dealloc];
1.32 +}
1.33 +
1.34 +- (NSAttributedString *)filterAttributedString:(NSAttributedString *)inAttributedString context:(id)context
1.35 +{
1.36 + if (!inAttributedString || ![inAttributedString length]) return inAttributedString;
1.37 +
1.38 + NSMutableAttributedString *mutableString = [inAttributedString mutableCopy];
1.39 +
1.40 + if (!defaultRemovedAttributes) {
1.41 + NSFont *defaultFont = [[adium.preferenceController defaultPreferenceForKey:KEY_FORMATTING_FONT
1.42 + group:PREF_GROUP_FORMATTING
1.43 + object:nil] representedFont];
1.44 +
1.45 + defaultRemovedAttributes = [[NSDictionary dictionaryWithObjectsAndKeys:
1.46 + defaultFont, NSFontAttributeName,
1.47 + [NSColor colorWithCalibratedRed:1.0 green:1.0 blue:1.0 alpha:1.0], NSBackgroundColorAttributeName,
1.48 + nil] retain];
1.49 + }
1.50 +
1.51 + for (NSString *attributeName in defaultRemovedAttributes.allKeys) {
1.52 + NSUInteger position = 0;
1.53 +
1.54 + while (position < mutableString.length) {
1.55 + NSRange attributeRange;
1.56 + id attributeValue = [mutableString attribute:attributeName
1.57 + atIndex:position
1.58 + effectiveRange:&attributeRange];
1.59 +
1.60 + if (attributeValue && [attributeValue isEqualTo:[defaultRemovedAttributes objectForKey:attributeName]]) {
1.61 + [mutableString removeAttribute:attributeName range:attributeRange];
1.62 + }
1.63 +
1.64 + position += attributeRange.length;
1.65 + }
1.66 + }
1.67 +
1.68 + return [mutableString autorelease];
1.69 +}
1.70 +
1.71 +/*!
1.72 + * @brief When should this run?
1.73 + *
1.74 + * We want this font removal to occur as early as possible, in case any other filters try and modify the fonts.
1.75 + */
1.76 +- (CGFloat)filterPriority
1.77 +{
1.78 + return HIGHEST_FILTER_PRIORITY;
1.79 +}
1.80 +
1.81 +@end