• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

true type font vertical alignment issue

I have text that I am placing on an image

I am allowing the user to select color, font, horizontal justification and location.

I am doing this by using a jedi tools movable bevel.

This bevel returns (of course) a top, left width and height.

I want the text to appear on the baseline of this box.

I have been doing it in this order:

1. get inputs from user
2. apply font name, size, color etc.
3. get WIDTH from label and justify appropriately

(now it gets tricky...  I'm obviously doing it WRONG but heres what i'm doing)

4. I get the HEIGHT of the label I'm working with and move it to the baseline by doing:
text.top := bevel.top + bevel.height - text.height (I have autosize turned on for the label)
I have ALSO tried to use + text.font.height (is is always a negative value...  I have never asked why)  

the first one works great with a large number of fonts like arial narrow etc.   It does NOT work with some fonts like arial black or impact.  This is unacceptable as these are two of what will be the most popular fonts to use!  

What will happen is that the bottom of the font will go below the bounding box ( the bevel ) and not rest nicely on the baseline.   Am I grabbing the wrong properties?   What am I missing???  Unfortunately this is holding up the whole project ;(

Thanks for any help you might give ;)

[edited to make last sentence make sense]

  • 3
  • 2
1 Solution
there is a   TCanvas  TextHeight method that will get to the text Height for Any Font that is the Canvas Font
Image1.Canvas.Font.Size := 20;
TextHeight := Image1.Canvas.TextHeight('M');

this TextHeight should be correct for the current font
hibbidijiAuthor Commented:
I tried this (kinda) and it is BETTER...  I have a label I'm  working with called lblimage.   so I'm trying:


It does a better job than my previous effort, though still a little off...    in this case, most fonts tend to float justa BIT above the baseline.    I am almost satisfied with this, but perhaps I'm missing something?
no you are not missing something, (I guess), the "TextHeight" will include some space above and below the actual text that is colored in on the canvas, this is because the is "TextHeight" is suppose to give a "Space" separator above and below the colored text written, , , as with a Line of text in a TMemo, so the lines will have some space between them, to be easy to read. . . if I was you I would see if you can get by, and let the text be a little above your baseline, but if you need a closer fit, then you can add some pixels to your baseline Y position, maybe you will need to adjust this baseline acording to the relative size of the text, , but take note, not all fonts will have the same "Rise" from the baseline as all other fonts of the same size, some "Handwritting" artistic fonts can even go below the baseline for certain characters
hibbidijiAuthor Commented:
The solution is unclear in the end, but this answer helped make the problem a lot less noticable and annoying.    
hibbidijiAuthor Commented:
procedure TForm1.Button1Click(Sender: TObject);
var TMet: TTextMetric;


ACTUALheight:= frmimage.lblimage.height - TMet.tmDescent;


THIS works like a charm. I can get the baseline of the chars to sit nicely on my bounding box now

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now