Page 1 of 2

Playing with Unicode: A question...

Posted: Fri Apr 29, 2022 9:19 am
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

Re: Playing with Unicode: A question...

Posted: Fri Apr 29, 2022 9:53 am
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

Re: Playing with Unicode: A question...

Posted: Fri Apr 29, 2022 1:53 pm
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

Re: Playing with Unicode: A question...

Posted: Fri Apr 29, 2022 2:05 pm
by richmond62
SShot 2022-04-29 at 16.03.39.png
-
Sorry, haven't a clue re the HTML code.

Re: Playing with Unicode: A question...

Posted: Fri Apr 29, 2022 2:07 pm
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

Re: Playing with Unicode: A question...

Posted: Fri Apr 29, 2022 2:30 pm
by Klaus
Addendum:
Only fields have the HTMLTEXT property, custom properties don't.

Re: Playing with Unicode: A question...

Posted: Fri Apr 29, 2022 2:49 pm
by richmond62
I just stole Klaus's code:
-
SShot 2022-04-29 at 16.47.45.png
-
Not sure about that semi-colon.

Re: Playing with Unicode: A question...

Posted: Fri Apr 29, 2022 3:28 pm
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 pm
Not sure about that semi-colon.
That is part of the HTML code for that character.

Re: Playing with Unicode: A question...

Posted: Fri Apr 29, 2022 3:59 pm
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)

Re: Playing with Unicode: A question...

Posted: Fri Apr 29, 2022 4:16 pm
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"
...

Re: Playing with Unicode: A question...

Posted: Fri Apr 29, 2022 4:19 pm
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:

Re: Playing with Unicode: A question...

Posted: Fri Apr 29, 2022 4:35 pm
by Klaus
Glad he/she doesn't do this with a german BASS player! 8)

Re: Playing with Unicode: A question...

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

Re: Playing with Unicode: A question...

Posted: Fri Apr 29, 2022 4:44 pm
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/

Re: Playing with Unicode: A question...

Posted: Fri Apr 29, 2022 4:53 pm
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