pop-os / cosmic-text

Pure Rust multi-line text handling

Home Page:https://pop-os.github.io/cosmic-text/cosmic_text/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tabs not handled properly

nichoj10 opened this issue · comments

The unicode character for tabulation is laid out as an unknown glyph through cosmic-text.

When I layout this unicode sequence using core-text, I get the correct rendering characteristics because core-text returns the properly spaced glyphs.
Screenshot 2024-05-24 at 5 46 05 PM

When I layout this unicode sequence using cosmic-text, it's not handled properly:
Screenshot 2024-05-24 at 5 49 18 PM

I've inspected the output of text layout to isolate this to cosmic-text. In core-text, the output of laying out "Z\tZ" is:

Run {
            font_id: FontId(
                2,
            ),
            glyphs: [
                Glyph {
                    id: 114,
                    position_along_baseline: Vector2F(
                        F32x2(
                            [
                                0.0,
                                0.0,
                            ],
                        ),
                    ),
                    index: 0,
                },
                Glyph {
                    id: 3,
                    position_along_baseline: Vector2F(
                        F32x2(
                            [
                                7.82666,
                                0.0,
                            ],
                        ),
                    ),
                    index: 1,
                },
                Glyph {
                    id: 114,
                    position_along_baseline: Vector2F(
                        F32x2(
                            [
                                28.0,
                                0.0,
                            ],
                        ),
                    ),
                    index: 2,
                },
            ],
}

Notice that the glyph with id 3 is used to represent the whitespace from the tab. In cosmic-text, the tab is returned as a glyph with id 0, indicating that it's unknown:

Run {
            font_id: FontId(
                2,
            ),
            glyphs: [
                Glyph {
                    id: 114,
                    position_along_baseline: Vector2F(
                        F32x2(
                            [
                                0.0,
                                0.0,
                            ],
                        ),
                    ),
                    index: 0,
                },
                Glyph {
                    id: 0,
                    position_along_baseline: Vector2F(
                        F32x2(
                            [
                                7.82666,
                                0.0,
                            ],
                        ),
                    ),
                    index: 1,
                },
                Glyph {
                    id: 114,
                    position_along_baseline: Vector2F(
                        F32x2(
                            [
                                15.65332,
                                0.0,
                            ],
                        ),
                    ),
                    index: 2,
                },
            ],
}

Any thoughts about this?

Thank you for putting up a fix! One thing I wanna call out is that the spacing now looks correct but cosmic-text still lays out the '\t' as an unknown glyph (id = 0). This is confusing because an unknown glyph should render as a replacement character. Before the fix, cosmic-text laid out "Z\tZ" as something akin to this:

Glyph { id: 114, position_along_baseline: Vector2F(F32x2([0.0, 0.0])), index: 0 }, 
Glyph { id: 0, position_along_baseline: Vector2F(F32x2([7.82666, 0.0])), index: 1 }, 
Glyph { id: 114, position_along_baseline: Vector2F(F32x2([15.65332, 0.0])), index: 2 }

After the fix, cosmic-text lays out "Z\tZ" as:

Glyph { id: 114, position_along_baseline: Vector2F(F32x2([0.0, 0.0])), index: 0 }, 
Glyph { id: 0, position_along_baseline: Vector2F(F32x2([7.82666, 0.0])), index: 1 }, 
Glyph { id: 114, position_along_baseline: Vector2F(F32x2([31.30664, 0.0])), index: 2 }

The point is that the horizontal spacing is accounted for, but the glyph id 0 still communicates there's an unknown character in there.

@jackpot51

I'm going to replace tabs with spaces, see #248