Re: Unicode text editor for Mac?

From: David Goldsmith (goldsmith@apple.com)
Date: Fri Feb 07 1997 - 20:15:37 EST


>Can anyone recommend a Mac application that can view and edit Unicode text? I
>don't need anything fancy, but I have not been able to find a single
>program on
>the Mac that handles Unicode.

I'm afraid that Unicode support on the Mac is pretty poor right now. The
only way I am aware of to edit or view Unicode text on the Mac right now
is to write a Java application that does so and run it using Apple's
Macintosh Runtime for Java (MRJ) 1.0. MRJ 1.0 supports display of Unicode
via drawing, and editing via the AWT TextArea. There are several sample
programs around that use TextArea to make a simple editor. You can read
and write UCS-2 or UTF-8 files. I've attached the source for a very
simple one at the end of this message.

CyberDog 1.2 or later also has some support for Unicode, but I don't
think it will read or write a file.

For either MRJ or CyberDog, you need to have the appropriate Macintosh
scripts and fonts installed to view the corresponding portion of Unicode.
For example, you won't be able to view or edit Japanese unless you have a
Japanese Mac OS or the Japanese Language Kit installed. You might be able
to view Japanese using the Korean Language Kit, as I believe that font
covers all the common Japanese characters. Anyway, you get the idea.

We are about to release an SDK for our Text Encoding Converter, which
supports conversion between Unicode and other character sets, and makes
it possible to do some Unicode display and editing via WorldScript. I
expect more apps to support Unicode directly over the next year or so.

// Modified to support Unicode files by David Goldsmith, Apple Computer,
Inc.
// December 5, 1996. Based on the "Java in a Nutshell" example cited
below.

// This example is from the book _Java in a Nutshell_ by David Flanagan.
// Written by David Flanagan. Copyright (c) 1996 O'Reilly & Associates.
// You may study, use, modify, and distribute this example for any
purpose.
// This example is provided WITHOUT WARRANTY either expressed or implied.

import java.awt.*;
import java.io.*;

public class UniViewer extends Frame {
    Button close;
    // Query the size of the specified file, create an array of bytes big
    // enough, and read it in. Then create a TextArea to display the text
    // and a "Close" button to pop the window down.
    public UniViewer(String filename) throws IOException {
        super("UniViewer: " + filename);
        File f = new File(filename);
        int size = (int) f.length();
        FileInputStream in = new FileInputStream(f);
        DataInputStream data = new DataInputStream(in);
        StringBuffer buffer = new StringBuffer(size/2);
        int charsDone = 0;
        try {
                char c;
                while (true) {
                        c = data.readChar();
                        if (c != '\uFEFF') {
                                buffer.append(c);
                                charsDone += 1;
                        }
                }
        }
        catch (EOFException e) {
                
        }
        
        TextArea textarea = new TextArea(buffer.toString(), 24, 80);
        // textarea.setFont(new Font("Times", Font.PLAIN, 12));
        textarea.setEditable(false);
        this.add("Center", textarea);
        
        close = new Button("Close");
        this.add("South", close);
        this.pack();
        this.show();
    }
    
    // Handle the close button by popping this window down
    public boolean action(Event e, Object what) {
        if (e.target == close) {
            this.hide();
            this.dispose();
            return true;
        }
        return false;
    }
    
    // The UniViewer can be used by other classes, or it can be
    // used standalone with this main() method.
    static public void main(String[] args) throws IOException {
            String fileName;
        if (args.length != 1) {
                FileDialog dialog = new FileDialog(null, "Choose a file");
                dialog.show();
                fileName = dialog.getDirectory() + File.separator +
dialog.getFile();
        }
        else
                fileName = args[0];
        try { Frame f = new UniViewer(fileName); }
        catch (IOException e) { System.out.println(e); }
    }
}

David Goldsmith
Text and International Software Architect
Apple Computer, Inc.
goldsmith@apple.com



This archive was generated by hypermail 2.1.2 : Tue Jul 10 2001 - 17:20:34 EDT