Results 1 to 4 of 4

Thread: [RESOLVED] LOGFONT and Unicode font names

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Resolved [RESOLVED] LOGFONT and Unicode font names

    I tried to find information on the web and in other people's projects, but I didn't find something to clarify the issue.

    This is the declaration of the LOGFONT type:

    Code:
    Public Type LOGFONT
        lfHeight As Long
        lfWidth As Long
        lfEscapement As Long
        lfOrientation As Long
        lfWeight As Long
        lfItalic As Byte
        lfUnderline As Byte
        lfStrikeOut As Byte
        lfCharSet As Byte
        lfOutPrecision As Byte
        lfClipPrecision As Byte
        lfQuality As Byte
        lfPitchAndFamily As Byte
        lfFaceName(0 To LF_FACESIZE - 1) As Byte
    End Type
    And I have some code:

    Code:
        If nFontName = "" Then
            iFontName = nFont.Name
        Else
            iFontName = nFontName
        End If
        
        For c = 0 To 31
            If c < Len(iFontName) Then
                StdFontToLogFont_Printer.lfFaceName(c) = Asc(Mid$(iFontName, c + 1, 1))
            Else
                StdFontToLogFont_Printer.lfFaceName(c) = 0
            End If
        Next
    The problem is that with Windows in Chinese, the name of the font can come in Unicode.

    Some suggested as a solution code like this:

    Code:
        Dim temp() As Byte
    
        temp = StrConv(iFontName, vbUnicode)
        For c = 0 To 31
            If c < UBound(temp) + 1 Then
                StdFontToLogFont_Printer.lfFaceName(c) = CByte(temp(c))
            Else
                StdFontToLogFont_Printer.lfFaceName(c) = 0
            End If
        Next
    But even if they say it works, it doesn't seem correct to me.
    The font name comes already in Unicode, and they convert it to Unicode again... and the lfFaceName member of the LOGFONT expects an ANSI string..... so... ¿¿??

    May be a bit better could be:

    Code:
        Dim temp() As Byte
    
        temp = iFontName ' iFontName is a String with the font name
        For c = 0 To 31
            If c < UBound(temp) + 1 Then
                StdFontToLogFont_Printer.lfFaceName(c) = CByte(temp(c))
            Else
                StdFontToLogFont_Printer.lfFaceName(c) = 0
            End If
        Next
    The strange thing is that everything seems to work here (still not tested very much).

    But in the case of the second option, the one they suggested, that is converting to Unicode font names that are already in Unicode, it leads to Arial occupying 20 bytes of the 32 available.

    Anyone knows about this issue?

  2. #2

  3. #3
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,388

    Re: LOGFONT and Unicode font names

    Code:
    LFFaceName(0 To ((LF_FACESIZE * 2) - 1)) As Byte

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: LOGFONT and Unicode font names

    Thanks wqweto and Krool, I already updated the program.
    We'll see what the guys from China say.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width