sciapp / gr

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

feature request: add Fira Math to the fontlist #148

Closed xzackli closed 2 years ago

xzackli commented 2 years ago

I totally understand if GR is supposed to be a lean plotting package with a fixed font list, in which case please close this issue.

Could Fira Math be added to the fontlist? Fira Sans is a particularly clear font, and this variant has strong Unicode support.

jheinen commented 2 years ago

I think we can add the Fira font family:

const texlive_dir = "/usr/local/TeX/texmf-dist/fonts/opentype/public"

const firamath_font = joinpath(texlive_dir, "firamath", "FiraMath-Regular.otf")
const fira_font_dir = joinpath(texlive_dir, "fira")

ENV["GKS_FONT_DIRS"] = string(pwd(), ":", fira_font_dir)

using GR

selntran(0)
setcharheight(0.015)
settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF)

y = 0.95
for fontname in [firamath_font; readdir(fira_font_dir)]
  global y
  font = loadfont(fontname)
  settextfontprec(font, GR.TEXT_PRECISION_OUTLINE)
  text(0.5, y, "The quick brown fox jumps over the lazy dog")
  tbx, tby = inqtext(0.5, y, "The quick brown fox jumps over the lazy dog")
  fillrect(tbx[1], tbx[2], tby[1], tby[3])
  y -= 0.03
end

updatews()
Screen Shot 2022-02-24 at 10 28 31
jheinen commented 2 years ago

Unfortunately, the FiraMath font can't be uses as a replacement for the (default) font CMUSerif-Math, because it's incomplete. Not only glyphs are missing, but also the font metrics do not match the current implementation of our formula editor (character sizes, alignment etc.). Against this background, an extension of the mathematical fonts in GR makes little sense.

The Fira fonts can of course be used for normal text output.

Screen Shot 2022-02-24 at 13 13 18
xzackli commented 2 years ago

Thank you so much for taking a look at this! I'm disappointed to hear that the math fonts won't work out, but I'm not totally surprised. I know GR does a lot of custom drawing, and math fonts seem very perilous.