meld icon indicating copy to clipboard operation
meld copied to clipboard

Changing font does not work properly

Open nobodo opened this issue 4 years ago • 6 comments

Might be upstream (gtk/pango/...) issue, but the font changing does not seem to work for all fonts I'd like to use. It is already visible in the font picker where the font preview does not match the actual font face which is shown in the selector window.

For some fonts it displays the correct font face in the preview and those also affect the Meld font, but for others it just has some default (haven't yet identified which that is)

I have tested this with previous Meld versions too, and the same issue is with those, which indicates that this might be gtk issue or some strange font problem for me and that's why I'd like to hear if anyone else can witness this.

nobodo avatar Apr 16 '20 11:04 nobodo

Something to do with Pango not recognizing the font. I modified Resources/lib/python3.6/gi/overrides/Pango.py to print out the font string, and for example when I select 'Menlo Regular' it prints out 'Menlo Condensed'

pango-list shows only these:

Menlo (monospace)
  Bold Italic: Menlo Bold Italic
  Bold:        Menlo Bold
  Italic:      Menlo Italic
  Regular:     Menlo

So I assume that when unrecognized font is selected, it uses some default.

Did a jolly hack to manually override the font string to the same Pango.py, until someone solves this permanently. At least I'm happy for a while.

nobodo avatar Apr 16 '20 17:04 nobodo

@nobodo interesting issue. I'll try to figure it out. My guess is something to do with fontconfig paths or something like that. Can you share the code that you used to debug (printing out fonts, etc)? I'm not an expert on this part but I could use your code as a starting point.

yousseb avatar Apr 18 '20 18:04 yousseb

Since I still haven't found a way to actually build meld (somehow it's super complicated and I seem to have always the wrong versions of everything) so I have a bit limited ways to actually dig in to this.

So, I just modified one file in the installed application. The path is /Applications/Meld.app/Contents/Resources/lib/python3.6/gi/overrides/Pango.py and I added the print(string) to this:

class FontDescription(Pango.FontDescription):

    def __new__(cls, string=None):
        if string is not None:
            print(string)
            return Pango.font_description_from_string(string)
        else:
            return Pango.FontDescription.__new__(cls)

nobodo avatar Apr 19 '20 11:04 nobodo

Resetting the stretch to normal gives better results. Otherwise it uses the Condensed and is then unable to select correct font.

if string is not None:
	my_fd = Pango.font_description_from_string(string)
	my_fd.set_stretch(4)
	string=my_fd.to_string()
	return Pango.font_description_from_string(string)

I did not find a way to use the enums (pango.STRETCH_NORMAL), thus using the value 4 which yields the same result.

Possibly related issue from pango: https://gitlab.gnome.org/GNOME/pango/-/issues/466

nobodo avatar Apr 20 '20 14:04 nobodo

The font chooser dialog can be tested with this simple python code (just switch comment to test with 2.0 and 3.0) and it works as expected with gtk 2.0 but 3.0 has font issue. Attached screenshots of the differences, in gtk 2.0 all fonts and variations work, most of the fonts in 3.0 look identical - only italic / oblique change the font to italic but that's all. I selected "Source Code Pro" just as an example. Screenshot 2020-04-21 at 17 36 00 Screenshot 2020-04-21 at 17 36 12 Screenshot 2020-04-21 at 17 36 46 Screenshot 2020-04-21 at 17 36 54

import gi
#gi.require_version("Gtk", "2.0")
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

class PyApp(Gtk.Window):
   def __init__(self):
      super(PyApp, self).__init__()
      dlg = Gtk.FontSelectionDialog()
      dlg.run()
      exit()
PyApp()
Gtk.main()

nobodo avatar Apr 21 '20 14:04 nobodo

I did some experiments with the gtk3-demo which is shipped along with gtk3 and found out some interesting features. That gtk3-demo has font picker under the 'Pickers' and the behaviour is somewhat inconsistent. When I start browsing through the fonts one by one, they seem to be displayed ok, until at some point it starts showing the default font for newly selected fonts. Browsing back to the already traversed ones will show they are still ok. Then I close the picker widget and reopen it and continue from the place where the default font was last seen - now it displays the font correctly and I can again browse the fonts and they look fine, until certain point the default font appears.

With my own test, I have now evidence that only those fonts that have Condensed stretch available (visible via pango-list for example) are the only ones that work. Also, if I set manually some font in the code, like this:

      dlg = Gtk.FontSelectionDialog()
      dlg.set_font_name('Helvetica 10')
      dlg.run()

This will be displayed on the terminal:

(gtktest.py:30282): Pango-WARNING **: 10:39:19.220: couldn't load font "Helvetica Condensed Not-Rotated 10", modified variant/weight/stretch as fallback, expect ugly output.

nobodo avatar Apr 22 '20 07:04 nobodo