Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is the y_offset negated? #213

Open
CryZe opened this issue Jan 18, 2024 · 2 comments
Open

Why is the y_offset negated? #213

CryZe opened this issue Jan 18, 2024 · 2 comments

Comments

@CryZe
Copy link
Contributor

CryZe commented Jan 18, 2024

I've been trying to figure out why my Arabic rendering is wrong, and it turns out that the y_offset of a glyph needs to be subtracted from its y coordinate, as opposed to x_offset which always needs to be added. This fixes my code, but turns out cosmic-text does it exactly like this internally too. This is very confusing, seemingly not documented and possibly a bug (that cancels itself out internally):

(self.x + x_offset) * scale + offset.0,
libm::truncf((self.y - y_offset) * scale + offset.1), // Hinting in Y axis

One way I could explain this to myself is that the fonts use a coordinate system where Y Up points in the opposite direction. If this however is the case, then y_advance is not properly subtracted throughout the codebase, such as here:

y += y_advance;

and here:

y_advance += glyph.y_advance;

@jackpot51
Copy link
Member

Don't have a good answer other than the coordinates that were coming from fonts were flipped. If we flip it now, it would be a breaking change.

@CryZe
Copy link
Contributor Author

CryZe commented Jan 18, 2024

I'm guessing it's indeed a difference in Y Up (fonts) and Y Down (images). I'm fairly convinced a purely vertical font / script, where y_advance would be non-zero, would probably be messed up, cause there's no reason to believe that y_advance would use a different coordinate system than y_offset when they are emitted from the underlying rustybuzz right next to each other. But then again, a vertical font is probably broken in many other ways in terms of text layout anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants