Solved

true type font vertical alignment issue

Posted on 2004-08-06
5
344 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
ID: 11744355
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
ID: 11747147
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
ID: 11747944
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
ID: 11748830
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
ID: 11789108
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Mydac connection data base issue 3 135
Delphi XE10, MySQL Query 4 125
drawing animated level bar based on numbers 3 85
When i run adoquery my application freezes 26 150
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
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…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

937 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

10 Experts available now in Live!

Get 1:1 Help Now