← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2843: apply custom fonts to chat nicks

 

------------------------------------------------------------
revno: 2843
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2012-01-29 19:05:27 +0100
message:
  apply custom fonts to chat nicks
modified:
  changelog.txt
  dwt/include/dwt/widgets/RichTextBox.h
  win32/HubFrame.cpp
  win32/WinUtil.cpp
  win32/WinUtil.h


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt	2012-01-27 22:41:48 +0000
+++ changelog.txt	2012-01-29 18:05:27 +0000
@@ -15,7 +15,7 @@
 * Allow empty user matching definitions that match every user (poy)
 * Add predefined user matching defs for favs (bold, more red) & ops (more blue) (poy)
 * [L#300971] Keep updating GUI elements while a menu is up (poy)
-* Color nicks in chats according to user matching definitions (poy)
+* Apply user matching definition styles to nicks in chats (poy)
 * Fix favorite hub groups on Win XP (poy)
 
 -- 0.791 2012-01-14 --

=== modified file 'dwt/include/dwt/widgets/RichTextBox.h'
--- dwt/include/dwt/widgets/RichTextBox.h	2012-01-27 22:19:56 +0000
+++ dwt/include/dwt/widgets/RichTextBox.h	2012-01-29 18:05:27 +0000
@@ -124,8 +124,8 @@
 	/// escape Rich Edit control chars: {, }, and \, as well as \n which becomes \line.
 	static tstring rtfEscape(const tstring& str);
 
-	void setTextColor(COLORREF color);
-	void setBgColor(COLORREF color);
+	COLORREF getTextColor() const { return textColor; }
+	COLORREF getBgColor() const { return bgColor; }
 
 protected:
 	tstring currentNeedle;		// search in chat window
@@ -164,7 +164,6 @@
 	// aspects::Font
 	void setFontImpl();
 
-	// store current colors for the onPrinting handler and for setFontImpl.
 	COLORREF textColor;
 	COLORREF bgColor;
 };

=== modified file 'win32/HubFrame.cpp'
--- win32/HubFrame.cpp	2012-01-28 11:36:54 +0000
+++ win32/HubFrame.cpp	2012-01-29 18:05:27 +0000
@@ -561,20 +561,28 @@
 		ret.first += message.thirdPerson ? _T("* ") + nick + _T(" ") : _T("<") + nick + _T("> ");
 
 		nick = chat->rtfEscape(nick);
-		if(style.textColor != -1 || style.bgColor != -1) {
-			// {{\\colortbl\\red0\\green0\\blue0;\\red1\\green1\\blue1;}\\cf0\\highlight1 nick}
-			tstring colors = _T("{{\\colortbl");
-			tstring colSel;
-			if(style.textColor != -1) {
-				colors += toRTF(style.textColor);
-				colSel += _T("\\cf0");
-			}
-			if(style.bgColor != -1) {
-				colors += toRTF(style.bgColor);
-				colSel += _T("\\highlight");
-				colSel += (style.textColor != -1) ? _T("1") : _T("0");
-			}
-			nick = colors + _T("}") + colSel + _T(" ") + nick + _T("}");
+		tstring rtfHeader;
+		tstring rtfFormat;
+		if(!style.font.empty()) {
+			auto cached = WinUtil::getUserMatchFont(style.font);
+			if(cached.get()) {
+				auto lf = cached->getLogFont();
+				rtfHeader += _T("{\\fonttbl{\\f0\\fnil\\fcharset") + Text::toT(Util::toString(lf.lfCharSet)) + _T(" ") + lf.lfFaceName + _T(";}}");
+				rtfFormat += _T("\\f0\\fs") + Text::toT(Util::toString(lf.lfHeight * 2));
+				if(lf.lfWeight >= FW_BOLD) { rtfFormat += _T("\\b"); }
+				if(lf.lfItalic) { rtfFormat += _T("\\i"); }
+			}
+		}
+		if(!rtfFormat.empty() || style.textColor != -1 || style.bgColor != -1) {
+			/* when creating a new context (say for a font table), always redefine colors as the Rich Edit
+			control seems to randomly reset them like a boss. */
+			if(style.textColor == -1) { style.textColor = chat->getTextColor(); }
+			if(style.bgColor == -1) { style.bgColor = chat->getBgColor(); }
+			rtfHeader += _T("{\\colortbl") + toRTF(style.textColor) + toRTF(style.bgColor) + _T("}");
+			rtfFormat += _T("\\cf0\\highlight1");
+		}
+		if(!rtfFormat.empty()) {
+			nick = _T("{") + rtfHeader + rtfFormat + _T(" ") + nick + _T("}");
 		}
 		ret.second += message.thirdPerson ? _T("* ") + nick + _T(" ") : _T("<") + nick + _T("> ");
 	}
@@ -900,10 +908,9 @@
 	auto style = identity.getStyle();
 
 	if(!style.font.empty()) {
-		// cache lookup might fail when refreshing the list of user matching defs...
-		auto cached = WinUtil::userMatchFonts.find(style.font);
-		if(cached != WinUtil::userMatchFonts.end()) {
-			font = cached->second->handle();
+		auto cached = WinUtil::getUserMatchFont(style.font);
+		if(cached.get()) {
+			font = cached->handle();
 		}
 	}
 

=== modified file 'win32/WinUtil.cpp'
--- win32/WinUtil.cpp	2012-01-27 23:03:27 +0000
+++ win32/WinUtil.cpp	2012-01-29 18:05:27 +0000
@@ -484,6 +484,15 @@
 	}
 }
 
+dwt::FontPtr WinUtil::getUserMatchFont(const string& key) {
+	// cache lookup might fail when refreshing the list of user matching defs...
+	auto cached = userMatchFonts.find(key);
+	if(cached != userMatchFonts.end()) {
+		return cached->second;
+	}
+	return nullptr;
+}
+
 void WinUtil::updateUploadFont() {
 	updateFont(uploadFont, SettingsManager::UPLOAD_FONT);
 }

=== modified file 'win32/WinUtil.h'
--- win32/WinUtil.h	2012-01-22 20:27:14 +0000
+++ win32/WinUtil.h	2012-01-29 18:05:27 +0000
@@ -131,7 +131,9 @@
 	static dwt::FontPtr font;
 	static dwt::FontPtr uploadFont;
 	static dwt::FontPtr downloadFont;
-	static unordered_map<string, dwt::FontPtr> userMatchFonts;
+private:
+	static unordered_map<string, dwt::FontPtr> userMatchFonts; // use getUserMatchFont to access
+public:
 	static tstring commands;
 	static dwt::ImageListPtr fileImages;
 	static dwt::ImageListPtr userImages;
@@ -179,6 +181,7 @@
 	static void decodeFont(const tstring& setting, LOGFONT &dest);
 	static void updateFont(dwt::FontPtr& font, int setting);
 	static void updateUserMatchFonts();
+	static dwt::FontPtr getUserMatchFont(const string& key);
 
 	static void updateUploadFont();
 	static void updateDownloadFont();