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
How do I reliably get the kerning information into a file? #3811
Comments
Your Metrics View image shows |
@ctrlcctrlv Sorry about that; fixed. None of the glyphs had kerning information in the file that was created. |
Sorry, your Python code is also confusing. The screenshot shows CormorantUpright-Regular, while the font tests for Your code is very…interesting, by the way… |
@ctrlcctrlv That was a quick hack because the program crashed on a particular font without first prompting me with an error, and I didn't want to wait for the program to repeat work for the fonts prior to the one that crashed. When I reran the code the program didn't crash, so I'm still confused about what happened. |
Assuming your code works, the actual FontForge call you're asking about is
and
|
I understand that but you're asking us for help, meaning we have to read and run your code, so it would benefit all of us to have as few hacks as possible, it's just etiquette. I'm not being paid to help you, I volunteer to fix FontForge bugs, and I'd like to understand the bug as quickly as possible without hitting things like |
Understood. To clarify: Why is "the font file" bolded above and show up twice? |
Because that's what I need at minimum to help you. Two font files, one with a kern that shows in the interface and in Python, and one that shows in the interface and not in Python. |
ok got it, working on that now. |
Here's a link to the three fonts used below: Screenshots of the FontForge UI showing the kerning for all three fonts: Here's the example program used to generate the output shown further down:
Here's the output from running the program:
|
OK, thanks for that. I can see what's going on. Your problem is simple, your script only understands pair positioning ( So you have two choices:
I have a lot on my plate, but (2) seems interesting to me. I'll take a glance at what would be required to implement it, and if it's simple enough, perhaps open a PR real quick for you. † It is perfectly valid for GPOS to affect vertical position, see |
Thank you for looking at this so quickly. If you end up not having time for option 2, please consider giving me some links to more information that could help me to implement option 1. I just tried searching the docs for "single positioning" and only came up with two links, both of which were kind of confusing to understand. |
I took the glance I promised. It seems like the best way to implement would be to port @NathanWailes Feel free to email me privately if you'd like me to do this for you for hire. That will of course bring it to №1 on my list. Until then, sorry, it's getting late in my country, and I might be going to another city tomorrow, so good night. I'm not sure when I'll get to this otherwise, but if @skef seems interested it might happen regardless, but of course not as fast as if you hire me 😛 I certainly don't have time to do your research for you. |
There are a number of situations where some interface to (An aside: Single positioning can be a factor but I suspect the bulk of the problem here is not processing character-class based kerning.) @NathanWailes: Suppose that instead of processing each file as it is you were to open it,
Output:
|
(Nothing with a new python interface and doc requirements is really "bite-sized". OpenType lookup processing has a lot of quirks.) |
@skef Thank you for your help. I tried implementing your solution and while it seemed to be working at first, now the saves (to the temp font) keep failing on other fonts, and the code keeps crashing at some point starting at the "Cs" (in Google's list of free fonts). The window immediately closes, so I can't see what's happening. I tried putting in a broad try/except, and that doesn't even seem to work. Any idea what might be going on, or how I could try to further debug it? To get the fonts, download Google's GitHub repo for the fonts, then do a search for every file that ends in "ttf" and move them into a new directory. Here's the code:
|
Oh, it's probably a memory leak in FontForge if I had to guess. Assuming you have spare disk space try doing load/save first, in advance of the rest of it. Since you're only processing ttf files you can do something like (the following is pseudo-code)
That way if it crashes you can just run it a few times until it gets to the end, and then run something like your older script on that directory. It could be that you'll also run into memory problems with that. Just add code to periodically save your results (maybe by pickling), and to track which files you've already processed so you can skip over them. The skipping process is unlikely to leak and you'll eventually get to the end. |
As far as failed saves go, if that's not a memory problem we would need an example. But given that you're bulk processing, perhaps you don't need every single file? |
Just so you know @skef he asked me to help him get this working via Pango (apply PangoAttrList with colors to arbitrary text) for hire, I don't know why he's still replying here. I told him:
And I also started working on this, so I really don't think continuing this conversation is fruitful. I stand by my observation that FontForge can't do what he wants anyway unless you use FontForge to implement your own text rendering engine like Harfbuzz, which just seems silly to me. |
@ctrlcctrlv Sorry, I didn't mean to waste skef's time. I just wanted to try his solution because I didn't know if you'd manage to get the Pango solution working, and then when I ran into an issue I figured my question would be quick for him to answer. |
OK I was literally working with |
@ctrlcctrlv Understood; I thought it was just a quick question. I just wanted to try his solution quickly so that if the Pango solution didn't work, I could weigh this hacky approach against your more-in-depth (more expensive?) Harfbuzz approach. I strongly prefer a non-hacky solution but I'm just a freelance programmer and it isn't easy for me to save the money to hire other freelancers for large projects. |
(This is way off topic, but fixing FontForge to support all possible fonts is way more expensive than just using Pango, I already got it mostly working) |
Just to be clear I offered that first option freely and always choose how I use my time here. As far as other arrangements go those are not my business and, accordingly, not my problem (other than a general hope that people deal well with one another). Bulk data extraction is almost always hacky -- a script runs supervised and only needs to work once. If this were needed in an ongoing processing cycle it would be a different story. |
I’m not sure what this issue is about, but Pillow already has support for complex text layout (including Latin) when Raqm integration is enabled. Refer to Pillow documentation on how to enable Raqm. |
@khaledhosny Thank you for your advice! You can find an explanation of the underlying problem here: python-pillow/Pillow#3977 ctrlcctrlv showed me (in an email) how to use Pango (code below), but if it would be easier to use Raqm, I might prefer that. Here's what I was going to go with (code from ctrlcctrlv):
That code would produce the image below: The code is really simple, which is great, but I've been running into some issues getting Pango and Cairo installed. However, ctrlcctrlv is helping me with that. In any case, I don't think I need any further help; I just wanted to thank you for your input and give more background information in case you maybe had an opinion and didn't mind sharing it. |
The problem, as I see it, is that:
|
Right, I don’t think Pillow supports this. Very few applications/libraries do actually, Pango stands out here. |
I am working off the code found here to try to extract kerning information from TTF fonts using fontforge.
I'm running the program against Google's entire set of free fonts.
Sometimes it works, sometimes it doesn't:
What was extracted:
What the FontForge UI shows:
How can I reliably get that "Kern" number that shows up in the UI, except in text form, so that I can reference it in a Python program?
Here's the code I'm using:
The text was updated successfully, but these errors were encountered: