Author: gs Date: Tue Mar 10 14:46:23 2009 New Revision: 56046 URL: http://svn.opensuse.org/viewcvs/yast?rev=56046&view=rev Log: bugfix for text in <pre> ... </pre> tags: show DOS files correctly, i.e. don't print '\r' and use correct length. 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=56046&r1=56045&r2=56046&view=diff ============================================================================== --- trunk/ncurses/src/NCRichText.cc (original) +++ trunk/ncurses/src/NCRichText.cc Tue Mar 10 14:46:23 2009 @@ -321,9 +321,12 @@ void NCRichText::PadPlainTXT( const wchar_t * osch, const unsigned olen ) { wstring wtxt( osch, olen ); + // resolve the entities even in PRE (#71718) + wtxt = filterEntities( wtxt ); + NCstring nctxt( wtxt ); NCtext ftext( nctxt ); - + if ( ftext.Columns() > textwidth ) textwidth = ftext.Columns(); @@ -334,20 +337,20 @@ while ( *sch ) { - myPad()->addwstr( sch, 1 ); // add one wide chararacter - cc += wcwidth( *sch ); - - if ( *sch == L'\n' ) + if ( *sch != L'\r' ) // skip carriage return { - PadNL(); // add a new line - } + myPad()->addwstr( sch, 1 ); // add one wide chararacter + cc += wcwidth( *sch ); + if ( *sch == L'\n' ) + { + PadNL(); // add a new line + } + } ++sch; } } - - // // DrawHTMLPad tools // @@ -433,7 +436,6 @@ case L'\n': case L'\v': case L'\r': - if ( ! preTag ) { SkipWS( wch ); @@ -441,8 +443,11 @@ } else { - myPad()->addwstr( wch, 1 ); // add one wide chararacter - ++cc; + if ( *wch != L'\r' ) // skip carriage return + { + myPad()->addwstr( wch, 1 ); // add the wide chararacter + cc += wcwidth( *wch ); + } ++wch; } @@ -450,7 +455,7 @@ case L'<': swch = wch; - SkipToken( wch ); + SkipToken( wch ); if ( PadTOKEN( swch, wch ) ) break; // strip token @@ -468,11 +473,7 @@ else { SkipPreTXT( wch ); - - // resolve the entities even in PRE (#71718) - wstring txt = filterEntities( wstring( swch, wch - swch ) ); - - PadPlainTXT( txt.c_str(), textWidth( txt ) ); + PadPlainTXT( swch, wch - swch ); } break; @@ -561,7 +562,12 @@ } } - +/** + * 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'). + * 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). + */ size_t NCRichText::textWidth( wstring wstr ) { size_t len = 0; @@ -569,7 +575,9 @@ for ( wstr_it = wstr.begin(); wstr_it != wstr.end() ; ++wstr_it ) { - len += wcwidth( *wstr_it ); + // check whether char is printable + if ( iswprint( *wstr_it ) ) + len += wcwidth( *wstr_it ); } return len; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org