I am trying to get the padding pixel perfect to the baseline and top of the capital letters in a font (in this case Google Roboto). This means that if i want 100px padding, I need to subtract the amount of "built-in padding" that the font has.
I was able to open the font in glyphs trial version and get some useful numbers, however the numbers that give the best results are far from intuitive, and I'd like to know how it really works.
Here is an image of the codepen where i am exploring:
Text is 100px and desired padding is 100px (to the edges of the E) Left block is with line-height: 1em Middle is with line-height:1.4em Right is an image showing the calculation method using info from glyphs
The red background shows the size of the paragraph element. The blue background around the dash "-" is because it is selected - also indicates an interesting size, which most closely matches the apparent size of the whole "art-board" when opened in glyphs.
I found out that if I calculate the distance between the midline guide and the top and bottom of the letter, then i can calculate how much space there is above and below the letter and then divide by 2048 (the number of units the font indicates for 1 em).
.div1 {
padding-top: calc( 1em - 0.132em );
padding-left: calc( 1em - 0.081em );
padding-bottom: calc( 1em - 0.157em );
padding-right: calc( 1em - 0.081em );
}
The results seem solid, but is it really needed to dive into such detail to get the numbers??
Isn't there a way to calculate this in css or js?