DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2761
Version: 1.3-current


This adds an option to force long words to break if they don't fit the
width in fl_expand_text (which is used by the various fl_draw and
fl_measure functions).  This is especially helpful in things like
fl_choice or other situations where all data must show. The option is
enabled by setting fl_force_wrap_breaks=1.  This was lightly tested
against some strings that were causing fl_choice to cut off text. Full
test probably needed, especially against non-printable data (< ' ' or 127)
that is converted to ^X format.


Link: http://www.fltk.org/str.php?L2761
Version: 1.3-current
Index: FL/fl_draw.H
===================================================================
--- FL/fl_draw.H        (revision 9166)
+++ FL/fl_draw.H        (working copy)
@@ -34,7 +34,9 @@
 
 // Label flags...
 FL_EXPORT extern char fl_draw_shortcut;
+FL_EXPORT extern char fl_force_wrap_breaks; // option set by app and/or widgets
 
+
 /** \addtogroup fl_attributes
     @{
 */
Index: src/fl_draw.cxx
===================================================================
--- src/fl_draw.cxx     (revision 9166)
+++ src/fl_draw.cxx     (working copy)
@@ -32,9 +32,13 @@
 #include <ctype.h>
 #include <math.h>
 
+// GCC nor FLTK build environment set NDEBUG on release builds.
+//#include <assert.h>
+
 #define MAXBUF 1024
 
 char fl_draw_shortcut; // set by fl_labeltypes.cxx
+char fl_force_wrap_breaks; // option set by app and/or widgets
 
 static char* underline_at;
 
@@ -119,11 +123,36 @@
       // test for word-wrap:
       if (word_start < p && wrap) {
        double newwidth = w + fl_width(word_end, o-word_end);
-       if (word_end > buf && newwidth > maxw) { // break before this word
+        // determine if line too long
+        if (newwidth > maxw) {
+          // determine if prior word output that fits
+          if (word_end > buf) {
+            // go back to the end of the prior word
          o = word_end;
          p = word_start;
          break;
        }
+          // determine if this line has no spaces and is too long
+          else if (word_end == buf && fl_force_wrap_breaks) {
+            // truncate to maxw
+            while (newwidth > maxw && p > word_start) {
+              // move back to prior char
+              o--;
+              p--;
+              // handle encoded characters in output buffer
+              int tc=*p & 255;
+              if (tc < ' ' || tc == 127) {
+                o--;
+              }
+              // sanity check in debugging mode
+              //assert(o >= buf);
+              // calculate new width again
+              newwidth = w + fl_width(word_end, o-word_end);
+            }
+            // leave the rest of this long word for the next line
+            break;
+          }
+        }
        word_end = o;
        w = newwidth;
       }
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to