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

Font size scaling #2

Open
ItMightBeKaraoke opened this issue May 13, 2024 · 0 comments
Open

Font size scaling #2

ItMightBeKaraoke opened this issue May 13, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@ItMightBeKaraoke
Copy link
Owner

KBP font sizes are based on cap height (possibly capital X specifically?). That means, if you request font size 12, your capital X will be 12 characters high. Depending on font, some symbols could be substantially larger or smaller, and it makes layout difficult.

ASS font sizes are based on the total height of the font, e.g. the full block character, if it exists in the font face, will have that height. This way it's easier to prevent collisions and such, but the fact that it's different from KBS causes issues.

Current code is scaling the KBP font size by 1.4x, which works well for Arial and fonts with similar metrics, but it can cause issues with weird fonts. Messing around with freetype, I think I can calculate the appropriate scaling factor as follows (example with Arial 12 Bold):

>>>> import freetype
>>> face = freetype.Face('/usr/share/fonts/truetype/arialbd.ttf')
>>> face.load_char('X')
>>> 12 * 2048 / face.glyph.metrics.height
16.763983628922237 # Lines up great with 1.4*kbp_size=16.8

But hopefully there's a way to do this at a higher level than freetype because just locating all the font files by name would be difficult.

@ItMightBeKaraoke ItMightBeKaraoke added the enhancement New feature or request label May 13, 2024
@ItMightBeKaraoke ItMightBeKaraoke self-assigned this May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant