Playing with Unicode: A question...

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Playing with Unicode: A question...

Post by Klaus » Fri Apr 29, 2022 5:00 pm

richmond62 wrote:
Fri Apr 29, 2022 4:40 pm
Your fiddle is another man's bagpipes. :D
LOL! :D :D :D

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7229
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Playing with Unicode: A question...

Post by jacque » Fri Apr 29, 2022 5:33 pm

dunbarx wrote:
Fri Apr 29, 2022 1:53 pm
I do not use unicode at all, but wonder why you would use the templateField. The "templateGadgets" are phantom controls
That's why they're so handy. If you want to do a temporary action that doesn't touch the stack at all and disappears when it's done, the template objects provide a sort of scratchpad. I mostly use it to convert htmltext back to plain text without all the tags. Set the htmltext of the templateField and retrieve the text. It's instant.

But as Klaus said, you can use it for just about anything the regular object supports.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7229
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Playing with Unicode: A question...

Post by jacque » Fri Apr 29, 2022 5:40 pm

keithglong wrote:
Fri Apr 29, 2022 9:19 am
I have been experimenting with Unicode using LiveCode. Would anyone out there happen to have some sample code for getting the Unicode Number and HTML-Code/UTF-16BE Dec for a specific character? I would also like to learn how to use these numbers/codes to convert to and from Unicode in the LiveCode environment.
Can you give us an example of the use for this information? LC provides all the conversion commands you're likely to need for scripting and display of unicode text. It can also convert among different unicode types if you're moving text in and out of LC.

If you are just using text inside LC, unicode is automatic.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Playing with Unicode: A question...

Post by dunbarx » Fri Apr 29, 2022 6:28 pm

Klaus, Jacque.

Aha. I see, an invisible scratchpad that is also a "standard" field. Nice and clean, and the field itself does some real work for free, because that is how fields roll.

I have always only used templates as, er, templates, that is, pre-filled/pre-configured controls. When more than one variation of a particular templateGadget was needed, I had multiple real controls set up as a "library" of such gadgets, set the templateGadget to the appropriate "real" gadget, and then used that until the next variation was required.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Playing with Unicode: A question...

Post by richmond62 » Fri Apr 29, 2022 6:46 pm

Can you give us an example of the use for this information?
Well, I, for one, can think of a use for this information straight way . . .

To contextualise: I work with complex fonts used by ancient Indic languages that have as many as 5000 glyphs.

If I see a text that uses a character I would like to leverage either in a program I am developing
or in an Office document, I normally do require its Unicode address (and whether in Hex or in Decimal is
not a problem as the calculator app on most operating systems can convert back and forth) so that I can call
it when I require it without having to "fart around" with endless obscure keyboard layout and the old
hunt-and-peck.

My stack (see above) does what is required: simply copy-paste your funky character into the top-dead-centre field and hit the button.

I have performed this sort of action many. many times, when, for instance, inserting Grantha script glyphs into my
Devawriter.ttf font.
Last edited by richmond62 on Fri Apr 29, 2022 7:06 pm, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Playing with Unicode: A question...

Post by richmond62 » Fri Apr 29, 2022 6:50 pm

LC provides all the conversion commands you're likely to need for scripting and display of unicode text.
Well, that is like saying that a motor car provides all the tools for driving it: but if you haven't had driving lessons
then that is NBG.

And unicode text is all very fine and dandy IFF you know the 'magic numbers', because without the magic numbers
of the characters you wish to use, you won't get very far indeed, and may end up wrapped round a metaphorical
lamp-post.

Certainly, in any "Let's Get To Grips With Unicode" course I might or might not design, day one would be all about
how the Unicode 'thang' works, and how it works starts with unicode addresses: each of the 150,000 odd glyphs
having a unique address; and, straight after that would be a section on how you find where some character that
thrills your gorilla resides in the unicode system; and at that point I would drag out that incredibly simple but
vital stack I uploaded earlier.

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Playing with Unicode: A question...

Post by Klaus » Fri Apr 29, 2022 6:58 pm

Hi Craig,
dunbarx wrote:
Fri Apr 29, 2022 6:28 pm
Aha. I see, an invisible scratchpad that is also a "standard" field. Nice and clean, and the field itself does some real work for free, because that is how fields roll...
not really, it (the templatefield) is what the name says, the template for newly created fields.

Remember we only have ONE field object but by setting some properties we can turn it into a listfield, scrolling field, label field etc.
The LC TOOLS palette makes heavy use of this and faciliates the creation of the above mentioned different types of fields for us.

If you script "create field" you get the "naked" and pure field object.
If you script:

Code: Select all

...
set the listbehavior of the templatefield to TRU
set the multiplehilites of the templatefield to TRUE
set the togglehilites of the templatefield to TRUE
set the hscrollbar of the templatefield to TRUE
create field
## Always a good idea to avoid surprises :-)
reset the templatefield
...
You get a scrolling list field with multiple and toggling hilites and that is what the TOOLS palette does.

With that in mind we can use it also for tricks like my first example.
Same for all other templatexxx.

Best

Klaus

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Playing with Unicode: A question...

Post by richmond62 » Fri Apr 29, 2022 7:04 pm

I would also like to learn how to use these numbers/codes to convert to and from Unicode in the LiveCode environment.
The Dictionary is your friend.
-
SShot 2022-04-29 at 21.02.03.png
SShot 2022-04-29 at 21.02.03.png (7.69 KiB) Viewed 2223 times
-

The 2 bits of code you need are as follows:

1. numToCodePoint(XXXX) (where 'XXXX' is a unicode number)

https://www.unicode.org/charts/

the unicode number can be in HEXADECIMAL (that is to say the way the Unicode consortium chooses to express them) like this:

0x12FB4 (where the '0x' prefix tells LiveCode that what follows i2 a Hexadecimal number),

this gets the character assigned to that unicode address,

or like this:

77740 (where the number is DECIMAL for people like me who only have 10 fingers).

2. codePointToNum(Z) (Where 'Z' is the character).

this gets the unicode address of the character.

scott_morrow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 29
Joined: Tue Jun 27, 2006 8:35 pm
Location: Bellingham, WA USA
Contact:

Re: Playing with Unicode: A question...

Post by scott_morrow » Sat Apr 30, 2022 7:59 am

Perhaps Klaus answered this question early on but one use-case that I have had was for converting native LiveCode Unicode glyphs into UTF8 htmlEntities. I had an app that allowed the user to enter text and then submit it as data to be displayed on a web page. In the app, LiveCode works with its native UTF16 format and an easy (and fast!) way to convert this to UTF8 / htmlText is through the templateField. Perhaps I misunderstand the textEncode() function in this case but, I believe htmlText is required in order to assure the proper htmlEntities needed by web pages.

-- here is my thinking (for the messageBox):
put textEncode("😆","UTF-8") into tTextEncode --> üòÜ
put "😆" into the templateField
put char 4 to -5 of the htmlText of the templateField into tHTMLText --> 😆
-- see for yourself
put "tTextEncode:"&& tTextEncode &CR& "tHTMLText:"&&tHTMLText

Once I began seeing how others were using the template objects to do amazing things (Scott Rossi comes to mind) I started trying to use them myself and have found that they can be useful in areas other than just prepping before creating multiple copies of an object.
Elementary Software
...now with 20% less chalk dust!

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Playing with Unicode: A question...

Post by richmond62 » Sat Apr 30, 2022 9:53 am

And, I can also point something else out which might be quite useful:

Code: Select all

on mouseUp
  ask file "Choose where you wish to export your text"
  if the result = "cancel" 
  then exit mouseUp
  else
     put the htmltext of fld "XXXX" into url("file:" & it & ".html")
     set the itemDelimiter to slash
     set the defaultFolder to item 1 to -2 of the longFilePath of it
  end if
  end mouseUp
This will export a field that contains Unicode text to an HTML page.

MInd you, it may screw up if your original font contains glyphs in the PUA.

And before you ask, PUA does not stand for Pain-Up-The-AbbaDabbaDoo (although it can seem that way),
it stands for Private Use Areas:

https://en.wikipedia.org/wiki/Private_Use_Areas

Post Reply

Return to “Talking LiveCode”