sciapp / gr

GR framework: a graphics library for visualisation applications
Other
327 stars 54 forks source link

Add Inter Font Support #171

Open EldarAgalarov opened 1 year ago

EldarAgalarov commented 1 year ago

Hi. It would be great if Inter font will be supported by GR. Ugly and scary fonts like Courier are supported, but not beautiful fonts like Inter :(

danielkaiser commented 1 year ago

Hi, we only bundle a very limited amount of fonts to keep the GR runtime downloads small. For this reason we even removed existing fonts and instead added the gr_loadfont function, with the help of which you can load arbitrary fonts.

This function also searches the default font directories of the operating system, so if you presumably have Inter installed, this snippet should be sufficient to use the Inter font in GR:

int font;
gr_loadfont("Inter-Regular.ttf", &font);
if (font >= 0) {
    gr_settextfontprec(font, 3);
}
EldarAgalarov commented 1 year ago

Hi @danielkaiser Can I load Inter font into GR using Julia? I'm using GR Framework as backend of the Julian's Plots library.

IngoMeyer441 commented 1 year ago

Hey @EldarAgalarov, the direct GR wrapper GR.jl has support for custom user fonts, see the user_fonts.jl example as a reference. However, I don't know if GR.jl and Plots can be mixed together. Probably @jheinen can tell more about this.

danielkaiser commented 1 year ago

Hi @EldarAgalarov,

with this commit by @jheinen in Plots.jl (included since version 1.38.6) loading of custom fonts with the GR backend should be supported there as well.

Does this solve your issue?

EldarAgalarov commented 1 year ago

Hi @danielkaiser Tried without success:

using Plots

ENV["GKS_FONT_DIRS"] = joinpath(pwd(), "Documents", "inter") # Inter.ttf

p = plot(1:10, rand(10), title = "Title", label = "Label", xguide = "xGuide", yguide = "yGuide")
f = font("Inter")

Plots.gr_set_font(f, p[1])
p
jheinen commented 1 year ago

Could you please try:

ENV["GKS_FONT_DIRS"] = joinpath(pwd(), "Documents", "inter") # Inter.ttf

using Plots
default(fontfamily="Inter")

p = plot(1:10, rand(10), title = "Title", label = "Label", xguide = "xGuide", yguide = "yGuide")
Screenshot 2023-03-10 at 07 14 42

This plot was created using a symbolic link Inter.ttf => Inter-Regular.ttf.

EldarAgalarov commented 1 year ago

Hi @jheinen Your code works!

PS. It would be nice to add support for variable fonts (all styles are packed into one file) and for OpenType fonts (.otf).