diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2008-09-10 23:56:49 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2008-09-10 23:56:49 +0000 |
| commit | b6bde2e4569aa617c8a6af64947c688c624ed7f8 (patch) | |
| tree | 010d15843eb7d4faf7cd1b0cd44d5b9c00462a83 /src/fl_draw.cxx | |
| parent | dfb50e85292687561927610e689eb5ab30d0ba26 (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_draw.cxx')
| -rw-r--r-- | src/fl_draw.cxx | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/fl_draw.cxx b/src/fl_draw.cxx index 216ec072a..0a1f55a97 100644 --- a/src/fl_draw.cxx +++ b/src/fl_draw.cxx @@ -33,6 +33,8 @@ // Aligns them against the inside of the box. #define min(a,b) ((a)<(b)?(a):(b)) +#include <FL/fl_utf8.H> +#include <FL/Fl.H> #include <FL/fl_draw.H> #include <FL/Fl_Image.H> @@ -53,11 +55,11 @@ static char* underline_at; // Sets n to the number of characters put into the buffer. // Sets width to the width of the string in the current font. -static const char* -expand(const char* from, char* buf, double maxw, int& n, double &width, - int wrap, int draw_symbols) { +const char* +fl_expand_text(const char* from, char* buf, int maxbuf, double maxw, int& n, + double &width, int wrap, int draw_symbols) { char* o = buf; - char* e = buf+(MAXBUF-4); + char* e = buf+(maxbuf-4); underline_at = 0; char* word_end = o; const char* word_start = from; @@ -88,7 +90,8 @@ expand(const char* from, char* buf, double maxw, int& n, double &width, if (o > e) break; // don't overflow buffer if (c == '\t') { - for (c = (o-buf)%8; c<8 && o<e; c++) *o++ = ' '; + for (c = fl_utf_nb_char((uchar*)buf, o-buf)%8; c<8 && o<e; c++) + *o++ = ' '; } else if (c == '&' && fl_draw_shortcut && *(p+1)) { if (*(p+1) == '&') {p++; *o++ = '&';} else if (fl_draw_shortcut != 2) underline_at = o; @@ -158,13 +161,15 @@ void fl_draw( symtotal = symwidth[0] + symwidth[1]; + if (str) { for (p = str, lines=0; p;) { - e = expand(p, buf, w - symtotal, buflen, width, align&FL_ALIGN_WRAP, - draw_symbols); + e = fl_expand_text(p, buf, MAXBUF, w - symtotal, buflen, width, + align&FL_ALIGN_WRAP, draw_symbols); lines++; if (!*e || (*e == '@' && e[1] != '@' && draw_symbols)) break; p = e; } + } else lines = 0; if ((symwidth[0] || symwidth[1]) && lines) { if (symwidth[0]) symwidth[0] = lines * fl_height(); @@ -201,8 +206,8 @@ void fl_draw( if (str) { int desc = fl_descent(); for (p=str; ; ypos += height) { - if (lines>1) e = expand(p, buf, w - symtotal, buflen, width, - align&FL_ALIGN_WRAP, draw_symbols); + if (lines>1) e = fl_expand_text(p, buf, MAXBUF, w - symtotal, buflen, + width, align&FL_ALIGN_WRAP, draw_symbols); else e = ""; if (width > symoffset) symoffset = (int)(width + 0.5); @@ -313,7 +318,9 @@ void fl_measure(const char* str, int& w, int& h, int draw_symbols) { symtotal = symwidth[0] + symwidth[1]; for (p = str, lines=0; p;) { - e = expand(p, buf, w - symtotal, buflen, width, w != 0, draw_symbols); +// e = expand(p, buf, w - symtotal, buflen, width, w != 0, draw_symbols); + e = fl_expand_text(p, buf, MAXBUF, w - symtotal, buflen, width, + w != 0, draw_symbols); if ((int)ceil(width) > W) W = (int)ceil(width); lines++; if (!*e || (*e == '@' && draw_symbols)) break; |
