... but word-wrap would make me love it more :smile.gif:
please Mr. Minecraft, copy/paste this snippet I made for you into 1.6.7 <3
/*
Notes:
- A client-side fix would be much cleaner
- The array should be created once at load-time (and probably already exists somewhere)
- This will truncate (unexpectedly) a user's message if word-wrap inserts spaces beyond
a string length of 119, thus...
- Similar code should be implemented when a user is inputing text
- This code could also be used to change the max words of 119 into a width-based length
- This code could be used to wrap input and detect the need for temporary expansion of the
input-box, correcting the 'invisible text' phenomenon
- Hard-coded font widths present various limitations to future modifications
- Extended language fonts are not supported within this code
- If this code does anything bad or implies anything not-so-good, then I didn't write it :smile.gif:
*/
//////////////////////////////////////////////////////////////////
//__Array which holds relative font widths______________________//
//////////////////////////////////////////////////////////////////
//*This should be moved to global scope or an accessible class* //
public int fontSizes[] =
/// , !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, 0, 1,/////////
{ 4, 2, 5, 6, 6, 6, 6, 3, 6, 6, 5, 6, 2, 6, 2, 6, 6, 6,
///2, 3, 4, 5, 6, 7, 8, 9, :, ;, <, =, >, ?, @, A, B, C,/////////
6, 6, 6, 6, 6, 6, 6, 6, 2, 2, 5, 6, 5, 6, 7, 6, 6, 6,
///D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U,/////////
6, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
///V ,W, X, Y, Z, [, \, ], ^, _, `, a, b, c, d, e, f, g,/////////
6, 6, 6, 6, 6, 4, 6, 4, 6, 6, 3, 6, 6, 6, 6, 6, 5, 6,
///h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y,/////////
6, 2, 6, 5, 3, 6, 6, 6, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
///z, {, |, }, ~
6, 5, 2, 5, 7 };
//////////////////////////////////////////////////////////////////
public Packet3Chat(String s)
{
int lastWordPos = 0; // Index of the last char before character-wrap is induced
int charVal = 0; // Reusable int to hold casted char values
int wordspace = 0; // Relative amount of space utilized by the string
// Assuming that the total width of the chat-box is 326 units...
if( s.length() > 3 ) // <--Protect against empty / non-chat strings
{
// Loop until the sum of int-casted characters' widths exceeds the chat-box width
while(wordspace < 326 && lastWordPos < s.length() )
{
charVal = (int)s.charAt(lastWordPos) - 32; // <--Each value is in ASCII decimal with a -32 offset
if( charVal >= 0 && charVal <= 94) // <--Protect against non-display characters
wordspace += fontSizes[ charVal ];
lastWordPos++;
}
// Attempt word-wrap if character-wrap is imminent.
if( wordspace > 320 && s.charAt(lastWordPos-1) != ' ')
{
// Loop until the beginning of the last word is found...
while( s.charAt(--lastWordPos) != ' ' && lastWordPos > 3 )
{
charVal = (int)s.charAt(lastWordPos) - 32;
wordspace -= fontSizes[ charVal ];
}
// Split the string accordingly...
String begStr = s.substring(0, lastWordPos);
String endStr = s.substring(lastWordPos, s.length());
// Then loop, filling with spaces until the word is 'pushed' to a new line
for(int idx = 0; idx < (322 - wordspace); idx += 4)
begStr += ' ';
// Concatenate the strings
begStr += endStr;
s = begStr;
}
}
// Truncate
if(s.length() > 119)
s = s.substring(0, 119);
message = s;
}
It's a server-side fix for how text gets character-wrapped. I didn't want my buddies to have to go through all the mod stuff so figured I would change the string before it gets sent out to the users :smile.gif:
It changes...
[ <Fuzums> Hello peoples, what's goi]
[ ng on today? ]
into...
[ <Fuzums> Hello peoples, what's ]
[ going on today? ]
by adding spaces equal to the width of the first half of the cut-up word. It's not pretty, but it works :|
I'd really like to use it to fix how text writes past the visible area of the text box too, but thought I should wait for the official code release... It's also not a pretty fix, since a lot of memory gets allocated each time a message is sent out, but it's not noticeable--just a ghetto-rig until I can do a client-side fix ^^
Feel free to use it, but you might want to consider defining the fontSizes[] array somewhere that isn't instantiated often :3
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
ft!
... but word-wrap would make me love it more :smile.gif:
please Mr. Minecraft, copy/paste this snippet I made for you into 1.6.7 <3
/* Notes: - A client-side fix would be much cleaner - The array should be created once at load-time (and probably already exists somewhere) - This will truncate (unexpectedly) a user's message if word-wrap inserts spaces beyond a string length of 119, thus... - Similar code should be implemented when a user is inputing text - This code could also be used to change the max words of 119 into a width-based length - This code could be used to wrap input and detect the need for temporary expansion of the input-box, correcting the 'invisible text' phenomenon - Hard-coded font widths present various limitations to future modifications - Extended language fonts are not supported within this code - If this code does anything bad or implies anything not-so-good, then I didn't write it :smile.gif: */ ////////////////////////////////////////////////////////////////// //__Array which holds relative font widths______________________// ////////////////////////////////////////////////////////////////// //*This should be moved to global scope or an accessible class* // public int fontSizes[] = /// , !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, 0, 1,///////// { 4, 2, 5, 6, 6, 6, 6, 3, 6, 6, 5, 6, 2, 6, 2, 6, 6, 6, ///2, 3, 4, 5, 6, 7, 8, 9, :, ;, <, =, >, ?, @, A, B, C,///////// 6, 6, 6, 6, 6, 6, 6, 6, 2, 2, 5, 6, 5, 6, 7, 6, 6, 6, ///D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U,///////// 6, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, ///V ,W, X, Y, Z, [, \, ], ^, _, `, a, b, c, d, e, f, g,///////// 6, 6, 6, 6, 6, 4, 6, 4, 6, 6, 3, 6, 6, 6, 6, 6, 5, 6, ///h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y,///////// 6, 2, 6, 5, 3, 6, 6, 6, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6, ///z, {, |, }, ~ 6, 5, 2, 5, 7 }; ////////////////////////////////////////////////////////////////// public Packet3Chat(String s) { int lastWordPos = 0; // Index of the last char before character-wrap is induced int charVal = 0; // Reusable int to hold casted char values int wordspace = 0; // Relative amount of space utilized by the string // Assuming that the total width of the chat-box is 326 units... if( s.length() > 3 ) // <--Protect against empty / non-chat strings { // Loop until the sum of int-casted characters' widths exceeds the chat-box width while(wordspace < 326 && lastWordPos < s.length() ) { charVal = (int)s.charAt(lastWordPos) - 32; // <--Each value is in ASCII decimal with a -32 offset if( charVal >= 0 && charVal <= 94) // <--Protect against non-display characters wordspace += fontSizes[ charVal ]; lastWordPos++; } // Attempt word-wrap if character-wrap is imminent. if( wordspace > 320 && s.charAt(lastWordPos-1) != ' ') { // Loop until the beginning of the last word is found... while( s.charAt(--lastWordPos) != ' ' && lastWordPos > 3 ) { charVal = (int)s.charAt(lastWordPos) - 32; wordspace -= fontSizes[ charVal ]; } // Split the string accordingly... String begStr = s.substring(0, lastWordPos); String endStr = s.substring(lastWordPos, s.length()); // Then loop, filling with spaces until the word is 'pushed' to a new line for(int idx = 0; idx < (322 - wordspace); idx += 4) begStr += ' '; // Concatenate the strings begStr += endStr; s = begStr; } } // Truncate if(s.length() > 119) s = s.substring(0, 119); message = s; }Cheers!
It changes...
by adding spaces equal to the width of the first half of the cut-up word. It's not pretty, but it works :|
I'd really like to use it to fix how text writes past the visible area of the text box too, but thought I should wait for the official code release... It's also not a pretty fix, since a lot of memory gets allocated each time a message is sent out, but it's not noticeable--just a ghetto-rig until I can do a client-side fix ^^
Feel free to use it, but you might want to consider defining the fontSizes[] array somewhere that isn't instantiated often :3