Chlumsky/msdf-atlas-gen

Bottom-alligned text for a top-left aligned display

Closed this issue · 0 comments

Hi! I am using this amazing program to generate font atlases for my game.

However, I've been struggling to get the text properly aligned.

The system expects to get 2 coordinates, the top left and bottom right positions, with the top left being the closest one to [0, 0] and the bottom right one being the one closest to [screenWidth, screenHeight]. In other words, the screen uses a Y-down coordinate system.

Do you have any tips and/or tricks on how to get it working?

So far I've mangaged to cook up the following with the hope of at least getting something working, however it doesn't feel like the base line is straight, and certain characters are heavily displaced(e.g comma)

FontCharacter meta = Meta.Characters[glyph];


Vector2 uvStart = new Vector2(meta.AtlasBounds.Left, meta.AtlasBounds.Top) / new Vector2(Meta.AtlasMetrics.Width, Meta.AtlasMetrics.Height);
Vector2 uvEnd = new Vector2(meta.AtlasBounds.Right, meta.AtlasBounds.Bottom) / new Vector2(Meta.AtlasMetrics.Width, Meta.AtlasMetrics.Height);
            
			
Vector2 screenStart = new Vector2(meta.PlaneBounds.Left, Meta.Metrics.Ascender + meta.PlaneBounds.Bottom) * size;
Vector2 screenEnd = new Vector2(meta.PlaneBounds.Right, Meta.Metrics.Ascender + meta.PlaneBounds.Top) * size;

drawCallback(uvStart, uvEnd, screenStart, screenEnd, offset);

offset.X += meta.Advance * size;