Author: matt
Date: 2009-09-23 14:32:23 -0700 (Wed, 23 Sep 2009)
New Revision: 6899
Log:
File Chooser now also recognizes utf8 encoded text files. STR 2218.

Modified:
   branches/branch-1.3/CHANGES
   branches/branch-1.3/src/Fl_File_Chooser2.cxx

Modified: branches/branch-1.3/CHANGES
===================================================================
--- branches/branch-1.3/CHANGES 2009-09-23 20:43:27 UTC (rev 6898)
+++ branches/branch-1.3/CHANGES 2009-09-23 21:32:23 UTC (rev 6899)
@@ -1,5 +1,7 @@
 CHANGES IN FLTK 1.3.0
 
+       - File chooser preview now recognizes utf8 encoded 
+         text files (STR #2218)
        - Empty functions in Fluid no longer create an
          implementation (STR #2259)
        - Fixed Fluid dependency on X11 (STR #2261)

Modified: branches/branch-1.3/src/Fl_File_Chooser2.cxx
===================================================================
--- branches/branch-1.3/src/Fl_File_Chooser2.cxx        2009-09-23 20:43:27 UTC 
(rev 6898)
+++ branches/branch-1.3/src/Fl_File_Chooser2.cxx        2009-09-23 21:32:23 UTC 
(rev 6899)
@@ -1332,10 +1332,37 @@
     window->cursor(FL_CURSOR_DEFAULT);
     Fl::check();
 
-    // Scan the buffer for printable chars...
-    for (ptr = preview_text_;
+    // Scan the buffer for printable UTF8 chars...
+    for (ptr = preview_text_; *ptr; ptr++) {
+      uchar c = uchar(*ptr);
+      if ( (c&0x80)==0 ) {
+        if (!isprint(c&255) && !isspace(c&255)) break;
+      } else if ( (c&0xe0)==0xc0 ) {
+        if (ptr[1] && (ptr[1]&0xc0)!=0x80) break;
+        ptr++;
+      } else if ( (c&0xf0)==0xe0 ) {
+        if (ptr[1] && (ptr[1]&0xc0)!=0x80) break;
+        ptr++;
+        if (ptr[1] && (ptr[1]&0xc0)!=0x80) break;
+        ptr++;
+      } else if ( (c&0xf8)==0xf0 ) {
+        if (ptr[1] && (ptr[1]&0xc0)!=0x80) break;
+        ptr++;
+        if (ptr[1] && (ptr[1]&0xc0)!=0x80) break;
+        ptr++;
+        if (ptr[1] && (ptr[1]&0xc0)!=0x80) break;
+        ptr++;
+      }
+    } 
+//         *ptr && (isprint(*ptr & 255) || isspace(*ptr & 255));
+//      ptr ++);
+
+    // Scan the buffer for printable characters in 8 bit
+    if (*ptr || ptr == preview_text_) {
+      for (ptr = preview_text_;
          *ptr && (isprint(*ptr & 255) || isspace(*ptr & 255));
         ptr ++);
+    }
 
     if (*ptr || ptr == preview_text_) {
       // Non-printable file, just show a big ?...

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to