GDI - Text Bounding Box - True Type Fonts 
Author Message
 GDI - Text Bounding Box - True Type Fonts

Hi,
VBA under Microsoft Access, probably applicable to VB as well.

I am trying to get a TextBox control that does not natively support
rotated text, to use a logical font with rotation selected into the
controls Device Context(DC).

I have been able to gain access to the controls DC, which changes every
time the control gets the focus, by caching the controls HWnd, which
remains constant at runtime.

A font with rotation is created with CreateFontIndirect and selected
into the controls device context. I issue a forms Repaint and the
controls text is redrawn with the new font and the selected rotation
angle.

It works...almost.
 Two problems surface.

As an example, let's use a rotation angle of 45 degrees with a standard
Textbox control.

1) Since the control doesn't seem to recognize all of the DC
SetTextAlign flags, specifically any vertical positioning coords, the
outputted text is clipped by the top of the control. This is easy to fix
by making the control a multiline textbox/label and setting the control
source to something like:
=Chr(13)+Chr(10) & "Stephen"
This starts the text output down one line. This could be adjusted to
handle different degrees of rotation.

2) Unfortunately the Text is still clipped because Access/VBA is still
imposing the fonts standard Bounding Box rectangle, calculated at 0
degrees rotation.

After reading the True Type Spec, it seems that Windows uses two fields
to calculate a font's bounding box.
These are in the "OS/2" Table, usWinAscent and usWinDescent. The file
format is well documented and offers easy access from VB.

Does it seem feasible to increase these values to match the current
rotation value. Perhaps a copy of one of the system fonts, say Arial,
could be made. This copy could then be modified, and added to the system
at design time, so as to be available for the control.

I have the TRIG routines to calculate the bounding box of a rotated line
of text. The values generated from these routines could be used to make
sure windows bounding rectangle would not clip the rotated text in the
control.

Does anybody know if I am on the right track. I can't find the required
documentation for how the Windows GDI calculates and implements a
bounding rectangle based on the True Type Fonts metric info.

For my current VB sourcecode to create Rotated Text by using Enhanced
Metafiles go to my Web page at
http://www.*-*-*.com/ ~slebans/

Stephen Lebans



Thu, 22 Nov 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. GDI - Text Bounding Box - True Type Fonts

2. True Data Bound Grid to update text boxes

3. Creating multiple font types in a single Rich Text Box

4. Accessing special characters in True Type fonts

5. Installing True Type Fonts

6. How to install True Type Fonts In Win 3.1 with VB3

7. HOW CAN I VIEW A FONT FILE (TRUE TYPE)

8. DOS FONTS TO TRUE TYPE

9. Can't print symbol true type fonts.

10. How to view/print fonts true type?

11. Printing aligned columns with True Type fonts, how?

12. VIEW A TTF FILE (True Type Font) with VB 3/4/5

 

 
Powered by phpBB® Forum Software