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

Bitmap fonts sometimes clip first character on left edge #422

Closed
qcapen opened this issue May 3, 2021 · 4 comments · Fixed by #423
Closed

Bitmap fonts sometimes clip first character on left edge #422

qcapen opened this issue May 3, 2021 · 4 comments · Fixed by #423
Assignees

Comments

@qcapen
Copy link
Collaborator

qcapen commented May 3, 2021

From mpf-users group

"The only problem I have found is this:
when using a bitmap font and I make the font slightly larger, for example placing a border around the font, the left side of the border gets clipped on the very first character of a string. I have intentionally increased the offsets for all of the characters so this would not happen and it works fine for all the other characters because of the offset, however, the first character of a string is still clipped, but only on the left side. I am not sure if this is an MC bug or a kivy bug, but I find nothing in MC that would do this in my very brief search. For now, I am using a "work around" of adding a leading space to all strings."

@qcapen qcapen self-assigned this May 3, 2021
@qcapen
Copy link
Collaborator Author

qcapen commented May 3, 2021

This occurs when the first character in the drawn text has a negative xoffset value in the font descriptor file. Because the drawing loop adds the xoffset to the current cursor position, a negative value in the first character is drawn outside of the label widget bounds. Positive xoffset values for the first character can also lead to clipping of the last character for the same reason.

The solution is to adjust the initial cursor/drawing position by the first character xoffset position so it is always drawn at position 0.

qcapen added a commit that referenced this issue May 3, 2021
qcapen added a commit that referenced this issue May 4, 2021
qcapen added a commit that referenced this issue May 4, 2021
@qcapen
Copy link
Collaborator Author

qcapen commented May 4, 2021

Backported fix to version 0.54.1

@qcapen
Copy link
Collaborator Author

qcapen commented May 4, 2021

Now there are some conditions where the right edge of the last character is cut off. It appears the issue is in the BitmapFont.get_extents method. The algorithm used to calculate the extents does not properly take into account the width of the last character (only the xadvance character attribute which is sometimes less than the character width).

@qcapen qcapen reopened this May 4, 2021
qcapen added a commit that referenced this issue May 5, 2021
Fix bug in bitmap font get_extents, add comments. Fixes issue #422
@qcapen
Copy link
Collaborator Author

qcapen commented May 5, 2021

The algorithm to calculate the font extents and do the drawing had some slight differences that in some conditions could cause clipping on either the right or left edge of the text widget. This is now fixed as both methods are now in sync.

@qcapen qcapen closed this as completed May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant