From 0406fca7d12e2f7ca4946717cfac670b1f26ad8d Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Sun, 2 Aug 2009 12:36:21 +0000 Subject: Add EastAsianWidth utility to check ICU via JNI git-svn-id: https://connectbot.googlecode.com/svn/trunk/connectbot@382 df292f66-193f-0410-a5fc-6d59da041ff2 --- AndroidManifest.xml | 2 +- libs/armeabi/libcbicu.so | Bin 0 -> 3513 bytes src/de/mud/terminal/vt320.java | 4 +-- src/org/connectbot/service/Relay.java | 38 +++++++++++++++++++++++----- src/org/connectbot/util/EastAsianWidth.java | 20 +++++++++++++++ 5 files changed, 55 insertions(+), 9 deletions(-) create mode 100755 libs/armeabi/libcbicu.so create mode 100644 src/org/connectbot/util/EastAsianWidth.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 3c6001f..8307a14 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2,7 +2,7 @@ + android:versionCode="183"> 0) { //markLine(R, 1); int lastChar = -1; @@ -112,7 +112,7 @@ public abstract class vt320 extends VDUBuffer implements VDUInput { putChar((char) lastChar, isWide, false); lastChar = c; if (fullwidths != null) - isWide = fullwidths[i]; + isWide = fullwidths[i] == 1; } } } diff --git a/src/org/connectbot/service/Relay.java b/src/org/connectbot/service/Relay.java index 22b8299..e9ff6c5 100644 --- a/src/org/connectbot/service/Relay.java +++ b/src/org/connectbot/service/Relay.java @@ -29,6 +29,7 @@ import java.nio.charset.CoderResult; import java.nio.charset.CodingErrorAction; import org.connectbot.transport.AbsTransport; +import org.connectbot.util.EastAsianWidth; import android.util.Log; import de.mud.terminal.vt320; @@ -41,10 +42,13 @@ public class Relay implements Runnable { private static final int BUFFER_SIZE = 4096; + private static boolean useJNI = true; + private TerminalBridge bridge; private Charset currentCharset; private CharsetDecoder decoder; + private boolean isLegacyEastAsian = false; private AbsTransport transport; @@ -56,6 +60,15 @@ public class Relay implements Runnable { private byte[] byteArray; private char[] charArray; + static { + try { + System.loadLibrary("cbicu"); + } catch (UnsatisfiedLinkError e) { + Log.e(TAG, "Could not load cbicu library; using fallback width measurement method", e); + useJNI = false; + } + } + public Relay(TerminalBridge bridge, AbsTransport transport, vt320 buffer, String encoding) { setCharset(encoding); this.bridge = bridge; @@ -92,8 +105,15 @@ public class Relay implements Runnable { byteBuffer = ByteBuffer.allocate(BUFFER_SIZE); charBuffer = CharBuffer.allocate(BUFFER_SIZE); - float[] widths = new float[BUFFER_SIZE]; - boolean[] fullwidths = new boolean[BUFFER_SIZE]; + /* for both JNI and non-JNI method */ + byte[] wideAttribute = new byte[BUFFER_SIZE]; + + /* non-JNI fallback method */ + float[] widths = null; + + if (!useJNI) { + widths = new float[BUFFER_SIZE]; + } byteArray = byteBuffer.array(); charArray = charBuffer.array(); @@ -128,11 +148,17 @@ public class Relay implements Runnable { } offset = charBuffer.position(); - bridge.defaultPaint.getTextWidths(charArray, 0, offset, widths); - for (int i = 0; i < offset; i++) - fullwidths[i] = (int)widths[i] != charWidth; - buffer.putString(charArray, fullwidths, 0, charBuffer.position()); + if (!useJNI) { + bridge.defaultPaint.getTextWidths(charArray, 0, offset, widths); + for (int i = 0; i < offset; i++) + wideAttribute[i] = + (byte) (((int)widths[i] != charWidth) ? 1 : 0); + } else { + EastAsianWidth.measure(charArray, 0, charBuffer.position(), + wideAttribute, isLegacyEastAsian); + } + buffer.putString(charArray, wideAttribute, 0, charBuffer.position()); charBuffer.clear(); bridge.redraw(); } diff --git a/src/org/connectbot/util/EastAsianWidth.java b/src/org/connectbot/util/EastAsianWidth.java new file mode 100644 index 0000000..d99d06f --- /dev/null +++ b/src/org/connectbot/util/EastAsianWidth.java @@ -0,0 +1,20 @@ +/** + * + */ +package org.connectbot.util; + +/** + * @author Kenny Root + * + */ +public class EastAsianWidth { + /** + * @param charArray + * @param i + * @param position + * @param wideAttribute + * @param isLegacyEastAsian + */ + public native static void measure(char[] charArray, int start, int end, + byte[] wideAttribute, boolean isLegacyEastAsian); +} -- cgit v1.2.3