Break down conv summary lines based on chars that actually fit; bug #916

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2514 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2006-11-21 22:39:23 +00:00
parent 696495da97
commit e5fd8282bf
+19 -42
View File
@@ -100,7 +100,6 @@ static int
_count_lines (PTEXT pText) _count_lines (PTEXT pText)
{ {
SIZE text_width; SIZE text_width;
COUNT maxchars = (COUNT)~0;
const unsigned char *pStr; const unsigned char *pStr;
int numLines = 0; int numLines = 0;
BOOLEAN eol; BOOLEAN eol;
@@ -113,8 +112,8 @@ _count_lines (PTEXT pText)
{ {
++numLines; ++numLines;
pText->pStr = pStr; pText->pStr = pStr;
eol = getLineWithinWidth(pText, &pStr, text_width, maxchars); eol = getLineWithinWidth(pText, &pStr, text_width, (COUNT)~0);
} while (!eol && maxchars); } while (!eol);
pText->pStr = pStr; pText->pStr = pStr;
return numLines; return numLines;
@@ -307,13 +306,15 @@ add_text (int status, PTEXT pTextIn)
// past the newline, or if the entire string fits, to the end of the // past the newline, or if the entire string fits, to the end of the
// string. // string.
// maxWidth is the maximum number of pixels that a line may be wide // maxWidth is the maximum number of pixels that a line may be wide
// ASSUMPTION: there are no words in the text wider than maxWidth
// maxChars is the maximum number of characters (not bytes) that are to // maxChars is the maximum number of characters (not bytes) that are to
// be fitted. // be fitted.
// TRUE is returned if a complete line fitted // TRUE is returned if a complete line fitted
// FALSE otherwise // FALSE otherwise
BOOLEAN BOOLEAN
getLineWithinWidth(TEXT *pText, const unsigned char **startNext, getLineWithinWidth(TEXT *pText, const unsigned char **startNext,
SIZE maxWidth, COUNT maxChars) { SIZE maxWidth, COUNT maxChars)
{
BOOLEAN eol; BOOLEAN eol;
// The end of the line of text has been reached. // The end of the line of text has been reached.
BOOLEAN done; BOOLEAN done;
@@ -925,7 +926,6 @@ static BOOLEAN
DoConvSummary (PSUMMARY_STATE pSS) DoConvSummary (PSUMMARY_STATE pSS)
{ {
#define DELTA_Y_SUMMARY 8 #define DELTA_Y_SUMMARY 8
#define SUMMARY_CHARS (SIS_SCREEN_WIDTH - 34) / 4
#define MAX_SUMM_ROWS ((SIS_SCREEN_HEIGHT - SLIDER_Y - SLIDER_HEIGHT) \ #define MAX_SUMM_ROWS ((SIS_SCREEN_HEIGHT - SLIDER_Y - SLIDER_HEIGHT) \
/ DELTA_Y_SUMMARY) - 1 / DELTA_Y_SUMMARY) - 1
@@ -960,7 +960,6 @@ DoConvSummary (PSUMMARY_STATE pSS)
{ // print the next page { // print the next page
RECT r; RECT r;
TEXT t; TEXT t;
UNICODE buffer[320]; // SUMMARY_CHARS * 6
int row; int row;
FONT oldFont; FONT oldFont;
@@ -975,71 +974,48 @@ DoConvSummary (PSUMMARY_STATE pSS)
SetContextForeGroundColor (COMM_HISTORY_TEXT_COLOR); SetContextForeGroundColor (COMM_HISTORY_TEXT_COLOR);
t.baseline.x = SAFE_X + 2; r.extent.width -= 2 + 2;
t.baseline.x = 2;
t.align = ALIGN_LEFT; t.align = ALIGN_LEFT;
t.baseline.y = SAFE_Y + DELTA_Y_SUMMARY; t.baseline.y = DELTA_Y_SUMMARY;
t.CharCount = (COUNT)~0;
oldFont = SetContextFont (TinyFont); oldFont = SetContextFont (TinyFont);
for (row = 0; row < MAX_SUMM_ROWS && pSS->NextSub; for (row = 0; row < MAX_SUMM_ROWS && pSS->NextSub;
++row, pSS->NextSub = pSS->NextSub->next) ++row, pSS->NextSub = pSS->NextSub->next)
{ {
UNICODE *temp; UNICODE *next;
if (pSS->LeftOver) if (pSS->LeftOver)
{ // some text left from last subtitle { // some text left from last subtitle
temp = pSS->LeftOver; t.pStr = pSS->LeftOver;
pSS->LeftOver = NULL; pSS->LeftOver = NULL;
} }
else else
{ {
temp = pSS->NextSub->text; t.pStr = pSS->NextSub->text;
if (!temp) if (!t.pStr)
continue; continue;
} }
t.CharCount = (COUNT)~0;
for ( ; row < MAX_SUMM_ROWS && for ( ; row < MAX_SUMM_ROWS &&
utf8StringCount (temp) > (unsigned) SUMMARY_CHARS; !getLineWithinWidth(&t, &next, r.extent.width, (COUNT)~0);
++row) ++row)
{ {
UNICODE *pend = skipUTF8Chars (temp, SUMMARY_CHARS);
int space_index = pend - temp;
int i;
// find last space before it goes over the max chars per line
for (i = space_index; i > 0; i--)
{
if (temp[i] == ' ')
{
space_index = i;
break;
}
}
if ((unsigned)space_index >= sizeof (buffer))
{
UnlockMutex (GraphicsLock);
log_add (log_Fatal, "DoConvSummary() BUG: "
"buffer[%u] too small to fit %d bytes\n",
sizeof (buffer), space_index);
exit (EXIT_FAILURE);
}
strncpy (buffer, temp, space_index);
buffer[space_index] = '\0';
temp += space_index + 1;
t.pStr = buffer;
font_DrawText (&t); font_DrawText (&t);
t.baseline.y += DELTA_Y_SUMMARY; t.baseline.y += DELTA_Y_SUMMARY;
t.pStr = next;
t.CharCount = (COUNT)~0;
} }
if (row >= MAX_SUMM_ROWS) if (row >= MAX_SUMM_ROWS)
{ // no more space on screen, but some text left over { // no more space on screen, but some text left over
// from the current subtitle // from the current subtitle
pSS->LeftOver = temp; pSS->LeftOver = next;
break; break;
} }
t.pStr = temp; // this subtitle fit completely
font_DrawText (&t); font_DrawText (&t);
t.baseline.y += DELTA_Y_SUMMARY; t.baseline.y += DELTA_Y_SUMMARY;
} }
@@ -1047,6 +1023,7 @@ DoConvSummary (PSUMMARY_STATE pSS)
if (row >= MAX_SUMM_ROWS && (pSS->NextSub || pSS->LeftOver)) if (row >= MAX_SUMM_ROWS && (pSS->NextSub || pSS->LeftOver))
{ // draw *MORE* { // draw *MORE*
TEXT mt; TEXT mt;
UNICODE buffer[80];
mt.baseline.x = SIS_SCREEN_WIDTH >> 1; mt.baseline.x = SIS_SCREEN_WIDTH >> 1;
mt.baseline.y = t.baseline.y; mt.baseline.y = t.baseline.y;