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

keithglong
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 348
Joined: Sun Jul 03, 2011 2:04 am

Playing with Unicode: A question...

Post by keithglong »

Hi All,

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.

For example:

Character: Δ
Unicode Number: U+0394
HTML-Code / UTF-16BE Dec: &#916 / 916;

See: https://unicode-table.com/en/0394/

Any code examples, explanations, or sample stacks would be most welcome. So far I've been able to convert Unicode characters to binary, and then back again. It's been fun! (And it's about time I learned this stuff.) I've played around with binaryEncode(), baseConvert(), textDecode(), etc.--and have made some progress--but some examples sure would go a long way.

Thanks!

Keith George Long
a.k.a "Boo"
Gulf Breeze, Florida
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Playing with Unicode: A question...

Post by Klaus »

Hi Keith,

not an expert in Unicode, but you can always use "the templatefield" to get the html for (a) special unicode characte(s).
Example with your delta char:

Code: Select all

...
set the text of the templatefield to numtocodepoint(0x0394)
put the htmltext of the templatefield
## <p>&Delta;</p>
## Strip the P tags and you have the html value
reset the templatefield
...
Hope that helps.

best

Klaus
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Playing with Unicode: A question...

Post by dunbarx »

Klaus.

I do not use unicode at all, but wonder why you would use the templateField. The "templateGadgets" are phantom controls with certain properties set, that can be configured as desired and recalled as needed with those properties preloaded front and center.

What are you doing with the templateField that simply setting a custom property would not do better? :?:

Craig
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Playing with Unicode: A question...

Post by richmond62 »

SShot 2022-04-29 at 16.03.39.png
-
Sorry, haven't a clue re the HTML code.
Attachments
GETTER.livecode.zip
Stack.
(1005 Bytes) Downloaded 350 times
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Playing with Unicode: A question...

Post by Klaus »

Hi Craig,

setting a custom property might require some more lines to finally get the html value for that unicode character.
Once I finally found out the benefits of "the templatexxx" I tend to use them more often. :-)

Example:
Getting the height and width of an image on disk we can use the template field, so this does not require to create an
extra image and query the formattedheight and formattedwidth of that.

I recently also found that we can even create a snapshot from "the templateimage" after setting its filename!
Now how cool is THAT? :-D

Best

Klaus
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Playing with Unicode: A question...

Post by Klaus »

Addendum:
Only fields have the HTMLTEXT property, custom properties don't.
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Playing with Unicode: A question...

Post by richmond62 »

I just stole Klaus's code:
-
SShot 2022-04-29 at 16.47.45.png
-
Not sure about that semi-colon.
Attachments
GETTER.livecode.zip
Stack.
(1.15 KiB) Downloaded 342 times
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Playing with Unicode: A question...

Post by Klaus »

richmond62 wrote: Fri Apr 29, 2022 2:49 pm I just stole Klaus's code:
Sheeesh... :-D
richmond62 wrote: Fri Apr 29, 2022 2:49 pmNot sure about that semi-colon.
That is part of the HTML code for that character.
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Playing with Unicode: A question...

Post by richmond62 »

That is part of the HTML code for that character.
Aha: last time I looked at HTML was about 17 years ago. :?

Code: Select all

on mouseUp
   if fld "ff" is not empty then
      put fld "ff" into MAGIC
      put codePointToNum(MAGIC) into ACHE
      put codePointToNum(MAGIC) into fld "gg"
      set the text of the templatefield to numtocodepoint(ACHE)
      put the htmltext of the templatefield into HWG
      delete char 1 of HWG
      delete char 1 of HWG
      delete char 1 of HWG
      delete the last char of HWG
      delete the last char of HWG
      delete the last char of HWG
      delete the last char of HWG
      put HWG into fld "hh"
   end if
end mouseUp
Gold Medal for Primitive, Clunky code. 8)
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Playing with Unicode: A question...

Post by Klaus »

You forgot "very verbose"! :-)

Code: Select all

...
## Maybe also a bit clunky, but much less verbose:
put the htmltext of the templatefield into HWG
replace "<p>" with "" in HWG
replace "</p>" with "" in HWG
put HWG into fld "hh"
...
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Playing with Unicode: A question...

Post by richmond62 »

replace "<p>" with "" in HWG
OK, OK: here's my excuse:

I have 5 Ukrainian families camping around and about and I am running around contacting everyone
trying to find them flats: they idea of 19 "bodies" sleeping on our living room floor makes me feel
very funny indeed.

Oh, and there is the other thing: someone, somewhere quite enjoys teasing a German guitar player. :lol:
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Playing with Unicode: A question...

Post by Klaus »

Glad he/she doesn't do this with a german BASS player! 8)
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Playing with Unicode: A question...

Post by richmond62 »

Your fiddle is another man's bagpipes. :D
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Playing with Unicode: A question...

Post by richmond62 »

I wonder why the OP needs the HTML code for these characters when, as far as I know, all they need to
do us use a WOFF or WOFF2 font.

http://www.techcybers.com/blog/ttf-otf- ... nt-format/
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Playing with Unicode: A question...

Post by richmond62 »

Thinking about things . . .

How does the new HTML5 "thingy" in LiveCode 10 cope with fonts?

I would assume that it relies on fonts embedded in the source stack?

And are those OTF, TTF, WOFF or WOFF2?
-
SShot 2022-04-29 at 18.52.30.png
Post Reply