Solved

true type font vertical alignment issue

Posted on 2004-08-06
5
352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 34

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 34

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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