News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

How to use the temporary fonts?

Started by Loaden, January 17, 2010, 10:24:49 AM

Previous topic - Next topic

Loaden

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]

Loaden

This patch works fine. WinXP SP3.
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
         {


Loaden

Hi, this patch works well on XPSP3.  :)
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]

MortenMacFly

Quote from: Loaden on January 17, 2010, 12:12:55 PM
Hi, this patch works well on XPSP3.  :)
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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

Loaden

Quote from: MortenMacFly on January 17, 2010, 02:14:29 PM
Quote from: Loaden on January 17, 2010, 12:12:55 PM
Hi, this patch works well on XPSP3.  :)
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

MortenMacFly

Quote from: Loaden on January 17, 2010, 02:47:23 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

Loaden

#6
Quote from: MortenMacFly on January 17, 2010, 03:28:55 PM
Quote from: Loaden on January 17, 2010, 02:47:23 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.
#ifdef __WXMSW__
       wxString font = wxFindFirstFile(_T("share/CodeBlocks/fonts/*.*"));
       while (!font.IsEmpty())
       {
           AddFontResource(font);
           font = wxFindNextFile();
       }

       SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
#endif

Loaden

Need to free fonts, this patch better.
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]

Loaden

Sorry, need an absolute path, rather than a relative path!
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]