EditorGadget & Unicode

Just starting out? Need help? Post your questions and find answers here.
lavachri
User
User
Posts: 19
Joined: Tue Oct 14, 2008 3:01 pm
Location: French

EditorGadget & Unicode

Post by lavachri »

Hi,

some characters are not displayed correctly in unicode compilation...
Code to be compiled in unicode :

Code: Select all

If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)  
  EditorGadget(0, 8, 8, 306, 133) 
  L$ ="euro="+Chr(128)+" oe="+Chr(156)+#CRLF$
 For a = 128 To 255
    L$ + Chr(a) + " "
  Next 
;  SendMessage_( GadgetID( 0), #WM_SETTEXT, 0, @L$) ; Same result
  SetGadgetText(0,L$) 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf
PeekS() doesn't work for this problem.

How can i display chars correctly ?

Thanks
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: EditorGadget & Unicode

Post by STARGÅTE »

the euro character is only in ascii mode the numer 128. (same for other characters)
If you use Unicode, you have to use also the unicode character set, with the euro character at 8364 ($20AC):


enable Unicode and UTF8-file format!

Code: Select all

If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)  
  EditorGadget(0, 8, 8, 306, 133) 
  SetGadgetText(0,Chr(8364)) 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf
so, no bug!
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
lavachri
User
User
Posts: 19
Joined: Tue Oct 14, 2008 3:01 pm
Location: French

Re: EditorGadget & Unicode

Post by lavachri »

Yes, i know that character can have severals code identification, like ASCII ou Unicode.
but Chr() is for ASCII and your code doesn't works for me...

In fact, i want to read text from a file (UTF8) and display it.
But, if file contains euro character, for exemple, the display is not correct with editorgadget.
I thought for a bug, because just some chars are not correctrly displayed.
and i wasn't been able to correct it.

Now, i have found a method in end of this code.

thanks

Code: Select all

If CreateFile(0, "D:\Test.txt")
  WriteString( 0, Chr(128), #PB_UTF8 )
  CloseFile(0)
EndIf
Delay(100)
If ReadFile(0, "D:\Test.txt")
  F$ = ReadString( 0, #PB_UTF8)
  CloseFile(0)
EndIf
If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)  
  EditorGadget(0, 8, 8, 306, 133) 
  A$ = Chr(8364) + Chr(128) + Chr(65)
  Debug PeekW(@A$ ) ; => 172 and not 8364
  Debug PeekW(@A$+2 ) ; => 128
  Debug PeekW(@A$+4 ) ; => 65
  SetGadgetText(0,A$ +#CRLF$+F$) 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf
; To convert ASCII to Unicode
;  C$ = " "
;  PokeW(@C$,8364)
;  A$ = ReplaceString( A$, Chr(128), PeekS(@C$,1) )
;  SetGadgetText( A$ )
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: EditorGadget & Unicode

Post by STARGÅTE »

Chr() is for Unicode too, but you must enable the UFT8-File-Format in the IDE!!
I get this output with your code:
8364
128
65
same here:

Code: Select all

Debug Asc("€")
result is:
8364
(enable unicode and utf8-file-format)

the character 128 is empty in unicode and UTF8, and not the €
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
lavachri
User
User
Posts: 19
Joined: Tue Oct 14, 2008 3:01 pm
Location: French

Re: EditorGadget & Unicode

Post by lavachri »

Sorry, you are right !

I've finaly understood the "UTF8-File-Format" utility...

SetGadgetText( 0, Chr(8364) )
works only in Unicode and "Utf8-File-Format" setted

Thanks a lot
User avatar
Regenduft
Enthusiast
Enthusiast
Posts: 121
Joined: Mon Mar 02, 2009 9:20 pm
Location: Germany

Re: EditorGadget & Unicode

Post by Regenduft »

Maybe Chr() in the PB documentation needs a notice on the fact, that it is also working with Unicode? At the moment Unicode isn't mentioned.

EDIT: :oops:
http://www.purebasic.com/documentation/string/chr.html wrote:This command also works in Unicode mode and then returns the related characters associated to the given value.
Post Reply