Solved

true type font vertical alignment issue

Posted on 2004-08-06
5
351 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 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
make top menus bigger font 3 76
SUM 2 INTEGER ARRAYS INTO 1 10 108
Dynamically Created Query 3 62
firemonkey keyboard covers the controls 1 37
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

837 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