Author: gs Date: Wed Feb 8 13:26:38 2012 New Revision: 67379 URL: http://svn.opensuse.org/viewcvs/yast?rev=67379&view=rev Log: improve adjusting of pad size or text in <pre> tags 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=67379&r1=67378&r2=67379&view=diff ============================================================================== --- trunk/ncurses/src/NCRichText.cc (original) +++ trunk/ncurses/src/NCRichText.cc Wed Feb 8 13:26:38 2012 @@ -347,22 +347,13 @@ void NCRichText::PadPreTXT( 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 ); - int len = textWidth( wtxt ); - - if ( cc + len > textwidth ) - { - textwidth = cc + len; - AdjustPad( wsze(cl + ftext.Lines(), textwidth) ); - yuiDebug() << "Adjust: " << cl+ftext.Lines() << " " << textwidth << endl; - } - // insert the text const wchar_t * sch = wtxt.data(); @@ -370,9 +361,6 @@ { myPad()->addwstr( sch, 1 ); // add one wide chararacter - if ( iswprint( *sch ) ) - cc += wcwidth( *sch ); // wcwidth for \t returns -1 - ++sch; } } @@ -432,7 +420,74 @@ } +void NCRichText::AdjustPrePad( const wchar_t *osch ) +{ + const wchar_t * wch = osch; + wstring wstr( wch, 6 ); + + size_t llen = 0; // longest line + size_t tmp_len = 0; // width of current line + + list<NCstring>::const_iterator line; // iterator for list <NCstring> mtext + std::wstring::const_iterator wstr_it; // iterator for wstring + + do + { + ++wch; + wstr.assign( wch, 6 ); + } + while ( *wch && wstr != L"</pre>" ); + + wstring wtxt( osch, wch - osch ); + + // resolve the entities to get correct length for calculation of longest line + wtxt = filterEntities( wtxt ); + + wstring to_repl = L"<br>"; + size_t pos; + + // replace <br> by \n to get appropriate lines in NCtext + for ( ; (pos = wtxt.find( to_repl )) != wstring::npos ; ) + wtxt.replace( pos, to_repl.length(), L"\n" ); + + yuiDebug() << "Input: " << wtxt << " olen: " << wch - osch << endl; + + NCstring nctxt( wtxt ); + NCtext ftext( nctxt ); + + // iterate through NCtext + for ( line = ftext.Text().begin(); line != ftext.Text().end(); ++line ) + { + tmp_len = 0; + + for ( wstr_it = ( *line ).str().begin(); wstr_it != ( *line ).str().end() ; ++wstr_it ) + { + // skip html tags + if ( *wstr_it == '<' ) + { + wstr_it = find(wstr_it, (*line).str().end(), L'>'); + } + else if ( *wstr_it == '\t' ) + { + tmp_len += myPad()->tabsize(); + } + else + { + tmp_len += wcwidth( *wstr_it ); + } + } + + if ( tmp_len > llen ) + llen = tmp_len; + } + if ( llen > textwidth ) + { + textwidth = llen; + AdjustPad( wsze( cl + ftext.Lines(), llen ) ); // adjust pad to longest line + } + +} void NCRichText::DrawHTMLPad() { @@ -470,20 +525,15 @@ { switch ( *wch ) { - case L' ': // add white space + case L' ': // add white space + case L'\t': 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; } @@ -996,11 +1046,11 @@ if ( !endtag ) { preTag = true; // display text preserving newlines and spaces + AdjustPrePad( sch ); } else { preTag = false; - PadNL(); // add new line after pre } break; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org