Font problem

It seems that the Cambria Math font has recently acquired an extremely large 
Ascent and Descent. Has it perhaps always been that way and I've never 
noticed it before, or is it something recent, perhaps a Vista thing? Try the 
following code for example. For Arial and Times New Roman (and virtually all 
other fonts) I am getting pretty much exactly what I would expect (a 
TextHeight that is a bit larger than the point size) but for Cambria Math I 
am getting an extremely large TextHeight (I get exactly the same results 
using GDI32 methods). At this end (on my Vista Business laptop and my Vista 
Home Premium desktop which both run at the standard 96 dpi) I get 15.75/18 
for Arial and 15.75/17.25 for Times New Roman, which both seem okay, but I 
get 15.75/87.75 for Cambria Math, which seems extraordinary.

Mike

Private Sub Command1_Click()
ScaleMode = vbPoints
Caption = "All sizes are in Points " & _
  "(point size first followed by TextHeight)"
Font.Name = "Arial"
Font.Size = 16
Print Font.Name; Font.Size; TextHeight("x")
Print "Seems okay"
Font.Name = "Cambria Math"
Font.Size = 16
Print Font.Name; Font.Size; TextHeight("x")
Print "Very odd?"
Font.Name = "Times New Roman"
Font.Size = 16
Print Font.Name; Font.Size; TextHeight("x")
Print "Seems okay"
End Sub




0
Mike
3/28/2010 8:44:35 AM
vb.general.discussion 1016 articles. 0 followers. Follow

11 Replies
2552 Views

Similar Articles

[PageSpeed] 11

"Mike Williams" <Mike@WhiskyAndCoke.com> wrote in message 
news:OIiWmLlzKHA.3884@TK2MSFTNGP06.phx.gbl...
> It seems that the Cambria Math font has recently acquired an extremely 
> large Ascent and Descent. Has it perhaps always been that way and I've 
> never noticed it before, or is it something recent, perhaps a Vista thing? 
> Try the following code for example. For Arial and Times New Roman (and 
> virtually all other fonts) I am getting pretty much exactly what I would 
> expect (a TextHeight that is a bit larger than the point size) but for 
> Cambria Math I am getting an extremely large TextHeight (I get exactly the 
> same results using GDI32 methods). At this end (on my Vista Business 
> laptop and my Vista Home Premium desktop which both run at the standard 96 
> dpi) I get 15.75/18 for Arial and 15.75/17.25 for Times New Roman, which 
> both seem okay, but I get 15.75/87.75 for Cambria Math, which seems 
> extraordinary.

I got the exact same number here in XP+SP2. I am using VB6+SP5 with SP6 
runtime.


0
Nobody
3/28/2010 9:27:04 AM
"Nobody" <nobody@nobody.com> schrieb im Newsbeitrag 
news:Oa22WjlzKHA.1796@TK2MSFTNGP02.phx.gbl...
> "Mike Williams" <Mike@WhiskyAndCoke.com> wrote in message 
> news:OIiWmLlzKHA.3884@TK2MSFTNGP06.phx.gbl...
>> It seems that the Cambria Math font has recently acquired an extremely large 
>> Ascent and Descent. Has it perhaps always been that way and I've never 
>> noticed it before, or is it something recent, perhaps a Vista thing? Try the 
>> following code for example. For Arial and Times New Roman (and virtually all 
>> other fonts) I am getting pretty much exactly what I would expect (a 
>> TextHeight that is a bit larger than the point size) but for Cambria Math I 
>> am getting an extremely large TextHeight (I get exactly the same results 
>> using GDI32 methods). At this end (on my Vista Business laptop and my Vista 
>> Home Premium desktop which both run at the standard 96 dpi) I get 15.75/18 
>> for Arial and 15.75/17.25 for Times New Roman, which both seem okay, but I 
>> get 15.75/87.75 for Cambria Math, which seems extraordinary.
>
> I got the exact same number here in XP+SP2. I am using VB6+SP5 with SP6 
> runtime.
>
>



Hmmm,

I just went to Control Panel / Fonts on my Vista Home Premium 32-bit system
and clicked on 'Cambria & Cambria Math'. It's a True Type Collection.
It displays Cambria as usual, but when you switch to Cambria Math it shows
this font with extremely space between the lines. My guess is there are
mathematical symbols in this font which need this height. They didn't bother
with Italic, Bold or Bold Italic versions of Cambria Math.

Helmut.



0
Helmut
3/28/2010 11:13:51 AM
"Helmut Meukel" <NoSpam@NoProvider.de> wrote in message news:%

> I just went to Control Panel / Fonts on my Vista Home Premium
> 32-bit system and clicked on 'Cambria & Cambria Math' . . . It
> displays Cambria as usual, but when you switch to Cambria Math
> it shows this font with extremely space between the lines.

It's probably always been like that, and I haven't noticed before. I never 
actually use that font and I only noticed it because I was writing a little 
utility for somebody and I came across it in the process.

> They didn't bother with Italic, Bold or Bold Italic versions
> of Cambria Math.

No, they didn't produce a special italic or bold fontface for it, although 
you can of course get simulated bold and/or italic in the normal way that 
you can get them for any other font that does not have its own specially 
designed italic or bold font face, simply by specifying bold or italic in 
the usual way.

> My guess is there are mathematical symbols in this font which
> need this height.

You're probably right there, although I did have a quick look through lots 
of the characters using Unicode view in CharacterMap and I couldn't find 
any. Even the special math characters that you might expect would be large 
in relation to the other characters were not so huge as to occupy anywhere 
near the full available character cell height . . but hey, what I know about 
math or math fonts can be written on the back of a postage stamp, so that 
doesn't mean very much ;-)

Mike



0
Mike
3/28/2010 12:49:17 PM
I've noticed this for Symath.

Except from that, the textheight in VB is always the same.

*************************************************************************************
sample
*************************************************************************************
Private Sub Form_Load()

  Form1.ScaleMode = vbPixels

End Sub
Private Sub Form_Paint()

  Form1.Font.Name = "Times New Roman"
  Form1.Font.Size = 24

  Form1.Print Form1.Font.Name
  Form1.Print Form1.Font.Name
  Form1.Print Form1.Font.Size
  Form1.Print "x"
  Form1.Print Form1.TextWidth("x") & " " & Form1.TextHeight("x")
  Form1.Print "X"
  Form1.Print Form1.TextWidth("X") & " " & Form1.TextHeight("X")
  Form1.Print "h"
  Form1.Print Form1.TextWidth("h") & " " & Form1.TextHeight("h")
  Form1.Print "gh"
  Form1.Print Form1.TextWidth("gh") & " " & Form1.TextHeight("gh")

End Sub

Output:

Times New Roman
24
15 36
23 36
15 36
30 36

Width and height measured in paint (pixels):

x 15 14
X 22 21
h 15 22
gh 29 29

Distance bottom of line to bottom of next line:

36 pixels

*************************************************************************************
end sample
*************************************************************************************
0
sven2000
3/28/2010 2:08:42 PM
"sven2000" <sven2000@gmail.com> wrote in message 
news:483a013e-4cac-42e8-b592-77c3e11f7898@k13g2000yqe.googlegroups.com...

> I've noticed this for Symath.
> Except from that, the textheight in VB is always the same.
>  Form1.Print "x"
>  Form1.Print Form1.TextWidth("x") & " " & Form1.TextHeight("x")
>  Form1.Print "X"
>  Form1.Print Form1.TextWidth("X") & " " & Form1.TextHeight("X")

The TextHeight of a font of any specific size and type is the sum of its 
Ascent and Descent (or the overall height of a character cell or the 
distance from the top of one line of text to the top of the next line in a 
normally printed block of text if you prefer to look at it in either of 
those ways). It is the same for all characters in the font, so the character 
"x" and the character"X" and the character "." all have the same TextHeight 
(except that the VB TextHeight function, as opposed to the GDI32 
GettextExtentPoint32 function, assumes that any string containing a line 
feed or a carriage consists of two or more printed lines and so VB 
TextHeight returns two or three or more times the normal value for any 
string containing either of those characters). So, the characters "X" and 
"x" and "." all have the same TextHeight. It is their TextWidths that are 
different (in a proportionaly spaced font, which most fonts are). If you 
instead want to get the height of the actual "drawn part" of a specific 
character, and its placement within the character cell (which of course is 
different for different characters) then you can use the GetGlyphOutline 
function, although that is not necessary for most jobs. Regarding the Ascent 
and Descent and various other things and how they relate to the overall 
TextHeight here is some code that produces a more graphical explanation of 
it (paste it into a VB Form):

Mike

Option Explicit
Private Declare Function GetTextMetrics Lib "gdi32" _
  Alias "GetTextMetricsA" (ByVal hdc As Long, _
  lpMetrics As TEXTMETRIC) As Long
Private Type TEXTMETRIC
  tmHeight As Long
  tmAscent As Long
  tmDescent As Long
  tmInternalLeading As Long
  tmExternalLeading As Long
  tmAveCharWidth As Long
  tmMaxCharWidth As Long
  tmWeight As Long
  tmOverhang As Long
  tmDigitizedAspectX As Long
  tmDigitizedAspectY As Long
  tmFirstChar As Byte
  tmLastChar As Byte
  tmDefaultChar As Byte
  tmBreakChar As Byte
  tmItalic As Byte
  tmUnderlined As Byte
  tmStruckOut As Byte
  tmPitchAndFamily As Byte
  tmCharSet As Byte
End Type
Private Const DEFAULT_QUALITY As Byte = 0
Private Const DRAFT_QUALITY As Byte = 1
Private Const NONANTIALIASED_QUALITY As Byte = 3
Private Const ANTIALIASED_QUALITY As Byte = 4
Private Const CLEARTYPE_COMPAT_QUALITY As Byte = 5
Private Const CLEARTYPE_QUALITY As Byte = 6

Private Sub Form_Load()
' A graphical representation of the various
' Font details (by Mike Williams).
Dim fName As String, fSize As Single
Dim sampleText As String
fName = "Times New Roman"
fSize = 72
sampleText = "MjtplqdgfH0123"
Dim mymetrics As TEXTMETRIC, savey As Single
Dim InternalLeading As Single
Dim Ascent As Single
Dim Descent As Single
Dim ExternalLeading As Single
Dim txtHeight As Single
Me.AutoRedraw = True
Me.Show
Me.BackColor = vbWhite
Me.Width = Me.ScaleX(7.6, vbInches, vbTwips)
Me.Height = Me.ScaleY(5.7, vbInches, vbTwips)
Me.Line (0, 0)-(Me.ScaleWidth, Me.ScaleHeight), _
  RGB(200, 100, 255), BF
Me.ScaleMode = vbPoints
Me.Font.Name = fName
Me.Font.Size = fSize ' 72 points = 1 inch
Me.Font.Italic = False
Me.Font.Bold = False
txtHeight = Me.TextHeight("some text")
GetTextMetrics Me.hdc, mymetrics
InternalLeading = Me.ScaleY(mymetrics.tmInternalLeading, _
                                 vbPixels, Me.ScaleMode)
Ascent = Me.ScaleY(mymetrics.tmAscent, _
               vbPixels, Me.ScaleMode)
Descent = Me.ScaleY(mymetrics.tmDescent, _
               vbPixels, Me.ScaleMode)
ExternalLeading = Me.ScaleY(mymetrics.tmExternalLeading, _
                                 vbPixels, Me.ScaleMode)
Me.CurrentX = 0: Me.CurrentY = 0
Me.FontTransparent = True
Me.Print sampleText
Me.FontTransparent = False
Me.Print sampleText
savey = Me.CurrentY
Me.Line (0, InternalLeading)- _
  (Me.ScaleWidth, InternalLeading), vbYellow
Me.Line (0, Ascent)- _
  (Me.ScaleWidth, Ascent), vbGreen
Me.Line (0, Ascent + Descent)- _
  (Me.ScaleWidth, Ascent + Descent), vbBlue
If mymetrics.tmExternalLeading > 0 Then
  Me.Line (0, Ascent + Descent + ExternalLeading)- _
  (Me.ScaleWidth, Ascent + Descent + ExternalLeading), vbRed
End If
' Capital letters (A - Z) and numbers (0 - 9)in most fonts
' start a little after the External Leading and extend down
' to the Ascent line, and the centre of those characters is
' usually about 0.48 of the overall "TextHeight" down from
' the top of the character cell. The following code will
' therefore draw a line approximately through the centre
' of these characters on most (but  not all) fonts.
Me.Line (0, txtHeight * 0.48)- _
  (Me.ScaleWidth, txtHeight * 0.48), vbWhite
Me.CurrentX = 0
Me.CurrentY = savey
Me.Font.Name = "Arial"
Me.Font.Size = 8
Me.Print " The example text is " & fName & " " _
         & Format(fSize, "0.0") & " points"
Me.Print " Internal Leading = " & InternalLeading & " points"
Me.Print " Ascent = " & Ascent & " points"
Me.Print " Descent = " & Descent & " points"
Me.Print " External Leading = " & ExternalLeading & " points"
Me.Print " Total Height (Ascent + Descent) = " _
         & Ascent + Descent & " points"
Me.Print " VB TextHeight returns " & txtHeight & " points"
Me.Print " The point size is the Ascent plus the Descent";
Me.Print " minus the Internal Leading = ";
Me.Print Ascent + Descent - InternalLeading
Me.FontTransparent = True
Me.Print
Me.Print " Internal Leading is from the top down to the";
Me.Print " yellow line."
Me.Print " Ascent is from the top down to the green line";
Me.Print " (called the Baseline)";
Me.Print " and it includes the Internal Leading."
Me.Print " Descent is from the green line down to the blue";
Me.Print " line."
Me.Print " The overall height is equal to Ascent plus";
Me.Print " Descent and is equal to the VB TextHeight."
Me.Print " The point size is from the yellow line down to";
Me.Print " the blue line and is equal to Ascent plus Descent";
Me.Print " minus Internal Leading."
If mymetrics.tmExternalLeading > 0 Then
  Me.Print " The External Leading is from the blue line to";
  Me.Print " the red line and is ignored."
Else
  Me.Print " This font has zero external leading."
End If
Me.Print " The white line is typically 0.48 of the TextHeight";
Me.Print " down from the top and runs approximately through the ";
Me.Print " centre of capital letters and numerals."
Me.Print " NOTE: If you use a negative value (normal practice)";
Me.Print " for the desired font size when using the ";
Me.Print " CreateFontIndirect API the system will attempt"
Me.Print " to give you a font where the distance from the yellow";
Me.Print " line to the blue line is equal to the requested value. ";
Me.Print " If you use a positive value the"
Me.Print " system will attempt to give you a font where the overall";
Me.Print " height is equal to the requested value. In both cases";
Me.Print " however all of the above elements "
Me.Print " will be present. (Using a positive value is effectively ";
Me.Print " the same as asking for a slightly smaller font.)"
End Sub




0
Mike
3/28/2010 4:45:03 PM
"Mike Williams" <Mike@WhiskyAndCoke.com> wrote in message 
news:OIiWmLlzKHA.3884@TK2MSFTNGP06.phx.gbl...

> It seems that the Cambria Math font has recently acquired an extremely 
> large Ascent and Descent. Has it perhaps always been that way and I've 
> never noticed it before, or is it something recent, perhaps a Vista thing?

I wrote an owner-draw combo box in...well, let's just say "another 
language"...to draw each font name in its own font and I ran into exactly 
the same thing you're seeing. XP SP2. 


0
Jeff
3/29/2010 8:52:59 PM
Thanks Mike, that's very helpful.

Two questions, though. As it says the ascent includes the internal
leading. This is not true normally in font metrics, right? And there's
a white center line, but there's no x-height?
0
sven2000
4/7/2010 8:56:09 PM
"sven2000" <sven2000@gmail.com> wrote in message 
news:72a6c676-4657-4ac3-912e-6249b344f500@30g2000yqi.googlegroups.com...

> Thanks Mike, that's very helpful.
> Two questions, though. As it says the ascent includes the
> internal leading. This is not true normally in font metrics,
> right?

In the TextMetric structure the tmAscent is from the base line to the top 
and the tmDescent is from the base line to the bottom. The total of these 
two is the tmHeight, which is the total height and which is the same as 
would, for example, be returned by the VB TextHeight function. The 
tmInternalLeading is measured from the top and is contained within the 
overall Height (usually quite small and almost always entirely within the 
Ascent portion). In most fonts that I've seen it usually extends down to 
just above the top edge of the capital letters.

    http://msdn.microsoft.com/en-us/library/dd145132(VS.85).aspx

> And there's a white center line, but there's no x-height?

The TEXTMETRIC structure (used by the GetTextMetrics function) does not 
include an entry for the x-height. There is an x-height entry in the more 
detailed OUTLINETEXTMETRIC structure (as used by the GetOutlineTextMetric 
function) but according to the MS docs the x-height entry is not supported. 
If you want to get an idea of the x-height then you could use the 
GetGlyphOutline function which can tell you the size and position within the 
cell of the "black box" that exactly fits over the shape of the glyph of any 
character you pass to it. However, having said that, I think that there are 
some fonts where, as odd as it seems, the character "x" is not actually the 
same height as the x-height of the font.

I'm pretty sure that GDI+ can tell you the x-height of most fonts, and also 
other things such as the CapsHeight etc, but I don't "do" GDI+ so I can't 
help you on that one.

Mike


0
Mike
4/7/2010 11:35:22 PM
"sven2000" <sven2000@gmail.com> wrote in message 
news:72a6c676-4657-4ac3-912e-6249b344f500@30g2000yqi.googlegroups.com...

> Thanks Mike, that's very helpful.
> Two questions, though. As it says the ascent includes
> the internal leading. This is not true normally in font
> metrics, right?

Further to my previous reponse to this question, I've just realised what you 
actually meant by it.

In my previous response I assumed that you were asking me to confirm, or 
that you were querying, what I had said in my earlier messages regarding 
GDI32, and so when I answered it I reaffirmed that the Internal Leading as 
far as the GDI GetTextMetrics function is concerned is included in the 
Ascent and actually forms a part of it, which is in fact the case as is 
shown in the example code I had earlier posted which gives a graphical 
repesentation of the information returned by the GDI32 GetTextMetrics 
function.

However, I've just realised that you had actually accepted that point but 
that you were saying the inclusion of the Internal Leading within the Ascent 
is not normally the practise generally in font metrics, rather than 
specifically in Windows GDI. In that case you are of course correct because 
(as far as I know) most systems other than Windows GDI which deal with fonts 
do no treat them in that manner, and the various "leadings" are /not/ 
considered to be part of either the Ascent or the Descent of a font, which 
makes sense of course because the "leadings" actually were lumps of lead 
back in the old days, although in recent years people seem to be moving away 
from the "leading" term and using other names for it.

Certainly the people at Apple do not see any Leading as being part of the 
Ascent, and neither do most people, I would suspect. So, you're right in 
that respect, and Windows (at least Windows GDI32) is the "odd one out" (and 
it would appear that GDI+ and .Nxt are "the odd one out" as well, as 
mentioned below. It seems to be a general "MS Windows" thing).

Whether Micro$oft intended it that way, or whether it was just something 
which came about purely because of the fact that no one person is really in 
charge of anything at Micro$oft, is anybody's guess! It's not always easy to 
find really detailed information about stuff like that on MSDN, and when you 
do find it you often find that one piece of information entirely contradicts 
another, even on the same page! Micro$oft have never been any good at 
writing help files or documentation in a way that is really helpful, and 
they are often either so incomplete, or sometimes so "overly complete" in 
some respects and "incomplete" in other respects, that they are worse than 
useless!

I've just had a look for some information on MSDN to see what I can find 
regarding Ascent and Descent and Leading etc (and how it is seen by 
Micro$oft) and to see whether it has changed since GDI32, but (as usual) I 
came away more confused than I was when I went there! The reason, as usual, 
is that the MSDN page I found contains conflicting information!

    http://msdn.microsoft.com/en-us/library/ms533824(v=VS.85).aspx

Like most Micro$oft things these days, it deals with GDI+ rather thanGDI32 
(although that of course is specifically what I was looking for) and the 
examples are in .Nxt so I cannot (or rather I am not prepared to!) try them 
for myself.

If you look at the nice little drawings at the top of the page (the drawings 
of the letter Q) you will see quite clearly that /in the drawings/ the 
Ascent and Descent together form the font size, and they do /not/ inlcude 
any form of leading (either internal or external). So, judging solely by the 
labelled drawings it looks as though Micro$oft have had a change of heart 
and have moved to comply with Apple and most other people in this respect . 
..

.. . However, if you look at the output from the Micro$oft example .Nxt code 
on the very same page (which uses GDI+ stuff and the output of which is 
shown below the code) you will see a different story. Font sizes are 
normally expressed in pixels (rather than points) in .Nxt and also GDI+ 
allows floating point values when dealing with them, so there are some 
differences but it is easy to account for them. In the example they have 
used a 16 pixel Arial font and the output shows the font size as being 16.00 
pixels, the Ascent as being 14.48 pixels and the Descent as being 3.39 
pixels. So, the total of the values returned for the Ascent and Descent is 
18.19 pixels, 2.19 pixels greater than the font size, and between them they 
clearly include the "leading" (totally contrary to the labelled drawing of 
the letter Q at the top of the page!). In fact, if you do a bit of peddling 
around in VB6 using very large font sizes to compensate for the fact that we 
cannot use floating point values with GDI32 font stuff you will see that for 
the Arial font the typical Internal Leading is 0.12 times the font size 
(when both are expressed in the same units). So, for a typical 16.00 pixel 
Arial font we would expect the Internal Leading to be 1.92 pixels, giving a 
total of 17.92 pixels. Therefore, the total of Ascent and Descent returned 
by the .Nxt GDI+ code (18.19 pixels) clearly includes /all/ of the expected 
value for Internal Leading. In fact it might even include the External 
Leading as well, which is a much smaller amount and which is ignored in VB6 
and GDI32.

Naturally you need to make allowances for the differences between the two 
systems and for the fact that the font stuff in GDI+ uses floating point 
values whereas GDI32 does not, but it is quite clear that the drawing at the 
top of that MSDN page shows that the Internal Leading (or any other kind of 
leading) is NOT included in the Ascent and Descent, whereas the actual .Nxt 
code on the very same MSDN page and the GDI+ results it returns clearly 
shows quite the opposite!

Typical Micro$oft stuff, that ;-)

Here (below) is a "rough and ready" modification of the code I posted 
previously which I have changed to use pixels throughout instead of points 
and which displays the VB6 (GDI32) details of a 160 pixel Arial font. You 
should be able to compare the output of it with the output of the GDI+ 16 
pixel Arial font .Nxt code shown on the MSDN page and you'll see what I mean 
(the outputs of the code below should of course be divided by 10 in your 
head to make the comparison . . I've avoided doing the "divide by ten" in 
code so as to make it obvious that it is pulling in the correct results). 
Whoever made and labelled the drawings of the font characters on that MSDN 
page clearly knows what the Ascent and Descent of a font SHOULD be, but he 
then appears to have totally ignored the output of the code he included on 
the same MSDN page, which clearly shows that Windows thinks quite the 
opposite!

Mike

Option Explicit
Private Declare Function GetTextMetrics Lib "gdi32" _
  Alias "GetTextMetricsA" (ByVal hdc As Long, _
  lpMetrics As TEXTMETRIC) As Long
Private Type TEXTMETRIC
  tmHeight As Long
  tmAscent As Long
  tmDescent As Long
  tmInternalLeading As Long
  tmExternalLeading As Long
  tmAveCharWidth As Long
  tmMaxCharWidth As Long
  tmWeight As Long
  tmOverhang As Long
  tmDigitizedAspectX As Long
  tmDigitizedAspectY As Long
  tmFirstChar As Byte
  tmLastChar As Byte
  tmDefaultChar As Byte
  tmBreakChar As Byte
  tmItalic As Byte
  tmUnderlined As Byte
  tmStruckOut As Byte
  tmPitchAndFamily As Byte
  tmCharSet As Byte
End Type
Private Const DEFAULT_QUALITY As Byte = 0
Private Const DRAFT_QUALITY As Byte = 1
Private Const NONANTIALIASED_QUALITY As Byte = 3
Private Const ANTIALIASED_QUALITY As Byte = 4
Private Const CLEARTYPE_COMPAT_QUALITY As Byte = 5
Private Const CLEARTYPE_QUALITY As Byte = 6

Private Sub Form_Load()
' A graphical representation of the various
' Font details (by Mike Williams).
Dim fName As String, pixelSize As Single, y As Single
Dim sampleText As String
fName = "Arial"
Me.ScaleMode = vbPixels
Me.Font.Name = fName
' set font size to 160 pixels (not points)
pixelSize = 160
' set point size so as to achieve a 160 pixel font
Me.Font.Size = Me.ScaleY(pixelSize, vbPixels, vbPoints)
Me.Font.Italic = False
Me.Font.Bold = False
sampleText = "QtjM"
Dim mymetrics As TEXTMETRIC, savey As Single
Dim InternalLeading As Single
Dim Ascent As Single
Dim Descent As Single
Dim ExternalLeading As Single
Dim txtHeight As Single
Me.AutoRedraw = True
Me.Show
Me.BackColor = vbWhite
Me.Width = Me.ScaleX(900, vbPixels, vbTwips)
Me.Height = Me.ScaleY(680, vbPixels, vbTwips)
Me.Line (0, 0)-(Me.ScaleWidth, Me.ScaleHeight), _
  RGB(200, 100, 255), BF
txtHeight = Me.TextHeight("some text")
GetTextMetrics Me.hdc, mymetrics
InternalLeading = mymetrics.tmInternalLeading
Ascent = mymetrics.tmAscent
Descent = mymetrics.tmDescent
ExternalLeading = mymetrics.tmExternalLeading
Me.CurrentX = 0: Me.CurrentY = 0
Me.FontTransparent = True
Me.Print sampleText;
y = Me.TextHeight("x")
Me.Font.Name = "Times New Roman"
Me.Print "  " & sampleText;
Me.CurrentY = Me.CurrentY + y
Me.CurrentX = 0
Me.Font.Name = "Arial"
Me.FontTransparent = False
Me.Print sampleText;
Me.Font.Name = "Times New Roman"
Me.Print "  " & sampleText;
Me.CurrentY = Me.CurrentY + y
savey = Me.CurrentY
Me.Line (0, InternalLeading)- _
  (Me.ScaleWidth, InternalLeading), vbYellow
Me.Line (0, Ascent)- _
  (Me.ScaleWidth, Ascent), vbGreen
Me.Line (0, Ascent + Descent)- _
  (Me.ScaleWidth, Ascent + Descent), vbBlue
If mymetrics.tmExternalLeading > 0 Then
  Me.Line (0, Ascent + Descent + ExternalLeading)- _
  (Me.ScaleWidth, Ascent + Descent + ExternalLeading), vbRed
End If
' Capital letters (A - Z) and numbers (0 - 9)in most fonts
' start a little after the External Leading and extend down
' to the Ascent line, and the centre of those characters is
' usually about 0.48 of the overall "TextHeight" down from
' the top of the character cell. The following code will
' therefore draw a line approximately through the centre
' of these characters on most (but  not all) fonts.
Me.Line (0, txtHeight * 0.48)- _
  (Me.ScaleWidth, txtHeight * 0.48), vbWhite
Me.CurrentX = 0
Me.CurrentY = savey
Me.Font.Name = "Arial"
Me.Font.Size = 8
Me.Print " The following details are for Arial " _
         & Format(pixelSize) & " pixels (The Times New Roman is also 
displayed purely so you can compare the Q glyph)"
Me.Print " Internal Leading = " & InternalLeading & " pixels"
Me.Print " Ascent = " & Ascent & " pixels"
Me.Print " Descent = " & Descent & " pixels"
Me.Print " External Leading = " & ExternalLeading & " pixels"
Me.Print " Total Height (Ascent + Descent) = " _
         & Ascent + Descent & " pixels"
Me.Print " VB TextHeight returns " & txtHeight & " pixels"
Me.Print " The font size is the Ascent plus the Descent";
Me.Print " minus the Internal Leading = ";
Me.Print Ascent + Descent - InternalLeading & " pixels"
Me.FontTransparent = True
Me.Print
Me.Print " Internal Leading is from the top down to the";
Me.Print " yellow line."
Me.Print " Ascent is from the top down to the green line";
Me.Print " (called the Baseline)";
Me.Print " and it includes the Internal Leading."
Me.Print " Descent is from the green line down to the blue";
Me.Print " line."
Me.Print " The overall height is equal to Ascent plus";
Me.Print " Descent and is equal to the VB TextHeight."
Me.Print " The point size is from the yellow line down to";
Me.Print " the blue line and is equal to Ascent plus Descent";
Me.Print " minus Internal Leading."
If mymetrics.tmExternalLeading > 0 Then
  Me.Print " The External Leading is from the blue line to";
  Me.Print " the red line and is ignored."
Else
  Me.Print " This font has zero external leading."
End If
Me.Print " The white line is typically 0.48 of the TextHeight";
Me.Print " down from the top and runs approximately through the ";
Me.Print " centre of capital letters and numerals."
Me.Print " NOTE: If you use a negative value (normal practice)";
Me.Print " for the desired font size when using the ";
Me.Print " CreateFontIndirect API the system will attempt"
Me.Print " to give you a font where the distance from the yellow";
Me.Print " line to the blue line is equal to the requested value. ";
Me.Print " If you use a positive value the"
Me.Print " system will attempt to give you a font where the overall";
Me.Print " height is equal to the requested value. In both cases";
Me.Print " however all of the above elements "
Me.Print " will be present. (Using a positive value is effectively ";
Me.Print " the same as asking for a slightly smaller font.)"
End Sub



0
Mike
4/9/2010 3:46:53 PM
"sven2000" <sven2000@gmail.com> wrote in message 
news:72a6c676-4657-4ac3-912e-6249b344f500@30g2000yqi.googlegroups.com...

> As it says the ascent includes the internal
> leading . . .

Actually, looking at what I just posted I seemsto have got one of the 
numbers just slightly wrong (had so many different windows open here!). 
Regarding the details on the MSDN page I was talking about I said . .

> In the example they have used a 16 pixel Arial font and the output
> shows the font size as being 16.00 pixels, the Ascent as being 14.48
> pixels and the Descent as being 3.39 pixels. So, the total of the
> values returned for the Ascent and Descent is 18.19 pixels . .

The sum of 14.48 and 3.39 for the GDI+ (.Nxt) code on that page is of course 
17.87 (don't know where I got that 18.19 from!) and that 17.87 is pretty 
much exactly the same as the total of the Ascent and Descent as would be 
returned by our VB (GDI32) code after allowing for the fact that we cannot 
use floating point values (because a ten times larger GDI32 font returns 178 
pixels for the sum of Ascent and Descent). So, that shows even more clearly 
that Micro$oft are still including the Internal Leading as part of the 
Ascent and Descent in GDI+ and .Nxt, just as they do in GDI32, and that they 
are still apparently "the odd one out" in the font business. The only real 
difference is the fact that the GDI+ (.Nxt) code on the MSDN page also shows 
a figure of 18.40 pixels for the total "line spacing" (the distance between 
one line of text and the next). That is a difference of 0.53 pixels from the 
17.87 sum of Ascent and descent (which includes the Internal Leading) and it 
is certainly more than just coincidence (if you check the output from the 
VB6 code I posted or if you write your own) that 0.53 pixels is pretty much 
exactly what you would expect for the "External Leading" (as opposed to the 
"Internal Leading") of a 12 pixel Arial font.

So, clearly Microsoft /do/ still include the Internal Leading in the Ascent 
and Descent (and still continue to do so in GDI+ and .Nxt) and the only 
difference is that in GDI+ and .Nxt they also include the relatively small 
External Leading value in the total line spacing (something which VB6 and 
GDI32 does not do).

So, after all that "waffle" in all these messages, the answers to your 
supplementary question are:

    Yes, Micro$oft /do/ include the Internal Leading within the Ascent in 
GDI32, and . .

    Yes, they apparently continue to do so in GDI+ and .Nxt, and . .

    Yes, they are unusual in that respect ;-)

Mike





0
Mike
4/9/2010 4:57:40 PM
Hi Mike, Thanks for the elaborate replies.I've been looking into it a
bit and I found it to confusing. I decided to just print the glyph on
the form and use the point method to scan the glyph for all relevant
metrics and store them in a table.

0
sven2000
4/30/2010 3:32:21 PM
Reply:

Similar Artilces:

Change default font format in Excel
I have an existing workbook with cell text entries in regular black font. I want to make a number of additional entries in various cells in this workbook, and I want all my text entries to be a different font format (bold, red). Is there a way to do this automatically without highlighting each entry I make and manually changing the cell format? Thanks. Michael, Copy the code below, right-click on your sheet tab, select "View Code" and paste the code in the window that appears. HTH, Bernie MS Excel MVP Private Sub Worksheet_Change(ByVal Target As Range) If Target.Cells.Cou...

Re: Update for Windows Vista (KB980248) -- No more fonts available!
cf. http://social.answers.microsoft.com/Forums/en-US/vistawu/thread/f7fa37ca-683c-4be1-b4ad-ab2dd1249399 PA Bear [MS MVP] wrote: > Are you running Vista SP1 or Vista SP2? Is Office 2010 installed? > > Was KB980248 offered & eventually installed via Windows Update or did you > (attempt to) install it manually? > > What anti-virus application or security suite is installed and is your > subscription current? What anti-spyware applications (other than > Defender)? > What third-party firewall (if any)? > > Has a(another) Norton or McAfee ap...

Smart List problem
I recently re-installed a client (version 9.0). Everything went fine but when we tried to open Smartlist on this client we got an error message telling us that “To use Smartlist capability in this product the Smartlist tables must be built. This is one time initialization process and may take a few minutes”. I answered yes, it ran and then returned the following error “number of columns does not match table definitions”. Every other machine is working fine, is the tables it is talking about building on the client? It does not seem like that should be so. It does not matter ...

Problem with systemstate backup with DPM 2010
Hi! We running DPM 2010RC on a Windows 2008 R2 The Protected computer is: Microsoft(R) Windows(R) Server 2003, Standard Edition 5.2.3790 Service Pack 2 Build 3790 When we installed the DPM agent the first backup of system state was successfully, so we have one restore point. But further backups in failing, the system state backup is in status “replica is inconsistent” and when I running a consistent check the job failing. In the error in DPM is: The replica of System Protection Computer\System Protection on sea0700smon1.xxxx.local is inconsistent with the protected data so...

Questiontest-outlookwebservices problem
hi all and thanks for the support. i'm facing a problem with test.outlookwebservices. notice that oulook side everything seems to be pretty good: the autodiscovery and auto-configuration of the account succeedes, the test email autoconfiguration suceedes too. when i launch the test, once it suceedes for certain services and after a while it fails for those services and suceedes for other. look the prints: here are failing the RPC tests Message : [EXCH] The UM is configured for this user in the AutoDiscover response received from https://mytest-EXC1. myt...

Problem when switching datasource
Help please :) I have created an excel report, that retrieves its data from a view. From that data i have created several sheets with different pivottables. The view is based per country, so each country has to connect to their own view. So I use the same file and change the datasource. It looks fine when i have updated. BUT when I use the dropdown on a field, the old values from the last data are still visible, however they dont show anything if you choose them. For example France has sales men a +b and Sweden c+d. when switching datasource from france to sweden, only c+d should be visible i...

Fewer normal template problems with Word 2000 or 2002?
I have enjoyed some things about Word 2007, but I keep having problems with macros and templates. I am wondering if (a) macros increase the likelihood of corrupting the normal template in 2007, or (b) if the older versions of Word had as many template problems. I have used Word in 2000, with Office 2003, and now with Office 2007 and I don't ever recall having as many problems as I've had with 2007. What I'm thinking is that if it is simply a macro problem causing corruption, I would simply use 2007 without the macros (they're nice but I can live without them). On the...

Font problem
It seems that the Cambria Math font has recently acquired an extremely large Ascent and Descent. Has it perhaps always been that way and I've never noticed it before, or is it something recent, perhaps a Vista thing? Try the following code for example. For Arial and Times New Roman (and virtually all other fonts) I am getting pretty much exactly what I would expect (a TextHeight that is a bit larger than the point size) but for Cambria Math I am getting an extremely large TextHeight (I get exactly the same results using GDI32 methods). At this end (on my Vista Business laptop...

08 Mac Office activation problems
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Just found an article posted by michellec and I am faced with exactly the same problem - on 'activation' of the product, none of the 3 product keys seem to be correct, hence activation is unsuccessful!! Have received some help emails (and thanks Diana yours had the microsoft help number that has been good, despite the fact they can't help me and tell me I must get in touch with Digital River) but seems that what I need is another product key, and now that I'm asking for that since about 10 days, I don't get any reply ...

Problems with loading xml from XmlTextWriter
I use an XmlTextWriter to generate xml data. The declaration is: System.Text.StringBuilder sb = new System.Text.StringBuilder(); System.IO.StringWriter sw = new System.IO.StringWriter(sb); XmlTextWriter w = new XmlTextWriter(sw); And I write to it using .... w.WriteElementString("foo","bar"); When the creation is done, I need to load it into DOM to select an XmlNode or an XmlElement to apply to another method (which I cannot control). I thought I could do it with: XmlDocument xDoc = new XmlDocument(); xDoc.Load(sb.ToString()); XmlNode node = xDoc.SelectSingleNode(&...

Problem access variable in On Format
Hi, I'm using Access via Office XP Pro. I am trying to format the Zip Code on the detail line of my report. I have tried the following lines of code in both the On Format event and the On Print event: If len([PostalCode]) > 5 Then : : end if or if len(Me.PostalCode) > 5 Then : : end if In both events and either code, I receive the error message: Access can't find the field 'PostalCode' referred to in your expression. If I put "PostalCode" as the source of the report's control...

Autoshapes' visible problem
When I add some Rectangle autoshapes above the embeded chart, I find it's hard to control it's visibility, They maybe hide when I select some cell or activate chart. I want to know how to make them always visible no matter what I select. Thank you in advance! ^_^ Yours,fujing You need to click on the chart before you use the drawing tool. In this way the Shape and the Chart become one. best wishes -- Bernard V Liengme www.stfx.ca/people/bliengme remove caps from email "fujing1003" <fujing1003@gmail.com> wrote in message news:1171358292.074278.135950@v33g2000cwv...

Problem inserting delta symbol into Excel
Dear Group, Hello. I recently posted a question related to the issue of putting a mu (=B5) symbol into MS Excel charts. Someone kindly suggested using the Alt-numeric code (alt-0181) to place this symbol into the spreadsheet cell which then showed up nicely in the chart. However, when I try to do this same operation using alt+ NumPad 68 (susposed to give the delta symbol), all I get is a capital D. What gives? Why does one symbol work and not the other? I even downloaded the program QuickKeys from SourceForge.net and this still did not solve the problem. Any ideas?? Thank you....

Office 2004 SP 11.1.0 installation problems
I'm trying to update Office 2004 on my brand new iBook. I installed Office 2004 from the CD without incident. Then I downloaded SP 11.1.1.0 and 11.1.0 (which according to the MS website is to be installed 1st.) When I try to install, I received a message, "An error prevented the update from completing 11002:2,-14" The "Read Me" file indicates several potential explainatins/solutions none of whice are relevant except for uninstalling Office and then reinstalling it. I tried dragging the Office folder to the trash and reinstalled and am having the same problem. I've t...

RMS and/or PC Charge Problems
We are having some interesting problems with our RMS system and PC Charge: For no apparent reason RMS will have an error message after a card is swiped or keyed into the system: • DENIED (With a wide variety of error messages) • DUPLICATE use F+ to force (even when it is the first transaction) • TIMED OUT Attempted solutions: • Turned modem off and on • Disconnected the modem and plugged everything back in • Turned the server on/off • Called PC Charge only to be told that it is RMS • RMS said it is PC Charge • Confirmed that everything is set up properly in PC Charge and RMS What works:...

Excel deleting xml item problem
I have an excel macro (in an add-in) that is called by the main excel macro that is deleting various items in an xml file When it gets to the last line as below it generates the following message “An unhandled error occurred: Object variable or with block not set” the variable is dimensioned see Dim statement that I have copied here. This has worked for some time with no problem but suddenly out of the blue generates this error. I have tried replacing the xml file with a copy, also tried replacing the add-in with a copy (in case either have been corrupted). The error desc...

Other problem with recent update that locks you out without product key
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel I can't get into my Office anymore either until I locate my product key, but I'm also finding that I'm getting a sound stutter when I watch movies online with Netflix. This wasn't happening before the download and I don't get the stutter when I switch to Windows operating system. Is anyone else having this trouble and have you been able to fix it? Thanks. Hey !! I can't get into my Office anymore either until I locate my product key because on my mac, download updates come through automatically. ...

Dialog based problem in vc6
Hi, I am writing an mfc project in vs6 and I have a problem! When I add radio button to my dialog based application and run the application and press that button my application hang, even when I try to run it in the test mode inside visual studio and press that radio button it stack the all environment why?? It append only if I add a radio button for a regular button its all ok! I install sp-6 but it didn't solve the problem. Thanks "Dave" <dbg@012.net.il> wrote in message news:eq14GyguEHA.3872@TK2MSFTNGP11.phx.gbl... > Hi, > > I am writing an mfc project in ...

Problem with Outlook error message
Hi everyone - I just started having problems in Outlook 2003 after uninstalling Mozilla Firefox broswer. Every time I try to open a URL in an Outlook message I get the following error message: "This operation has been cancelled due to restirctions in effect on this computer. Please contact your system administrator." Any way to get rid of this? I've already changed all *.htm and *.html associations to IE. Thanks for your help!!! scripteez wrote: > Hi everyone - > > I just started having problems in Outlook 2003 after uninstalling > Mozilla Firefox broswer. Every...

Outlook 2003 Signature Problem
I've created a signature with my company logo (.jpg file) using Outlook 2003. When the signature is attached in my email, the photo/icon file shows a box with an 'x' in place of the .jpg file. I checked the location where the files are stored and I found the .jpg file in the proper folder under signatures. Thanks in advance for your help. Mike Tools - options -security tab, click on change automatic download settings. Change to what you want. "Mikeul" <Mikeul@hotmail.com> wrote in message news:1132112656.7e1c9b39fdb73a3c7ed44fdbd3e3fbc4@fe5.teranews.com......

Problem in restricting users from sending/receving internet email
I have found a helpful articel here: http://www.msexchange.org/tutorials/MF009.html I read it through couple times but I would like to ask some questions before I start the work on our Exchange 2000 server. 1. The "group" I am going to create for adding users into the restricting list, will it be a Security group or Distribution group? What group scope should I give it? 2. Under the section of "Restricting Users from Sending Internet Base Email", the article tells us to create a *new* SMTP connector and add the group into the "Dilivery Restriction" page. Will ...

Best FOnts?
I'm tired of the Arial font that is commonly used for Excel Spreadsheets. What other fonts are recommended for printed output? I like Times New Roman for big headings AvantGarde and Courier good for the others -- _______________________ Naz, London "Kurchian" wrote: > I'm tired of the Arial font that is commonly used for Excel Spreadsheets. > > What other fonts are recommended for printed output? Verdana for clarity, Comic Sans MS for levity. -- HTH RP (remove nothere from the email address if mailing direct) "Kurchian" <Kurchian@disc...

Hyperlink Problem #6
Hi all, Maybe someone can help me with a hyperlink problem we have. We have an index spreadsheet with links to all our main documents etc. These documents can be Pdfs, gifs Jpegs etc. I would have expected that when you click on the hyperlink the document would open with the program associated with the file type. On my particular box, the image file ( gif, jpeg) open in internet explorer although the association to the file should use irfranview, on other machine the file opens in Irfranview. I am not understanding why the file should open in different programs although the file associa...

Outlook Draft Email Print Problem
I have emails saved in draft but when i go to print them it doesnt show who it is being sent to and the fact it hasnt been sent yet, i have played with the setting but to no avail. I am using outlook 2003 any help would be appriciated. Turn off WordMail before printing the draft (Tools | Options | Mail Format) or wait to print until after you send it. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx <kpmail76@yahoo.co.uk> wrote in message news:...

Create or change font in font scheme in Publisher 2003
How do I create or change a font in a font scheme in Publisher 2003? I can duplicate a font scheme but have not figured out how to change any of the fonts in the scheme. Legvidal <Legvidal@discussions.microsoft.com> was very recently heard to utter: > How do I create or change a font in a font scheme in Publisher 2003? > I can duplicate a font scheme but have not figured out how to change > any of the fonts in the scheme. http://www.publishermvps.com/Default.aspx?tabid=77 -- Ed Bennett - MVP Microsoft Publisher "Ed Bennett" wrote: > Legvidal <Legvida...