]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mgl/fontutil.cpp
add implementation fallback for not yet instantiated control peers
[wxWidgets.git] / src / mgl / fontutil.cpp
index 78d0443857cefe7eb7e6af43e2874300d152dd40..7900bda0ec9d5671a962815bc4c57415cf5ac6a4 100644 (file)
@@ -4,12 +4,12 @@
 // Author:      Vaclav Slavik
 // Created:     2001/04/29
 // RCS-ID:      $Id$
-// Copyright:   (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
-// Licence:     wxWindows license
+// Copyright:   (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
     #pragma implementation "fontutil.h"
 #endif
 
     #pragma hdrstop
 #endif
 
-#ifndef WX_PRECOMP
-#endif // PCH
-
-
+#include "wx/log.h"
 #include "wx/fontutil.h"
+#include "wx/encinfo.h"
 #include "wx/fontmap.h"
 #include "wx/tokenzr.h"
 #include "wx/hash.h"
-#include "wx/module.h"
+
 #include "wx/listimpl.cpp"
-#include "wx/log.h"
+#include "wx/sysopt.h"
 #include "wx/mgl/private.h"
 
 #include <mgraph.h>
@@ -189,8 +187,10 @@ wxMGLFontInstance::~wxMGLFontInstance()
         MGL_unloadFontInstance(m_font);
 }
     
-wxMGLFontLibrary::wxMGLFontLibrary(const wxString& filename, int type)
+wxMGLFontLibrary::wxMGLFontLibrary(const wxString& filename, int type, 
+                                   wxMGLFontFamily *parentFamily)
 {
+    m_family = parentFamily;
     m_type = type;
     m_fileName = filename;
     m_refs = 0;
@@ -229,6 +229,8 @@ void wxMGLFontLibrary::DecRef()
     }
 }
 
+static int gs_antialiasingThreshold = -1;
+
 wxMGLFontInstance *wxMGLFontLibrary::GetFontInstance(wxFont *font, 
                                                      float scale, bool aa)
 {
@@ -236,10 +238,28 @@ wxMGLFontInstance *wxMGLFontLibrary::GetFontInstance(wxFont *font,
 
     wxString facename;
     bool slant;
-    bool antialiased = 
-        (m_fontLib->fontLibType == MGL_BITMAPFONT_LIB) ? FALSE : aa;
+    bool antialiased;
     float pt = (float)font->GetPointSize() * scale;
 
+    if ( gs_antialiasingThreshold == -1 )
+    {
+        gs_antialiasingThreshold = 10;
+#if wxUSE_SYSTEM_OPTIONS
+        if ( wxSystemOptions::HasOption(wxT("mgl.aa-threshold")) )
+            gs_antialiasingThreshold = 
+                wxSystemOptions::GetOptionInt(wxT("mgl.aa-threshold"));
+        wxLogTrace("mgl_font", "AA threshold set to %i", gs_antialiasingThreshold);
+#endif
+    }
+
+    // Small characters don't look good when antialiased with the algorithm
+    // that FreeType uses (mere 2x2 supersampling), so lets disable it AA
+    // completely for small fonts.
+    if ( pt <= gs_antialiasingThreshold )
+        antialiased = FALSE;
+    else
+        antialiased = (m_fontLib->fontLibType == MGL_BITMAPFONT_LIB) ? FALSE : aa;
+
     slant = (((m_type & wxFONTFACE_ITALIC) == 0) &&
              (font->GetStyle() == wxSLANT || font->GetStyle() == wxITALIC));
 
@@ -279,25 +299,25 @@ wxMGLFontFamily::wxMGLFontFamily(const font_info_t *info)
         m_fontLibs[wxFONTFACE_REGULAR] = NULL;
     else
         m_fontLibs[wxFONTFACE_REGULAR] = 
-            new wxMGLFontLibrary(info->regularFace, wxFONTFACE_REGULAR);
+            new wxMGLFontLibrary(info->regularFace, wxFONTFACE_REGULAR, this);
     
     if ( info->italicFace[0] == '\0' )
         m_fontLibs[wxFONTFACE_ITALIC] = NULL;
     else
         m_fontLibs[wxFONTFACE_ITALIC] = 
-            new wxMGLFontLibrary(info->italicFace, wxFONTFACE_ITALIC);
+            new wxMGLFontLibrary(info->italicFace, wxFONTFACE_ITALIC, this);
     
     if ( info->boldFace[0] == '\0' )
         m_fontLibs[wxFONTFACE_BOLD] = NULL;
     else
         m_fontLibs[wxFONTFACE_BOLD] = 
-            new wxMGLFontLibrary(info->boldFace, wxFONTFACE_BOLD);
+            new wxMGLFontLibrary(info->boldFace, wxFONTFACE_BOLD, this);
     
     if ( info->boldItalicFace[0] == '\0' )
         m_fontLibs[wxFONTFACE_BOLD_ITALIC] = NULL;
     else
         m_fontLibs[wxFONTFACE_BOLD_ITALIC] = 
-            new wxMGLFontLibrary(info->boldItalicFace, wxFONTFACE_BOLD_ITALIC);
+            new wxMGLFontLibrary(info->boldItalicFace, wxFONTFACE_BOLD_ITALIC, this);
             
     wxLogTrace("mgl_font", "new family '%s' (r=%s, i=%s, b=%s, bi=%s)\n",
                info->familyName, info->regularFace, info->italicFace, 
@@ -323,20 +343,17 @@ bool wxMGLFontFamily::HasFace(int type) const
 wxMGLFontLibrary *wxFontsManager::GetFontLibrary(wxFont *font)
 {
     wxMGLFontFamily *family;
-    wxString facename;
     int type;
+    wxString facename = font->GetFaceName();
     
-    if ( facename )
-        family = GetFamily(font->GetFaceName());
+    if ( !facename.IsEmpty() )
+        family = GetFamily(facename);
     else
         family = NULL;
-    if ( family )
-        facename = font->GetFaceName();
-    else
-        facename.Empty();
-    
+
     if ( !family )
     {
+        facename.Empty();
         switch (font->GetFamily())
         {
             case wxSCRIPT:
@@ -397,7 +414,7 @@ wxMGLFontLibrary *wxFontsManager::GetFontLibrary(wxFont *font)
     return family->GetLibrary(type);
 }
 
-static ibool enum_callback(const font_info_t *info, void *cookie)
+static ibool MGLAPI enum_callback(const font_info_t *info, void *cookie)
 {
     wxFontsManager *db = (wxFontsManager*)cookie;
     db->AddFamily(info);
@@ -433,24 +450,3 @@ wxMGLFontFamily *wxFontsManager::GetFamily(const wxString& name) const
 
 
 wxFontsManager *wxTheFontsManager = NULL;
-
-
-// A module that takes care of fonts DB initialization and destruction:
-
-class wxFontutilModule: public wxModule
-{
-DECLARE_DYNAMIC_CLASS(wxFontutilModule)
-public:
-    wxFontutilModule() {}
-    bool OnInit() 
-    {
-        wxTheFontsManager = new wxFontsManager;
-        return TRUE; 
-    }
-    void OnExit() 
-    { 
-        delete wxTheFontsManager;
-    }
-};
-
-IMPLEMENT_DYNAMIC_CLASS(wxFontutilModule, wxModule)