Mailinglist Archive: yast-commit (126 mails)

< Previous Next >
[yast-commit] r67590 - in /branches/SuSE-Code-11-SP2-Branch/ncurses/src: NCRichText.cc NCRichText.h
Author: gs
Date: Thu Mar 8 11:26:16 2012
New Revision: 67590

URL: http://svn.opensuse.org/viewcvs/yast?rev=67590&view=rev
Log:
interpret html tags inside <pre> (bnc #724119),
also solves problem with license text (bnc #737752)

Modified:
branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCRichText.cc
branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCRichText.h

Modified: branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCRichText.cc
URL:
http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCRichText.cc?rev=67590&r1=67589&r2=67590&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCRichText.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCRichText.cc Thu Mar 8
11:26:16 2012
@@ -160,7 +160,7 @@
, NCPadWidget( parent )
, text( ntext )
, plainText( plainTextMode )
- , textwidth( 0 )
+ , textwidth( 0 )
, cl( 0 )
, cc( 0 )
, cindent( 0 )
@@ -322,36 +322,23 @@
}
}

-
-void NCRichText::PadPlainTXT( const wchar_t * osch, const unsigned olen )
+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 );

- if ( ftext.Columns() > textwidth )
- textwidth = ftext.Columns();
-
- AdjustPad( wsze( cl + ftext.Lines(), textwidth ) );
-
// insert the text
const wchar_t * sch = wtxt.data();

while ( *sch )
{
- if ( *sch != L'\r' ) // skip carriage return
- {
- myPad()->addwstr( sch, 1 ); // add one wide chararacter
- cc += wcwidth( *sch );
+ myPad()->addwstr( sch, 1 ); // add one wide chararacter

- if ( *sch == L'\n' )
- {
- PadNL(); // add a new line
- }
- }
++sch;
}
}
@@ -398,21 +385,92 @@
while ( *wch && WDtoken.find( *wch ) == wstring::npos );
}

+static wstring PREtoken( L"<\n\v\r\f" ); // line manipulations + TokenStart
'<'
+

inline void SkipPreTXT( const wchar_t *& wch )
{
+ do
+ {
+ ++wch;
+ }
+ while ( *wch && PREtoken.find( *wch ) == wstring::npos );
+}
+
+
+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;
+ ++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" );
+ // handle DOS text
+ for ( ; (pos = wtxt.find( L"\r" )) != wstring::npos ; )
+ wtxt.replace( pos, 1, L"" );
+ for ( ; (pos = wtxt.find( L"\f" )) != wstring::npos ; )
+ wtxt.replace( pos, 1, 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()
{
@@ -441,6 +499,7 @@
case L'\n':
case L'\v':
case L'\r':
+ case L'\f':
if ( ! preTag )
{
SkipWS( wch );
@@ -448,12 +507,20 @@
}
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
+ case L'\t':
+ myPad()->addwstr( wch, 1 );
+ break;
+
+ case L'\n':
+ case L'\f':
+ PadNL(); // add new line
+ break;
+
+ default:
+ yuiDebug() << "Ignoring " << *wch << endl;
}
++wch;
}
@@ -461,16 +528,14 @@
break;

case L'<':
- if ( !preTag )
- {
- swch = wch;
- SkipToken( wch );
+ swch = wch;
+ SkipToken( wch );
+
+ if ( PadTOKEN( swch, wch ) )
+ break; // strip token
+ else
+ wch = swch; // reset and fall through

- if ( PadTOKEN( swch, wch ) )
- break; // strip token
- else
- wch = swch; // reset and fall through
- }
default:
swch = wch;

@@ -482,9 +547,7 @@
else
{
SkipPreTXT( wch );
- PadPlainTXT( swch, wch - swch );
- preTag = false;
- PadNL(); // add new line after pre is closed
+ PadPreTXT( swch, wch - swch );
}

break;
@@ -493,6 +556,7 @@

PadBOL();
AdjustPad( wsze( cl, textwidth ) );
+
yuiDebug() << "Anchors: " << anchors.size() << endl;

for ( unsigned i = 0; i < anchors.size(); ++i )
@@ -575,7 +639,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).
*/
@@ -588,7 +653,13 @@
{
// check whether char is printable
if ( iswprint( *wstr_it ) )
+ {
len += wcwidth( *wstr_it );
+ }
+ else if ( *wstr_it == '\t' )
+ {
+ len += myPad()->tabsize();
+ }
}

return len;
@@ -819,7 +890,7 @@
else if ( value == L"li" ) token = T_LI;
else if ( value == L"ol" ) { token = T_LEVEL; leveltag =
1; }
else if ( value == L"qt" ) token = T_IGNORE;
- else if ( value == L"tt" ) token = T_TT;
+ else if ( value == L"tt" ) token = T_IGNORE;
else if ( value == L"ul" ) { token = T_LEVEL; leveltag =
0; }

break;
@@ -959,11 +1030,13 @@

if ( !endtag )
{
- preTag = true; // display plain text
+ preTag = true; // display text preserving newlines and spaces
+ AdjustPrePad( ech );
}
else
{
preTag = false;
+ PadNL(); // add new line (text may continue after
</pre>)
}

break;

Modified: branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCRichText.h
URL:
http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCRichText.h?rev=67590&r1=67589&r2=67590&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCRichText.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCRichText.h Thu Mar 8
11:26:16 2012
@@ -1,4 +1,3 @@
-
/*---------------------------------------------------------------------\
| |
| __ __ ____ _____ ____ |
@@ -69,8 +68,7 @@
unsigned cindent;
bool atbol;

- bool preTag; // default is false; set true
- // if <pre> tag is found
+ bool preTag; // <pre> tag

unsigned Tattr;

@@ -190,7 +188,8 @@
void PadBOL();
void PadWS( const bool tab = false );
void PadTXT( const wchar_t * sch, const unsigned len );
- void PadPlainTXT( const wchar_t * sch, const unsigned len );
+ void PadPreTXT( const wchar_t * sch, const unsigned len );
+ void AdjustPrePad( const wchar_t * sch );
bool PadTOKEN( const wchar_t * sch, const wchar_t *& ech );

protected:

--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages