Click here to Skip to main content
13,766,364 members
Click here to Skip to main content
Add your own
alternative version


25 bookmarked
Posted 27 Nov 2011
Licenced CPOL

Developing multi-lingual support as part of the development of Rashumon word processor

, 9 Oct 2013
Rate this:
Please Sign up or sign in to vote.
When I have devleoped Rashumon, there was no built in support for multi-lingual / bi-directional text and I had to develop such from scratch

Download Rashumon DTP version


This article brings some information about the development of Rashumon, and the way, basic building blocks had to be developed due to lack of SDK to provide them.


During 1989 to 1994 I have developed Rashumon, the first multi-lingual graphic word processor for the Amiga. Rashumon brought some unique features:

  • Multiple Selection of text (selecting non continious parts of text simmultaneously)

  • Table generator

  • Multiple key maps support (up to 5 simultaneously)

  • Search and replace includes color, style and font filters

    Rashumon - Search / Replace

  • Multi-lingual string gadgets to be used for creating and renaming files, drawers, etc.

  • Imports and exports multilingual ASCII files from and to PC and MAC

  • Ultra fast screen updating and scrolling

  • IFF graphics support (import and export).

  • Direct access to each one of the 256 characters per each font.


Using the code

The code samples used in this article are taken from Rashumon source code, as can be examined by any C++ compiler, even though they were created for Amiga Aztec C compiler.

Points of Interest

Now days we tend to forget some of the complexeity which was part of coding 20 years ago, and today is built in as part of any Operating System SDK, among them: bi directional editing, text editing in general, scorlling text and word wrapping.

Developing a multi-lingual graphic word for the Amiga, back in 1989, required in fact, writing parts of what would be today, part of an Operating System, but was missing back then.

Developing Rashumon

The Amiga was and still is a great computer, with great capabilities, especially when it comes to sound and video. However, basic elements such as a File Browse dialog box was missing, not to mention any support for right to left languages.

Today, all operating systems contain the core elements required to support multi-lingual text editing. The text is stored by the order it was typed, and displayed backward, when it comes to a right to left language. This makes it simple and easy to edit and manipulate it, since the storage reflects to the logical order of the text flow. Back then, there was a need to develop such building block, and it was have made my word processor too slow, had I displayed the text differently than the way it is stored. Instead, I wanted to develop a word wrapping engine of my own. Word Wrapping is the mechanism that allows breaking lines without breaking words. Unlike the old type writer, where you get to the end of the line, and sometime break a word at the middle, word processors are able to move the last typed word to the next line, in case there is not enough room for it in the current line.

That becomes even more complex when you have to deal with proportional fonts, where each character has its own width, and when you allow combining several fonts. All of the above was not part of a high level API, but required calculating the predicted length of a given text, in pixels, taking into calculation each character width based on the character and the font, attribute (bold, italics) and size used, along with the margins selected.

So even if we deal only one direction (left to right) of editing, it was still complicated to develop from scratch.

To being with, I wrote the routine to calculate a length of a given line:

int LLen=(mode==GRAPHICS)?ln->Len:(ln->CharLen=strlen(ln->Txt))*8; 

As you can see, there is a simple scenario where "mode" isn't "GRAPHICS", then the length is calculated based on the number of characters multiplied by 8 (which is the length of each character when mono spaced font is used).

When it comes to editing bi directional text using proportional and multiple fonts, it is more complex even to insert a single character:

// This is a rountine for adding a single character, taken
from Rashumon source code
static put_char(wrap,chr)
BOOL wrap;
UBYTE chr;
    UBYTE c[2];
    BOOL update=FALSE;
    // Left to right text
        if(chr>='a' && chr<='z' && map[Header->format >> 11]<2) chr=ucase(chr);
        if(Header->Insert || !HCL->Txt[CR])
            if(!wrap && HCL->Len+font_width(HCL,CR)>HCL->MaxLen) return();

// Here we add the additional size to the overall line 
//size in pixels
// Now we treat Overwrite mode
// Hebrew ( or Right to Left) mode
    if(!Header->Insert && CR)
        if(!wrap && HCL->Len+font_width(HCL,CR)>HCL->MaxLen) return();
if(HCL->Mode & TABS) calc_all(HCL);
if(c[0]!=SPACE_CHR && fonts[Header->format >> 11]->tf_YSize>LH(HCL)) 
    HCL->LineHeight=Header->LineHeight=fonts[Header->format >> 11]->tf_YSize;
    HCL->BaseLine=Header->BaseLine=fonts[Header->format >> 11]->tf_YSize-fonts[Header->format >> 11]->tf_Baseline;
if(c[0]==SPACE_CHR && HCL->prev && !(HCL->Mode & PAR) && wrap)
if(HCL->Len<=HCL->MaxLen && !(update))

The next step was to perform word wrap to bi-directional lines. As I have explained, the lines were displayed as they were stored in memory. The text "abcאבג" was stored exactly like it looks. Rashumon used double byte characters, meaning that each character was stored using 2 bytes. That was before UNICODE was invented, so the first byte was sufficient to store any character in any language supported. At that time, ASCII characters were in two forms, one form used the values from 0 to 127 and the expanded form uses values 0 to 255. I used the expanded form, and had to decide where to place the right to left languages.

There was no standard for right to left languages. IBM used places 128 to 154, but I found it problematic and chose the places starting of 224, which seems to be the right choice today, as it is identical to how right to left languages are represented today using Double Byte encoding.So if I open a floppy disk image from 1989 (.ADF file), all Rashumon Hebrew documents appear in the correct encoding.

As for the 2nd byte, it was used to store the character color (3 types, meaning up to 8 colors), font attributes (Bold, Italics and underline, or any combination between the 3), language (right to left or left to right) and the font, by pointing to an index of this font within a local list created from the entire list of fonts used per each document.

/* Line structure */
#define COLOR_BIT_1 1           /* 1  */
#define COLOR_BIT_2 2           /* 2  */
#define COLOR_BIT_3 4           /* 3  */
#define UNDL 8                  /* 4  */
#define BOLD 16                 /* 5  */
#define ITAL 32                 /* 6  */
#define SELECT 64               /* 7  */
#define LANG 128                /* 8  */
#define TAB 256                 /* 9  */
#define UNUSED_1 1024           /* 10 */
#define UNUSED_2 2048           /* 11 */
#define FONT_BIT_1 4096         /* 12 */
#define FONT_BIT_2 8192         /* 13 */
#define FONT_BIT_3 16384        /* 14 */
#define FONT_BIT_4 32768        /* 15 */
#define FONT_BIT_5 65536        /* 16 */ 

Key Mapping and Encoding


Key Mapping was used as an array of all characters per the places starting from "1" and to the end of the array.

Here is another part taken from Rashumon source code, where the keymaps are defined:

 unsigned char regmap[] = 
       ";1234567890-=\\0/'-˜€ˆ...\"[] 123(tm)ƒ‚‹'‰‡ŒŠ",  456 †'„Ž-š•. .789 ";
 unsigned char engmap[] = 
       "`1234567890-=\\0qwertyuiop[] 123asdfghjkl;'  456zxcvbnm,./ .789 ";
 unsigned char shiftmap[] = 
       "~!@#$%^&*()_+|0QWERTYUIOP{} 123ASDFGHJKL:\"  456 ZXCVBNM<>?.789 ";
 unsigned char shiftrus[] = 
       "~!@#$%^&*()_+|0°¶₪±³¸´¨(r)¯{} 123 ²£¥¦§(c)׫:\"  456 ¹·¢µ¡­¬<>? .789 ";
 unsigned char rusmap[] = 
       "`1234567890-=\\0׀ײִׁ׃״װָ־ֿ[] 123ְֳֵֶַֹֺֻׂ;'  456 ׳ֲױֱּֽ,./ .789 ";

As you can see, "regmap" is the Hebrew encoding, "engmap" is for the Latin text, "shiftmap" is for the characters typed with SHIFT button, and there was also a keymap for Russian (and later on, one for Arabic as well, thanks to John Hajjer, from Chicago, who spent a lot of time to help me release an Arabic version).

Switching between the two directions was made using a unique ruller with two versions: left to right and right to left:

(Thanks to Shimon Wiessman for the graphic design) 

Pressing the arrow, changed the direction of editing.

Scrolling Text

Even obvious things such as scrolling had to be invented back then. That includes determining how many lines of text to display, based on the current window size (Amiga windows had the ability to be resized by the end user, as well as maximized and minimized), displaying a scroll bar, and calculating the size of the scroll bar's gauge which should be proportional to the possible movement and the available scroll.

struct Line *ln;
       register SHORT distance,
       printf("BEFORE: top=%ld (%ld <> TOP=%ld) ",
       printf("bottom=%ld (%ld <> BOT=%ld)\n",
       printf("AFTER: top=%ld (%ld <> TOP=%ld) ",
       printf("bottom=%ld (%ld <> BOT=%ld)\n",

Word Wrapping Bi-Directional Text

But now let's go back to the bi-directional text word wrap. Basically, the algorithm, developed by me along with Tamer Even –Zohar, and her husband Nimrod, was based on examining a given line and if it is longer than the size between the two margins (calculating the line width in pixels, taking into calculation each character, based on it's independent attributes), we should remove the last word from it, and then check again the new length, and so on, until the line is within the width of the margins.

The first question to ask is where is the "last" word? If it is a right to left paragraph, the last word will appear first, in the buffer.

In such case, I used the following function, which in fact measured the size (in pixels) of the first word in a given buffer. The following routines are based on mono space font, which is complicated enough…

/* returns the len of the first word in s */
#define BLNK(c)      ((c)==' '
|| (c)=='\n')
margin, *blnks1, *blnks2;
    int i, j;
    for (i=margin; BLNK(s[i]) && s[i]; i++);
             *blnks1 = i;
       for (; !(BLNK(s[i])) && s[i]; i++);
       for (j=i; BLNK(s[j]) && s[i]; j++);
       *blnks2 = j-i;

If the line is a left to right one, a different function was used:

*blnks1, *blnks2, maxlen;
    register int i, j;
        if (!strlen(s)) return(0);
    for (i=strlen(s)-1; BLNK(s[i]) && i; i--);
    if (i==0) return(0); 
    *blnks1 = (strlen(s)-(i+1));
    for (i=min(maxlen,strlen(s)-1); BLNK(s[i]) && i; i--);
    for (; !(BLNK(s[i])) && i; i--);
    for (j=i; BLNK(s[j]) && j; j--);
       *blnks2 = i - j;
       return(strlen(s)- i);

Of course we do not only remove the last word from a line, but also place back the first word of the next line, when there is space available (for example, if the first word in the current line is deleted, and space becomes available), so another building block would be placing the next word (from the beginning of the next line) back to the end of the current line.

/* copies first word of length len & trailing blanks
blnks fron s2 to s1 */
       append(s2,s1,strlen(s1)+len+(blnks? 1 : 0));
       delete1(s2,0,len+(blnks ?1 : 0));

In Rashumon, the paragraph direction of text was automatically calculated by examining the encoding of each character in each line, and determining which direction is dominant. While brainstorming with Tamar Even Zohar and her husband Nimrod, we came to know that even space " " character can have a direction, and we had to decide if we wish to have Hebrew space character in addition to the Latin one. Well, this requirement became a "must", as it is needed to word wrap paragraphs with multiple languages combined.

For example:

"This is an example of a paragraph with opposed direction languages. זוהי דוגמה לפיסקה עם שילוב של שתי שפות עם כיוונים מנוגדים"

The following clip demonstrate how bi-directional text is edited by Rashumon.

Now, if you make change the margins, which word will "jump" to the next line, or "jump" back to the current line? The only way to determine that, is by knowing the direction of each character (either right to left or left to right), including special characters such as tabs, spaces, commas, etc.

Rashumon can still be downloaded from Aminet at this link.

An Article about Rashumon (UK)

Further reading

Rashumon web site

HarmonySoft web site

My Blog (hebrew)

My Blog (English)

My Coding Blog

 Michael Haephrati CodeProject MVP 2013    


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Michael Haephrati
CEO Secured Globe, Inc.
United States United States
Michael Haephrati, CEO and co-founder of Secured Globe, Inc. Worked on many ventures starting from HarmonySoft, designing Rashumon, the first Graphical Multi-lingual word processor for Amiga computer. During 1995-1996 he worked as a Contractor with Apple at Cupertino.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Pablo Aliskevicius10-Oct-13 5:20
memberPablo Aliskevicius10-Oct-13 5:20 
GeneralMy vote of 5 Pin
alonbarak14-Jun-13 12:11
groupalonbarak14-Jun-13 12:11 
GeneralMy vote of 5 Pin
25-Jan-13 2:22
suss25-Jan-13 2:22 
GeneralMy vote of 5 Pin
resi243125-Jan-13 1:18
memberresi243125-Jan-13 1:18 
GeneralMy vote of 5 Pin
24-Jan-13 23:59
suss24-Jan-13 23:59 
GeneralMy vote of 5 Pin
24-Jan-13 23:26
suss24-Jan-13 23:26 
GeneralMy vote of 5 Pin
evan89724-Jan-13 22:48
groupevan89724-Jan-13 22:48 
GeneralMessage Closed Pin
23-Jan-13 23:14
suss23-Jan-13 23:14 
GeneralMessage Closed Pin
23-Jan-13 20:58
suss23-Jan-13 20:58 
GeneralMy vote of 5 Pin
George Rogers II13-Oct-12 7:43
memberGeorge Rogers II13-Oct-12 7:43 
GeneralMy vote of 5 Pin
Emma20123217-Sep-12 7:48
memberEmma20123217-Sep-12 7:48 
AnswerRe: My vote of 5 Pin
Michael Haephrati21-Sep-17 11:28
mvpMichael Haephrati21-Sep-17 11:28 
GeneralMy vote of 5 Pin
25-Jul-12 0:43
suss25-Jul-12 0:43 
GeneralMy vote of 5 Pin
Jeff Kibling31-Jan-12 4:30
memberJeff Kibling31-Jan-12 4:30 
QuestionNice article Pin
Ganesan Senthilvel22-Jan-12 1:51
memberGanesan Senthilvel22-Jan-12 1:51 
QuestionMy vote of 5 Pin
PhotoPinka3-Jan-12 20:49
memberPhotoPinka3-Jan-12 20:49 
QuestionProblem with the download link Pin
Michael Haephrati28-Nov-11 8:29
mvpMichael Haephrati28-Nov-11 8:29 
AnswerRe: Problem with the download link Pin
Richard MacCutchan29-Nov-11 1:01
protectorRichard MacCutchan29-Nov-11 1:01 
GeneralRe: Problem with the download link Pin
Michael Haephrati30-Nov-11 5:56
mvpMichael Haephrati30-Nov-11 5:56 
GeneralRe: Problem with the download link Pin
Richard MacCutchan30-Nov-11 5:59
protectorRichard MacCutchan30-Nov-11 5:59 
GeneralMy vote of 5 Pin
td12327-Nov-11 7:47
membertd12327-Nov-11 7:47 
SuggestionImages Pin
DaveAuld27-Nov-11 6:48
protectorDaveAuld27-Nov-11 6:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.181114.1 | Last Updated 9 Oct 2013
Article Copyright 2011 by Michael Haephrati
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid