From c4cf3766e12cf652cece9f1957b55bf3acb28146 Mon Sep 17 00:00:00 2001
From: Jacek Antonelli
Date: Tue, 31 Aug 2010 05:54:55 -0500
Subject: Added Preferences > Fonts tab, with basic font chooser.

Choosing a font sets FontChoice setting, but no real effect yet.
---
 linden/indra/newview/CMakeLists.txt                |  2 +
 linden/indra/newview/app_settings/settings.xml     | 11 +++
 linden/indra/newview/impprefsfonts.cpp             | 86 ++++++++++++++++++++++
 linden/indra/newview/impprefsfonts.h               | 45 +++++++++++
 linden/indra/newview/llfloaterpreference.cpp       | 15 +++-
 linden/indra/newview/llfloaterpreference.h         |  2 +
 .../newview/skins/default/xui/en-us/fonts.xml      | 14 ++++
 .../skins/default/xui/en-us/notifications.xml      |  7 ++
 .../default/xui/en-us/panel_preferences_fonts.xml  | 33 +++++++++
 9 files changed, 214 insertions(+), 1 deletion(-)
 create mode 100644 linden/indra/newview/impprefsfonts.cpp
 create mode 100644 linden/indra/newview/impprefsfonts.h
 create mode 100644 linden/indra/newview/skins/default/xui/en-us/panel_preferences_fonts.xml

diff --git a/linden/indra/newview/CMakeLists.txt b/linden/indra/newview/CMakeLists.txt
index 7dfe3d2..ba715ca 100644
--- a/linden/indra/newview/CMakeLists.txt
+++ b/linden/indra/newview/CMakeLists.txt
@@ -76,6 +76,7 @@ set(viewer_SOURCE_FILES
     hippoGridManager.cpp
     hippoLimits.cpp
     hippoRestRequest.cpp
+    impprefsfonts.cpp
     jcfloater_animation_list.cpp
     jcfloaterareasearch.cpp
     lightshare.cpp
@@ -509,6 +510,7 @@ set(viewer_HEADER_FILES
     hippoGridManager.h
     hippoLimits.h
     hippoRestRequest.h
+    impprefsfonts.h
     jcfloater_animation_list.h
     jcfloaterareasearch.h
     lightshare.h
diff --git a/linden/indra/newview/app_settings/settings.xml b/linden/indra/newview/app_settings/settings.xml
index f101396..cf5f33f 100644
--- a/linden/indra/newview/app_settings/settings.xml
+++ b/linden/indra/newview/app_settings/settings.xml
@@ -255,6 +255,17 @@
       <integer>0</integer>
     </array>
   </map>
+  <key>FontChoice</key>
+  <map>
+    <key>Comment</key>
+    <string>User's font choice (Liberation or DejaVu)</string>
+    <key>Persist</key>
+    <integer>1</integer>
+    <key>Type</key>
+    <string>String</string>
+    <key>Value</key>
+    <string>DejaVu</string>
+  </map>
   <key>GoAction</key>
   <map>
     <key>Comment</key>
diff --git a/linden/indra/newview/impprefsfonts.cpp b/linden/indra/newview/impprefsfonts.cpp
new file mode 100644
index 0000000..3ce71eb
--- /dev/null
+++ b/linden/indra/newview/impprefsfonts.cpp
@@ -0,0 +1,86 @@
+/**
+ * @file impprefsfonts.cpp
+ * @brief Font preferences panel
+ *
+ * Copyright (c) 2010, Jacek Antonelli
+ *
+ * The source code in this file ("Source Code") is provided to you
+ * under the terms of the GNU General Public License, version 2.0
+ * ("GPL"). Terms of the GPL can be found in doc/GPL-license.txt in
+ * this distribution, or online at
+ * http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ *
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ *
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ *
+ * ALL SOURCE CODE IS PROVIDED "AS IS." THE AUTHOR MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ */
+
+
+#include "llviewerprecompiledheaders.h"
+#include "impprefsfonts.h"
+
+#include "llradiogroup.h"
+#include "lluictrlfactory.h"
+
+#include "llviewercontrol.h"
+#include "llviewerwindow.h"
+
+
+ImpPrefsFonts::ImpPrefsFonts()
+{
+	LLUICtrlFactory::getInstance()->
+		buildPanel(this, "panel_preferences_fonts.xml");
+}
+
+ImpPrefsFonts::~ImpPrefsFonts()
+{
+}
+
+
+BOOL ImpPrefsFonts::postBuild()
+{
+	refresh();
+	return true;
+}
+
+
+void ImpPrefsFonts::refresh()
+{
+	LLRadioGroup* fonts = getChild<LLRadioGroup>("fonts");
+	if (fonts)
+	{
+		fonts->setValue( gSavedSettings.getString("FontChoice") );
+	}
+}
+
+void ImpPrefsFonts::apply()
+{
+	LLRadioGroup* fonts = getChild<LLRadioGroup>("fonts");
+
+	if (fonts)
+	{
+		std::string font_choice = fonts->getValue().asString();
+
+		if (font_choice != gSavedSettings.getString("FontChoice") &&
+		    !font_choice.empty())
+		{
+			gSavedSettings.setString("FontChoice", font_choice);
+			LLNotifications::instance().add("ChangeFont");
+			refresh();
+		}
+	}
+}
+
+void ImpPrefsFonts::cancel()
+{
+}
diff --git a/linden/indra/newview/impprefsfonts.h b/linden/indra/newview/impprefsfonts.h
new file mode 100644
index 0000000..12aa0bb
--- /dev/null
+++ b/linden/indra/newview/impprefsfonts.h
@@ -0,0 +1,45 @@
+/**
+ * @file impprefsfonts.h
+ * @brief Font preferences panel
+ *
+ * Copyright (c) 2010, Jacek Antonelli
+ *
+ * The source code in this file ("Source Code") is provided to you
+ * under the terms of the GNU General Public License, version 2.0
+ * ("GPL"). Terms of the GPL can be found in doc/GPL-license.txt in
+ * this distribution, or online at
+ * http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ *
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ *
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ *
+ * ALL SOURCE CODE IS PROVIDED "AS IS." THE AUTHOR MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ */
+
+#ifndef IMP_PREFSFONTS_H
+#define IMP_PREFSFONTS_H
+
+#include "llpanel.h"
+
+class ImpPrefsFonts : public LLPanel
+{
+public:
+	ImpPrefsFonts();
+	virtual ~ImpPrefsFonts();
+
+	virtual BOOL postBuild();
+	void refresh();
+	void apply();
+	void cancel();
+};
+
+#endif // IMP_PREFSFONTS_H
diff --git a/linden/indra/newview/llfloaterpreference.cpp b/linden/indra/newview/llfloaterpreference.cpp
index 744c179..09336cb 100644
--- a/linden/indra/newview/llfloaterpreference.cpp
+++ b/linden/indra/newview/llfloaterpreference.cpp
@@ -48,6 +48,7 @@
 #include "llspinctrl.h"
 #include "message.h"
 
+#include "impprefsfonts.h"
 #include "llcommandhandler.h"
 #include "llfloaterpreference.h"
 #include "llpanelnetwork.h"
@@ -133,7 +134,8 @@ LLPreferenceCore::LLPreferenceCore(LLTabContainer* tab_container, LLButton * def
 	mMsgPanel(NULL),
 	mSkinsPanel(NULL),
 	mLCDPanel(NULL),
-	mPrefsAdvanced(NULL)
+	mPrefsAdvanced(NULL),
+	mPrefsFonts(NULL)
 {
 	mGeneralPanel = new LLPanelGeneral();
 	mTabContainer->addTabPanel(mGeneralPanel, mGeneralPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
@@ -197,6 +199,10 @@ LLPreferenceCore::LLPreferenceCore(LLTabContainer* tab_container, LLButton * def
 	mTabContainer->addTabPanel(mPrefsAdvanced, mPrefsAdvanced->getLabel(), FALSE, onTabChanged, mTabContainer);
 	mPrefsAdvanced->setDefaultBtn(default_btn);
 
+	mPrefsFonts = new ImpPrefsFonts();
+	mTabContainer->addTabPanel(mPrefsFonts, mPrefsFonts->getLabel(), FALSE, onTabChanged, mTabContainer);
+	mPrefsFonts->setDefaultBtn(default_btn);
+
 	if (!mTabContainer->selectTab(gSavedSettings.getS32("LastPrefTab")))
 	{
 		mTabContainer->selectFirstTab();
@@ -261,6 +267,11 @@ LLPreferenceCore::~LLPreferenceCore()
 		delete mPrefsAdvanced;
 		mPrefsAdvanced = NULL;
 	}
+	if (mPrefsFonts)
+	{
+		delete mPrefsFonts;
+		mPrefsFonts = NULL;
+	}
 
 }
 
@@ -278,6 +289,7 @@ void LLPreferenceCore::apply()
 	mMsgPanel->apply();
 	mSkinsPanel->apply();
 	mPrefsAdvanced->apply();
+	mPrefsFonts->apply();
 
 	// hardware menu apply
 	LLFloaterHardwareSettings::instance()->apply();
@@ -307,6 +319,7 @@ void LLPreferenceCore::cancel()
 	mMsgPanel->cancel();
 	mSkinsPanel->cancel();
 	mPrefsAdvanced->cancel();
+	mPrefsFonts->cancel();
 
 	// cancel hardware menu
 	LLFloaterHardwareSettings::instance()->cancel();
diff --git a/linden/indra/newview/llfloaterpreference.h b/linden/indra/newview/llfloaterpreference.h
index 1878280..e98c45c 100644
--- a/linden/indra/newview/llfloaterpreference.h
+++ b/linden/indra/newview/llfloaterpreference.h
@@ -56,6 +56,7 @@ class LLPrefsIM;
 class LLPanelMsgs;
 class LLPanelSkins;
 class LLPrefsAdvanced;
+class ImpPrefsFonts;
 class LLScrollListCtrl;
 
 class LLPreferenceCore
@@ -93,6 +94,7 @@ private:
 	LLPanelMsgs				*mMsgPanel;
 	LLPanelLCD				*mLCDPanel;
 	LLPrefsAdvanced			*mPrefsAdvanced;
+  ImpPrefsFonts* mPrefsFonts;
 };
 
 // Floater to control preferences (display, audio, bandwidth, general.
diff --git a/linden/indra/newview/skins/default/xui/en-us/fonts.xml b/linden/indra/newview/skins/default/xui/en-us/fonts.xml
index 95070ed..5d831c6 100644
--- a/linden/indra/newview/skins/default/xui/en-us/fonts.xml
+++ b/linden/indra/newview/skins/default/xui/en-us/fonts.xml
@@ -33,6 +33,7 @@
     <file>VeraMono.ttf</file>
   </font>
 
+
   <font name="DejaVu"
 	comment="Name of DejaVu font">
     <file>DejaVuSansCondensed.ttf</file>
@@ -56,6 +57,19 @@
     <file>DejaVuSansCondensed-BoldOblique.ttf</file>
   </font>
 
+
+  <font name="Liberation"
+        comment="Name of Liberation font">
+    <file>LiberationSans-Regular.ttf</file>
+  </font>
+
+  <font name="Liberation"
+        comment="Name of Liberation font (bold)"
+        font_style="BOLD">
+    <file>LiberationSans-Bold.ttf</file>
+  </font>
+
+
   <font name="Helvetica"
 	comment="Name of Helvetica font">
     <file>arial.ttf</file>
diff --git a/linden/indra/newview/skins/default/xui/en-us/notifications.xml b/linden/indra/newview/skins/default/xui/en-us/notifications.xml
index a490af1..58d5f19 100644
--- a/linden/indra/newview/skins/default/xui/en-us/notifications.xml
+++ b/linden/indra/newview/skins/default/xui/en-us/notifications.xml
@@ -7052,6 +7052,13 @@ Apply this region's settings? (&quot;Ignore&quot; will ignore all region setting
   </form>
 </notification>
 
+<notification
+ name="ChangeFont"
+ icon="alertmodal.tga"
+ type="alertmodal">
+The new font will appear after you restart [VIEWER_NAME].
+</notification>
+
 
 <!--End Imprudence notifications-->
 
diff --git a/linden/indra/newview/skins/default/xui/en-us/panel_preferences_fonts.xml b/linden/indra/newview/skins/default/xui/en-us/panel_preferences_fonts.xml
new file mode 100644
index 0000000..e55981b
--- /dev/null
+++ b/linden/indra/newview/skins/default/xui/en-us/panel_preferences_fonts.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
+
+<panel name="font_panel" label="Fonts"
+       bottom="-409" left="102" height="408" width="517"
+       border="true" follows="left|top|right|bottom">
+
+  <text bottom="-25" left="10" height="15" width="300">
+    User interface font (requires restart):
+  </text>
+
+  <radio_group name="fonts" draw_border="false"
+               top="-30" left="20" bottom="0" right="-20"
+               follows="top|left|bottom|right">
+
+    <radio_item name="DejaVu" bottom="-20" left="0" height="20">
+      DejaVu Sans Condensed
+    </radio_item>
+
+    <radio_item name="Liberation" bottom="-70" left="0" height="20">
+      Liberation Sans (classic Imprudence font)
+    </radio_item>
+    
+  </radio_group>
+
+  <text name="dejavu_preview" font="DejaVuMedium" top="-55" left="60">
+    Preview: The quick brown fox jumped over the lazy dog. :)
+  </text>
+
+  <text name="lib_preview" font="LiberationMedium" top="-105" left="60">
+    Preview: The quick brown fox jumped over the lazy dog. :)
+  </text>
+
+</panel>
-- 
cgit v1.1