It is currently September 29th, 2024, 1:25 pm

Vertial text centering behaves weird

General topics related to Rainmeter.
User avatar
Active Colors
Moderator
Posts: 1316
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany

Vertial text centering behaves weird

Post by Active Colors »

I have several text meters which have exactly identical specifications (except one which is heighter a bit). They go one after another vertically relatively to each other.
Capture2.PNG
Capture.PNG
Everything looks perfect but weird text centering. I will place zoomed pic to see what I mean
ddds.PNG
On the left is "Change Icon" text meter, on the right "Rename" text meter. As you can see both have same height but one of the texts is shifted. Concluding from situation the "Rename" text meter is shifted because all three text meters "Choose File", "Choose Folder" and "Change Icon" have the same centering.

Why do they have different vertical centering?
You do not have the required permissions to view the files attached to this post.
Last edited by Active Colors on June 17th, 2014, 10:17 am, edited 1 time in total.
User avatar
VasTex
Posts: 407
Joined: September 20th, 2012, 3:17 pm
Location: USA - Montana

Re: Vertial text centering behaves weird

Post by VasTex »

I'm fairly certain that it has to do with the differences in height of the letters themselves.

For example, the word "Change" is 9 pixels tall. The smaller letters (a, n & e) have a height of 5 pixels, but both the 'C' and 'h' extend the height by 2 pixels. In addition to that the 'g' extends the height downward by 2 pixels. What you end up with is a total height of 9 pixels for the word 'Change'. However, when you look at the word 'Rename' you have again 5 pixels for the smaller letters (e, n, a & m) and an additional 2 pixels added to the top from 'R', but you don't have any letters extending downward. This gives you a total height of 7 pixels for the word 'Rename'.

To recap:
If you divided the word 'Change' in half you would find it has a center at its 5th pixel with 4 pixels extending both above and below the center giving it a total height of 9 pixels.
If you divided the word 'Rename' in half you would find it has a center at its 4th pixel with 3 pixels extending both above and below the center giving it a total height of 7 pixels.

So let's say that the height of these string meters is set to 25 pixels. We can figure out how much spacing both above and below the words there will be by using this equation:

((Round Up ((Meter Height - 1) / 2)) - (Round Up ((Word Height - 1) / 2)))
*We subtract 1 to account for the center pixel which neither the top nor bottom get to use and then divide it by 2 to find the heights of the Top and Bottom. Finally, we round up to nearest whole pixel since you can't occupy half of a pixel and then we simply find the difference of the two heights.

In this scenario we have a Meter Height of 25 pixels and Word Heights of 9 and 7 pixels. If we work out the equations for both the word 'Change' and 'Rename' we get the following:

[Change]:
[Step 1]: ((Round Up ((25 - 1) / 2)) - (Round Up ((9 - 1) / 2)))
[Step 2]: (Round Up (24 / 2)) - (Round Up (8 / 2))
[Step 3]: (Round Up (12)) - (Round Up (4))
[Step 4]: (12) - (4)
[Step 5]: (8) Pixels of empty space between the center of the word 'Change' and the top and bottom if its meter height.

[Rename]:
[Step 1]: ((Round Up ((25 - 1) / 2)) - (Round Up ((7 - 1) / 2)))
[Step 2]: (Round Up (24 / 2)) - (Round Up (6 / 2))
[Step 3]: (Round Up (12)) - (Round Up (3))
[Step 4]: (12) - (3)
[Step 5]: (9) Pixels of empty space between the center of the word 'Rename' and the top and bottom if its meter height.

*Notice that there is a 1 pixel difference between the spacing for the words 'Change' and 'Rename'. This difference is due to their differing centers and explains the 1 pixel difference you see if your pictures.

Hopefully I explained that fairly well... It makes sense to me at least!
01010100 01100101 01100011 01101000 01101110 01101111 01101100 01101111 01100111 01101001
01100011 01100001 01101100 00100000 01000010 01100001 01100100 01100001 01110011 01110011
User avatar
Active Colors
Moderator
Posts: 1316
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany

Re: Vertial text centering behaves weird

Post by Active Colors »

You are totally correct, VasTex. Thanks for the fluent explanations :thumbup: