yeslogic / allsorts

Font parser, shaping engine, and subsetter implemented in Rust
https://yeslogic.com/blog/allsorts-rust-font-shaping-engine/
Apache License 2.0
706 stars 23 forks source link

Mark-to-mark glyph positioning incorrect #107

Closed wezm closed 1 month ago

wezm commented 1 month ago

Some marks in the Arabic text "ٱللَّهَ" are not positioned correctly.

Issue

The last glyph colored in "Blue" should be positioned similar to its corresponding glyph in the word below.

This is the layout details for the last glyph

"glyph_index": 104
"kerning": 0

// Layout Info.
"hori_advance": 0
"vert_advance": 0
"x_offset": 640
"y_offset": 1600

// Placement
"MarkAnchor": [
        3,
        {
          "x": 135,
          "y": 250
        },
        {
          "x": 225,
          "y": 0
        }
    ]
}

This is the **computed** x position for each glyph — 5 glyphs
[-438, -2184, -1429, -1454, -1544] // negative for RTL
fn( i ) => -( hor_advance_sum( i ) - x_offset[ i ])

The hori_advance for each glyph from allsorts
[438, 1746, 0, 0, 0]

The x_offset for each glyph from allsorts
[0, 0, 755, 730, 640]

// Render Settings font_size: 72 dpi: 96 upm: 2048 font: uthmanic_hafs_v20.ttf

I will attach the data collected from allsorts in the next comment. Looking forward to hearing from you.

Originally posted by @solomancode in https://github.com/yeslogic/allsorts/discussions/106

solomancode commented 1 month ago

If anyone has an idea how to fix this issue, I'd be glad to help. Thank you.

wezm commented 1 month ago

If anyone has an idea how to fix this issue, I'd be glad to help. Thank you.

I have a fix, it's just working its way through internal review.

solomancode commented 1 month ago

@wezm That's great. Thanks for your efforts, Please let me know if I could be of any help.

wezm commented 1 month ago

This is the fix https://github.com/yeslogic/allsorts/commit/1bf2db89673d28e3cfc781a64ddf7cfbf3c5d416

I'll work on a patch release now

wezm commented 1 month ago

0.14.2 has been published.

solomancode commented 1 month ago

Thank you.

It's impressive your deep knowledge of opentype specs. even though the resources are scarce. This fix was — Combining Ligature Marks. Am I correct ?

solomancode commented 1 month ago

image 😊

wezm commented 1 month ago

It's impressive your deep knowledge of opentype specs. even though the resources are scarce.

Unfortunately the OpenType specs are lacking specification for this type of thing so it mostly comes down to receiving bug reports like yours and then trying to work out what should be happening.

This fix was — Combining Ligature Marks. Am I correct ?

The fix for your specific issue was when performing mark-to-mark positioning to consider the ligature component position and only perform mark-to-mark positioning when the marks are on the same ligature component. However, applying this in isolation broke a Vietnamese test we had where one of the marks was itself a ligature so I mirrored what Harfbuzz does and allowed mark-to-mark positioning across ligature components in the case where one of the marks is a ligature.

solomancode commented 1 month ago

@wezm Thanks again for your efforts.

wezm commented 1 month ago

No worries, thanks for the clear bug report.