Font Name needs to be Null-Terminated

Summary

Id: 974.1
Type: Bug Bug
Current Status: Open

Detail

24 Nov 2004 Open Richard Lewis

Just spent a morning trying to rotate a font from code on your excellent website. However, I found a bug. In the SideLogo demo, the font name should be null terminated or the font array isn't always accepted.

Private Sub pOLEFontToLogFont(fntThis As StdFont, hDC As Long, tLF As
LOGFONT) 
Dim sFont As String 
Dim iChar As Integer 
 
   ' Convert an OLE StdFont to a LOGFONT structure: 
   With tLF 
      sFont = fntThis.Name 
      ' There is a quicker way involving StrConv and CopyMemory, but 
      ' this is simpler!: 
      For iChar = 1 To Len(sFont) 
         .lfFaceName(iChar - 1) = CByte(Asc(Mid$(sFont, iChar, 1))) 
      Next iChar 
 
 
      .lfFaceName(iChar - 1) = CByte(Asc(0)) ' Null terminate string! 
 
 
      ' Based on the Win32SDK documentation: 
      .lfHeight = -MulDiv((fntThis.Size), (GetDeviceCaps(hDC, LOGPIXELSY)), 72) 
      .lfItalic = fntThis.Italic 
      If (fntThis.Bold) Then 
         .lfWeight = FW_BOLD 
      Else 
         .lfWeight = FW_NORMAL 
      End If 
      .lfUnderline = fntThis.Underline 
      .lfStrikeOut = fntThis.Strikethrough 
      ' Fix to ensure the correct character set is selected. Otherwise you 
      ' cannot display Wingdings or international fonts: 
      .lfCharset = fntThis.CharSet 
 
   End With
 
End Sub