Skip to content

Commit

Permalink
Add Unicode support in TTerminal
Browse files Browse the repository at this point in the history
  • Loading branch information
magiblot committed Aug 21, 2020
1 parent 7fdf689 commit ee821b6
Showing 1 changed file with 42 additions and 10 deletions.
52 changes: 42 additions & 10 deletions source/tvision/textview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <string.h>
#endif // __STRING_H

#include <malloc.h>

TTextDevice::TTextDevice( const TRect& bounds,
TScrollBar *aHScrollBar,
TScrollBar *aVScrollBar,
Expand Down Expand Up @@ -120,12 +122,37 @@ Boolean TTerminal::canInsert( ushort amount )
return Boolean( queBack > T );
}

#ifdef __FLAT__

#define DRAW_DYNAMIC_STR 1
#define resizeStr(_len) \
slen = _len; \
if (slen > scap) \
s = (char *) ::realloc(s, (scap = max(slen, 2*scap)));

#else

#define DRAW_DYNAMIC_STR 0
#define resizeStr(_len) \
slen = _len;

#endif // __FLAT__

void TTerminal::draw()
{
#if DRAW_DYNAMIC_STR
size_t scap = 256;
char *s = (char*) ::malloc(scap);
#else
char s[256];
#endif
size_t slen = 0;
TScreenCell *_b = (TScreenCell*) alloca(size.x*sizeof(TScreenCell));
TSpan<TScreenCell> b(_b, size.x);
short i;
ushort begLine, endLine;
char s[256];
ushort bottomLine;
uchar color = mapColor(1);

bottomLine = size.y + delta.y;
if( limit.y > bottomLine )
Expand All @@ -151,29 +178,34 @@ void TTerminal::draw()
if (endLine >= begLine)
{
int T = int( endLine - begLine );
resizeStr(T);
memcpy( s, &buffer[begLine], T );
s[T] = EOS;
}
else
{
int T = int( bufSize - begLine);
resizeStr(T + endLine);
memcpy( s, &buffer[begLine], T );
memcpy( s+T, buffer, endLine );
s[T+endLine] = EOS;
}
int l = strlen(s);
if( delta.x >= l )
*s = EOS;
else
memmove( s, &s[delta.x], l );

writeStr( 0, i, s, 1 );
writeChar( strlen(s), i, ' ', 1, size.x );
{
int x = TText::fill(b, size.x, TStringView(s, slen), color);
while (x < size.x)
::setCell(b[x++], ' ', color);
}
writeBuf( 0, i, size.x, 1, b.data() );
endLine = begLine;
bufDec( endLine );
}
#if DRAW_DYNAMIC_STR
::free(s);
#endif
}

#undef DRAW_DYNAMIC_STR
#undef resizeStr

ushort TTerminal::nextLine( ushort pos )
{
if( pos != queFront )
Expand Down

0 comments on commit ee821b6

Please sign in to comment.