php / php/php-src

Implement font lookup in ext/gd

未关闭
#17,852 4 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Extension: gd Feature Status: Needs Triage
主要语言
C
星标
40.4k
派生
8.2k
平均合并
2 天 13 小时
30 天内合并 PR
96

描述

Description

As is, libgd supports a somewhat complex font lookup for gdImageStringFT() (and friends). You can actually pass a semicolon delimeted list of fonts, and each font can be an absolute or relative path to a font file, or a suffix to any of the default font paths, which are hard-coded for different platforms, but which also can be overridden via the environment variable GDFONTPATH. As is, we pass the $font_file argument of imagettftext() and friends directly to gdImageStringFT(), so libgd does all the heavy work to actually find the desired font.

However, this does not (necessarily) work for ZTS builds when relative paths are given, since external libgd is not aware of the VCWD (while bundled libgd is) (see #17366). In addition, changing a global enviroment variable doesn't fit well to our ZTS model (see https://github.com/php/php-src/pull/16565#issuecomment-2665494265). And there are also some minor issues with the libgd implementation (e.g. https://github.com/libgd/libgd/issues/952).

In my opinion, the font lookup in libgd should have better been split from the actual drawing functions, what would have allowed us to implement our own font lookup in the first place, properly catering to VCWD and what not (e.g. fontconfig support, which is implemented in libgd, but not supported from ext/gd). Now this is moot, but I still suggest to implement our own font lookup in ext/gd (basically re-implementing what libgd does), and then to pass only a single absolute font path to gdImageStringFT(). This would allow to compensate the current incompatibilites between external and bundled font lookup (partially paving the way to unbundle libgd), and would also allow us to make further improvements (especially fontconfig comes to mind), with having to deal with the somewhat messy way that is implemented in external libgd (see gdImageStringFTEx()) (bundled libgd doesn't even support that).

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 ext/gd 中与字体相关的入口点开始,尤其是 imagettftext() 及其相关函数,并将它们当前移交给 gdImageStringFT() 的方式与 libgd 的 gdImageStringFTEx() 查找行为进行比较。完成的标准是在 ext/gd 中实现字体查找,在考虑 VCWD 的情况下处理所述的路径和环境场景,并将单个绝对字体路径传递给 gdImageStringFT()。

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

评估

技术栈
c, php
领域
computer-graphics
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
冷清
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

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