Page 1 of 1

[Done] UTF8 / Plain text file format

Posted: Sat Jan 04, 2014 12:16 pm
by Num3
The problem still persists, if i create a form and set it to be plain text, and if then i switch between form view / code view the editor changes the encoding to UTF8 and messes up all latin characthers ...

This is a pain, because there is no warning the encoding changed, and i have to manually reedit all labels to latin (ç ã ó etc) (not funny has the project now passes 150.000 lines of code)

Re: UTF8 / Plain text file format

Posted: Sat Jan 04, 2014 2:39 pm
by IdeasVacuum
The Form Designer does not really support any editing other than the re-arrangement and add/delete of gadgets, so the best way forward is to use From Designer to design the basic layout of the form, and from there code the details by hand (which means you can't later use the Designer, but that is by no means a disaster, it's already done the bulk of the work).

Also, think about using Unicode by default anyway! Microsoft, Adobe and Apple have worked very hard (together!) to ensure that you can, because it is the best possible way to use text in your apps.

Re: UTF8 / Plain text file format

Posted: Sat Jan 04, 2014 4:35 pm
by Num3
My problem is not unicode, it is the fact the Form Designer saves in ASCII by default and that messes up UTF8 projects.

Most users don't see this bug, because it is only visible when using Latin or an encoding other then ascii.

Example for dummies:

I created this simple GUI and saved normally (IDE file format confirmed has: Utf8)

Code: Select all

;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;

Enumeration FormWindow
  #Window_0
EndEnumeration

Enumeration FormGadget
  #Button_0
  #Button_1
  #Button_2
  #Text_0
  #Text_1
  #Text_2
EndEnumeration


Procedure OpenWindow_0(x = 0, y = 0, width = 365, height = 105)
  OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu)
  ButtonGadget(#Button_0, 230, 15, 100, 25, "aáàâä")
  ButtonGadget(#Button_1, 125, 15, 100, 25, "oóòõö")
  ButtonGadget(#Button_2, 15, 15, 100, 25, "aáàâä")
  TextGadget(#Text_0, 20, 50, 100, 25, "oóòõö")
  TextGadget(#Text_1, 235, 50, 100, 25, "aáàâä")
  TextGadget(#Text_2, 125, 50, 100, 25, "aáàâä")
EndProcedure
I open this fresh file in notepad++ and it is ASCII, not UTF8 has it should be!

Now, i go to the IDE, change the form to code view and check File Format -> Encoding: ASCII and back to Encoding: UTF8, this is the result:

Code: Select all

Enumeration FormWindow
  #Window_0
EndEnumeration

Enumeration FormGadget
  #Button_0
  #Button_1
  #Button_2
  #Text_0
  #Text_1
  #Text_2
EndEnumeration


Procedure OpenWindow_0(x = 0, y = 0, width = 365, height = 105)
  OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu)
  ButtonGadget(#Button_0, 230, 15, 100, 25, "aÀ¡À À¢À¤")
  ButtonGadget(#Button_1, 125, 15, 100, 25, "oÀ³À²ÀµÀ¶")
  ButtonGadget(#Button_2, 15, 15, 100, 25, "aÀ¡À À¢À¤")
  TextGadget(#Text_0, 20, 50, 100, 25, "oÀ³À²ÀµÀ¶")
  TextGadget(#Text_1, 235, 50, 100, 25, "aÀ¡À À¢À¤")
  TextGadget(#Text_2, 125, 50, 100, 25, "aÀ¡À À¢À¤")
EndProcedure
Now the file is saved has UTF8 (has it should have been since start), but the gadget descriptions encoding are all *** up ...

And the problem is this happens automatically if i have the misfortune of opening the pbf file by mistake...

Re: UTF8 / Plain text file format

Posted: Sat Jan 04, 2014 8:50 pm
by IdeasVacuum
Well, you have effectively stated the opposite of your original post:
the editor changes the encoding to UTF8
Certainly agree, the Form Designer should in any case default to Unicode, but you can avoid inputting text at form design stage - just add it later.

Re: UTF8 / Plain text file format

Posted: Sat Jan 04, 2014 9:35 pm
by majikeyric
I encountered this problem too... What a pain... :(

Re: [Done] UTF8 / Plain text file format

Posted: Tue Feb 03, 2015 12:00 pm
by Niffo
The actual problem is that Form Designer, when used in graphical mode, saves files in UTF8 WITHOUT BOM. Then the compiler do not understand the file is in UTF8 and the labels and texts of the gadgets are corrupted.

Re: [Done] UTF8 / Plain text file format

Posted: Tue Feb 03, 2015 1:30 pm
by Fred
Good finding, I will take a closer look.

Re: [Done] UTF8 / Plain text file format

Posted: Tue Feb 03, 2015 1:44 pm
by Marc56us
From many times, I use Form Designer with accents (in texts, not in labels) in graphic mode with success.

The solution I use is to switch Forms in code mode before compile/start
(my files format is always utf-8 and I never write anything directly in code)

Work fine :D

(For Fred, in v.o, because my english spoken is poor ;) J'ai cherché aussi pendant un certain temps ce problème d'accents et fini par me rendre compte qu'on peut très bien utiliser des accents avec le form designer en mode graphique, à condition de repasser en mode code au moment de lancer / compiler. À défaut de réencoder, il est peut être possible de forcer cette 'bascule' avant compilation?)

Re: [Done] UTF8 / Plain text file format

Posted: Tue Feb 03, 2015 6:46 pm
by Polo
Sorry about this :oops:

I'll probably leave it to Fred as I'm not very good with file encoding stuff! (sorry Fred!!)

Re: [Done] UTF8 / Plain text file format

Posted: Tue Mar 03, 2015 12:45 pm
by Num3
[TWITCH voice] It's me :twisted: [\TWITCH voice]

PB 5.31 this time :mrgreen:

I have found another bug with UTF8 with purebasic editor and form designer...

Purebasic Editor file encoding is UTF8 (perfect)
Purebasic Form designer file encoding is UTF8 without BOM (latin characters get all messed up on the executable)

My solution for now is open .pbf files in notepad++ and convert the encoding to UTF8

Thank you all for your hard work!

Re: [Done] UTF8 / Plain text file format

Posted: Tue Mar 03, 2015 12:56 pm
by Niffo
Num3 wrote:Purebasic Form designer file encoding is UTF8 without BOM (latin characthers get all messed up on the executable)
Yes, already said in my post ;-)
Num3 wrote:My solution for now is open .pbf files in notepad++ and convert the encoding to UTF8
Or you can just toggle to "Code view" and save ;-)

Re: [Done] UTF8 / Plain text file format

Posted: Tue Mar 03, 2015 1:00 pm
by Num3
Niffo wrote:Yes, already said in my post ;-)
Upss missed it :lol: I was speed reading!
Niffo wrote:Or you can just toggle to "Code view" and save ;-)
Ah, them tips&tricks!

So the bug only happens when the form is saved while in editing mode! <- HINT HINT