mirror of
https://github.com/fltk/fltk.git
synced 2026-05-28 11:25:22 +08:00
Fixed Fl_Text_Display Tabulator calculations (STR #2450)
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7897 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
CHANGES IN FLTK 1.3.0
|
CHANGES IN FLTK 1.3.0
|
||||||
|
|
||||||
|
- Fixed Fl_Text_Display Tabulator calculations (STR #2450)
|
||||||
- Fixed file access code to use UTF-8 strings (STR #2440)
|
- Fixed file access code to use UTF-8 strings (STR #2440)
|
||||||
- Fixed ARM Unicode cross compilation issue (STR #2432)
|
- Fixed ARM Unicode cross compilation issue (STR #2432)
|
||||||
- Improved support for faulty X11 clients (STR #2385)
|
- Improved support for faulty X11 clients (STR #2385)
|
||||||
|
|||||||
+12
-31
@@ -25,10 +25,6 @@
|
|||||||
// http://www.fltk.org/str.php
|
// http://www.fltk.org/str.php
|
||||||
//
|
//
|
||||||
|
|
||||||
// TODO: fix all fixme's and todo's
|
|
||||||
// TODO: blinking selection when moving mouse outside of widget area
|
|
||||||
// TODO: line wrapping - scroll bars
|
|
||||||
// TODO: rendering of the Tab character
|
|
||||||
// TODO: rendering of the "optional hyphen"
|
// TODO: rendering of the "optional hyphen"
|
||||||
// TODO: make line numbering work again
|
// TODO: make line numbering work again
|
||||||
|
|
||||||
@@ -1744,6 +1740,7 @@ int Fl_Text_Display::handle_vline(
|
|||||||
for (i=0; i<lineLen; ) {
|
for (i=0; i<lineLen; ) {
|
||||||
currChar = lineStr[i]; // one byte is enough to handele tabs and other cases
|
currChar = lineStr[i]; // one byte is enough to handele tabs and other cases
|
||||||
int len = fl_utf8len(currChar);
|
int len = fl_utf8len(currChar);
|
||||||
|
if (len<=0) len = 1; // OUCH!
|
||||||
charStyle = position_style(lineStartPos, lineLen, i);
|
charStyle = position_style(lineStartPos, lineLen, i);
|
||||||
if (charStyle!=style || currChar=='\t' || prevChar=='\t') {
|
if (charStyle!=style || currChar=='\t' || prevChar=='\t') {
|
||||||
// draw a segment whenever the style changes or a Tab is found
|
// draw a segment whenever the style changes or a Tab is found
|
||||||
@@ -1972,17 +1969,7 @@ void Fl_Text_Display::draw_string(int style,
|
|||||||
if (!(style & BG_ONLY_MASK)) {
|
if (!(style & BG_ONLY_MASK)) {
|
||||||
fl_color( foreground );
|
fl_color( foreground );
|
||||||
fl_font( font, fsize );
|
fl_font( font, fsize );
|
||||||
|
fl_draw( string, nChars, X, Y + mMaxsize - fl_descent());
|
||||||
// FIXME: remove this again!
|
|
||||||
char *buf = (char*)malloc(nChars);
|
|
||||||
memcpy(buf, string, nChars);
|
|
||||||
int i = 0;
|
|
||||||
for (i=0; i<nChars; i++) {
|
|
||||||
if (buf[i]=='\t') buf[i] = '$';
|
|
||||||
}
|
|
||||||
fl_draw( buf, nChars, X, Y + mMaxsize - fl_descent());
|
|
||||||
|
|
||||||
//fl_draw( string, nChars, X, Y + mMaxsize - fl_descent());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CET - FIXME
|
// CET - FIXME
|
||||||
@@ -2195,16 +2182,6 @@ double Fl_Text_Display::string_width( const char *string, int length, int style
|
|||||||
fsize = textsize();
|
fsize = textsize();
|
||||||
}
|
}
|
||||||
fl_font( font, fsize );
|
fl_font( font, fsize );
|
||||||
|
|
||||||
// FIXME: remove this again!
|
|
||||||
char *buf = (char*)malloc(length);
|
|
||||||
memcpy(buf, string, length);
|
|
||||||
int i = 0;
|
|
||||||
for (i=0; i<length; i++) {
|
|
||||||
if (buf[i]=='\t') buf[i] = '$';
|
|
||||||
}
|
|
||||||
return fl_width( buf, length);
|
|
||||||
|
|
||||||
return fl_width( string, length );
|
return fl_width( string, length );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3138,7 +3115,7 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
|
|||||||
// FIXME: it is not a good idea to simply add character widths because on
|
// FIXME: it is not a good idea to simply add character widths because on
|
||||||
// some platforms, the width is a floating point value and depends on the
|
// some platforms, the width is a floating point value and depends on the
|
||||||
// previous character as well.
|
// previous character as well.
|
||||||
width += measure_proportional_character(s, colNum, p+styleBufOffset);
|
width += measure_proportional_character(s, width, p+styleBufOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If character exceeded wrap margin, find the break point and wrap there */
|
/* If character exceeded wrap margin, find the break point and wrap there */
|
||||||
@@ -3150,10 +3127,9 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
|
|||||||
newLineStart = buf->next_char(b);
|
newLineStart = buf->next_char(b);
|
||||||
colNum = 0;
|
colNum = 0;
|
||||||
width = 0;
|
width = 0;
|
||||||
// TODO: we should have a much more efficient function already available!
|
|
||||||
int iMax = buf->next_char(p);
|
int iMax = buf->next_char(p);
|
||||||
for (i=buf->next_char(b); i<iMax; i = buf->next_char(i)) {
|
for (i=buf->next_char(b); i<iMax; i = buf->next_char(i)) {
|
||||||
width += measure_proportional_character(buf->address(i), colNum,
|
width += measure_proportional_character(buf->address(i), width,
|
||||||
i+styleBufOffset);
|
i+styleBufOffset);
|
||||||
colNum++;
|
colNum++;
|
||||||
}
|
}
|
||||||
@@ -3165,7 +3141,7 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
|
|||||||
newLineStart = max(p, buf->next_char(lineStart));
|
newLineStart = max(p, buf->next_char(lineStart));
|
||||||
const char *s = buf->address(b);
|
const char *s = buf->address(b);
|
||||||
colNum++;
|
colNum++;
|
||||||
width = measure_proportional_character(s, colNum, p+styleBufOffset);
|
width = measure_proportional_character(s, 0, p+styleBufOffset);
|
||||||
}
|
}
|
||||||
if (p >= maxPos) {
|
if (p >= maxPos) {
|
||||||
*retPos = maxPos;
|
*retPos = maxPos;
|
||||||
@@ -3214,13 +3190,18 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
|
|||||||
should now be solid because they are now used for online help display.
|
should now be solid because they are now used for online help display.
|
||||||
|
|
||||||
\param s text string
|
\param s text string
|
||||||
\param colNum unused
|
\param xPix x pixel position needed for calculating tab widths
|
||||||
\param pos offset within string
|
\param pos offset within string
|
||||||
\return width of character in pixels
|
\return width of character in pixels
|
||||||
*/
|
*/
|
||||||
double Fl_Text_Display::measure_proportional_character(const char *s, int colNum, int pos) const {
|
double Fl_Text_Display::measure_proportional_character(const char *s, int xPix, int pos) const {
|
||||||
IS_UTF8_ALIGNED(s)
|
IS_UTF8_ALIGNED(s)
|
||||||
|
|
||||||
|
if (*s=='\t') {
|
||||||
|
int tab = col_to_x(8);
|
||||||
|
return (((xPix/tab)+1)*tab) - xPix;
|
||||||
|
}
|
||||||
|
|
||||||
int charLen = fl_utf8len(*s), style = 0;
|
int charLen = fl_utf8len(*s), style = 0;
|
||||||
if (mStyleBuffer) {
|
if (mStyleBuffer) {
|
||||||
style = mStyleBuffer->byte_at(pos);
|
style = mStyleBuffer->byte_at(pos);
|
||||||
|
|||||||
+2
-12
@@ -775,22 +775,12 @@ Fl_Window* new_view() {
|
|||||||
w->editor = new Fl_Text_Editor(0, 30, 660, 370);
|
w->editor = new Fl_Text_Editor(0, 30, 660, 370);
|
||||||
w->editor->textfont(FL_COURIER);
|
w->editor->textfont(FL_COURIER);
|
||||||
w->editor->textsize(TS);
|
w->editor->textsize(TS);
|
||||||
w->editor->wrap_mode(Fl_Text_Editor::WRAP_AT_BOUNDS, 250);
|
//w->editor->wrap_mode(Fl_Text_Editor::WRAP_AT_BOUNDS, 250);
|
||||||
w->editor->buffer(textbuf);
|
w->editor->buffer(textbuf);
|
||||||
w->editor->textfont(FL_HELVETICA);
|
|
||||||
textbuf->text(
|
|
||||||
"12345678912345678901234567890\n"
|
|
||||||
"\tqwertyuiop\n"
|
|
||||||
"WWWWWWWW\tqwertyuiop\n"
|
|
||||||
"iiiiiiii\tqwertyuiop\n"
|
|
||||||
"\tasdfghjkl\n"
|
|
||||||
"\t\tasdfghjkl\t\n"
|
|
||||||
"\t\t\tzxcvbnm,\t\t\n"
|
|
||||||
"a\tb\tc\td\te\n"
|
|
||||||
"nvfdnv");
|
|
||||||
w->editor->highlight_data(stylebuf, styletable,
|
w->editor->highlight_data(stylebuf, styletable,
|
||||||
sizeof(styletable) / sizeof(styletable[0]),
|
sizeof(styletable) / sizeof(styletable[0]),
|
||||||
'A', style_unfinished_cb, 0);
|
'A', style_unfinished_cb, 0);
|
||||||
|
textbuf->text();
|
||||||
style_init();
|
style_init();
|
||||||
w->end();
|
w->end();
|
||||||
w->resizable(w->editor);
|
w->resizable(w->editor);
|
||||||
|
|||||||
Reference in New Issue
Block a user