Font Size


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Font Size

  1. #1
    J Justin Guest

    Font Size

    In my vb app, I need to show the user, the list of available font size for
    each font.
    I have been told to use EnumFontFamily api to retrieve it. Of course, it
    allowed me to get
    the list of available system fonts, and its LOGFONT structure contains lot
    of other elements,
    but none for size. Could anybody throw some torch?

    Thanks in advance


    J Justin




  2. #2
    Michael \(michka\) Kaplan Guest

    Re: Font Size

    Size is certainly in there.... what do you think lfHeight (and occasionally
    though usually not lfWidth) is there for?

    --
    MichKa

    random junk of dubious value at the multilingual
    http://www.trigeminal.com/ and a new book on
    i18N in VB at http://www.trigeminal.com/michka.asp

    "J Justin" <precious@md3.vsnl.net.in> wrote in message
    news:3972c675@news.devx.com...
    > In my vb app, I need to show the user, the list of available font size for
    > each font.
    > I have been told to use EnumFontFamily api to retrieve it. Of course, it
    > allowed me to get
    > the list of available system fonts, and its LOGFONT structure contains lot
    > of other elements,
    > but none for size. Could anybody throw some torch?
    >
    > Thanks in advance
    >
    >
    > J Justin
    >
    >
    >




  3. #3
    Michael \(michka\) Kaplan Guest

    Re: Font Size

    Size is certainly in there.... what do you think lfHeight (and occasionally
    though usually not lfWidth) is there for?

    --
    MichKa

    random junk of dubious value at the multilingual
    http://www.trigeminal.com/ and a new book on
    i18N in VB at http://www.trigeminal.com/michka.asp

    "J Justin" <precious@md3.vsnl.net.in> wrote in message
    news:3972c675@news.devx.com...
    > In my vb app, I need to show the user, the list of available font size for
    > each font.
    > I have been told to use EnumFontFamily api to retrieve it. Of course, it
    > allowed me to get
    > the list of available system fonts, and its LOGFONT structure contains lot
    > of other elements,
    > but none for size. Could anybody throw some torch?
    >
    > Thanks in advance
    >
    >
    > J Justin
    >
    >
    >




  4. #4
    Klaus H. Probst Guest

    Re: Font Size

    J,

    As michka says, you need to use the lfHeight member. However, this number is
    expressed in logical units, so, for example, in the most common mapping mode
    (MM_TEXT), a font size of 8 corresponds to a font height of -11. The formula
    to calculate the height given a size is:

    Declare Function MulDiv Lib "kernel32" (ByVal nNumber As Long, ByVal
    nNumerator As Long, ByVal nDenominator As Long) As Long
    Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal nIndex
    As Long) As Long
    Public Const LOGPIXELSY = 90

    lfHeight = -MulDiv(lFontSize, GetDeviceCaps(pDC, LOGPIXELSY), 72)

    To do it the other way around, just reverse the division operation:

    lFontSize = -((.lfHeight * 72) \ GetDeviceCaps(pDC, LOGPIXELSY))

    This technique is documented in the LOGFONT reference on the PSDK.

    .. . . . . . . . . . . . . . . . . . . . . .
    Klaus H. Probst, MVP
    http://www.vbbox.com/
    http://www.mvps.org/ccrp/

    Please post/reply to the newsgroup(s)



    "J Justin" <precious@md3.vsnl.net.in> wrote in message
    news:3972c675@news.devx.com...
    > In my vb app, I need to show the user, the list of available font size for
    > each font.
    > I have been told to use EnumFontFamily api to retrieve it. Of course, it
    > allowed me to get
    > the list of available system fonts, and its LOGFONT structure contains lot
    > of other elements,
    > but none for size. Could anybody throw some torch?
    >
    > Thanks in advance
    >
    >
    > J Justin
    >
    >
    >




  5. #5
    Klaus H. Probst Guest

    Re: Font Size

    J,

    As michka says, you need to use the lfHeight member. However, this number is
    expressed in logical units, so, for example, in the most common mapping mode
    (MM_TEXT), a font size of 8 corresponds to a font height of -11. The formula
    to calculate the height given a size is:

    Declare Function MulDiv Lib "kernel32" (ByVal nNumber As Long, ByVal
    nNumerator As Long, ByVal nDenominator As Long) As Long
    Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal nIndex
    As Long) As Long
    Public Const LOGPIXELSY = 90

    lfHeight = -MulDiv(lFontSize, GetDeviceCaps(pDC, LOGPIXELSY), 72)

    To do it the other way around, just reverse the division operation:

    lFontSize = -((.lfHeight * 72) \ GetDeviceCaps(pDC, LOGPIXELSY))

    This technique is documented in the LOGFONT reference on the PSDK.

    .. . . . . . . . . . . . . . . . . . . . . .
    Klaus H. Probst, MVP
    http://www.vbbox.com/
    http://www.mvps.org/ccrp/

    Please post/reply to the newsgroup(s)



    "J Justin" <precious@md3.vsnl.net.in> wrote in message
    news:3972c675@news.devx.com...
    > In my vb app, I need to show the user, the list of available font size for
    > each font.
    > I have been told to use EnumFontFamily api to retrieve it. Of course, it
    > allowed me to get
    > the list of available system fonts, and its LOGFONT structure contains lot
    > of other elements,
    > but none for size. Could anybody throw some torch?
    >
    > Thanks in advance
    >
    >
    > J Justin
    >
    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center