[yast-commit] r67353 - /trunk/ncurses/src/NCRichText.cc
Author: gs Date: Thu Feb 2 15:39:12 2012 New Revision: 67353 URL: http://svn.opensuse.org/viewcvs/yast?rev=67353&view=rev Log: handle tabs inside <pre> correctly Modified: trunk/ncurses/src/NCRichText.cc Modified: trunk/ncurses/src/NCRichText.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ncurses/src/NCRichText.cc?rev=67353&r1=67352&r2=67353&view=diff ============================================================================== --- trunk/ncurses/src/NCRichText.cc (original) +++ trunk/ncurses/src/NCRichText.cc Thu Feb 2 15:39:12 2012 @@ -355,11 +355,12 @@ NCtext ftext( nctxt ); int len = textWidth( wtxt ); - + if ( cc + len > textwidth ) { textwidth = cc + len; - AdjustPad( wsze(cl+ftext.Lines(), textwidth) ); + AdjustPad( wsze(cl + ftext.Lines(), textwidth) ); + yuiDebug() << "Adjust: " << cl+ftext.Lines() << " " << textwidth << endl; } // insert the text @@ -368,8 +369,10 @@ while ( *sch ) { myPad()->addwstr( sch, 1 ); // add one wide chararacter - cc += wcwidth( *sch ); + if ( iswprint( *sch ) ) + cc += wcwidth( *sch ); // wcwidth for \t returns -1 + ++sch; } } @@ -465,12 +468,24 @@ } else { - if ( *wch != L'\r' ) // skip carriage return + switch ( *wch ) { - myPad()->addwstr( wch, 1 ); // add the wide chararacter - cc += wcwidth( *wch ); - if ( *wch == '\n' ) - PadNL(); + case L' ': // add white space + myPad()->addwstr( wch, 1 ); + cc+=wcwidth( *wch ); + break; + + case L'\n': + PadNL(); // add new line + break; + + case L'\t': // add tab + myPad()->addwstr( wch, 1 ); + cc += myPad()->tabsize(); + break; + + default: + yuiDebug() << "Ignoring " << *wch << endl; } ++wch; } @@ -506,7 +521,7 @@ PadBOL(); AdjustPad( wsze( cl, textwidth ) ); - yuiMilestone() << "adjust: lines: " << cl << " columns: " << textwidth << endl; + yuiDebug() << "Anchors: " << anchors.size() << endl; for ( unsigned i = 0; i < anchors.size(); ++i ) @@ -589,7 +604,8 @@ /** * Get the number of columns needed to print a 'wstring'. Only printable characters - * are taken into account because others would return -1 (e.g. '\n'). + * are taken into account because otherwise 'wcwidth' would return -1 (e.g. for '\n'). + * Tabs are calculated with tabsize(). * Attention: only use textWidth() to calculate space, not for iterating through a text * or to get the length of a text (real text length includes new lines). */ @@ -602,7 +618,13 @@ { // check whether char is printable if ( iswprint( *wstr_it ) ) - len += wcwidth( *wstr_it ); + { + len += wcwidth( *wstr_it ); + } + else if ( *wstr_it == '\t' ) + { + len += myPad()->tabsize(); + } } return len; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
gs@svn2.opensuse.org