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

[STR New]

Link: http://www.fltk.org/str.php?L2376
Version: 1.3-feature


Clarifications

Do I understand it correctly that the Fl_Text_* range is supposed to cope
with some kind of extended ASCII *and* UTF8 at the same time? As far as I
can tell the current implementation does navigate and render neither ASCII
text (means: extended ASCII in the local German code page) nor UTF8 text
properly with the given example.


|=---=[ OS note

Same problem as initially described on Linux.


|=---=[ General note on the test/editor example

The given text "Rügenwälder Ruß." is already UTF8 encoded. I think that
at least legal UTF8 should be supported without exceptions to code pages or
whatever.
You should at least offer the possibility to mark a text buffer as pure
UTF8 if special code page handling is "generally accepted".


|=---=[ Navigation clarification

This looks plain wrong to me:
    char c = buffer()->character( pos );
    if (!((c & 0x80) && !(c & 0x40))) ok = 1;

The meaning of this is to detect UTF8 continuation characters, but
Fl_Text_Buffer::character() does not return the binary character at the
given position, it returns a Unicode value. This function happens to work
for plain ASCII text.


|=---=[ Rendering clarification

The erasing and rendering loops both iterate with (outer loop) and without
(inner loop) UTF8 awareness. This is a lengthy patch for a part of
Fl_Text_Buffer::draw_vline() that doesn't improve readability, but at
least tries to make the inner loop UTF8 aware as well.

  for (charIndex = startIndex;
       charIndex < rightCharIndex;
       charIndex += lineStr ? fl_utf8len(lineStr[charIndex]) : 1 )
  {
    charLen = charIndex >= lineLen ? 1 :
              Fl_Text_Buffer::expand_character( lineStr+charIndex,
outIndex, expandedChar,
                                                buf->tab_distance());
    charStyle = position_style( lineStartPos, lineLen, charIndex,
                                outIndex + dispIndexOffset );
    for ( i = 0; i < charLen; /*i++*/ ) { // FIXME: this rips apart the
utf-8 sequneces
      if ( i != 0 && charIndex < lineLen && lineStr[ charIndex ] == '\t' )
        charStyle = position_style( lineStartPos, lineLen,
                                    charIndex, outIndex + dispIndexOffset
);
      if ( charStyle != style ) {
        draw_string( style|BG_ONLY_MASK, sX, Y, X, outStr, outPtr - outStr
);
        outPtr = outStr;
        sX = X;
        style = charStyle;
      }
      int l = 1;
      if ( charIndex < lineLen ) {
        char theChar = expandedChar[ i ];
        //int l = 1;
        if (theChar & 0x80) {
          l = fl_utf8len(theChar);
          if (l<=0) l = 1;
        }
        charWidth = string_width( &expandedChar[ i ], l, charStyle );
        // copy the whole UTF8 sequence
        for (int code_i = 0; code_i < l; code_i++) {
          *outPtr++ = expandedChar[ i + code_i ];
          outIndex++;
        }
      } else {
        charWidth = stdCharWidth;
        outPtr++;
        outIndex++;
      }
      X += charWidth;
      // advance the UTF8 code length
      i += l;
    }
    if ( outPtr - outStr + FL_TEXT_MAX_EXP_CHAR_LEN >= MAX_DISP_LINE_LEN
|| X >= rightClip )
      break;
  }
  draw_string( style|BG_ONLY_MASK, sX, Y, X, outStr, outPtr - outStr );

  /* now draw the text over the previously erased background */
  outPtr = outStr;
  outIndex = outStartIndex;
  X = startX;
  for (charIndex = startIndex;
       charIndex < rightCharIndex;
       charIndex += lineStr ? fl_utf8len(lineStr[charIndex]) : 1)
  {
    charLen = charIndex >= lineLen ? 1 :
              Fl_Text_Buffer::expand_character( lineStr+charIndex,
outIndex, expandedChar,
                                                buf->tab_distance());
    charStyle = position_style( lineStartPos, lineLen, charIndex,
                                outIndex + dispIndexOffset );
    for ( i = 0; i < charLen; /*i++*/ ) { // FIXME: this rips apart the
utf-8 sequneces
      if ( i != 0 && charIndex < lineLen && lineStr[ charIndex ] == '\t' )
        charStyle = position_style( lineStartPos, lineLen,
                                    charIndex, outIndex + dispIndexOffset
);
      if ( charStyle != style ) {
        draw_string( style|TEXT_ONLY_MASK, startX, Y, X, outStr, outPtr -
outStr );
        outPtr = outStr;
        startX = X;
        style = charStyle;
      }
      int l = 1;
      if ( charIndex < lineLen ) {
        char theChar = expandedChar[ i ];
        //int l = 1;
        if (theChar & 0x80) {
          l = fl_utf8len(theChar);
          if (l<=0) l = 1;
        }
        charWidth = string_width( &expandedChar[ i ], l, charStyle );
        // copy the whole UTF8 sequence
        for (int code_i = 0; code_i < l; code_i++) {
          *outPtr++ = expandedChar[ i + code_i ];
          outIndex++;
        }
      } else {
        charWidth = stdCharWidth;
        outPtr++;
        outIndex++;
      }
      X += charWidth;
      // advance the UTF8 code length
      i += l;
    }
    if ( outPtr - outStr + FL_TEXT_MAX_EXP_CHAR_LEN >= MAX_DISP_LINE_LEN
|| X >= rightClip )
      break;
  }


Link: http://www.fltk.org/str.php?L2376
Version: 1.3-feature

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

Reply via email to