Results 1 to 3 of 3

Thread: SetFont in RichTextBox with UTF-8 characters

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Posts
    234

    SetFont in RichTextBox with UTF-8 characters

    Hi,

    I've modified the VBAccel. RichEdit box so that I could take advantage of the UTF-8 and Unicode support provided by Version 3+ of the control. However, I'm running into problems when I'm setting font for the control when the UTF-8 characterset is used. When in ANSI, the program loads right away but when I set it to a UTF-8 characterset, the load stalls. I'm pretty sure it has something to either with the bCharSet value in the CHARFORMAT2 structure or the EM_SETCHARFORMAT message. Either way, the program basically pauses when I try to change the font using the function below. I'm really looking for any ideas (because I'm running out of them). Just so you know, if the RichEdit is version 1, then is uses the first if statement, if its Version 2+, then it uses the else statement So long as the codepage is ANSI, there is no problem using either function -- however, as soon I change the codepage, it slows down.

    VB Code:
    1. Public Sub SetFont( _
    2.       ByRef fntThis As StdFont, _
    3.       Optional ByVal oColor As OLE_COLOR = vbWindowText, _
    4.       Optional ByVal eType As ERECTextTypes = ercTextNormal, _
    5.       Optional ByVal bHyperLink As Boolean = False, _
    6.       Optional ByVal eRange As ERECSetFormatRange = ercSetFormatSelection _
    7.    )
    8. Dim tCF As CHARFORMAT
    9. Dim tCF2 As CHARFORMAT2
    10. Dim tRect As RECT
    11. Dim dwEffects As Long
    12. Dim dwMask As Long
    13. Dim i As Long
    14. Dim int_eventMask As Long
    15.  
    16. If (m_eVersion = eRICHED32) Then
    17.    tCF.cbSize = Len(tCF)
    18.    tCF.crTextColor = TranslateColor(oColor)
    19.    dwMask = CFM_COLOR
    20.    If fntThis.Bold Then
    21.       dwEffects = dwEffects Or CFE_BOLD
    22.    End If
    23.    dwMask = dwMask Or CFM_BOLD
    24.    If fntThis.Italic Then
    25.       dwEffects = dwEffects Or CFE_ITALIC
    26.    End If
    27.    dwMask = dwMask Or CFM_ITALIC
    28.    If fntThis.Strikethrough Then
    29.       dwEffects = dwEffects Or CFE_STRIKEOUT
    30.    End If
    31.    dwMask = dwMask Or CFM_STRIKEOUT
    32.    If fntThis.Underline Then
    33.       dwEffects = dwEffects Or CFE_UNDERLINE
    34.    End If
    35.    dwMask = dwMask Or CFM_UNDERLINE
    36.  
    37.    If bHyperLink Then
    38.       dwEffects = dwEffects Or CFE_LINK
    39.    End If
    40.    dwMask = dwMask Or CFM_LINK
    41.    
    42.    tCF.dwEffects = dwEffects
    43.    tCF.dwMask = dwMask Or CFM_FACE Or CFM_SIZE
    44.    
    45.    For i = 1 To Len(fntThis.Name)
    46.       tCF.szFaceName(i - 1) = Asc(Mid$(fntThis.Name, i, 1))
    47.    Next i
    48.    tCF.yHeight = (fntThis.Size * 20)
    49.    If (eType = ercTextSubscript) Then
    50.       tCF.yOffset = -tCF.yHeight \ 2
    51.    End If
    52.    If (eType = ercTextSuperscript) Then
    53.       tCF.yOffset = tCF.yHeight \ 2
    54.    End If
    55.    
    56.       SendMessage m_hWnd, EM_SETCHARFORMAT, eRange, tCF
    57.    Else
    58.    
    59.      tCF2.cbSize = Len(tCF2)
    60.      tCF2.crTextColor = TranslateColor(oColor)
    61.      
    62.      tCF2.bCharSet = 255
    63.      
    64.        dwMask = CFM_COLOR
    65.        If fntThis.Bold Then
    66.           dwEffects = dwEffects Or CFE_BOLD
    67.        End If
    68.        dwMask = dwMask Or CFM_BOLD
    69.        If fntThis.Italic Then
    70.           dwEffects = dwEffects Or CFE_ITALIC
    71.        End If
    72.        dwMask = dwMask Or CFM_ITALIC
    73.        If fntThis.Strikethrough Then
    74.           dwEffects = dwEffects Or CFE_STRIKEOUT
    75.        End If
    76.        dwMask = dwMask Or CFM_STRIKEOUT
    77.        If fntThis.Underline Then
    78.           dwEffects = dwEffects Or CFE_UNDERLINE
    79.        End If
    80.        dwMask = dwMask Or CFM_UNDERLINE
    81.    
    82.        If bHyperLink Then
    83.           dwEffects = dwEffects Or CFE_LINK
    84.        End If
    85.        dwMask = dwMask Or CFM_LINK
    86.        
    87.        tCF2.dwEffects = dwEffects
    88.        
    89.        tCF2.dwMask = dwMask Or CFM_FACE Or CFM_SIZE Or CFM_CHARSET
    90.      
    91.        
    92.        For i = 1 To Len(fntThis.Name)
    93.           tCF2.szFaceName(i - 1) = Asc(Mid$(fntThis.Name, i, 1))
    94.        Next i
    95.        
    96.        tCF2.yHeight = (fntThis.Size * 20)
    97.        If (eType = ercTextSubscript) Then
    98.           tCF2.yOffset = -tCF2.yHeight \ 2
    99.        End If
    100.        If (eType = ercTextSuperscript) Then
    101.           tCF2.yOffset = tCF2.yHeight \ 2
    102.        End If
    103.  
    104.       If (eType = ercTextSubscript) Then
    105.          tCF2.dwEffects = tCF2.dwEffects Or CFE_SUBSCRIPT
    106.          tCF2.dwMask = tCF2.dwMask Or CFM_SUBSCRIPT
    107.       End If
    108.       If (eType = ercTextSuperscript) Then
    109.          tCF2.dwEffects = tCF2.dwEffects Or CFE_SUPERSCRIPT
    110.          tCF2.dwMask = tCF2.dwMask Or CFM_SUPERSCRIPT
    111.       End If
    112.        
    113.  
    114.       SendMessage m_hWnd, WM_SETREDRAW, False, 0
    115.       SendMessage m_hWnd, EM_SETCHARFORMAT, eRange, tCF2
    116.       SendMessage m_hWnd, WM_SETREDRAW, True, 0
    117.       InvalidateRect m_hWnd, tRect, True
    118.  
    119.    End If
    120.    
    121. End Sub

    Thanks
    Last edited by TPR25; May 25th, 2003 at 03:42 PM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Posts
    234
    Just putting it back into the queue (since it looks like no one saw it)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Posts
    234
    After much testing (it amazes me that I couldn't find any documentation on this), I did find an answer to my question. Because my RichTextBox must be able to switch between ANSI and UTF-8, the problem seems to be that the RichEdit box occasionally gets confused over what type of data its using. To remove the ambiguity, one simply needs to pass the following message: EM_SETTEXTMODE before setting the font. After adding this message, the control now works as expected.

    Thanks

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