home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form Form1
- Caption = "Font Viewer"
- ClientHeight = 4020
- ClientLeft = 3735
- ClientTop = 1650
- ClientWidth = 7365
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- LinkMode = 1 'Source
- LinkTopic = "Form1"
- PaletteMode = 1 'UseZOrder
- ScaleHeight = 4020
- ScaleWidth = 7365
- Begin VB.CommandButton cmdFontInfo
- Caption = "Show Info"
- Height = 435
- Left = 2700
- TabIndex = 17
- Top = 3300
- Width = 1335
- End
- Begin VB.TextBox TxtWeight
- Height = 315
- Left = 1260
- TabIndex = 8
- Text = "400"
- Top = 2880
- Width = 1335
- End
- Begin VB.CommandButton CmdShowMetrics
- Appearance = 0 'Flat
- BackColor = &H80000005&
- Caption = "ShowMetrics"
- Height = 495
- Left = 2700
- TabIndex = 16
- Top = 2700
- Width = 1335
- End
- Begin VB.TextBox TxtEscapement
- Height = 315
- Left = 1260
- TabIndex = 6
- Text = "0"
- Top = 2520
- Width = 1335
- End
- Begin VB.CommandButton CmdShowFont
- Appearance = 0 'Flat
- BackColor = &H80000005&
- Caption = "ShowFont"
- Default = -1 'True
- Height = 495
- Left = 2700
- TabIndex = 13
- Top = 2100
- Width = 1335
- End
- Begin VB.TextBox TxtWidth
- Height = 315
- Left = 1260
- TabIndex = 4
- Text = "10"
- Top = 2160
- Width = 1335
- End
- Begin VB.PictureBox PicText
- Height = 1635
- Left = 4200
- ScaleHeight = 1605
- ScaleWidth = 2925
- TabIndex = 9
- Top = 2100
- Width = 2955
- End
- Begin VB.TextBox TxtHeight
- Height = 315
- Left = 1260
- TabIndex = 1
- Text = "10"
- Top = 1800
- Width = 1335
- End
- Begin VB.TextBox TxtSample
- Height = 315
- Left = 5400
- TabIndex = 14
- Text = "ABC"
- Top = 1440
- Width = 1755
- End
- Begin VB.CheckBox ChkStrikeout
- Caption = "StrikeOut"
- Height = 375
- Left = 4140
- TabIndex = 12
- Top = 1020
- Width = 1575
- End
- Begin VB.CheckBox ChkItalic
- Caption = "Italic"
- Height = 375
- Left = 4140
- TabIndex = 11
- Top = 600
- Width = 1575
- End
- Begin VB.CheckBox ChkUnderline
- Caption = "Underline"
- Height = 315
- Left = 4140
- TabIndex = 10
- Top = 240
- Width = 1635
- End
- Begin VB.ListBox FontList
- Height = 1395
- Left = 240
- Sorted = -1 'True
- TabIndex = 0
- Top = 240
- Width = 3015
- End
- Begin VB.Label Label4
- Alignment = 1 'Right Justify
- Appearance = 0 'Flat
- BackColor = &H80000005&
- BackStyle = 0 'Transparent
- Caption = "Weight"
- ForeColor = &H80000008&
- Height = 315
- Left = 120
- TabIndex = 7
- Top = 2940
- Width = 1035
- End
- Begin VB.Label Label3
- Alignment = 1 'Right Justify
- Appearance = 0 'Flat
- BackColor = &H80000005&
- BackStyle = 0 'Transparent
- Caption = "Escapement"
- ForeColor = &H80000008&
- Height = 315
- Left = 60
- TabIndex = 5
- Top = 2580
- Width = 1155
- End
- Begin VB.Label Label2
- Alignment = 1 'Right Justify
- Appearance = 0 'Flat
- BackColor = &H80000005&
- BackStyle = 0 'Transparent
- Caption = "Width"
- ForeColor = &H80000008&
- Height = 255
- Left = 540
- TabIndex = 3
- Top = 2220
- Width = 675
- End
- Begin VB.Label Label1
- Alignment = 1 'Right Justify
- Appearance = 0 'Flat
- BackColor = &H80000005&
- BackStyle = 0 'Transparent
- Caption = "Height"
- ForeColor = &H80000008&
- Height = 255
- Left = 540
- TabIndex = 2
- Top = 1860
- Width = 675
- End
- Begin VB.Label Label5
- Appearance = 0 'Flat
- BackColor = &H80000005&
- BackStyle = 0 'Transparent
- Caption = "Sample Text"
- ForeColor = &H80000008&
- Height = 255
- Left = 4200
- TabIndex = 15
- Top = 1500
- Width = 1095
- End
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- ' Copyright
- 1997 by Desaware Inc. All Rights Reserved.
- Private Sub cmdFontInfo_Click()
- If FontToUse = 0 Then
- MsgBox "Select a font"
- Exit Sub
- End If
- frmInfo.Show 1
- End Sub
- ' Creates a logical font based on the various control
- ' settings. Then displays a sample string in that font.
- Private Sub CmdShowFont_Click()
- Dim lf As LOGFONT
- #If Win32 Then
- Dim oldhdc&
- #Else
- Dim oldhdc%
- #End If
- Dim TempByteArray() As Byte
- Dim dl&, x%
- Dim ByteArrayLimit&
- Dim rc As RECT
- PicText.Cls
- If FontToUse <> 0 Then dl = DeleteObject(FontToUse)
- lf.lfHeight = Val(TxtHeight.Text)
- lf.lfWidth = Val(TxtWidth.Text)
- lf.lfEscapement = Val(TxtEscapement.Text)
- lf.lfWeight = Val(TxtWeight.Text)
- If (ChkItalic.value = 1) Then lf.lfItalic = 1
- If (ChkUnderline.value = 1) Then lf.lfUnderline = 1
- If (ChkStrikeout.value = 1) Then lf.lfStrikeOut = 1
- lf.lfOutPrecision = OUT_DEFAULT_PRECIS
- lf.lfClipPrecision = OUT_DEFAULT_PRECIS
- ' This kind of chr$ assignment is no longer necessary and
- ' is not advisiable
- ' lf.lfQuality = Chr$(DEFAULT_QUALITY)
- lf.lfQuality = DEFAULT_QUALITY
- lf.lfPitchAndFamily = DEFAULT_PITCH Or FF_DONTCARE
- lf.lfCharSet = DEFAULT_CHARSET
- ' When we changed this to a byte array, we
- ' no longer can assign a text string to a fixed
- ' length byte array.
- ' lf.lfFaceName = FontList.Text & Chr$(0)
- #If Win32 Then
- TempByteArray = StrConv(FontList.Text & Chr$(0), vbFromUnicode)
- #Else
- TempByteArray = FontList.Text & Chr$(0)
- #End If
- ByteArrayLimit = UBound(TempByteArray)
- For x% = 0 To ByteArrayLimit
- lf.lfFaceName(x%) = TempByteArray(x%)
- Next x%
- FontToUse = CreateFontIndirect(lf)
- If FontToUse = 0 Then Exit Sub
- oldhdc = SelectObject(PicText.hdc, FontToUse)
- ' Get the client rectangle in order to place the
- ' text midway down the box
- dl& = GetClientRect(PicText.hwnd, rc)
- dl& = TextOut(PicText.hdc, 1, rc.Bottom / 2, (TxtSample.Text), Len(TxtSample.Text))
- dl& = SelectObject(PicText.hdc, oldhdc)
- End Sub
- ' Display the text metrics for the physical font.
- Private Sub CmdShowMetrics_Click()
- Dim tm As TEXTMETRIC
- Dim r$
- Dim crlf$
- #If Win32 Then
- Dim oldfont&
- #Else
- Dim oldfont%
- #End If
- Dim di&
- Dim tbuf As String * 80
- crlf$ = Chr$(13) + Chr$(10)
- If FontToUse = 0 Then
- MsgBox "Font not yet selected"
- Exit Sub
- End If
- oldfont = SelectObject(PicText.hdc, FontToUse)
- di = GetTextMetrics(PicText.hdc, tm)
- di = GetTextFace(PicText.hdc, 79, tbuf)
- ' Add to r$ only the part up to the null terminator
- r$ = "Facename = " + agGetStringFromLPSTR$(tbuf) + crlf$
- ' No need to have Asc conversions here
- If (tm.tmPitchAndFamily And TMPF_TRUETYPE) <> 0 Then r$ = r$ + "... is a TrueType font" + crlf$
- If (tm.tmPitchAndFamily And TMPF_DEVICE) <> 0 Then r$ = r$ + "... is a Device font" + crlf$
- ' Curiously enough, this bit is set for variable width fonts.
- If (tm.tmPitchAndFamily And TMPF_FIXED_PITCH) <> 0 Then
- r$ = r$ + "... is a variable pitch font" + crlf$
- Else
- r$ = r$ + "... is a fixed pitch font" + crlf$
- End If
- If (tm.tmPitchAndFamily And TMPF_VECTOR) <> 0 Then r$ = r$ + "... is a vector font" + crlf$
- r$ = r$ + "Height=" + Str$(tm.tmHeight) + ", Ascent=" + Str$(tm.tmAscent) + ", Descent=" + Str$(tm.tmDescent) + crlf$
- r$ = r$ + "Internal Leading=" + Str$(tm.tmInternalLeading) + ", External Leading=" + Str$(tm.tmExternalLeading) + crlf$
- r$ = r$ + "Average char width=" + Str$(tm.tmAveCharWidth) + ", Max char width=" + Str$(tm.tmMaxCharWidth) + crlf$
- r$ = r$ + "Weight=" + Str$(tm.tmWeight) + ", First char=" + Str$(Asc(tm.tmFirstChar)) + ", Last char=" + Str$(Asc(tm.tmLastChar)) + crlf$
- MsgBox r$, 0, "Physical Font Metrics"
- di = SelectObject(PicText.hdc, oldfont)
- End Sub
- Private Sub FontList_Click()
- CmdShowFont_Click
- End Sub
- ' Load the font list dialog box with the available fonts
- Private Sub Form_Load()
- Dim x%
- Dim a$
- #If Win16 Then
- ' This functionality is disabled for Win16
- cmdFontInfo.Visible = False
- #End If
- Screen.MousePointer = 11
- For x% = 1 To Screen.FontCount
- a$ = Screen.Fonts(x%)
- If a$ <> "" Then FontList.AddItem a$
- Next x%
- Screen.MousePointer = 0
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- ' Be sure to clean up GDI objects when leaving the program
- Dim di&
- If FontToUse& <> 0 Then di = DeleteObject(FontToUse)
- End Sub
-