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.
When I layout this unicode sequence using cosmic-text
, it's not handled properly:
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.
I'm going to replace tabs with spaces, see #248