Author: matt
Date: 2010-04-30 15:29:08 -0700 (Fri, 30 Apr 2010)
New Revision: 7574
Log:
Removed character expansion.

Modified:
   branches/branch-1.3-STR2158-matt/FL/Fl_Text_Buffer.H
   branches/branch-1.3-STR2158-matt/src/Fl_Text_Buffer.cxx
   branches/branch-1.3-STR2158-matt/src/Fl_Text_Display.cxx

Modified: branches/branch-1.3-STR2158-matt/FL/Fl_Text_Buffer.H
===================================================================
--- branches/branch-1.3-STR2158-matt/FL/Fl_Text_Buffer.H        2010-04-30 
22:13:40 UTC (rev 7573)
+++ branches/branch-1.3-STR2158-matt/FL/Fl_Text_Buffer.H        2010-04-30 
22:29:08 UTC (rev 7574)
@@ -537,35 +537,6 @@
   int word_end(int pos) const;
   
   /**
-   Expands the given character to a displayable format. Tabs and
-   other control characters are given special treatment.
-   Get a character from the text buffer expanded into its screen
-   representation (which may be several characters for a tab or a
-   control code).  Returns the number of characters written to \p outStr.
-   \p indent is the number of characters from the start of the line
-   for figuring tabs.  Output string is guranteed to be shorter or
-   equal in length to FL_TEXT_MAX_EXP_CHAR_LEN
-   \todo unicode check
-   */
-  int expand_character(int pos, int indent, char *outStr) const;
-  
-  /**
-   Expand a single character \p c from the text buffer into it's displayable
-   screen representation (which may be several characters for a tab or a
-   control code).  Returns the number of characters added to \p outStr.
-   \p indent is the number of characters from the start of the line
-   for figuring tabs of length \p tabDist.  Output string is guaranteed 
-   to be shorter or equal in length to FL_TEXT_MAX_EXP_CHAR_LEN
-   Tabs and  other control characters are given special treatment.
-   \param src address of utf-8 text
-   \param indent 
-   \param[out] outStr write substitution here
-   \param tabDist
-   \return number of byte in substitution
-   */
-  static int expand_character(const char *src, int indent, char* outStr, int 
tabDist);
-  
-  /**
    Return the length in displayed characters of character \p c expanded
    for display (as discussed above in expand_character() ).  
    \param src address of utf-8 text
@@ -574,7 +545,6 @@
    \return number of byte in substitution
    */
   static int character_width(const char *src, int indent, int tabDist);
-  //static int character_width(const char    c, int indent, int tabDist);
 
   /**
    Count the number of displayed characters between buffer position

Modified: branches/branch-1.3-STR2158-matt/src/Fl_Text_Buffer.cxx
===================================================================
--- branches/branch-1.3-STR2158-matt/src/Fl_Text_Buffer.cxx     2010-04-30 
22:13:40 UTC (rev 7573)
+++ branches/branch-1.3-STR2158-matt/src/Fl_Text_Buffer.cxx     2010-04-30 
22:29:08 UTC (rev 7574)
@@ -70,12 +70,6 @@
 
 #endif
 
-static const char *ControlCodeTable[32] = {
-  "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
-  "bs", "ht", "nl", "vt", "np", "cr", "so", "si",
-  "dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb",
-  "can", "em", "sub", "esc", "fs", "gs", "rs", "us"
-};
 
 static char *undobuffer;
 static int undobufferlength;
@@ -679,57 +673,6 @@
 }
 
 
-// Expand from the byte representation into some readable text.
-// Under unicode, this is not really needed because all characters should
-// be prinatble one way or the other. But since we use this to (badly) simulate
-// tabs, we can leave this here anyway.
-// - unicode ok
-int Fl_Text_Buffer::expand_character(int pos, int indent, char *outStr) const {
-  const char *src = address(pos);
-  return expand_character(src, indent, outStr, mTabDist);
-}
-
-
-// static function and counterpart to "character_width"
-// - unicode ok
-// FIXME: harmonise with new character_width(char*...) version
-//
-int Fl_Text_Buffer::expand_character(const char *src, int indent, char 
*outStr, int tabDist)
-{
-  char c = *src;
-  /* Convert tabs to spaces */
-  if (c == '\t') {
-    int nSpaces = tabDist - (indent % tabDist);
-    for (int i = 0; i < nSpaces; i++)
-      outStr[i] = ' ';
-    return nSpaces;
-  }
-  
-  /* Convert control codes to readable character sequences */
-  if (((unsigned char) c) <= 31) {
-    sprintf(outStr, "<%s>", ControlCodeTable[(unsigned char) c]);
-    return strlen(outStr);
-  } else if (c == 127) {
-    sprintf(outStr, "<del>");
-    return 5;
-  } else if ((c & 0x80) && !(c & 0x40)) {
-#ifdef DEBUG
-    fprintf(stderr, "%s:%d - Error in UTF-8 encoding!\n", __FILE__, __LINE__);
-#endif
-    *outStr = c;
-    return 1;
-  } else if (c & 0x80) {
-    int i, n = fl_utf8len(c);
-    for (i=0; i<n; i++) *outStr++ = *src++;
-    return n;
-  }
-  
-  /* Otherwise, just return the character */
-  *outStr = c;
-  return 1;
-}
-
-
 // This function takes a character and optionally converts it into a little
 // string which will replace the character on screen. This function returns
 // the number of bytes in the replacement string, but *not* the number of 
@@ -779,15 +722,18 @@
 }
 #endif
 
+// FIXME: is this funciton still needed?
 int Fl_Text_Buffer::count_displayed_characters(int lineStartPos,
                                               int targetPos) const
 {
   int charCount = 0;
-  char expandedChar[FL_TEXT_MAX_EXP_CHAR_LEN];
   
   int pos = lineStartPos;
-  while (pos < targetPos)
-    charCount += expand_character(pos++, charCount, expandedChar);
+  while (pos < targetPos) {
+    int len = fl_utf8len(*address(pos));
+    charCount += 1;
+    pos += len;
+  }
   return charCount;
 } 
 

Modified: branches/branch-1.3-STR2158-matt/src/Fl_Text_Display.cxx
===================================================================
--- branches/branch-1.3-STR2158-matt/src/Fl_Text_Display.cxx    2010-04-30 
22:13:40 UTC (rev 7573)
+++ branches/branch-1.3-STR2158-matt/src/Fl_Text_Display.cxx    2010-04-30 
22:29:08 UTC (rev 7574)
@@ -1928,20 +1928,19 @@
      to find the character position corresponding to the X coordinate */
   xStep = text_area.x - mHorizOffset;
   outIndex = 0;
-  for (charIndex = 0;
-       charIndex < lineLen;
-       charIndex += fl_utf8len(lineStr[charIndex]) ) 
+  for (charIndex = 0; charIndex < lineLen; ) 
   {
-    charLen = Fl_Text_Buffer::expand_character( lineStr+charIndex, outIndex, 
expandedChar,
-              mBuffer->tab_distance());
+    // FIXME: use a unified function for this
+    charLen = fl_utf8len(lineStr[charIndex]);    
     charStyle = position_style( lineStart, lineLen, charIndex );
-    charWidth = string_width( expandedChar, charLen, charStyle );
+    charWidth = string_width( lineStr+charIndex, charLen, charStyle );
     if ( X < xStep + ( posType == CURSOR_POS ? charWidth / 2 : charWidth ) ) {
       free((char *)lineStr);
       return lineStart + charIndex;
     }
     xStep += charWidth;
     outIndex += charLen;
+    charIndex += charLen;
   }
 
   /* If the X position was beyond the end of the line, return the position
@@ -2359,6 +2358,8 @@
 int Fl_Text_Display::measure_vline( int visLineNum ) const {
   
   return 1024; // FIXME: time waster!
+  
+#if 0
   /* The line above helps us clean up this widget.
    
    The original code measures each individual character. That is not only 
@@ -2404,6 +2405,7 @@
     }
   }
   return width;
+#endif
 }
 
 /**
@@ -2828,26 +2830,13 @@
    insertion/deletion, though static display and wrapping and resizing
    should now be solid because they are now used for online help display.
 */
-
 int Fl_Text_Display::measure_proportional_character(const char *s, int colNum, 
int pos) const {
-    int charLen, style;
-    char expChar[ FL_TEXT_MAX_EXP_CHAR_LEN ];
-    Fl_Text_Buffer *styleBuf = mStyleBuffer;
-    
-  charLen = Fl_Text_Buffer::expand_character(s, colNum, expChar, 
buffer()->tab_distance()); // FIXME: unicode
-    if (styleBuf == 0) {
-       style = 0;
-    } else {
-      // FIXME: character is ucs-4
-       style = (unsigned char)styleBuf->at(pos);
-       if (style == mUnfinishedStyle && mUnfinishedHighlightCB) {
-           /* encountered "unfinished" style, trigger parsing */
-           (mUnfinishedHighlightCB)(pos, mHighlightCBArg);
-          // FIXME: character is ucs-4
-           style = (unsigned char)styleBuf->at(pos);
-       }
-    }
-    return string_width(expChar, charLen, style);
+  int charLen = fl_utf8len(*s), style = 0;
+  if (mStyleBuffer) {
+    const char *b = mStyleBuffer->address(pos);
+    style = *b;
+  }
+  return string_width(s, charLen, style);
 }
 
 /**

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

Reply via email to