[Done] UTF8 / Plain text file format

You need some new stunning features ? Tell us here.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2810
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

[Done] UTF8 / Plain text file format

Post 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)
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: UTF8 / Plain text file format

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2810
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Re: UTF8 / Plain text file format

Post 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...
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: UTF8 / Plain text file format

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
majikeyric
Enthusiast
Enthusiast
Posts: 181
Joined: Mon Oct 21, 2013 5:21 pm
Location: France
Contact:

Re: UTF8 / Plain text file format

Post by majikeyric »

I encountered this problem too... What a pain... :(
Niffo
Enthusiast
Enthusiast
Posts: 500
Joined: Tue Jan 31, 2006 9:43 am
Location: France

Re: [Done] UTF8 / Plain text file format

Post 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.
Last edited by Niffo on Thu Oct 22, 2015 5:50 pm, edited 1 time in total.
Niffo
Fred
Administrator
Administrator
Posts: 16681
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [Done] UTF8 / Plain text file format

Post by Fred »

Good finding, I will take a closer look.
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: [Done] UTF8 / Plain text file format

Post 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?)
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: [Done] UTF8 / Plain text file format

Post 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!!)
Num3
PureBasic Expert
PureBasic Expert
Posts: 2810
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Re: [Done] UTF8 / Plain text file format

Post 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!
Last edited by Num3 on Tue Mar 03, 2015 12:56 pm, edited 1 time in total.
Niffo
Enthusiast
Enthusiast
Posts: 500
Joined: Tue Jan 31, 2006 9:43 am
Location: France

Re: [Done] UTF8 / Plain text file format

Post 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 ;-)
Niffo
Num3
PureBasic Expert
PureBasic Expert
Posts: 2810
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Re: [Done] UTF8 / Plain text file format

Post 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
Post Reply