Solved

How to enumerate font sizes for a font

Posted on 2002-07-15
7
316 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

771 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

9 Experts available now in Live!

Get 1:1 Help Now