JuliaGraphics / Winston.jl

2D plotting for Julia
MIT License
171 stars 55 forks source link

example of how to change the font? #303

Open ezaron opened 4 years ago

ezaron commented 4 years ago

Hello All,

In one of the recent updates of either Winston or Gtk, I noticed that the default font has changed from a sans serif font to a serif font.

Would anyone on this list have a suggestion for how to access the old sans serif font (arial or helvetica or similar)? I am running Julia 1.4.1 on linux.

All the best, Ed

tknopp commented 4 years ago

This is because Gtk/Cairo/Fontconfig now get binaries from BinaryBuilder. This might be the same issue I posted here:

https://github.com/JuliaGraphics/Gtk.jl/issues/507

If you can come up with a minimal example, maybe @lobingera or @giordano can help.

ezaron commented 4 years ago

Thx, tknopp. Following through the link you provided and also looking at this Cairo issue, https://github.com/JuliaGraphics/Cairo.jl/issues/312 it seems like a quick fix is to add the following two lines to the textdraw function in the Winston/src/renderer.jl file:

fs = get(self,:fontsize) set_font_face(self.ctx, "DejaVu Sans $(fs)px")

I tried a few variations of above, and the following command (from the Cairo sample_text.jl file),

select_font_face(cr, "DejaVu Sans", Cairo.FONT_SLANT_NORMAL, Cairo.FONT_WEIGHT_BOLD);

when the graphics context is first created, but it didn't work.

Anyway, agreed, this seems to be a lower-level issue related to Cairo or Fontconfig.

lobingera commented 4 years ago

I don't have a working solution right now - even not on my own computer(s). The set_font_face works with the Pango (pangocairo) interfaces which should work once fontconfig is working, select_font_face with the libcairo 'toy' interface which is only a PoC for testing or similar, in using cairo one should open the font externally (e.g. via Freetype).

I'm not happy with the current setup but to get a stable solution (for Cairo.jl and higher) we need a fontconfig expert (and the julia environment seems to lack one).