[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs qe.h charset.c tty.c
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs qe.h charset.c tty.c |
Date: |
Thu, 02 Jan 2014 11:28:30 +0000 |
CVSROOT: /sources/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 14/01/02 11:28:30
Modified files:
. : qe.h charset.c tty.c
Log message:
added generic utility function unicode_glyph_tty_width in charset.c
* moved and improved code from tty_term_glyph_width
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.104&r2=1.105
http://cvs.savannah.gnu.org/viewcvs/qemacs/charset.c?cvsroot=qemacs&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/qemacs/tty.c?cvsroot=qemacs&r1=1.51&r2=1.52
Patches:
Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -b -r1.104 -r1.105
--- qe.h 27 Dec 2013 01:54:12 -0000 1.104
+++ qe.h 2 Jan 2014 11:28:30 -0000 1.105
@@ -1,8 +1,8 @@
/*
* QEmacs, tiny but powerful multimode editor
*
- * Copyright (c) 2000,2001 Fabrice Bellard.
- * Copyright (c) 2000-2013 Charlie Gordon.
+ * Copyright (c) 2000-2001 Fabrice Bellard.
+ * Copyright (c) 2000-2014 Charlie Gordon.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -516,6 +516,7 @@
int decode_8bit(CharsetDecodeState *s);
u8 *encode_8bit(QECharset *charset, u8 *q, int c);
+int unicode_glyph_tty_width(unsigned int ucs);
int unicode_to_charset(char *buf, unsigned int c, QECharset *charset);
/* arabic.c */
Index: charset.c
===================================================================
RCS file: /sources/qemacs/qemacs/charset.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- charset.c 21 May 2008 06:42:32 -0000 1.24
+++ charset.c 2 Jan 2014 11:28:30 -0000 1.25
@@ -1,8 +1,8 @@
/*
* Basic Charset functions for QEmacs
*
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
- * Copyright (c) 2002-2008 Charlie Gordon.
+ * Copyright (c) 2000-2002 Fabrice Bellard.
+ * Copyright (c) 2002-2014 Charlie Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -23,7 +23,64 @@
QECharset *first_charset;
-/* specific tables */
+/* Unicode utilities */
+
+/* Compute tty width of unicode characters. This is a modified
+ * implementation of wcwidth() from Markus Kuhn. We do not handle non
+ * spacing and enclosing combining characters and control chars.
+ */
+
+static unsigned int const unicode_glyph_ranges[] = {
+ 0x10FF, 1, 0x115f, 2, /* 0: Hangul Jamo */
+ 0x2328, 1, 0x232a, 2, /* 2: wide Angle brackets */
+ 0x2E7F, 1, 0x2efd, 2, /* 4: CJK Radicals */
+ 0x2EFF, 1, 0x303e, 2, /* 6: Kangxi Radicals */
+ 0x303F, 1, 0x4dbf, 2, /* 8: CJK */
+ 0x4DFF, 1, 0xa4cf, 2, /* 10: CJK */
+ 0xABFF, 1, 0xd7a3, 2, /* 12: Hangul Syllables */
+ 0xF8FF, 1, 0xfaff, 2, /* 14: CJK Compatibility Ideographs */
+ 0xFDFF, 1, 0xFE1F, 2, /* 16: */
+ 0xFE2F, 1, 0xfe6f, 2, /* 18: CJK Compatibility Forms */
+ 0xFEFF, 1, 0xff5f, 2, /* 20: Fullwidth Forms */
+ 0xFFDF, 1, 0xffe6, 2, /* 22: */
+ 0x1FFFF, 1, 0x3fffd, 2, /* 24: CJK Compatibility */
+ UINT_MAX, 1, /* 26: catchall */
+};
+
+static unsigned int const unicode_glyph_range_index[16] = {
+ 2 * 0, /* 0000-0FFF */
+ 2 * 0, /* 1000-1FFF */
+ 2 * 2, /* 2000-2FFF */
+ 2 * 7, /* 3000-3FFF */
+ 2 * 9, /* 4000-4FFF */
+ 2 * 11, /* 5000-5FFF */
+ 2 * 11, /* 6000-6FFF */
+ 2 * 11, /* 7000-7FFF */
+ 2 * 11, /* 8000-8FFF */
+ 2 * 11, /* 9000-9FFF */
+ 2 * 11, /* A000-AFFF */
+ 2 * 13, /* B000-BFFF */
+ 2 * 13, /* C000-CFFF */
+ 2 * 13, /* D000-DFFF */
+ 2 * 14, /* E000-EFFF */
+ 2 * 14, /* F000-FFFF */
+};
+
+int unicode_glyph_tty_width(unsigned int ucs)
+{
+ unsigned int const *ip;
+
+ /* Iterative lookup with fast initial jump, no boundary test needed */
+ ip = unicode_glyph_ranges + unicode_glyph_range_index[(ucs >> 12) & 0xF];
+
+ while (ucs > ip[0]) {
+ ip += 2;
+ }
+ return ip[1];
+}
+
+/* utf-8 specific tables */
+
static unsigned short table_idem[256];
static unsigned short table_utf8[256];
static unsigned short table_none[256];
@@ -286,6 +343,12 @@
if (c < 0x80 || c >= 0xc0)
nb_chars++;
}
+ /* CG: nb_chars is the number of character boundaries, trailing
+ * utf-8 sequence at start of buffer is ignored in count while
+ * incomplete utf-8 sequence at end of buffer is counted. This may
+ * cause problems when counting characters with eb_get_pos with an
+ * offset falling indside an utf-8 sequence.
+ */
return nb_chars;
}
Index: tty.c
===================================================================
RCS file: /sources/qemacs/qemacs/tty.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -b -r1.51 -r1.52
--- tty.c 17 Dec 2013 16:06:35 -0000 1.51
+++ tty.c 2 Jan 2014 11:28:30 -0000 1.52
@@ -1,8 +1,8 @@
/*
* TTY handling for QEmacs
*
- * Copyright (c) 2000,2001 Fabrice Bellard.
- * Copyright (c) 2002-2013 Charlie Gordon.
+ * Copyright (c) 2000-2001 Fabrice Bellard.
+ * Copyright (c) 2002-2014 Charlie Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -879,65 +879,13 @@
qe_free(&font);
}
-/*
- * Modified implementation of wcwidth() from Markus Kuhn. We do not
- * handle non spacing and enclosing combining characters and control
- * chars.
- */
-
-static unsigned int const tty_term_glyph_ranges[] = {
- 0x10FF, 1, 0x115f, 2, /* 0: Hangul Jamo */
- 0x2328, 1, 0x232a, 2, /* 1: wide Angle brackets */
- 0x2E7F, 1, 0x2efd, 2, /* 2: CJK Radicals */
- 0x2EFF, 1, 0x303e, 2, /* 3: Kangxi Radicals */
- 0x303F, 1, 0x4dbf, 2, /* 4: CJK */
- 0x4DFF, 1, 0xa4cf, 2, /* 5: CJK */
- 0xABFF, 1, 0xd7a3, 2, /* 6: Hangul Syllables */
- 0xF8FF, 1, 0xfaff, 2, /* 7: CJK Compatibility Ideographs */
- 0xFDFF, 1, 0xFE1F, 2, /* 8: */
- 0xFE2F, 1, 0xfe6f, 2, /* 9: CJK Compatibility Forms */
- 0xFEFF, 1, 0xff5f, 2, /* 10: Fullwidth Forms */
- 0xFFDF, 1, 0xffe6, 2, /* 11: */
- 0x1FFFF, 1, 0x3fffd, 2, /* 12: CJK Compatibility */
- UINT_MAX, 1, /* 13: catchall */
-};
-
-static unsigned int const tty_term_glyph_index[16] = {
- 4 * 0, /* 0000-0FFF */
- 4 * 0, /* 1000-1FFF */
- 4 * 1, /* 2000-2FFF */
- 4 * 3, /* 3000-3FFF */
- 4 * 4, /* 4000-4FFF */
- 4 * 5, /* 5000-5FFF */
- 4 * 5, /* 6000-6FFF */
- 4 * 5, /* 7000-7FFF */
- 4 * 5, /* 8000-8FFF */
- 4 * 5, /* 9000-9FFF */
- 4 * 5, /* A000-AFFF */
- 4 * 6, /* B000-BFFF */
- 4 * 6, /* C000-CFFF */
- 4 * 6, /* D000-DFFF */
- 4 * 7, /* E000-EFFF */
- 4 * 7, /* F000-FFFF */
-};
-
-static int tty_term_glyph_width(__unused__ QEditScreen *s, unsigned int ucs)
+static inline int tty_term_glyph_width(__unused__ QEditScreen *s, unsigned int
ucs)
{
- unsigned int const *ip;
-
/* fast test for majority of non-wide scripts */
if (ucs < 0x1100)
return 1;
- /* Iterative lookup with fast initial jump, no boundary test needed */
- ip = tty_term_glyph_ranges +
- tty_term_glyph_index[(ucs >> 12) & 0xF] - 2;
-
- for (;;) {
- ip += 2;
- if (ucs <= ip[0])
- return ip[1];
- }
+ return unicode_glyph_tty_width(ucs);
}
static void tty_term_text_metrics(QEditScreen *s, __unused__ QEFont *font,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs qe.h charset.c tty.c,
Charlie Gordon <=