[RESOLVED] Kanji TextOut (Unicode)
Hello!
vb 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 String, ByVal nCount As Long) As Long
Private Sub DisplayLetter()
Dim sS As String
sS = StrConv(ChrW$((78 * 256) + 12), vbUnicode)
PictureBox1.Cls
TextOutW PictureBox1.hdc, 0, 0, sS, 1
End Sub
This will pop up a character from the unicode kanji table, but will be rotated to the left :ehh:
What am i missing here?
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.
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.
1 Attachment(s)
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)
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.
Re: Kanji TextOut (Unicode)
Quote:
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. :ehh:
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)
Re: Kanji TextOut (Unicode)
I'm running Finnish XP Professional SP3, here is what I get with the above code:
http://kontu.selfip.info/vb6/img/tex...sans_serif.png
(The style is installed by Vistamizer.)
Edit!
Have you installed support for Far East Languages from Regional and Language Options in Control Panel?
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.
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.
1 Attachment(s)
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
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:
Private Type SIZE: Width As Long: Height As Long: End Type
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 Declare Function GetTextExtentPoint32W Lib "gdi32" (ByVal hdc As Long, ByVal lpsz As Long, ByVal cbString As Long, lpSize As SIZE) As Long
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:
Private Sub DisplayLetter(ByVal CharMap As Long, ByVal Char As Byte, Optional ByVal X As Long = -&HFF, Optional ByVal Y As Long = -&HFE)
Static PosX As Long, PosY As Long
Static LastFontSize As SIZE 'will remember the last displayed font size, the code will intend the current character to the right place.
Dim sS As String
'Parameters
'X = -&HFF will position the char to the next valid column. (default value)
'Y = -&HFE will position the char to the same row. (default value)
'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)
sS = ChrW$((CharMap * 256) + Char)
If -X = &HFF Then
PosX = PosX + LastFontSize.Width
Else
PosX = X
End If
Select Case -Y
Case &HFF
PosY = PosY + LastFontSize.Height
Case &HFE:
Case Else
PosY = Y
End Select
GetTextExtentPoint32W Me.hdc, StrPtr(sS), 1, LastFontSize
TextOutW Me.hdc, PosX, PosY, StrPtr(sS), 1
End Sub
Usage, example.
vb Code:
Private Sub Form_Load()
Me.Show
DoEvents
lStartAt = 78
Me.AutoRedraw = True
Me.FontName = "Arial Unicode MS" 'Important! Dont use the @Arial Unicode MS that will cause invalid results. Use the @-less.
Me.Cls
DisplayLetter lStartAt, 64, 60, 100
DisplayLetter lStartAt, 73
DisplayLetter lStartAt, 113
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 :)