livecode.com
  • Home
  • Download
  • Developers
  • Academy
  • Community
  • Store
  • Support
  • About
LiveCode Lessons » How To - Step-By-Step Guides To Tasks In LiveCode » How do I use Unicode in Rev?

Topics

  • Creating User Interfaces 22
    • Using Tab Buttons
    • How to create a rollover button with icon images
    • How to apply the new graphics effects to an object
    • How to make a stack with a window shape
    • How do I Send Messages During A Drag Operation?
    • How to show the progress of a download
    • How do I populate a field when an option menu is changed?
    • How do I scroll a card that is taller or wider than the window?
    • Creating Hypertext Links in Fields
    • How do I use the same controls on multiple cards?
    • Pinning Drag-and-drop to the mat: a primer
    • Detecting changes in a field
    • How do I use a Progress Bar?
    • How to manage and position objects when a stack is resized
    • How do I move between cards in my stack?
    • Play Sounds
    • How do I display a PDF in Rev?
    • How do I Create an ANSI Font Menu?
    • How to make a simple line graph
    • How to build an interactive plotter with a polygon
    • How To Create a Custom Cursor
    • How do I use Relayering?
  • Text 9
    • How Do I Use UTF-8 Text With Fields?
    • How do I Display Tab Delimited Text in a Table Field?
    • How can I search delimited data for a matching string?
    • How do I use Unicode in Rev?
    • How to count upper and lower case characters
    • Using the flagged property in a field
    • How do I style paragraphs in a field in LiveCode 5.5?
    • How do I display a table in a field?
    • How do I use hierarchical list support?
  • Working with files 9
    • How to list the files in a folder
    • How to read in data from an XML file
    • File Input/Output
    • How do I import a text file?
    • How Do I Process a Binary File?
    • How do I export a csv file?
    • How do I get the content of a URL on a web server into Revolution?
    • How do I rename the headers on a text file?
    • Uploading a file using FTP
  • The LiveCode Message Path 2
    • How to call a function or command in another object?
    • How to send messages to an object using the send command
  • Custom Properties 3
    • How do I save custom properties in a standalone application?
    • How do I define my own properties for an object?
    • Grouping custom properties in a custompropertyset
  • LiveCode tips 18
    • How to communicate with other applications using sockets
    • Opening a Stack from the Server
    • How do I Locate Scripts or Custom Properties in my Project?
    • How to relayer grouped controls
    • Setting toolTip and toolTipDelay
    • How do I get the path to common folders on my computer?
    • How can I get the path to the folder a stack file resides in?
    • Message box tips and tricks
    • What Are The Alternatives To Using Global Variables?
    • How to use date and time in Rev
    • How to create simple lists in LiveCode
    • How to create PDFs using LiveCode
    • How do I Create an HTML E-Mail?
    • How do I Attach a File to an E-Mail?
    • Dropping System Folders on Fields
    • How to Quickly Edit a Palette Stack in the IDE
    • Visual Basic-to-revTalk cheat sheet
    • How to create an application that opens when you drag a file onto it
  • LiveCode Arrays 9
    • How do I display an array in a table field?
    • How do I convert tab delimited data into an array?
    • How do I sort an array?
    • How do I add keys to or delete keys from an array?
    • How do I rename a key in an array?
    • How do I store an array in a text file and then retrieve it again?
    • How do I Search an Array?
    • How do I Display an Array in Human Readable Form?
    • How do I Store an Array Variable Inside of Another Array Variable?
  • Using Behaviors 3
    • How To Assign A Behavior
    • How to Override a Behavior
    • How To Create Field Placeholder Text Using Behaviors
  • LiveCode and Databases 5
    • How do I Create and set up a Database?
    • Converting a Database Cursor to a Data Grid Array
    • Connecting to a MySQL database
    • How to connect Database using ODBC
    • How to create and use an SQLite database
  • Creating an 8-puzzle game 3
    • How do I Create an 8-Puzzle Game?
    • How do I Tell the Computer to Solve the 8-Puzzle Game?
    • How do I Tell the Computer to Solve the 8-Puzzle Game Using A*?
  • Groups 0
  • Using Graphics 3
    • How do I Create Animated Overlays?
    • How do I add Motion to Animated Overlays?
    • How to create a scrolling group using the improved graphics architecture
  • Using Images 9
    • How to Create a Thumbnail Image
    • Vision: How do I Threshold an Image?
    • Vision: How do I Blur an Image?
    • Vision: How do I Edge Detect an Image?
    • How to proportionally resize an image
    • Vision: How do I Convert a Color Image to Grayscale?
    • How do you embed an image in a stack so a path reference is not needed?
    • Screenshot with Effects
    • How do you display an image by dragging it on to a stack?
  • LiveCode Plugins and Externals 5
    • How To Install 3rd Party Externals For Use in the IDE and Standalone Builder
    • How To Install a 3rd Party Plugin In the Revolution IDE
    • How to safely attach an external to your stack
    • Linking an OSX external bundle with a .dylib library
    • How to install custom user plugins
  • LiveCode revLets and the Web plugin 7
    • How to build a revlet
    • How do I communicate with the browser from a plugin?
    • How do I determine which permissions a revlet has?
    • How do I create a web-based revlet that references assets such as videos?
    • How do I pass data from a webpage to a plugin?
    • How do I Pass Variable Data from a Webpage to a Plugin?
    • How to build a revLet without a security prompt
  • Using dialogs 7
    • How do I Create a Color Picker Swatch?
    • How can I restrict an answer file dialog to just applications?
    • How Can I Pass Data To and Get Data From a Dialog Window?
    • How do I Create a Modal Dialog?
    • How to control where the answer file/folder dialog starts
    • How do I use the Project Browser?
    • How do I create a scalable UI using graphics?

Last Updated

Mar 31, 2010

Download Lesson PDF

Other Resources

  • Getting Started with LiveCode

  • Get Up and Running with LiveCode
  • Getting Started with LiveCode Development
  • LiveCode Concepts

  • Features, concepts and aspects of LiveCode
  • LiveCode Lessons

  • How To - Step-By-Step Guides To Tasks In LiveCode
  • How To - LiveCode Server Tasks
  • How To - LiveCode Mobile Tasks
  • How To - LiveCode Sample Scripts
  • How to - LiveCode Marketplace Products
  • How to Purchase and License LiveCode
  • Tutorials

  • Creating a Video Library Application
  • Data Grid

  • LiveCode Data Grid
  • Data Grid Tips & Tricks
  • Converting the Stock Program

Comments

0 for this lesson

  • Prev: How can I search delimited data for a matching string?
  • Next: How to count upper and lower case characters

How do I use Unicode in Rev?

If you want to create stacks in languages other than English or the more common European languages then you need to use Unicode. Luckily Rev handles Unicode text very well in most cases. This lesson will cover the main tips and tricks you need to know in order to use Unicode in your stacks.

A brief introduction to Unicode

ASCII (the American Standard Code for Information Interchange) is a standard character encoding system which was developed in the 1960's. As ASCII is an 8-bit encoding it is limited to 128 code points numbered 0-127. ASCII assigns unique codes to upper and lower case Latin letters, numbers and common punctuation, ASCII is still widely used today and is consistent across all operating systems.

Unfortunately 128 code points are not nearly enough to represent all the characters in use across the world. In the 1980's the Unicode consortium created a character encoding standard designed to provide a way to display all of the world's languages by using a larger, 16-bit character table. The goal of Unicode was to assign each character in all the world's languages a unique code number.

Under the Unicode standard, there are several encoding systems, most notably UTF-8, UTF-16, and UTF-32. Revolution uses the UTF-16 encoding. However, Revolution has the ability to transcode between UTF-16 and several other common encodings.

For a more detailed introduction to Rev and Unicode have a look at the Unicode tutorial at

http://www.runrev.com/developers/lessons-and-tutorials/tutorials/unicode-in-revolution/

Typing Unicode into a field

This is nice and easy in Rev, Rev fields can handle Unicode text input without you needing to do anything because Rev simply uses the text input methods supplied by the host operating system. So if you want to type Russian characters into a field just select the Russian text input system and start typing, thats all there is to it!

Note on displaying right to left text

However, Unicode text input in Rev is not perfect. Rev has trouble rendering right-to-left languages like Hebrew and Arabic. This comes down to what is and isn't encoded as Unicode so

<arabic word 1> <non-unicode space><arabic word 2> would render incorrectly as
<arabic word 1> <arabic word 2>

but

<arabic word 1> <unicode space><arabic word 2> would render correctly as
<arabic word 2> <arabic word 1>

So when display right-to-left text you need to be careful and ensure that Unicode encodings are not lost.

Using unicodeText

When using non Unicode fields you can move text and chunks of text between them by just referring to the field (1 and 2)

put field 1 into field 2

But if you want to put unicodeText into a field you need to set its unicodeText property (3 and 4)

set the unicodeText of field 2 to the unicodeText of field 1

Using character chunk expressions with unicodeText

When manipulating Unicode text in Rev you can use character chunk expressions just as you usually would, but you must remember to use the unicodeText of the field rather than just a reference to the field or the text of the field.

set the unicodeText of field 2 to character 1 to 10 of the unicodeText of field 1

Remember each Unicode character is represented by 2 bytes so to display a single character you need to get 2 characters of the unicodeText. Thats why what looks like 5 characters is character 1 to 10.

Other types of chunk expression such as word and item cannot be used directly with unicodeText but they can be used, we will look at how later in the lesson.

Unicode and buttons

So far we have only discussed Unicode in fields, what if you want to use Unicode text to label a button? You need to use a different method for this as buttons don't have a unicodeText property.

Instead we need to set the textFont of the button to a Unicode font and then set the label of the button, Unicode textFont names in Rev are in the form

font name, language

font name is the name of an installed font and language is the name of the language you want to display, for displaying Unicode text it should always be "unicode". To use Russian text as the label for a button we would set the textFont to "Arial,Unicode".

set the textFont of button 1 to "Arial,Unicode"
set the label of button 1 to the unicodeText of field 1

Single and Double Byte Encoding and UTF-8

UTF-8 is the best method to store and transfer Unicode text in Rev. UTF-8 is part of the Unicode standard, and is a way to store Unicode (double-byte) text in an ASCII (single-byte) text file this is especially important for encoding Unicode text for use in web browsers and email.

They keys to using UTF-8 text within Rev are the uniEncode() and uniDecode() functions. These funtions convert between single-byte and double-byte characters so you can convert UTF-8 to Unicode and then display it in a field or as a button label.

Importing text from a UTF-8 file

To import text from a UTF-8 file and display it in our stack we just need to read it in, uniEncode() it and then display it as we learnt earlier.

put url ("file:greek.txt") into tUnicodeText
set the unicodeText of field 1 to uniEncode(tUnicodeText,"UTF8")

If we want to export text from our stack we simply go in the other direction

put uniDecode(the unicodeText of field 1,"UTF8") into tUTF8Text
put tUTF8Text into url("file:greek2.txt")

Using chunk experssions with UTF-8

A big advantage of UTF-8 is that it preserves ASCII characters, so it preserves the default chunk characters - return, space, tab and comma. This means that, by using UTF-8 as an intermediate stage, we can use the chunk expressions that don't work directly with unicodeText.

put uniDecode(the unicodeText of field 1,"UTF8") into tText
set the unicodeText of field 2 to uniEncode(word 1 of tText,"UTF8")

  • Prev: How can I search delimited data for a matching string?
  • Next: How to count upper and lower case characters

Comments (0)

Add your comment

E-Mail me when someone replies to this comment
Brought to you by RunRev Ltd, Registered in Scotland, No. SC200728