textDecode() use & dictionary entry

If you find an issue in LiveCode but are having difficulty pinning down a reliable recipe or want to sanity-check your findings with others, this is the place.

Please have one thread per issue, and try to summarize the issue concisely in the thread title so others can find related issues here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
jim1001
Posts: 140
Joined: Fri Jan 29, 2016 6:25 pm

textDecode() use & dictionary entry

Post by jim1001 » Fri Oct 13, 2017 12:31 pm

This may be a stupid idea but I was thinking of using Unicode characters to label buttons instead of importing images to use as icons.

This led me on to trying textDecode() which I tried, using the LiveCode dictionary as reference, without success. So I went to the basics (even if the first idea is stupid I’d still like to know how to use textDecode).

The syntax for textDecode in the dictionary is
textDecode(binaryData, encoding)
The simplest example of this in the dictionary is
textDecode("A","UTF8")
which raises questions:
Is “A” valid as binary data? (I thought binary was 1s & 0s)
If it is valid, what should be the output?

ps: There is no encoding UTF8 in the dictionary so assume this should be UTF-8
pps: The encoding listing in the Parameters section has “the encoding of the original data” then a list followed by “One of the following items” then another list. You'd need to see it. Does it make any sense?

Thanks for any replies.

bogs
Posts: 727
Joined: Sat Feb 25, 2017 10:45 pm

Re: textDecode() use & dictionary entry

Post by bogs » Fri Oct 13, 2017 2:28 pm

Mind you, I haven't actually tried this and I just woke up, and not sure this belongs in bug triage, but...
jim1001 wrote:
Fri Oct 13, 2017 12:31 pm
ps: There is no encoding UTF8 in the dictionary so assume this should be UTF-8
pps
I assume you have to use textEncode first, so you have something to decode later
Lc Dictionary wrote: Examples:
textEncode("A","UTF16")

put textEncode(field "output","UTF-8") into tOutput
put tOutput into url ("file:output.txt")

Converts from text to binary data.
Which answers your first question...
Is “A” valid as binary data? (I thought binary was 1s & 0s)
If it is valid, what should be the output?
binary is 1 & 0, textEncode, if it does indeed convert text to binary (and I don't doubt that it does), would convert "A" in your example into "01000001" (no quotes on either).
ImageImage

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1553
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: textDecode() use & dictionary entry

Post by [-hh] » Fri Oct 13, 2017 4:06 pm

What you have in mind is already possible.
For example a button with the following script shows the "hospital" SVG-icon.

Code: Select all

on mouseUp
   set the textfont of me to "FontAwesome"
   set the textsize of me to 20
   set the label of me to numToCodePoint(0xf0f9)
end mouseUp
There are already threads incl. scripts/tools in the forum about that, for example http://forums.livecode.com/viewtopic.php?f=10&t=29163

p.s.

As long as we don't have ternary CPUs every data is binary. The difference is the encoding.

So, no bug in sight.

"Binary data" means here raw (non-text) data, not the binary representation of numbers. For example the imagedata of an image is of type "binary data". That's why you read an image file as url("binfile:" & filePath).

"Text data" is binary data that uses a certain text-encoding, for example "ASCII" or "UTF-8".
shiftLock happens

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

Re: textDecode() use & dictionary entry

Post by jacque » Fri Oct 13, 2017 4:42 pm

ps: There is no encoding UTF8 in the dictionary so assume this should be UTF-8
They are synonymous, the hyphen is optional.

As hh mentioned, in this case "binary" refers to the internal coding of the text. Binary text uses 2 or more bytes per character where LC previously used only one before unicode was implemented. Unicode text is always binary, which can be encoded several different ways. LC uses UTF16 but UTF8 is more common in many other apps. The list of options in the dictionary are still more ways that unicode can be encoded.

TextEncode and textDecode are used to import or export text from outside sources that use different encodings. If you are typing the labels within LC you can do so directly without changing anything (except perhaps your language keyboard. )

If you are importing a list of translations from an outside source like a file created by another app, you probably need to convert it from the app's original encoding (often UTF8) to LC's native UTF16. Use textDecode as in the dictionary example to do that. If you ever need to export text for use in another app, you'd use textEncode to convert LC unicode to the target app's encoding.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 727
Joined: Sat Feb 25, 2017 10:45 pm

Re: textDecode() use & dictionary entry

Post by bogs » Fri Oct 13, 2017 4:51 pm

[-hh] wrote:
Fri Oct 13, 2017 4:06 pm
"Binary data" means here raw (non-text) data, not the binary representation of numbers.
See? I told you I wasn't awake yet :P
ImageImage

jim1001
Posts: 140
Joined: Fri Jan 29, 2016 6:25 pm

Re: textDecode() use & dictionary entry

Post by jim1001 » Fri Oct 13, 2017 6:23 pm

Thank you all for the very informative replies. I have a lot to look up & try now. I did have a search in the forums & elsewhere for putting SVG icons on buttons but concluded it wasn't currently possible. Delighted to be proven wrong.

Thanks also for the vital background to binary data & encoding which I clearly need to review. :oops:

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

Re: textDecode() use & dictionary entry

Post by jacque » Sat Oct 14, 2017 6:18 pm

Well, technically it isn't possible to use an SVG as an icon directly (we've been asking for that.) The trick above uses a special image font instead so you'll be limited to the images it provides.

If you want specific images not included in that font you'd either need to use a copy of the SVG for each button or create your own font from the custom images. Once SVGs are converted to a font they aren't really SVG any more, they're font glyphs. The suggestion above is setting the label of the button, not its icon. The visual result is the same though and avoids unnecessary duplication.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jim1001
Posts: 140
Joined: Fri Jan 29, 2016 6:25 pm

Re: textDecode() use & dictionary entry

Post by jim1001 » Tue Oct 17, 2017 10:57 am

Well, technically it isn't possible to use an SVG as an icon directly (we've been asking for that.) The trick above uses a special image font instead so you'll be limited to the images it provides...
Thanks for the clarification Jacque. I look forward to trying the image font.

Post Reply

Return to “Bug Triage”