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

Aperta
#245 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

@mamicicekel ci sta già lavorando.

Dal 23/11/2026.

  • #246 di @mamicicekel — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
67/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Rust
Stelle
798
Fork
96
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di harfbuzz/ttf-parser

Tutte le issue di harfbuzz/ttf-parser

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.