Page 1 of 1

EditorGadget & Unicode

Posted: Thu Nov 08, 2012 10:38 am
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

Re: EditorGadget & Unicode

Posted: Thu Nov 08, 2012 11:15 am
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!

Re: EditorGadget & Unicode

Posted: Thu Nov 08, 2012 2:55 pm
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$ )

Re: EditorGadget & Unicode

Posted: Thu Nov 08, 2012 3:09 pm
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 €

Re: EditorGadget & Unicode

Posted: Thu Nov 08, 2012 5:43 pm
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

Re: EditorGadget & Unicode

Posted: Fri Nov 09, 2012 5:34 am
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.