GPOS PairPosFormat1: device/VariationIndex offsets in PairValueRecords are resolved from the wrong base, so they are always dropped

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

@mamicicekel 已经在做这个了。

开始于 2026年11月23日。

  • #246 来自 @mamicicekel —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
67/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
backend

调研方向

Start with PairSet::parse and PairSet::get in src/tables/gpos.rs, then compare how ValueRecordsArray in SinglePos retains data for device offsets. Keep the PairSet's full data available when parsing ValueRecords while using the records slice for binary search. Done when the reproduction returns a VariationIndex device and the variation delta affects the pair adjustment.

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

描述

In PairPosFormat1, a PairValueRecord's ValueRecord device offsets
are always lost: ValueRecord::x_advance_device (and the other three
device fields) come back None. In a variable font, every glyph-pair
kerning value with a variation delta is then read at its default value.

The OpenType spec (GPOS, Shared formats → Value record) says each
device offset is "from beginning of the immediate parent table
(SinglePos or PairPosFormat2 lookup subtable, PairSet table within a
PairPosFormat1 lookup subtable)".

PairSet::parse (src/tables/gpos.rs) keeps only the records' bytes
(s.read_bytes(count * record_len), after pairValueCount), and
PairSet::get passes those bytes to ValueRecord::parse as the table
data. A device offset is therefore resolved from 2 bytes past the
PairSet's start, inside a slice that ends with the records. A device
table placed after the records (where font compilers put it) is outside
that slice, so Device::parse gets nothing and the field is None.
PairPosFormat2 and SinglePos pass their subtable's data and are not
affected.

Reproduction. A font with one PairPosFormat1 pair (a, b): x advance
−30, plus a VariationIndex device (0, 0) whose delta is +30 at wght 900.
Font (fontTools):

# make_fonts.py, attached; excerpt
f = build("kerning-device", "languagesystem DFLT dflt; feature kern { pos a b -30; } kern;", var=True)
var_gdef(f, 30)   # GDEF 1.3, ItemVariationStore entry (0, 0) = +30 at wght max
st = f["GPOS"].table.LookupList.Lookup[0].SubTable[0]   # Format 1
st.ValueFormat1 |= 0x0040
st.PairSet[0].PairValueRecord[0].Value1.XAdvDevice = buildVarDevTable(0)
// ttf-parser = "=0.25.1"
use ttf_parser::gpos::{PairAdjustment, PositioningSubtable};
use ttf_parser::{Face, Tag};

let data = std::fs::read("kerning-device.ttf").unwrap();
let mut face = Face::parse(&data, 0).unwrap();
face.set_variation(Tag::from_bytes(b"wght"), 900.0).unwrap();
let (a, b) = (face.glyph_index('a').unwrap(), face.glyph_index('b').unwrap());
let st = face.tables().gpos.unwrap().lookups.get(0).unwrap().subtables.get::<PositioningSubtable>(0).unwrap();
let PositioningSubtable::Pair(PairAdjustment::Format1 { coverage, sets }) = st else { panic!() };
let (v1, _) = sets.get(coverage.get(a).unwrap()).unwrap().get(b).unwrap();
println!("{} {}", v1.x_advance, v1.x_advance_device.is_some());
println!("{:?}", face.tables().gdef.unwrap().glyph_variation_delta(0, 0, face.variation_coordinates()));

Output (0.25.1, and main at 0c7291223):

-30 false
Some(30.0)

Expected: x_advance_device is Some(Device::Variation { outer_index: 0, inner_index: 0 }), so the pair kerns −30 + 30 = 0 at wght 900.
HarfBuzz (uharfbuzz 0.57) shapes "ab" in this font with advances [570, 600] at wght 400 and [600, 600] at wght 900.

Fix: keep the PairSet's full data (from its start) for resolving
device offsets, separate from the records slice used for the binary
search, as ValueRecordsArray does for SinglePos.

Found while using ttf-parser 0.25.1 (font: Fredoka's variable font,
whose glyph-pair kerning goes to zero at its condensed width; ttf-parser
kept −30).

The fontTools excerpt above builds the font (GitHub doesn't accept .ttf attachments); happy to share the full script and font.

主要语言
Rust
星标
798
派生
96
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

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

harfbuzz/ttf-parser 的其他 Issue

查看 harfbuzz/ttf-parser 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

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