diff options
| -rw-r--r-- | engines/queen/journal.cpp | 53 | 
1 files changed, 37 insertions, 16 deletions
| diff --git a/engines/queen/journal.cpp b/engines/queen/journal.cpp index 7846fa5c36..b782328f83 100644 --- a/engines/queen/journal.cpp +++ b/engines/queen/journal.cpp @@ -380,35 +380,56 @@ void Journal::handleMouseDown(int x, int y) {  	update();  } +static void removeLeadingAndTrailingSpaces(char *dst, size_t dstSize, const char* src) { +	assert(dstSize > 0); +	size_t srcLen = strlen(src); +	if (0 == srcLen) { +		dst[0] = '\0'; +		return; +	} +	 +	size_t firstNonSpaceIndex; +	for (firstNonSpaceIndex = 0; firstNonSpaceIndex < srcLen; ++firstNonSpaceIndex) { +		if (src[firstNonSpaceIndex] != ' ') +			break;		 +	} +	if (firstNonSpaceIndex == srcLen) { +		dst[0] = '\0'; +		return; +	} +	 +	size_t lastNonSpaceIndex = srcLen - 1; +	while (src[lastNonSpaceIndex] == ' ') +		--lastNonSpaceIndex; +	 +	size_t newLen = lastNonSpaceIndex - firstNonSpaceIndex + 1; +	assert(newLen < dstSize); +	for (size_t i = 0; i < newLen; ++i) { +		dst[i] = src[firstNonSpaceIndex + i]; +	} +	dst[newLen] = '\0';	 +} +  void Journal::drawPanelText(int y, const char *text) {  	debug(7, "Journal::drawPanelText(%d, '%s')", y, text); +	  	char s[128]; -	strncpy(s, text, 127); -	s[127] = 0; -	char *p; +	removeLeadingAndTrailingSpaces(s, 128, text); // necessary for spanish version -	// remove leading and trailing spaces (necessary for spanish version) -	for (p = s + strlen(s) - 1; p >= s && *p == ' '; --p) { -		*p = 0; -	} -	text = s; -	for (p = s; *p == ' '; ++p) { -		text = p + 1; -	}  	// draw the substrings -	p = (char *)strchr(text, ' '); +	char *p = strchr(s, ' ');  	if (!p) { -		int x = (128 - _vm->display()->textWidth(text)) / 2; -		_vm->display()->setText(x, y, text, false); +		int x = (128 - _vm->display()->textWidth(s)) / 2; +		_vm->display()->setText(x, y, s, false);  		assert(_panelTextCount < MAX_PANEL_TEXTS);  		_panelTextY[_panelTextCount++] = y;  	} else {  		*p++ = '\0';  		if (_vm->resource()->getLanguage() == Common::HB_ISR) {  			drawPanelText(y - 5, p); -			drawPanelText(y + 5, text); +			drawPanelText(y + 5, s);  		} else { -			drawPanelText(y - 5, text); +			drawPanelText(y - 5, s);  			drawPanelText(y + 5, p);  		}  	} | 
