Author Topic: How to use the temporary fonts?  (Read 13474 times)

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
How to use the temporary fonts?
« 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

[attachment deleted by admin]

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: How to use the temporary fonts?
« Reply #1 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
         {

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: How to use the temporary fonts?
« Reply #2 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]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: How to use the temporary fonts?
« Reply #3 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...)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: How to use the temporary fonts?
« Reply #4 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

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: How to use the temporary fonts?
« Reply #5 on: January 17, 2010, 03:28:55 pm »
yes! is same.
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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: How to use the temporary fonts?
« Reply #6 on: January 17, 2010, 03:48:20 pm »
yes! is same.
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
« Last Edit: January 17, 2010, 05:17:17 pm by Loaden »

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: How to use the temporary fonts?
« Reply #7 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]

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: How to use the temporary fonts?
« Reply #8 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]