Exemplo n.º 1
0
// returns maximum font height used
void GfxText16::Draw(const char *text, int16 from, int16 len, GuiResourceId orgFontId, int16 orgPenColor) {
	uint16 curChar, charWidth;
	Common::Rect rect;

	GetFont();
	if (!_font)
		return;

	rect.top = _ports->_curPort->curTop;
	rect.bottom = rect.top + _ports->_curPort->fontHeight;
	text += from;
	while (len--) {
		curChar = (*(const byte *)text++);
		if (_font->isDoubleByte(curChar)) {
			curChar |= (*(const byte *)text++) << 8;
			len--;
		}
		switch (curChar) {
		case 0x0A:
		case 0x0D:
		case 0:
		case 0x9781: // this one is used by SQ4/japanese as line break as well
			break;
		case 0x7C:
			if (getSciVersion() >= SCI_VERSION_1_1) {
				len -= CodeProcessing(text, orgFontId, orgPenColor, true);
				break;
			}
			// fall through
			// FIXME: fall through intended?
		default:
			charWidth = _font->getCharWidth(curChar);
			// clear char
			if (_ports->_curPort->penMode == 1) {
				rect.left = _ports->_curPort->curLeft;
				rect.right = rect.left + charWidth;
				_paint16->eraseRect(rect);
			}
			// CharStd
			_font->draw(curChar, _ports->_curPort->top + _ports->_curPort->curTop, _ports->_curPort->left + _ports->_curPort->curLeft, _ports->_curPort->penClr, _ports->_curPort->greyedOutput);
			_ports->_curPort->curLeft += charWidth;
		}
	}
}
Exemplo n.º 2
0
void GfxText16::Width(const char *text, int16 from, int16 len, GuiResourceId orgFontId, int16 &textWidth, int16 &textHeight, bool restoreFont) {
	uint16 curChar;
	GuiResourceId previousFontId = GetFontId();
	int16 previousPenColor = _ports->_curPort->penClr;

	textWidth = 0; textHeight = 0;

	GetFont();
	if (_font) {
		text += from;
		while (len--) {
			curChar = (*(const byte *)text++);
			if (_font->isDoubleByte(curChar)) {
				curChar |= (*(const byte *)text++) << 8;
				len--;
			}
			switch (curChar) {
			case 0x0A:
			case 0x0D:
			case 0x9781: // this one is used by SQ4/japanese as line break as well
				textHeight = MAX<int16> (textHeight, _ports->_curPort->fontHeight);
				break;
			case 0x7C:
				if (getSciVersion() >= SCI_VERSION_1_1) {
					len -= CodeProcessing(text, orgFontId, 0, false);
					break;
				}
				// fall through
				// FIXME: fall through intended?
			default:
				textHeight = MAX<int16> (textHeight, _ports->_curPort->fontHeight);
				textWidth += _font->getCharWidth(curChar);
			}
		}
	}
	// When calculating size, we do not restore font because we need the current (code modified) font active
	//  If we are drawing this is called inbetween, so font needs to get restored
	//  If we are calculating size of just one fixed string (::StringWidth), then we need to restore
	if (restoreFont) {
		SetFont(previousFontId);
		_ports->penColor(previousPenColor);
	}
	return;
}
Exemplo n.º 3
0
// return max # of chars to fit maxwidth with full words, does not include
// breaking space
int16 GfxText16::GetLongest(const char *text, int16 maxWidth, GuiResourceId orgFontId) {
	uint16 curChar = 0;
	int16 maxChars = 0, curCharCount = 0;
	uint16 width = 0;
	GuiResourceId previousFontId = GetFontId();
	int16 previousPenColor = _ports->_curPort->penClr;

	GetFont();
	if (!_font)
		return 0;

	while (width <= maxWidth) {
		curChar = (*(const byte *)text++);
		if (_font->isDoubleByte(curChar)) {
			curChar |= (*(const byte *)text++) << 8;
			curCharCount++;
		}
		switch (curChar) {
		case 0x7C:
			if (getSciVersion() >= SCI_VERSION_1_1) {
				curCharCount++;
				curCharCount += CodeProcessing(text, orgFontId, previousPenColor, false);
				continue;
			}
			break;

		// We need to add 0xD, 0xA and 0xD 0xA to curCharCount and then exit
		//  which means, we split text like
		//  'Mature, experienced software analyst available.' 0xD 0xA
		//  'Bug installation a proven speciality. "No version too clean."' (normal game text, this is from lsl2)
		//   and 0xA '-------' 0xA (which is the official sierra subtitle separator)
		//  Sierra did it the same way.
		case 0xD:
			// Check, if 0xA is following, if so include it as well
			if ((*(const unsigned char *)text) == 0xA)
				curCharCount++;
			// it's meant to pass through here
		case 0xA:
		case 0x9781: // this one is used by SQ4/japanese as line break as well
			curCharCount++;
			// and it's also meant to pass through here
		case 0:
			SetFont(previousFontId);
			_ports->penColor(previousPenColor);
			return curCharCount;

		case ' ':
			maxChars = curCharCount; // return count up to (but not including) breaking space
			break;
		}
		// Sometimes this can go off the screen, like for example bug #3040161.
		// However, we only perform this for non-Japanese games, as these require
		// special handling, done after this loop.
		if (width + _font->getCharWidth(curChar) > maxWidth && g_sci->getLanguage() != Common::JA_JPN)
			break;
		width += _font->getCharWidth(curChar);
		curCharCount++;
	}

	// Text without spaces, probably Kanji/Japanese
	if (maxChars == 0) {
		maxChars = curCharCount;

		uint16 nextChar;

		// We remove the last char only, if maxWidth was actually equal width
		// before adding the last char. Otherwise we won't get the same cutting
		// as in sierra pc98 sci.
		if (maxWidth == (width - _font->getCharWidth(curChar))) {
			maxChars--;
			if (curChar > 0xFF)
				maxChars--;
			nextChar = curChar;
		} else {
			nextChar = (*(const byte *)text++);
			if (_font->isDoubleByte(nextChar))
				nextChar |= (*(const byte *)text++) << 8;
		}
		// sierra checked the following character against a punctuation kanji table
		if (nextChar > 0xFF) {
			// if the character is punctuation, we go back one character
			uint nonBreakingNr = 0;
			while (text16_punctuationSjis[nonBreakingNr]) {
				if (text16_punctuationSjis[nonBreakingNr] == nextChar) {
					maxChars--;
					if (curChar > 0xFF)
						maxChars--; // go back 2 chars, when last char was double byte
					break;
				}
				nonBreakingNr++;
			}
		}
	}
	SetFont(previousFontId);
	_ports->penColor(previousPenColor);
	return maxChars;
}
Exemplo n.º 4
0
// return max # of chars to fit maxwidth with full words, does not include
// breaking space
//  Also adjusts text pointer to the new position for the caller
// 
// Special cases in games:
//  Laura Bow 2 - Credits in the game menu - all the text lines start with spaces (bug #5159)
//                Act 6 Coroner questionaire - the text of all control buttons has trailing spaces
//                                              "Detective Ryan Hanrahan O'Riley" contains even more spaces (bug #5334)
//  Conquests of Camelot - talking with Cobb - one text box of the dialogue contains a longer word,
//                                              that will be broken into 2 lines (bug #5159)
int16 GfxText16::GetLongest(const char *&textPtr, int16 maxWidth, GuiResourceId orgFontId) {
	uint16 curChar = 0;
	const char *textStartPtr = textPtr;
	const char *lastSpacePtr = NULL;
	int16 lastSpaceCharCount = 0;
	int16 curCharCount = 0, resultCharCount = 0;
	uint16 curWidth = 0, tempWidth = 0;
	GuiResourceId previousFontId = GetFontId();
	int16 previousPenColor = _ports->_curPort->penClr;

	GetFont();
	if (!_font)
		return 0;

	while (1) {
		curChar = (*(const byte *)textPtr);
		if (_font->isDoubleByte(curChar)) {
			curChar |= (*(const byte *)(textPtr + 1)) << 8;
		}
		switch (curChar) {
		case 0x7C:
			if (getSciVersion() >= SCI_VERSION_1_1) {
				curCharCount++; textPtr++;
				curCharCount += CodeProcessing(textPtr, orgFontId, previousPenColor, false);
				continue;
			}
			break;

		// We need to add 0xD, 0xA and 0xD 0xA to curCharCount and then exit
		//  which means, we split text like for example
		//  - 'Mature, experienced software analyst available.' 0xD 0xA
		//    'Bug installation a proven speciality. "No version too clean."' (normal game text, this is from lsl2)
		//  - 0xA '-------' 0xA (which is the official sierra subtitle separator) (found in multilingual versions)
		//  Sierra did it the same way.
		case 0xD:
			// Check, if 0xA is following, if so include it as well
			if ((*(const byte *)(textPtr + 1)) == 0xA) {
				curCharCount++; textPtr++;
			}
			// it's meant to pass through here
		case 0xA:
		case 0x9781: // this one is used by SQ4/japanese as line break as well (was added for SCI1/PC98)
			curCharCount++; textPtr++;
			if (curChar > 0xFF) {
				// skip another byte in case char is double-byte (PC-98)
				curCharCount++; textPtr++;
			}
			// and it's also meant to pass through here
		case 0:
			SetFont(previousFontId);
			_ports->penColor(previousPenColor);
			return curCharCount;

		case ' ':
			lastSpaceCharCount = curCharCount; // return count up to (but not including) breaking space
			lastSpacePtr = textPtr + 1; // remember position right after the current space
			break;
		}
		tempWidth += _font->getCharWidth(curChar);
		
		// Width is too large? -> break out
		if (tempWidth > maxWidth)
			break;

		// still fits, remember width
		curWidth = tempWidth;

		// go to next character
		curCharCount++; textPtr++;
		if (curChar > 0xFF) {
			// Double-Byte
			curCharCount++; textPtr++;
		 }
	}

	if (lastSpaceCharCount) {
		// Break and at least one space was found before that
		resultCharCount = lastSpaceCharCount;

		// additionally skip over all spaces, that are following that space, but don't count them for displaying purposes
		textPtr = lastSpacePtr;
		while (*textPtr == ' ')
			textPtr++;

	} else {
		// Break without spaces found, we split the very first word - may also be Kanji/Japanese
		if (curChar > 0xFF) {
			// current charracter is Japanese

			// PC-9801 SCI actually added the last character, which shouldn't fit anymore, still onto the
			//  screen in case maxWidth wasn't fully reached with the last character
			if (( maxWidth - 1 ) > curWidth) {
				curCharCount += 2; textPtr += 2;

				curChar = (*(const byte *)textPtr);
				if (_font->isDoubleByte(curChar)) {
					curChar |= (*(const byte *)(textPtr + 1)) << 8;
				}
			}

			// But it also checked, if the current character is not inside a punctuation table and it even
			//  went backwards in case it found multiple ones inside that table.
			// Note: PQ2 PC-98 only went back 1 character and not multiple ones
			uint nonBreakingPos = 0;

			const uint16 *punctuationTable;

			if (getSciVersion() != SCI_VERSION_01) {
				punctuationTable = text16_shiftJIS_punctuation;
			} else {
				// Quest for Glory 1 PC-98 only
				punctuationTable = text16_shiftJIS_punctuation_SCI01;
			}

			while (1) {
				// Look up if character shouldn't be the first on a new line
				nonBreakingPos = 0;
				while (punctuationTable[nonBreakingPos]) {
					if (punctuationTable[nonBreakingPos] == curChar)
						break;
					nonBreakingPos++;
				}
				if (!punctuationTable[nonBreakingPos]) {
					// character is fine
					break;
				}
				// Character is not acceptable, seek backward in the text
				curCharCount -= 2; textPtr -= 2;
				if (textPtr < textStartPtr)
					error("Seeking back went too far, data corruption?");

				curChar = (*(const byte *)textPtr);
				if (!_font->isDoubleByte(curChar))
					error("Non double byte while seeking back");
				curChar |= (*(const byte *)(textPtr + 1)) << 8;
			}

			if (curChar == 0x4081) {
				// Skip over alphabetic double-byte space
				// This was introduced for SCI1
				// Happens in Castle of Dr. Brain PC-98 in room 120, when looking inside the mirror
				// (game mentions Mixed Up Fairy Tales and uses English letters for that)
				textPtr += 2;
			}
		}

		// We split the word in that case
		resultCharCount = curCharCount;
	}
	SetFont(previousFontId);
	_ports->penColor(previousPenColor);
	return resultCharCount;
}