Results 1 to 11 of 11

Thread: [RESOLVED] Kanji TextOut (Unicode)

  1. #1

    Thread Starter
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Resolved [RESOLVED] Kanji TextOut (Unicode)

    Hello!

    vb Code:
    1. Option Explicit
    2. Private Declare Function TextOutW Lib "gdi32.dll" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
    3.  
    4. Private Sub DisplayLetter()
    5. Dim sS As String
    6.   sS = StrConv(ChrW$((78 * 256) + 12), vbUnicode)
    7.   PictureBox1.Cls
    8.   TextOutW PictureBox1.hdc, 0, 0, sS, 1
    9. End Sub

    This will pop up a character from the unicode kanji table, but will be rotated to the left

    What am i missing here?
    Last edited by Jim Davis; Dec 4th, 2008 at 03:51 PM.

  2. #2

    Thread Starter
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Kanji TextOut (Unicode)

    I forgot to tell, that you have to set the Arial Unicode font, for the picturebox. Theres no need to choose any special character coding for the font properties.

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Kanji TextOut (Unicode)

    It doesn't depend as much on the font, Windows has a rather good "font fallback"; primarily in this case the issue is with the API call:
    Code:
    Option Explicit
    
    Private Declare Function TextOutW Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal lpString As Long, ByVal nCount As Long) As Long
    
    Private Sub DisplayLetter()
        Dim strText As String
        strText = ChrW$((78 * 256) + 12)
        Picture1.Cls
        TextOutW Picture1.hDC, 0, 0, StrPtr(strText), 1
    End Sub
    It is better not to pass strings As String, much easier to use StrPtr and declare strings As Long.


    Edit!
    But I'm unsure whether I guessed the problem right.
    Last edited by Merri; Dec 5th, 2008 at 12:37 PM.

  4. #4

    Thread Starter
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Kanji TextOut (Unicode)

    Wow nice, i didnt knew that a pointer is also works for TextOutW! Thanks.

    However, the letter is still rotated to left (by 90 degs)
    Attached Images Attached Images  

  5. #5
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Kanji TextOut (Unicode)

    Remove the control and insert a new one. Don't do any other calls to it. Do you still have a problem?

    I don't have a problem when I simply paste the code and add a command button to call it. The character will be displayed even if the font does not support it.

  6. #6

    Thread Starter
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Kanji TextOut (Unicode)

    The character will be displayed even if the font does not support it.
    Erm. False. It doesnt display, but the small "black filled rectangle" on "MS Sans Serif", and the un-filled rectangle in Tahoma. I didnt test on any other non unicode character set.

    I can select Arial Unicode MS, that is will display the font, but it will be rotated.

    Here is the code i use to display the font. A picturebox and a Command button but nothing else.

    Code:
    Option Explicit
    Private Declare Function TextOutW Lib "gdi32.dll" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal lpString As Long, ByVal nCount As Long) As Long
    
    Private Sub DisplayLetter()
    Dim sS As String
      sS = ChrW$((78 * 256) + 12)
      Picture1.Cls
      TextOutW Picture1.hdc, 0, 0, StrPtr(sS), 1
    End Sub
    
    Private Sub Command1_Click()
    
      Call DisplayLetter
    
    End Sub
    All fonts i am using are windows xp standards. (Hungarian incl. sp2)
    Last edited by Jim Davis; Dec 5th, 2008 at 10:53 PM.

  7. #7
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Kanji TextOut (Unicode)

    I'm running Finnish XP Professional SP3, here is what I get with the above code:


    (The style is installed by Vistamizer.)


    Edit!
    Have you installed support for Far East Languages from Regional and Language Options in Control Panel?

  8. #8

    Thread Starter
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Kanji TextOut (Unicode)

    At the regional settings, i can see a tons of code pages are installed (checkbox) by defult, just like a 50220 (iso-2022 japanese - half-width without katakana) (or whatever the text in english, i am using hungarian xp), but for some reason its grayed out (but i cant select the check on/off on it, but it already checked)

    The combolist, (lang of non unicode apps) is selected as Hungarian, that is my xp's default language.

    Because it display the letter, that means it enabled, but for some reason it cannot display in the proper rotation.

  9. #9
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Kanji TextOut (Unicode)

    Those aren't remarkable; when you open up the Regional Options, the most important are the two checkboxes that talk about installing fonts for example Arabic and Far East languages in the second tab of the window. Checking these two are required. You can mostly ignore the big list.

  10. #10

    Thread Starter
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Kanji TextOut (Unicode)

    The windows built-in char table app (charmap.exe) already displaying the item as properly (without installing the far east language package, that is just 230Mbyte). By looking the dll inports, it seems like the app is using the following gdi apis:

    -CreateFontW and CreateFontIndirectW
    -GetObjectW
    -TextOutW and ExtTextOutW for displaying the letters
    -TranslateCharsetInfo
    -EnumFontFamiliesEx

    And it also using the following, for metrics and so on
    -GetTextAlign
    -GetTextExtentPointW
    -GetTextExtentPoint32W
    -GetTextMetricsW
    -GetCharWidth32W

    I will play around these apis, to get the font displayed properly, without installing the extra 230 mbyte stuff.

    If you have any tips, please drop an input!
    Thx
    Attached Images Attached Images  
    Last edited by Jim Davis; Dec 7th, 2008 at 11:29 AM.

  11. #11

    Thread Starter
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Kanji TextOut (Unicode)

    HAHAHA.

    The "@Arial Unicode MS" will display the fonts rotated (inproperly) but, there is also a @-less "Arial Unicode MS" that will display in the right angle. And, for sure, you dont have to install the far-east font support (the 230 mbyte thing)!

    Proper declarations:

    vb Code:
    1. Private Type SIZE: Width As Long: Height As Long: End Type
    2. Private Declare Function TextOutW Lib "GDI32.dll" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal lpString As Long, ByVal nCount As Long) As Long
    3. Private Declare Function GetTextExtentPoint32W Lib "gdi32" (ByVal hdc As Long, ByVal lpsz As Long, ByVal cbString As Long, lpSize As SIZE) As Long
    4. Private lStartAt As Long

    Here is a simple method, how to display characters, that will invent the TextWidth/Height properties, by using the proper encoding, via GetTextExtentPoint32W api call

    vb Code:
    1. Private Sub DisplayLetter(ByVal CharMap As Long, ByVal Char As Byte, Optional ByVal X As Long = -&HFF, Optional ByVal Y As Long = -&HFE)
    2.   Static PosX As Long, PosY As Long
    3.   Static LastFontSize As SIZE 'will remember the last displayed font size, the code will intend the current character to the right place.
    4.   Dim sS As String
    5.  
    6.   'Parameters
    7.   'X = -&HFF will position the char to the next valid column. (default value)
    8.   'Y = -&HFE will position the char to the same row. (default value)
    9.   'Y = -&HFF will position the char to the next row. (creates a new line, but dont forget to set the X to the begin of the row)
    10.  
    11.   sS = ChrW$((CharMap * 256) + Char)
    12.  
    13.   If -X = &HFF Then
    14.     PosX = PosX + LastFontSize.Width
    15.   Else
    16.     PosX = X
    17.   End If
    18.  
    19.   Select Case -Y
    20.     Case &HFF
    21.       PosY = PosY + LastFontSize.Height
    22.     Case &HFE:
    23.    
    24.     Case Else
    25.       PosY = Y
    26.   End Select
    27.  
    28.   GetTextExtentPoint32W Me.hdc, StrPtr(sS), 1, LastFontSize
    29.   TextOutW Me.hdc, PosX, PosY, StrPtr(sS), 1
    30.  
    31. End Sub

    Usage, example.
    vb Code:
    1. Private Sub Form_Load()
    2.   Me.Show
    3.   DoEvents
    4.   lStartAt = 78
    5.   Me.AutoRedraw = True
    6.   Me.FontName = "Arial Unicode MS" 'Important! Dont use the @Arial Unicode MS that will cause invalid results. Use the @-less.
    7.   Me.Cls
    8.  
    9.   DisplayLetter lStartAt, 64, 60, 100
    10.   DisplayLetter lStartAt, 73
    11.   DisplayLetter lStartAt, 113
    12.  
    13. End Sub


    @Merri, thanks for your time, it was my fault, i used this font (i dont know why it is a @'ed font, dont know why it is displayed in the font enum lists, but there it is, and it causes the rotation issue). I cant give u rep, coz i gave you not so long ago
    Last edited by Jim Davis; Dec 7th, 2008 at 02:12 PM.

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