[Scummvm-git-logs] scummvm master -> c276bc6fb0c8912ddd1c2211e18756bf9989bf0a

elasota noreply at scummvm.org
Mon Jul 4 03:31:45 UTC 2022


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
c276bc6fb0 MTROPOLIS: Add some more text rendering functionality


Commit: c276bc6fb0c8912ddd1c2211e18756bf9989bf0a
    https://github.com/scummvm/scummvm/commit/c276bc6fb0c8912ddd1c2211e18756bf9989bf0a
Author: elasota (ejlasota at gmail.com)
Date: 2022-07-03T23:30:46-04:00

Commit Message:
MTROPOLIS: Add some more text rendering functionality

Changed paths:
    engines/mtropolis/assets.cpp
    engines/mtropolis/data.cpp
    engines/mtropolis/data.h
    engines/mtropolis/elements.cpp
    engines/mtropolis/elements.h


diff --git a/engines/mtropolis/assets.cpp b/engines/mtropolis/assets.cpp
index 4d70e12b0f3..102f1553f2f 100644
--- a/engines/mtropolis/assets.cpp
+++ b/engines/mtropolis/assets.cpp
@@ -1119,6 +1119,9 @@ bool MToonMetadata::FrameRangeDef::load(AssetLoaderContext &context, const Data:
 bool TextAsset::load(AssetLoaderContext &context, const Data::TextAsset &data) {
 	_assetID = data.assetID;
 
+	_isBitmap = ((data.isBitmap & 1) != 0);
+
+	// Bitmaps may contain garbled alignment
 	switch (data.alignment) {
 	case Data::kTextAlignmentCodeLeft:
 		_alignment = kTextAlignmentLeft;
@@ -1130,11 +1133,13 @@ bool TextAsset::load(AssetLoaderContext &context, const Data::TextAsset &data) {
 		_alignment = kTextAlignmentCenter;
 		break;
 	default:
-		return false;
+		if (_isBitmap)
+			_alignment = kTextAlignmentLeft;
+		else
+			return false;
+		break;
 	};
 
-	_isBitmap = ((data.isBitmap & 1) != 0);
-
 	if (_isBitmap) {
 		if (!data.bitmapRect.toScummVMRect(_bitmapRect))
 			return false;
@@ -1160,7 +1165,11 @@ bool TextAsset::load(AssetLoaderContext &context, const Data::TextAsset &data) {
 		_bitmapData->create(width, height, Graphics::PixelFormat::createFormatCLUT8());
 
 		for (int row = 0; row < height; row++) {
-			uint8 *outRow = static_cast<uint8 *>(_bitmapData->getBasePtr(0, row));
+			int outRowY = row;
+			if (data.isBottomUp)
+				outRowY = height - 1 - row;
+
+			uint8 *outRow = static_cast<uint8 *>(_bitmapData->getBasePtr(0, outRowY));
 			const uint8 *inRow = &data.bitmapData[row * pitch];
 			for (int col = 0; col < width; col++) {
 				int bit = ((inRow[col / 8] >> (7 - (col & 7))) & 1);
diff --git a/engines/mtropolis/data.cpp b/engines/mtropolis/data.cpp
index dd28f88e56e..fd5bff6cf19 100644
--- a/engines/mtropolis/data.cpp
+++ b/engines/mtropolis/data.cpp
@@ -1765,10 +1765,12 @@ DataReadErrorCode TextAsset::load(DataReader &reader) {
 	haveWinPart = false;
 	if (reader.getProjectFormat() == kProjectFormatMacintosh) {
 		haveMacPart = true;
+		isBottomUp = false;
 		if (!reader.readBytes(platform.mac.unknown3))
 			return kDataReadErrorReadFailed;
 	} else if (reader.getProjectFormat() == kProjectFormatWindows) {
 		haveWinPart = true;
+		isBottomUp = true;
 		if (!reader.readBytes(platform.win.unknown4))
 			return kDataReadErrorReadFailed;
 	} else
diff --git a/engines/mtropolis/data.h b/engines/mtropolis/data.h
index d050745cc30..2db06c5ee35 100644
--- a/engines/mtropolis/data.h
+++ b/engines/mtropolis/data.h
@@ -1768,6 +1768,8 @@ struct TextAsset : public DataObject {
 	Common::String text;
 	Common::Array<uint8> bitmapData;
 
+	bool isBottomUp;
+
 	Common::Array<MacFormattingSpan> macFormattingSpans;
 
 protected:
diff --git a/engines/mtropolis/elements.cpp b/engines/mtropolis/elements.cpp
index 6004d12eccd..5eaae0ecfdf 100644
--- a/engines/mtropolis/elements.cpp
+++ b/engines/mtropolis/elements.cpp
@@ -1714,7 +1714,7 @@ void TextLabelElement::activate() {
 
 	TextAsset *textAsset = static_cast<TextAsset *>(asset.get());
 
-	if (textAsset->isBitmap()) {
+	if (textAsset->isBitmap()) { 
 		_renderedText = textAsset->getBitmapSurface();
 		_needsRender = false;
 	} else {
@@ -1750,6 +1750,8 @@ void TextLabelElement::render(Window *window) {
 		const Graphics::Font *font = nullptr;
 		if (_fontFamilyName.size() > 0) {
 			font = FontMan.getFontByName(_fontFamilyName.c_str());
+			if (!font)
+				font = FontMan.getFontByUsage(getDefaultUsageForNamedFont(_fontFamilyName, _size));
 		} else if (_macFontID != 0) {
 			// TODO: Formatting spans
 			int slant = 0;
@@ -1769,12 +1771,10 @@ void TextLabelElement::render(Window *window) {
 			if (_styleFlags.expanded)
 				slant |= 64;
 
-			// FIXME/HACK: This is a stupid way to make getFont return null on failure
-			font = _runtime->getMacFontManager()->getFont(Graphics::MacFont(_macFontID, _size, slant, static_cast<Graphics::FontManager::FontUsage>(-1)));
-		}
+			const Graphics::FontManager::FontUsage defaultUsage = getDefaultUsageForMacFont(_macFontID, _size);
 
-		if (!font)
-			font = FontMan.getFontByUsage(Graphics::FontManager::kConsoleFont);
+			font = _runtime->getMacFontManager()->getFont(Graphics::MacFont(_macFontID, _size, slant, defaultUsage));
+		}
 
 		int height = font->getFontHeight();
 		int ascent = font->getFontAscent();
@@ -1865,7 +1865,9 @@ void TextLabelElement::render(Window *window) {
 	Common::Rect srcRect(0, 0, renderWidth, renderHeight);
 	Common::Rect destRect(_cachedAbsoluteOrigin.x, _cachedAbsoluteOrigin.y, _cachedAbsoluteOrigin.x + _rect.width(), _cachedAbsoluteOrigin.y + _rect.height());
 
-	const uint32 opaqueColor = 0xff000000;
+	// TODO: Need to handle more modes
+	const ColorRGB8 &color = _renderProps.getForeColor();
+	const uint32 opaqueColor = target->format.RGBToColor(color.r, color.g, color.b);
 	const uint32 drawPalette[2] = {0, opaqueColor};
 
 	if (_renderedText) {
@@ -1875,8 +1877,10 @@ void TextLabelElement::render(Window *window) {
 }
 
 void TextLabelElement::setTextStyle(uint16 macFontID, const Common::String &fontFamilyName, uint size, TextAlignment alignment, const TextStyleFlags &styleFlags) {
-	_needsRender = true;
-	_contentsDirty = true;
+	if (!_text.empty()) {
+		_needsRender = true;
+		_contentsDirty = true;
+	}
 
 	_macFontID = macFontID;
 	_fontFamilyName = fontFamilyName;
@@ -1885,6 +1889,33 @@ void TextLabelElement::setTextStyle(uint16 macFontID, const Common::String &font
 	_styleFlags = styleFlags;
 }
 
+Graphics::FontManager::FontUsage TextLabelElement::getDefaultUsageForMacFont(uint16 macFontID, uint size) {
+	switch (macFontID) {
+	case Graphics::kMacFontCourier:
+		return Graphics::FontManager::kConsoleFont;
+	default:
+		break;
+	}
+
+	warning("Unhandled font ID %i default, this might not render well", static_cast<int>(macFontID));
+	return Graphics::FontManager::kGUIFont;
+}
+
+Graphics::FontManager::FontUsage TextLabelElement::getDefaultUsageForNamedFont(const Common::String &fontFamilyName, uint size) {
+	if (fontFamilyName == "Courier New") {
+		if (size == 8)
+			return Graphics::FontManager::kConsoleFont;
+	} else if (fontFamilyName == "Arial") {
+		if (size == 10)
+			return Graphics::FontManager::kGUIFont;
+		if (size == 14)
+			return Graphics::FontManager::kBigGUIFont;
+	}
+
+	warning("Unhandled font name '%s' default, this might not render well", fontFamilyName.c_str());
+	return Graphics::FontManager::kGUIFont;
+}
+
 MiniscriptInstructionOutcome TextLabelElement::scriptSetText(MiniscriptThread *thread, const DynamicValue &value) {
 	if (value.getType() != DynamicValueTypes::kString) {
 		thread->error("Tried to set a text label element's text to something that wasn't a string");
diff --git a/engines/mtropolis/elements.h b/engines/mtropolis/elements.h
index dbfb78d59f6..b2a37f0c333 100644
--- a/engines/mtropolis/elements.h
+++ b/engines/mtropolis/elements.h
@@ -22,6 +22,8 @@
 #ifndef MTROPOLIS_ELEMENTS_H
 #define MTROPOLIS_ELEMENTS_H
 
+#include "graphics/fontman.h"
+
 #include "mtropolis/data.h"
 #include "mtropolis/runtime.h"
 #include "mtropolis/render.h"
@@ -278,6 +280,9 @@ public:
 
 	void setTextStyle(uint16 macFontID, const Common::String &fontFamilyName, uint size, TextAlignment alignment, const TextStyleFlags &styleFlags);
 
+	Graphics::FontManager::FontUsage getDefaultUsageForMacFont(uint16 macFontID, uint size);
+	Graphics::FontManager::FontUsage getDefaultUsageForNamedFont(const Common::String &fontFamilyName, uint size);
+
 #ifdef MTROPOLIS_DEBUG_ENABLE
 	const char *debugGetTypeName() const override { return "Text Label Element"; }
 	SupportStatus debugGetSupportStatus() const override { return kSupportStatusPartial; }




More information about the Scummvm-git-logs mailing list