Author: engelsman
Date: 2010-04-20 14:43:31 -0700 (Tue, 20 Apr 2010)
New Revision: 7551
Log:
added implementations of fl_wcwidth_() and fl_wcwidth() to src/fl_utf.c
these supercede the old fl_wcwidth() code in src/xutf8/fl_wcwidth.c.
also added corresponding declarations to FL/fl_utf.c, and updated
src/Fl_Text_Buffer.c to enable the call to fl_wcwidth()
Modified:
branches/branch-1.3/FL/fl_utf8.h
branches/branch-1.3/src/Fl_Text_Buffer.cxx
branches/branch-1.3/src/fl_utf.c
Modified: branches/branch-1.3/FL/fl_utf8.h
===================================================================
--- branches/branch-1.3/FL/fl_utf8.h 2010-04-20 20:20:15 UTC (rev 7550)
+++ branches/branch-1.3/FL/fl_utf8.h 2010-04-20 21:43:31 UTC (rev 7551)
@@ -142,6 +142,15 @@
* type of the src text. */
FL_EXPORT int fl_utf8test(const char *src, unsigned len);
+/* XX: return width of "raw" ucs character in columns.
+ * for internal use only */
+FL_EXPORT int fl_wcwidth_(unsigned int ucs);
+
+/* XX: return width of utf-8 character string in columns.
+ * NOTE: this may also do C1 control character (0x80 to 0x9f) to CP1252
mapping,
+ * depending on original build options */
+FL_EXPORT int fl_wcwidth(const char *src);
+
/* OD: Return true if the character is non-spacing */
FL_EXPORT unsigned int fl_nonspacing(unsigned int ucs);
Modified: branches/branch-1.3/src/Fl_Text_Buffer.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Text_Buffer.cxx 2010-04-20 20:20:15 UTC (rev
7550)
+++ branches/branch-1.3/src/Fl_Text_Buffer.cxx 2010-04-20 21:43:31 UTC (rev
7551)
@@ -1025,8 +1025,8 @@
int len = fl_utf8len(c);
int ret = 0;
unsigned int ucs = fl_utf8decode(src, src+len, &ret);
- int width = 1; // mk_wcwidth((wchar_t)ucs); // FIXME
- // fprintf(stderr, "mk_wcwidth(%x) -> %d (%d, %d, %s)\n", ucs, width, len,
ret, s);
+ int width = fl_wcwidth_(ucs); // FIXME
+ // fprintf(stderr, "mk_wcwidth(%x) -> %d (%d, %d, %s)\n", ucs, width, len,
ret, src);
return width;
}
if ((c & 0x80) && !(c & 0x40)) { // other byte of UTF-8 sequence
Modified: branches/branch-1.3/src/fl_utf.c
===================================================================
--- branches/branch-1.3/src/fl_utf.c 2010-04-20 20:20:15 UTC (rev 7550)
+++ branches/branch-1.3/src/fl_utf.c 2010-04-20 21:43:31 UTC (rev 7551)
@@ -856,6 +856,51 @@
return ret;
}
+/* forward declare mk_wcwidth() as static so the name is not visible.
+ */
+ static int mk_wcwidth(unsigned int ucs);
+
+ /* include the c source directly so it's contents are only visible here
+ */
+#include "xutf8/mk_wcwidth.c"
+
+/** wrapper to adapt Markus Kuhn's implementation of wcwidth() for FLTK
+ \param [in] ucs Unicode character value
+ \returns width of character in columns
+
+ This is an implementation of wcwidth() and wcswidth()
+ (defined in IEEE Std 1002.1-2001) for Unicode.
+ See http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
+
+ WARNING: this function returns widths for "raw" Unicode characters.
+ It does not even try to map C1 control characters (0x80 to 0x9F) to
+ CP1252, and C0/C1 control characters and DEL will return -1.
+ */
+int fl_wcwidth_(unsigned int ucs) {
+ return mk_wcwidth(ucs);
+}
+
+/** extended wrapper around fl_wcwidth_(unsigned int ucs) function.
+ \param[in] src pointer to start of UTF-8 byte sequence
+ \returns width of character in columns
+
+ Depending on build options, this function may map C1 control
+ characters (0x80 to 0x9f) to CP1252, and return the width of
+ that character instead. This is not the same behaviour as
+ fl_wcwidth_(unsigned int ucs) .
+
+ Note that other control characters and DEL will still return -1,
+ so if you want different behaviour, you need to test for those
+ characters before calling fl_wcwidth(), and handle them separately.
+ */
+int fl_wcwidth(const char* src) {
+ int len = fl_utf8len(*src);
+ int ret = 0;
+ unsigned int ucs = fl_utf8decode(src, src+len, &ret);
+ int width = fl_wcwidth_(ucs);
+ return width;
+}
+
/** @} */
/*
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit