Font magic
swift font ftxdumperfuser descender Estimated reading time: 3 minutesMaking a good app requires that all components was done properly and look and feel natively. Every button, every message should be perfectly aligned and configured.
But sometimes the problem waits for u in the most unexpected places.
Recently I have faced with custom font problem - the font is not properly aligned vertically. I’m talking about a font, that was used for Arabic localization and has the name FFShamelFamily
.
The reason of issue was that Descender
property of the font was incorrectly configured. And this results into next:
Font
To fix this problem we can try to use some dark magic regarding every element that can show text, aka:
This is a naive and error-prone approach that should be skipped at the very beginning.
The better way to do this - is to dive a bit into fonts, and understood how it works and which components it has.
As always, 1 image worce a 1000 words. In this case I found at some post this:
Now, even without deep dive into font anatomy, we can see the problem-making part of the issue - descender.
The good question here is how we can modify this descender. Reading a bit more about the font and how do they create and managed, I found that there is a special table, that can control a lot of font parameters. The name for this table - hhea
(Horizontal Header Table)
The hhea
table
If we check Apple’s post about it available here, we can find that The ‘hhea’ table contains information needed to layout fonts whose characters are written horizontally, that is, either left to right or right to left. This table contains information that is general to the font as a whole. The information which pertains to specific glyphs is given in the ‘hmtx’ table.
There are a lot of params that we can use to modify the font:
There are a lot of other components in fonts, to know all about which required a separate book at least. But for us, this information is enough and we can move forward.
Font modification
The next step - we should find a way how we can modify the font. Luckily for us, Apple prepared a set of tools, that can be used for such modification and is available here.
U can check this link to find out the latest font tools available. The good thing is that this package contains a lot of the tutorials and information needed for working with a font.
In our case, the problem can be solved with ftxdumperfuser
that can modify font attributes.
First - we should read attributes:
in my case:
This produce additional file FFShamelFamily-SemiRoundBold.hhea.xml
:
With content:
Here we can easily found the trouble-maker:
We can change this value (in my case to -500) and pack it back to font, using a similar command:
Result:
pitfalls
On prev os version OS fonts packadge failed during installation:
There is a great step-by-step guide available here if u faced with a similar problem
Alternatively, u can use various font-editing tools like FontForge if u find this way not appropriate for u. Another alternative is Glyphs. Example described here.
Resources
Share on: