Solved

How to enumerate font sizes for a font

Posted on 2002-07-15
7
318 Views
Last Modified: 2013-12-02
Hello:

In common dialog controls or microsoft word, when we select a font, it lists only selected font sizes. The list varies on font selection. I have a similar need. I need to enumerate font sizes for a given font. In my application, if user types in a font size which is not valid one, vb rich text box or list view will truncate it to the nearest valid number. When user looks at it, he thinks it does not work. If I could limit the choices to the user, then it will be ok.

Is there a way to enumerate the font sizes ?

thanks

0
Comment
Question by:sgarg
7 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 7155261
If you are using true-type fonts, there are not "font sizes" even though Office limits the selection.  True type fonts, by design, are fully-scalable to any font size, including fractional sizes (like 8.5)

When you see a list with a discrete set of font sizes on a true-type font, I think it represents "common, suggested" font sizes.

When you see font sizes on non-scalable fonts (such as .FON extensions), this means that they are bitmap fonts and any font size that is not in the specified list is not support (but will appear using some pixelated version.)  However, I am not familiar with the file-format for these so I'm not sure how to determine the font size selection available.
0
 

Author Comment

by:sgarg
ID: 7155295
I use MS Sans Serif and user can type 9 for the font size but rich text box when assigned the size 9, will truncate it down to 8.25.

0
 
LVL 20

Accepted Solution

by:
hes earned 50 total points
ID: 7155317
Could you use something like this

Private Sub Command1_Click()
Dim I As Integer
Dim OldFontSize As Integer
Dim result As Boolean

OldFontSize = RichTextBox1.Font.Size
For I = 1 To 50
  result = SetFontSize(RichTextBox1, I)
  If result Then
  List1.AddItem I
  End If
Next
RichTextBox1.Font.Size = OldFontSize
End Sub

Function SetFontSize(obj As Object, FontSize As Integer) As Boolean
    On Error Resume Next
    obj.Font.Size = FontSize
    SetFontSize = (obj.Font.Size = FontSize)
End Function
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 49

Expert Comment

by:DanRollins
ID: 8012411
Hi sgarg,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Split points between: rspahitz and hes

sgarg, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 8012507
Correction, to make this a worthwhile PAQ:

The font sizes in many Windows products seem to increment in 3/4-point sizes, so hes' code should be modified as follows:

...
Dim I As Single' yeah, I know it's strange, but easier than modifying the entire code
...
For I = 1 To 50 step .75
...

--
Any font that cannot be displayed exactly will be rounded up or down to the nearest 3/4-point.

I find it odd that 9 rounds down since it's on a 3/4-point interval.

Also note that if you omit the 3/4-point step, 7 will round down to 6.75 and 8 will round up to 8.25, and 7.5 will never be included.

 
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 8012521
After further review, I see that the routine is seeking integer font sizes, so I guess you should increment by .25 to catch them all:

...
For I = 1 To 50 step .25
...

0
 

Expert Comment

by:SpideyMod
ID: 8096098
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange

rspahitz points for you at:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20543670.html
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now