Ver código fonte

fixed: LookupGuiFont could return Null under linux/Gtk and MaxIDE would crash if specific font faces weren't installed (#56)

* fixed: LookupGuiFont could return Null under Gtk as it depended on hardcoded fontnames
pango actually does font substitution lookup for us, and is guarenteed to find an alternative, so we'll trust it and let it decide instead of specifying our own hardcoded fallbacks and then failing with Null

* fixed: pango font substitutions were still dumb, due to the initial pango description being cached and never updated
We now clear the cache when we've manually updated the font description (we may need to do this in OTHER places too!), and try later fallbacks, THEN if all fallbacks fail, we finally let pango decide on a font on its own
ProPuke 3 anos atrás
pai
commit
4a38c074d7
2 arquivos alterados com 34 adições e 2 exclusões
  1. 10 0
      gtk3maxgui.mod/gtkcommon.bmx
  2. 24 2
      gtk3maxgui.mod/gtkgui.bmx

+ 10 - 0
gtk3maxgui.mod/gtkcommon.bmx

@@ -1041,6 +1041,16 @@ Function getPangoDescriptionFromGuiFont(font:TGtkGuiFont)
 
 End Function
 
+Rem
+internal: Clear a cached Pango font description for a TGuiFont. (INTERNAL)
+End Rem
+Function clearPangoDescriptionCacheForGuiFont(font:TGtkGuiFont)
+	If font.fontDesc Then
+		pango_font_description_free(font.fontDesc)
+		font.fontDesc = Null
+	EndIf
+End Function
+
 Rem
 internal: Returns a TGuiFont from a pango description object. (INTERNAL)
 End Rem

+ 24 - 2
gtk3maxgui.mod/gtkgui.bmx

@@ -412,7 +412,7 @@ Type TGTK3GUIDriver Extends TMaxGUIDriver
 		Return DoLoadFont(font)
 	End Method
 	
-	Method DoLoadFont:TGuiFont(font:TGuiFont)
+	Method DoLoadFont:TGuiFont(font:TGuiFont, automaticFallback:Int = False )
 		Local widget:Byte Ptr = gtk_label_new(Null)
 		Local _context:Byte Ptr = gtk_widget_get_pango_context(widget)
 
@@ -420,7 +420,11 @@ Type TGTK3GUIDriver Extends TMaxGUIDriver
 		'Local fontdesc:Byte Ptr = font.fontDesc
 		Local _fontset:Byte Ptr = pango_context_load_fontset(_context, TGtkGuiFont(font).fontDesc, Null)
 
-		pango_fontset_foreach(_fontset, fontforeach, font)
+		If automaticFallback
+			pango_fontset_foreach(_fontset, fontforeachFallback, font)
+		Else
+			pango_fontset_foreach(_fontset, fontforeach, font)
+		EndIf
 
 		'pango_font_description_free(fontdesc)
 
@@ -434,17 +438,25 @@ Type TGTK3GUIDriver Extends TMaxGUIDriver
 			Select font.name
 				Case "Lucida"
 					font.name = "DejaVu Sans Mono"
+					clearPangoDescriptionCacheForGuiFont(TGtkGuiFont(font))
 					font = DoLoadFont(font)
 				Case "DejaVu Sans Mono"
 					font.name = "Droid Sans Mono"
+					clearPangoDescriptionCacheForGuiFont(TGtkGuiFont(font))
 					font = DoLoadFont(font)
 				Case "Droid Sans Mono"
 					font.name = "FreeMono"
+					clearPangoDescriptionCacheForGuiFont(TGtkGuiFont(font))
 					font = DoLoadFont(font)
 				Case "FreeMono"
+					font.name = "Monospace"
+					clearPangoDescriptionCacheForGuiFont(TGtkGuiFont(font))
+					font = DoLoadFont(font, True)
+				Case "MonoSpace"
 					Return Null
 				Default ' try a default...
 					font.name = "Lucida"
+					clearPangoDescriptionCacheForGuiFont(TGtkGuiFont(font))
 					font = DoLoadFont(font)
 			End Select
 
@@ -498,6 +510,16 @@ Type TGTK3GUIDriver Extends TMaxGUIDriver
 		End If
 	End Function
 
+	Function fontforeachFallback:Int(fontset:Byte Ptr, _font:Byte Ptr, data:Object)
+		Local fontdesc:Byte Ptr = pango_font_describe(_font)
+		Local thisfont:TGuiFont = getGuiFontFromPangoDescription(fontdesc)
+
+		TGuiFont(data).name = thisfont.name
+		TGuiFont(data).path = "OK!"
+
+		Return True
+	End Function
+
 	Method CreateGadget:TGadget(GadgetClass:Int, name:String, x:Int, y:Int, w:Int, h:Int,group:TGadget, style:Int)
 		Local gadget:TGTKGadget
 		Local gtkclass:Int = -1