Skip to content
Permalink
Browse files

Make rocketChatField UCS2 aware.

Fixes #595
  • Loading branch information...
DolceTriade committed May 5, 2015
1 parent cd011ff commit a3794f9b131a88017ef32a5595e1fa6f8faf5708
Showing with 46 additions and 32 deletions.
  1. +1 −3 src/engine/client/cl_scrn.cpp
  2. +45 −29 src/engine/client/rocketChatField.h
@@ -299,8 +299,6 @@ void SCR_DrawStringExt( int x, int y, float size, const char *string, float *set

while ( *s )
{
int ch;

if ( !noColorEscape && Q_IsColorString( s ) )
{
s += 2;
@@ -312,7 +310,7 @@ void SCR_DrawStringExt( int x, int y, float size, const char *string, float *set
++s;
}

ch = Q_UTF8_CodePoint( s );
auto ch = Q_UTF8_CodePoint( s );
SCR_DrawUnichar( xx + 2, y + 2, size, ch );
xx += size;
s += Q_UTF8_WidthCP( ch );
@@ -41,7 +41,7 @@ Maryland 20850 USA.
#include <Rocket/Core/GeometryUtilities.h>
#include "client.h"
#include "rocket.h"
#include "framework/CommandSystem.h"
#include "../framework/CommandSystem.h"

class RocketChatField : public Rocket::Core::Element, Rocket::Core::EventListener
{
@@ -192,7 +192,9 @@ class RocketChatField : public Rocket::Core::Element, Rocket::Core::EventListene
}
else if ( cmd == "/" )
{
Cmd::BufferCommandText( text.CString() );
Rocket::Core::String utf8String;
Rocket::Core::WString( text ).ToUTF8( utf8String );
Cmd::BufferCommandText( utf8String.CString() );
text.Clear();
UpdateText();
GetOwnerDocument()->Hide();
@@ -206,7 +208,9 @@ class RocketChatField : public Rocket::Core::Element, Rocket::Core::EventListene

if ( !cmd.Empty() && !text.Empty() )
{
Cmd::BufferCommandText( va( "%s %s", cmd.CString(), Cmd::Escape( text.CString() ).c_str() ) );
Rocket::Core::String utf8String;
Rocket::Core::WString( text ).ToUTF8( utf8String );
Cmd::BufferCommandText( Cmd::Escape( va( "%s %s", cmd.CString(), utf8String.CString() ) ) );
text.Clear();
UpdateText();
GetOwnerDocument()->Hide();
@@ -229,7 +233,7 @@ class RocketChatField : public Rocket::Core::Element, Rocket::Core::EventListene

if ( text.Length() == cursor_character_index )
{
text.Append( ( char )character );
text.Append( character );
}

else
@@ -332,41 +336,54 @@ class RocketChatField : public Rocket::Core::Element, Rocket::Core::EventListene
text_element->RemoveReference();
if ( !text.Empty() )
{
q2rml( text.CString(), text_element );
q2rml( text, text_element );
}
}

bool IsColorString( Rocket::Core::WString str, size_t position )
{
if ( position + 1 < str.Length() )
{
return ( str[position] == Q_COLOR_ESCAPE &&
( str[position + 1] == COLOR_NULL || ( str[position + 1] >= '0' && str[position + 1] != Q_COLOR_ESCAPE && str[position + 1] < 'p' ) )
) ? true : false;
}
else
{
return false;
}
}

// Special q -> rml conversion function that preserves carets and codes
void q2rml( const char *in, Rocket::Core::Element *parent )
void q2rml( Rocket::Core::WString in, Rocket::Core::Element *parent )
{
const char *p;
Rocket::Core::String out;
Rocket::Core::WString out;
Rocket::Core::Element *child = nullptr;
bool span = false;

if ( !*in )
if ( in.Empty() )
{
return;
}

for ( p = in; p && *p; ++p )
for ( size_t i = 0; i < in.Length(); ++i )
{
if ( *p == '<' )
if ( in[i] == '<' )
{
out.Append( "&lt;" );
out.Append( Rocket::Core::WString( "&lt;" ) );
}

else if ( *p == '>' )
else if ( in[i] == '>' )
{
out.Append( "&gt;" );
out.Append( Rocket::Core::WString( "&gt;" ) );
}

else if ( *p == '&' )
else if ( in[i] == '&' )
{
out.Append( "&amp;" );
out.Append( Rocket::Core::WString( "&amp;" ) );
}

else if ( *p == '\n' )
else if ( in[i] == '\n' )
{
// Child element initialized.
if ( span )
@@ -389,19 +406,17 @@ class RocketChatField : public Rocket::Core::Element, Rocket::Core::EventListene
child->RemoveReference();
out.Clear();
}

// Convert ^^ to ^
else if ( *p == '^' && *( p + 1 ) == '^' )
else if ( in[i] == '^' && i < in.Length() - 1 && in[i + 1] == '^' )
{
p++;
out.Append( "^" );
i++;
out.Append( Rocket::Core::WString( "^" ) );
}

else if ( Q_IsColorString( p ) )
else if ( IsColorString( in, i ) )
{
Rocket::Core::XMLAttributes xml;
int code = ColorIndex( *++p );
char c = *p;
int code = ColorIndex( in[++i] );
auto c = in[i];

// Child element initialized
if ( span )
@@ -431,13 +446,12 @@ class RocketChatField : public Rocket::Core::Element, Rocket::Core::EventListene
( int )( g_color_table[ code ][ 0 ] * 255 ),
( int )( g_color_table[ code ][ 1 ] * 255 ),
( int )( g_color_table[ code ][ 2 ] * 255 ) ) );
out.Append( va( "^%c", c ) );
out.Append( Rocket::Core::WString( va( "^%c", c ) ) );
span = true;
}

else
{
out.Append( *p );
out.Append( in[i] );
}
}

@@ -470,8 +484,10 @@ class RocketChatField : public Rocket::Core::Element, Rocket::Core::EventListene
Rocket::Core::Geometry cursor_geometry;
Rocket::Core::Vector2f cursor_size;
Rocket::Core::Vector2f dimensions;
Rocket::Core::String text;
Rocket::Core::WString text;
Rocket::Core::String cmd;

};
#endif


0 comments on commit a3794f9

Please sign in to comment.
You can’t perform that action at this time.