Solved

true type font vertical alignment issue

Posted on 2004-08-06
5
341 Views
Last Modified: 2013-12-03
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]

0
Comment
Question by:hibbidiji
  • 3
  • 2
5 Comments
 
LVL 33

Accepted Solution

by:
Slick812 earned 500 total points
Comment Utility
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
0
 
LVL 1

Author Comment

by:hibbidiji
Comment Utility
I tried this (kinda) and it is BETTER...  I have a label I'm  working with called lblimage.   so I'm trying:

frmimage.image1.lblimage.canvas.textheight('HELLO');

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?
0
 
LVL 33

Expert Comment

by:Slick812
Comment Utility
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
0
 
LVL 1

Author Comment

by:hibbidiji
Comment Utility
The solution is unclear in the end, but this answer helped make the problem a lot less noticable and annoying.    
0
 
LVL 1

Author Comment

by:hibbidiji
Comment Utility
UPDATE:
procedure TForm1.Button1Click(Sender: TObject);
var TMet: TTextMetric;



...

  GetTextMetrics(Canvas.Handle,TMet);
ACTUALheight:= frmimage.lblimage.height - TMet.tmDescent;


end



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

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now