Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

plot: Changing the default font for plots is unintuitive and/or not possible

未关闭
#702 9 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
go

调研方向

首先跟踪 plot.DefaultFont 以及 vg.FontDirs 和 vg.MakeFont() 周围的字体处理,然后检查 SVG 渲染器的字体映射。重现 Arial 示例,并沿着字体范围计算和 SVG 输出追踪失败原因。完成的标准是:配置的默认字体不再触发 panic,并且不支持的字体能够产生明确的结果。

由索引模型根据 Issue 内容生成。

描述

What are you trying to do?

Render a plot to SVG with a certain font as a default for title and axis

What did you do?
plot.DefaultFont = font.Font{Typeface: "Arial"}
p := plot.New()
err := plotutil.AddLinePoints(p, ...)
...
err = p.Save(4*vg.Inch, 4*vg.Inch, "plot.svg")
...
What did you expect to happen?

That all labels in the plot use the Arial font.

What actually happened?

Rending the plot panic'ed, because Font objects are used unchecked in places using Extent().

It is not clear at all, what fonts can even be used for plot.DefaultFont and that it needs to happen before calling plot.New(). Digging through the code reveals there was a built-in map, which is currently being removed.

It is possible to load a custom font such as Arial, by extending the vg.FontDirs global. In addition, the default font cache needs to be manually extended with a mapping for "Arial" to a font object loaded via vg.MakeFont().

However, this will still fail later in the SVG renderer, because it has a hard-coded mapping of typefaces to CSS style strings. This mapping cannot currently be extended. If a font is not part of this mapping, it will at least throw a proper error.

What version of Go and Gonum/plot are you using?

From go.sum, it looks like I am using v0.9.0.

Does this issue reproduce with the current master?

No idea.

主要语言
Go
星标
3k
派生
202
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

gonum/plot 的其他 Issue

查看 gonum/plot 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。