Hi,
I just wonder if the te_Height returned by TextExtent() is really the size in pixels of a text displayed on a RastPort ?
Considering I have a window of 132 pixels height with a Text whose TextExtent.te_Height is 128.
If I move my text to y = 130, it should be vertically centered, no ?
In the following test, I try to vertically center a text of 128 pixels height in a 132 pixels height window (window height returned by window->Height and by SysMon).
I use a Topaz.font with ta_YSize of 128 (but the same problem occurs with all fonts)
the text height is returned by texteDimension.te_Height from TextExtent structure
struct TextExtent texteDimension ; TextExtent(window->RPort,bufferHeure, strlen(bufferHeure),&texteDimension);
So if TextExtent.te_Height is not really the height of a displayed text, is it a way to find the height of a displayed font ?
Thank you by advance
Guillaume
I am sure that te_Height holds the right value, You just did not Move() to the right place.
The y coordinate of the text points to the base line of the font, not to the bottom of it.
The base line is the bottom of letters like a, b or c while letters like q or g draw below the base line!
RastPort->TxBaseline holds the offset of the base line you have to add to the y coordinate to get from the top to the base line.
IMHO TextExtent is a bit overkill. In most cases RastPort->TxHeight should be sufficient.
This is a small code snippet which centers a piece of text in a given window:
Thank you Thomas,
you are (again) right, I didn't thought about Baseline.
As I want only to use numeric and "/" ":", by shifting your calculation by
Move(rp, (win_w - text_w) / 2, (win_h - text_h) / 2 + rp->TxBaseline + ( (text_h - rp->TxBaseline) /2) ) ;
it works well now with Topaz.font :)
In the 2 following picture, the BaseLine is represented by the horizontal blue line
But not for all fonts, Nimbus Sans L Bold.font and Ledsitex St.font for example have to use the Baseline to be centered (even if 'q' letter is displayed below this baseline)
For them, I have to use your method untouched
Move(rp, (win_w - text_w) / 2, (win_h - text_h) / 2 + rp->TxBaseline);
Did you ever have maths at school? This is the same as (win_h - rp->TxBaseline) / 2 + rp->TxBaseline, i.e. using the base line instead of the height.
Either your first hardcopy is wrong or the font you are using is faulty.
Here is a small program which properly plots the base line for a given font into a window: http://thomas-rapp.homepage.t-online.de/examples/baseline.c
Example:
Regarding your nice comment about my school years, as I stated in my reply, I simply added something in bold to your expression to make it works for Topaz.font. For others fonts, i used yours unmodified,
So true, i didn't simplified the operation to be more clear.
My font should not be faulty, it's Topaz, but I volontary shifted the font to the bottom because I don't care about characters with descenders and I want that displayed chars are centered. Therefore the baseline is not respected.
But thx for your sample. I will take a look tomorrow.
Launching your baseline.c with
1) struct TextAttr attr = {"topaz.font",64};
2) struct TextAttr attr = {"Nimbus Sans L Bold.font",64};
Same problem than my screenshots for Topaz.font.
As I want to use only numbers chararcters and I want that there are centered, I will have to shift to bottom the Topaz Text().
BUT strangely, for Nimbus font , the numbers seems well centered even if displayed on the baseline.
Maybe the Nimbus font contains letters with signs above the top, for example Spanish or Czech. (French accents are only printed above lower-case letters AFAIK).
Maybe, thank you.