]> git.saurik.com Git - wxWidgets.git/blobdiff - src/unix/fontutil.cpp
modified shell script to copy setup0.h into DerivedSource directory
[wxWidgets.git] / src / unix / fontutil.cpp
index e1521328fca140588fef7bb2566652b12c1ae464..268300e5fcb2f60a357c9b86beba45d867783522 100644 (file)
@@ -17,7 +17,7 @@
 // headers
 // ----------------------------------------------------------------------------
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
     #pragma implementation "fontutil.h"
 #endif
 
@@ -235,10 +235,13 @@ static wxHashTable *g_fontHash = (wxHashTable*) NULL;
 #elif defined(__WXGTK__)
     wxNativeFont wxLoadFont(const wxString& fontSpec)
     {
-        // use gdk_fontset_load() instead of gdk_font_load() because otherwise
-        // we have problems with Japanese (not terribly precise, I know, but
-        // this is all the patch said)
-        return gdk_fontset_load( wxConvertWX2MB(fontSpec) );
+        // VZ: we should use gdk_fontset_load() instead of gdk_font_load()
+        //     here to be able to display Japanese fonts correctly (at least
+        //     this is what people report) but unfortunately doing it results
+        //     in tons of warnings when using GTK with "normal" European
+        //     languages and so we can't always do it and I don't know enough
+        //     to determine when should this be done... (FIXME)
+        return gdk_font_load( wxConvertWX2MB(fontSpec) );
     }
 
     inline void wxFreeFont(wxNativeFont font)
@@ -794,27 +797,49 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize,
           *xFontName = newFontName;
     }
 
-    // try to load exactly the font requested first
-    if( !font )
-    {
-        font = wxLoadQueryFont( pointSize, family, style, weight,
-                                underlined, facename,
-                                info.xregistry, info.xencoding,
-                                xFontName );
-    }
-
     if ( !font )
     {
         // search up and down by stepsize 10
         int max_size = pointSize + 20 * (1 + (pointSize/180));
         int min_size = pointSize - 20 * (1 + (pointSize/180));
 
-        int i;
+        int i, round; // counters
 
-        // Search for smaller size (approx.)
-        for ( i = pointSize - 10; !font && i >= 10 && i >= min_size; i -= 10 )
+        // first round: search for equal, then for smaller and for larger size with the given weight and style
+        int testweight = weight;
+        int teststyle = style;
+
+        for ( round = 0; round < 3; round++ )
+        {
+            // second round: use normal weight
+            if ( round == 1 )
         {
-            font = wxLoadQueryFont(i, family, style, weight, underlined,
+                if ( testweight != wxNORMAL )
+                {
+                    testweight = wxNORMAL;
+                }
+                else
+                {
+                    ++round; // fall through to third round
+                }
+            }
+
+            // third round: ... and use normal style
+            if ( round == 2 )
+            {
+                if ( teststyle != wxNORMAL )
+                {
+                    teststyle = wxNORMAL;
+                }
+                else
+                {
+                    break;
+                }
+            }
+            // Search for equal or smaller size (approx.)
+            for ( i = pointSize; !font && i >= 10 && i >= min_size; i -= 10 )
+            {
+                font = wxLoadQueryFont(i, family, teststyle, testweight, underlined,
                                    facename, info.xregistry, info.xencoding,
                                    xFontName);
         }
@@ -822,9 +847,10 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize,
         // Search for larger size (approx.)
         for ( i = pointSize + 10; !font && i <= max_size; i += 10 )
         {
-            font = wxLoadQueryFont(i, family, style, weight, underlined,
+                font = wxLoadQueryFont(i, family, teststyle, testweight, underlined,
                                    facename, info.xregistry, info.xencoding,
                                    xFontName);
+            }
         }
 
         // Try default family