|
-
Nov 19th, 2001, 06:18 PM
#1
Thread Starter
Fanatic Member
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.
-
Nov 19th, 2001, 06:25 PM
#2
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.
-
Nov 19th, 2001, 06:31 PM
#3
Frenzied Member
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:
Private Sub Form_Load()
Form1.ScaleMode = vbPixels
Form1.FontName = "Ariel"
Form1.FontSize = "10"
Debug.Print "Width in pixels of i = " & Form1.TextWidth("i")
Debug.Print "Width in pixels of A = " & Form1.TextWidth("A")
End Sub
Greg
Free VB Add-In - The Reference Librarian
Click Here for screen shot and download link.
-
Nov 19th, 2001, 06:45 PM
#4
Thread Starter
Fanatic Member
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:
Dim intSize As Integer
Dim intHeight As Integer
Dim intVis As Integer
frm1.ScaleMode = 1
intSize = Text1.FontSize
intHeight = Text1.Height
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?
-
Nov 19th, 2001, 06:45 PM
#5
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.
-
Nov 19th, 2001, 07:06 PM
#6
Thread Starter
Fanatic Member
anyone??
Does the point size include the top and bottom spacing of the font? or is this seperate
-
Nov 19th, 2001, 07:41 PM
#7
Frenzied Member
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.
-
Nov 19th, 2001, 07:56 PM
#8
Thread Starter
Fanatic Member
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
-
Nov 19th, 2001, 08:32 PM
#9
Thread Starter
Fanatic Member
just in case any of you ever want this info the answer is this
VB Code:
Dim dblSize As Double
Dim intheight As Integer
Dim dblVis As Double
frm1.ScaleMode = 1
dblSize = Text1.FontSize
intheight = Text1.Height
dblVis = intheight / ((dblSize * 20) + (0.05 * 1440))
Label2.Caption = dblVis
'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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|