Exemple #1
0
bool WinFont::loadFromNE(const Common::String &fileName, const WinFontDirEntry &dirEntry) {
	Common::NEResources exe;

	if (!exe.loadFromEXE(fileName))
		return false;

	// Let's pull out the font directory
	Common::SeekableReadStream *fontDirectory = exe.getResource(Common::kNEFontDir, Common::String("FONTDIR"));
	if (!fontDirectory) {
		warning("No font directory in '%s'", fileName.c_str());
		return false;
	}

	uint32 fontId = getFontIndex(*fontDirectory, dirEntry);

	delete fontDirectory;

	// Couldn't match the face name
	if (fontId == 0xffffffff) {
		warning("Could not find face '%s' in '%s'", dirEntry.faceName.c_str(), fileName.c_str());
		return false;
	}

	// Actually go get our font now...
	Common::SeekableReadStream *fontStream = exe.getResource(Common::kNEFont, fontId);
	if (!fontStream) {
		warning("Could not find font %d in %s", fontId, fileName.c_str());
		return false;
	}

	bool ok = loadFromFNT(*fontStream);
	delete fontStream;
	return ok;
}
Exemple #2
0
bool WinFont::loadFromFON(const Common::String &fileName, const WinFontDirEntry &dirEntry) {
	// TODO: PE libraries (If it's used anywhere by a ScummVM game)

	Common::NEResources exe;

	if (!exe.loadFromEXE(fileName))
		return false;

	// Let's pull out the font directory
	Common::SeekableReadStream *fontDirectory = exe.getResource(Common::kNEFontDir, Common::String("FONTDIR"));
	if (!fontDirectory) {
		warning("No font directory in '%s'", fileName.c_str());
		return false;
	}

	uint16 numFonts = fontDirectory->readUint16LE();

	// Probably not possible, so this is really a sanity check
	if (numFonts == 0) {
		warning("No fonts in '%s'", fileName.c_str());
		return false;
	}

	// Scour the directory for our matching name
	int fontId = -1;
	for (uint16 i = 0; i < numFonts; i++) {
		uint16 id = fontDirectory->readUint16LE();

		if (dirEntry.faceName.empty()) {
			// Use the first name when empty
			fontId = id;
			break;
		}

		WinFontDirEntry entry = readDirEntry(*fontDirectory);

		if (dirEntry.faceName.equalsIgnoreCase(entry.faceName) && dirEntry.points == entry.points) {
			// Match!
			fontId = id;
			break;
		}
	}

	delete fontDirectory;

	// Couldn't match the face name
	if (fontId < 0) {
		warning("Could not find face '%s' in '%s'", dirEntry.faceName.c_str(), fileName.c_str());
		return false;
	}

	// Actually go get our font now...
	Common::SeekableReadStream *fontStream = exe.getResource(Common::kNEFont, fontId);
	if (!fontStream) {
		warning("Could not find font %d in %s", fontId, fileName.c_str());
		return false;
	}

	bool ok = loadFromFNT(*fontStream);
	delete fontStream;
	return ok;
}