adium 2795:74a33a2e7467: Add a "Default font remover" plugin. Re...
commits at adium.im
commits at adium.im
Wed Oct 28 14:52:14 UTC 2009
details: http://hg.adium.im/adium/rev/74a33a2e7467
revision: 2795:74a33a2e7467
author: Zachary West <zacw at adium.im>
date: Wed Oct 28 10:44:02 2009 -0400
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.
Subject: adium 2796:341c96961054: Restore back AIHTMLDecoder's assumption that fonts are Helvetica and the sky is blue.
details: http://hg.adium.im/adium/rev/341c96961054
revision: 2796:341c96961054
author: Zachary West <zacw at adium.im>
date: Wed Oct 28 10:49:09 2009 -0400
Restore back AIHTMLDecoder's assumption that fonts are Helvetica and the sky is blue.
This fixes the "italics" case talked about in adium-1.4/a81e3542ed8f. Refs #12906.
Pre-SL behavior now fully achieved. Hooray.
diffs (190 lines):
diff -r ca3d8c8b4a3d -r 341c96961054 Adium.xcodeproj/project.pbxproj
--- a/Adium.xcodeproj/project.pbxproj Wed Oct 28 03:09:37 2009 -0700
+++ b/Adium.xcodeproj/project.pbxproj Wed Oct 28 10:49:09 2009 -0400
@@ -56,6 +56,7 @@
0CD3C3AD0C43C8CC003E637C /* NSWindowScriptingAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 0CD3C3AB0C43C8CC003E637C /* NSWindowScriptingAdditions.m */; };
0CD41C710C2776550082F83B /* AICreateCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = 0CD41C6F0C2776550082F83B /* AICreateCommand.m */; };
0CFA98C90D35C18000A077C6 /* NSDataAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 0CFA98C70D35C18000A077C6 /* NSDataAdditions.m */; };
+ 11000D041098863B0096A1E2 /* AIDefaultFontRemovalPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 11000D031098863B0096A1E2 /* AIDefaultFontRemovalPlugin.m */; };
110763F608676CC9005987A5 /* RAFBlockEditorPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 110763F208676CC9005987A5 /* RAFBlockEditorPlugin.m */; };
110763F808676CC9005987A5 /* RAFBlockEditorWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 110763F408676CC9005987A5 /* RAFBlockEditorWindowController.m */; };
110763FA08676D05005987A5 /* BlockEditorWindow.nib in Resources */ = {isa = PBXBuildFile; fileRef = 110763F908676D04005987A5 /* BlockEditorWindow.nib */; };
@@ -1797,6 +1798,8 @@
0CD41C6F0C2776550082F83B /* AICreateCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AICreateCommand.m; path = Source/AICreateCommand.m; sourceTree = "<group>"; };
0CFA98C60D35C18000A077C6 /* NSDataAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NSDataAdditions.h; path = Source/NSDataAdditions.h; sourceTree = "<group>"; };
0CFA98C70D35C18000A077C6 /* NSDataAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NSDataAdditions.m; path = Source/NSDataAdditions.m; sourceTree = "<group>"; };
+ 11000D021098863B0096A1E2 /* AIDefaultFontRemovalPlugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AIDefaultFontRemovalPlugin.h; path = Source/AIDefaultFontRemovalPlugin.h; sourceTree = "<group>"; };
+ 11000D031098863B0096A1E2 /* AIDefaultFontRemovalPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AIDefaultFontRemovalPlugin.m; path = Source/AIDefaultFontRemovalPlugin.m; sourceTree = "<group>"; };
110763F108676CC9005987A5 /* RAFBlockEditorPlugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RAFBlockEditorPlugin.h; path = Source/RAFBlockEditorPlugin.h; sourceTree = "<group>"; };
110763F208676CC9005987A5 /* RAFBlockEditorPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RAFBlockEditorPlugin.m; path = Source/RAFBlockEditorPlugin.m; sourceTree = "<group>"; };
110763F308676CC9005987A5 /* RAFBlockEditorWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RAFBlockEditorWindowController.h; path = Source/RAFBlockEditorWindowController.h; sourceTree = "<group>"; };
@@ -4908,6 +4911,15 @@
name = Localized;
sourceTree = "<group>";
};
+ 11000CFE109886010096A1E2 /* Removal of Helvetica at 12 */ = {
+ isa = PBXGroup;
+ children = (
+ 11000D021098863B0096A1E2 /* AIDefaultFontRemovalPlugin.h */,
+ 11000D031098863B0096A1E2 /* AIDefaultFontRemovalPlugin.m */,
+ );
+ name = "Removal of Helvetica at 12";
+ sourceTree = "<group>";
+ };
111E89030F93FE3B00A5F18B /* IRC */ = {
isa = PBXGroup;
children = (
@@ -5906,6 +5918,7 @@
F1D0C631051AC2380000000E /* Message Alias Support */,
6E5A43DC0611604B0078C342 /* Message History */,
F569E38102CA876501A8010A /* Message Window Interface */,
+ 11000CFE109886010096A1E2 /* Removal of Helvetica at 12 */,
343022240AB4763D0082CF7C /* Removal of NULs in Messages */,
34A65AF606A5A0C400898470 /* Safari Link Toolbar Item */,
34DFF46607A5EAC800B92233 /* Secure Messaging */,
@@ -10580,6 +10593,7 @@
1197F6710FCF8D180032F19B /* AITwitterStatusFollowup.m in Sources */,
112939100FD5AE1400FA8F53 /* AIConfirmationsAdvancedPreferences.m in Sources */,
11D915720FFC100700B39713 /* AIGenericMultipartImageUploader.m in Sources */,
+ 11000D041098863B0096A1E2 /* AIDefaultFontRemovalPlugin.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff -r ca3d8c8b4a3d -r 341c96961054 Frameworks/Adium Framework/Source/AIHTMLDecoder.m
--- a/Frameworks/Adium Framework/Source/AIHTMLDecoder.m Wed Oct 28 03:09:37 2009 -0700
+++ b/Frameworks/Adium Framework/Source/AIHTMLDecoder.m Wed Oct 28 10:49:09 2009 -0400
@@ -249,10 +249,10 @@
}
//Setup the default attributes
- NSString *currentFamily = nil;
+ NSString *currentFamily = [@"Helvetica" retain];
NSString *currentColor = nil;
NSString *currentBackColor = nil;
- int currentSize = 0;
+ int currentSize = 12;
BOOL currentItalic = NO;
BOOL currentBold = NO;
BOOL currentUnderline = NO;
diff -r ca3d8c8b4a3d -r 341c96961054 Source/AICoreComponentLoader.m
--- a/Source/AICoreComponentLoader.m Wed Oct 28 03:09:37 2009 -0700
+++ b/Source/AICoreComponentLoader.m Wed Oct 28 10:49:09 2009 -0400
@@ -142,6 +142,7 @@
@"OWSpellingPerContactPlugin",
@"GBQuestionHandlerPlugin",
@"AINulRemovalPlugin",
+ @"AIDefaultFontRemovalPlugin",
@"AIAdvancedPreferencesPlugin",
@"GBImportPlugin",
@"AIMentionEventPlugin",
diff -r ca3d8c8b4a3d -r 341c96961054 Source/AIDefaultFontRemovalPlugin.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Source/AIDefaultFontRemovalPlugin.h Wed Oct 28 10:49:09 2009 -0400
@@ -0,0 +1,25 @@
+//
+// AIDefaultFontRemoval.h
+// Adium
+//
+// Created by Zachary West on 2009-10-28.
+// Copyright 2009 . All rights reserved.
+//
+
+#import <Adium/AIContentControllerProtocol.h>
+
+/*!
+ * @class AIDefaultFontRemoval
+ *
+ * This class removes the default (as in, shipping with Adium) font attributes
+ * for a given outgoing message. This restores a "plaintext" default for messages.
+ *
+ * The basic effect is that Helvetica sized 12 (set in FormattingDefaults.plist) is
+ * stripped from outgoing messages, along with any background coloring if no foreground
+ * is specified.
+ */
+ at interface AIDefaultFontRemovalPlugin : AIPlugin <AIContentFilter> {
+ NSDictionary *defaultRemovedAttributes;
+}
+
+ at end
diff -r ca3d8c8b4a3d -r 341c96961054 Source/AIDefaultFontRemovalPlugin.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Source/AIDefaultFontRemovalPlugin.m Wed Oct 28 10:49:09 2009 -0400
@@ -0,0 +1,78 @@
+//
+// AIDefaultFontRemoval.m
+// Adium
+//
+// Created by Zachary West on 2009-10-28.
+// Copyright 2009 . All rights reserved.
+//
+
+#import "AIDefaultFontRemovalPlugin.h"
+#import <AIUtilities/AIFontAdditions.h>
+#import <AIUtilities/AIColorAdditions.h>
+
+ at implementation AIDefaultFontRemovalPlugin
+- (void)installPlugin
+{
+ // We only monitor outgoing messages.
+ [adium.contentController registerContentFilter:self ofType:AIFilterContent direction:AIFilterOutgoing];
+}
+
+- (void)uninstallPlugin
+{
+ [adium.contentController unregisterContentFilter:self];
+}
+
+- (void)dealloc
+{
+ [defaultRemovedAttributes release];
+ [super dealloc];
+}
+
+- (NSAttributedString *)filterAttributedString:(NSAttributedString *)inAttributedString context:(id)context
+{
+ if (!inAttributedString || ![inAttributedString length]) return inAttributedString;
+
+ NSMutableAttributedString *mutableString = [inAttributedString mutableCopy];
+
+ if (!defaultRemovedAttributes) {
+ NSFont *defaultFont = [[adium.preferenceController defaultPreferenceForKey:KEY_FORMATTING_FONT
+ group:PREF_GROUP_FORMATTING
+ object:nil] representedFont];
+
+ defaultRemovedAttributes = [[NSDictionary dictionaryWithObjectsAndKeys:
+ defaultFont, NSFontAttributeName,
+ [NSColor colorWithCalibratedRed:1.0 green:1.0 blue:1.0 alpha:1.0], NSBackgroundColorAttributeName,
+ nil] retain];
+ }
+
+ for (NSString *attributeName in defaultRemovedAttributes.allKeys) {
+ NSUInteger position = 0;
+
+ while (position < mutableString.length) {
+ NSRange attributeRange;
+ id attributeValue = [mutableString attribute:attributeName
+ atIndex:position
+ effectiveRange:&attributeRange];
+
+ if (attributeValue && [attributeValue isEqualTo:[defaultRemovedAttributes objectForKey:attributeName]]) {
+ [mutableString removeAttribute:attributeName range:attributeRange];
+ }
+
+ position += attributeRange.length;
+ }
+ }
+
+ return [mutableString autorelease];
+}
+
+/*!
+ * @brief When should this run?
+ *
+ * We want this font removal to occur as early as possible, in case any other filters try and modify the fonts.
+ */
+- (CGFloat)filterPriority
+{
+ return HIGHEST_FILTER_PRIORITY;
+}
+
+ at end
More information about the commits
mailing list