Results 1 to 9 of 9

Thread: Font size in relation to number of pixels in height???(*Resolved*)

  1. #1

    Thread Starter
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935

    Font size in relation to number of pixels in height???(*Resolved*)

    Hi all

    Does anyone here know exactly how many pixels on the x axis that say a 10pt font would use??

    is 10pt 10 pixels??

    Thanks in advance
    Last edited by rudvs2; Nov 19th, 2001 at 08:29 PM.

  2. #2
    jim mcnamara
    Guest
    First of, pixels are actually different sizes, depending on resolution.
    Screen.TwipsPerPixel tells you how many twips per pixel.

    TextHeight returns a value in twips.

    10pt is 10/72 inches - there are 72 points per inch, 1440 twips to the inch, and any number of pixels to the inch. a twip is 1/20 of a point.

    So 10pt would be 200 twips.

  3. #3
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    I think that depends on whether it is a fixed width font or not. In a non-fixed-width font the letter 'A' will be wider than the letter 'i'.

    I looked into converting points to pixels once a long time ago and found it was not an easy thing to do. Maybe someone else had a differnt experience. You can, however, get the width of a letter or string using the TextWidth method of a Form or PictureBox.

    VB Code:
    1. Private Sub Form_Load()
    2.     Form1.ScaleMode = vbPixels
    3.     Form1.FontName = "Ariel"
    4.     Form1.FontSize = "10"
    5.     Debug.Print "Width in pixels of i = " & Form1.TextWidth("i")
    6.     Debug.Print "Width in pixels of A = " & Form1.TextWidth("A")
    7. End Sub

    Greg
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

  4. #4

    Thread Starter
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    okay thanks guys

    I dont actually need to get the width i just need to get the Height value

    The reason is this

    I want to work out how many lines are visible in a textbox control I already know how to get a total line count and also a current line index value

    so all i need is to find out how many lines are actually visible in the textbox at any given time

    so based on your description Jim it would be something like this

    VB Code:
    1. Dim intSize As Integer
    2. Dim intHeight As Integer
    3. Dim intVis As Integer
    4.  
    5. frm1.ScaleMode = 1
    6. intSize = Text1.FontSize
    7. intHeight = Text1.Height
    8. intVis = intHeight / (intSize * 20)

    except this did not work

    it returned a value of 5 but the textbox only diplayed 3 lines

    is there anything i am missing here?

  5. #5
    jim mcnamara
    Guest
    Greg - FWIW

    In font parlance, 10 pt is 10pts tall. Period. This normally includes ascenders and descenders. In practice, specialty fonts (translation: weird fonts that hit characters above & below) can be more.

    Depending on kerning the width may or may not vary, and is found by TextWidth as you noted.

    However, size is the pointsize of the font. Not the width.

    I know - I've made Truetype fonts, and modified them as well.
    Printers refer to fontsize only in terms of how 'tall' it is.

  6. #6

    Thread Starter
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    anyone??

    Does the point size include the top and bottom spacing of the font? or is this seperate

  7. #7
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    Originally posted by jim mcnamara
    Greg - FWIW

    In font parlance, 10 pt is 10pts tall. Period. This normally includes ascenders and descenders. In practice, specialty fonts (translation: weird fonts that hit characters above & below) can be more.

    Depending on kerning the width may or may not vary, and is found by TextWidth as you noted.

    However, size is the pointsize of the font. Not the width.

    I know - I've made Truetype fonts, and modified them as well.
    Printers refer to fontsize only in terms of how 'tall' it is.
    You know, now that I think about it that makes perfect sense. Rudvs2 originally asked how many pixels on the x axis and the x azis would be the width so I went with that.

    Now, back to Rudvs2's problem, what if you just did Textbox.Height Devided by Form1.TextHeight("A"). You would need to make sure both the Form and the Trextbox had the same font name, size, bold, etc.

    Greg
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

  8. #8

    Thread Starter
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    well that works the same as Jims math did

    But there is a line spacing value which buffers above and below each charactor and it doesnt seem to be a static value eg

    I can calculate the value manually based on the number of visible lines i can count and the text height value divided into the textbox height and then work out the diference

    but if i change font size this difference changes and I cant seem to work out by what percentage it differs

  9. #9

    Thread Starter
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    just in case any of you ever want this info the answer is this

    VB Code:
    1. Dim dblSize As Double
    2. Dim intheight As Integer
    3. Dim dblVis As Double
    4.  
    5. frm1.ScaleMode = 1
    6.  
    7. dblSize = Text1.FontSize
    8. intheight = Text1.Height
    9. dblVis = intheight / ((dblSize * 20) + (0.05 * 1440))
    10. Label2.Caption = dblVis
    11. 'where 0.05 is in inches and is the default text box linespacing, 1440 is the value to convert the inch into twipsperpixel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width