Skip to content

Calculate the total line height of a text#1068

Merged
pspeed42 merged 2 commits into
jMonkeyEngine:masterfrom
rvandoosselaer:fix-letters-totalheight-calculation
Apr 14, 2019
Merged

Calculate the total line height of a text#1068
pspeed42 merged 2 commits into
jMonkeyEngine:masterfrom
rvandoosselaer:fix-letters-totalheight-calculation

Conversation

@rvandoosselaer
Copy link
Copy Markdown
Contributor

@rvandoosselaer rvandoosselaer commented Apr 10, 2019

This PR fixes: #363

The totalHeight was calculated using this line:

totalHeight = Math.max(totalHeight, -l.getY1());

This always resulted in totalHeight = 0. I changed the calculation to using the lineHeight of the font and multiplying it by the line count.

totalHeight = font.getLineHeight(block) * block.getLineCount();

Since the new height calculation needs the proper line count, I inversed the order of calling the methods in the update() method. First the line count is set, then the alignment is calculated.

I also added a test case with some different alignment settings: TestBitmapFontAlignment.

Screenshot-20190411-102416

…e the total line height from the font line height and total line count. Include a test case with alignment examples. fixes: #363
@tlf30
Copy link
Copy Markdown
Contributor

tlf30 commented Apr 11, 2019

Thank you for the fix!
The code looks good to me but I did not test it, thoughts anyone?

@pspeed42 pspeed42 merged commit 0ccf3b9 into jMonkeyEngine:master Apr 14, 2019
@pspeed42
Copy link
Copy Markdown
Contributor

It looks like you might be only the second person in the world that has made a change to BitmapText classes without breaking something else. I mean, time will tell, I guess. :) Looks good to me, though (and I'm the only other person whose done it... and I did it by failing 5-10 times before that.)

@stephengold stephengold mentioned this pull request Apr 15, 2019
4 tasks
@rvandoosselaer rvandoosselaer deleted the fix-letters-totalheight-calculation branch April 23, 2019 09:21
@stephengold stephengold added this to the v3.2.4 milestone Jul 8, 2019
@stephengold
Copy link
Copy Markdown
Member

Re-target to v3.3.0 due to the risk of breaking existing applications.

@stephengold stephengold modified the milestones: v3.2.4, v3.3.0 Jul 9, 2019
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

Successfully merging this pull request may close these issues.

BitmapFont positions text incorrectly when VAlign is set to "Center" or "Bottom"

4 participants