PDA

View Full Version : Does ThinAir supports Unicode ?



kcvinu
18-08-2016, 09:05
Hi all,
Thanks for this nice IDE and nice language. It doesn't deems to be support unicode. When i type some texts in my native language (Malayalam - India), it shows some question marks. Normaly, this type ide's have an option set the encoding to UTF-8 or something like that. I can't find one in ThinAir. Did i miss something ?

Petr Schreiber
18-08-2016, 18:15
Hi,

thinBasic unicode support is an area which could be expanded a lot.

But to give you a start, have a look at the following functions to see, if their help you achieve what you need:

IsUnicode
Ascii2Unicode
Unicode2Ascii
WideCharToUTF8$
UTF8ToWideChar$

UTF8ToAnsi$

AnsiToUTF8$


I remember talking with Eros regarding UTF8. I think thinAir does not support it in current build, but thinBasic interpreter can use UTF8 files to execute.

Regarding code page in console, I think the following function is very helpful:



Console_SetCP


You can check the information about these in Help file, which you can launch by pressing F1 key in thinAir.


Petr

kcvinu
18-08-2016, 21:05
@Petr Schreiber,
Thanks. Let me try :)

kcvinu
18-08-2016, 21:15
Hi,
I have tried all functions you said in above post. None of them are worked. Feeling sad about unicode.

primo
18-08-2016, 22:44
Hi kcvinu
i am curious if this approach works:
use notepad to save this code:

Uses "UI"

string a
a = "മലയാളം"
msgbox 0,a

to the thinbasic folder, then from command prompt write
thinBasicc test.txt
does it display the മലയാളം correctly on your system ? if not try the functions listed by Petr with the മലയാളം in notepad and try again.
i have tried the Greek and several other languages and it is displayed correctly in the thinAir ide and in the msgbox, except the indian(
Malayalam) . but don't despair, you can request the proper management of your language here http://www.thinbasic.com/community/project.php?projectid=1 . Eros in a holiday (in a remote island with no internet connection) for 2 weeks.

kcvinu
19-08-2016, 07:50
@primo
Thanks for your reply. But your aproach didn't worked for me. The msgbox showed with strange symbols.

Petr Schreiber
21-08-2016, 10:53
It is often the case to store the string literals in some kind of string table, separate from the main program.
In the program, you then reference the literals by names.

Cookbook
- create a data file with strings, for example in format:


programName,"Čučoriedka"
okButton,"Tak třeba jó"
cancelButton,"Tak spíš teda né"

- create a wrapper user defined type to handle the loading and referencing
- use wrapper user defined type in your program


Petr

ErosOlmi
21-08-2016, 11:09
Unicode is still a problem for thinBasic.
Most of the API functions thinBasic uses are Ascii version and not Wide version.

I will see what I can do in next thinBasic versions on this side.

kcvinu
21-08-2016, 13:19
@Petr - That's a nice workaround to try. Thanks.
@eros - I will be happy if i can do some coding in thinBasic with unicode support. I like to see my programs show my native language.

Uzulo
27-08-2016, 10:18
Saluton, ĉiuj // Hello, everyone,

Just in case somebody — kcvinu, for instance — is still interested in how Unicode can be used with ThinBASIC: there is a small example below.

A very short summary:
in order to display Unicode correctly in buttons and messageboxes we can use
(a) the functions Petr kindly indicated above, i. e. UTF8ToWideChar$ and others; actually, for my programme UTF8ToWideChar$ was sufficient (the encoding was UTF-8 throughout);
(b) WinAPI functions, Unicode versions (their declarations are in the text of the programme): SendMessageW, SetWindowTextW, MessageBoxW.

Strings are declared as AsciiZ, specified in the programme directly (UTF-8) and converted to WideChar, then pointed to by ThinBASIC's STRPTR().


'
' =======================================
' FASADO. Provo uzi kodoprezenton UTF-8
' =======================================
'

uses "UI"

declare function SendMessageW lib "user32.dll" _
alias "SendMessageW" _
(ByVal t as DWord, ByVal m as DWord, _
ByVal wp as DWord, ByVal adrL as Long) _
as Long
declare function SetWindowTextW lib "user32.dll" _
alias "SetWindowTextW" _
(ByVal t as DWord, ByVal adrL as Long) _
as Long
declare function MessageBoxW lib "user32.dll" _
alias "MessageBoxW" _
(ByVal t as DWord, ByVal adrLt as Long, _
ByVal adrLcx as Long, ByVal n as DWord) _
as Long

Begin ControlID
%butEn
%butEo
%butRu
%butFa
%butKr
%butYi
%butAr
%butHi
%butJa
%knvP
End ControlID

%UTF8 = 65001
%DlgL = 600
%DlgAt = 300
%DlgA = 400
%CxL = %DlgL \ 3
%CxA = %DlgAt \ 3
%d = 10
%bL = %CxL - %d - %d
%bA = %CxA - %d - %d
%LtrA = 12

$Ttl = "Unicode-text buttons; each changes the colour of the canvas below."
$nButEn = "Well... Close!"
$LtrN = "Arial Unicode MS"

dim DlgH, DlgV, r as Long
dim tDlg, _
tButEo, tButRu, tButFa, tButKr, tButYi, tButAr, tButHi, tButJa, tKnv _
as DWord
dim nButEo, nButRu, nButFa, nButKr, nButYi, nButAr, nButHi, nButJa, _
mFaCx, mFaT _
as AsciiZ

' ================
' CXEFA PROGRAMO
' ================

FUNCTION TbMain()

nButEo = "Ŝanĝiĝu... Ĝis!"
nButRu = "Что ж, закроем!"
nButFa = "!ﺪﯿﻨﻜﺑ ﻪﺘﺴﺑ"
nButKr = "창문을 닫기!"
nButYi = "!ןכאַמוצ רעטצנעפֿ"
nButAr = "Պատուհան փակել"
nButHi = "खिड़की बंद करे ।"
nButJa = "まど を 閉じる。"

mFaCx = UTF8ToWideChar$("Ĉapo de mesaĝ-panelo:")
mFaT = UTF8ToWideChar$(nButRu & $CRLF & nButFa)

desktop get client to DlgH, DlgV
DlgH = (DlgH - %DlgL) \ 2: DlgV = (DlgV - %DlgA) \ 2

dialog font $LtrN, %LtrA

tDlg = Dialog_New (Pixels, 0, $Ttl, _
DlgH, DlgV, %DlgL, %DlgA, _
%WS_DLGFRAME | _
%WS_CAPTION | _
%WS_SYSMENU | _
%WS_OVERLAPPEDWINDOW , 0)

dialog set client tDlg, %DlgL, %DlgA

control add button, tDlg, %butEn, $nButEn, %d, %d, %bL, %bA

control add button, tDlg, %butEo, $SPC, %d+%CxL, %d, %bL, %bA
control handle tDlg, %butEo to tButEo
nButEo = UTF8ToWideChar$(nButEo)
SendMessageW (tButEo, 12, 0, strptr(nButEo))

control add button, tDlg, %butRu, $SPC, %d+%CxL+%CxL, %d, %bL, %bA
control handle tDlg, %butRu to tButRu
nButRu = UTF8ToWideChar$(nButRu)
SendMessageW (tButRu, 12, 0, strptr(nButRu))

control add button, tDlg, %butFa, $SPC, %d, %d+%CxA, %bL, %bA
control handle tDlg, %butFa to tButFa
nButFa = UTF8ToWideChar$(nButFa)
' SendMessageW (tButFa, 12, 0, strptr(nButFa))
SetWindowTextW (tButFa, strptr(nButFa))

control add button, tDlg, %butKr, $SPC, %d+%CxL, %d+%CxA, %bL, %bA
control handle tDlg, %butKr to tButKr
nButKr = UTF8ToWideChar$(nButKr)
SendMessageW (tButKr, 12, 0, strptr(nButKr))

control add button, tDlg, %butYi, $SPC, %d+%CxL+%CxL, %d+%CxA, %bL, %bA
control handle tDlg, %butYi to tButYi
nButYi = UTF8ToWideChar$(nButYi)
SendMessageW (tButYi, 12, 0, strptr(nButYi))

control add button, tDlg, %butAr, $SPC, %d, %d+%CxA+%CxA, %bL, %bA
control handle tDlg, %butAr to tButAr
nButAr = UTF8ToWideChar$(nButAr)
SendMessageW (tButAr, 12, 0, strptr(nButAr))

control add button, tDlg, %butHi, $SPC, %d+%CxL, %d+%CxA+%CxA, %bL, %bA
control handle tDlg, %butHi to tButHi
nButHi = UTF8ToWideChar$(nButHi)
SendMessageW (tButHi, 12, 0, strptr(nButHi))

control add button, tDlg, %butJa, $SPC, %d+%CxL+%CxL, %d+%CxA+%CxA, %bL, %bA
control handle tDlg, %butJa to tButJa
nButJa = UTF8ToWideChar$(nButJa)
SendMessageW (tButJa, 12, 0, strptr(nButJa))

tKnv = control add canvas, tDlg, %knvP, "", _
%d, %d+%CxA+%CxA+%CxA, %DlgL - %d - %d, %bA, , %WS_EX_STATICEDGE
Canvas_Attach (tDlg, %knvP, %FALSE)
Canvas_Clear (%RGB_BLACK)

dialog show modal tDlg, call trFENESTRO

END FUNCTION

' =========================
' PROCEDUROJ KAJ FUNKCIOJ
' =========================

Callback Function trFENESTRO() as Long

SELECT CASE cbMsg

CASE %WM_COMMAND

select case cbCtl

case %butEn
if cbCtlMsg = %BN_CLICKED then Canvas_Clear (%RGB_BLUE)

case %butEo
if cbCtlMsg = %BN_CLICKED then Canvas_Clear (%RGB_RED)

case %butRu
if cbCtlMsg = %BN_CLICKED then
Canvas_Clear (%RGB_GREEN)
MsgBox (tDlg, "=m=", %MB_OK, "=t=")
end if

case %butFa
if cbCtlMsg = %BN_CLICKED then
Canvas_Clear (%RGB_CYAN)
MessageBoxW (tDlg, strptr(mFaT), strptr(mFaCx), %MB_OK)
end if

case %butKr
if cbCtlMsg = %BN_CLICKED then Canvas_Clear (%RGB_MAGENTA)

case %butYi
if cbCtlMsg = %BN_CLICKED then Canvas_Clear (%RGB_YELLOW)

case %butAr
if cbCtlMsg = %BN_CLICKED then Canvas_Clear (%RGB_BROWN)

case %butHi
if cbCtlMsg = %BN_CLICKED then Canvas_Clear (%RGB_GRAY)

case %butJa
if cbCtlMsg = %BN_CLICKED then Canvas_Clear (%RGB_POWDERBLUE)

end select

END SELECT

End Function


Ĝis // Regards,
Uzulo

primo
27-08-2016, 11:34
Thank you Uzulo very much, yes it works
9622
but i can't display the languages in the ThinAir ide, it is displayed like nButRu = "??? ?, ???????!", so i have used the notepad and then saved the file as utf-8 and then perform from the dos prompt: thinbasicc test.txt

Uzulo
27-08-2016, 13:10
Primo,

1. Seems like the ThinAir IDE doesn’t — so far — support the UTF-8 encoding: you can choose a font, but it doesn’t help much.
In addition to Notepad, you could also use such editors as Notepad2 (http://www.flos-freeware.ch/notepad2.html) or Notepad++ (https://notepad-plus-plus.org/) for writing your programmes: they do support UTF-8.

2. From your nice picture I can see that right-to-left (RtL) text support (needed to display e. g. Yiddish and Persian correctly) is not installed on your system. If you need it, you can just switch it on (through Control Panel >> Regional Options).

Uzulo

ErosOlmi
28-08-2016, 01:05
Thanks a lot Uzulo for helping.

Just to let you know I'm working on this side. Not just round the corner but in few weeks I will be able to release a thinAir working on UTF-8. I've already started to work on it switching editor control thinAir uses from very old CodeMax (ascii only) to Scintilla edit control that supports UTF-8 and other encoding.

Attached an example.

More work will require to add wide string support to user interface controls and console.
Will see.

Ciao
Eros

kcvinu
28-08-2016, 05:41
Hi ErosOlmi,
It's a glad news and i am waiting for the new release. Yes Scintilla is correct choice. I am suggesting some more features if you don't mind.

Automatic insertion of end keywords like "End If, Next, End Function, End Select". I mean just like Visual Studio.

ErosOlmi
28-08-2016, 13:03
There is already something, not automatic, that insert code blocks.
Right click where you want a block of predefined code and use "Insert code block ..." --> chose the code block you want to insert.
See image

I will study automatic insertion when I will release new thinAir with Scintilla features.

ErosOlmi
28-08-2016, 13:11
Configuration of code blocks are inside the following file: \thinBasic\ThinAir\Syntax\thinBasic\thinBasic_Blocks.ini

Personalized code blocks can be added using user file: \thinBasic\ThinAir\Syntax\thinBasic\thinBasic_Blocks_Usr.ini
So if you have some block you would add to right click, insert them into this file, just copy and amend a block from official file.

Official files like thinBasic_Blocks.ini are always rewritten when a new thinBasic instalaltion takes place.
While user files like thinBasic_Blocks_Usr.ini are not rewritten when a new thinBasic installation takes place.

kcvinu
28-08-2016, 13:43
Hi ErosOlmi,
Yeah, i saw it. It can insert code blocks. But you can easily add the automatic feature in scintilla. When a user presses enter key, check for the current line and get the starting keyword. Add a new line and a tab space and again a new line. Insert the appropriate end keyword there. And move the cursor to upward so that user can start typing. When checking for current line, please check if there is "()" for a function and "Then" for an "If".
You can add a feature to arrange the code when each enter key press. For example, fixing the unnecessary spaces, adding proper spaces, fixing capital letters. These features make thinAir a state of the art IDE.

ReneMiner
28-08-2016, 22:13
kcvinu, guess you want a functionality of some auto-complete-feature as my thinICE-project (http://www.thinbasic.com/community/showthread.php?12611-preview-thinICE) has.

If you type "End " it will automatically suggest

Const, ControlID, Function, If, Select, Sub, Type, Union, With...

depending on what is actually to end.

Also I vote for some more project-oriented makeover of the thinAir-codebrowser...

It still prefixes functions below "End Type" with the type-name of the type above and a dot.

kcvinu
29-08-2016, 07:40
ReneMiner,
I didn't understand what is ThinICE. Is that an IDE or a GUI library ?. Sorry for my ignorance. I didn't find any executables in that zip file except TBGL_Requester. It only asks for a screen resolution and keyboard language. When i click done, it disappears. Then i saw the readme file. Read a few lines and understood that it is something else. When i get enough time to play with it, i will check what it can do with my thinBasic project. Thanks.

ReneMiner
29-08-2016, 14:57
just run thinICE.tBasic.
Either from Explorer, from thinAir - or even from command prompt if you like to tuck it in.

The executeable in there is just to request screen-resolution and keyboard-layout. It get's started only the first time you run thinICE.tBasic and saves the settings to current APP_Inifile which is thinICE.ini in that case.

It's an "IDE" for thinBasic written in thinBasic but i called it "ICE" since its not an
"Integrated Developing Environment" but some "Inconvenient Coding Environment"

- it has no visual designer for UI-module but a lot of detailed code- and variable-overview, autocomplete and other features.
- it's unlike thinAir - which allows to load any tBasic, tBasicU, tBasicI, tBasicC-scriptunit - more project-oriented so you can load a tBasic-file and it will load all included files by itself so it knows all the variables, udts etc.
- currently thinICE is a source of ideas how i would improve thinAir - nevertheless it's meant to type scripts as fast and as free of bugs as possible :)