Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Loaden on January 17, 2010, 10:24:49 am

Title: How to use the temporary fonts?
Post by: Loaden on January 17, 2010, 10:24:49 am
For example there is a font named "DejaVu", I do not want to install the fonts into the system path: "C:\Windows\Fonts", then how can we use this font?

I find that OOo has such features: only copies all fonts to "share\fonts\truetype" directory.

In Windows OS, i found this API can do that:http://msdn.microsoft.com/en-us/library/dd183326(VS.85).aspx (http://msdn.microsoft.com/en-us/library/dd183326(VS.85).aspx)

[attachment deleted by admin]
Title: Re: How to use the temporary fonts?
Post by: Loaden on January 17, 2010, 10:53:17 am
This patch works fine. WinXP SP3.
Code
Index: app.cpp
===================================================================
--- app.cpp     (revision 6089)
+++ app.cpp     (working copy)
@@ -656,6 +656,18 @@

         CheckVersion();

+#ifdef __WXMSW__
+        AddFontResource(_T("tool\\font\\CONSOLA.ttf"));
+        AddFontResource(_T("tool\\font\\CONSOLAB.ttf"));
+        AddFontResource(_T("tool\\font\\CONSOLAI.ttf"));
+        AddFontResource(_T("tool\\font\\CONSOLAZ.ttf"));
+//        AddFontResource(_T("tool\\font\\DejaVuSansMono.ttf"));
+//        AddFontResource(_T("tool\\font\\DejaVuSansMono-Oblique.ttf"));
+//        AddFontResource(_T("tool\\font\\DejaVuSansMono-Bold.ttf"));
+//        AddFontResource(_T("tool\\font\\DejaVuSansMono-BoldOblique.ttf"));
+        SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
+#endif
+
         // run startup script
         try
         {
Title: Re: How to use the temporary fonts?
Post by: Loaden on January 17, 2010, 12:12:55 pm
Hi, this patch works well on XPSP3.  :)
Code
Index: app.cpp
===================================================================
--- app.cpp (revision 6089)
+++ app.cpp (working copy)
@@ -656,6 +656,17 @@
 
         CheckVersion();
 
+#ifdef __WXMSW__
+        wxString font = wxFindFirstFile(_T("share/CodeBlocks/fonts/*.*"));
+        while (!font.empty())
+        {
+            AddFontResource(font);
+            font = wxFindNextFile();
+        }
+
+        SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
+#endif
+
         // run startup script
         try
         {


[attachment deleted by admin]
Title: Re: How to use the temporary fonts?
Post by: MortenMacFly on January 17, 2010, 02:14:29 pm
Hi, this patch works well on XPSP3.  :)
Code
Index: app.cpp
+        while (!font.empty())
Are you sure? Because verifying if a string is empty is done using IsEmpty() on wx usually...?! Probably empty is a STL compatibility function?! (I need to check the docs...)
Title: Re: How to use the temporary fonts?
Post by: Loaden on January 17, 2010, 02:47:23 pm
Hi, this patch works well on XPSP3.  :)
Code
Index: app.cpp
+        while (!font.empty())
Are you sure? Because verifying if a string is empty is done using IsEmpty() on wx usually...?! Probably empty is a STL compatibility function?! (I need to check the docs...)
yes! is same.
http://docs.wxwidgets.org/stable/wx_filefunctions.html#wxfindfirstfile (http://docs.wxwidgets.org/stable/wx_filefunctions.html#wxfindfirstfile)
Title: Re: How to use the temporary fonts?
Post by: MortenMacFly on January 17, 2010, 03:28:55 pm
yes! is same.
http://docs.wxwidgets.org/stable/wx_filefunctions.html#wxfindfirstfile (http://docs.wxwidgets.org/stable/wx_filefunctions.html#wxfindfirstfile)
Ok. But I'd still prefer IsEmpty() to avoid conflicts / misunderstandings with wxSting's Empty() method (notice the capital first letter), which clears the string.
Title: Re: How to use the temporary fonts?
Post by: Loaden on January 17, 2010, 03:48:20 pm
yes! is same.
http://docs.wxwidgets.org/stable/wx_filefunctions.html#wxfindfirstfile (http://docs.wxwidgets.org/stable/wx_filefunctions.html#wxfindfirstfile)
Ok. But I'd still prefer IsEmpty() to avoid conflicts / misunderstandings with wxSting's Empty() method (notice the capital first letter), which clears the string.
Well.
Code
#ifdef __WXMSW__
        wxString font = wxFindFirstFile(_T("share/CodeBlocks/fonts/*.*"));
        while (!font.IsEmpty())
        {
            AddFontResource(font);
            font = wxFindNextFile();
        }

        SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
#endif
Title: Re: How to use the temporary fonts?
Post by: Loaden on January 18, 2010, 10:09:16 am
Need to free fonts, this patch better.
Code
Index: app.cpp

===================================================================

--- app.cpp (revision 6089)

+++ app.cpp (working copy)

@@ -656,6 +656,16 @@

 
         CheckVersion();
 
+#ifdef __WXMSW__
+        wxString font = wxFindFirstFile(_T("share/CodeBlocks/fonts/*.*"));
+        while (!font.IsEmpty())
+        {
+            ::AddFontResource(font);
+            font = wxFindNextFile();
+        }
+        ::SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
+#endif
+
         // run startup script
         try
         {
@@ -725,6 +735,8 @@

 #ifdef __WXMSW__
     if (m_ExceptionHandlerLib)
         FreeLibrary(m_ExceptionHandlerLib);
+
+
 #endif
     if (m_pSingleInstance)
         delete m_pSingleInstance;
@@ -732,6 +744,16 @@

     // ultimate shutdown...
     Manager::Free();
 
+#ifdef __WXMSW__
+        wxString font = wxFindFirstFile(_T("share/CodeBlocks/fonts/*.*"));
+        while (!font.IsEmpty())
+        {
+            ::RemoveFontResource(font);
+            font = wxFindNextFile();
+        }
+        ::SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
+#endif
+
     // WX docs say that this function's return value is ignored,
     // but we return our value anyway. It might not be ignored at some point...
     return m_Batch ? m_BatchExitCode : 0;

[attachment deleted by admin]
Title: Re: How to use the temporary fonts?
Post by: Loaden on January 18, 2010, 11:53:59 am
Sorry, need an absolute path, rather than a relative path!
Code
Index: app.cpp

===================================================================

--- app.cpp (revision 6089)

+++ app.cpp (working copy)

@@ -656,6 +656,17 @@

 
         CheckVersion();
 
+#ifdef __WXMSW__
+        wxString fontPath = GetAppPath() + _T("/share/CodeBlocks/fonts/*.*");
+        wxString font = wxFindFirstFile(fontPath);
+        while (!font.IsEmpty())
+        {
+            ::AddFontResource(font);
+            font = wxFindNextFile();
+        }
+        ::SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
+#endif
+
         // run startup script
         try
         {
@@ -725,6 +736,8 @@

 #ifdef __WXMSW__
     if (m_ExceptionHandlerLib)
         FreeLibrary(m_ExceptionHandlerLib);
+
+
 #endif
     if (m_pSingleInstance)
         delete m_pSingleInstance;
@@ -732,6 +745,17 @@

     // ultimate shutdown...
     Manager::Free();
 
+#ifdef __WXMSW__
+        wxString fontPath = GetAppPath() + _T("/share/CodeBlocks/fonts/*.*");
+        wxString font = wxFindFirstFile(fontPath);
+        while (!font.IsEmpty())
+        {
+            ::RemoveFontResource(font);
+            font = wxFindNextFile();
+        }
+        ::SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
+#endif
+
     // WX docs say that this function's return value is ignored,
     // but we return our value anyway. It might not be ignored at some point...
     return m_Batch ? m_BatchExitCode : 0;

[attachment deleted by admin]