better math parent font matching

This commit is contained in:
Zhanibek 2021-09-05 19:13:23 +09:00
parent 121ab8755c
commit 68f23d3955

View File

@ -178,14 +178,19 @@ py_fillstyle(::Nothing) = nothing
py_fillstyle(fillstyle::Symbol) = string(fillstyle) py_fillstyle(fillstyle::Symbol) = string(fillstyle)
function py_get_matching_math_font(parent_fontfamily) function py_get_matching_math_font(parent_fontfamily)
math_font_family = if parent_fontfamily == "sans-serif" # matplotlib supported math fonts according to
"dejavusans" # https://matplotlib.org/stable/tutorials/text/mathtext.html
elseif parent_fontfamily == "serif" py_math_supported_fonts = Dict{String, String}(
"dejavuserif" "sans-serif" => "dejavusans",
else "serif" => "dejavuserif",
parent_fontfamily "cm" => "cm",
end "stix" => "stix",
return math_font_family "stixsans" => "stixsans"
)
# Fallback to "dejavusans" or "dejavuserif" in case the parentfont is different
# from supported by matplotlib fonts
matching_font(font) = occursin("serif", lowercase(font)) ? "dejavuserif" : "dejavusans"
return get(py_math_supported_fonts, parent_fontfamily, matching_font(parent_fontfamily))
end end
# # untested... return a FontProperties object from a Plots.Font # # untested... return a FontProperties object from a Plots.Font