summaryrefslogtreecommitdiff
path: root/src/Fl_Text_Buffer.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2008-09-10 23:56:49 +0000
committerMatthias Melcher <fltk@matthiasm.com>2008-09-10 23:56:49 +0000
commitb6bde2e4569aa617c8a6af64947c688c624ed7f8 (patch)
tree010d15843eb7d4faf7cd1b0cd44d5b9c00462a83 /src/Fl_Text_Buffer.cxx
parentdfb50e85292687561927610e689eb5ab30d0ba26 (diff)
Merging the UTF8 patch, consisting of O'ksi'd s original 1.1.6 patch and additions by Ian. PLEASE BE AWARE that the patch in its current incarnation is a regression in many aspects and further work is required before we can announce Unicode support.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6212 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Text_Buffer.cxx')
-rw-r--r--src/Fl_Text_Buffer.cxx54
1 files changed, 50 insertions, 4 deletions
diff --git a/src/Fl_Text_Buffer.cxx b/src/Fl_Text_Buffer.cxx
index 86d8e3398..a4bd5fbd4 100644
--- a/src/Fl_Text_Buffer.cxx
+++ b/src/Fl_Text_Buffer.cxx
@@ -27,6 +27,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <FL/fl_utf8.H>
#include "flstring.h"
#include <ctype.h>
#include <FL/Fl.H>
@@ -80,6 +81,27 @@ static int undocut; // number of characters deleted there
static int undoinsert; // number of characters inserted
static int undoyankcut; // length of valid contents of buffer, even if undocut=0
+static int utf_len(char c)
+{
+ if (!(c & 0x80)) return 1;
+ if (c & 0x40) {
+ if (c & 0x20) {
+ if (c & 0x10) {
+ if (c & 0x08) {
+ if (c & 0x04) {
+ return 6;
+ }
+ return 5;
+ }
+ return 4;
+ }
+ return 3;
+ }
+ return 2;
+ }
+ return 0;
+}
+
static void undobuffersize(int n) {
if (n > undobufferlength) {
if (undobuffer) {
@@ -197,7 +219,7 @@ void Fl_Text_Buffer::text( const char *t ) {
** include the character pointed to by "end"
*/
char * Fl_Text_Buffer::text_range( int start, int end ) {
- char * s;
+ char * s = NULL;
int copiedLength, part1Length;
/* Make sure start and end are ok, and allocate memory for returned string.
@@ -927,8 +949,22 @@ int Fl_Text_Buffer::word_end( int pos ) {
** equal in length to FL_TEXT_MAX_EXP_CHAR_LEN
*/
int Fl_Text_Buffer::expand_character( int pos, int indent, char *outStr ) {
- return expand_character( character( pos ), indent, outStr,
+ int ret;
+ char c = character( pos );
+ ret = expand_character( c, indent, outStr,
mTabDist, mNullSubsChar );
+ if (ret > 1 && (c & 0x80)) {
+ int i;
+ i = utf_len(c);
+ while (i > 1) {
+ i--;
+ pos++;
+ outStr++;
+ *outStr = character( pos );
+ }
+ }
+
+ return ret;
}
/*
@@ -962,6 +998,11 @@ int Fl_Text_Buffer::expand_character( char c, int indent, char *outStr, int tabD
} else if ( c == nullSubsChar ) {
sprintf( outStr, "<nul>" );
return 5;
+ } else if ((c & 0x80) && !(c & 0x40)) {
+ return 0;
+ } else if (c & 0x80) {
+ *outStr = c;
+ return utf_len(c);
}
/* Otherwise, just return the character */
@@ -986,6 +1027,11 @@ int Fl_Text_Buffer::character_width( char c, int indent, int tabDist, char nullS
return 5;
else if ( c == nullSubsChar )
return 5;
+ else if ((c & 0x80) && !(c & 0x40))
+ return 0;
+ else if (c & 0x80) {
+ return utf_len(c);
+ }
return 1;
}
@@ -2499,7 +2545,7 @@ static int min( int i1, int i2 ) {
int
Fl_Text_Buffer::insertfile(const char *file, int pos, int buflen) {
FILE *fp; int r;
- if (!(fp = fopen(file, "r"))) return 1;
+ if (!(fp = fl_fopen(file, "r"))) return 1;
char *buffer = new char[buflen];
for (; (r = fread(buffer, 1, buflen - 1, fp)) > 0; pos += r) {
buffer[r] = (char)0;
@@ -2515,7 +2561,7 @@ Fl_Text_Buffer::insertfile(const char *file, int pos, int buflen) {
int
Fl_Text_Buffer::outputfile(const char *file, int start, int end, int buflen) {
FILE *fp;
- if (!(fp = fopen(file, "w"))) return 1;
+ if (!(fp = fl_fopen(file, "w"))) return 1;
for (int n; (n = min(end - start, buflen)); start += n) {
const char *p = text_range(start, start + n);
int r = fwrite(p, 1, n, fp);