![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Jan 2005
Posts: 110
Rep Power: 4
![]() |
unicode
Hey
I need to find the width/height for japenese text so I was wondering how can I make my text boxes work for unicode characters. I searched a found something about "Microsoft Forms 2.0 Library" or something, I looked in my components and it was not there so any other way I can get it to work, or does someone know where I can get a hold of this dll. thanks |
|
|
|
|
|
#2 | |
|
Expert Programmer
|
Quote:
Obviously the VB data types do so as well, the only areas to be careful are when marshalling to COM or converting a string to a byte array, in which case you'd need to handle the encoding manually. As for getting the size of characters, so long as you have the Japanese UI components and fonts installed, your system display encoding is set to Unicode, and you have set the Font property of the object you're printing too (e.g. a PictureBox) to an extended font like MS Mincho, the TextHeight("something japanese") and TextWidth methods should return the size of the japanese string or character. |
|
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Jan 2005
Posts: 110
Rep Power: 4
![]() |
thanks ill try
![]() |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Jan 2005
Posts: 110
Rep Power: 4
![]() |
Hi, I can't seem to get it to work just by opening the text with unicode in and adding it to a textbox. Here is the code i tried :/
Private Sub Label2_Click()
On Error GoTo EndSub
CommonDialog1.CancelError = True
CommonDialog1.Filter = "Script Files (*.ssa, *.ass)|*.ssa;*.ass"
CommonDialog1.ShowOpen
OpenScript CommonDialog1.FileName
EndSub:
End Sub
Function OpenScript(FileName As String)
Dim fso, ts, s
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(FileName, ForReading, TristateTrue)
s = ts.ReadAll
Text1.Text = s
ts.Close
End Function
Private Sub Label5_Click()
If (Label5.Caption = "Unicode > SJIS") Then
Label5.Caption = "SJIS > Unicode"
DisableItems
Else
Label5.Caption = "Unicode > SJIS"
EnableItems
End If
End Sub
Function DisableItems()
Check1.Enabled = False
Check2.Enabled = False
End Function
Function EnableItems()
Check1.Enabled = True
Check2.Enabled = True
End Functionin the script..is just some japenese text... Dialogue: 1,0:04:04.09,0:04:14.46,*Default,,0000,0000,0000,,空は飛べないけど翼ならあるのさ Dialogue: 1,0:04:20.42,0:04:24.94,*Default,,0000,0000,0000,,慰めながら不謹慎だけど and the output i get is: ÿþ anyone know how i can at least make it open the unicode txt. thanks alot ![]() |
|
|
|
|
|
#5 |
|
Expert Programmer
|
Try copying and pasting your japanese string into a resource file with the langID set to unicode so you can load a unicode string into memory, and check it displays on the form correctly. If you get a load of squares or question marks, it means your font doesn't support unicode characters.
Judging by your code, I'd say your file containing unicode text isn't being read as unicode but as ASCII/ANSI. Try setting the encoding to unicode somewhere, or alternatively use the native VB binary I/O and run StrConv(Something(), vbUnicode) on the resultant byte array to decode it to a string as unicode. |
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Jan 2005
Posts: 110
Rep Power: 4
![]() |
thankyou very much rory!!!!!!!! ^_^
i got it working by reading in binany. ![]() now i have another question...XD i have 2 kinds of strings in my program a japanese one and an english one. the 2 will never be in 1. The program i am making returns the size of charecters i have that working now but for the japanese strings if a unsupported font is chosen i would like to change to the default font for that encoding. so basically is there anyway to find the default font for its codepage 128 i think. or just the default unicode font. unless u already know what that font would be (im not sure if it varies). thanks alot again ^^ |
|
|
|
|
|
#7 |
|
Expert Programmer
|
Hmm, I believe that the core windows fonts (MS Sans Serif, Arial, MS Mincho, Times New Roman etc) should all support any language, as the MUI language packs simply extend them. You can get fonts that'll definitely work with a particular language by going into a web browser and seeing which ones it defaults to for particular encodings (e.g. firefox uses Latha for pages in Tamil languages.)
|
|
|
|
|
|
#8 |
|
Hobbyist Programmer
Join Date: Jan 2005
Posts: 110
Rep Power: 4
![]() |
ok now that makes me think that what im doing is wrong lol.
i didnt add the binary to a byte array, or convert to unicode, i just did a string variable and added to the textbox, but it outputted to a textfile perfect (i could see the japanese..unicode..worked) but wont display in the textbox(not really important)..or picturebox(for the widths important..else ill get wrong values).. heres some of the code: Private Sub Label2_Click() On Error GoTo EndSub CommonDialog1.CancelError = True CommonDialog1.Filter = "Script Files (*.ssa, *.ass)|*.ssa;*.ass" CommonDialog1.ShowOpen OpenScript CommonDialog1.FileName EndSub: End Sub Function OpenScript(FileName As String) Dim i As String Dim i2 As String Text1.text = "" List1.Clear i2 = FreeFile Open FileName For Binary As #i2 Do Until (EOF(i2)) Line Input #i2, i If (Len(Text1.text) = "0") Then Text1.text = i Else Text1.text = Text1.text & vbCrLf & i End If If (Left(i, 6) = "Style:") Then ' not important :p End If Loop Close #1 End Function I had the font set as arial, i guess that shoulda worked but didnt any ideas? does the byte vars/converting functions make any differences? side note: does anyone know about indenting in vb6? my code always looks scruffy..all to the left >D thanks a lot ^_^ |
|
|
|
|
|
#9 |
|
Expert Programmer
|
I'd give it a go reading it into a byte array and then doing the conversion nevertheless, to ensure its unicode. Also in If (Len(Text1.text) = "0") Then the quotes are unecessary and actually slow your loop down (double conversion to string and back).
|
|
|
|
|
|
#10 | |
|
Hobbyist Programmer
Join Date: Jan 2005
Posts: 110
Rep Power: 4
![]() |
Quote:
i tried the bite and converting but i can a type mismatch with the line input, how else can i get the text file line to the byte string or fix this. Function OpenScript(FileName As String) Dim i As Byte Dim i2 As String Text1.text = "" List1.Clear i2 = FreeFile Open FileName For Binary As #i2 Do Until (EOF(i2)) Line Input #i2, i If (Len(Text1.text) = 0) Then Text1.text = StrConv(i, vbUnicode) Else Text1.text = Text1.text & vbCrLf & StrConv(i, vbUnicode) End If If (Left(i, 6) = "Style:") Then ' ... End If Loop Close #1 End Function ![]() |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|